@pioneer-code/pioneer-charts 22.2.0 → 22.2.2

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
- if (config.yFormat) {
218
- switch (config.yFormat) {
219
- case PcacFormatEnum.Percentage:
220
- yAxis.tickFormat(d => d + "%");
221
- break;
222
- case PcacFormatEnum.Minutes:
223
- yAxis.tickFormat((d) => d + 'm');
224
- break;
225
- case PcacFormatEnum.Fahrenheit:
226
- yAxis.tickFormat((d) => d + ' F');
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
- if (config.xFormat) {
248
- switch (config.xFormat) {
249
- case PcacFormatEnum.Percentage:
250
- xAxis.tickFormat(d => d + "%");
251
- break;
252
- case PcacFormatEnum.Minutes:
253
- xAxis.tickFormat((d) => d + 'm');
254
- break;
255
- case PcacFormatEnum.Fahrenheit:
256
- xAxis.tickFormat((d) => d + ' F');
257
- break;
258
- case PcacFormatEnum.OneDayHours:
259
- xAxis.tickFormat((d) => {
260
- const h = d;
261
- const hour = h % 12 === 0 ? 12 : h % 12;
262
- const period = h < 12 ? 'am' : 'pm';
263
- return `${hour}${period}`;
264
- });
265
- break;
266
- case PcacFormatEnum.Decimal:
267
- xAxis.tickFormat((d) => format(".2s")(d));
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')
@@ -500,7 +518,7 @@ class PcacTooltipBuilder {
500
518
  * projected `pcacTooltip` template. This only ever renders the default content.
501
519
  */
502
520
  showBarTooltip(event, data, valueFormat, keyFormat) {
503
- this.showTooltip(event, undefined, { $implicit: data, parent: null, isThreshold: false, index: 0, parentIndex: null }, valueFormat, keyFormat);
521
+ this.showTooltip(event, undefined, { $implicit: data, parent: null, isThreshold: false, index: 0, parentIndex: null, coincident: [] }, valueFormat, keyFormat);
504
522
  }
505
523
  hideTooltip() {
506
524
  this.tooltip.style('display', 'none');
@@ -641,11 +659,13 @@ class PcacChart {
641
659
  lastContainerHeight = null;
642
660
  lastHeightFull = false;
643
661
  /**
644
- * How much `initializeAxisState()` last added to `margin.bottom` for tick marks and axis
645
- * labels (negative when a short tick took some away). `resolveHeight()` subtracts it from the
646
- * plot height so the SVG's total height doesn't change with either. Reset alongside the margins.
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
- reservedTickHeight = 0;
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.reservedTickHeight = 0;
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.reservedTickHeight += space;
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 and
717
- * formats is already on the instance. Builders pass the result to `drawAxis()` (or `drawXAxis()`
718
- * with a rescaled x, on zoom).
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, xFormat, yFormat) {
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 `reservedTickHeight` and taken back out of the plot
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.reservedTickHeight = bottom - this.margin.bottom;
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
@@ -788,6 +835,7 @@ class PcacChart {
788
835
  isThreshold: options.isThreshold ?? false,
789
836
  index: options.index,
790
837
  parentIndex: options.parentIndex ?? null,
838
+ coincident: options.coincident ?? [],
791
839
  }, options.valueFormat, options.keyFormat);
792
840
  }
793
841
  hideTooltip() {
@@ -836,9 +884,10 @@ class PcacChart {
836
884
  * @param config Chart specific configuration
837
885
  */
838
886
  resolveHeight(container, config) {
839
- // See `reserveTickSizeMargins()`: room made for longer ticks comes out of the plot area, not
840
- // added on to the SVG. Applies to the floor in the `heightFull` case too, for the same reason.
841
- const height = Math.max(0, config.height - this.reservedTickHeight);
887
+ // See `reserveTickSizeMargins()` / `reserveEdgeSpace()`: room made in the vertical margins
888
+ // comes out of the plot area, not added on to the SVG. Applies to the floor in the `heightFull`
889
+ // case too, for the same reason.
890
+ const height = Math.max(0, config.height - this.reservedHeight);
842
891
  if (!config.heightFull) {
843
892
  return height;
844
893
  }
@@ -990,8 +1039,9 @@ class BarHorizontalChartBuilder extends PcacChart {
990
1039
  config.data[0].data.map((d) => {
991
1040
  return d.value;
992
1041
  });
1042
+ // Bars grow from 0, so only `domainMax` is read; `xAxis.domainMin` is ignored.
993
1043
  this.xScale = scaleLinear()
994
- .domain([0, config.domainMax]);
1044
+ .domain([0, this.xAxis.domainMax]);
995
1045
  this.yScaleStacked = scaleBand()
996
1046
  .domain(config.data.map((d) => d.key))
997
1047
  .range([this.height, 0])
@@ -1008,7 +1058,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1008
1058
  }
1009
1059
  drawChart(chartElm, config) {
1010
1060
  this.buildContainer(chartElm);
1011
- this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScale, this.yScaleStacked, config.tickFormat || PcacFormatEnum.None, PcacFormatEnum.None));
1061
+ this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScale, this.yScaleStacked));
1012
1062
  this.drawGrids(this.xScale, this.yScaleStacked);
1013
1063
  this.addGroups(config);
1014
1064
  this.axisBuilder.raiseAxes(this.svg);
@@ -1092,7 +1142,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1092
1142
  .on('mousemove', function (event, d) {
1093
1143
  const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
1094
1144
  const index = Number(this.getAttribute('data-group-bar-id'));
1095
- self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: config.tickFormat || PcacFormatEnum.None });
1145
+ self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.xAxis.format });
1096
1146
  })
1097
1147
  .on('mouseout', function () {
1098
1148
  self.hideTooltip();
@@ -1124,7 +1174,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1124
1174
  return i;
1125
1175
  })
1126
1176
  .on('mousemove', (event) => {
1127
- this.showTooltip(event, config.thresholds[0], { index: 0, isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
1177
+ this.showTooltip(event, config.thresholds[0], { index: 0, isThreshold: true, valueFormat: this.xAxis.format });
1128
1178
  })
1129
1179
  .transition()
1130
1180
  .duration(this.transitionService.getTransitionDuration())
@@ -1144,7 +1194,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1144
1194
  const threshold = config.thresholds[index];
1145
1195
  // A threshold's own PcacData is typically just a value, so its parent is the *data* group
1146
1196
  // 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: config.tickFormat || PcacFormatEnum.None });
1197
+ self.showTooltip(event, config.isStacked ? threshold.data[0] : threshold, { index, parent: config.data[index], parentIndex: index, isThreshold: true, valueFormat: self.xAxis.format });
1148
1198
  })
1149
1199
  .transition()
1150
1200
  .duration(this.transitionService.getTransitionDuration())
@@ -1164,7 +1214,7 @@ class BarHorizontalChartBuilder extends PcacChart {
1164
1214
  const index = Number(target.getAttribute("data-group-threshold-id"));
1165
1215
  const groupIndex = Number(this.parentElement.dataset['groupId']);
1166
1216
  // 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: config.tickFormat || PcacFormatEnum.None });
1217
+ self.showTooltip(event, config.thresholds[groupIndex].data[index], { index, parent: config.data[groupIndex], parentIndex: groupIndex, isThreshold: true, valueFormat: self.xAxis.format });
1168
1218
  })
1169
1219
  .transition()
1170
1220
  .duration(this.transitionService.getTransitionDuration())
@@ -1280,6 +1330,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
1280
1330
  * <div class="my-tooltip">{{ orders[g!][i].customer }}: {{ point.value | number }}</div>
1281
1331
  * </ng-template>
1282
1332
  * ```
1333
+ *
1334
+ * `coincident` lists the other points at the hovered coordinate, each located the same way:
1335
+ *
1336
+ * ```html
1337
+ * <ng-template pcacTooltip let-point let-others="coincident">
1338
+ * <div class="my-tooltip">
1339
+ * {{ point.key }}, {{ point.value }}
1340
+ * @for (other of others; track other.parentIndex) { <div>Also here: {{ other.parent.key }}</div> }
1341
+ * </div>
1342
+ * </ng-template>
1343
+ * ```
1283
1344
  */
1284
1345
  class PcacTooltipDirective {
1285
1346
  templateRef = inject(TemplateRef);
@@ -1345,10 +1406,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
1345
1406
  }], 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
1407
 
1347
1408
  class PcacBarHorizontalChartConfig extends PcacAxisChartConfig {
1348
- domainMax = 100;
1349
1409
  isStacked = false;
1350
1410
  thresholds = [];
1351
- tickFormat = PcacFormatEnum.None;
1352
1411
  spreadColorsPerGroup = false;
1353
1412
  colorOverride = new PcacBarHorizontalChartColorOverrideConfig();
1354
1413
  }
@@ -1391,9 +1450,10 @@ class BarVerticalChartBuilder extends PcacChart {
1391
1450
  buildScales(config) {
1392
1451
  // `this.height`, not `config.height`: with `heightFull` on they differ (see
1393
1452
  // PcacChart.resolveHeight), and the axis, grid and bar baselines all use the resolved one.
1453
+ // Bars grow from 0, so only `domainMax` is read; `yAxis.domainMin` is ignored.
1394
1454
  this.yScale = scaleLinear()
1395
1455
  .rangeRound([0, this.height])
1396
- .domain([config.domainMax, 0]);
1456
+ .domain([this.yAxis.domainMax, 0]);
1397
1457
  this.xScaleStacked = scaleBand()
1398
1458
  .domain(config.data.map((d) => d.key))
1399
1459
  .rangeRound([0, this.width])
@@ -1405,7 +1465,7 @@ class BarVerticalChartBuilder extends PcacChart {
1405
1465
  }
1406
1466
  drawChart(chartElm, config) {
1407
1467
  this.buildContainer(chartElm);
1408
- this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScaleStacked, this.yScale, PcacFormatEnum.None, config.tickFormat || PcacFormatEnum.None));
1468
+ this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScaleStacked, this.yScale));
1409
1469
  this.drawGrids(this.xScaleStacked, this.yScale);
1410
1470
  this.addGroups(config);
1411
1471
  this.axisBuilder.raiseAxes(this.svg);
@@ -1492,7 +1552,7 @@ class BarVerticalChartBuilder extends PcacChart {
1492
1552
  .on('mousemove', function (event, d) {
1493
1553
  const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
1494
1554
  const index = Number(this.getAttribute('data-group-bar-id'));
1495
- self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: config.tickFormat || PcacFormatEnum.None });
1555
+ self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.yAxis.format });
1496
1556
  })
1497
1557
  .on('mouseout', function () {
1498
1558
  self.hideTooltip();
@@ -1531,7 +1591,7 @@ class BarVerticalChartBuilder extends PcacChart {
1531
1591
  return i;
1532
1592
  })
1533
1593
  .on('mousemove', (event) => {
1534
- this.showTooltip(event, config.thresholds[0], { index: 0, isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
1594
+ this.showTooltip(event, config.thresholds[0], { index: 0, isThreshold: true, valueFormat: this.yAxis.format });
1535
1595
  })
1536
1596
  .transition()
1537
1597
  .duration(this.transitionService.getTransitionDuration())
@@ -1551,7 +1611,7 @@ class BarVerticalChartBuilder extends PcacChart {
1551
1611
  const threshold = config.thresholds[index];
1552
1612
  // A threshold's own PcacData is typically just a value, so its parent is the *data* group
1553
1613
  // 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: config.tickFormat || PcacFormatEnum.None });
1614
+ self.showTooltip(event, config.isStacked ? threshold.data[0] : threshold, { index, parent: config.data[index], parentIndex: index, isThreshold: true, valueFormat: self.yAxis.format });
1555
1615
  })
1556
1616
  .transition()
1557
1617
  .duration(this.transitionService.getTransitionDuration())
@@ -1570,7 +1630,7 @@ class BarVerticalChartBuilder extends PcacChart {
1570
1630
  const index = Number(target.getAttribute("data-group-threshold-id"));
1571
1631
  const groupIndex = Number(this.parentElement.dataset['groupId']);
1572
1632
  // 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: config.tickFormat || PcacFormatEnum.None });
1633
+ self.showTooltip(event, config.thresholds[groupIndex].data[index], { index, parent: config.data[groupIndex], parentIndex: groupIndex, isThreshold: true, valueFormat: self.yAxis.format });
1574
1634
  })
1575
1635
  .attr('width', this.xScaleGrouped.bandwidth())
1576
1636
  .transition()
@@ -1660,10 +1720,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
1660
1720
  }], 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
1721
 
1662
1722
  class PcacBarVerticalChartConfig extends PcacAxisChartConfig {
1663
- domainMax = 100;
1664
1723
  isStacked = false;
1665
1724
  thresholds = [];
1666
- tickFormat = PcacFormatEnum.None;
1667
1725
  spreadColorsPerGroup = false;
1668
1726
  colorOverride = new PcacBarVerticalChartColorOverrideConfig();
1669
1727
  }
@@ -1715,15 +1773,18 @@ class PcacPointImageConfig {
1715
1773
  maxWidth = 16;
1716
1774
  maxHeight = 16;
1717
1775
  }
1776
+ /**
1777
+ * The axes' `format` and `domainMin`/`domainMax` (`PcacAxisConfig`) do more here than on the bar
1778
+ * charts. `yAxis.domainMin`/`domainMax` are the y scale's domain (default 0..100). `xAxis.format`
1779
+ * decides how each point's `key` becomes an x position: `Decimal` reads it as a number on a
1780
+ * linear scale from `xAxis.domainMin` to `domainMax`, `DateTime` parses it with `new Date()` on
1781
+ * a time scale between the two (both required), and every other format - including the default -
1782
+ * places points by their index within their series, sizing the axis from the first series'
1783
+ * length and ignoring the domain fields.
1784
+ */
1718
1785
  class PcacLineAreaChartConfig extends PcacAxisChartConfig {
1719
1786
  enableEffects = true;
1720
1787
  enableZoom = true;
1721
- yFormat = PcacFormatEnum.DatasetLength;
1722
- xFormat = PcacFormatEnum.DatasetLength;
1723
- yDomainMax;
1724
- yDomainMin;
1725
- xDomainMin;
1726
- xDomainMax;
1727
1788
  /**
1728
1789
  * Hex color codes to override the default colors
1729
1790
  */
@@ -1880,46 +1941,80 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
1880
1941
  type: Injectable
1881
1942
  }] });
1882
1943
 
1944
+ /**
1945
+ * How the plot chart spreads out points that share a coordinate (see
1946
+ * `PcacPlotChartConfig.pointFanOut`). Each group of coincident points is placed evenly around
1947
+ * a ring centered on the shared coordinate, starting at 12 o'clock and going clockwise in data
1948
+ * order (series order, then point order), so every point stays visible and hoverable.
1949
+ */
1950
+ class PcacPointFanOutConfig {
1951
+ /**
1952
+ * Ring radius in px, the same for every group. When not set, each group gets the smallest
1953
+ * radius at which its neighbours sit `gap` px apart - so a pair barely moves while a group of
1954
+ * five spreads as far as it has to.
1955
+ */
1956
+ radius;
1957
+ /**
1958
+ * Space between neighbouring points on the ring, in px, when `radius` is not set. Measured
1959
+ * between their image boxes (or hovered dots), not their centers.
1960
+ */
1961
+ gap = 4;
1962
+ /**
1963
+ * Draw a dot at the shared coordinate - the value the group's points actually have - with a
1964
+ * spoke out to each of them. Styled by the theme's `.fan-out-anchor` / `.fan-out-spoke` rules.
1965
+ */
1966
+ showAnchor = true;
1967
+ }
1968
+ class PcacPlotChartConfig extends PcacLineAreaChartConfig {
1969
+ /**
1970
+ * Spread points that share a coordinate around it instead of drawing them on top of one
1971
+ * another (where only the last series' point shows, and only it can be hovered). Off when not
1972
+ * set; `{}` turns it on with every `PcacPointFanOutConfig` default. The fanned points keep
1973
+ * their true value in the tooltip, and the hovered point's tooltip context lists the others at
1974
+ * its coordinate in `coincident` (see `PcacTooltipContext`).
1975
+ *
1976
+ * Plot chart only: a line or area chart's points are joined in series order, so moving one
1977
+ * would kink the line.
1978
+ */
1979
+ pointFanOut;
1980
+ }
1981
+
1883
1982
  class PlaChartScales {
1884
1983
  x;
1885
1984
  y;
1886
1985
  }
1986
+ /**
1987
+ * Takes the chart's *resolved* axes (`PcacChart.xAxis`/`yAxis`), not the raw config, so the
1988
+ * `format`/`domainMin`/`domainMax` defaults are already applied - see `PcacLineAreaChartConfig`
1989
+ * for what each format does with them.
1990
+ */
1887
1991
  class PlaChartScalesBuilder {
1888
- build(config, chartWidth, chartHeight) {
1992
+ build(xAxis, yAxis, data, chartWidth, chartHeight) {
1889
1993
  const resp = new PlaChartScales();
1890
- resp.x = this.buildXScale(config, chartWidth);
1891
- resp.y = this.buildYScale(config, chartHeight);
1994
+ resp.x = this.buildXScale(xAxis, data, chartWidth);
1995
+ resp.y = this.buildYScale(yAxis, chartHeight);
1892
1996
  return resp;
1893
1997
  }
1894
- buildXScale(config, chartWidth) {
1895
- let resp;
1896
- switch (config.xFormat) {
1998
+ buildXScale(xAxis, data, chartWidth) {
1999
+ switch (xAxis.format) {
1897
2000
  case PcacFormatEnum.DateTime:
1898
- resp = scaleTime()
1899
- .domain([new Date(config.xDomainMin), new Date(config.xDomainMax)])
2001
+ return scaleTime()
2002
+ .domain([new Date(xAxis.domainMin), new Date(xAxis.domainMax)])
1900
2003
  .range([0, chartWidth]);
1901
- break;
1902
2004
  case PcacFormatEnum.Decimal:
1903
- resp = scaleLinear()
1904
- .domain([config.xDomainMin || 0, config.xDomainMax || 100])
1905
- .range([0, chartWidth]);
1906
- break;
1907
- case PcacFormatEnum.DatasetLength:
1908
- resp = scaleLinear()
1909
- .domain([0, config.data[0].data.length - 1])
2005
+ return scaleLinear()
2006
+ .domain([xAxis.domainMin, xAxis.domainMax])
1910
2007
  .range([0, chartWidth]);
1911
- break;
1912
2008
  default:
1913
- resp = scaleLinear()
1914
- .domain([0, config.data[0].data.length - 1])
2009
+ // DatasetLength and every other format position points by index
2010
+ return scaleLinear()
2011
+ .domain([0, data[0].data.length - 1])
1915
2012
  .range([0, chartWidth]);
1916
- break;
1917
2013
  }
1918
- return resp;
1919
2014
  }
1920
- buildYScale(config, chartHeight) {
2015
+ buildYScale(yAxis, chartHeight) {
1921
2016
  return scaleLinear()
1922
- .domain([config.yDomainMin || 0, config.yDomainMax || 100])
2017
+ .domain([yAxis.domainMin, yAxis.domainMax])
1923
2018
  .range([chartHeight, 0]);
1924
2019
  }
1925
2020
  }
@@ -1962,13 +2057,96 @@ function buildAreaGenerator(format, scales, chartHeight) {
1962
2057
  });
1963
2058
  }
1964
2059
 
2060
+ /**
2061
+ * `extent` (the viewport the gesture happens in) is set to the plot area explicitly rather than
2062
+ * left to d3's default, which reads the *owning `<svg>`'s* size - plot plus margins. With the
2063
+ * viewport wider than `translateExtent`, d3's constraint centers the plot within it instead of
2064
+ * pinning the two together, so the first gesture (even one that zooms straight back out to k = 1)
2065
+ * left the chart shifted right/down by half the margins: x domain min detached from the y axis,
2066
+ * domain max pushed off the right edge.
2067
+ */
1965
2068
  function buildZoomBehavior(width, height, zoomedFn) {
1966
2069
  return zoom()
1967
2070
  .scaleExtent([1, 10])
2071
+ .extent([[0, 0], [width, height]])
1968
2072
  .translateExtent([[0, 0], [width, height]])
1969
2073
  .on("zoom", zoomedFn);
1970
2074
  }
1971
2075
 
2076
+ /**
2077
+ * Finds every set of points that share a coordinate across all of the chart's visible series.
2078
+ * Coincidence is decided from the data rather than from scaled pixels, so this can run before
2079
+ * the scales exist (the space the fan-out needs has to be reserved before the plot area, and so
2080
+ * the scales, is sized): two points coincide when they have the same y `value` and the same x
2081
+ * position under `xFormat` - the same numeric `key` (`Decimal`), the same instant (`DateTime`), or
2082
+ * the same index within their series (every other format, which positions by index). Mirrors
2083
+ * `getXFormat()`, which is what actually places them. Hidden series and points without a value
2084
+ * are left out, as they aren't drawn.
2085
+ */
2086
+ function findCoincidentGroups(series, xFormat) {
2087
+ const byPosition = new Map();
2088
+ series.forEach((s, seriesIndex) => {
2089
+ if (s.hide) {
2090
+ return;
2091
+ }
2092
+ s.data.forEach((data, index) => {
2093
+ if (data.value === null || data.value === undefined) {
2094
+ return;
2095
+ }
2096
+ const key = `${xPositionKey(xFormat, data, index)}|${data.value}`;
2097
+ let members = byPosition.get(key);
2098
+ if (!members) {
2099
+ members = [];
2100
+ byPosition.set(key, members);
2101
+ }
2102
+ members.push({ data, series: s, index, seriesIndex });
2103
+ });
2104
+ });
2105
+ return Array.from(byPosition.values())
2106
+ .filter((members) => members.length > 1)
2107
+ .map((members) => ({ members }));
2108
+ }
2109
+ function xPositionKey(xFormat, data, index) {
2110
+ switch (xFormat) {
2111
+ case PcacFormatEnum.DateTime:
2112
+ return data.key ? new Date(data.key).getTime() : 'none';
2113
+ case PcacFormatEnum.Decimal:
2114
+ return data.key ? Number(data.key) : 'none';
2115
+ default:
2116
+ return index;
2117
+ }
2118
+ }
2119
+ /**
2120
+ * The smallest ring radius at which `count` marks of `size` px sit `gap` px apart from their
2121
+ * neighbours: the chord between adjacent ring positions is `2r sin(π/n)`, so solve it for
2122
+ * `size + gap`. A pair (n = 2) lands `size + gap` apart along a diameter, as expected.
2123
+ */
2124
+ function fanOutRadius(count, size, gap) {
2125
+ return (size + gap) / (2 * Math.sin(Math.PI / count));
2126
+ }
2127
+ /**
2128
+ * Places each group's members evenly around a ring centered on their shared coordinate, the
2129
+ * first member at 12 o'clock and the rest clockwise. `radius` is called per group so it can
2130
+ * depend on the group's size (see `fanOutRadius`). Keyed by the point objects themselves,
2131
+ * which are the very elements the builder binds to the DOM, so lookups are exact.
2132
+ */
2133
+ function fanOutOffsets(groups, radius) {
2134
+ const offsets = new Map();
2135
+ for (const group of groups) {
2136
+ const r = radius(group);
2137
+ const n = group.members.length;
2138
+ group.members.forEach((member, i) => {
2139
+ const angle = -Math.PI / 2 + (i * 2 * Math.PI) / n;
2140
+ offsets.set(member.data, { dx: round(r * Math.cos(angle)), dy: round(r * Math.sin(angle)) });
2141
+ });
2142
+ }
2143
+ return offsets;
2144
+ }
2145
+ /** Two decimal places is plenty for an SVG coordinate and keeps `cos(π/2)` from reading as `6e-17`. */
2146
+ function round(value) {
2147
+ return Math.round(value * 100) / 100;
2148
+ }
2149
+
1972
2150
  /**
1973
2151
  * Provided per-component (see PcacLineAreaChartComponent's `providers`), not root-scoped: this
1974
2152
  * builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
@@ -1988,10 +2166,23 @@ class PlaChartBuilder extends PcacChart {
1988
2166
  * How far the clip-path rect extends past the drawable [0, width] x [0, height] area on every
1989
2167
  * side, so a point sitting exactly on the domain's edge isn't cut in half. 10px comfortably
1990
2168
  * 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.
2169
+ * buildChart() widens this to half the largest image dimension whenever any point has one
2170
+ * (and grows the margins to match - see `reservePointImageSpace()` - since the clip-path only
2171
+ * matters up to the edge of the SVG).
1992
2172
  */
1993
2173
  clipBuffer = 10;
1994
2174
  pointImage;
2175
+ /**
2176
+ * Points that share a coordinate, found by `resolvePointLayout()`. `coincidentOf` looks a
2177
+ * point's group up for its tooltip; the rest only matter when `fanOut` is on (plot chart with
2178
+ * `pointFanOut`): `fanOutOffsets` is where each member is drawn relative to its true position,
2179
+ * and `fanOutReach` how far the farthest one sits from it, for the edge space to reserve.
2180
+ */
2181
+ coincidentGroups = [];
2182
+ coincidentOf = new Map();
2183
+ fanOut = null;
2184
+ fanOutOffsets = new Map();
2185
+ fanOutReach = 0;
1995
2186
  dotClicked$ = this.dotClickedSource.asObservable();
1996
2187
  buildChart(chartElm, config, type) {
1997
2188
  if (!config?.data?.length) {
@@ -2006,6 +2197,8 @@ class PlaChartBuilder extends PcacChart {
2006
2197
  }));
2007
2198
  // A hidden axis keeps 8px rather than 0 so a dot on the edge of the plot isn't clipped
2008
2199
  this.initializeAxisState(this.config, 'y', 8);
2200
+ this.resolvePointLayout(type);
2201
+ this.reservePointSpace();
2009
2202
  if (!this.initializeChartState(chartElm, this.config)) {
2010
2203
  return;
2011
2204
  }
@@ -2015,35 +2208,34 @@ class PlaChartBuilder extends PcacChart {
2015
2208
  if (this.config.colorOverride?.length) {
2016
2209
  this.colors = this.config.colorOverride;
2017
2210
  }
2018
- this.pointImage = { ...new PcacPointImageConfig(), ...this.config.pointImage };
2019
- this.clipBuffer = this.config.data.some((series) => series.data.some((point) => !!point.image))
2020
- ? Math.max(10, Math.ceil(this.pointImage.maxWidth / 2), Math.ceil(this.pointImage.maxHeight / 2))
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);
2211
+ this.scales = new PlaChartScalesBuilder().build(this.xAxis, this.yAxis, this.config.data, this.width, this.height);
2212
+ this.lineGenerator = buildLineGenerator(this.xAxis.format, this.scales);
2213
+ this.areaGenerator = buildAreaGenerator(this.xAxis.format, this.scales, this.height);
2025
2214
  if (this.config.enableZoom) {
2026
2215
  this.zoomBehavior = buildZoomBehavior(this.width, this.height, (event) => {
2027
2216
  // Rescale x
2028
2217
  const newX = event.transform.rescaleX(this.scales.x);
2029
2218
  // Update axis
2030
- this.axisBuilder.drawXAxis(this.axisBuilderConfig(newX, this.scales.y, this.config.xFormat, this.config.yFormat));
2219
+ this.axisBuilder.drawXAxis(this.axisBuilderConfig(newX, this.scales.y));
2031
2220
  // Update lines/areas. Fresh generators against the rescaled x, so they go through the
2032
2221
  // same getXFormat() as the dots below - positioning by bare index here (which this used
2033
2222
  // to do, and which also overwrote the original generators' x accessor for good) is only
2034
2223
  // right for the default DatasetLength format; a DateTime/Decimal chart's lines drifted
2035
2224
  // away from its dots as soon as it was zoomed.
2036
2225
  const zoomedScales = { x: newX, y: this.scales.y };
2037
- const zoomedLine = buildLineGenerator(this.config.xFormat, zoomedScales);
2038
- const zoomedArea = buildAreaGenerator(this.config.xFormat, zoomedScales, this.height);
2226
+ const zoomedLine = buildLineGenerator(this.xAxis.format, zoomedScales);
2227
+ const zoomedArea = buildAreaGenerator(this.xAxis.format, zoomedScales, this.height);
2039
2228
  this.svg.selectAll('.line').attr('d', (d) => zoomedLine(d));
2040
2229
  this.svg.selectAll('.area').attr('d', (d) => zoomedArea(d));
2041
2230
  // 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 xFormat default
2231
+ // that `i` is the point's index *within its own series* - the x format default
2043
2232
  // (DatasetLength) positions by index, and a flat selection would number every series'
2044
2233
  // points consecutively, shoving the second series' points off to the right on zoom.
2045
2234
  this.svg.selectAll('.dots').selectAll('.point')
2046
2235
  .attr('transform', (d, i) => this.pointTransform(d, i, newX));
2236
+ // A fan-out's anchor is positioned like the points it belongs to, so it moves the same way.
2237
+ this.svg.selectAll('.fan-out')
2238
+ .attr('transform', (g) => this.fanOutTransform(g, newX));
2047
2239
  // The vertical grid hangs off the x ticks too, so redraw it against the rescaled x and
2048
2240
  // drop it back underneath everything (append puts it on top).
2049
2241
  this.svg.selectAll('.pcac-grid-vertical').remove();
@@ -2051,6 +2243,7 @@ class PlaChartBuilder extends PcacChart {
2051
2243
  this.svg.selectAll('.pcac-grid-vertical').lower();
2052
2244
  // drawXAxis re-appends the x axis at the end of the group, above the dots; put them back
2053
2245
  // on top so a point on the baseline isn't covered (see drawChart's draw order).
2246
+ this.svg.selectAll('.fan-outs').raise();
2054
2247
  this.svg.selectAll('.dots').raise();
2055
2248
  });
2056
2249
  }
@@ -2060,7 +2253,7 @@ class PlaChartBuilder extends PcacChart {
2060
2253
  this.buildContainer(chartElm);
2061
2254
  this.attachZoomBehavior();
2062
2255
  this.createReusableClipPath();
2063
- this.axisBuilder.drawAxis(this.axisBuilderConfig(this.scales.x, this.scales.y, config.xFormat, config.yFormat));
2256
+ this.axisBuilder.drawAxis(this.axisBuilderConfig(this.scales.x, this.scales.y));
2064
2257
  this.drawGrids(this.scales.x, this.scales.y);
2065
2258
  this.drawLineArea(config, type);
2066
2259
  if (config.enableEffects) {
@@ -2075,10 +2268,62 @@ class PlaChartBuilder extends PcacChart {
2075
2268
  });
2076
2269
  }
2077
2270
  // Axes above the lines/areas (so an axis line isn't covered by a series sitting at x = 0),
2078
- // but the dots above the axes: a point on the baseline or the y axis stays whole.
2271
+ // but the dots above the axes: a point on the baseline or the y axis stays whole. Fan-out
2272
+ // spokes go between the two so they run underneath the points they lead to.
2079
2273
  this.axisBuilder.raiseAxes(this.svg);
2274
+ this.drawFanOuts();
2080
2275
  this.drawDots(config);
2081
2276
  }
2277
+ /**
2278
+ * Resolves `pointImage`, finds the points that share a coordinate and, on a plot chart with
2279
+ * `pointFanOut`, works out where to draw each of them instead. Coincidence is found from the
2280
+ * data (see `findCoincidentGroups`) so this can run before the scales exist - it has to, as
2281
+ * `reservePointSpace()` needs the fan-out's reach before the plot area is sized. Line and area
2282
+ * charts still get the groups, for the tooltip's `coincident` list, but never an offset.
2283
+ */
2284
+ resolvePointLayout(type) {
2285
+ this.pointImage = { ...new PcacPointImageConfig(), ...this.config.pointImage };
2286
+ this.coincidentGroups = findCoincidentGroups(this.config.data, this.xAxis.format);
2287
+ this.coincidentOf = new Map(this.coincidentGroups.flatMap((group) => group.members.map((member) => [member.data, group])));
2288
+ const fanOut = type === PcacLineAreaPlotChartConfigType.Plot
2289
+ ? this.config.pointFanOut
2290
+ : undefined;
2291
+ if (!fanOut) {
2292
+ this.fanOut = null;
2293
+ this.fanOutOffsets = new Map();
2294
+ this.fanOutReach = 0;
2295
+ return;
2296
+ }
2297
+ this.fanOut = { ...new PcacPointFanOutConfig(), ...fanOut };
2298
+ // A group's members are kept apart by the size of what's drawn for them: the image box when
2299
+ // any member has an image, else a hovered dot (r = 6).
2300
+ const { maxWidth, maxHeight } = this.pointImage;
2301
+ const markSize = (group) => group.members.some((member) => !!member.data.image) ? Math.max(maxWidth, maxHeight) : 12;
2302
+ const radius = (group) => this.fanOut.radius ?? fanOutRadius(group.members.length, markSize(group), this.fanOut.gap);
2303
+ this.fanOutOffsets = fanOutOffsets(this.coincidentGroups, radius);
2304
+ this.fanOutReach = Math.ceil(Math.max(0, ...this.coincidentGroups.map(radius)));
2305
+ }
2306
+ /**
2307
+ * When any point has an `image`, or a fan-out has moved points off their coordinate, makes
2308
+ * room for them at the edge of the domain: the clip-path buffer grows to half the box (plus
2309
+ * the fan-out's reach) so the `.dots` group lets it through, and the margins grow to at least
2310
+ * that same amount so the `<svg>` doesn't cut off what the clip-path let through (an image box
2311
+ * is centered on its point, so at the top of the y domain half of it sits above the plot area
2312
+ * - in `margin.top`, which is only 8px by default). A fanned-out plain dot needs the same
2313
+ * treatment, its hovered radius plus the reach. Must run after `resolvePointLayout()` and
2314
+ * between `initializeAxisState()` and `initializeChartState()`, see `reserveEdgeSpace`.
2315
+ */
2316
+ reservePointSpace() {
2317
+ const hasImages = this.config.data.some((series) => series.data.some((point) => !!point.image));
2318
+ if (!hasImages && this.fanOutReach === 0) {
2319
+ this.clipBuffer = 10;
2320
+ return;
2321
+ }
2322
+ const halfWidth = (hasImages ? Math.ceil(this.pointImage.maxWidth / 2) : 6) + this.fanOutReach;
2323
+ const halfHeight = (hasImages ? Math.ceil(this.pointImage.maxHeight / 2) : 6) + this.fanOutReach;
2324
+ this.clipBuffer = Math.max(10, halfWidth, halfHeight);
2325
+ this.reserveEdgeSpace({ top: halfHeight, bottom: halfHeight, left: halfWidth, right: halfWidth });
2326
+ }
2082
2327
  createReusableClipPath() {
2083
2328
  this.clipPathId = `pcac-clip-${Date.now()}-${Math.floor(Math.random() * 10000)}`;
2084
2329
  this.svg.selectAll(`defs #${this.clipPathId}`).remove();
@@ -2160,13 +2405,51 @@ class PlaChartBuilder extends PcacChart {
2160
2405
  .duration(this.transitionService.getTransitionDuration())
2161
2406
  .attr('d', this.areaGenerator);
2162
2407
  }
2408
+ /**
2409
+ * Draws one `<g class="fan-outs">` holding a `<g class="fan-out">` per group of coincident
2410
+ * points: a spoke from the shared coordinate to where each member is drawn, and an anchor dot
2411
+ * on the coordinate itself. Only when the fan-out is on and asks for anchors. The group is
2412
+ * positioned by the same x translate as a point (see `drawDots`), so zoom moves it the same
2413
+ * way, and fades in over the points' own entry transition.
2414
+ */
2415
+ drawFanOuts() {
2416
+ if (!this.fanOut?.showAnchor || this.coincidentGroups.length === 0) {
2417
+ return;
2418
+ }
2419
+ const y = (group) => this.scales.y(group.members[0].data.value);
2420
+ const groups = this.svg.append('g')
2421
+ .attr('class', 'fan-outs')
2422
+ .attr('clip-path', `url(#${this.clipPathId})`)
2423
+ .selectAll('.fan-out')
2424
+ .data(this.coincidentGroups)
2425
+ .enter().append('g')
2426
+ .attr('class', 'fan-out')
2427
+ .attr('transform', (group) => this.fanOutTransform(group, this.scales.x));
2428
+ groups.selectAll('.fan-out-spoke')
2429
+ .data((group) => group.members.map((member) => ({ y: y(group), ...this.offsetOf(member.data) })))
2430
+ .enter().append('line')
2431
+ .attr('class', 'fan-out-spoke')
2432
+ .attr('x1', 0)
2433
+ .attr('y1', (spoke) => spoke.y)
2434
+ .attr('x2', (spoke) => spoke.dx)
2435
+ .attr('y2', (spoke) => spoke.y + spoke.dy);
2436
+ groups.append('circle')
2437
+ .attr('class', 'fan-out-anchor')
2438
+ .attr('cy', y)
2439
+ .attr('r', 3);
2440
+ groups.attr('opacity', 0)
2441
+ .transition()
2442
+ .duration(this.transitionService.getTransitionDuration())
2443
+ .attr('opacity', 1);
2444
+ }
2163
2445
  /**
2164
2446
  * Draws one `<g class="dots">` per series holding a `<g class="point">` per data point. The
2165
2447
  * point group carries the x position (as a translate) so that zoom only has to touch that one
2166
2448
  * attribute regardless of what's inside; the child is either the regular `<circle class="dot">`
2167
2449
  * or, when the point has a `PcacData.image`, an `<image class="dot-image">` in its place. Both
2168
2450
  * animate in from the baseline the same way, and the tooltip / click handlers sit on the group
2169
- * so they behave identically for either.
2451
+ * so they behave identically for either. A fanned-out point's offset is applied to the child,
2452
+ * inside the group, so it too is untouched by zoom.
2170
2453
  */
2171
2454
  drawDots(config) {
2172
2455
  const self = this;
@@ -2189,8 +2472,9 @@ class PlaChartBuilder extends PcacChart {
2189
2472
  index: series.data.indexOf(d),
2190
2473
  parent: series,
2191
2474
  parentIndex: index,
2192
- valueFormat: self.config.yFormat,
2193
- keyFormat: self.config.xFormat,
2475
+ coincident: self.coincidentWith(d),
2476
+ valueFormat: self.yAxis.format,
2477
+ keyFormat: self.xAxis.format,
2194
2478
  });
2195
2479
  // No-op for an image point (no circle inside to grow).
2196
2480
  select$1(this).select('.dot')
@@ -2214,11 +2498,12 @@ class PlaChartBuilder extends PcacChart {
2214
2498
  .append('circle')
2215
2499
  .attr('class', 'dot')
2216
2500
  .attr('stroke', this.colors[index])
2501
+ .attr('cx', (d) => this.offsetOf(d).dx)
2217
2502
  .attr('cy', this.scales.y(0))
2218
2503
  .attr('fill', '#fff')
2219
2504
  .transition()
2220
2505
  .duration(duration)
2221
- .attr('cy', (d) => this.scales.y(d.value))
2506
+ .attr('cy', (d) => this.scales.y(d.value) + this.offsetOf(d).dy)
2222
2507
  .attr('r', 4);
2223
2508
  // `preserveAspectRatio="xMidYMid meet"` is what does the "resize to fit" - the image is
2224
2509
  // scaled uniformly to fit inside the maxWidth x maxHeight box and centered within it, so
@@ -2231,15 +2516,33 @@ class PlaChartBuilder extends PcacChart {
2231
2516
  .attr('width', maxWidth)
2232
2517
  .attr('height', maxHeight)
2233
2518
  .attr('preserveAspectRatio', 'xMidYMid meet')
2234
- .attr('x', -maxWidth / 2)
2519
+ .attr('x', (d) => -maxWidth / 2 + this.offsetOf(d).dx)
2235
2520
  .attr('y', this.scales.y(0) - maxHeight / 2)
2236
2521
  .transition()
2237
2522
  .duration(duration)
2238
- .attr('y', (d) => this.scales.y(d.value) - maxHeight / 2);
2523
+ .attr('y', (d) => this.scales.y(d.value) - maxHeight / 2 + this.offsetOf(d).dy);
2239
2524
  }
2240
2525
  }
2241
2526
  pointTransform(d, i, xScale) {
2242
- return `translate(${getXFormat(this.config.xFormat, d, i, xScale)}, 0)`;
2527
+ return `translate(${getXFormat(this.xAxis.format, d, i, xScale)}, 0)`;
2528
+ }
2529
+ /** A fan-out sits where its members would have been drawn; any member locates it. */
2530
+ fanOutTransform(group, xScale) {
2531
+ const { data, index } = group.members[0];
2532
+ return this.pointTransform(data, index, xScale);
2533
+ }
2534
+ offsetOf(d) {
2535
+ return this.fanOutOffsets.get(d) ?? { dx: 0, dy: 0 };
2536
+ }
2537
+ /** The other points at `d`'s coordinate, for the tooltip context (see `PcacTooltipContext.coincident`). */
2538
+ coincidentWith(d) {
2539
+ const group = this.coincidentOf.get(d);
2540
+ if (!group) {
2541
+ return [];
2542
+ }
2543
+ return group.members
2544
+ .filter((member) => member.data !== d)
2545
+ .map((member) => ({ data: member.data, parent: member.series, index: member.index, parentIndex: member.seriesIndex }));
2243
2546
  }
2244
2547
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: PlaChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
2245
2548
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: PlaChartBuilder });
@@ -2293,11 +2596,11 @@ class PcacLineAreaChartComponent {
2293
2596
  }
2294
2597
  }
2295
2598
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: PcacLineAreaChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2296
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.1.6", type: PcacLineAreaChartComponent, isStandalone: true, selector: "pcac-line-area-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: true, transformFunction: null }, tooltipTemplate: { classPropertyName: "tooltipTemplate", publicName: "tooltipTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [PlaChartBuilder, PlaChartEffectsBuilder], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, template: "<section class=\"pcac-line-area-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-line-area-chart svg{width:100%;display:block}.pcac-line-area-chart .dot{stroke-width:2px}.pcac-line-area-chart .effects-canvas{fill:none}.pcac-line-area-chart .effect-line{stroke:#ced4da;stroke-width:1px;opacity:0}.pcac-line-area-chart .effect-circle{stroke-width:1px;fill:none;opacity:0}.pcac-line-area-chart .effect-text{font-size:11px;font-weight:700;fill:#343a40}pcac-line-chart.pcac-height-full,pcac-area-chart.pcac-height-full,pcac-plot-chart.pcac-height-full,pcac-line-area-chart.pcac-height-full{display:block;height:100%}pcac-line-area-chart.pcac-height-full .pcac-line-area-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
2599
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.1.6", type: PcacLineAreaChartComponent, isStandalone: true, selector: "pcac-line-area-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: true, transformFunction: null }, tooltipTemplate: { classPropertyName: "tooltipTemplate", publicName: "tooltipTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [PlaChartBuilder, PlaChartEffectsBuilder], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, template: "<section class=\"pcac-line-area-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-line-area-chart svg{width:100%;display:block}.pcac-line-area-chart .dot{stroke-width:2px}.pcac-line-area-chart .fan-out-spoke{stroke:#ced4da;stroke-width:1px}.pcac-line-area-chart .fan-out-anchor{fill:#6c757d}.pcac-line-area-chart .effects-canvas{fill:none}.pcac-line-area-chart .effect-line{stroke:#ced4da;stroke-width:1px;opacity:0}.pcac-line-area-chart .effect-circle{stroke-width:1px;fill:none;opacity:0}.pcac-line-area-chart .effect-text{font-size:11px;font-weight:700;fill:#343a40}pcac-line-chart.pcac-height-full,pcac-area-chart.pcac-height-full,pcac-plot-chart.pcac-height-full,pcac-line-area-chart.pcac-height-full{display:block;height:100%}pcac-line-area-chart.pcac-height-full .pcac-line-area-chart{height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
2297
2600
  }
2298
2601
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
2299
2602
  type: Component,
2300
- args: [{ selector: 'pcac-line-area-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [PlaChartBuilder, PlaChartEffectsBuilder], template: "<section class=\"pcac-line-area-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-line-area-chart svg{width:100%;display:block}.pcac-line-area-chart .dot{stroke-width:2px}.pcac-line-area-chart .effects-canvas{fill:none}.pcac-line-area-chart .effect-line{stroke:#ced4da;stroke-width:1px;opacity:0}.pcac-line-area-chart .effect-circle{stroke-width:1px;fill:none;opacity:0}.pcac-line-area-chart .effect-text{font-size:11px;font-weight:700;fill:#343a40}pcac-line-chart.pcac-height-full,pcac-area-chart.pcac-height-full,pcac-plot-chart.pcac-height-full,pcac-line-area-chart.pcac-height-full{display:block;height:100%}pcac-line-area-chart.pcac-height-full .pcac-line-area-chart{height:100%}\n"] }]
2603
+ args: [{ selector: 'pcac-line-area-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [PlaChartBuilder, PlaChartEffectsBuilder], template: "<section class=\"pcac-line-area-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-line-area-chart svg{width:100%;display:block}.pcac-line-area-chart .dot{stroke-width:2px}.pcac-line-area-chart .fan-out-spoke{stroke:#ced4da;stroke-width:1px}.pcac-line-area-chart .fan-out-anchor{fill:#6c757d}.pcac-line-area-chart .effects-canvas{fill:none}.pcac-line-area-chart .effect-line{stroke:#ced4da;stroke-width:1px;opacity:0}.pcac-line-area-chart .effect-circle{stroke-width:1px;fill:none;opacity:0}.pcac-line-area-chart .effect-text{font-size:11px;font-weight:700;fill:#343a40}pcac-line-chart.pcac-height-full,pcac-area-chart.pcac-height-full,pcac-plot-chart.pcac-height-full,pcac-line-area-chart.pcac-height-full{display:block;height:100%}pcac-line-area-chart.pcac-height-full .pcac-line-area-chart{height:100%}\n"] }]
2301
2604
  }], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }], tooltipTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipTemplate", required: false }] }] } });
2302
2605
 
2303
2606
  class PcacPlotChart {
@@ -2319,9 +2622,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
2319
2622
  args: [{ selector: 'pcac-plot-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, imports: [PcacLineAreaChartComponent], template: "<pcac-line-area-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Plot\" (dotClicked)=\"dotClicked.emit($event)\"/>" }]
2320
2623
  }], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], dotClicked: [{ type: i0.Output, args: ["dotClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
2321
2624
 
2322
- class PcacPlotChartConfig extends PcacLineAreaChartConfig {
2323
- }
2324
-
2325
2625
  class PcacLineChart {
2326
2626
  config = input.required(/* @ts-ignore */
2327
2627
  ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
@@ -2522,5 +2822,5 @@ class PcacPieChartConfig extends PcacChartConfig {
2522
2822
  * Generated bundle index. Do not edit.
2523
2823
  */
2524
2824
 
2525
- export { BarHorizontalChartBuilder, BarVerticalChartBuilder, PCAC_AXIS_LABEL_SPACE, PCAC_AXIS_SUB_LABEL_SPACE, PcacAreaChart, PcacAreaChartConfig, PcacAxisBuilder, PcacAxisChartConfig, PcacAxisConfig, PcacAxisSubLabels, PcacBarHorizontalChartColorOverrideConfig, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartColorOverrideConfig, PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChart, PcacChartConfig, PcacChartResizeService, PcacColorService, PcacData, PcacFormatEnum, PcacGridBuilder, PcacLegend, PcacLegendConfig, PcacLegendConfigItem, PcacLineChart, PcacLineChartConfig, PcacPieChartComponent, PcacPieChartConfig, PcacPlotChart, PcacPlotChartConfig, PcacPointImageConfig, PcacTooltipBuilder, PcacTooltipDirective, PcacTransitionService, PieChartBuilder, axisLabelSpace, hasAxisSubLabels, resolveAxisConfig };
2825
+ export { BarHorizontalChartBuilder, BarVerticalChartBuilder, PCAC_AXIS_LABEL_SPACE, PCAC_AXIS_SUB_LABEL_SPACE, PcacAreaChart, PcacAreaChartConfig, PcacAxisBuilder, PcacAxisChartConfig, PcacAxisConfig, PcacAxisSubLabels, PcacBarHorizontalChartColorOverrideConfig, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartColorOverrideConfig, PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChart, PcacChartConfig, PcacChartResizeService, PcacColorService, PcacData, PcacFormatEnum, PcacGridBuilder, PcacLegend, PcacLegendConfig, PcacLegendConfigItem, PcacLineChart, PcacLineChartConfig, PcacPieChartComponent, PcacPieChartConfig, PcacPlotChart, PcacPlotChartConfig, PcacPointFanOutConfig, PcacPointImageConfig, PcacTooltipBuilder, PcacTooltipDirective, PcacTransitionService, PieChartBuilder, axisLabelSpace, hasAxisSubLabels, resolveAxisConfig };
2526
2826
  //# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map