Skip to content

Commit 3c9e2f3

Browse files
committed
WIP: growth chart
1 parent 9d9851a commit 3c9e2f3

File tree

1 file changed

+166
-14
lines changed

1 file changed

+166
-14
lines changed

components/Charts/PowerEnergyChart.vue

+166-14
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,61 @@
4949
@date-axis="(visible) => showDateAxis = visible"
5050
/>
5151

52+
<div
53+
v-if="isTypeGrowthStackedArea"
54+
style="position: absolute; top: 3rem; left: 3rem; font-style: italic;">
55+
{{ growthDataset.length }}
56+
</div>
57+
58+
59+
<stacked-area-vis
60+
v-if="chartShown && (isTypeGrowthStackedArea)"
61+
:read-only="readOnly"
62+
:domains="domains"
63+
:dataset="growthDataset"
64+
:range="range"
65+
:interval="interval"
66+
:curve="chartCurve"
67+
:y-min="computedGrowthYMin"
68+
:y-max="computedGrowthYMax"
69+
:vis-height="visHeight"
70+
:hover-on="hoverOn"
71+
:hover-date="hoverDate"
72+
:dynamic-extent="zoomExtent"
73+
:zoomed="zoomExtent.length > 0"
74+
:x-guides="xGuides"
75+
:y-guides="yGuides"
76+
:x-axis-dy="tabletBreak ? 8 : 12"
77+
:y-axis-ticks="5"
78+
:show-x-axis="false"
79+
:compare-dates="compareDates"
80+
:focus-date="focusDate"
81+
:focus-on="focusOn"
82+
:incomplete-intervals="incompleteIntervals"
83+
:dataset-two="
84+
chartEnergyRenewablesLine ? renewablesPercentageDataset : []
85+
"
86+
:dataset-two-colour="renewablesLineColour"
87+
:highlight-domain="highlightId"
88+
:mobile-screen="tabletBreak"
89+
:display-prefix="chartDisplayPrefix"
90+
:should-convert-value="false"
91+
:unit="` ${chartDisplayPrefix}${chartUnit}`"
92+
:null-check-prop="'_total'"
93+
:filter-period="filterPeriod"
94+
:show-total-line="chartEnergyNetLine"
95+
:total-line-domain="'_total'"
96+
:class="{ dragging: dragging }"
97+
:use-offset-diverge="true"
98+
class="vis-chart"
99+
@dateOver="handleDateHover"
100+
@domainOver="handleDomainHover"
101+
@svgClick="handleSvgClick"
102+
@enter="handleVisEnter"
103+
@leave="handleVisLeave"
104+
@zoomExtent="handleZoomExtent"
105+
/>
106+
52107
<stacked-area-vis
53108
v-if="chartShown && (isTypeArea || isTypeProportion)"
54109
:read-only="readOnly"
@@ -149,11 +204,6 @@
149204
@leave="handleVisLeave"
150205
/>
151206

152-
<div v-if="isTypeGrowthStackedArea">
153-
{{ growthDataset.length }}
154-
155-
</div>
156-
157207
<date-brush
158208
v-if="showDateAxis && chartShown"
159209
:dataset="dataset"
@@ -343,7 +393,9 @@ export default {
343393
visHeight: 330,
344394
draggedHeight: 330,
345395
dragging: false,
346-
showDivider: false
396+
showDivider: false,
397+
398+
growthDataset: []
347399
}
348400
},
349401
@@ -541,14 +593,6 @@ export default {
541593
return unit
542594
},
543595
544-
growthDataset() {
545-
if (this.isTypeGrowthStackedArea) {
546-
console.log('growthDataset', this.stackedAreaDataset)
547-
}
548-
549-
return []
550-
},
551-
552596
energyPercentDataset() {
553597
const dataset = _cloneDeep(this.powerEnergyDataset)
554598
dataset.forEach((d, i) => {
@@ -727,6 +771,7 @@ export default {
727771
this.$emit('selectedDataset', ds)
728772
return ds
729773
},
774+
730775
// yMin() {
731776
// const loadDomains = this.domains.filter((d) => d.category === LOAD)
732777
// if (loadDomains.length === 0) {
@@ -756,6 +801,51 @@ export default {
756801
// })
757802
// return max(dataset, d => d._stackedTotalMax)
758803
// },
804+
computedGrowthYMin() {
805+
let lowest = 0
806+
807+
console.log('computedGrowthYMin', this.powerEnergyDomains)
808+
809+
const loadDomains = this.powerEnergyDomains.filter((d) => d.category === LOAD)
810+
if (loadDomains.length === 0) {
811+
console.log('computedGrowthYMin', lowest)
812+
return lowest
813+
} else {
814+
this.growthDataset.forEach((d) => {
815+
let total = 0
816+
loadDomains.forEach((domain) => {
817+
total += d[domain.id] || 0
818+
})
819+
820+
if (total < lowest) {
821+
lowest = total
822+
}
823+
})
824+
825+
console.log('computedGrowthYMin', lowest)
826+
827+
return -10
828+
}
829+
},
830+
computedGrowthYMax() {
831+
let highest = 0
832+
833+
this.growthDataset.forEach((d) => {
834+
let total = 0
835+
this.powerEnergyDomains.forEach((domain) => {
836+
total += d[domain.id] || 0
837+
})
838+
839+
if (total > highest) {
840+
highest = total
841+
}
842+
})
843+
844+
console.log('computedGrowthYMax', highest)
845+
846+
return 10
847+
},
848+
759849
computedYMin() {
760850
let lowest = 0
761851
@@ -956,8 +1046,41 @@ export default {
9561046
chartUnitPrefix() {
9571047
this.$emit('selectedDataset', this.dataset)
9581048
},
1049+
9591050
interval() {
9601051
this.handleTypeClick()
1052+
1053+
if (this.isTypeGrowthStackedArea) {
1054+
this.growthDataset = this.zoomExtent.length > 0 ? this.getGrowthDataset().filter((d) => {
1055+
return d.date >= this.zoomExtent[0] && d.date < this.zoomExtent[1]
1056+
}) : this.getGrowthDataset()
1057+
1058+
console.log('growthDataset zoomExtent', this.growthDataset)
1059+
}
1060+
},
1061+
1062+
zoomExtent(val) {
1063+
console.log('zoomExtent', val, this.stackedAreaDataset)
1064+
1065+
if (this.isTypeGrowthStackedArea) {
1066+
this.growthDataset = val.length > 0 ? this.getGrowthDataset().filter((d) => {
1067+
return d.date >= val[0] && d.date < val[1]
1068+
}) : this.getGrowthDataset()
1069+
1070+
console.log('growthDataset zoomExtent', this.growthDataset)
1071+
}
1072+
},
1073+
1074+
isTypeGrowthStackedArea(val) {
1075+
console.log('isTypeGrowthStackedArea', val)
1076+
1077+
if (val) {
1078+
this.growthDataset = this.zoomExtent.length > 0 ? this.getGrowthDataset().filter((d) => {
1079+
return d.date >= this.zoomExtent[0] && d.date < this.zoomExtent[1]
1080+
}) : this.getGrowthDataset()
1081+
1082+
console.log('growthDataset isTypeGrowthStackedArea', this.growthDataset)
1083+
}
9611084
}
9621085
},
9631086
@@ -1063,6 +1186,35 @@ export default {
10631186
return newDataset
10641187
},
10651188
1189+
getGrowthDataset() {
1190+
const dataset= []
1191+
1192+
this.stackedAreaDataset.forEach((d, i) => {
1193+
const obj = {
1194+
date: d.date,
1195+
time: d.time
1196+
}
1197+
1198+
this.powerEnergyDomains.forEach((domain) => {
1199+
const ftId = domain.id
1200+
1201+
if (i === 0) {
1202+
obj[ftId] = 0
1203+
} else {
1204+
obj[ftId] = d[ftId] - this.stackedAreaDataset[i - 1][ftId]
1205+
}
1206+
1207+
})
1208+
1209+
dataset.push(obj)
1210+
1211+
})
1212+
1213+
console.log('growthDataset end', dataset)
1214+
1215+
return dataset
1216+
},
1217+
10661218
handleDomainHover(domain) {
10671219
this.setHoverDomain(domain)
10681220
},

0 commit comments

Comments
 (0)