@pioneer-code/pioneer-charts 22.2.1 → 22.2.3

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.
@@ -232,6 +232,7 @@ class PcacAxisBuilder {
232
232
  drawYAxis(config) {
233
233
  if (config.yAxis.hide)
234
234
  return;
235
+ config.svg.selectAll('.pcac-y-axis').remove();
235
236
  const yAxis = axisLeft(config.yScale).ticks(config.yAxis.ticks);
236
237
  if (config.yAxis.tickSize !== undefined) {
237
238
  yAxis.tickSizeInner(config.yAxis.tickSize);
@@ -352,8 +353,8 @@ function gridLines(scale, numberOfTicks) {
352
353
  class PcacGridBuilder {
353
354
  /**
354
355
  * Vertical lines, one per x-axis tick (or category), running the plot's full height. The group
355
- * is classed `pcac-grid-vertical` so a chart can find and redraw just this grid - the
356
- * line/area/plot charts do on zoom, when the x ticks move.
356
+ * is classed `pcac-grid-vertical` (the horizontal one `pcac-grid-horizontal`) so a chart can
357
+ * find and redraw just one grid - the line/area/plot charts do on zoom, when an axis's ticks move.
357
358
  */
358
359
  drawVerticalGrid(config) {
359
360
  config.svg.append('g')
@@ -518,7 +519,7 @@ class PcacTooltipBuilder {
518
519
  * projected `pcacTooltip` template. This only ever renders the default content.
519
520
  */
520
521
  showBarTooltip(event, data, valueFormat, keyFormat) {
521
- this.showTooltip(event, undefined, { $implicit: data, parent: null, isThreshold: false, index: 0, parentIndex: null }, valueFormat, keyFormat);
522
+ this.showTooltip(event, undefined, { $implicit: data, parent: null, isThreshold: false, index: 0, parentIndex: null, coincident: [] }, valueFormat, keyFormat);
522
523
  }
523
524
  hideTooltip() {
524
525
  this.tooltip.style('display', 'none');
@@ -752,7 +753,7 @@ class PcacChart {
752
753
  /**
753
754
  * Draws whichever grids the resolved axes ask for: vertical lines from the x axis's ticks,
754
755
  * horizontal from the y's (`PcacAxisConfig.showGrid`). `which` restricts it to one axis - the
755
- * line/area/plot charts redraw just the x grid against the rescaled x on zoom.
756
+ * line/area/plot charts redraw just a zoomed axis's grid against its rescaled scale on zoom.
756
757
  */
757
758
  drawGrids(xScale, yScale, which = 'both') {
758
759
  const base = { svg: this.svg, width: this.width, height: this.height, xScale, yScale };
@@ -835,6 +836,7 @@ class PcacChart {
835
836
  isThreshold: options.isThreshold ?? false,
836
837
  index: options.index,
837
838
  parentIndex: options.parentIndex ?? null,
839
+ coincident: options.coincident ?? [],
838
840
  }, options.valueFormat, options.keyFormat);
839
841
  }
840
842
  hideTooltip() {
@@ -1329,6 +1331,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
1329
1331
  * <div class="my-tooltip">{{ orders[g!][i].customer }}: {{ point.value | number }}</div>
1330
1332
  * </ng-template>
1331
1333
  * ```
1334
+ *
1335
+ * `coincident` lists the other points at the hovered coordinate, each located the same way:
1336
+ *
1337
+ * ```html
1338
+ * <ng-template pcacTooltip let-point let-others="coincident">
1339
+ * <div class="my-tooltip">
1340
+ * {{ point.key }}, {{ point.value }}
1341
+ * @for (other of others; track other.parentIndex) { <div>Also here: {{ other.parent.key }}</div> }
1342
+ * </div>
1343
+ * </ng-template>
1344
+ * ```
1332
1345
  */
1333
1346
  class PcacTooltipDirective {
1334
1347
  templateRef = inject(TemplateRef);
@@ -1772,7 +1785,13 @@ class PcacPointImageConfig {
1772
1785
  */
1773
1786
  class PcacLineAreaChartConfig extends PcacAxisChartConfig {
1774
1787
  enableEffects = true;
1775
- enableZoom = true;
1788
+ /**
1789
+ * Zoom and pan along the x / y axis (scroll / pinch to zoom 1x-10x, drag to pan, never leaving
1790
+ * the original domain). Either, or both, can be on. A gesture is always two-dimensional, so with
1791
+ * only one enabled the other axis simply stays put. Both off by default.
1792
+ */
1793
+ enableZoomX = false;
1794
+ enableZoomY = false;
1776
1795
  /**
1777
1796
  * Hex color codes to override the default colors
1778
1797
  */
@@ -1815,6 +1834,16 @@ class PlaChartEffectsBuilder {
1815
1834
  this.buildCollection();
1816
1835
  this.buildCanvas();
1817
1836
  }
1837
+ /**
1838
+ * Swaps in the scales a zoom has rescaled. The crosshair finds its point by walking the line
1839
+ * geometry, which the chart already redraws on zoom, but the value it labels comes from
1840
+ * inverting `y` - so a y-axis zoom has to hand the zoomed scale over here or the label reads
1841
+ * the pixel against the original domain.
1842
+ */
1843
+ updateScales(x, y) {
1844
+ this.config.x = x;
1845
+ this.config.y = y;
1846
+ }
1818
1847
  buildCollection() {
1819
1848
  const collection = this.config.svg.append('g')
1820
1849
  .attr('class', 'effects');
@@ -1929,6 +1958,44 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
1929
1958
  type: Injectable
1930
1959
  }] });
1931
1960
 
1961
+ /**
1962
+ * How the plot chart spreads out points that share a coordinate (see
1963
+ * `PcacPlotChartConfig.pointFanOut`). Each group of coincident points is placed evenly around
1964
+ * a ring centered on the shared coordinate, starting at 12 o'clock and going clockwise in data
1965
+ * order (series order, then point order), so every point stays visible and hoverable.
1966
+ */
1967
+ class PcacPointFanOutConfig {
1968
+ /**
1969
+ * Ring radius in px, the same for every group. When not set, each group gets the smallest
1970
+ * radius at which its neighbours sit `gap` px apart - so a pair barely moves while a group of
1971
+ * five spreads as far as it has to.
1972
+ */
1973
+ radius;
1974
+ /**
1975
+ * Space between neighbouring points on the ring, in px, when `radius` is not set. Measured
1976
+ * between their image boxes (or hovered dots), not their centers.
1977
+ */
1978
+ gap = 4;
1979
+ /**
1980
+ * Draw a dot at the shared coordinate - the value the group's points actually have - with a
1981
+ * spoke out to each of them. Styled by the theme's `.fan-out-anchor` / `.fan-out-spoke` rules.
1982
+ */
1983
+ showAnchor = true;
1984
+ }
1985
+ class PcacPlotChartConfig extends PcacLineAreaChartConfig {
1986
+ /**
1987
+ * Spread points that share a coordinate around it instead of drawing them on top of one
1988
+ * another (where only the last series' point shows, and only it can be hovered). Off when not
1989
+ * set; `{}` turns it on with every `PcacPointFanOutConfig` default. The fanned points keep
1990
+ * their true value in the tooltip, and the hovered point's tooltip context lists the others at
1991
+ * its coordinate in `coincident` (see `PcacTooltipContext`).
1992
+ *
1993
+ * Plot chart only: a line or area chart's points are joined in series order, so moving one
1994
+ * would kink the line.
1995
+ */
1996
+ pointFanOut;
1997
+ }
1998
+
1932
1999
  class PlaChartScales {
1933
2000
  x;
1934
2001
  y;
@@ -2023,6 +2090,80 @@ function buildZoomBehavior(width, height, zoomedFn) {
2023
2090
  .on("zoom", zoomedFn);
2024
2091
  }
2025
2092
 
2093
+ /**
2094
+ * Finds every set of points that share a coordinate across all of the chart's visible series.
2095
+ * Coincidence is decided from the data rather than from scaled pixels, so this can run before
2096
+ * the scales exist (the space the fan-out needs has to be reserved before the plot area, and so
2097
+ * the scales, is sized): two points coincide when they have the same y `value` and the same x
2098
+ * position under `xFormat` - the same numeric `key` (`Decimal`), the same instant (`DateTime`), or
2099
+ * the same index within their series (every other format, which positions by index). Mirrors
2100
+ * `getXFormat()`, which is what actually places them. Hidden series and points without a value
2101
+ * are left out, as they aren't drawn.
2102
+ */
2103
+ function findCoincidentGroups(series, xFormat) {
2104
+ const byPosition = new Map();
2105
+ series.forEach((s, seriesIndex) => {
2106
+ if (s.hide) {
2107
+ return;
2108
+ }
2109
+ s.data.forEach((data, index) => {
2110
+ if (data.value === null || data.value === undefined) {
2111
+ return;
2112
+ }
2113
+ const key = `${xPositionKey(xFormat, data, index)}|${data.value}`;
2114
+ let members = byPosition.get(key);
2115
+ if (!members) {
2116
+ members = [];
2117
+ byPosition.set(key, members);
2118
+ }
2119
+ members.push({ data, series: s, index, seriesIndex });
2120
+ });
2121
+ });
2122
+ return Array.from(byPosition.values())
2123
+ .filter((members) => members.length > 1)
2124
+ .map((members) => ({ members }));
2125
+ }
2126
+ function xPositionKey(xFormat, data, index) {
2127
+ switch (xFormat) {
2128
+ case PcacFormatEnum.DateTime:
2129
+ return data.key ? new Date(data.key).getTime() : 'none';
2130
+ case PcacFormatEnum.Decimal:
2131
+ return data.key ? Number(data.key) : 'none';
2132
+ default:
2133
+ return index;
2134
+ }
2135
+ }
2136
+ /**
2137
+ * The smallest ring radius at which `count` marks of `size` px sit `gap` px apart from their
2138
+ * neighbours: the chord between adjacent ring positions is `2r sin(π/n)`, so solve it for
2139
+ * `size + gap`. A pair (n = 2) lands `size + gap` apart along a diameter, as expected.
2140
+ */
2141
+ function fanOutRadius(count, size, gap) {
2142
+ return (size + gap) / (2 * Math.sin(Math.PI / count));
2143
+ }
2144
+ /**
2145
+ * Places each group's members evenly around a ring centered on their shared coordinate, the
2146
+ * first member at 12 o'clock and the rest clockwise. `radius` is called per group so it can
2147
+ * depend on the group's size (see `fanOutRadius`). Keyed by the point objects themselves,
2148
+ * which are the very elements the builder binds to the DOM, so lookups are exact.
2149
+ */
2150
+ function fanOutOffsets(groups, radius) {
2151
+ const offsets = new Map();
2152
+ for (const group of groups) {
2153
+ const r = radius(group);
2154
+ const n = group.members.length;
2155
+ group.members.forEach((member, i) => {
2156
+ const angle = -Math.PI / 2 + (i * 2 * Math.PI) / n;
2157
+ offsets.set(member.data, { dx: round(r * Math.cos(angle)), dy: round(r * Math.sin(angle)) });
2158
+ });
2159
+ }
2160
+ return offsets;
2161
+ }
2162
+ /** Two decimal places is plenty for an SVG coordinate and keeps `cos(π/2)` from reading as `6e-17`. */
2163
+ function round(value) {
2164
+ return Math.round(value * 100) / 100;
2165
+ }
2166
+
2026
2167
  /**
2027
2168
  * Provided per-component (see PcacLineAreaChartComponent's `providers`), not root-scoped: this
2028
2169
  * builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
@@ -2048,6 +2189,17 @@ class PlaChartBuilder extends PcacChart {
2048
2189
  */
2049
2190
  clipBuffer = 10;
2050
2191
  pointImage;
2192
+ /**
2193
+ * Points that share a coordinate, found by `resolvePointLayout()`. `coincidentOf` looks a
2194
+ * point's group up for its tooltip; the rest only matter when `fanOut` is on (plot chart with
2195
+ * `pointFanOut`): `fanOutOffsets` is where each member is drawn relative to its true position,
2196
+ * and `fanOutReach` how far the farthest one sits from it, for the edge space to reserve.
2197
+ */
2198
+ coincidentGroups = [];
2199
+ coincidentOf = new Map();
2200
+ fanOut = null;
2201
+ fanOutOffsets = new Map();
2202
+ fanOutReach = 0;
2051
2203
  dotClicked$ = this.dotClickedSource.asObservable();
2052
2204
  buildChart(chartElm, config, type) {
2053
2205
  if (!config?.data?.length) {
@@ -2062,7 +2214,8 @@ class PlaChartBuilder extends PcacChart {
2062
2214
  }));
2063
2215
  // A hidden axis keeps 8px rather than 0 so a dot on the edge of the plot isn't clipped
2064
2216
  this.initializeAxisState(this.config, 'y', 8);
2065
- this.reservePointImageSpace();
2217
+ this.resolvePointLayout(type);
2218
+ this.reservePointSpace();
2066
2219
  if (!this.initializeChartState(chartElm, this.config)) {
2067
2220
  return;
2068
2221
  }
@@ -2075,18 +2228,32 @@ class PlaChartBuilder extends PcacChart {
2075
2228
  this.scales = new PlaChartScalesBuilder().build(this.xAxis, this.yAxis, this.config.data, this.width, this.height);
2076
2229
  this.lineGenerator = buildLineGenerator(this.xAxis.format, this.scales);
2077
2230
  this.areaGenerator = buildAreaGenerator(this.xAxis.format, this.scales, this.height);
2078
- if (this.config.enableZoom) {
2231
+ if (this.zoomEnabled) {
2079
2232
  this.zoomBehavior = buildZoomBehavior(this.width, this.height, (event) => {
2080
- // Rescale x
2081
- const newX = event.transform.rescaleX(this.scales.x);
2082
- // Update axis
2083
- this.axisBuilder.drawXAxis(this.axisBuilderConfig(newX, this.scales.y));
2084
- // Update lines/areas. Fresh generators against the rescaled x, so they go through the
2085
- // same getXFormat() as the dots below - positioning by bare index here (which this used
2086
- // to do, and which also overwrote the original generators' x accessor for good) is only
2087
- // right for the default DatasetLength format; a DateTime/Decimal chart's lines drifted
2088
- // away from its dots as soon as it was zoomed.
2089
- const zoomedScales = { x: newX, y: this.scales.y };
2233
+ // A d3 zoom transform is always two-dimensional; only the enabled axes follow it and the
2234
+ // other keeps its original scale, so that component of the gesture is simply ignored.
2235
+ const newX = this.config.enableZoomX ? event.transform.rescaleX(this.scales.x) : this.scales.x;
2236
+ const newY = this.config.enableZoomY ? event.transform.rescaleY(this.scales.y) : this.scales.y;
2237
+ const zoomedScales = { x: newX, y: newY };
2238
+ // Update the zoomed axes, each with its grid: the grid hangs off the axis's ticks, so it
2239
+ // is redrawn against the rescaled scale and dropped back underneath everything (append
2240
+ // puts it on top).
2241
+ if (this.config.enableZoomX) {
2242
+ this.axisBuilder.drawXAxis(this.axisBuilderConfig(newX, newY));
2243
+ this.svg.selectAll('.pcac-grid-vertical').remove();
2244
+ this.drawGrids(newX, newY, 'x');
2245
+ }
2246
+ if (this.config.enableZoomY) {
2247
+ this.axisBuilder.drawYAxis(this.axisBuilderConfig(newX, newY));
2248
+ this.svg.selectAll('.pcac-grid-horizontal').remove();
2249
+ this.drawGrids(newX, newY, 'y');
2250
+ }
2251
+ this.svg.selectAll('.pcac-grid').lower();
2252
+ // Update lines/areas. Fresh generators against the rescaled scales, so they go through
2253
+ // the same getXFormat() as the dots below - positioning by bare index here (which this
2254
+ // used to do, and which also overwrote the original generators' x accessor for good) is
2255
+ // only right for the default DatasetLength format; a DateTime/Decimal chart's lines
2256
+ // drifted away from its dots as soon as it was zoomed.
2090
2257
  const zoomedLine = buildLineGenerator(this.xAxis.format, zoomedScales);
2091
2258
  const zoomedArea = buildAreaGenerator(this.xAxis.format, zoomedScales, this.height);
2092
2259
  this.svg.selectAll('.line').attr('d', (d) => zoomedLine(d));
@@ -2096,14 +2263,18 @@ class PlaChartBuilder extends PcacChart {
2096
2263
  // (DatasetLength) positions by index, and a flat selection would number every series'
2097
2264
  // points consecutively, shoving the second series' points off to the right on zoom.
2098
2265
  this.svg.selectAll('.dots').selectAll('.point')
2099
- .attr('transform', (d, i) => this.pointTransform(d, i, newX));
2100
- // The vertical grid hangs off the x ticks too, so redraw it against the rescaled x and
2101
- // drop it back underneath everything (append puts it on top).
2102
- this.svg.selectAll('.pcac-grid-vertical').remove();
2103
- this.drawGrids(newX, this.scales.y, 'x');
2104
- this.svg.selectAll('.pcac-grid-vertical').lower();
2105
- // drawXAxis re-appends the x axis at the end of the group, above the dots; put them back
2266
+ .attr('transform', (d, i) => this.pointTransform(d, i, zoomedScales));
2267
+ // A fan-out's anchor is positioned like the points it belongs to, so it moves the same way.
2268
+ this.svg.selectAll('.fan-out')
2269
+ .attr('transform', (g) => this.fanOutTransform(g, zoomedScales));
2270
+ // The hover crosshair walks the (already updated) line geometry, but reads its value back
2271
+ // off the y scale - which must be the zoomed one or the label is wrong.
2272
+ if (this.config.enableEffects) {
2273
+ this.effectsBuilder.updateScales(newX, newY);
2274
+ }
2275
+ // Redrawing an axis appends it at the end of the group, above the dots; put them back
2106
2276
  // on top so a point on the baseline isn't covered (see drawChart's draw order).
2277
+ this.svg.selectAll('.fan-outs').raise();
2107
2278
  this.svg.selectAll('.dots').raise();
2108
2279
  });
2109
2280
  }
@@ -2128,27 +2299,59 @@ class PlaChartBuilder extends PcacChart {
2128
2299
  });
2129
2300
  }
2130
2301
  // Axes above the lines/areas (so an axis line isn't covered by a series sitting at x = 0),
2131
- // but the dots above the axes: a point on the baseline or the y axis stays whole.
2302
+ // but the dots above the axes: a point on the baseline or the y axis stays whole. Fan-out
2303
+ // spokes go between the two so they run underneath the points they lead to.
2132
2304
  this.axisBuilder.raiseAxes(this.svg);
2305
+ this.drawFanOuts();
2133
2306
  this.drawDots(config);
2134
2307
  }
2135
2308
  /**
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`.
2309
+ * Resolves `pointImage`, finds the points that share a coordinate and, on a plot chart with
2310
+ * `pointFanOut`, works out where to draw each of them instead. Coincidence is found from the
2311
+ * data (see `findCoincidentGroups`) so this can run before the scales exist - it has to, as
2312
+ * `reservePointSpace()` needs the fan-out's reach before the plot area is sized. Line and area
2313
+ * charts still get the groups, for the tooltip's `coincident` list, but never an offset.
2142
2314
  */
2143
- reservePointImageSpace() {
2315
+ resolvePointLayout(type) {
2144
2316
  this.pointImage = { ...new PcacPointImageConfig(), ...this.config.pointImage };
2317
+ this.coincidentGroups = findCoincidentGroups(this.config.data, this.xAxis.format);
2318
+ this.coincidentOf = new Map(this.coincidentGroups.flatMap((group) => group.members.map((member) => [member.data, group])));
2319
+ const fanOut = type === PcacLineAreaPlotChartConfigType.Plot
2320
+ ? this.config.pointFanOut
2321
+ : undefined;
2322
+ if (!fanOut) {
2323
+ this.fanOut = null;
2324
+ this.fanOutOffsets = new Map();
2325
+ this.fanOutReach = 0;
2326
+ return;
2327
+ }
2328
+ this.fanOut = { ...new PcacPointFanOutConfig(), ...fanOut };
2329
+ // A group's members are kept apart by the size of what's drawn for them: the image box when
2330
+ // any member has an image, else a hovered dot (r = 6).
2331
+ const { maxWidth, maxHeight } = this.pointImage;
2332
+ const markSize = (group) => group.members.some((member) => !!member.data.image) ? Math.max(maxWidth, maxHeight) : 12;
2333
+ const radius = (group) => this.fanOut.radius ?? fanOutRadius(group.members.length, markSize(group), this.fanOut.gap);
2334
+ this.fanOutOffsets = fanOutOffsets(this.coincidentGroups, radius);
2335
+ this.fanOutReach = Math.ceil(Math.max(0, ...this.coincidentGroups.map(radius)));
2336
+ }
2337
+ /**
2338
+ * When any point has an `image`, or a fan-out has moved points off their coordinate, makes
2339
+ * room for them at the edge of the domain: the clip-path buffer grows to half the box (plus
2340
+ * the fan-out's reach) so the `.dots` group lets it through, and the margins grow to at least
2341
+ * that same amount so the `<svg>` doesn't cut off what the clip-path let through (an image box
2342
+ * is centered on its point, so at the top of the y domain half of it sits above the plot area
2343
+ * - in `margin.top`, which is only 8px by default). A fanned-out plain dot needs the same
2344
+ * treatment, its hovered radius plus the reach. Must run after `resolvePointLayout()` and
2345
+ * between `initializeAxisState()` and `initializeChartState()`, see `reserveEdgeSpace`.
2346
+ */
2347
+ reservePointSpace() {
2145
2348
  const hasImages = this.config.data.some((series) => series.data.some((point) => !!point.image));
2146
- if (!hasImages) {
2349
+ if (!hasImages && this.fanOutReach === 0) {
2147
2350
  this.clipBuffer = 10;
2148
2351
  return;
2149
2352
  }
2150
- const halfWidth = Math.ceil(this.pointImage.maxWidth / 2);
2151
- const halfHeight = Math.ceil(this.pointImage.maxHeight / 2);
2353
+ const halfWidth = (hasImages ? Math.ceil(this.pointImage.maxWidth / 2) : 6) + this.fanOutReach;
2354
+ const halfHeight = (hasImages ? Math.ceil(this.pointImage.maxHeight / 2) : 6) + this.fanOutReach;
2152
2355
  this.clipBuffer = Math.max(10, halfWidth, halfHeight);
2153
2356
  this.reserveEdgeSpace({ top: halfHeight, bottom: halfHeight, left: halfWidth, right: halfWidth });
2154
2357
  }
@@ -2166,8 +2369,11 @@ class PlaChartBuilder extends PcacChart {
2166
2369
  .attr('width', this.width + this.clipBuffer * 2)
2167
2370
  .attr('height', this.height + this.clipBuffer * 2);
2168
2371
  }
2372
+ get zoomEnabled() {
2373
+ return !!(this.config.enableZoomX || this.config.enableZoomY);
2374
+ }
2169
2375
  attachZoomBehavior() {
2170
- if (!this.config.enableZoom)
2376
+ if (!this.zoomEnabled)
2171
2377
  return;
2172
2378
  // Add a transparent rect to capture zoom events
2173
2379
  //
@@ -2233,18 +2439,58 @@ class PlaChartBuilder extends PcacChart {
2233
2439
  .duration(this.transitionService.getTransitionDuration())
2234
2440
  .attr('d', this.areaGenerator);
2235
2441
  }
2442
+ /**
2443
+ * Draws one `<g class="fan-outs">` holding a `<g class="fan-out">` per group of coincident
2444
+ * points: a spoke from the shared coordinate to where each member is drawn, and an anchor dot
2445
+ * on the coordinate itself. Only when the fan-out is on and asks for anchors. The group is
2446
+ * positioned by the same translate as a point (see `drawDots`), so zoom moves it the same
2447
+ * way and everything inside is relative to the coordinate; it fades in over the points' own
2448
+ * entry transition.
2449
+ */
2450
+ drawFanOuts() {
2451
+ if (!this.fanOut?.showAnchor || this.coincidentGroups.length === 0) {
2452
+ return;
2453
+ }
2454
+ const groups = this.svg.append('g')
2455
+ .attr('class', 'fan-outs')
2456
+ .attr('clip-path', `url(#${this.clipPathId})`)
2457
+ .selectAll('.fan-out')
2458
+ .data(this.coincidentGroups)
2459
+ .enter().append('g')
2460
+ .attr('class', 'fan-out')
2461
+ .attr('transform', (group) => this.fanOutTransform(group, this.scales));
2462
+ groups.selectAll('.fan-out-spoke')
2463
+ .data((group) => group.members.map((member) => this.offsetOf(member.data)))
2464
+ .enter().append('line')
2465
+ .attr('class', 'fan-out-spoke')
2466
+ .attr('x1', 0)
2467
+ .attr('y1', 0)
2468
+ .attr('x2', (spoke) => spoke.dx)
2469
+ .attr('y2', (spoke) => spoke.dy);
2470
+ groups.append('circle')
2471
+ .attr('class', 'fan-out-anchor')
2472
+ .attr('r', 3);
2473
+ groups.attr('opacity', 0)
2474
+ .transition()
2475
+ .duration(this.transitionService.getTransitionDuration())
2476
+ .attr('opacity', 1);
2477
+ }
2236
2478
  /**
2237
2479
  * Draws one `<g class="dots">` per series holding a `<g class="point">` per data point. The
2238
- * point group carries the x position (as a translate) so that zoom only has to touch that one
2239
- * attribute regardless of what's inside; the child is either the regular `<circle class="dot">`
2240
- * or, when the point has a `PcacData.image`, an `<image class="dot-image">` in its place. Both
2241
- * animate in from the baseline the same way, and the tooltip / click handlers sit on the group
2242
- * so they behave identically for either.
2480
+ * point group carries the position (as a translate) so that zoom, on either axis, only has to
2481
+ * touch that one attribute regardless of what's inside; the child is either the regular
2482
+ * `<circle class="dot">` or, when the point has a `PcacData.image`, an `<image class="dot-image">`
2483
+ * in its place, and sits at the group's origin. Both animate in from the baseline the same way
2484
+ * - the start is the baseline expressed relative to the point, since the group is already on
2485
+ * the point - and the tooltip / click handlers sit on the group so they behave identically for
2486
+ * either. A fanned-out point's offset is applied to the child, inside the group, so it too is
2487
+ * untouched by zoom.
2243
2488
  */
2244
2489
  drawDots(config) {
2245
2490
  const self = this;
2246
2491
  const duration = this.transitionService.getTransitionDuration();
2247
2492
  const { maxWidth, maxHeight } = this.pointImage;
2493
+ const rise = (d) => this.scales.y(0) - this.scales.y(d.value);
2248
2494
  for (let index = 0; index < config.data.length; index++) {
2249
2495
  const series = config.data[index];
2250
2496
  const points = this.svg.append('g')
@@ -2255,13 +2501,14 @@ class PlaChartBuilder extends PcacChart {
2255
2501
  .data(series.data)
2256
2502
  .enter().append('g')
2257
2503
  .attr('class', 'point')
2258
- .attr('transform', (d, i) => this.pointTransform(d, i, this.scales.x))
2504
+ .attr('transform', (d, i) => this.pointTransform(d, i, this.scales))
2259
2505
  .on('mouseover', function (event, d) {
2260
2506
  // `d` is the very element bound from `series.data` above, so identity lookup is exact.
2261
2507
  self.showTooltip(event, d, {
2262
2508
  index: series.data.indexOf(d),
2263
2509
  parent: series,
2264
2510
  parentIndex: index,
2511
+ coincident: self.coincidentWith(d),
2265
2512
  valueFormat: self.yAxis.format,
2266
2513
  keyFormat: self.xAxis.format,
2267
2514
  });
@@ -2287,16 +2534,18 @@ class PlaChartBuilder extends PcacChart {
2287
2534
  .append('circle')
2288
2535
  .attr('class', 'dot')
2289
2536
  .attr('stroke', this.colors[index])
2290
- .attr('cy', this.scales.y(0))
2537
+ .attr('cx', (d) => this.offsetOf(d).dx)
2538
+ .attr('cy', rise)
2291
2539
  .attr('fill', '#fff')
2292
2540
  .transition()
2293
2541
  .duration(duration)
2294
- .attr('cy', (d) => this.scales.y(d.value))
2542
+ .attr('cy', (d) => this.offsetOf(d).dy)
2295
2543
  .attr('r', 4);
2296
2544
  // `preserveAspectRatio="xMidYMid meet"` is what does the "resize to fit" - the image is
2297
2545
  // scaled uniformly to fit inside the maxWidth x maxHeight box and centered within it, so
2298
2546
  // a non-square image still lands centered on the point. x/y offset by half the box so the
2299
- // box (not its top-left corner) is centered on the data point, matching where a dot sits.
2547
+ // box (not its top-left corner) is centered on the point group's origin, matching where a
2548
+ // dot sits.
2300
2549
  points.filter((d) => !!d.image)
2301
2550
  .append('image')
2302
2551
  .attr('class', 'dot-image')
@@ -2304,15 +2553,33 @@ class PlaChartBuilder extends PcacChart {
2304
2553
  .attr('width', maxWidth)
2305
2554
  .attr('height', maxHeight)
2306
2555
  .attr('preserveAspectRatio', 'xMidYMid meet')
2307
- .attr('x', -maxWidth / 2)
2308
- .attr('y', this.scales.y(0) - maxHeight / 2)
2556
+ .attr('x', (d) => -maxWidth / 2 + this.offsetOf(d).dx)
2557
+ .attr('y', (d) => rise(d) - maxHeight / 2)
2309
2558
  .transition()
2310
2559
  .duration(duration)
2311
- .attr('y', (d) => this.scales.y(d.value) - maxHeight / 2);
2560
+ .attr('y', (d) => -maxHeight / 2 + this.offsetOf(d).dy);
2312
2561
  }
2313
2562
  }
2314
- pointTransform(d, i, xScale) {
2315
- return `translate(${getXFormat(this.xAxis.format, d, i, xScale)}, 0)`;
2563
+ pointTransform(d, i, scales) {
2564
+ return `translate(${getXFormat(this.xAxis.format, d, i, scales.x)}, ${scales.y(d.value)})`;
2565
+ }
2566
+ /** A fan-out sits where its members would have been drawn; any member locates it. */
2567
+ fanOutTransform(group, scales) {
2568
+ const { data, index } = group.members[0];
2569
+ return this.pointTransform(data, index, scales);
2570
+ }
2571
+ offsetOf(d) {
2572
+ return this.fanOutOffsets.get(d) ?? { dx: 0, dy: 0 };
2573
+ }
2574
+ /** The other points at `d`'s coordinate, for the tooltip context (see `PcacTooltipContext.coincident`). */
2575
+ coincidentWith(d) {
2576
+ const group = this.coincidentOf.get(d);
2577
+ if (!group) {
2578
+ return [];
2579
+ }
2580
+ return group.members
2581
+ .filter((member) => member.data !== d)
2582
+ .map((member) => ({ data: member.data, parent: member.series, index: member.index, parentIndex: member.seriesIndex }));
2316
2583
  }
2317
2584
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: PlaChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
2318
2585
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: PlaChartBuilder });
@@ -2366,11 +2633,11 @@ class PcacLineAreaChartComponent {
2366
2633
  }
2367
2634
  }
2368
2635
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: PcacLineAreaChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2369
- 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 });
2636
+ 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 });
2370
2637
  }
2371
2638
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
2372
2639
  type: Component,
2373
- 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"] }]
2640
+ 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"] }]
2374
2641
  }], 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 }] }] } });
2375
2642
 
2376
2643
  class PcacPlotChart {
@@ -2392,9 +2659,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
2392
2659
  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)\"/>" }]
2393
2660
  }], 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 }] }] } });
2394
2661
 
2395
- class PcacPlotChartConfig extends PcacLineAreaChartConfig {
2396
- }
2397
-
2398
2662
  class PcacLineChart {
2399
2663
  config = input.required(/* @ts-ignore */
2400
2664
  ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
@@ -2595,5 +2859,5 @@ class PcacPieChartConfig extends PcacChartConfig {
2595
2859
  * Generated bundle index. Do not edit.
2596
2860
  */
2597
2861
 
2598
- 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 };
2862
+ 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 };
2599
2863
  //# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map