@bino-bi/bn-template-engine 1.0.0-next.61 → 1.0.0-next.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
- package/dist/bn-template-engine/{p-ac917d72.entry.js → p-7b74696e.entry.js} +1 -1
- package/dist/cjs/bn-annotation-layer_30.cjs.entry.js +688 -266
- package/dist/cjs/bn-template-engine.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/bn-chart-time/bn-chart-time-renderer/bn-chart-time-renderer.js +8 -8
- package/dist/collection/components/bn-chart-time/bn-chart-time.js +115 -34
- package/dist/collection/components/bn-chart-time/utils/TimeChart.js +534 -221
- package/dist/collection/components/bn-chart-time/utils/helper/ElementPositions.js +23 -1
- package/dist/collection/components/bn-chart-time/utils/model/TimeChartComponentConfig.js +15 -8
- package/dist/components/bn-chart-time-renderer.js +1 -1
- package/dist/components/bn-chart-time.js +1 -1
- package/dist/components/p-C3-kXJUZ.js +1 -0
- package/dist/esm/bn-annotation-layer_30.entry.js +688 -266
- package/dist/esm/bn-template-engine.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/types/components/bn-chart-time/bn-chart-time-renderer/bn-chart-time-renderer.d.ts +2 -2
- package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +29 -16
- package/dist/types/components/bn-chart-time/utils/TimeChart.d.ts +63 -30
- package/dist/types/components/bn-chart-time/utils/helper/ElementPositions.d.ts +8 -0
- package/dist/types/components/bn-chart-time/utils/model/TimeChartComponentConfig.d.ts +16 -7
- package/dist/types/components.d.ts +8 -8
- package/package.json +1 -1
- package/dist/components/p-D-JwLFMJ.js +0 -1
|
@@ -107,8 +107,9 @@ export class TimeChart {
|
|
|
107
107
|
this.lastScenarios = [];
|
|
108
108
|
this.axisLabelsStep = 1;
|
|
109
109
|
this.scalingIndicator = 0;
|
|
110
|
-
this.
|
|
111
|
-
this.
|
|
110
|
+
this.totals = null;
|
|
111
|
+
this.totalColumns = [];
|
|
112
|
+
this.totalVariances = [];
|
|
112
113
|
this.highestColumnDataPointValue = new DataPoint(0, "default", 0, Scenario.NEU);
|
|
113
114
|
this.highestPeriodVarianceDataPointValue = new DataPoint(0, "default", 0, Scenario.NEU);
|
|
114
115
|
this.scenarioSwitch = false;
|
|
@@ -211,7 +212,7 @@ export class TimeChart {
|
|
|
211
212
|
this.intervalSpanLimit = config.intervalSpanLimit;
|
|
212
213
|
this.axisLabelsStep = (_a = config.axisLabelsStep) !== null && _a !== void 0 ? _a : 1;
|
|
213
214
|
this.scalingIndicator = (_b = config.scalingIndicator) !== null && _b !== void 0 ? _b : 0;
|
|
214
|
-
this.
|
|
215
|
+
this.totals = (_c = config.totals) !== null && _c !== void 0 ? _c : null;
|
|
215
216
|
this.scenarioSwitch = (_d = config.scenarioSwitch) !== null && _d !== void 0 ? _d : false;
|
|
216
217
|
this.axisTitlePosition = (_e = config.axisTitlePosition) !== null && _e !== void 0 ? _e : "left";
|
|
217
218
|
this.dateInterval = this.findDateInterval(config.dateInterval);
|
|
@@ -263,13 +264,16 @@ export class TimeChart {
|
|
|
263
264
|
this.highestColumnDataPointValue = this.highestDataPointValue;
|
|
264
265
|
// the highest period variance: a break mark is for a variance of a period, the total has its own cut
|
|
265
266
|
this.highestPeriodVarianceDataPointValue = this.highestVarianceDataPointValue;
|
|
266
|
-
this.
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
this.totalColumns = this.computeTotalColumns();
|
|
268
|
+
this.totalVariances = this.computeTotalVariances();
|
|
269
|
+
for (const point of this.totalVariances) {
|
|
270
|
+
if (point == null || !Number.isFinite(point.value))
|
|
271
|
+
continue;
|
|
272
|
+
if (point.value > Number(this.highestVarianceDataPointValue.value)) {
|
|
273
|
+
this.highestVarianceDataPointValue = point;
|
|
270
274
|
}
|
|
271
|
-
if (
|
|
272
|
-
this.smallestVarianceDataPointValue =
|
|
275
|
+
if (point.value < Number(this.smallestVarianceDataPointValue.value)) {
|
|
276
|
+
this.smallestVarianceDataPointValue = point;
|
|
273
277
|
}
|
|
274
278
|
}
|
|
275
279
|
if (this.hasScalingIndicator() && this.scalingIndicator > Number(this.highestDataPointValue.value)) {
|
|
@@ -278,7 +282,7 @@ export class TimeChart {
|
|
|
278
282
|
this.highestDataPointValue = new DataPoint(this.scalingIndicator, scenario, this.pixelPerUnit, variance);
|
|
279
283
|
}
|
|
280
284
|
// the total column has its own scale: it counts for the height with the pixels it needs
|
|
281
|
-
const totalHeight = this.isVarianceChart() ? 0 : this.
|
|
285
|
+
const totalHeight = this.isVarianceChart() ? 0 : this.totalsHeight();
|
|
282
286
|
if (totalHeight > this.highestDataPointValue.getScaledUnit() && this.pixelPerUnit > 0) {
|
|
283
287
|
const { scenario, variance } = this.highestDataPointValue;
|
|
284
288
|
this.highestDataPointValue = new DataPoint(totalHeight / this.pixelPerUnit, scenario, this.pixelPerUnit, variance);
|
|
@@ -398,8 +402,8 @@ export class TimeChart {
|
|
|
398
402
|
}).width;
|
|
399
403
|
indicatorEnd = this.scalingIndicatorLabelX() + textWidth + this.styles.padding.right;
|
|
400
404
|
}
|
|
401
|
-
const totalEnd = this.
|
|
402
|
-
? this.
|
|
405
|
+
const totalEnd = this.hasEndTotal()
|
|
406
|
+
? this.totalGeometry(0).right + this.endTotalTextWidth() + this.styles.padding.right
|
|
403
407
|
: 0;
|
|
404
408
|
return Math.max(axisEnd + labelBuffer, bboxTotal, titleEnd, legendEnd, indicatorEnd, totalEnd);
|
|
405
409
|
}
|
|
@@ -639,9 +643,9 @@ export class TimeChart {
|
|
|
639
643
|
const points = this.variancesDataModel
|
|
640
644
|
.filter((entry) => entry.type === VarianceType.RELATIVE)
|
|
641
645
|
.map((entry) => entry.scenario1);
|
|
642
|
-
if (points.length > 0
|
|
643
|
-
// the
|
|
644
|
-
points.push(this.
|
|
646
|
+
if (points.length > 0) {
|
|
647
|
+
// the pins of the total columns are pins of the row
|
|
648
|
+
points.push(...this.totalVariances.filter((point) => point != null));
|
|
645
649
|
}
|
|
646
650
|
if (points.length === 0 || !points.some((point) => point.isClipped())) {
|
|
647
651
|
return;
|
|
@@ -741,8 +745,9 @@ export class TimeChart {
|
|
|
741
745
|
}
|
|
742
746
|
if (this.isVarianceChart()) {
|
|
743
747
|
this.drawVarianceScenario(this.variancesDataModel, svgContainer);
|
|
748
|
+
// before the axis: the line of a scenario switch runs over the full height of the row
|
|
749
|
+
this.drawTotalVariances(svgContainer);
|
|
744
750
|
this.drawAxisAndLabels(this.variancesDataModel, svgContainer);
|
|
745
|
-
this.drawTotalVariance(svgContainer);
|
|
746
751
|
}
|
|
747
752
|
else if (this.stackConfig != null) {
|
|
748
753
|
const effectiveChartMode = this.determineEffectiveChartMode();
|
|
@@ -768,17 +773,19 @@ export class TimeChart {
|
|
|
768
773
|
this.drawOverlayLayer(this.dataModel, svgContainer);
|
|
769
774
|
this.drawAxisAndLabels(this.dataModel, svgContainer);
|
|
770
775
|
this.drawScalingIndicator(svgContainer);
|
|
771
|
-
this.
|
|
776
|
+
this.drawTotalColumns(svgContainer);
|
|
772
777
|
}
|
|
773
778
|
}
|
|
774
779
|
}
|
|
775
780
|
/** True for a chart that draws the scaling indicator: columns or an absolute stack, no variance chart. */
|
|
776
781
|
hasScalingIndicator() {
|
|
777
|
-
var _a;
|
|
782
|
+
var _a, _b;
|
|
778
783
|
return (this.scalingIndicator > 0 &&
|
|
779
784
|
!this.isVarianceChart() &&
|
|
785
|
+
// the segment of a variance that is not valid has no variance model, but it is no base chart
|
|
786
|
+
((_a = this.configVariances) !== null && _a !== void 0 ? _a : []).every((variance) => !variance) &&
|
|
780
787
|
this.determineEffectiveChartMode() === ChartMode.BAR &&
|
|
781
|
-
((
|
|
788
|
+
((_b = this.stackConfig) === null || _b === void 0 ? void 0 : _b.mode) !== StackMode.RELATIVE);
|
|
782
789
|
}
|
|
783
790
|
/** The value of the scaling indicator, printed like a value label. */
|
|
784
791
|
scalingIndicatorText() {
|
|
@@ -796,7 +803,11 @@ export class TimeChart {
|
|
|
796
803
|
scalingIndicatorLabelX() {
|
|
797
804
|
const gap = this.position.spacings.labelToColumn;
|
|
798
805
|
const half = this.position.getColumnWidth() / 2 + this.position.spacings.scenarioOffset;
|
|
799
|
-
|
|
806
|
+
let right = this.position.getColumnCenterPositionX(Math.max(0, this.dataModel.length - 1)) + half;
|
|
807
|
+
if (this.hasTotals() && !this.hasEndTotal()) {
|
|
808
|
+
// a total stands behind the last period: the value goes behind it
|
|
809
|
+
right = Math.max(right, this.totalGeometry(this.totalColumns.length - 1).right);
|
|
810
|
+
}
|
|
800
811
|
const legendWidth = this.legendWidth("right");
|
|
801
812
|
return right + gap + (legendWidth > 0 ? legendWidth + gap : 0);
|
|
802
813
|
}
|
|
@@ -829,154 +840,431 @@ export class TimeChart {
|
|
|
829
840
|
const { left, right, height } = band;
|
|
830
841
|
const axisY = this.position.getColumnPositionY();
|
|
831
842
|
const group = svgContainer.group().id("ScalingIndicator");
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
.
|
|
836
|
-
|
|
843
|
+
// totals on the axis have their own band at their own scale: the band of the periods leaves their place free
|
|
844
|
+
const half = this.position.getColumnWidth() / 2 + this.position.spacings.scenarioOffset;
|
|
845
|
+
const runs = this.hasTotals() && !this.hasEndTotal()
|
|
846
|
+
? this.totalRuns().map((run) => ({
|
|
847
|
+
left: this.position.getColumnCenterPositionX(run.from) - half,
|
|
848
|
+
right: this.position.getColumnCenterPositionX(run.to) + half,
|
|
849
|
+
}))
|
|
850
|
+
: [{ left, right }];
|
|
851
|
+
for (const run of runs) {
|
|
852
|
+
group
|
|
853
|
+
.rect(run.right - run.left, height)
|
|
854
|
+
.x(run.left)
|
|
855
|
+
.y(axisY - height)
|
|
856
|
+
.fill(SCALING_INDICATOR_FILL);
|
|
857
|
+
}
|
|
837
858
|
group.back();
|
|
838
859
|
new Label(svgContainer.group().id("ScalingIndicatorLabel"), this.scalingIndicatorLabelX(), axisY - height, "SCALING_INDICATOR", this.scalingIndicatorText(), this.styles, HookLocation.Center, HookLocation.Left).forceStringTypeDraw();
|
|
839
860
|
}
|
|
840
|
-
/** Where a title at the right starts when a total column stands
|
|
861
|
+
/** Where a title at the right starts when a total column stands at the end: behind the column and its texts. */
|
|
841
862
|
rightTitleX() {
|
|
842
|
-
if (!this.
|
|
863
|
+
if (!this.hasEndTotal()) {
|
|
843
864
|
return undefined;
|
|
844
865
|
}
|
|
845
|
-
return this.
|
|
866
|
+
return this.totalGeometry(0).right + this.endTotalTextWidth() + this.position.spacings.labelToColumn;
|
|
846
867
|
}
|
|
847
|
-
/** True for a chart with
|
|
848
|
-
|
|
849
|
-
return this.
|
|
868
|
+
/** True for a chart with total columns. */
|
|
869
|
+
hasTotals() {
|
|
870
|
+
return this.totalColumns.length > 0;
|
|
850
871
|
}
|
|
851
|
-
/**
|
|
852
|
-
|
|
872
|
+
/** True for the one total column of `by: all`: it stands apart at the end, with its own axis and its names. */
|
|
873
|
+
hasEndTotal() {
|
|
874
|
+
return this.hasTotals() && this.totals.by === "all";
|
|
875
|
+
}
|
|
876
|
+
/** The index of a total column for the positions: the totals follow the periods. */
|
|
877
|
+
totalIndex(total) {
|
|
878
|
+
// the index behind the last period stays what it is without totals: the end of the overlay lines
|
|
879
|
+
return this.dataModel.length + 1 + total;
|
|
880
|
+
}
|
|
881
|
+
/** Place of a total column. `left` and `right` are the ends of its band, and of its own axis at the end. */
|
|
882
|
+
totalGeometry(total) {
|
|
853
883
|
var _a, _b;
|
|
854
|
-
const
|
|
855
|
-
const
|
|
856
|
-
// one period of room between the last period and the column: the axis of the periods ends before it
|
|
857
|
-
const center = this.position.getColumnCenterPositionX(this.dataModel.length + 1) + (width - columnWidth) / 2;
|
|
884
|
+
const width = this.position.getColumnWidth() * ((_b = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 1);
|
|
885
|
+
const center = this.position.getColumnCenterPositionX(this.totalIndex(total));
|
|
858
886
|
const margin = this.position.spacings.scenarioOffset;
|
|
859
|
-
|
|
860
|
-
// Every tier of the chart knows the indicator, so the column has the same place in all of them.
|
|
861
|
-
const x = center + (this.scalingIndicator > 0 ? this.scalingIndicatorTextWidth() + margin : 0);
|
|
862
|
-
return { center: x, width, left: x - width / 2 - 2 * margin, right: x + width / 2 + margin };
|
|
887
|
+
return { center, width, left: center - width / 2 - 2 * margin, right: center + width / 2 + margin };
|
|
863
888
|
}
|
|
864
889
|
/**
|
|
865
|
-
*
|
|
866
|
-
*
|
|
867
|
-
*
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
* show a negative part, so such a chart has no total column at all.
|
|
890
|
+
* The places of the periods and of the total columns on the axis, in category
|
|
891
|
+
* widths, and the number of places the axis of the periods covers. A total of
|
|
892
|
+
* `by: all` stands one period behind the last one, with its own axis. The
|
|
893
|
+
* other totals stand right behind the last period of their group, and the
|
|
894
|
+
* periods after them move on.
|
|
871
895
|
*/
|
|
872
|
-
|
|
873
|
-
var _a;
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
896
|
+
totalSlots(columnWidth, categoryWidth, fontSize, scenarioOffset) {
|
|
897
|
+
var _a, _b, _c;
|
|
898
|
+
const count = this.dataModel.length;
|
|
899
|
+
const extra = categoryWidth > 0 ? ((((_b = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 1) - 1) * columnWidth) / categoryWidth : 0;
|
|
900
|
+
const slots = [];
|
|
901
|
+
const totals = [];
|
|
902
|
+
if (this.totals.by === "all") {
|
|
903
|
+
for (let index = 0; index < count; index++)
|
|
904
|
+
slots.push(index);
|
|
905
|
+
// the value of the band of the periods stands in the gap: the column moves right by its width.
|
|
906
|
+
// Every tier of the chart knows the indicator, so the column has the same place in all of them.
|
|
907
|
+
const shift = this.scalingIndicator > 0 && categoryWidth > 0
|
|
908
|
+
? (this.scalingIndicatorTextWidth() + scenarioOffset * fontSize) / (categoryWidth * fontSize)
|
|
909
|
+
: 0;
|
|
910
|
+
totals.push(count + 1 + extra / 2 + shift);
|
|
911
|
+
return { slots: [...slots, count, ...totals], axisColumns: count };
|
|
879
912
|
}
|
|
913
|
+
// the names of the scenarios stand right of the last period: its total keeps one place of room for them.
|
|
914
|
+
// A series with a scenario switch has its names under the axis.
|
|
880
915
|
const followers = this.followerSlots();
|
|
881
|
-
const
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
916
|
+
const lastRow = this.dataModel[count - 1];
|
|
917
|
+
const lastIsFollower = followers.includes((_c = this.visibleSlot(lastRow, followers)) !== null && _c !== void 0 ? _c : "scenario1");
|
|
918
|
+
// the second marker prints its name there too
|
|
919
|
+
const markerName = !followers.includes("scenario4") && this.dataModel.some((row) => TimeChart.hasValue(row.scenario4));
|
|
920
|
+
const namesRoom = lastIsFollower && !markerName ? 0 : 1;
|
|
921
|
+
let offset = 0;
|
|
922
|
+
let next = 0;
|
|
923
|
+
for (let index = 0; index < count; index++) {
|
|
924
|
+
slots.push(index + offset);
|
|
925
|
+
const group = this.totalColumns[next];
|
|
926
|
+
if (group != null && group.to === index) {
|
|
927
|
+
const room = index === count - 1 ? namesRoom : 0;
|
|
928
|
+
totals.push(index + offset + room + 1 + extra / 2);
|
|
929
|
+
offset += room + 1 + extra;
|
|
930
|
+
next++;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
return { slots: [...slots, count + offset, ...totals], axisColumns: count + offset };
|
|
934
|
+
}
|
|
935
|
+
/** The runs of periods between the total columns on the axis: each ends with the last period of a total, or of the chart. */
|
|
936
|
+
totalRuns() {
|
|
937
|
+
const runs = [];
|
|
938
|
+
let from = 0;
|
|
939
|
+
for (const column of this.totalColumns) {
|
|
940
|
+
runs.push({ from, to: column.to });
|
|
941
|
+
from = column.to + 1;
|
|
890
942
|
}
|
|
891
|
-
|
|
892
|
-
|
|
943
|
+
if (from < this.dataModel.length) {
|
|
944
|
+
runs.push({ from, to: this.dataModel.length - 1 });
|
|
945
|
+
}
|
|
946
|
+
return runs;
|
|
947
|
+
}
|
|
948
|
+
/** The start of the group of a date, null for one group over all periods. */
|
|
949
|
+
totalGroupStart(date) {
|
|
950
|
+
var _a, _b;
|
|
951
|
+
const by = (_b = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.by) !== null && _b !== void 0 ? _b : "all";
|
|
952
|
+
if (by === "all" || date == null || !date.isValid) {
|
|
893
953
|
return null;
|
|
894
954
|
}
|
|
895
|
-
|
|
955
|
+
return date.startOf(by);
|
|
956
|
+
}
|
|
957
|
+
/** The name of a total column under the axis: the text of the config at the end, else the name of its period. */
|
|
958
|
+
totalLabel(start) {
|
|
959
|
+
var _a, _b;
|
|
960
|
+
if (start == null) {
|
|
961
|
+
return (_b = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : "";
|
|
962
|
+
}
|
|
963
|
+
const interval = {
|
|
964
|
+
year: DateDistance.YEAR,
|
|
965
|
+
quarter: DateDistance.QUARTER,
|
|
966
|
+
month: DateDistance.MONTH,
|
|
967
|
+
week: DateDistance.WEEK,
|
|
968
|
+
}[this.totals.by];
|
|
969
|
+
return this.createDateFactory().getShortDateString(start, interval);
|
|
970
|
+
}
|
|
971
|
+
/** The scenarios of the series: the first one, and the ones that follow it. */
|
|
972
|
+
seriesSlotKeys() {
|
|
973
|
+
return ["scenario1", ...this.followerSlots()];
|
|
974
|
+
}
|
|
975
|
+
/** The slot of the reference of a total: the first scenario with values that is not part of the series. */
|
|
976
|
+
referenceSlot() {
|
|
977
|
+
const followers = this.followerSlots();
|
|
896
978
|
for (const slot of ["scenario2", "scenario3", "scenario4"]) {
|
|
897
979
|
if (followers.includes(slot))
|
|
898
980
|
continue;
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
reference = {
|
|
902
|
-
scenario: values[0].scenario,
|
|
903
|
-
value: values.reduce((sum, point) => sum + point.value, 0),
|
|
904
|
-
};
|
|
905
|
-
break;
|
|
981
|
+
if (this.dataModel.some((row) => { var _a; return Number.isFinite((_a = row[slot]) === null || _a === void 0 ? void 0 : _a.value); })) {
|
|
982
|
+
return slot;
|
|
906
983
|
}
|
|
907
984
|
}
|
|
908
|
-
return
|
|
909
|
-
parts,
|
|
910
|
-
height: parts.reduce((sum, part) => sum + part.value, 0),
|
|
911
|
-
total: parts.reduce((sum, part) => sum + part.value, 0),
|
|
912
|
-
reference,
|
|
913
|
-
};
|
|
985
|
+
return null;
|
|
914
986
|
}
|
|
915
|
-
/**
|
|
916
|
-
|
|
987
|
+
/** The look of one column for several scenarios: a forecast wins, then a plan, then the first one. */
|
|
988
|
+
mixedScenario(scenarios) {
|
|
917
989
|
var _a, _b;
|
|
918
|
-
|
|
919
|
-
|
|
990
|
+
return ((_b = (_a = scenarios.find((scenario) => getScenarioPrefix(scenario) === "fc")) !== null && _a !== void 0 ? _a : scenarios.find((scenario) => getScenarioPrefix(scenario) === "pl")) !== null && _b !== void 0 ? _b : scenarios[0]);
|
|
991
|
+
}
|
|
992
|
+
/** The rows of the totals dataset, one per group, with the scenario columns added up. */
|
|
993
|
+
totalDatasetRows() {
|
|
994
|
+
var _a, _b, _c, _d;
|
|
995
|
+
const name = (_a = this.totals) === null || _a === void 0 ? void 0 : _a.dataset;
|
|
996
|
+
if (!name) {
|
|
997
|
+
return null;
|
|
998
|
+
}
|
|
999
|
+
const from = sourceExpr(this.db, name, "");
|
|
1000
|
+
const rows = new Map();
|
|
1001
|
+
if (!from) {
|
|
1002
|
+
return rows;
|
|
1003
|
+
}
|
|
1004
|
+
let result;
|
|
1005
|
+
try {
|
|
1006
|
+
result = this.db.exec(`SELECT * FROM ${from}`);
|
|
1007
|
+
}
|
|
1008
|
+
catch (e) {
|
|
1009
|
+
this.failQuery(e);
|
|
1010
|
+
return rows;
|
|
1011
|
+
}
|
|
1012
|
+
for (const row of result) {
|
|
1013
|
+
const date = TimeChart.parseDate(row.date);
|
|
1014
|
+
const start = date ? this.totalGroupStart(date) : null;
|
|
1015
|
+
const key = start ? ((_b = start.toISODate()) !== null && _b !== void 0 ? _b : "") : "";
|
|
1016
|
+
if (this.totals.by !== "all" && key === "")
|
|
1017
|
+
continue;
|
|
1018
|
+
const sums = (_c = rows.get(key)) !== null && _c !== void 0 ? _c : {};
|
|
1019
|
+
for (const [column, raw] of Object.entries(row)) {
|
|
1020
|
+
// a value can come as a text, like in the dataset of the chart
|
|
1021
|
+
const value = typeof raw === "string" && raw.trim() !== "" ? Number(raw) : raw;
|
|
1022
|
+
if (column !== "date" && typeof value === "number" && Number.isFinite(value)) {
|
|
1023
|
+
sums[column] = ((_d = sums[column]) !== null && _d !== void 0 ? _d : 0) + value;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
rows.set(key, sums);
|
|
1027
|
+
}
|
|
1028
|
+
return rows;
|
|
1029
|
+
}
|
|
1030
|
+
static parseDate(value) {
|
|
1031
|
+
if (value instanceof Date) {
|
|
1032
|
+
return DateTime.fromJSDate(value, { zone: "utc" });
|
|
1033
|
+
}
|
|
1034
|
+
if (typeof value === "string") {
|
|
1035
|
+
const date = DateTime.fromISO(value, { zone: "utc" });
|
|
1036
|
+
return date.isValid ? date : null;
|
|
1037
|
+
}
|
|
1038
|
+
if (typeof value === "number") {
|
|
1039
|
+
return DateTime.fromMillis(value, { zone: "utc" });
|
|
1040
|
+
}
|
|
1041
|
+
return null;
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* The total columns of the chart. A group is the run of periods of one year,
|
|
1045
|
+
* quarter, month or week, or all periods. With `sum` a column stacks one part
|
|
1046
|
+
* per scenario of the series, else it is one column in the look of the
|
|
1047
|
+
* scenarios in it. The first other scenario is the reference behind. The
|
|
1048
|
+
* variance rows read the same list, for the same answer to "are there
|
|
1049
|
+
* totals". Empty without the config, with a stack, in line mode, and when a
|
|
1050
|
+
* part is not positive: a column cannot show that, so the chart has none.
|
|
1051
|
+
*/
|
|
1052
|
+
computeTotalColumns() {
|
|
1053
|
+
var _a, _b, _c, _d, _e;
|
|
1054
|
+
if (this.totals == null ||
|
|
1055
|
+
this.stackConfig != null ||
|
|
1056
|
+
this.dataModel.length === 0 ||
|
|
1057
|
+
this.determineEffectiveChartMode() !== ChartMode.BAR) {
|
|
1058
|
+
return [];
|
|
1059
|
+
}
|
|
1060
|
+
const followers = this.followerSlots();
|
|
1061
|
+
const series = this.seriesSlotKeys();
|
|
1062
|
+
const referenceSlot = this.referenceSlot();
|
|
1063
|
+
const referenceScenario = referenceSlot
|
|
1064
|
+
? (_a = this.dataModel.find((row) => { var _a; return ((_a = row[referenceSlot]) === null || _a === void 0 ? void 0 : _a.scenario) != null; })) === null || _a === void 0 ? void 0 : _a[referenceSlot].scenario
|
|
1065
|
+
: null;
|
|
1066
|
+
const fromData = this.totalDatasetRows();
|
|
1067
|
+
// the groups: runs of periods with the same start
|
|
1068
|
+
const groups = [];
|
|
1069
|
+
this.dataModel.forEach((row, index) => {
|
|
1070
|
+
const start = this.totalGroupStart(row.date);
|
|
1071
|
+
const last = groups[groups.length - 1];
|
|
1072
|
+
if (last != null && (start == null || (last.start != null && +last.start === +start))) {
|
|
1073
|
+
last.to = index;
|
|
1074
|
+
}
|
|
1075
|
+
else {
|
|
1076
|
+
groups.push({ from: index, to: index, start });
|
|
1077
|
+
}
|
|
1078
|
+
});
|
|
1079
|
+
// a total per period would repeat every column: `by` is not coarser than the periods of the chart
|
|
1080
|
+
if (this.totals.by !== "all" && groups.length === this.dataModel.length && groups.length > 1) {
|
|
1081
|
+
return [];
|
|
1082
|
+
}
|
|
1083
|
+
const columns = [];
|
|
1084
|
+
for (const group of groups) {
|
|
1085
|
+
const rows = this.dataModel.slice(group.from, group.to + 1);
|
|
1086
|
+
let parts = [];
|
|
1087
|
+
let reference = null;
|
|
1088
|
+
let counted = [];
|
|
1089
|
+
if (fromData != null) {
|
|
1090
|
+
// the values as the dataset gives them: one part per scenario of the series
|
|
1091
|
+
const data = (_c = fromData.get(group.start ? ((_b = group.start.toISODate()) !== null && _b !== void 0 ? _b : "") : "")) !== null && _c !== void 0 ? _c : {};
|
|
1092
|
+
for (const slot of series) {
|
|
1093
|
+
const scenario = (_d = this.dataModel.find((row) => { var _a; return ((_a = row[slot]) === null || _a === void 0 ? void 0 : _a.scenario) != null; })) === null || _d === void 0 ? void 0 : _d[slot].scenario;
|
|
1094
|
+
// a 0 is a scenario without a value in this total
|
|
1095
|
+
if (scenario != null && Number.isFinite(data[scenario]) && data[scenario] !== 0) {
|
|
1096
|
+
parts.push({ scenario, value: data[scenario] });
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
if (referenceScenario != null && Number.isFinite(data[referenceScenario])) {
|
|
1100
|
+
reference = { scenario: referenceScenario, value: data[referenceScenario] };
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
else {
|
|
1104
|
+
// the periods where the series has a value. The reference counts in the same periods only,
|
|
1105
|
+
// as the variance of the total does: else the two would not tell the same.
|
|
1106
|
+
const used = rows.filter((row) => {
|
|
1107
|
+
var _a;
|
|
1108
|
+
const slot = this.visibleSlot(row, followers);
|
|
1109
|
+
return slot != null && Number.isFinite((_a = row[slot]) === null || _a === void 0 ? void 0 : _a.value);
|
|
1110
|
+
});
|
|
1111
|
+
counted = used.map((row) => this.dataModel.indexOf(row));
|
|
1112
|
+
const visible = used.map((row) => row[this.visibleSlot(row, followers)]);
|
|
1113
|
+
// with `last` the one period that gives the value counts. A reference with a gap in
|
|
1114
|
+
// the counted periods is no reference: half a sum would stand against a full one.
|
|
1115
|
+
const referenceRows = this.totals.aggregation === "last" ? used.slice(-1) : used;
|
|
1116
|
+
const found = referenceSlot
|
|
1117
|
+
? referenceRows.map((row) => row[referenceSlot]).filter((point) => Number.isFinite(point === null || point === void 0 ? void 0 : point.value))
|
|
1118
|
+
: [];
|
|
1119
|
+
const references = found.length === referenceRows.length ? found : [];
|
|
1120
|
+
const sum = (points) => points.reduce((total, point) => total + point.value, 0);
|
|
1121
|
+
if (this.totals.aggregation === "sum") {
|
|
1122
|
+
const sums = new Map();
|
|
1123
|
+
for (const point of visible) {
|
|
1124
|
+
sums.set(point.scenario, ((_e = sums.get(point.scenario)) !== null && _e !== void 0 ? _e : 0) + point.value);
|
|
1125
|
+
}
|
|
1126
|
+
parts = [...sums.entries()].map(([scenario, value]) => ({ scenario, value }));
|
|
1127
|
+
if (references.length > 0) {
|
|
1128
|
+
reference = { scenario: referenceScenario, value: sum(references) };
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
else if (visible.length > 0) {
|
|
1132
|
+
const last = this.totals.aggregation === "last";
|
|
1133
|
+
parts = [
|
|
1134
|
+
{
|
|
1135
|
+
scenario: last
|
|
1136
|
+
? visible[visible.length - 1].scenario
|
|
1137
|
+
: this.mixedScenario(visible.map((point) => point.scenario)),
|
|
1138
|
+
value: last ? visible[visible.length - 1].value : sum(visible) / visible.length,
|
|
1139
|
+
},
|
|
1140
|
+
];
|
|
1141
|
+
if (references.length > 0) {
|
|
1142
|
+
reference = {
|
|
1143
|
+
scenario: referenceScenario,
|
|
1144
|
+
value: last ? references[references.length - 1].value : sum(references) / references.length,
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
if (parts.length === 0) {
|
|
1150
|
+
// a group without a value of the series has no total, the others keep theirs
|
|
1151
|
+
continue;
|
|
1152
|
+
}
|
|
1153
|
+
if (parts.some((part) => !(part.value > 0))) {
|
|
1154
|
+
return [];
|
|
1155
|
+
}
|
|
1156
|
+
const total = parts.reduce((sum, part) => sum + part.value, 0);
|
|
1157
|
+
columns.push(Object.assign(Object.assign({}, group), { label: this.totalLabel(group.start), parts, total, reference, counted }));
|
|
1158
|
+
}
|
|
1159
|
+
return columns;
|
|
1160
|
+
}
|
|
1161
|
+
/** Height of the highest total column in pixels: its parts, its reference and its band of the scaling indicator. */
|
|
1162
|
+
totalsHeight() {
|
|
1163
|
+
if (!this.hasTotals()) {
|
|
920
1164
|
return 0;
|
|
921
1165
|
}
|
|
922
1166
|
const band = this.hasScalingIndicator() ? this.scalingIndicator : 0;
|
|
923
|
-
return Math.max(total
|
|
1167
|
+
const units = Math.max(...this.totalColumns.map((column) => { var _a, _b; return Math.max(column.total, (_b = (_a = column.reference) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0); }));
|
|
1168
|
+
return Math.max(units, band) * this.totals.pixelPerUnit;
|
|
924
1169
|
}
|
|
925
1170
|
/**
|
|
926
|
-
* The
|
|
927
|
-
*
|
|
928
|
-
*
|
|
1171
|
+
* The variances of the total columns in a variance chart, one per column:
|
|
1172
|
+
* the series against the reference, put together the way the total is. With
|
|
1173
|
+
* a dataset the values come from its row. A total takes the notation of the
|
|
1174
|
+
* forecast when a forecast is part of it.
|
|
929
1175
|
*/
|
|
930
|
-
|
|
931
|
-
var _a, _b
|
|
932
|
-
if (!this.
|
|
933
|
-
return
|
|
1176
|
+
computeTotalVariances() {
|
|
1177
|
+
var _a, _b;
|
|
1178
|
+
if (!this.hasTotals() || !this.isVarianceChart()) {
|
|
1179
|
+
return [];
|
|
934
1180
|
}
|
|
935
1181
|
const firstRow = (_a = this.dataModel[0]) !== null && _a !== void 0 ? _a : null;
|
|
936
1182
|
const candidates = ((_b = this.configVariances) !== null && _b !== void 0 ? _b : [])
|
|
937
1183
|
.map((name) => ({ name, variance: new VarianceScenario(name) }))
|
|
938
1184
|
.filter((entry) => entry.variance.isValid);
|
|
939
1185
|
if (candidates.length === 0) {
|
|
940
|
-
return
|
|
1186
|
+
return [];
|
|
941
1187
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
const
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1188
|
+
const first = candidates[0].variance;
|
|
1189
|
+
const relative = first.type === VarianceType.RELATIVE;
|
|
1190
|
+
const fromData = this.totalDatasetRows();
|
|
1191
|
+
const aggregation = this.totals.aggregation;
|
|
1192
|
+
return this.totalColumns.map((column) => {
|
|
1193
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1194
|
+
let base;
|
|
1195
|
+
let delta;
|
|
1196
|
+
const notations = new Set();
|
|
1197
|
+
if (fromData != null) {
|
|
1198
|
+
base = 0;
|
|
1199
|
+
const data = (_b = fromData.get(column.start ? ((_a = column.start.toISODate()) !== null && _a !== void 0 ? _a : "") : "")) !== null && _b !== void 0 ? _b : {};
|
|
1200
|
+
// the bases of the row are the scenarios of the series, each counts once
|
|
1201
|
+
for (const name of new Set(candidates.map((entry) => entry.variance.base))) {
|
|
1202
|
+
// a 0 is a scenario without a value in this total, as for the parts
|
|
1203
|
+
if (Number.isFinite(data[name]) && data[name] !== 0) {
|
|
1204
|
+
base += data[name];
|
|
1205
|
+
notations.add(name.slice(0, 2));
|
|
1206
|
+
}
|
|
955
1207
|
}
|
|
1208
|
+
if (notations.size === 0 || !Number.isFinite(data[first.delta])) {
|
|
1209
|
+
return null;
|
|
1210
|
+
}
|
|
1211
|
+
delta = data[first.delta];
|
|
956
1212
|
}
|
|
1213
|
+
else {
|
|
1214
|
+
// the same periods as the column, so the two tell the same: with `last` the one
|
|
1215
|
+
// period of the value. Without both values in each of them there is no variance.
|
|
1216
|
+
const rows = (aggregation === "last" ? column.counted.slice(-1) : column.counted).map((index) => this.dataModel[index]);
|
|
1217
|
+
const pairs = [];
|
|
1218
|
+
for (const row of rows) {
|
|
1219
|
+
for (const { variance } of candidates) {
|
|
1220
|
+
const slots = this.mapScenarios(variance, firstRow);
|
|
1221
|
+
const baseValue = (_d = row[(_c = slots.get(variance.base)) !== null && _c !== void 0 ? _c : ""]) === null || _d === void 0 ? void 0 : _d.value;
|
|
1222
|
+
const deltaValue = (_f = row[(_e = slots.get(variance.delta)) !== null && _e !== void 0 ? _e : ""]) === null || _f === void 0 ? void 0 : _f.value;
|
|
1223
|
+
if (Number.isFinite(baseValue) && Number.isFinite(deltaValue)) {
|
|
1224
|
+
pairs.push({ base: baseValue, delta: deltaValue, notation: variance.base.slice(0, 2) });
|
|
1225
|
+
break;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
if (pairs.length === 0 || pairs.length !== rows.length) {
|
|
1230
|
+
return null;
|
|
1231
|
+
}
|
|
1232
|
+
const divisor = aggregation === "average" ? pairs.length : 1;
|
|
1233
|
+
base = pairs.reduce((sum, pair) => sum + pair.base, 0) / divisor;
|
|
1234
|
+
delta = pairs.reduce((sum, pair) => sum + pair.delta, 0) / divisor;
|
|
1235
|
+
pairs.forEach((pair) => notations.add(pair.notation));
|
|
1236
|
+
}
|
|
1237
|
+
const point = new DataPoint(relative ? relativeVariance(base - delta, delta) : base - delta, first.delta, relative ? this.pixelPerPercentage : this.pixelPerUnit, first.direction);
|
|
1238
|
+
if (this.scenarioSwitch) {
|
|
1239
|
+
point.notation = notations.has("fc") ? "fc" : notations.size === 1 ? [...notations][0] : "ac";
|
|
1240
|
+
}
|
|
1241
|
+
point.key = this.totalKey(column, candidates[0].name);
|
|
1242
|
+
return point;
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
/** The point key of an element of a total column: `row: total`, and the start of its group when there are several. */
|
|
1246
|
+
totalKey(column, scenario) {
|
|
1247
|
+
const key = { row: "total" };
|
|
1248
|
+
if (column.start != null) {
|
|
1249
|
+
key.date = TimeChart.pointDate(column.start);
|
|
957
1250
|
}
|
|
958
|
-
if (
|
|
959
|
-
|
|
960
|
-
}
|
|
961
|
-
const first = candidates[0].variance;
|
|
962
|
-
const relative = first.type === VarianceType.RELATIVE;
|
|
963
|
-
const point = new DataPoint(relative ? relativeVariance(base - delta, delta) : base - delta, first.delta, relative ? this.pixelPerPercentage : this.pixelPerUnit, first.direction);
|
|
964
|
-
if (this.scenarioSwitch) {
|
|
965
|
-
point.notation = notations.has("fc") ? "fc" : notations.size === 1 ? [...notations][0] : "ac";
|
|
1251
|
+
if (scenario) {
|
|
1252
|
+
key.scenario = scenario;
|
|
966
1253
|
}
|
|
967
|
-
|
|
968
|
-
return point;
|
|
1254
|
+
return key;
|
|
969
1255
|
}
|
|
970
|
-
/** Width of the texts right of the total column: the names of its parts, and the value of
|
|
971
|
-
|
|
1256
|
+
/** Width of the texts right of the total column at the end: the names of its parts, and the value of its band. */
|
|
1257
|
+
endTotalTextWidth() {
|
|
1258
|
+
if (!this.hasEndTotal()) {
|
|
1259
|
+
return 0;
|
|
1260
|
+
}
|
|
972
1261
|
const width = (text) => CalculateSize(text, { font: this.styles.fontStyles.font, fontSize: this.styles.fontStyles.size + "px" }).width;
|
|
973
1262
|
const gap = this.position.spacings.labelToColumn;
|
|
974
|
-
const
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
const indicator = total != null && this.hasScalingIndicator() ? gap + width(this.scalingIndicatorText()) : 0;
|
|
1263
|
+
const parts = this.totalColumns[0].parts;
|
|
1264
|
+
const names = !this.isVarianceChart() && parts.length > 1
|
|
1265
|
+
? gap + Math.max(...parts.map((part) => width(this.scenarioName(part.scenario))))
|
|
1266
|
+
: 0;
|
|
1267
|
+
const indicator = this.hasScalingIndicator() ? gap + width(this.scalingIndicatorText()) : 0;
|
|
980
1268
|
return names + indicator;
|
|
981
1269
|
}
|
|
982
1270
|
scenarioName(scenario) {
|
|
@@ -997,125 +1285,142 @@ export class TimeChart {
|
|
|
997
1285
|
solid: pattern ? null : color,
|
|
998
1286
|
};
|
|
999
1287
|
}
|
|
1000
|
-
/** The axis of the total column: its own piece of line, in the look of the axis of the chart. */
|
|
1288
|
+
/** The axis of the total column at the end: its own piece of line, in the look of the axis of the chart. */
|
|
1001
1289
|
drawTotalAxis(group, y) {
|
|
1002
|
-
const { left, right } = this.
|
|
1290
|
+
const { left, right } = this.totalGeometry(0);
|
|
1003
1291
|
const scenario = this.axisScenario == null ? "default" : `${this.axisScenario}`.slice(0, 2);
|
|
1004
1292
|
group.line(left, y, right, y).addClass("axis-" + scenario);
|
|
1005
1293
|
}
|
|
1006
1294
|
/**
|
|
1007
|
-
* The total
|
|
1008
|
-
*
|
|
1009
|
-
*
|
|
1010
|
-
*
|
|
1295
|
+
* The total columns of the base chart, at their own scale: the parts, the
|
|
1296
|
+
* reference behind, the total above and the name under the axis. With a
|
|
1297
|
+
* scaling indicator a column has its own band. The column at the end has its
|
|
1298
|
+
* own axis and the names of its parts at the right, and a line links its band
|
|
1299
|
+
* to the band of the periods.
|
|
1011
1300
|
*/
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
if (total == null) {
|
|
1301
|
+
drawTotalColumns(svgContainer) {
|
|
1302
|
+
if (!this.hasTotals() || this.isVarianceChart()) {
|
|
1015
1303
|
return;
|
|
1016
1304
|
}
|
|
1017
|
-
const
|
|
1018
|
-
const scale = this.totalColumn.pixelPerUnit;
|
|
1305
|
+
const scale = this.totals.pixelPerUnit;
|
|
1019
1306
|
const axisY = this.position.getColumnPositionY();
|
|
1020
1307
|
const gap = this.position.spacings.labelToColumn;
|
|
1308
|
+
const atEnd = this.hasEndTotal();
|
|
1021
1309
|
const group = svgContainer.group().id("TotalColumn");
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1026
|
-
.
|
|
1027
|
-
.
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1310
|
+
const labelGroup = svgContainer.group().id("TotalColumnLabels");
|
|
1311
|
+
this.totalColumns.forEach((column, index) => {
|
|
1312
|
+
const { center, width, left, right } = this.totalGeometry(index);
|
|
1313
|
+
if (this.hasScalingIndicator()) {
|
|
1314
|
+
const height = this.scalingIndicator * scale;
|
|
1315
|
+
const periods = this.scalingIndicatorBand();
|
|
1316
|
+
const band = group
|
|
1317
|
+
.rect(right - left, height)
|
|
1318
|
+
.x(left)
|
|
1319
|
+
.y(axisY - height)
|
|
1320
|
+
.fill(SCALING_INDICATOR_FILL);
|
|
1321
|
+
// behind the columns of the periods that stand next to it
|
|
1322
|
+
band.back();
|
|
1323
|
+
if (atEnd && periods != null) {
|
|
1324
|
+
// the line starts behind the value of the band of the periods
|
|
1325
|
+
const from = this.scalingIndicatorLabelX() + this.scalingIndicatorTextWidth() + gap / 2;
|
|
1326
|
+
group
|
|
1327
|
+
.line(Math.min(from, left), axisY - periods.height, left, axisY - height)
|
|
1328
|
+
.stroke({ color: SCALING_INDICATOR_LINE, width: 1 })
|
|
1329
|
+
.id("ScalingIndicatorLink");
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
if (column.reference != null && column.reference.value > 0) {
|
|
1333
|
+
const look = this.columnLook(column.reference.scenario);
|
|
1334
|
+
const height = column.reference.value * scale;
|
|
1033
1335
|
group
|
|
1034
|
-
.
|
|
1035
|
-
.
|
|
1036
|
-
.
|
|
1336
|
+
.rect(width, height)
|
|
1337
|
+
.cx(center - this.position.spacings.scenarioOffset)
|
|
1338
|
+
.y(axisY - height)
|
|
1339
|
+
.fill(look.fill)
|
|
1340
|
+
.stroke(look.stroke)
|
|
1341
|
+
.attr(dataPointAttributes(this.totalKey(column, column.reference.scenario), "element"))
|
|
1342
|
+
.attr("data-bn-value", column.reference.value);
|
|
1037
1343
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
.
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
.stroke(look.stroke)
|
|
1064
|
-
.attr(dataPointAttributes(key, "element"))
|
|
1065
|
-
.attr("data-bn-value", part.value);
|
|
1066
|
-
if (total.parts.length > 1) {
|
|
1067
|
-
if (height >= this.position.dataLabelHeight) {
|
|
1068
|
-
const label = new Label(labelGroup, center, top + height / 2, "TOTAL_PART", part.value, this.styles, HookLocation.Center, HookLocation.Center).setPoint(key);
|
|
1069
|
-
// a label on a hatching keeps the background of a plain label
|
|
1070
|
-
(look.solid ? label.setSegmentFill(look.solid) : label).draw(true, this.dataFormatDigits, this.measureScale);
|
|
1344
|
+
let top = axisY;
|
|
1345
|
+
for (const part of column.parts) {
|
|
1346
|
+
const look = this.columnLook(part.scenario);
|
|
1347
|
+
const height = part.value * scale;
|
|
1348
|
+
top -= height;
|
|
1349
|
+
const key = this.totalKey(column, part.scenario);
|
|
1350
|
+
group
|
|
1351
|
+
.rect(width, height)
|
|
1352
|
+
.cx(center)
|
|
1353
|
+
.y(top)
|
|
1354
|
+
.fill(look.fill)
|
|
1355
|
+
.stroke(look.stroke)
|
|
1356
|
+
.attr(dataPointAttributes(key, "element"))
|
|
1357
|
+
.attr("data-bn-value", part.value);
|
|
1358
|
+
if (column.parts.length > 1) {
|
|
1359
|
+
if (height >= this.position.dataLabelHeight) {
|
|
1360
|
+
const label = new Label(labelGroup, center, top + height / 2, "TOTAL_PART", part.value, this.styles, HookLocation.Center, HookLocation.Center).setPoint(key);
|
|
1361
|
+
// a label on a hatching keeps the background of a plain label
|
|
1362
|
+
(look.solid ? label.setSegmentFill(look.solid) : label).draw(true, this.dataFormatDigits, this.measureScale);
|
|
1363
|
+
}
|
|
1364
|
+
if (atEnd) {
|
|
1365
|
+
new Label(labelGroup, center + width / 2 + gap,
|
|
1366
|
+
// the name of a thin top part stays below the total above the column
|
|
1367
|
+
Math.max(top + height / 2, axisY - column.total * scale + this.position.dataLabelHeight / 2), "TOTAL_NAME", this.scenarioName(part.scenario), this.styles, HookLocation.Center, HookLocation.Left).forceStringTypeDraw();
|
|
1368
|
+
}
|
|
1071
1369
|
}
|
|
1072
|
-
new Label(labelGroup, center + width / 2 + gap,
|
|
1073
|
-
// the name of a thin top part stays below the total above the column
|
|
1074
|
-
Math.max(top + height / 2, axisY - total.height * scale + this.position.dataLabelHeight / 2), "TOTAL_NAME", this.scenarioName(part.scenario), this.styles, HookLocation.Center, HookLocation.Left).forceStringTypeDraw();
|
|
1075
1370
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
}
|
|
1089
|
-
if (this.hideAxisLabels === false && this.totalColumn.label) {
|
|
1090
|
-
new Label(labelGroup, center, this.position.getAxisPositionY(false) + this.position.spacings.labelToAxis, "TOTAL_LABEL", this.totalColumn.label, this.styles, HookLocation.Top, HookLocation.Center).forceStringTypeDraw();
|
|
1371
|
+
new Label(labelGroup, center, top - gap, "TOTAL", column.total, this.styles, HookLocation.Bottom, HookLocation.Center)
|
|
1372
|
+
.setPoint(this.totalKey(column), "total")
|
|
1373
|
+
.draw(true, this.dataFormatDigits, this.measureScale);
|
|
1374
|
+
if (this.hideAxisLabels === false && column.label) {
|
|
1375
|
+
new Label(labelGroup, center, this.position.getAxisPositionY(false) + this.position.spacings.labelToAxis, "TOTAL_LABEL", column.label, this.styles, HookLocation.Top, HookLocation.Center).forceStringTypeDraw();
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
if (atEnd) {
|
|
1379
|
+
this.drawTotalAxis(group, this.position.getAxisPositionY(false));
|
|
1380
|
+
if (this.hasScalingIndicator()) {
|
|
1381
|
+
new Label(labelGroup, this.totalGeometry(0).right + this.endTotalTextWidth() - this.scalingIndicatorTextWidth(), axisY - this.scalingIndicator * scale, "SCALING_INDICATOR_TOTAL", this.scalingIndicatorText(), this.styles, HookLocation.Center, HookLocation.Left).forceStringTypeDraw();
|
|
1382
|
+
}
|
|
1091
1383
|
}
|
|
1092
1384
|
}
|
|
1093
|
-
/** The
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
if (point
|
|
1385
|
+
/** The variances of the total columns, in the tier of their variance chart: columns or pins like the others. */
|
|
1386
|
+
drawTotalVariances(svgContainer) {
|
|
1387
|
+
var _a;
|
|
1388
|
+
if (!this.totalVariances.some((point) => point != null)) {
|
|
1097
1389
|
return;
|
|
1098
1390
|
}
|
|
1099
|
-
|
|
1100
|
-
const
|
|
1101
|
-
const
|
|
1102
|
-
|
|
1103
|
-
const index = (center - this.position.getColumnCenterPositionX(0)) /
|
|
1104
|
-
(this.position.getColumnCenterPositionX(1) - this.position.getColumnCenterPositionX(0));
|
|
1391
|
+
// inside the group of the variances: its box is the height of the row, also below the axis
|
|
1392
|
+
const scenarios = (_a = svgContainer.findOne("#Scenarios")) !== null && _a !== void 0 ? _a : svgContainer.group().id("Scenarios");
|
|
1393
|
+
const group = scenarios.group().id("TotalColumn");
|
|
1394
|
+
const labelGroup = scenarios.group().id("TotalColumnLabels");
|
|
1105
1395
|
const relative = this.variancesDataModel.some((entry) => entry.type === VarianceType.RELATIVE);
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1396
|
+
this.totalVariances.forEach((point, total) => {
|
|
1397
|
+
if (point == null) {
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
const index = this.totalIndex(total);
|
|
1401
|
+
if (relative) {
|
|
1402
|
+
new Needle(this.position, this.scenarioStyles(), point, index, group.group())
|
|
1403
|
+
.updateLabelGroup(labelGroup.group())
|
|
1404
|
+
.draw(this.dataFormatDigits);
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
// a row whose period variances are cut cuts the total the same way. The part above the
|
|
1408
|
+
// break is scaled by the largest overflow: that can be the one of the total.
|
|
1409
|
+
const overflow = this.overflowConfig
|
|
1410
|
+
? Object.assign(Object.assign({}, this.overflowConfig), { maxOverflow: Math.max(this.overflowConfig.maxOverflow, point.getScaledUnit() - (this.overflowConfig.cutHeight - this.overflowConfig.scenarioCutOffset)) }) : null;
|
|
1411
|
+
new Column(this.position, this.scenarioStyles(), point, index, true, group.group(), null, overflow)
|
|
1114
1412
|
.updateLabelGroup(labelGroup.group())
|
|
1115
1413
|
.setAsVariance()
|
|
1116
1414
|
.draw(this.dataFormatDigits, this.measureScale);
|
|
1415
|
+
});
|
|
1416
|
+
if (this.hasEndTotal()) {
|
|
1417
|
+
this.drawTotalAxis(group, this.position.getAxisPositionY(relative));
|
|
1117
1418
|
}
|
|
1118
|
-
|
|
1419
|
+
const box = scenarios.bbox();
|
|
1420
|
+
this.scenariosArea = {
|
|
1421
|
+
height: box.height + this.styles.padding.top + this.styles.padding.bottom,
|
|
1422
|
+
width: box.width + this.position.spacings.columnWidth,
|
|
1423
|
+
};
|
|
1119
1424
|
}
|
|
1120
1425
|
determineEffectiveChartMode() {
|
|
1121
1426
|
if (this.chartMode === ChartMode.LINE) {
|
|
@@ -1187,6 +1492,7 @@ export class TimeChart {
|
|
|
1187
1492
|
return new Map([...defaultI18n, ...i18n]);
|
|
1188
1493
|
}
|
|
1189
1494
|
createElementPosition(scenarios) {
|
|
1495
|
+
var _a, _b;
|
|
1190
1496
|
let maxLabelLengthLeft;
|
|
1191
1497
|
// only need scenarios written on the leftside of bar/ marker
|
|
1192
1498
|
const scenarioLabelLeft = CalculateSize(scenarios
|
|
@@ -1230,7 +1536,7 @@ export class TimeChart {
|
|
|
1230
1536
|
if (this.overflowConfig) {
|
|
1231
1537
|
const { cutHeight, overdriveZoneHeight, breakGap } = this.overflowConfig;
|
|
1232
1538
|
// the total column is not cut: it keeps its room above the cut columns
|
|
1233
|
-
const virtualHeight = Math.max(cutHeight + overdriveZoneHeight + breakGap, this.isVarianceChart() ? 0 : this.
|
|
1539
|
+
const virtualHeight = Math.max(cutHeight + overdriveZoneHeight + breakGap, this.isVarianceChart() ? 0 : this.totalsHeight());
|
|
1234
1540
|
// Create a virtual DataPoint with pixelPerUnit=1 so getScaledUnit() returns virtualHeight directly
|
|
1235
1541
|
max = new DataPoint(virtualHeight, max.scenario, 1, max.variance);
|
|
1236
1542
|
}
|
|
@@ -1261,7 +1567,13 @@ export class TimeChart {
|
|
|
1261
1567
|
effectiveScaleFactors = cloned;
|
|
1262
1568
|
}
|
|
1263
1569
|
}
|
|
1264
|
-
|
|
1570
|
+
// total columns take places on the axis: the periods behind them move on
|
|
1571
|
+
const places = this.hasTotals()
|
|
1572
|
+
? this.totalSlots(effectiveScaleFactors.columnWidth, effectiveScaleFactors.categoryWidth, this.styles.fontStyles.size, effectiveScaleFactors.scenarioOffset)
|
|
1573
|
+
: null;
|
|
1574
|
+
const position = new ElementPositions(new Padding(this.styles.padding), effectiveScaleFactors, this.styles.fontStyles, min, max, (_a = places === null || places === void 0 ? void 0 : places.axisColumns) !== null && _a !== void 0 ? _a : this.dataModel.length, maxLabelLengthLeft);
|
|
1575
|
+
position.setSlots((_b = places === null || places === void 0 ? void 0 : places.slots) !== null && _b !== void 0 ? _b : null);
|
|
1576
|
+
return position;
|
|
1265
1577
|
}
|
|
1266
1578
|
calculateTitleLength(minWidth) {
|
|
1267
1579
|
let tmpTitle = "_______"; // default width if this.title is sorther
|
|
@@ -1799,7 +2111,8 @@ export class TimeChart {
|
|
|
1799
2111
|
const bottom = namesHeight > 0 ? height - this.styles.padding.bottom : height;
|
|
1800
2112
|
const lineWidth = Math.max(1, this.position.spacings.auxiliaryLineWidth);
|
|
1801
2113
|
runs.slice(1).forEach((run) => {
|
|
1802
|
-
|
|
2114
|
+
// half a period before the first period of the run: a total column can stand between the two runs
|
|
2115
|
+
const x = this.position.getColumnCenterPositionX(run.from) - this.position.spacings.categoryWidth / 2;
|
|
1803
2116
|
group
|
|
1804
2117
|
.line(x, 0, x, bottom)
|
|
1805
2118
|
.stroke({ color: this.styles.fontStyles.color || "#000000", width: lineWidth })
|