@pioneer-code/pioneer-charts 22.1.4 → 22.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/pioneer-code-pioneer-charts.mjs +433 -170
- package/fesm2022/pioneer-code-pioneer-charts.mjs.map +1 -1
- package/package.json +1 -1
- package/scss/pioneer-charts.scss +24 -0
- package/themes/pioneer-charts.css +16 -0
- package/themes/pioneer-charts.min.css +1 -1
- package/types/pioneer-code-pioneer-charts.d.ts +288 -36
|
@@ -40,6 +40,123 @@ class PcacChartConfig {
|
|
|
40
40
|
*/
|
|
41
41
|
heightFull = false;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Up to three short labels placed along an axis by position rather than by value: `min` at its
|
|
45
|
+
* start, `mid` at its center, `max` at its end. Any subset can be given.
|
|
46
|
+
*/
|
|
47
|
+
class PcacAxisSubLabels {
|
|
48
|
+
min;
|
|
49
|
+
mid;
|
|
50
|
+
max;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Everything configurable about one axis. Used twice per chart, as `xAxis` and `yAxis` on
|
|
54
|
+
* `PcacAxisChartConfig`, so the two never drift apart and a new per-axis option lands in one place.
|
|
55
|
+
*
|
|
56
|
+
* Every field is optional so an object-literal / JSON config can give just the ones it cares
|
|
57
|
+
* about (or omit the axis entirely); the initializers apply to anything built with `new`, and
|
|
58
|
+
* `resolveAxisConfig()` fills the rest in for builders.
|
|
59
|
+
*/
|
|
60
|
+
class PcacAxisConfig {
|
|
61
|
+
/**
|
|
62
|
+
* Don't draw this axis at all (labels, tick marks, line), and give the margins it would have
|
|
63
|
+
* occupied back to the plot area. Hiding the y axis reclaims the left and top margins; hiding
|
|
64
|
+
* the x axis reclaims the bottom and right. The chart's total footprint doesn't change.
|
|
65
|
+
*/
|
|
66
|
+
hide = false;
|
|
67
|
+
/**
|
|
68
|
+
* Draw grid lines from this axis's ticks (or, on a category axis, from each category) across
|
|
69
|
+
* the plot: horizontal lines for the y axis, vertical for the x. Left unset, each chart keeps
|
|
70
|
+
* the grid it has always drawn - the y axis's on vertical bar and line/area/plot charts, the
|
|
71
|
+
* x axis's on the horizontal bar chart - and no other; set it to turn either grid on or off
|
|
72
|
+
* explicitly. Deliberately has no initializer, since "unset" is what carries the per-chart
|
|
73
|
+
* default.
|
|
74
|
+
*/
|
|
75
|
+
showGrid;
|
|
76
|
+
/**
|
|
77
|
+
* Requested number of ticks (D3's `ticks()` hint, so the actual count can differ slightly) -
|
|
78
|
+
* also the number of grid lines for this axis. Ignored by a category (band) axis, which has one
|
|
79
|
+
* tick per category. Default 5.
|
|
80
|
+
*/
|
|
81
|
+
ticks = 5;
|
|
82
|
+
/**
|
|
83
|
+
* Length in pixels of the small tick marks. Tick marks are not drawn at all unless this is set
|
|
84
|
+
* (the theme hides them, as it always has), so setting a size is also what turns them on; D3's
|
|
85
|
+
* default 6px is a sensible first value. `0` keeps them off but still pulls the labels in to
|
|
86
|
+
* the axis. Labels follow the marks (D3 places them at tick length + 3px), and the chart's
|
|
87
|
+
* margins grow or shrink by the same amount so the plot area makes room for them - a longer
|
|
88
|
+
* tick means a slightly smaller plot, never labels pushed off the edge. Only the per-tick marks
|
|
89
|
+
* change; the axis line's two end-caps keep their default length. Color comes from the theme
|
|
90
|
+
* (`.pcac-axis-tick-marks .tick line`, `$gray-900`, the same as the axis line).
|
|
91
|
+
*/
|
|
92
|
+
tickSize;
|
|
93
|
+
/**
|
|
94
|
+
* Draw a solid line along the axis itself (the full length of the axis, with D3's short
|
|
95
|
+
* end-caps). Off by default, as the theme has always hidden it. Color comes from the theme
|
|
96
|
+
* (`.pcac-axis-line .domain`, `$gray-900`).
|
|
97
|
+
*/
|
|
98
|
+
showLine = false;
|
|
99
|
+
/**
|
|
100
|
+
* A title for the whole axis (e.g. "Revenue ($)"), drawn centered along it just inside the
|
|
101
|
+
* chart's edge: below the tick labels for the x axis, rotated to read bottom-to-top left of
|
|
102
|
+
* them for the y axis. The chart's margin grows by `PcacChart.AXIS_LABEL_SPACE` to make room,
|
|
103
|
+
* shrinking the plot area the same way a longer tick does. Not drawn on a hidden axis. Styled
|
|
104
|
+
* by the theme's `.pcac-axis-label` rule.
|
|
105
|
+
*/
|
|
106
|
+
label;
|
|
107
|
+
/**
|
|
108
|
+
* Min / mid / max sub labels (e.g. "Low" / "Medium" / "High") in their own row just outside the
|
|
109
|
+
* tick labels, and inside the `label` if there is one: `min` left-aligned at the axis's start,
|
|
110
|
+
* `mid` centered, `max` right-aligned at its end, so they never spill past the axis. On the
|
|
111
|
+
* y axis they run bottom-to-top like the label, `min` at the bottom. The margin grows by
|
|
112
|
+
* `PcacChart.AXIS_SUB_LABEL_SPACE` when any is set, shrinking the plot area. Not drawn on a
|
|
113
|
+
* hidden axis. Styled by the theme's `.pcac-axis-sub-label` rule.
|
|
114
|
+
*/
|
|
115
|
+
subLabels;
|
|
116
|
+
}
|
|
117
|
+
/** True if `axis` has at least one sub label to draw (an empty `subLabels` object counts as none). */
|
|
118
|
+
function hasAxisSubLabels(axis) {
|
|
119
|
+
const sub = axis?.subLabels;
|
|
120
|
+
return !!sub && (!!sub.min || !!sub.mid || !!sub.max);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Room reserved in a margin for an axis `label`: the theme's 12px label plus a gap from the tick
|
|
124
|
+
* labels. Reserved on the side the label sits on (`bottom` for x, `left` for y), and taken out
|
|
125
|
+
* of the plot area, the same way a longer tick is. Change together with `.pcac-axis-label`.
|
|
126
|
+
*/
|
|
127
|
+
const PCAC_AXIS_LABEL_SPACE = 18;
|
|
128
|
+
/** Likewise for a row of `subLabels`: the theme's 11px text plus a gap (`.pcac-axis-sub-label`). */
|
|
129
|
+
const PCAC_AXIS_SUB_LABEL_SPACE = 16;
|
|
130
|
+
/**
|
|
131
|
+
* Total margin an axis's `label` and `subLabels` take on its side. `PcacChart` reserves it and
|
|
132
|
+
* the axis builder places the text by it, so the two stay in step.
|
|
133
|
+
*/
|
|
134
|
+
function axisLabelSpace(axis) {
|
|
135
|
+
return (axis?.label ? PCAC_AXIS_LABEL_SPACE : 0) + (hasAxisSubLabels(axis) ? PCAC_AXIS_SUB_LABEL_SPACE : 0);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @param showGridDefault what `showGrid` resolves to when the consumer left it unset - each chart
|
|
139
|
+
* passes `true` for the axis whose grid it has always drawn and `false` for the other.
|
|
140
|
+
*/
|
|
141
|
+
function resolveAxisConfig(axis, showGridDefault = false) {
|
|
142
|
+
const defaults = new PcacAxisConfig();
|
|
143
|
+
return {
|
|
144
|
+
hide: axis?.hide ?? defaults.hide,
|
|
145
|
+
showGrid: axis?.showGrid ?? showGridDefault,
|
|
146
|
+
ticks: axis?.ticks ?? defaults.ticks,
|
|
147
|
+
tickSize: axis?.tickSize,
|
|
148
|
+
showLine: axis?.showLine ?? defaults.showLine,
|
|
149
|
+
label: axis?.label,
|
|
150
|
+
subLabels: axis?.subLabels,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Base configuration for every chart that has an x and y axis (bar, line, area, plot - not pie).
|
|
155
|
+
*/
|
|
156
|
+
class PcacAxisChartConfig extends PcacChartConfig {
|
|
157
|
+
xAxis = new PcacAxisConfig();
|
|
158
|
+
yAxis = new PcacAxisConfig();
|
|
159
|
+
}
|
|
43
160
|
class PcacData {
|
|
44
161
|
key = null;
|
|
45
162
|
value = null;
|
|
@@ -78,10 +195,25 @@ class PcacAxisBuilder {
|
|
|
78
195
|
this.drawXAxis(config);
|
|
79
196
|
this.drawYAxis(config);
|
|
80
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Moves both axis groups to the end of the chart's `<g>`, so they paint over everything drawn
|
|
200
|
+
* since `drawAxis()`. Axes are drawn first (so scales and margins are settled before content),
|
|
201
|
+
* which leaves anything sitting at x = 0 - a line chart's first segment and dot, an area's fill,
|
|
202
|
+
* a horizontal bar chart's bars - painting over the y axis line. Builders call this after the
|
|
203
|
+
* content that should sit *under* the axes, and draw anything that should stay on top (the
|
|
204
|
+
* line/area/plot charts' dots) afterwards. Safe to sit above the hover/zoom overlay rects too,
|
|
205
|
+
* because the groups are `pointer-events: none` (set where each group is appended).
|
|
206
|
+
*/
|
|
207
|
+
raiseAxes(svg) {
|
|
208
|
+
svg.selectAll('.pcac-x-axis, .pcac-y-axis').raise();
|
|
209
|
+
}
|
|
81
210
|
drawYAxis(config) {
|
|
82
|
-
if (config.
|
|
211
|
+
if (config.yAxis.hide)
|
|
83
212
|
return;
|
|
84
|
-
const yAxis = axisLeft(config.yScale).ticks(config.
|
|
213
|
+
const yAxis = axisLeft(config.yScale).ticks(config.yAxis.ticks);
|
|
214
|
+
if (config.yAxis.tickSize !== undefined) {
|
|
215
|
+
yAxis.tickSizeInner(config.yAxis.tickSize);
|
|
216
|
+
}
|
|
85
217
|
if (config.yFormat) {
|
|
86
218
|
switch (config.yFormat) {
|
|
87
219
|
case PcacFormatEnum.Percentage:
|
|
@@ -95,15 +227,23 @@ class PcacAxisBuilder {
|
|
|
95
227
|
break;
|
|
96
228
|
}
|
|
97
229
|
}
|
|
98
|
-
config.svg.append('g')
|
|
230
|
+
const group = config.svg.append('g')
|
|
99
231
|
.attr('class', 'pcac-y-axis')
|
|
232
|
+
// Axes are raised above the interactive overlays (see raiseAxes) and take no mouse events
|
|
233
|
+
.attr('pointer-events', 'none')
|
|
234
|
+
.classed('pcac-axis-tick-marks', config.yAxis.tickSize !== undefined)
|
|
235
|
+
.classed('pcac-axis-line', config.yAxis.showLine)
|
|
100
236
|
.call(yAxis);
|
|
237
|
+
this.drawLabels(group, config.yAxis, { length: config.height, outer: config.margin.left, vertical: true });
|
|
101
238
|
}
|
|
102
239
|
drawXAxis(config) {
|
|
103
|
-
if (config.
|
|
240
|
+
if (config.xAxis.hide)
|
|
104
241
|
return;
|
|
105
242
|
config.svg.selectAll('.pcac-x-axis').remove();
|
|
106
|
-
const xAxis = axisBottom(config.xScale).ticks(config.
|
|
243
|
+
const xAxis = axisBottom(config.xScale).ticks(config.xAxis.ticks);
|
|
244
|
+
if (config.xAxis.tickSize !== undefined) {
|
|
245
|
+
xAxis.tickSizeInner(config.xAxis.tickSize);
|
|
246
|
+
}
|
|
107
247
|
if (config.xFormat) {
|
|
108
248
|
switch (config.xFormat) {
|
|
109
249
|
case PcacFormatEnum.Percentage:
|
|
@@ -128,10 +268,49 @@ class PcacAxisBuilder {
|
|
|
128
268
|
break;
|
|
129
269
|
}
|
|
130
270
|
}
|
|
131
|
-
config.svg.append('g')
|
|
271
|
+
const group = config.svg.append('g')
|
|
132
272
|
.attr('class', 'pcac-x-axis')
|
|
273
|
+
.attr('pointer-events', 'none')
|
|
274
|
+
.classed('pcac-axis-tick-marks', config.xAxis.tickSize !== undefined)
|
|
275
|
+
.classed('pcac-axis-line', config.xAxis.showLine)
|
|
133
276
|
.attr('transform', 'translate(0,' + config.height + ')')
|
|
134
277
|
.call(xAxis);
|
|
278
|
+
this.drawLabels(group, config.xAxis, { length: config.width, outer: config.margin.bottom, vertical: false });
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The axis `label` and `subLabels`. Both are placed by two distances: along the axis (0 at its
|
|
282
|
+
* start, `length` at its end - for the y axis, 0 is the bottom) and out from it, toward the
|
|
283
|
+
* chart's edge. The label goes at the very edge (`outer`, i.e. the margin), the sub-label row
|
|
284
|
+
* `PCAC_AXIS_LABEL_SPACE` inside that when there's a label. For the y axis the text is rotated
|
|
285
|
+
* to read bottom-to-top, which swaps the two: after `rotate(-90)` x runs up the axis (so the
|
|
286
|
+
* bottom is x = -length) and y runs left. `fill` is set explicitly because d3-axis puts
|
|
287
|
+
* `fill="none"` on the group; its own tick text does the same.
|
|
288
|
+
*/
|
|
289
|
+
drawLabels(group, axis, layout) {
|
|
290
|
+
const text = (cls, along, out, anchor, content) => {
|
|
291
|
+
group.append('text')
|
|
292
|
+
.attr('class', cls)
|
|
293
|
+
.attr('fill', 'currentColor')
|
|
294
|
+
.attr('text-anchor', anchor)
|
|
295
|
+
.attr('transform', layout.vertical ? 'rotate(-90)' : null)
|
|
296
|
+
.attr('x', layout.vertical ? along - layout.length : along)
|
|
297
|
+
.attr('y', layout.vertical ? -out : out)
|
|
298
|
+
.attr('dy', layout.vertical ? '1em' : '-0.35em')
|
|
299
|
+
.text(content);
|
|
300
|
+
};
|
|
301
|
+
if (axis.label) {
|
|
302
|
+
text('pcac-axis-label', layout.length / 2, layout.outer, 'middle', axis.label);
|
|
303
|
+
}
|
|
304
|
+
const sub = axis.subLabels;
|
|
305
|
+
if (sub) {
|
|
306
|
+
const edge = layout.outer - (axis.label ? PCAC_AXIS_LABEL_SPACE : 0);
|
|
307
|
+
if (sub.min)
|
|
308
|
+
text('pcac-axis-sub-label', 0, edge, 'start', sub.min);
|
|
309
|
+
if (sub.mid)
|
|
310
|
+
text('pcac-axis-sub-label', layout.length / 2, edge, 'middle', sub.mid);
|
|
311
|
+
if (sub.max)
|
|
312
|
+
text('pcac-axis-sub-label', layout.length, edge, 'end', sub.max);
|
|
313
|
+
}
|
|
135
314
|
}
|
|
136
315
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: PcacAxisBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
137
316
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.6", ngImport: i0, type: PcacAxisBuilder, providedIn: 'root' });
|
|
@@ -143,32 +322,47 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
|
|
|
143
322
|
}]
|
|
144
323
|
}] });
|
|
145
324
|
|
|
325
|
+
/** Where along its axis each grid line sits, in pixels. */
|
|
326
|
+
function gridLines(scale, numberOfTicks) {
|
|
327
|
+
if (typeof scale.ticks === 'function') {
|
|
328
|
+
return scale.ticks(numberOfTicks).map(d => scale(d) ?? 0);
|
|
329
|
+
}
|
|
330
|
+
const band = scale;
|
|
331
|
+
const half = typeof band.bandwidth === 'function' ? band.bandwidth() / 2 : 0;
|
|
332
|
+
return scale.domain().map(d => (scale(d) ?? 0) + half);
|
|
333
|
+
}
|
|
146
334
|
class PcacGridBuilder {
|
|
335
|
+
/**
|
|
336
|
+
* Vertical lines, one per x-axis tick (or category), running the plot's full height. The group
|
|
337
|
+
* is classed `pcac-grid-vertical` so a chart can find and redraw just this grid - the
|
|
338
|
+
* line/area/plot charts do on zoom, when the x ticks move.
|
|
339
|
+
*/
|
|
147
340
|
drawVerticalGrid(config) {
|
|
148
|
-
const xScale = config.xScale;
|
|
149
341
|
config.svg.append('g')
|
|
150
|
-
.attr('class', 'pcac-grid')
|
|
342
|
+
.attr('class', 'pcac-grid pcac-grid-vertical')
|
|
151
343
|
.selectAll('g.rule')
|
|
152
|
-
.data(
|
|
344
|
+
.data(gridLines(config.xScale, config.numberOfTicks))
|
|
153
345
|
.enter().append('svg:g')
|
|
154
346
|
.attr('class', 'pcac-grid-rule')
|
|
155
|
-
.attr('transform', (
|
|
347
|
+
.attr('transform', (x) => (`translate(${x}, 0)`))
|
|
156
348
|
.append('svg:line')
|
|
157
349
|
.attr('y1', 0)
|
|
158
350
|
.attr('y2', config.height)
|
|
159
351
|
.attr('class', (d, i) => (i === 0 ? 'pcac-grid-rule-last' : ''));
|
|
160
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Horizontal lines, one per y-axis tick (or category), running the plot's full width.
|
|
355
|
+
*/
|
|
161
356
|
drawHorizontalGrid(config) {
|
|
162
|
-
const yScale = config.yScale;
|
|
163
357
|
config.svg.append('g')
|
|
164
|
-
.attr('class', 'pcac-grid')
|
|
358
|
+
.attr('class', 'pcac-grid pcac-grid-horizontal')
|
|
165
359
|
.selectAll('g.pcac-grid-rule')
|
|
166
|
-
.data(
|
|
360
|
+
.data(gridLines(config.yScale, config.numberOfTicks))
|
|
167
361
|
.enter().append('svg:g')
|
|
168
362
|
.attr('class', 'pcac-grid-rule')
|
|
169
363
|
.append('svg:line')
|
|
170
|
-
.attr('y1', (
|
|
171
|
-
.attr('y2', (
|
|
364
|
+
.attr('y1', (y) => y)
|
|
365
|
+
.attr('y2', (y) => y)
|
|
172
366
|
.attr('x1', 0)
|
|
173
367
|
.attr('x2', config.width)
|
|
174
368
|
.attr('class', (_, i) => (i === 0 ? 'pcac-grid-rule-last' : ''));
|
|
@@ -306,7 +500,7 @@ class PcacTooltipBuilder {
|
|
|
306
500
|
* projected `pcacTooltip` template. This only ever renders the default content.
|
|
307
501
|
*/
|
|
308
502
|
showBarTooltip(event, data, valueFormat, keyFormat) {
|
|
309
|
-
this.showTooltip(event, undefined, { $implicit: data, parent: null, isThreshold: false }, valueFormat, keyFormat);
|
|
503
|
+
this.showTooltip(event, undefined, { $implicit: data, parent: null, isThreshold: false, index: 0, parentIndex: null }, valueFormat, keyFormat);
|
|
310
504
|
}
|
|
311
505
|
hideTooltip() {
|
|
312
506
|
this.tooltip.style('display', 'none');
|
|
@@ -411,8 +605,20 @@ class PcacChart {
|
|
|
411
605
|
transitionService = inject(PcacTransitionService);
|
|
412
606
|
tooltipBuilder = inject(PcacTooltipBuilder);
|
|
413
607
|
colorService = inject(PcacColorService);
|
|
608
|
+
/** D3's own `tickSizeInner` default, which the default `margin` below is sized around. */
|
|
609
|
+
static DEFAULT_TICK_SIZE = 6;
|
|
610
|
+
/** See `PCAC_AXIS_LABEL_SPACE` / `PCAC_AXIS_SUB_LABEL_SPACE` in chart.model.ts. */
|
|
611
|
+
static AXIS_LABEL_SPACE = PCAC_AXIS_LABEL_SPACE;
|
|
612
|
+
static AXIS_SUB_LABEL_SPACE = PCAC_AXIS_SUB_LABEL_SPACE;
|
|
414
613
|
margin = { top: 8, right: 16, bottom: 20, left: 40 };
|
|
415
614
|
defaultMargin = { ...this.margin };
|
|
615
|
+
/**
|
|
616
|
+
* The current build's per-axis settings with defaults applied, set by `initializeAxisState()`.
|
|
617
|
+
* Builders read these (not the raw `config.xAxis`) everywhere: drawing the axes, choosing
|
|
618
|
+
* whether to draw a grid, how many grid lines, and so on. Pie has no axes and never sets them.
|
|
619
|
+
*/
|
|
620
|
+
xAxis = resolveAxisConfig();
|
|
621
|
+
yAxis = resolveAxisConfig();
|
|
416
622
|
svg;
|
|
417
623
|
width = 400;
|
|
418
624
|
height = 400;
|
|
@@ -434,6 +640,12 @@ class PcacChart {
|
|
|
434
640
|
*/
|
|
435
641
|
lastContainerHeight = null;
|
|
436
642
|
lastHeightFull = false;
|
|
643
|
+
/**
|
|
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.
|
|
647
|
+
*/
|
|
648
|
+
reservedTickHeight = 0;
|
|
437
649
|
/**
|
|
438
650
|
* Resolves the consumer's projected `<ng-template pcacTooltip>`, if any. Each chart component
|
|
439
651
|
* points this at its own `contentChild(PcacTooltipDirective)` query. It's a getter rather than
|
|
@@ -443,22 +655,140 @@ class PcacChart {
|
|
|
443
655
|
*/
|
|
444
656
|
tooltipTemplate = () => undefined;
|
|
445
657
|
/**
|
|
446
|
-
* Puts `margin` back to its defaults.
|
|
447
|
-
*
|
|
448
|
-
* `margin.left`): `margin` lives on this per-chart instance and so persists
|
|
449
|
-
* and without a reset an adjustment made for one config silently carries into
|
|
450
|
-
* e.g. axes drawn with no room after `
|
|
658
|
+
* Puts `margin` back to its defaults. `initializeAxisState()` calls this first thing, before any
|
|
659
|
+
* per-build adjustment (hidden axes giving sides back, tick sizes growing them, label widths
|
|
660
|
+
* measured into `margin.left`): `margin` lives on this per-chart instance and so persists
|
|
661
|
+
* between builds, and without a reset an adjustment made for one config silently carries into
|
|
662
|
+
* the next - e.g. axes drawn with no room after `hide` flips back to false.
|
|
451
663
|
*/
|
|
452
664
|
resetMargin() {
|
|
453
665
|
this.margin = { ...this.defaultMargin };
|
|
666
|
+
this.reservedTickHeight = 0;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Resolves the config's `xAxis`/`yAxis` onto this chart and sets the margins up for them. Axis
|
|
670
|
+
* charts call this at the top of `buildChart()`, on their own copy of the config (it rewrites
|
|
671
|
+
* `config.height` for hidden axes), before `initializeChartState()` measures the plot area.
|
|
672
|
+
* In order:
|
|
673
|
+
*
|
|
674
|
+
* 1. `resetMargin()`.
|
|
675
|
+
* 2. Tick marks: room for a non-default `tickSize` is reserved on each axis that will actually
|
|
676
|
+
* be drawn (`reserveTickSizeMargins`).
|
|
677
|
+
* 3. Labels: `AXIS_LABEL_SPACE` is added to `bottom` / `left` for an axis with a `label`, and
|
|
678
|
+
* `AXIS_SUB_LABEL_SPACE` for one with any `subLabels` (see `axisLabelSpace`), again only if
|
|
679
|
+
* the axis will be drawn.
|
|
680
|
+
* 4. Hidden axes: an axis with `hide` gives its margins back to the plot. The y axis owns
|
|
681
|
+
* `left` and `top` (the top margin is only there so the topmost y label isn't clipped), the
|
|
682
|
+
* x axis `bottom` and `right` (likewise for the rightmost x label). Each reclaimed vertical
|
|
683
|
+
* margin is added onto `config.height` so the SVG's total height stays what the consumer
|
|
684
|
+
* configured; horizontally `initializeChartState()` picks the change up on its own.
|
|
685
|
+
*
|
|
686
|
+
* @param defaultGrid the axis whose grid this chart draws when the consumer hasn't said
|
|
687
|
+
* (`PcacAxisConfig.showGrid`): `'y'` for horizontal lines, `'x'` for vertical.
|
|
688
|
+
* @param hiddenAxisMargin what a hidden axis's sides shrink to, rather than 0. The
|
|
689
|
+
* line/area/plot charts keep 8px so a dot on the edge of the plot isn't clipped by the SVG.
|
|
690
|
+
*/
|
|
691
|
+
initializeAxisState(config, defaultGrid, hiddenAxisMargin = 0) {
|
|
692
|
+
this.xAxis = resolveAxisConfig(config.xAxis, defaultGrid === 'x');
|
|
693
|
+
this.yAxis = resolveAxisConfig(config.yAxis, defaultGrid === 'y');
|
|
694
|
+
this.resetMargin();
|
|
695
|
+
this.reserveTickSizeMargins(this.xAxis.hide ? undefined : this.xAxis.tickSize, this.yAxis.hide ? undefined : this.yAxis.tickSize);
|
|
696
|
+
if (!this.xAxis.hide) {
|
|
697
|
+
const space = axisLabelSpace(this.xAxis);
|
|
698
|
+
this.margin.bottom += space;
|
|
699
|
+
this.reservedTickHeight += space;
|
|
700
|
+
}
|
|
701
|
+
if (!this.yAxis.hide) {
|
|
702
|
+
this.margin.left += axisLabelSpace(this.yAxis);
|
|
703
|
+
}
|
|
704
|
+
if (this.yAxis.hide) {
|
|
705
|
+
config.height = config.height + this.margin.top - hiddenAxisMargin;
|
|
706
|
+
this.margin.top = hiddenAxisMargin;
|
|
707
|
+
this.margin.left = hiddenAxisMargin;
|
|
708
|
+
}
|
|
709
|
+
if (this.xAxis.hide) {
|
|
710
|
+
config.height = config.height + this.margin.bottom - hiddenAxisMargin;
|
|
711
|
+
this.margin.bottom = hiddenAxisMargin;
|
|
712
|
+
this.margin.right = hiddenAxisMargin;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
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).
|
|
719
|
+
*/
|
|
720
|
+
axisBuilderConfig(xScale, yScale, xFormat, yFormat) {
|
|
721
|
+
return {
|
|
722
|
+
svg: this.svg,
|
|
723
|
+
width: this.width,
|
|
724
|
+
height: this.height,
|
|
725
|
+
margin: this.margin,
|
|
726
|
+
xScale,
|
|
727
|
+
yScale,
|
|
728
|
+
xAxis: this.xAxis,
|
|
729
|
+
yAxis: this.yAxis,
|
|
730
|
+
xFormat,
|
|
731
|
+
yFormat
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Draws whichever grids the resolved axes ask for: vertical lines from the x axis's ticks,
|
|
736
|
+
* horizontal from the y's (`PcacAxisConfig.showGrid`). `which` restricts it to one axis - the
|
|
737
|
+
* line/area/plot charts redraw just the x grid against the rescaled x on zoom.
|
|
738
|
+
*/
|
|
739
|
+
drawGrids(xScale, yScale, which = 'both') {
|
|
740
|
+
const base = { svg: this.svg, width: this.width, height: this.height, xScale, yScale };
|
|
741
|
+
if (which !== 'y' && this.xAxis.showGrid) {
|
|
742
|
+
this.gridBuilder.drawVerticalGrid({ ...base, numberOfTicks: this.xAxis.ticks });
|
|
743
|
+
}
|
|
744
|
+
if (which !== 'x' && this.yAxis.showGrid) {
|
|
745
|
+
this.gridBuilder.drawHorizontalGrid({ ...base, numberOfTicks: this.yAxis.ticks });
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Makes room in the margins for tick marks longer (or shorter) than D3's default. The default
|
|
750
|
+
* margins are sized around that default (`DEFAULT_TICK_SIZE`), and D3 places each tick label at
|
|
751
|
+
* tick length + padding, so a longer tick pushes its labels outward by exactly the difference -
|
|
752
|
+
* into space the margin doesn't have unless it grows by the same amount. Growing the margin here,
|
|
753
|
+
* *before* `initializeChartState()` measures the plot area, is what makes the chart shrink to fit
|
|
754
|
+
* its labels rather than pushing them off the edge of the SVG. A shorter tick hands the
|
|
755
|
+
* difference back to the plot area the same way.
|
|
756
|
+
*
|
|
757
|
+
* Horizontally that happens on its own: `initializeChartState()` derives `width` from the
|
|
758
|
+
* container minus the margins. Vertically it doesn't - `config.height` is the plot area, and
|
|
759
|
+
* 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
|
|
761
|
+
* height by `resolveHeight()`, keeping the chart's total footprint where the consumer put it.
|
|
762
|
+
*
|
|
763
|
+
* Called by `initializeAxisState()` right after `resetMargin()`, for the axes that will be
|
|
764
|
+
* drawn. Only the axis a tick size is given for is affected; `undefined` leaves that margin
|
|
765
|
+
* alone.
|
|
766
|
+
* @param xTickSize `tickSizeInner` for the bottom (x) axis, which lives in `margin.bottom`
|
|
767
|
+
* @param yTickSize `tickSizeInner` for the left (y) axis, which lives in `margin.left`
|
|
768
|
+
*/
|
|
769
|
+
reserveTickSizeMargins(xTickSize, yTickSize) {
|
|
770
|
+
if (xTickSize !== undefined) {
|
|
771
|
+
const bottom = Math.max(0, this.margin.bottom + xTickSize - PcacChart.DEFAULT_TICK_SIZE);
|
|
772
|
+
this.reservedTickHeight = bottom - this.margin.bottom;
|
|
773
|
+
this.margin.bottom = bottom;
|
|
774
|
+
}
|
|
775
|
+
if (yTickSize !== undefined) {
|
|
776
|
+
this.margin.left = Math.max(0, this.margin.left + yTickSize - PcacChart.DEFAULT_TICK_SIZE);
|
|
777
|
+
}
|
|
454
778
|
}
|
|
455
779
|
/**
|
|
456
780
|
* Shows the tooltip for a hovered datum, through the chart's `pcacTooltip` template when one is
|
|
457
781
|
* projected and the default key/value content otherwise. Every builder's hover handler should
|
|
458
782
|
* go through here rather than `tooltipBuilder` directly so the template is honored everywhere.
|
|
459
783
|
*/
|
|
460
|
-
showTooltip(event, data, options
|
|
461
|
-
this.tooltipBuilder.showTooltip(event, this.tooltipTemplate(), {
|
|
784
|
+
showTooltip(event, data, options) {
|
|
785
|
+
this.tooltipBuilder.showTooltip(event, this.tooltipTemplate(), {
|
|
786
|
+
$implicit: data,
|
|
787
|
+
parent: options.parent ?? null,
|
|
788
|
+
isThreshold: options.isThreshold ?? false,
|
|
789
|
+
index: options.index,
|
|
790
|
+
parentIndex: options.parentIndex ?? null,
|
|
791
|
+
}, options.valueFormat, options.keyFormat);
|
|
462
792
|
}
|
|
463
793
|
hideTooltip() {
|
|
464
794
|
this.tooltipBuilder.hideTooltip();
|
|
@@ -506,10 +836,13 @@ class PcacChart {
|
|
|
506
836
|
* @param config Chart specific configuration
|
|
507
837
|
*/
|
|
508
838
|
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);
|
|
509
842
|
if (!config.heightFull) {
|
|
510
|
-
return
|
|
843
|
+
return height;
|
|
511
844
|
}
|
|
512
|
-
return Math.max(
|
|
845
|
+
return Math.max(height, container.clientHeight - this.margin.top - this.margin.bottom);
|
|
513
846
|
}
|
|
514
847
|
/**
|
|
515
848
|
* True if the container's current raw layout width differs from the one measured by the last
|
|
@@ -569,12 +902,19 @@ class PcacChart {
|
|
|
569
902
|
* In some cases, that state needs to be calculated based on the content that resides in that margin.
|
|
570
903
|
* For example, labels on a horizontal bar chart are dynamic and such the margin needs to be calculated ahead of
|
|
571
904
|
* chart axis construction.
|
|
905
|
+
*
|
|
906
|
+
* Measures with the y axis's own `tickSize` (the measured box spans the tick line as well as
|
|
907
|
+
* the label, so measuring at a different length would put the labels off by the difference)
|
|
908
|
+
* and adds its `axisLabelSpace()` back on top, since the measurement replaces whatever
|
|
909
|
+
* `initializeAxisState()` reserved for the label / sub labels.
|
|
572
910
|
* @param chartElm Reference to SVG on dom
|
|
573
|
-
* @param data Generic multi-dimensional PcacData structure
|
|
574
911
|
* @param yScale D3 scale transformation object (d3.ScaleBand)
|
|
575
912
|
*/
|
|
576
|
-
setHorizontalMarginsBasedOnContent(chartElm,
|
|
913
|
+
setHorizontalMarginsBasedOnContent(chartElm, yScale) {
|
|
577
914
|
const axisY = axisLeft(yScale).ticks(5);
|
|
915
|
+
if (this.yAxis.tickSize !== undefined) {
|
|
916
|
+
axisY.tickSizeInner(this.yAxis.tickSize);
|
|
917
|
+
}
|
|
578
918
|
let max = 0;
|
|
579
919
|
select$1(chartElm.nativeElement).append('g')
|
|
580
920
|
.call(axisY)
|
|
@@ -590,8 +930,9 @@ class PcacChart {
|
|
|
590
930
|
// double-counted it, and since `margin` persists on the builder between builds, the amount
|
|
591
931
|
// double-counted grew on the next rebuild - the plot area came out narrower than the
|
|
592
932
|
// container allowed and then shrank further after the first resize.
|
|
593
|
-
|
|
594
|
-
this.margin.left
|
|
933
|
+
const left = max + axisLabelSpace(this.yAxis);
|
|
934
|
+
this.width = this.width + this.margin.left - left;
|
|
935
|
+
this.margin.left = left;
|
|
595
936
|
}
|
|
596
937
|
}
|
|
597
938
|
|
|
@@ -633,10 +974,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
633
974
|
return;
|
|
634
975
|
}
|
|
635
976
|
this.config = JSON.parse(JSON.stringify(config));
|
|
636
|
-
this.
|
|
637
|
-
if (this.config.hideAxis) {
|
|
638
|
-
this.adjustForHiddenAxis();
|
|
639
|
-
}
|
|
977
|
+
this.initializeAxisState(this.config, 'x');
|
|
640
978
|
if (!this.initializeChartState(chartElm, this.config)) {
|
|
641
979
|
return;
|
|
642
980
|
}
|
|
@@ -648,13 +986,6 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
648
986
|
this.buildScales(chartElm, this.config);
|
|
649
987
|
this.drawChart(chartElm, this.config);
|
|
650
988
|
}
|
|
651
|
-
adjustForHiddenAxis() {
|
|
652
|
-
this.config.height = this.config.height + this.margin.top + this.margin.bottom;
|
|
653
|
-
this.margin.top = 0;
|
|
654
|
-
this.margin.bottom = 0;
|
|
655
|
-
this.margin.left = 0;
|
|
656
|
-
this.margin.right = 0;
|
|
657
|
-
}
|
|
658
989
|
buildScales(chartElm, config) {
|
|
659
990
|
config.data[0].data.map((d) => {
|
|
660
991
|
return d.value;
|
|
@@ -669,32 +1000,18 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
669
1000
|
.padding(0.05)
|
|
670
1001
|
.rangeRound([0, this.yScaleStacked.bandwidth()])
|
|
671
1002
|
.domain(config.data[0].data.map((d) => d.key));
|
|
672
|
-
|
|
1003
|
+
// The left margin is sized to the y axis's labels - unless there is no y axis to size it to
|
|
1004
|
+
if (!this.yAxis.hide) {
|
|
1005
|
+
this.setHorizontalMarginsBasedOnContent(chartElm, this.yScaleStacked);
|
|
1006
|
+
}
|
|
673
1007
|
this.xScale.range([0, this.width]);
|
|
674
1008
|
}
|
|
675
1009
|
drawChart(chartElm, config) {
|
|
676
1010
|
this.buildContainer(chartElm);
|
|
677
|
-
this.axisBuilder.drawAxis(
|
|
678
|
-
|
|
679
|
-
numberOfTicks: config.numberOfTicks || 5,
|
|
680
|
-
height: this.height,
|
|
681
|
-
xScale: this.xScale,
|
|
682
|
-
yScale: this.yScaleStacked,
|
|
683
|
-
xFormat: config.tickFormat || PcacFormatEnum.None,
|
|
684
|
-
yFormat: PcacFormatEnum.None,
|
|
685
|
-
hideXAxis: config.hideAxis
|
|
686
|
-
});
|
|
687
|
-
if (!config.hideGrid) {
|
|
688
|
-
this.gridBuilder.drawVerticalGrid({
|
|
689
|
-
svg: this.svg,
|
|
690
|
-
numberOfTicks: config.numberOfTicks || 5,
|
|
691
|
-
width: this.width,
|
|
692
|
-
height: this.height,
|
|
693
|
-
xScale: this.xScale,
|
|
694
|
-
yScale: this.yScaleStacked
|
|
695
|
-
});
|
|
696
|
-
}
|
|
1011
|
+
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScale, this.yScaleStacked, config.tickFormat || PcacFormatEnum.None, PcacFormatEnum.None));
|
|
1012
|
+
this.drawGrids(this.xScale, this.yScaleStacked);
|
|
697
1013
|
this.addGroups(config);
|
|
1014
|
+
this.axisBuilder.raiseAxes(this.svg);
|
|
698
1015
|
}
|
|
699
1016
|
addGroups(config) {
|
|
700
1017
|
const groupsContainer = this.svg.append('g')
|
|
@@ -774,7 +1091,8 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
774
1091
|
})
|
|
775
1092
|
.on('mousemove', function (event, d) {
|
|
776
1093
|
const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
|
|
777
|
-
|
|
1094
|
+
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 });
|
|
778
1096
|
})
|
|
779
1097
|
.on('mouseout', function () {
|
|
780
1098
|
self.hideTooltip();
|
|
@@ -806,7 +1124,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
806
1124
|
return i;
|
|
807
1125
|
})
|
|
808
1126
|
.on('mousemove', (event) => {
|
|
809
|
-
this.showTooltip(event, config.thresholds[0], { isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
|
|
1127
|
+
this.showTooltip(event, config.thresholds[0], { index: 0, isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
|
|
810
1128
|
})
|
|
811
1129
|
.transition()
|
|
812
1130
|
.duration(this.transitionService.getTransitionDuration())
|
|
@@ -826,7 +1144,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
826
1144
|
const threshold = config.thresholds[index];
|
|
827
1145
|
// A threshold's own PcacData is typically just a value, so its parent is the *data* group
|
|
828
1146
|
// it's drawn against (which has the key) rather than the threshold entry it came from.
|
|
829
|
-
self.showTooltip(event, config.isStacked ? threshold.data[0] : threshold, { parent: config.data[index], isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
|
|
1147
|
+
self.showTooltip(event, config.isStacked ? threshold.data[0] : threshold, { index, parent: config.data[index], parentIndex: index, isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
|
|
830
1148
|
})
|
|
831
1149
|
.transition()
|
|
832
1150
|
.duration(this.transitionService.getTransitionDuration())
|
|
@@ -846,7 +1164,7 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
846
1164
|
const index = Number(target.getAttribute("data-group-threshold-id"));
|
|
847
1165
|
const groupIndex = Number(this.parentElement.dataset['groupId']);
|
|
848
1166
|
// Parent is the data group (see drawThresholdsPerGroup), not the threshold entry itself.
|
|
849
|
-
self.showTooltip(event, config.thresholds[groupIndex].data[index], { parent: config.data[groupIndex], isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
|
|
1167
|
+
self.showTooltip(event, config.thresholds[groupIndex].data[index], { index, parent: config.data[groupIndex], parentIndex: groupIndex, isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
|
|
850
1168
|
})
|
|
851
1169
|
.transition()
|
|
852
1170
|
.duration(this.transitionService.getTransitionDuration())
|
|
@@ -953,7 +1271,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
|
|
|
953
1271
|
* ```
|
|
954
1272
|
*
|
|
955
1273
|
* The template is rendered with full Angular semantics (pipes, directives, components, DI from
|
|
956
|
-
* the declaring component), so anything a normal template can do works here too.
|
|
1274
|
+
* the declaring component), so anything a normal template can do works here too. `index` and
|
|
1275
|
+
* `parentIndex` locate the hovered datum within `data`, so a template can pull extra fields from
|
|
1276
|
+
* the consumer's own source collection when that collection is parallel to `data`:
|
|
1277
|
+
*
|
|
1278
|
+
* ```html
|
|
1279
|
+
* <ng-template pcacTooltip let-point let-i="index" let-g="parentIndex">
|
|
1280
|
+
* <div class="my-tooltip">{{ orders[g!][i].customer }}: {{ point.value | number }}</div>
|
|
1281
|
+
* </ng-template>
|
|
1282
|
+
* ```
|
|
957
1283
|
*/
|
|
958
1284
|
class PcacTooltipDirective {
|
|
959
1285
|
templateRef = inject(TemplateRef);
|
|
@@ -1018,14 +1344,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
|
|
|
1018
1344
|
args: [{ selector: 'pcac-bar-horizontal-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [BarHorizontalChartBuilder], template: "<section class=\"pcac-bar-horizontal-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-bar-horizontal-chart{display:block}.pcac-bar-horizontal-chart svg{width:100%;display:block}pcac-bar-horizontal-chart.pcac-height-full{display:block;height:100%}pcac-bar-horizontal-chart.pcac-height-full .pcac-bar-horizontal-chart{height:100%}\n"] }]
|
|
1019
1345
|
}], 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 }] }] } });
|
|
1020
1346
|
|
|
1021
|
-
class PcacBarHorizontalChartConfig extends
|
|
1347
|
+
class PcacBarHorizontalChartConfig extends PcacAxisChartConfig {
|
|
1022
1348
|
domainMax = 100;
|
|
1023
|
-
numberOfTicks = 5;
|
|
1024
1349
|
isStacked = false;
|
|
1025
1350
|
thresholds = [];
|
|
1026
1351
|
tickFormat = PcacFormatEnum.None;
|
|
1027
|
-
hideGrid = false;
|
|
1028
|
-
hideAxis = false;
|
|
1029
1352
|
spreadColorsPerGroup = false;
|
|
1030
1353
|
colorOverride = new PcacBarHorizontalChartColorOverrideConfig();
|
|
1031
1354
|
}
|
|
@@ -1049,13 +1372,11 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1049
1372
|
if (!config?.data?.length) {
|
|
1050
1373
|
return;
|
|
1051
1374
|
}
|
|
1052
|
-
// Shallow copy:
|
|
1053
|
-
// consumer's own config object (it previously did, growing it by the margins on
|
|
1375
|
+
// Shallow copy: initializeAxisState() rewrites `height` for hidden axes, and that must not
|
|
1376
|
+
// land on the consumer's own config object (it previously did, growing it by the margins on
|
|
1377
|
+
// first build).
|
|
1054
1378
|
config = { ...config };
|
|
1055
|
-
this.
|
|
1056
|
-
if (config.hideAxis) {
|
|
1057
|
-
this.adjustForHiddenAxis(config);
|
|
1058
|
-
}
|
|
1379
|
+
this.initializeAxisState(config, 'y');
|
|
1059
1380
|
if (!this.initializeChartState(chartElm, config)) {
|
|
1060
1381
|
return;
|
|
1061
1382
|
}
|
|
@@ -1067,26 +1388,6 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1067
1388
|
this.buildScales(config);
|
|
1068
1389
|
this.drawChart(chartElm, config);
|
|
1069
1390
|
}
|
|
1070
|
-
adjustForHiddenAxis(config) {
|
|
1071
|
-
const hasGroupLabel = this.hasGroupLabel(config);
|
|
1072
|
-
config.height = config.height + this.margin.top;
|
|
1073
|
-
if (!hasGroupLabel) {
|
|
1074
|
-
config.height = config.height + this.margin.bottom;
|
|
1075
|
-
}
|
|
1076
|
-
this.margin.top = 0;
|
|
1077
|
-
this.margin.bottom = hasGroupLabel ? this.margin.bottom : 0;
|
|
1078
|
-
this.margin.left = 0;
|
|
1079
|
-
this.margin.right = 0;
|
|
1080
|
-
}
|
|
1081
|
-
hasGroupLabel(config) {
|
|
1082
|
-
let hasGroupLabel = false;
|
|
1083
|
-
config.data.forEach(node => {
|
|
1084
|
-
if (node.key) {
|
|
1085
|
-
hasGroupLabel = true;
|
|
1086
|
-
}
|
|
1087
|
-
});
|
|
1088
|
-
return hasGroupLabel;
|
|
1089
|
-
}
|
|
1090
1391
|
buildScales(config) {
|
|
1091
1392
|
// `this.height`, not `config.height`: with `heightFull` on they differ (see
|
|
1092
1393
|
// PcacChart.resolveHeight), and the axis, grid and bar baselines all use the resolved one.
|
|
@@ -1104,27 +1405,10 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1104
1405
|
}
|
|
1105
1406
|
drawChart(chartElm, config) {
|
|
1106
1407
|
this.buildContainer(chartElm);
|
|
1107
|
-
this.axisBuilder.drawAxis(
|
|
1108
|
-
|
|
1109
|
-
numberOfTicks: config.numberOfTicks || 5,
|
|
1110
|
-
height: this.height,
|
|
1111
|
-
xScale: this.xScaleStacked,
|
|
1112
|
-
yScale: this.yScale,
|
|
1113
|
-
xFormat: PcacFormatEnum.None,
|
|
1114
|
-
yFormat: config.tickFormat || PcacFormatEnum.None,
|
|
1115
|
-
hideYAxis: config.hideAxis
|
|
1116
|
-
});
|
|
1117
|
-
if (!config.hideGrid) {
|
|
1118
|
-
this.gridBuilder.drawHorizontalGrid({
|
|
1119
|
-
svg: this.svg,
|
|
1120
|
-
numberOfTicks: config.numberOfTicks || 5,
|
|
1121
|
-
width: this.width,
|
|
1122
|
-
height: this.height,
|
|
1123
|
-
xScale: this.xScaleStacked,
|
|
1124
|
-
yScale: this.yScale
|
|
1125
|
-
});
|
|
1126
|
-
}
|
|
1408
|
+
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScaleStacked, this.yScale, PcacFormatEnum.None, config.tickFormat || PcacFormatEnum.None));
|
|
1409
|
+
this.drawGrids(this.xScaleStacked, this.yScale);
|
|
1127
1410
|
this.addGroups(config);
|
|
1411
|
+
this.axisBuilder.raiseAxes(this.svg);
|
|
1128
1412
|
}
|
|
1129
1413
|
addGroups(config) {
|
|
1130
1414
|
const groupsContainer = this.svg.append('g')
|
|
@@ -1207,7 +1491,8 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1207
1491
|
})
|
|
1208
1492
|
.on('mousemove', function (event, d) {
|
|
1209
1493
|
const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
|
|
1210
|
-
|
|
1494
|
+
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 });
|
|
1211
1496
|
})
|
|
1212
1497
|
.on('mouseout', function () {
|
|
1213
1498
|
self.hideTooltip();
|
|
@@ -1246,7 +1531,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1246
1531
|
return i;
|
|
1247
1532
|
})
|
|
1248
1533
|
.on('mousemove', (event) => {
|
|
1249
|
-
this.showTooltip(event, config.thresholds[0], { isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
|
|
1534
|
+
this.showTooltip(event, config.thresholds[0], { index: 0, isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
|
|
1250
1535
|
})
|
|
1251
1536
|
.transition()
|
|
1252
1537
|
.duration(this.transitionService.getTransitionDuration())
|
|
@@ -1266,7 +1551,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1266
1551
|
const threshold = config.thresholds[index];
|
|
1267
1552
|
// A threshold's own PcacData is typically just a value, so its parent is the *data* group
|
|
1268
1553
|
// it's drawn against (which has the key) rather than the threshold entry it came from.
|
|
1269
|
-
self.showTooltip(event, config.isStacked ? threshold.data[0] : threshold, { parent: config.data[index], isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
|
|
1554
|
+
self.showTooltip(event, config.isStacked ? threshold.data[0] : threshold, { index, parent: config.data[index], parentIndex: index, isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
|
|
1270
1555
|
})
|
|
1271
1556
|
.transition()
|
|
1272
1557
|
.duration(this.transitionService.getTransitionDuration())
|
|
@@ -1285,7 +1570,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1285
1570
|
const index = Number(target.getAttribute("data-group-threshold-id"));
|
|
1286
1571
|
const groupIndex = Number(this.parentElement.dataset['groupId']);
|
|
1287
1572
|
// Parent is the data group (see drawThresholdsPerGroup), not the threshold entry itself.
|
|
1288
|
-
self.showTooltip(event, config.thresholds[groupIndex].data[index], { parent: config.data[groupIndex], isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
|
|
1573
|
+
self.showTooltip(event, config.thresholds[groupIndex].data[index], { index, parent: config.data[groupIndex], parentIndex: groupIndex, isThreshold: true, valueFormat: config.tickFormat || PcacFormatEnum.None });
|
|
1289
1574
|
})
|
|
1290
1575
|
.attr('width', this.xScaleGrouped.bandwidth())
|
|
1291
1576
|
.transition()
|
|
@@ -1374,14 +1659,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
|
|
|
1374
1659
|
args: [{ selector: 'pcac-bar-vertical-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, encapsulation: ViewEncapsulation.None, providers: [BarVerticalChartBuilder], template: "<section class=\"pcac-bar-vertical-chart\">\n <svg #chart></svg>\n</section>\n", styles: [".pcac-bar-vertical-chart svg{width:100%;display:block}pcac-bar-vertical-chart.pcac-height-full{display:block;height:100%}pcac-bar-vertical-chart.pcac-height-full .pcac-bar-vertical-chart{height:100%}\n"] }]
|
|
1375
1660
|
}], 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 }] }] } });
|
|
1376
1661
|
|
|
1377
|
-
class PcacBarVerticalChartConfig extends
|
|
1662
|
+
class PcacBarVerticalChartConfig extends PcacAxisChartConfig {
|
|
1378
1663
|
domainMax = 100;
|
|
1379
|
-
numberOfTicks = 5;
|
|
1380
1664
|
isStacked = false;
|
|
1381
1665
|
thresholds = [];
|
|
1382
1666
|
tickFormat = PcacFormatEnum.None;
|
|
1383
|
-
hideGrid = false;
|
|
1384
|
-
hideAxis = false;
|
|
1385
1667
|
spreadColorsPerGroup = false;
|
|
1386
1668
|
colorOverride = new PcacBarVerticalChartColorOverrideConfig();
|
|
1387
1669
|
}
|
|
@@ -1433,12 +1715,9 @@ class PcacPointImageConfig {
|
|
|
1433
1715
|
maxWidth = 16;
|
|
1434
1716
|
maxHeight = 16;
|
|
1435
1717
|
}
|
|
1436
|
-
class PcacLineAreaChartConfig extends
|
|
1718
|
+
class PcacLineAreaChartConfig extends PcacAxisChartConfig {
|
|
1437
1719
|
enableEffects = true;
|
|
1438
1720
|
enableZoom = true;
|
|
1439
|
-
numberOfTicks = 5;
|
|
1440
|
-
hideGrid = false;
|
|
1441
|
-
hideAxis = false;
|
|
1442
1721
|
yFormat = PcacFormatEnum.DatasetLength;
|
|
1443
1722
|
xFormat = PcacFormatEnum.DatasetLength;
|
|
1444
1723
|
yDomainMax;
|
|
@@ -1725,14 +2004,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1725
2004
|
hide: false,
|
|
1726
2005
|
data: []
|
|
1727
2006
|
}));
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
this.config.height = this.config.height + 12;
|
|
1731
|
-
this.margin.top = 8;
|
|
1732
|
-
this.margin.bottom = 8;
|
|
1733
|
-
this.margin.left = 8;
|
|
1734
|
-
this.margin.right = 8;
|
|
1735
|
-
}
|
|
2007
|
+
// A hidden axis keeps 8px rather than 0 so a dot on the edge of the plot isn't clipped
|
|
2008
|
+
this.initializeAxisState(this.config, 'y', 8);
|
|
1736
2009
|
if (!this.initializeChartState(chartElm, this.config)) {
|
|
1737
2010
|
return;
|
|
1738
2011
|
}
|
|
@@ -1754,15 +2027,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1754
2027
|
// Rescale x
|
|
1755
2028
|
const newX = event.transform.rescaleX(this.scales.x);
|
|
1756
2029
|
// Update axis
|
|
1757
|
-
this.axisBuilder.drawXAxis(
|
|
1758
|
-
svg: this.svg,
|
|
1759
|
-
numberOfTicks: this.config.numberOfTicks || 5,
|
|
1760
|
-
height: this.height,
|
|
1761
|
-
xScale: newX,
|
|
1762
|
-
yScale: this.scales.y,
|
|
1763
|
-
yFormat: this.config.yFormat,
|
|
1764
|
-
xFormat: this.config.xFormat
|
|
1765
|
-
});
|
|
2030
|
+
this.axisBuilder.drawXAxis(this.axisBuilderConfig(newX, this.scales.y, this.config.xFormat, this.config.yFormat));
|
|
1766
2031
|
// Update lines/areas. Fresh generators against the rescaled x, so they go through the
|
|
1767
2032
|
// same getXFormat() as the dots below - positioning by bare index here (which this used
|
|
1768
2033
|
// to do, and which also overwrote the original generators' x accessor for good) is only
|
|
@@ -1779,6 +2044,14 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1779
2044
|
// points consecutively, shoving the second series' points off to the right on zoom.
|
|
1780
2045
|
this.svg.selectAll('.dots').selectAll('.point')
|
|
1781
2046
|
.attr('transform', (d, i) => this.pointTransform(d, i, newX));
|
|
2047
|
+
// The vertical grid hangs off the x ticks too, so redraw it against the rescaled x and
|
|
2048
|
+
// drop it back underneath everything (append puts it on top).
|
|
2049
|
+
this.svg.selectAll('.pcac-grid-vertical').remove();
|
|
2050
|
+
this.drawGrids(newX, this.scales.y, 'x');
|
|
2051
|
+
this.svg.selectAll('.pcac-grid-vertical').lower();
|
|
2052
|
+
// drawXAxis re-appends the x axis at the end of the group, above the dots; put them back
|
|
2053
|
+
// on top so a point on the baseline isn't covered (see drawChart's draw order).
|
|
2054
|
+
this.svg.selectAll('.dots').raise();
|
|
1782
2055
|
});
|
|
1783
2056
|
}
|
|
1784
2057
|
this.drawChart(chartElm, this.config, type);
|
|
@@ -1787,27 +2060,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1787
2060
|
this.buildContainer(chartElm);
|
|
1788
2061
|
this.attachZoomBehavior();
|
|
1789
2062
|
this.createReusableClipPath();
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
svg: this.svg,
|
|
1793
|
-
numberOfTicks: config.numberOfTicks || 5,
|
|
1794
|
-
height: this.height,
|
|
1795
|
-
xScale: this.scales.x,
|
|
1796
|
-
yScale: this.scales.y,
|
|
1797
|
-
yFormat: config.yFormat,
|
|
1798
|
-
xFormat: config.xFormat
|
|
1799
|
-
});
|
|
1800
|
-
}
|
|
1801
|
-
if (!config.hideGrid) {
|
|
1802
|
-
this.gridBuilder.drawHorizontalGrid({
|
|
1803
|
-
svg: this.svg,
|
|
1804
|
-
numberOfTicks: config.numberOfTicks || 5,
|
|
1805
|
-
width: this.width,
|
|
1806
|
-
height: this.height,
|
|
1807
|
-
xScale: this.scales.x,
|
|
1808
|
-
yScale: this.scales.y
|
|
1809
|
-
});
|
|
1810
|
-
}
|
|
2063
|
+
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.scales.x, this.scales.y, config.xFormat, config.yFormat));
|
|
2064
|
+
this.drawGrids(this.scales.x, this.scales.y);
|
|
1811
2065
|
this.drawLineArea(config, type);
|
|
1812
2066
|
if (config.enableEffects) {
|
|
1813
2067
|
this.effectsBuilder.buildEffects({
|
|
@@ -1820,6 +2074,9 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1820
2074
|
y: this.scales.y
|
|
1821
2075
|
});
|
|
1822
2076
|
}
|
|
2077
|
+
// 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.
|
|
2079
|
+
this.axisBuilder.raiseAxes(this.svg);
|
|
1823
2080
|
this.drawDots(config);
|
|
1824
2081
|
}
|
|
1825
2082
|
createReusableClipPath() {
|
|
@@ -1927,7 +2184,14 @@ class PlaChartBuilder extends PcacChart {
|
|
|
1927
2184
|
.attr('class', 'point')
|
|
1928
2185
|
.attr('transform', (d, i) => this.pointTransform(d, i, this.scales.x))
|
|
1929
2186
|
.on('mouseover', function (event, d) {
|
|
1930
|
-
|
|
2187
|
+
// `d` is the very element bound from `series.data` above, so identity lookup is exact.
|
|
2188
|
+
self.showTooltip(event, d, {
|
|
2189
|
+
index: series.data.indexOf(d),
|
|
2190
|
+
parent: series,
|
|
2191
|
+
parentIndex: index,
|
|
2192
|
+
valueFormat: self.config.yFormat,
|
|
2193
|
+
keyFormat: self.config.xFormat,
|
|
2194
|
+
});
|
|
1931
2195
|
// No-op for an image point (no circle inside to grow).
|
|
1932
2196
|
select$1(this).select('.dot')
|
|
1933
2197
|
.transition()
|
|
@@ -2170,7 +2434,7 @@ class PieChartBuilder extends PcacChart {
|
|
|
2170
2434
|
.style('fill', ct);
|
|
2171
2435
|
})
|
|
2172
2436
|
.on('mousemove', (event, d) => {
|
|
2173
|
-
self.showTooltip(event, d.data);
|
|
2437
|
+
self.showTooltip(event, d.data, { index: d.index });
|
|
2174
2438
|
})
|
|
2175
2439
|
.on('mouseout', function (_, d) {
|
|
2176
2440
|
self.hideTooltip();
|
|
@@ -2248,7 +2512,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.6", ngImpor
|
|
|
2248
2512
|
}], ctorParameters: () => [], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], chartElm: [{ type: i0.ViewChild, args: ['chart', { isSignal: true }] }], sliceClicked: [{ type: i0.Output, args: ["sliceClicked"] }], tooltipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => PcacTooltipDirective), { isSignal: true }] }] } });
|
|
2249
2513
|
|
|
2250
2514
|
class PcacPieChartConfig extends PcacChartConfig {
|
|
2251
|
-
numberOfTicks = 5;
|
|
2252
2515
|
}
|
|
2253
2516
|
|
|
2254
2517
|
/*
|
|
@@ -2259,5 +2522,5 @@ class PcacPieChartConfig extends PcacChartConfig {
|
|
|
2259
2522
|
* Generated bundle index. Do not edit.
|
|
2260
2523
|
*/
|
|
2261
2524
|
|
|
2262
|
-
export { BarHorizontalChartBuilder, BarVerticalChartBuilder, PcacAreaChart, PcacAreaChartConfig, PcacAxisBuilder, 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 };
|
|
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 };
|
|
2263
2526
|
//# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map
|