@pioneer-code/pioneer-charts 22.2.0 → 22.2.1
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.
|
@@ -113,6 +113,25 @@ class PcacAxisConfig {
|
|
|
113
113
|
* hidden axis. Styled by the theme's `.pcac-axis-sub-label` rule.
|
|
114
114
|
*/
|
|
115
115
|
subLabels;
|
|
116
|
+
/**
|
|
117
|
+
* How the values along this axis are interpreted and shown - the tick labels, and the value
|
|
118
|
+
* (`yAxis`) or key (`xAxis`) in the default tooltip. On the line/area/plot charts the x axis's
|
|
119
|
+
* format is also what decides how a point's `key` maps to an x position (by index for the
|
|
120
|
+
* default, `Decimal` and `DateTime` by the key's own value on a linear/time scale - see
|
|
121
|
+
* `PcacLineAreaChartConfig`); a bar chart's category axis ignores it. Default `None`, which
|
|
122
|
+
* on those charts behaves as `DatasetLength`.
|
|
123
|
+
*/
|
|
124
|
+
format = PcacFormatEnum.None;
|
|
125
|
+
/**
|
|
126
|
+
* The value axis's domain: it runs from `domainMin` to `domainMax`, ignoring the data. Defaults
|
|
127
|
+
* 0 and 100. Only the type of axis that has a domain to set reads them - a bar chart's category
|
|
128
|
+
* axis ignores both, its value axis reads `domainMax` only (bars always grow from 0), and a
|
|
129
|
+
* line/area/plot chart's x axis reads them only under the `Decimal` (numbers) and `DateTime`
|
|
130
|
+
* (anything `new Date()` accepts, and required) formats - the index-based formats size the
|
|
131
|
+
* axis from the data.
|
|
132
|
+
*/
|
|
133
|
+
domainMin = 0;
|
|
134
|
+
domainMax = 100;
|
|
116
135
|
}
|
|
117
136
|
/** True if `axis` has at least one sub label to draw (an empty `subLabels` object counts as none). */
|
|
118
137
|
function hasAxisSubLabels(axis) {
|
|
@@ -148,6 +167,9 @@ function resolveAxisConfig(axis, showGridDefault = false) {
|
|
|
148
167
|
showLine: axis?.showLine ?? defaults.showLine,
|
|
149
168
|
label: axis?.label,
|
|
150
169
|
subLabels: axis?.subLabels,
|
|
170
|
+
format: axis?.format ?? defaults.format,
|
|
171
|
+
domainMin: axis?.domainMin ?? defaults.domainMin,
|
|
172
|
+
domainMax: axis?.domainMax ?? defaults.domainMax,
|
|
151
173
|
};
|
|
152
174
|
}
|
|
153
175
|
/**
|
|
@@ -214,18 +236,16 @@ class PcacAxisBuilder {
|
|
|
214
236
|
if (config.yAxis.tickSize !== undefined) {
|
|
215
237
|
yAxis.tickSizeInner(config.yAxis.tickSize);
|
|
216
238
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
break;
|
|
228
|
-
}
|
|
239
|
+
switch (config.yAxis.format) {
|
|
240
|
+
case PcacFormatEnum.Percentage:
|
|
241
|
+
yAxis.tickFormat(d => d + "%");
|
|
242
|
+
break;
|
|
243
|
+
case PcacFormatEnum.Minutes:
|
|
244
|
+
yAxis.tickFormat((d) => d + 'm');
|
|
245
|
+
break;
|
|
246
|
+
case PcacFormatEnum.Fahrenheit:
|
|
247
|
+
yAxis.tickFormat((d) => d + ' F');
|
|
248
|
+
break;
|
|
229
249
|
}
|
|
230
250
|
const group = config.svg.append('g')
|
|
231
251
|
.attr('class', 'pcac-y-axis')
|
|
@@ -244,29 +264,27 @@ class PcacAxisBuilder {
|
|
|
244
264
|
if (config.xAxis.tickSize !== undefined) {
|
|
245
265
|
xAxis.tickSizeInner(config.xAxis.tickSize);
|
|
246
266
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
267
|
+
switch (config.xAxis.format) {
|
|
268
|
+
case PcacFormatEnum.Percentage:
|
|
269
|
+
xAxis.tickFormat(d => d + "%");
|
|
270
|
+
break;
|
|
271
|
+
case PcacFormatEnum.Minutes:
|
|
272
|
+
xAxis.tickFormat((d) => d + 'm');
|
|
273
|
+
break;
|
|
274
|
+
case PcacFormatEnum.Fahrenheit:
|
|
275
|
+
xAxis.tickFormat((d) => d + ' F');
|
|
276
|
+
break;
|
|
277
|
+
case PcacFormatEnum.OneDayHours:
|
|
278
|
+
xAxis.tickFormat((d) => {
|
|
279
|
+
const h = d;
|
|
280
|
+
const hour = h % 12 === 0 ? 12 : h % 12;
|
|
281
|
+
const period = h < 12 ? 'am' : 'pm';
|
|
282
|
+
return `${hour}${period}`;
|
|
283
|
+
});
|
|
284
|
+
break;
|
|
285
|
+
case PcacFormatEnum.Decimal:
|
|
286
|
+
xAxis.tickFormat((d) => format(".2s")(d));
|
|
287
|
+
break;
|
|
270
288
|
}
|
|
271
289
|
const group = config.svg.append('g')
|
|
272
290
|
.attr('class', 'pcac-x-axis')
|
|
@@ -641,11 +659,13 @@ class PcacChart {
|
|
|
641
659
|
lastContainerHeight = null;
|
|
642
660
|
lastHeightFull = false;
|
|
643
661
|
/**
|
|
644
|
-
* How much
|
|
645
|
-
* labels (negative when a short tick took some away)
|
|
646
|
-
*
|
|
662
|
+
* How much the vertical margins have grown this build beyond their defaults - for tick marks
|
|
663
|
+
* and axis labels (`initializeAxisState()`; negative when a short tick took some away) and for
|
|
664
|
+
* content that hangs past the plot's edge (`reserveEdgeSpace()`). `resolveHeight()` subtracts
|
|
665
|
+
* it from the plot height so the SVG's total height doesn't change with any of them. Reset
|
|
666
|
+
* alongside the margins.
|
|
647
667
|
*/
|
|
648
|
-
|
|
668
|
+
reservedHeight = 0;
|
|
649
669
|
/**
|
|
650
670
|
* Resolves the consumer's projected `<ng-template pcacTooltip>`, if any. Each chart component
|
|
651
671
|
* points this at its own `contentChild(PcacTooltipDirective)` query. It's a getter rather than
|
|
@@ -663,7 +683,7 @@ class PcacChart {
|
|
|
663
683
|
*/
|
|
664
684
|
resetMargin() {
|
|
665
685
|
this.margin = { ...this.defaultMargin };
|
|
666
|
-
this.
|
|
686
|
+
this.reservedHeight = 0;
|
|
667
687
|
}
|
|
668
688
|
/**
|
|
669
689
|
* Resolves the config's `xAxis`/`yAxis` onto this chart and sets the margins up for them. Axis
|
|
@@ -696,7 +716,7 @@ class PcacChart {
|
|
|
696
716
|
if (!this.xAxis.hide) {
|
|
697
717
|
const space = axisLabelSpace(this.xAxis);
|
|
698
718
|
this.margin.bottom += space;
|
|
699
|
-
this.
|
|
719
|
+
this.reservedHeight += space;
|
|
700
720
|
}
|
|
701
721
|
if (!this.yAxis.hide) {
|
|
702
722
|
this.margin.left += axisLabelSpace(this.yAxis);
|
|
@@ -713,11 +733,11 @@ class PcacChart {
|
|
|
713
733
|
}
|
|
714
734
|
}
|
|
715
735
|
/**
|
|
716
|
-
* The `PcacAxisBuilder` config for this chart's current state - everything but the scales
|
|
717
|
-
*
|
|
718
|
-
*
|
|
736
|
+
* The `PcacAxisBuilder` config for this chart's current state - everything but the scales is
|
|
737
|
+
* already on the instance. Builders pass the result to `drawAxis()` (or `drawXAxis()` with a
|
|
738
|
+
* rescaled x, on zoom).
|
|
719
739
|
*/
|
|
720
|
-
axisBuilderConfig(xScale, yScale
|
|
740
|
+
axisBuilderConfig(xScale, yScale) {
|
|
721
741
|
return {
|
|
722
742
|
svg: this.svg,
|
|
723
743
|
width: this.width,
|
|
@@ -726,9 +746,7 @@ class PcacChart {
|
|
|
726
746
|
xScale,
|
|
727
747
|
yScale,
|
|
728
748
|
xAxis: this.xAxis,
|
|
729
|
-
yAxis: this.yAxis
|
|
730
|
-
xFormat,
|
|
731
|
-
yFormat
|
|
749
|
+
yAxis: this.yAxis
|
|
732
750
|
};
|
|
733
751
|
}
|
|
734
752
|
/**
|
|
@@ -757,7 +775,7 @@ class PcacChart {
|
|
|
757
775
|
* Horizontally that happens on its own: `initializeChartState()` derives `width` from the
|
|
758
776
|
* container minus the margins. Vertically it doesn't - `config.height` is the plot area, and
|
|
759
777
|
* the SVG is that plus the margins - so a taller bottom margin would grow the SVG instead. The
|
|
760
|
-
* delta is therefore also remembered in `
|
|
778
|
+
* delta is therefore also remembered in `reservedHeight` and taken back out of the plot
|
|
761
779
|
* height by `resolveHeight()`, keeping the chart's total footprint where the consumer put it.
|
|
762
780
|
*
|
|
763
781
|
* Called by `initializeAxisState()` right after `resetMargin()`, for the axes that will be
|
|
@@ -769,13 +787,42 @@ class PcacChart {
|
|
|
769
787
|
reserveTickSizeMargins(xTickSize, yTickSize) {
|
|
770
788
|
if (xTickSize !== undefined) {
|
|
771
789
|
const bottom = Math.max(0, this.margin.bottom + xTickSize - PcacChart.DEFAULT_TICK_SIZE);
|
|
772
|
-
this.
|
|
790
|
+
this.reservedHeight = bottom - this.margin.bottom;
|
|
773
791
|
this.margin.bottom = bottom;
|
|
774
792
|
}
|
|
775
793
|
if (yTickSize !== undefined) {
|
|
776
794
|
this.margin.left = Math.max(0, this.margin.left + yTickSize - PcacChart.DEFAULT_TICK_SIZE);
|
|
777
795
|
}
|
|
778
796
|
}
|
|
797
|
+
/**
|
|
798
|
+
* Makes sure each given margin is at least that big, for content drawn at the very edge of the
|
|
799
|
+
* plot area that reaches past it - a point image on the line/area/plot charts, say, whose box
|
|
800
|
+
* is centered on a point at the top of the y domain and so hangs half of itself above the plot.
|
|
801
|
+
* Those charts already widen their clip-path to let such a point through; this is what stops
|
|
802
|
+
* the `<svg>` itself from cutting it off, the SVG being only the plot area plus the margins.
|
|
803
|
+
*
|
|
804
|
+
* "At least", not "add": the default margins, and any tick / label room already reserved in
|
|
805
|
+
* them, may well cover it already (`margin.left` is 40 by default), and adding on top of that
|
|
806
|
+
* would give up plot area for nothing. Vertical growth is taken out of the plot height the same
|
|
807
|
+
* way `reserveTickSizeMargins()`'s is, so the SVG's total height stays what the consumer
|
|
808
|
+
* configured; horizontally `initializeChartState()` picks the change up on its own. A side
|
|
809
|
+
* left `undefined` is untouched.
|
|
810
|
+
*
|
|
811
|
+
* Call after `initializeAxisState()` (which resets the margins) and before
|
|
812
|
+
* `initializeChartState()` (which measures the plot area against them).
|
|
813
|
+
*/
|
|
814
|
+
reserveEdgeSpace(space) {
|
|
815
|
+
for (const side of ['top', 'right', 'bottom', 'left']) {
|
|
816
|
+
const wanted = space[side];
|
|
817
|
+
if (wanted === undefined || wanted <= this.margin[side]) {
|
|
818
|
+
continue;
|
|
819
|
+
}
|
|
820
|
+
if (side === 'top' || side === 'bottom') {
|
|
821
|
+
this.reservedHeight += wanted - this.margin[side];
|
|
822
|
+
}
|
|
823
|
+
this.margin[side] = wanted;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
779
826
|
/**
|
|
780
827
|
* Shows the tooltip for a hovered datum, through the chart's `pcacTooltip` template when one is
|
|
781
828
|
* projected and the default key/value content otherwise. Every builder's hover handler should
|
|
@@ -836,9 +883,10 @@ class PcacChart {
|
|
|
836
883
|
* @param config Chart specific configuration
|
|
837
884
|
*/
|
|
838
885
|
resolveHeight(container, config) {
|
|
839
|
-
// See `reserveTickSizeMargins()`: room made
|
|
840
|
-
// added on to the SVG. Applies to the floor in the `heightFull`
|
|
841
|
-
|
|
886
|
+
// See `reserveTickSizeMargins()` / `reserveEdgeSpace()`: room made in the vertical margins
|
|
887
|
+
// comes out of the plot area, not added on to the SVG. Applies to the floor in the `heightFull`
|
|
888
|
+
// case too, for the same reason.
|
|
889
|
+
const height = Math.max(0, config.height - this.reservedHeight);
|
|
842
890
|
if (!config.heightFull) {
|
|
843
891
|
return height;
|
|
844
892
|
}
|
|
@@ -990,8 +1038,9 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
990
1038
|
config.data[0].data.map((d) => {
|
|
991
1039
|
return d.value;
|
|
992
1040
|
});
|
|
1041
|
+
// Bars grow from 0, so only `domainMax` is read; `xAxis.domainMin` is ignored.
|
|
993
1042
|
this.xScale = scaleLinear()
|
|
994
|
-
.domain([0,
|
|
1043
|
+
.domain([0, this.xAxis.domainMax]);
|
|
995
1044
|
this.yScaleStacked = scaleBand()
|
|
996
1045
|
.domain(config.data.map((d) => d.key))
|
|
997
1046
|
.range([this.height, 0])
|
|
@@ -1008,7 +1057,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1008
1057
|
}
|
|
1009
1058
|
drawChart(chartElm, config) {
|
|
1010
1059
|
this.buildContainer(chartElm);
|
|
1011
|
-
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScale, this.yScaleStacked
|
|
1060
|
+
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScale, this.yScaleStacked));
|
|
1012
1061
|
this.drawGrids(this.xScale, this.yScaleStacked);
|
|
1013
1062
|
this.addGroups(config);
|
|
1014
1063
|
this.axisBuilder.raiseAxes(this.svg);
|
|
@@ -1092,7 +1141,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1092
1141
|
.on('mousemove', function (event, d) {
|
|
1093
1142
|
const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
|
|
1094
1143
|
const index = Number(this.getAttribute('data-group-bar-id'));
|
|
1095
|
-
self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat:
|
|
1144
|
+
self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.xAxis.format });
|
|
1096
1145
|
})
|
|
1097
1146
|
.on('mouseout', function () {
|
|
1098
1147
|
self.hideTooltip();
|
|
@@ -1124,7 +1173,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1124
1173
|
return i;
|
|
1125
1174
|
})
|
|
1126
1175
|
.on('mousemove', (event) => {
|
|
1127
|
-
this.showTooltip(event, config.thresholds[0], { index: 0, isThreshold: true, valueFormat:
|
|
1176
|
+
this.showTooltip(event, config.thresholds[0], { index: 0, isThreshold: true, valueFormat: this.xAxis.format });
|
|
1128
1177
|
})
|
|
1129
1178
|
.transition()
|
|
1130
1179
|
.duration(this.transitionService.getTransitionDuration())
|
|
@@ -1144,7 +1193,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1144
1193
|
const threshold = config.thresholds[index];
|
|
1145
1194
|
// A threshold's own PcacData is typically just a value, so its parent is the *data* group
|
|
1146
1195
|
// it's drawn against (which has the key) rather than the threshold entry it came from.
|
|
1147
|
-
self.showTooltip(event, config.isStacked ? threshold.data[0] : threshold, { index, parent: config.data[index], parentIndex: index, isThreshold: true, valueFormat:
|
|
1196
|
+
self.showTooltip(event, config.isStacked ? threshold.data[0] : threshold, { index, parent: config.data[index], parentIndex: index, isThreshold: true, valueFormat: self.xAxis.format });
|
|
1148
1197
|
})
|
|
1149
1198
|
.transition()
|
|
1150
1199
|
.duration(this.transitionService.getTransitionDuration())
|
|
@@ -1164,7 +1213,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1164
1213
|
const index = Number(target.getAttribute("data-group-threshold-id"));
|
|
1165
1214
|
const groupIndex = Number(this.parentElement.dataset['groupId']);
|
|
1166
1215
|
// Parent is the data group (see drawThresholdsPerGroup), not the threshold entry itself.
|
|
1167
|
-
self.showTooltip(event, config.thresholds[groupIndex].data[index], { index, parent: config.data[groupIndex], parentIndex: groupIndex, isThreshold: true, valueFormat:
|
|
1216
|
+
self.showTooltip(event, config.thresholds[groupIndex].data[index], { index, parent: config.data[groupIndex], parentIndex: groupIndex, isThreshold: true, valueFormat: self.xAxis.format });
|
|
1168
1217
|
})
|
|
1169
1218
|
.transition()
|
|
1170
1219
|
.duration(this.transitionService.getTransitionDuration())
|
|
@@ -1345,10 +1394,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
|
|
|
1345
1394
|
}], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], barClicked: [{ type: i0.Output, args: ["barClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
|
|
1346
1395
|
|
|
1347
1396
|
class PcacBarHorizontalChartConfig extends PcacAxisChartConfig {
|
|
1348
|
-
domainMax = 100;
|
|
1349
1397
|
isStacked = false;
|
|
1350
1398
|
thresholds = [];
|
|
1351
|
-
tickFormat = PcacFormatEnum.None;
|
|
1352
1399
|
spreadColorsPerGroup = false;
|
|
1353
1400
|
colorOverride = new PcacBarHorizontalChartColorOverrideConfig();
|
|
1354
1401
|
}
|
|
@@ -1391,9 +1438,10 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1391
1438
|
buildScales(config) {
|
|
1392
1439
|
// `this.height`, not `config.height`: with `heightFull` on they differ (see
|
|
1393
1440
|
// PcacChart.resolveHeight), and the axis, grid and bar baselines all use the resolved one.
|
|
1441
|
+
// Bars grow from 0, so only `domainMax` is read; `yAxis.domainMin` is ignored.
|
|
1394
1442
|
this.yScale = scaleLinear()
|
|
1395
1443
|
.rangeRound([0, this.height])
|
|
1396
|
-
.domain([
|
|
1444
|
+
.domain([this.yAxis.domainMax, 0]);
|
|
1397
1445
|
this.xScaleStacked = scaleBand()
|
|
1398
1446
|
.domain(config.data.map((d) => d.key))
|
|
1399
1447
|
.rangeRound([0, this.width])
|
|
@@ -1405,7 +1453,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1405
1453
|
}
|
|
1406
1454
|
drawChart(chartElm, config) {
|
|
1407
1455
|
this.buildContainer(chartElm);
|
|
1408
|
-
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScaleStacked, this.yScale
|
|
1456
|
+
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScaleStacked, this.yScale));
|
|
1409
1457
|
this.drawGrids(this.xScaleStacked, this.yScale);
|
|
1410
1458
|
this.addGroups(config);
|
|
1411
1459
|
this.axisBuilder.raiseAxes(this.svg);
|
|
@@ -1492,7 +1540,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1492
1540
|
.on('mousemove', function (event, d) {
|
|
1493
1541
|
const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
|
|
1494
1542
|
const index = Number(this.getAttribute('data-group-bar-id'));
|
|
1495
|
-
self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat:
|
|
1543
|
+
self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.yAxis.format });
|
|
1496
1544
|
})
|
|
1497
1545
|
.on('mouseout', function () {
|
|
1498
1546
|
self.hideTooltip();
|
|
@@ -1531,7 +1579,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1531
1579
|
return i;
|
|
1532
1580
|
})
|
|
1533
1581
|
.on('mousemove', (event) => {
|
|
1534
|
-
this.showTooltip(event, config.thresholds[0], { index: 0, isThreshold: true, valueFormat:
|
|
1582
|
+
this.showTooltip(event, config.thresholds[0], { index: 0, isThreshold: true, valueFormat: this.yAxis.format });
|
|
1535
1583
|
})
|
|
1536
1584
|
.transition()
|
|
1537
1585
|
.duration(this.transitionService.getTransitionDuration())
|
|
@@ -1551,7 +1599,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1551
1599
|
const threshold = config.thresholds[index];
|
|
1552
1600
|
// A threshold's own PcacData is typically just a value, so its parent is the *data* group
|
|
1553
1601
|
// it's drawn against (which has the key) rather than the threshold entry it came from.
|
|
1554
|
-
self.showTooltip(event, config.isStacked ? threshold.data[0] : threshold, { index, parent: config.data[index], parentIndex: index, isThreshold: true, valueFormat:
|
|
1602
|
+
self.showTooltip(event, config.isStacked ? threshold.data[0] : threshold, { index, parent: config.data[index], parentIndex: index, isThreshold: true, valueFormat: self.yAxis.format });
|
|
1555
1603
|
})
|
|
1556
1604
|
.transition()
|
|
1557
1605
|
.duration(this.transitionService.getTransitionDuration())
|
|
@@ -1570,7 +1618,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1570
1618
|
const index = Number(target.getAttribute("data-group-threshold-id"));
|
|
1571
1619
|
const groupIndex = Number(this.parentElement.dataset['groupId']);
|
|
1572
1620
|
// Parent is the data group (see drawThresholdsPerGroup), not the threshold entry itself.
|
|
1573
|
-
self.showTooltip(event, config.thresholds[groupIndex].data[index], { index, parent: config.data[groupIndex], parentIndex: groupIndex, isThreshold: true, valueFormat:
|
|
1621
|
+
self.showTooltip(event, config.thresholds[groupIndex].data[index], { index, parent: config.data[groupIndex], parentIndex: groupIndex, isThreshold: true, valueFormat: self.yAxis.format });
|
|
1574
1622
|
})
|
|
1575
1623
|
.attr('width', this.xScaleGrouped.bandwidth())
|
|
1576
1624
|
.transition()
|
|
@@ -1660,10 +1708,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
|
|
|
1660
1708
|
}], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], barClicked: [{ type: i0.Output, args: ["barClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
|
|
1661
1709
|
|
|
1662
1710
|
class PcacBarVerticalChartConfig extends PcacAxisChartConfig {
|
|
1663
|
-
domainMax = 100;
|
|
1664
1711
|
isStacked = false;
|
|
1665
1712
|
thresholds = [];
|
|
1666
|
-
tickFormat = PcacFormatEnum.None;
|
|
1667
1713
|
spreadColorsPerGroup = false;
|
|
1668
1714
|
colorOverride = new PcacBarVerticalChartColorOverrideConfig();
|
|
1669
1715
|
}
|
|
@@ -1715,15 +1761,18 @@ class PcacPointImageConfig {
|
|
|
1715
1761
|
maxWidth = 16;
|
|
1716
1762
|
maxHeight = 16;
|
|
1717
1763
|
}
|
|
1764
|
+
/**
|
|
1765
|
+
* The axes' `format` and `domainMin`/`domainMax` (`PcacAxisConfig`) do more here than on the bar
|
|
1766
|
+
* charts. `yAxis.domainMin`/`domainMax` are the y scale's domain (default 0..100). `xAxis.format`
|
|
1767
|
+
* decides how each point's `key` becomes an x position: `Decimal` reads it as a number on a
|
|
1768
|
+
* linear scale from `xAxis.domainMin` to `domainMax`, `DateTime` parses it with `new Date()` on
|
|
1769
|
+
* a time scale between the two (both required), and every other format - including the default -
|
|
1770
|
+
* places points by their index within their series, sizing the axis from the first series'
|
|
1771
|
+
* length and ignoring the domain fields.
|
|
1772
|
+
*/
|
|
1718
1773
|
class PcacLineAreaChartConfig extends PcacAxisChartConfig {
|
|
1719
1774
|
enableEffects = true;
|
|
1720
1775
|
enableZoom = true;
|
|
1721
|
-
yFormat = PcacFormatEnum.DatasetLength;
|
|
1722
|
-
xFormat = PcacFormatEnum.DatasetLength;
|
|
1723
|
-
yDomainMax;
|
|
1724
|
-
yDomainMin;
|
|
1725
|
-
xDomainMin;
|
|
1726
|
-
xDomainMax;
|
|
1727
1776
|
/**
|
|
1728
1777
|
* Hex color codes to override the default colors
|
|
1729
1778
|
*/
|
|
@@ -1884,42 +1933,38 @@ class PlaChartScales {
|
|
|
1884
1933
|
x;
|
|
1885
1934
|
y;
|
|
1886
1935
|
}
|
|
1936
|
+
/**
|
|
1937
|
+
* Takes the chart's *resolved* axes (`PcacChart.xAxis`/`yAxis`), not the raw config, so the
|
|
1938
|
+
* `format`/`domainMin`/`domainMax` defaults are already applied - see `PcacLineAreaChartConfig`
|
|
1939
|
+
* for what each format does with them.
|
|
1940
|
+
*/
|
|
1887
1941
|
class PlaChartScalesBuilder {
|
|
1888
|
-
build(
|
|
1942
|
+
build(xAxis, yAxis, data, chartWidth, chartHeight) {
|
|
1889
1943
|
const resp = new PlaChartScales();
|
|
1890
|
-
resp.x = this.buildXScale(
|
|
1891
|
-
resp.y = this.buildYScale(
|
|
1944
|
+
resp.x = this.buildXScale(xAxis, data, chartWidth);
|
|
1945
|
+
resp.y = this.buildYScale(yAxis, chartHeight);
|
|
1892
1946
|
return resp;
|
|
1893
1947
|
}
|
|
1894
|
-
buildXScale(
|
|
1895
|
-
|
|
1896
|
-
switch (config.xFormat) {
|
|
1948
|
+
buildXScale(xAxis, data, chartWidth) {
|
|
1949
|
+
switch (xAxis.format) {
|
|
1897
1950
|
case PcacFormatEnum.DateTime:
|
|
1898
|
-
|
|
1899
|
-
.domain([new Date(
|
|
1951
|
+
return scaleTime()
|
|
1952
|
+
.domain([new Date(xAxis.domainMin), new Date(xAxis.domainMax)])
|
|
1900
1953
|
.range([0, chartWidth]);
|
|
1901
|
-
break;
|
|
1902
1954
|
case PcacFormatEnum.Decimal:
|
|
1903
|
-
|
|
1904
|
-
.domain([
|
|
1955
|
+
return scaleLinear()
|
|
1956
|
+
.domain([xAxis.domainMin, xAxis.domainMax])
|
|
1905
1957
|
.range([0, chartWidth]);
|
|
1906
|
-
break;
|
|
1907
|
-
case PcacFormatEnum.DatasetLength:
|
|
1908
|
-
resp = scaleLinear()
|
|
1909
|
-
.domain([0, config.data[0].data.length - 1])
|
|
1910
|
-
.range([0, chartWidth]);
|
|
1911
|
-
break;
|
|
1912
1958
|
default:
|
|
1913
|
-
|
|
1914
|
-
|
|
1959
|
+
// DatasetLength and every other format position points by index
|
|
1960
|
+
return scaleLinear()
|
|
1961
|
+
.domain([0, data[0].data.length - 1])
|
|
1915
1962
|
.range([0, chartWidth]);
|
|
1916
|
-
break;
|
|
1917
1963
|
}
|
|
1918
|
-
return resp;
|
|
1919
1964
|
}
|
|
1920
|
-
buildYScale(
|
|
1965
|
+
buildYScale(yAxis, chartHeight) {
|
|
1921
1966
|
return scaleLinear()
|
|
1922
|
-
.domain([
|
|
1967
|
+
.domain([yAxis.domainMin, yAxis.domainMax])
|
|
1923
1968
|
.range([chartHeight, 0]);
|
|
1924
1969
|
}
|
|
1925
1970
|
}
|
|
@@ -1962,9 +2007,18 @@ function buildAreaGenerator(format, scales, chartHeight) {
|
|
|
1962
2007
|
});
|
|
1963
2008
|
}
|
|
1964
2009
|
|
|
2010
|
+
/**
|
|
2011
|
+
* `extent` (the viewport the gesture happens in) is set to the plot area explicitly rather than
|
|
2012
|
+
* left to d3's default, which reads the *owning `<svg>`'s* size - plot plus margins. With the
|
|
2013
|
+
* viewport wider than `translateExtent`, d3's constraint centers the plot within it instead of
|
|
2014
|
+
* pinning the two together, so the first gesture (even one that zooms straight back out to k = 1)
|
|
2015
|
+
* left the chart shifted right/down by half the margins: x domain min detached from the y axis,
|
|
2016
|
+
* domain max pushed off the right edge.
|
|
2017
|
+
*/
|
|
1965
2018
|
function buildZoomBehavior(width, height, zoomedFn) {
|
|
1966
2019
|
return zoom()
|
|
1967
2020
|
.scaleExtent([1, 10])
|
|
2021
|
+
.extent([[0, 0], [width, height]])
|
|
1968
2022
|
.translateExtent([[0, 0], [width, height]])
|
|
1969
2023
|
.on("zoom", zoomedFn);
|
|
1970
2024
|
}
|
|
@@ -1988,7 +2042,9 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1988
2042
|
* How far the clip-path rect extends past the drawable [0, width] x [0, height] area on every
|
|
1989
2043
|
* side, so a point sitting exactly on the domain's edge isn't cut in half. 10px comfortably
|
|
1990
2044
|
* clears a dot (r = 4, or 6 on hover); a point image can be much bigger than that, so
|
|
1991
|
-
* buildChart() widens this to half the largest image dimension whenever any point has one
|
|
2045
|
+
* buildChart() widens this to half the largest image dimension whenever any point has one
|
|
2046
|
+
* (and grows the margins to match - see `reservePointImageSpace()` - since the clip-path only
|
|
2047
|
+
* matters up to the edge of the SVG).
|
|
1992
2048
|
*/
|
|
1993
2049
|
clipBuffer = 10;
|
|
1994
2050
|
pointImage;
|
|
@@ -2006,6 +2062,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2006
2062
|
}));
|
|
2007
2063
|
// A hidden axis keeps 8px rather than 0 so a dot on the edge of the plot isn't clipped
|
|
2008
2064
|
this.initializeAxisState(this.config, 'y', 8);
|
|
2065
|
+
this.reservePointImageSpace();
|
|
2009
2066
|
if (!this.initializeChartState(chartElm, this.config)) {
|
|
2010
2067
|
return;
|
|
2011
2068
|
}
|
|
@@ -2015,31 +2072,27 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2015
2072
|
if (this.config.colorOverride?.length) {
|
|
2016
2073
|
this.colors = this.config.colorOverride;
|
|
2017
2074
|
}
|
|
2018
|
-
this.
|
|
2019
|
-
this.
|
|
2020
|
-
|
|
2021
|
-
: 10;
|
|
2022
|
-
this.scales = new PlaChartScalesBuilder().build(this.config, this.width, this.height);
|
|
2023
|
-
this.lineGenerator = buildLineGenerator(this.config.xFormat, this.scales);
|
|
2024
|
-
this.areaGenerator = buildAreaGenerator(this.config.xFormat, this.scales, this.height);
|
|
2075
|
+
this.scales = new PlaChartScalesBuilder().build(this.xAxis, this.yAxis, this.config.data, this.width, this.height);
|
|
2076
|
+
this.lineGenerator = buildLineGenerator(this.xAxis.format, this.scales);
|
|
2077
|
+
this.areaGenerator = buildAreaGenerator(this.xAxis.format, this.scales, this.height);
|
|
2025
2078
|
if (this.config.enableZoom) {
|
|
2026
2079
|
this.zoomBehavior = buildZoomBehavior(this.width, this.height, (event) => {
|
|
2027
2080
|
// Rescale x
|
|
2028
2081
|
const newX = event.transform.rescaleX(this.scales.x);
|
|
2029
2082
|
// Update axis
|
|
2030
|
-
this.axisBuilder.drawXAxis(this.axisBuilderConfig(newX, this.scales.y
|
|
2083
|
+
this.axisBuilder.drawXAxis(this.axisBuilderConfig(newX, this.scales.y));
|
|
2031
2084
|
// Update lines/areas. Fresh generators against the rescaled x, so they go through the
|
|
2032
2085
|
// same getXFormat() as the dots below - positioning by bare index here (which this used
|
|
2033
2086
|
// to do, and which also overwrote the original generators' x accessor for good) is only
|
|
2034
2087
|
// right for the default DatasetLength format; a DateTime/Decimal chart's lines drifted
|
|
2035
2088
|
// away from its dots as soon as it was zoomed.
|
|
2036
2089
|
const zoomedScales = { x: newX, y: this.scales.y };
|
|
2037
|
-
const zoomedLine = buildLineGenerator(this.
|
|
2038
|
-
const zoomedArea = buildAreaGenerator(this.
|
|
2090
|
+
const zoomedLine = buildLineGenerator(this.xAxis.format, zoomedScales);
|
|
2091
|
+
const zoomedArea = buildAreaGenerator(this.xAxis.format, zoomedScales, this.height);
|
|
2039
2092
|
this.svg.selectAll('.line').attr('d', (d) => zoomedLine(d));
|
|
2040
2093
|
this.svg.selectAll('.area').attr('d', (d) => zoomedArea(d));
|
|
2041
2094
|
// Update dots / point images. Nested selectAll (not a flat svg.selectAll('.point')) so
|
|
2042
|
-
// that `i` is the point's index *within its own series* - the
|
|
2095
|
+
// that `i` is the point's index *within its own series* - the x format default
|
|
2043
2096
|
// (DatasetLength) positions by index, and a flat selection would number every series'
|
|
2044
2097
|
// points consecutively, shoving the second series' points off to the right on zoom.
|
|
2045
2098
|
this.svg.selectAll('.dots').selectAll('.point')
|
|
@@ -2060,7 +2113,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2060
2113
|
this.buildContainer(chartElm);
|
|
2061
2114
|
this.attachZoomBehavior();
|
|
2062
2115
|
this.createReusableClipPath();
|
|
2063
|
-
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.scales.x, this.scales.y
|
|
2116
|
+
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.scales.x, this.scales.y));
|
|
2064
2117
|
this.drawGrids(this.scales.x, this.scales.y);
|
|
2065
2118
|
this.drawLineArea(config, type);
|
|
2066
2119
|
if (config.enableEffects) {
|
|
@@ -2079,6 +2132,26 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2079
2132
|
this.axisBuilder.raiseAxes(this.svg);
|
|
2080
2133
|
this.drawDots(config);
|
|
2081
2134
|
}
|
|
2135
|
+
/**
|
|
2136
|
+
* Resolves `pointImage` and, when any point actually has an `image`, makes room for one at the
|
|
2137
|
+
* edge of the domain: the clip-path buffer grows to half the box so the `.dots` group lets it
|
|
2138
|
+
* through, and the margins grow to at least that same half so the `<svg>` doesn't cut off what
|
|
2139
|
+
* the clip-path let through (an image box is centered on its point, so at the top of the y
|
|
2140
|
+
* domain half of it sits above the plot area - in `margin.top`, which is only 8px by default).
|
|
2141
|
+
* Must run between `initializeAxisState()` and `initializeChartState()`, see `reserveEdgeSpace`.
|
|
2142
|
+
*/
|
|
2143
|
+
reservePointImageSpace() {
|
|
2144
|
+
this.pointImage = { ...new PcacPointImageConfig(), ...this.config.pointImage };
|
|
2145
|
+
const hasImages = this.config.data.some((series) => series.data.some((point) => !!point.image));
|
|
2146
|
+
if (!hasImages) {
|
|
2147
|
+
this.clipBuffer = 10;
|
|
2148
|
+
return;
|
|
2149
|
+
}
|
|
2150
|
+
const halfWidth = Math.ceil(this.pointImage.maxWidth / 2);
|
|
2151
|
+
const halfHeight = Math.ceil(this.pointImage.maxHeight / 2);
|
|
2152
|
+
this.clipBuffer = Math.max(10, halfWidth, halfHeight);
|
|
2153
|
+
this.reserveEdgeSpace({ top: halfHeight, bottom: halfHeight, left: halfWidth, right: halfWidth });
|
|
2154
|
+
}
|
|
2082
2155
|
createReusableClipPath() {
|
|
2083
2156
|
this.clipPathId = `pcac-clip-${Date.now()}-${Math.floor(Math.random() * 10000)}`;
|
|
2084
2157
|
this.svg.selectAll(`defs #${this.clipPathId}`).remove();
|
|
@@ -2189,8 +2262,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2189
2262
|
index: series.data.indexOf(d),
|
|
2190
2263
|
parent: series,
|
|
2191
2264
|
parentIndex: index,
|
|
2192
|
-
valueFormat: self.
|
|
2193
|
-
keyFormat: self.
|
|
2265
|
+
valueFormat: self.yAxis.format,
|
|
2266
|
+
keyFormat: self.xAxis.format,
|
|
2194
2267
|
});
|
|
2195
2268
|
// No-op for an image point (no circle inside to grow).
|
|
2196
2269
|
select$1(this).select('.dot')
|
|
@@ -2239,7 +2312,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2239
2312
|
}
|
|
2240
2313
|
}
|
|
2241
2314
|
pointTransform(d, i, xScale) {
|
|
2242
|
-
return `translate(${getXFormat(this.
|
|
2315
|
+
return `translate(${getXFormat(this.xAxis.format, d, i, xScale)}, 0)`;
|
|
2243
2316
|
}
|
|
2244
2317
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: PlaChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
2245
2318
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: PlaChartBuilder });
|