Skip to content

Commit d79d0c7

Browse files
authored
Feature/growth chart (#249)
* add growthstacked area option for powerenergy chart * wip: calculate growth dataset * WIP: growth chart * Update PowerEnergyChart.vue * Update PowerEnergyChart.vue * Update PowerEnergyChart.vue * fix issue where switching growth charts to stacked area doesn't update the data properly * fix issue where tooltip is not using growth dataset on hover * fix issue where yAxis doesn't rescale correctly when zoomed in * refactor and fix issue where growth dataset is not calculated when hiddenDomains changed * update growth dataset calculation for rolling sum * refactor and fix issue where zoom out sometimes doesn't work in growth chart * refactor and fix issue where growth dataset is not calculated when filter period changes * revert to stacked chart when switching from energy growth chart to power chart
1 parent f89c413 commit d79d0c7

File tree

6 files changed

+217
-13
lines changed

6 files changed

+217
-13
lines changed

components/Charts/PowerEnergyChart.vue

+164-9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
:is-type-proportion="isTypeProportion"
2222
:is-type-line="isTypeLine"
2323
:is-type-change-since-line="isTypeChangeSinceLine"
24+
:is-type-growth-stacked-area="isTypeGrowthStackedArea"
2425
:is-y-axis-absolute="isYAxisAbsolute"
2526
:is-y-axis-percentage="isYAxisPercentage"
2627
:is-y-axis-average-power="isYAxisAveragePower"
@@ -50,15 +51,15 @@
5051
/>
5152

5253
<stacked-area-vis
53-
v-if="chartShown && (isTypeArea || isTypeProportion)"
54+
v-if="chartShown && (isTypeArea || isTypeProportion || isTypeGrowthStackedArea)"
5455
:read-only="readOnly"
5556
:domains="domains"
56-
:dataset="stackedAreaDataset"
57+
:dataset="isTypeGrowthStackedArea ? growthDataset : stackedAreaDataset"
5758
:range="range"
5859
:interval="interval"
5960
:curve="chartCurve"
60-
:y-min="isTypeArea ? computedYMin : 0"
61-
:y-max="isTypeArea ? computedYMax : 100"
61+
:y-min="isTypeGrowthStackedArea ? computedGrowthYMin : isTypeArea ? computedYMin : 0"
62+
:y-max="isTypeGrowthStackedArea ? computedGrowthYMax : isTypeArea ? computedYMax : 100"
6263
:vis-height="visHeight"
6364
:hover-on="hoverOn"
6465
:hover-date="hoverDate"
@@ -88,6 +89,7 @@
8889
:show-total-line="chartEnergyNetLine"
8990
:total-line-domain="'_total'"
9091
:class="{ dragging: dragging }"
92+
:use-offset-diverge="isTypeGrowthStackedArea ? true : false"
9193
class="vis-chart"
9294
@dateOver="handleDateHover"
9395
@domainOver="handleDomainHover"
@@ -150,7 +152,24 @@
150152
/>
151153

152154
<date-brush
153-
v-if="showDateAxis && chartShown"
155+
v-if="showDateAxis && chartShown && isTypeGrowthStackedArea"
156+
:dataset="growthDataset"
157+
:zoom-range="zoomExtent"
158+
:x-ticks="xTicks"
159+
:tick-format="tickFormat"
160+
:second-tick-format="secondTickFormat"
161+
:read-only="readOnly"
162+
:interval="interval"
163+
:filter-period="filterPeriod"
164+
:append-datapoint="isEnergyType"
165+
class="date-brush vis-chart"
166+
@date-hover="handleDateHover"
167+
@date-filter="handleZoomExtent"
168+
@enter="handleVisEnter"
169+
@leave="handleVisLeave"
170+
/>
171+
<date-brush
172+
v-if="showDateAxis && chartShown && !isTypeGrowthStackedArea"
154173
:dataset="dataset"
155174
:zoom-range="zoomExtent"
156175
:x-ticks="xTicks"
@@ -191,6 +210,7 @@ import * as SI from '@/constants/si.js'
191210
import { RANGE_ALL_12MTH_ROLLING } from '@/constants/ranges.js'
192211
import { LOAD } from '@/constants/energy-fuel-techs/group-detailed.js'
193212
import EnergyToAveragePower from '@/data/transform/energy-to-average-power.js'
213+
import transformToGrowthTimeSeries from '~/data/transform/growth-series.js'
194214
import DateDisplay from '@/services/DateDisplay.js'
195215
import MultiLine from '@/components/Vis/MultiLine'
196216
import DateBrush from '@/components/Vis/DateBrush'
@@ -218,7 +238,8 @@ const energyOptions = {
218238
OPTIONS.CHART_STACKED,
219239
OPTIONS.CHART_PROPORTION,
220240
OPTIONS.CHART_LINE,
221-
OPTIONS.CHART_CHANGE_SINCE_LINE
241+
OPTIONS.CHART_CHANGE_SINCE_LINE,
242+
OPTIONS.CHART_GROWTH_STACKED_AREA
222243
],
223244
curve: [
224245
OPTIONS.CHART_CURVE_SMOOTH,
@@ -337,13 +358,17 @@ export default {
337358
visHeight: 330,
338359
draggedHeight: 330,
339360
dragging: false,
340-
showDivider: false
361+
showDivider: false,
362+
363+
growthDataset: []
341364
}
342365
},
343366
344367
computed: {
345368
...mapGetters({
346369
percentContributionTo: 'percentContributionTo',
370+
fuelTechGroupName: 'fuelTechGroupName',
371+
347372
tabletBreak: 'app/tabletBreak',
348373
349374
hoverDomain: 'visInteract/hoverDomain',
@@ -381,6 +406,7 @@ export default {
381406
isTypeProportion: 'chartOptionsPowerEnergy/isTypeProportion',
382407
isTypeLine: 'chartOptionsPowerEnergy/isTypeLine',
383408
isTypeChangeSinceLine: 'chartOptionsPowerEnergy/isTypeChangeSinceLine',
409+
isTypeGrowthStackedArea: 'chartOptionsPowerEnergy/isTypeGrowthStackedArea',
384410
allowResize: 'regionEnergy/allowResize'
385411
}),
386412
@@ -434,7 +460,7 @@ export default {
434460
shouldConvertValue() {
435461
return (
436462
this.isTypeArea ||
437-
((this.isTypeLine || this.isTypeChangeSinceLine) &&
463+
((this.isTypeLine || this.isTypeChangeSinceLine || this.isTypeGrowthStackedArea) &&
438464
!this.isYAxisPercentage)
439465
)
440466
},
@@ -712,6 +738,7 @@ export default {
712738
this.$emit('selectedDataset', ds)
713739
return ds
714740
},
741+
715742
// yMin() {
716743
// const loadDomains = this.domains.filter((d) => d.category === LOAD)
717744
// if (loadDomains.length === 0) {
@@ -741,6 +768,61 @@ export default {
741768
// })
742769
// return max(dataset, d => d._stackedTotalMax)
743770
// },
771+
computedGrowthYMin() {
772+
let lowest = 0
773+
774+
const filteredDataset =
775+
this.zoomExtent.length > 0
776+
? this.growthDataset.filter(
777+
(d) =>
778+
d.time >= this.zoomExtent[0].getTime() &&
779+
d.time <= this.zoomExtent[1].getTime() - 1
780+
)
781+
: this.growthDataset
782+
783+
filteredDataset.forEach((d) => {
784+
let total = 0
785+
786+
this.powerEnergyDomains.forEach((domain) => {
787+
const value = d[domain.id] || 0
788+
total += value < 0 ? value : 0
789+
})
790+
791+
if (total < lowest) {
792+
lowest = total
793+
}
794+
})
795+
796+
return lowest
797+
},
798+
799+
computedGrowthYMax() {
800+
let highest = 0
801+
802+
const filteredDataset =
803+
this.zoomExtent.length > 0
804+
? this.growthDataset.filter(
805+
(d) =>
806+
d.time >= this.zoomExtent[0].getTime() &&
807+
d.time <= this.zoomExtent[1].getTime() - 1
808+
)
809+
: this.growthDataset
810+
811+
filteredDataset.forEach((d) => {
812+
let total = 0
813+
this.powerEnergyDomains.forEach((domain) => {
814+
const value = d[domain.id] || 0
815+
total += value > 0 ? value : 0
816+
})
817+
818+
if (total > highest) {
819+
highest = total
820+
}
821+
})
822+
823+
return highest
824+
},
825+
744826
computedYMin() {
745827
let lowest = 0
746828
@@ -858,7 +940,9 @@ export default {
858940
return null
859941
}
860942
const time = date.getTime()
861-
return this.dataset.find((d) => d.time === time)
943+
return this.isTypeGrowthStackedArea
944+
? this.growthDataset.find((d) => d.time === time)
945+
: this.dataset.find((d) => d.time === time)
862946
},
863947
hoverValue() {
864948
let value = null
@@ -905,6 +989,7 @@ export default {
905989
hoverTotal() {
906990
let total = 0
907991
let allNulls = true
992+
908993
if (this.hoverData) {
909994
this.domains.forEach((d) => {
910995
const value = this.hoverData[d.id]
@@ -941,13 +1026,59 @@ export default {
9411026
chartUnitPrefix() {
9421027
this.$emit('selectedDataset', this.dataset)
9431028
},
1029+
1030+
zoomExtent() {
1031+
if (this.isTypeGrowthStackedArea) {
1032+
this.updateGrowDataset()
1033+
}
1034+
},
1035+
1036+
filterPeriod() {
1037+
if (this.isTypeGrowthStackedArea) {
1038+
this.updateGrowDataset()
1039+
}
1040+
},
1041+
1042+
fuelTechGroupName() {
1043+
if (this.isTypeGrowthStackedArea) {
1044+
this.updateGrowDataset()
1045+
}
1046+
},
1047+
9441048
interval() {
9451049
this.handleTypeClick()
1050+
1051+
if (this.isTypeGrowthStackedArea) {
1052+
this.updateGrowDataset()
1053+
}
1054+
},
1055+
1056+
isTypeGrowthStackedArea(val) {
1057+
if (val) {
1058+
this.updateGrowDataset()
1059+
}
1060+
},
1061+
1062+
hiddenDomains() {
1063+
if (this.isTypeGrowthStackedArea) {
1064+
this.updateGrowDataset()
1065+
}
9461066
}
9471067
},
9481068
9491069
mounted() {
9501070
this.visHeight = this.chartHeight
1071+
1072+
if (this.isTypeGrowthStackedArea) {
1073+
this.updateGrowDataset()
1074+
}
1075+
1076+
if (!this.isEnergyType && this.isTypeGrowthStackedArea) {
1077+
this.$store.commit(
1078+
'chartOptionsPowerEnergy/chartType',
1079+
OPTIONS.CHART_STACKED
1080+
)
1081+
}
9511082
},
9521083
9531084
methods: {
@@ -960,6 +1091,12 @@ export default {
9601091
doUpdateTickFormats: 'visInteract/doUpdateTickFormats'
9611092
}),
9621093
1094+
updateGrowDataset() {
1095+
this.growthDataset = this.zoomExtent.length > 0 ? this.getGrowthDataset().filter((d) => {
1096+
return d.date >= this.zoomExtent[0] && d.date < this.zoomExtent[1]
1097+
}) : this.getGrowthDataset()
1098+
},
1099+
9631100
convertValue(value) {
9641101
return SI.convertValue(
9651102
this.chartUnitPrefix,
@@ -1048,6 +1185,24 @@ export default {
10481185
return newDataset
10491186
},
10501187
1188+
getGrowthDataset() {
1189+
let compareIndex = 1
1190+
1191+
if (this.isRollingSumRange) {
1192+
if (this.interval === 'Season' || this.interval === 'Quarter') {
1193+
compareIndex = 4
1194+
} else if (this.interval === 'Half Year') {
1195+
compareIndex = 2
1196+
}
1197+
}
1198+
1199+
const dataset = transformToGrowthTimeSeries(this.powerEnergyDataset, this.domains, compareIndex)
1200+
1201+
this.handleTypeClick()
1202+
1203+
return dataset
1204+
},
1205+
10511206
handleDomainHover(domain) {
10521207
this.setHoverDomain(domain)
10531208
},

components/Charts/PowerEnergyChartOptions.vue

+8-4
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export default {
155155
type: Boolean,
156156
default: false
157157
},
158+
isTypeGrowthStackedArea: {
159+
type: Boolean,
160+
default: false
161+
},
158162
isYAxisAbsolute: {
159163
type: Boolean,
160164
default: false
@@ -246,7 +250,7 @@ export default {
246250
return (
247251
!this.isRenewableLineOnly &&
248252
(this.isTypeArea ||
249-
((this.isTypeLine || this.isTypeChangeSinceLine) &&
253+
((this.isTypeLine || this.isTypeChangeSinceLine || this.isTypeGrowthStackedArea) &&
250254
!this.isYAxisPercentage))
251255
)
252256
},
@@ -279,8 +283,8 @@ export default {
279283
let options = []
280284
if (this.isEnergyType) {
281285
options = this.energyOptions
282-
if (this.isTypeLine || this.isTypeChangeSinceLine) {
283-
if (this.isTypeChangeSinceLine) {
286+
if (this.isTypeLine || this.isTypeChangeSinceLine || this.isTypeGrowthStackedArea) {
287+
if (this.isTypeChangeSinceLine || this.isTypeGrowthStackedArea) {
284288
options.yAxis = [
285289
OPTIONS.CHART_YAXIS_ENERGY,
286290
OPTIONS.CHART_YAXIS_AVERAGE_POWER
@@ -427,7 +431,7 @@ export default {
427431
if (!this.isRenewableLineOnly) {
428432
if (
429433
this.isTypeArea ||
430-
((this.isTypeLine || this.isTypeChangeSinceLine) &&
434+
((this.isTypeLine || this.isTypeChangeSinceLine || this.isTypeGrowthStackedArea) &&
431435
!this.isYAxisPercentage)
432436
) {
433437
const updatedPrefix = this.togglePrefix(this.chartDisplayPrefix)

components/Vis/StackedArea.vue

+10
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,16 @@ export default {
568568
},
569569
570570
watch: {
571+
yMin() {
572+
this.update()
573+
},
574+
yMax() {
575+
this.update()
576+
},
577+
useOffsetDiverge() {
578+
this.setup()
579+
},
580+
571581
showXAxis() {
572582
this.handleResize()
573583
},

constants/chart-options.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const CHART_STACKED = 'area'
33
export const CHART_PROPORTION = 'proportion'
44
export const CHART_LINE = 'line'
55
export const CHART_CHANGE_SINCE_LINE = 'change-since-line'
6+
export const CHART_GROWTH_STACKED_AREA = 'growth-stacked-area'
67

78
export const CHART_CURVE_SMOOTH = 'smooth'
89
export const CHART_CURVE_STEP = 'step'
@@ -24,6 +25,7 @@ CHART_LABEL[CHART_STACKED] = 'Stacked'
2425
CHART_LABEL[CHART_PROPORTION] = 'Proportion'
2526
CHART_LABEL[CHART_LINE] = 'Line'
2627
CHART_LABEL[CHART_CHANGE_SINCE_LINE] = 'Change'
28+
CHART_LABEL[CHART_GROWTH_STACKED_AREA] = 'Growth'
2729
CHART_LABEL[CHART_CURVE_SMOOTH] = 'Smooth'
2830
CHART_LABEL[CHART_CURVE_STEP] = 'Step'
2931
CHART_LABEL[CHART_CURVE_STRAIGHT] = 'Straight'

0 commit comments

Comments
 (0)