@pioneer-code/pioneer-charts 22.1.5 → 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 +396 -156
- 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 +258 -34
package/package.json
CHANGED
package/scss/pioneer-charts.scss
CHANGED
|
@@ -36,4 +36,28 @@
|
|
|
36
36
|
line {
|
|
37
37
|
stroke: none;
|
|
38
38
|
}
|
|
39
|
+
|
|
40
|
+
// Tick marks and the axis line are hidden by default (above) and always have been, so they
|
|
41
|
+
// only appear on a chart that asks for them - `PcacAxisConfig.tickSize` for the marks,
|
|
42
|
+
// `showLine` for the line - via a class the axis builder adds for that axis. Nothing changes
|
|
43
|
+
// for charts that don't. Both share one color so a mark reads as part of its axis rather than a
|
|
44
|
+
// separate, fainter element.
|
|
45
|
+
&.pcac-axis-tick-marks .tick line,
|
|
46
|
+
&.pcac-axis-line .domain {
|
|
47
|
+
stroke: imports.$gray-900;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// The axis `label` (its title). `PcacChart.AXIS_LABEL_SPACE` reserves room for this size plus
|
|
51
|
+
// a gap, so change both together.
|
|
52
|
+
.pcac-axis-label {
|
|
53
|
+
font-size: 12px;
|
|
54
|
+
font-weight: 600;
|
|
55
|
+
fill: imports.$gray-700;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Min / mid / max `subLabels`; `PcacChart.AXIS_SUB_LABEL_SPACE` is sized to this.
|
|
59
|
+
.pcac-axis-sub-label {
|
|
60
|
+
font-size: 11px;
|
|
61
|
+
fill: imports.$gray-600;
|
|
62
|
+
}
|
|
39
63
|
}
|
|
@@ -23,4 +23,20 @@
|
|
|
23
23
|
.pcac-y-axis path,
|
|
24
24
|
.pcac-y-axis line {
|
|
25
25
|
stroke: none;
|
|
26
|
+
}
|
|
27
|
+
.pcac-x-axis.pcac-axis-tick-marks .tick line, .pcac-x-axis.pcac-axis-line .domain,
|
|
28
|
+
.pcac-y-axis.pcac-axis-tick-marks .tick line,
|
|
29
|
+
.pcac-y-axis.pcac-axis-line .domain {
|
|
30
|
+
stroke: #212529;
|
|
31
|
+
}
|
|
32
|
+
.pcac-x-axis .pcac-axis-label,
|
|
33
|
+
.pcac-y-axis .pcac-axis-label {
|
|
34
|
+
font-size: 12px;
|
|
35
|
+
font-weight: 600;
|
|
36
|
+
fill: #495057;
|
|
37
|
+
}
|
|
38
|
+
.pcac-x-axis .pcac-axis-sub-label,
|
|
39
|
+
.pcac-y-axis .pcac-axis-sub-label {
|
|
40
|
+
font-size: 11px;
|
|
41
|
+
fill: #6c757d;
|
|
26
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.pcac-d3-tooltip{position:absolute;pointer-events:none;display:none;z-index:1000}.pcac-d3-tooltip-default{text-align:center;font-size:14px;padding:.5rem;background-color:rgba(52,58,64,.85);color:#fff;border-radius:2px}.pcac-grid-rule line{stroke:#e9ecef}.pcac-x-axis path,.pcac-x-axis line,.pcac-y-axis path,.pcac-y-axis line{stroke:none}
|
|
1
|
+
.pcac-d3-tooltip{position:absolute;pointer-events:none;display:none;z-index:1000}.pcac-d3-tooltip-default{text-align:center;font-size:14px;padding:.5rem;background-color:rgba(52,58,64,.85);color:#fff;border-radius:2px}.pcac-grid-rule line{stroke:#e9ecef}.pcac-x-axis path,.pcac-x-axis line,.pcac-y-axis path,.pcac-y-axis line{stroke:none}.pcac-x-axis.pcac-axis-tick-marks .tick line,.pcac-x-axis.pcac-axis-line .domain,.pcac-y-axis.pcac-axis-tick-marks .tick line,.pcac-y-axis.pcac-axis-line .domain{stroke:#212529}.pcac-x-axis .pcac-axis-label,.pcac-y-axis .pcac-axis-label{font-size:12px;font-weight:600;fill:#495057}.pcac-x-axis .pcac-axis-sub-label,.pcac-y-axis .pcac-axis-sub-label{font-size:11px;fill:#6c757d}
|
|
@@ -32,6 +32,123 @@ declare class PcacChartConfig {
|
|
|
32
32
|
*/
|
|
33
33
|
heightFull?: boolean;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Up to three short labels placed along an axis by position rather than by value: `min` at its
|
|
37
|
+
* start, `mid` at its center, `max` at its end. Any subset can be given.
|
|
38
|
+
*/
|
|
39
|
+
declare class PcacAxisSubLabels {
|
|
40
|
+
min?: string;
|
|
41
|
+
mid?: string;
|
|
42
|
+
max?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Everything configurable about one axis. Used twice per chart, as `xAxis` and `yAxis` on
|
|
46
|
+
* `PcacAxisChartConfig`, so the two never drift apart and a new per-axis option lands in one place.
|
|
47
|
+
*
|
|
48
|
+
* Every field is optional so an object-literal / JSON config can give just the ones it cares
|
|
49
|
+
* about (or omit the axis entirely); the initializers apply to anything built with `new`, and
|
|
50
|
+
* `resolveAxisConfig()` fills the rest in for builders.
|
|
51
|
+
*/
|
|
52
|
+
declare class PcacAxisConfig {
|
|
53
|
+
/**
|
|
54
|
+
* Don't draw this axis at all (labels, tick marks, line), and give the margins it would have
|
|
55
|
+
* occupied back to the plot area. Hiding the y axis reclaims the left and top margins; hiding
|
|
56
|
+
* the x axis reclaims the bottom and right. The chart's total footprint doesn't change.
|
|
57
|
+
*/
|
|
58
|
+
hide?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Draw grid lines from this axis's ticks (or, on a category axis, from each category) across
|
|
61
|
+
* the plot: horizontal lines for the y axis, vertical for the x. Left unset, each chart keeps
|
|
62
|
+
* the grid it has always drawn - the y axis's on vertical bar and line/area/plot charts, the
|
|
63
|
+
* x axis's on the horizontal bar chart - and no other; set it to turn either grid on or off
|
|
64
|
+
* explicitly. Deliberately has no initializer, since "unset" is what carries the per-chart
|
|
65
|
+
* default.
|
|
66
|
+
*/
|
|
67
|
+
showGrid?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Requested number of ticks (D3's `ticks()` hint, so the actual count can differ slightly) -
|
|
70
|
+
* also the number of grid lines for this axis. Ignored by a category (band) axis, which has one
|
|
71
|
+
* tick per category. Default 5.
|
|
72
|
+
*/
|
|
73
|
+
ticks?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Length in pixels of the small tick marks. Tick marks are not drawn at all unless this is set
|
|
76
|
+
* (the theme hides them, as it always has), so setting a size is also what turns them on; D3's
|
|
77
|
+
* default 6px is a sensible first value. `0` keeps them off but still pulls the labels in to
|
|
78
|
+
* the axis. Labels follow the marks (D3 places them at tick length + 3px), and the chart's
|
|
79
|
+
* margins grow or shrink by the same amount so the plot area makes room for them - a longer
|
|
80
|
+
* tick means a slightly smaller plot, never labels pushed off the edge. Only the per-tick marks
|
|
81
|
+
* change; the axis line's two end-caps keep their default length. Color comes from the theme
|
|
82
|
+
* (`.pcac-axis-tick-marks .tick line`, `$gray-900`, the same as the axis line).
|
|
83
|
+
*/
|
|
84
|
+
tickSize?: number;
|
|
85
|
+
/**
|
|
86
|
+
* Draw a solid line along the axis itself (the full length of the axis, with D3's short
|
|
87
|
+
* end-caps). Off by default, as the theme has always hidden it. Color comes from the theme
|
|
88
|
+
* (`.pcac-axis-line .domain`, `$gray-900`).
|
|
89
|
+
*/
|
|
90
|
+
showLine?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* A title for the whole axis (e.g. "Revenue ($)"), drawn centered along it just inside the
|
|
93
|
+
* chart's edge: below the tick labels for the x axis, rotated to read bottom-to-top left of
|
|
94
|
+
* them for the y axis. The chart's margin grows by `PcacChart.AXIS_LABEL_SPACE` to make room,
|
|
95
|
+
* shrinking the plot area the same way a longer tick does. Not drawn on a hidden axis. Styled
|
|
96
|
+
* by the theme's `.pcac-axis-label` rule.
|
|
97
|
+
*/
|
|
98
|
+
label?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Min / mid / max sub labels (e.g. "Low" / "Medium" / "High") in their own row just outside the
|
|
101
|
+
* tick labels, and inside the `label` if there is one: `min` left-aligned at the axis's start,
|
|
102
|
+
* `mid` centered, `max` right-aligned at its end, so they never spill past the axis. On the
|
|
103
|
+
* y axis they run bottom-to-top like the label, `min` at the bottom. The margin grows by
|
|
104
|
+
* `PcacChart.AXIS_SUB_LABEL_SPACE` when any is set, shrinking the plot area. Not drawn on a
|
|
105
|
+
* hidden axis. Styled by the theme's `.pcac-axis-sub-label` rule.
|
|
106
|
+
*/
|
|
107
|
+
subLabels?: PcacAxisSubLabels;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The `PcacChartMargin` type lives here rather than in chart.ts so the axis builder can take
|
|
111
|
+
* one without importing the class module that imports it back.
|
|
112
|
+
*/
|
|
113
|
+
interface PcacChartMargin {
|
|
114
|
+
top: number;
|
|
115
|
+
right: number;
|
|
116
|
+
bottom: number;
|
|
117
|
+
left: number;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* `PcacAxisConfig` with every default applied - what builders work with, so they never have to
|
|
121
|
+
* null-check. `tickSize`, `label` and `subLabels` stay optional: "not set" is itself the meaningful
|
|
122
|
+
* default (no marks, no labels).
|
|
123
|
+
*/
|
|
124
|
+
type PcacResolvedAxisConfig = Required<Omit<PcacAxisConfig, 'tickSize' | 'label' | 'subLabels'>> & Pick<PcacAxisConfig, 'tickSize' | 'label' | 'subLabels'>;
|
|
125
|
+
/** True if `axis` has at least one sub label to draw (an empty `subLabels` object counts as none). */
|
|
126
|
+
declare function hasAxisSubLabels(axis: PcacAxisConfig | undefined): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Room reserved in a margin for an axis `label`: the theme's 12px label plus a gap from the tick
|
|
129
|
+
* labels. Reserved on the side the label sits on (`bottom` for x, `left` for y), and taken out
|
|
130
|
+
* of the plot area, the same way a longer tick is. Change together with `.pcac-axis-label`.
|
|
131
|
+
*/
|
|
132
|
+
declare const PCAC_AXIS_LABEL_SPACE = 18;
|
|
133
|
+
/** Likewise for a row of `subLabels`: the theme's 11px text plus a gap (`.pcac-axis-sub-label`). */
|
|
134
|
+
declare const PCAC_AXIS_SUB_LABEL_SPACE = 16;
|
|
135
|
+
/**
|
|
136
|
+
* Total margin an axis's `label` and `subLabels` take on its side. `PcacChart` reserves it and
|
|
137
|
+
* the axis builder places the text by it, so the two stay in step.
|
|
138
|
+
*/
|
|
139
|
+
declare function axisLabelSpace(axis: PcacAxisConfig | undefined): number;
|
|
140
|
+
/**
|
|
141
|
+
* @param showGridDefault what `showGrid` resolves to when the consumer left it unset - each chart
|
|
142
|
+
* passes `true` for the axis whose grid it has always drawn and `false` for the other.
|
|
143
|
+
*/
|
|
144
|
+
declare function resolveAxisConfig(axis?: PcacAxisConfig, showGridDefault?: boolean): PcacResolvedAxisConfig;
|
|
145
|
+
/**
|
|
146
|
+
* Base configuration for every chart that has an x and y axis (bar, line, area, plot - not pie).
|
|
147
|
+
*/
|
|
148
|
+
declare class PcacAxisChartConfig extends PcacChartConfig {
|
|
149
|
+
xAxis?: PcacAxisConfig;
|
|
150
|
+
yAxis?: PcacAxisConfig;
|
|
151
|
+
}
|
|
35
152
|
declare class PcacData {
|
|
36
153
|
key: string | number | null;
|
|
37
154
|
value: string | number | null;
|
|
@@ -64,14 +181,11 @@ declare enum PcacFormatEnum {
|
|
|
64
181
|
OneDayHours = "oneDayHours"
|
|
65
182
|
}
|
|
66
183
|
|
|
67
|
-
declare class PcacBarHorizontalChartConfig extends
|
|
184
|
+
declare class PcacBarHorizontalChartConfig extends PcacAxisChartConfig {
|
|
68
185
|
domainMax: number;
|
|
69
|
-
numberOfTicks: number;
|
|
70
186
|
isStacked: boolean;
|
|
71
187
|
thresholds: PcacData[];
|
|
72
188
|
tickFormat: PcacFormatEnum;
|
|
73
|
-
hideGrid: boolean;
|
|
74
|
-
hideAxis: boolean;
|
|
75
189
|
spreadColorsPerGroup: boolean;
|
|
76
190
|
colorOverride: PcacBarHorizontalChartColorOverrideConfig;
|
|
77
191
|
}
|
|
@@ -87,19 +201,53 @@ declare class PcacBarHorizontalChartColorOverrideConfig {
|
|
|
87
201
|
*/
|
|
88
202
|
interface IPcacAxisBuilderConfig<XDomain extends AxisDomain = AxisDomain, YDomain extends AxisDomain = AxisDomain> {
|
|
89
203
|
svg: Selection<SVGGElement, unknown, BaseType, unknown>;
|
|
204
|
+
/** Plot area size - the axes' own lengths - and the chart's margins, which position a `label`. */
|
|
205
|
+
width: number;
|
|
90
206
|
height: number;
|
|
207
|
+
margin: PcacChartMargin;
|
|
91
208
|
xScale: AxisScale<XDomain>;
|
|
92
209
|
yScale: AxisScale<YDomain>;
|
|
93
|
-
|
|
210
|
+
/**
|
|
211
|
+
* The chart's per-axis settings, defaults already applied (`resolveAxisConfig()`). `hide` skips
|
|
212
|
+
* the axis entirely. `tickSize` is D3's `tickSizeInner`; left undefined, D3's default of 6
|
|
213
|
+
* applies to the geometry - but the theme hides tick marks unless the axis group carries
|
|
214
|
+
* `pcac-axis-tick-marks`, which is added exactly when a size is given, so an undefined size
|
|
215
|
+
* means "no visible marks, labels where they've always been". `0` is a legitimate value (no
|
|
216
|
+
* marks, labels hugging the axis), hence the `!== undefined` checks below. `showLine` adds
|
|
217
|
+
* `pcac-axis-line`, which un-hides D3's `.domain` path the same way. The domain path keeps
|
|
218
|
+
* D3's default 6px outer end-caps (`tickSizeOuter`), so it reads as a bracket rather than a
|
|
219
|
+
* bare rule; that's D3's standard look and is left as-is. `label` and `subLabels` are drawn
|
|
220
|
+
* inside the axis group (so they're raised and non-interactive along with it) - see `drawLabels`.
|
|
221
|
+
*/
|
|
222
|
+
xAxis: PcacResolvedAxisConfig;
|
|
223
|
+
yAxis: PcacResolvedAxisConfig;
|
|
94
224
|
yFormat?: PcacFormatEnum;
|
|
95
225
|
xFormat?: PcacFormatEnum;
|
|
96
|
-
hideYAxis?: boolean;
|
|
97
|
-
hideXAxis?: boolean;
|
|
98
226
|
}
|
|
99
227
|
declare class PcacAxisBuilder {
|
|
100
228
|
drawAxis<XDomain extends AxisDomain, YDomain extends AxisDomain>(config: IPcacAxisBuilderConfig<XDomain, YDomain>): void;
|
|
229
|
+
/**
|
|
230
|
+
* Moves both axis groups to the end of the chart's `<g>`, so they paint over everything drawn
|
|
231
|
+
* since `drawAxis()`. Axes are drawn first (so scales and margins are settled before content),
|
|
232
|
+
* which leaves anything sitting at x = 0 - a line chart's first segment and dot, an area's fill,
|
|
233
|
+
* a horizontal bar chart's bars - painting over the y axis line. Builders call this after the
|
|
234
|
+
* content that should sit *under* the axes, and draw anything that should stay on top (the
|
|
235
|
+
* line/area/plot charts' dots) afterwards. Safe to sit above the hover/zoom overlay rects too,
|
|
236
|
+
* because the groups are `pointer-events: none` (set where each group is appended).
|
|
237
|
+
*/
|
|
238
|
+
raiseAxes(svg: Selection<SVGGElement, unknown, BaseType, unknown>): void;
|
|
101
239
|
drawYAxis<XDomain extends AxisDomain, YDomain extends AxisDomain>(config: IPcacAxisBuilderConfig<XDomain, YDomain>): void;
|
|
102
240
|
drawXAxis<XDomain extends AxisDomain, YDomain extends AxisDomain>(config: IPcacAxisBuilderConfig<XDomain, YDomain>): void;
|
|
241
|
+
/**
|
|
242
|
+
* The axis `label` and `subLabels`. Both are placed by two distances: along the axis (0 at its
|
|
243
|
+
* start, `length` at its end - for the y axis, 0 is the bottom) and out from it, toward the
|
|
244
|
+
* chart's edge. The label goes at the very edge (`outer`, i.e. the margin), the sub-label row
|
|
245
|
+
* `PCAC_AXIS_LABEL_SPACE` inside that when there's a label. For the y axis the text is rotated
|
|
246
|
+
* to read bottom-to-top, which swaps the two: after `rotate(-90)` x runs up the axis (so the
|
|
247
|
+
* bottom is x = -length) and y runs left. `fill` is set explicitly because d3-axis puts
|
|
248
|
+
* `fill="none"` on the group; its own tick text does the same.
|
|
249
|
+
*/
|
|
250
|
+
private drawLabels;
|
|
103
251
|
static ɵfac: i0.ɵɵFactoryDeclaration<PcacAxisBuilder, never>;
|
|
104
252
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
105
253
|
}
|
|
@@ -119,10 +267,22 @@ interface IPcacGridBuilderConfig<XDomain extends AxisDomain = AxisDomain, YDomai
|
|
|
119
267
|
height: number;
|
|
120
268
|
xScale: AxisScale<XDomain>;
|
|
121
269
|
yScale: AxisScale<YDomain>;
|
|
270
|
+
/**
|
|
271
|
+
* Tick count hint for a continuous scale (D3's `ticks(n)`); a category (band) scale ignores it
|
|
272
|
+
* and gets one line per category.
|
|
273
|
+
*/
|
|
122
274
|
numberOfTicks: number;
|
|
123
275
|
}
|
|
124
276
|
declare class PcacGridBuilder {
|
|
277
|
+
/**
|
|
278
|
+
* Vertical lines, one per x-axis tick (or category), running the plot's full height. The group
|
|
279
|
+
* is classed `pcac-grid-vertical` so a chart can find and redraw just this grid - the
|
|
280
|
+
* line/area/plot charts do on zoom, when the x ticks move.
|
|
281
|
+
*/
|
|
125
282
|
drawVerticalGrid<XDomain extends AxisDomain, YDomain extends AxisDomain>(config: IPcacGridBuilderConfig<XDomain, YDomain>): void;
|
|
283
|
+
/**
|
|
284
|
+
* Horizontal lines, one per y-axis tick (or category), running the plot's full width.
|
|
285
|
+
*/
|
|
126
286
|
drawHorizontalGrid<XDomain extends AxisDomain, YDomain extends AxisDomain>(config: IPcacGridBuilderConfig<XDomain, YDomain>): void;
|
|
127
287
|
static ɵfac: i0.ɵɵFactoryDeclaration<PcacGridBuilder, never>;
|
|
128
288
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
@@ -297,20 +457,26 @@ interface PcacTooltipOptions {
|
|
|
297
457
|
valueFormat?: PcacFormatEnum;
|
|
298
458
|
keyFormat?: PcacFormatEnum;
|
|
299
459
|
}
|
|
300
|
-
interface PcacChartMargin {
|
|
301
|
-
top: number;
|
|
302
|
-
right: number;
|
|
303
|
-
bottom: number;
|
|
304
|
-
left: number;
|
|
305
|
-
}
|
|
306
460
|
declare class PcacChart {
|
|
307
461
|
axisBuilder: PcacAxisBuilder;
|
|
308
462
|
gridBuilder: PcacGridBuilder;
|
|
309
463
|
transitionService: PcacTransitionService;
|
|
310
464
|
tooltipBuilder: PcacTooltipBuilder;
|
|
311
465
|
colorService: PcacColorService;
|
|
466
|
+
/** D3's own `tickSizeInner` default, which the default `margin` below is sized around. */
|
|
467
|
+
static readonly DEFAULT_TICK_SIZE = 6;
|
|
468
|
+
/** See `PCAC_AXIS_LABEL_SPACE` / `PCAC_AXIS_SUB_LABEL_SPACE` in chart.model.ts. */
|
|
469
|
+
static readonly AXIS_LABEL_SPACE = 18;
|
|
470
|
+
static readonly AXIS_SUB_LABEL_SPACE = 16;
|
|
312
471
|
margin: PcacChartMargin;
|
|
313
472
|
private readonly defaultMargin;
|
|
473
|
+
/**
|
|
474
|
+
* The current build's per-axis settings with defaults applied, set by `initializeAxisState()`.
|
|
475
|
+
* Builders read these (not the raw `config.xAxis`) everywhere: drawing the axes, choosing
|
|
476
|
+
* whether to draw a grid, how many grid lines, and so on. Pie has no axes and never sets them.
|
|
477
|
+
*/
|
|
478
|
+
xAxis: PcacResolvedAxisConfig;
|
|
479
|
+
yAxis: PcacResolvedAxisConfig;
|
|
314
480
|
svg: Selection<SVGGElement, unknown, BaseType, unknown>;
|
|
315
481
|
width: number;
|
|
316
482
|
height: number;
|
|
@@ -332,6 +498,12 @@ declare class PcacChart {
|
|
|
332
498
|
*/
|
|
333
499
|
private lastContainerHeight;
|
|
334
500
|
private lastHeightFull;
|
|
501
|
+
/**
|
|
502
|
+
* How much `initializeAxisState()` last added to `margin.bottom` for tick marks and axis
|
|
503
|
+
* labels (negative when a short tick took some away). `resolveHeight()` subtracts it from the
|
|
504
|
+
* plot height so the SVG's total height doesn't change with either. Reset alongside the margins.
|
|
505
|
+
*/
|
|
506
|
+
private reservedTickHeight;
|
|
335
507
|
/**
|
|
336
508
|
* Resolves the consumer's projected `<ng-template pcacTooltip>`, if any. Each chart component
|
|
337
509
|
* points this at its own `contentChild(PcacTooltipDirective)` query. It's a getter rather than
|
|
@@ -341,13 +513,71 @@ declare class PcacChart {
|
|
|
341
513
|
*/
|
|
342
514
|
tooltipTemplate: () => TemplateRef<PcacTooltipContext> | undefined;
|
|
343
515
|
/**
|
|
344
|
-
* Puts `margin` back to its defaults.
|
|
345
|
-
*
|
|
346
|
-
* `margin.left`): `margin` lives on this per-chart instance and so persists
|
|
347
|
-
* and without a reset an adjustment made for one config silently carries into
|
|
348
|
-
* e.g. axes drawn with no room after `
|
|
516
|
+
* Puts `margin` back to its defaults. `initializeAxisState()` calls this first thing, before any
|
|
517
|
+
* per-build adjustment (hidden axes giving sides back, tick sizes growing them, label widths
|
|
518
|
+
* measured into `margin.left`): `margin` lives on this per-chart instance and so persists
|
|
519
|
+
* between builds, and without a reset an adjustment made for one config silently carries into
|
|
520
|
+
* the next - e.g. axes drawn with no room after `hide` flips back to false.
|
|
349
521
|
*/
|
|
350
522
|
resetMargin(): void;
|
|
523
|
+
/**
|
|
524
|
+
* Resolves the config's `xAxis`/`yAxis` onto this chart and sets the margins up for them. Axis
|
|
525
|
+
* charts call this at the top of `buildChart()`, on their own copy of the config (it rewrites
|
|
526
|
+
* `config.height` for hidden axes), before `initializeChartState()` measures the plot area.
|
|
527
|
+
* In order:
|
|
528
|
+
*
|
|
529
|
+
* 1. `resetMargin()`.
|
|
530
|
+
* 2. Tick marks: room for a non-default `tickSize` is reserved on each axis that will actually
|
|
531
|
+
* be drawn (`reserveTickSizeMargins`).
|
|
532
|
+
* 3. Labels: `AXIS_LABEL_SPACE` is added to `bottom` / `left` for an axis with a `label`, and
|
|
533
|
+
* `AXIS_SUB_LABEL_SPACE` for one with any `subLabels` (see `axisLabelSpace`), again only if
|
|
534
|
+
* the axis will be drawn.
|
|
535
|
+
* 4. Hidden axes: an axis with `hide` gives its margins back to the plot. The y axis owns
|
|
536
|
+
* `left` and `top` (the top margin is only there so the topmost y label isn't clipped), the
|
|
537
|
+
* x axis `bottom` and `right` (likewise for the rightmost x label). Each reclaimed vertical
|
|
538
|
+
* margin is added onto `config.height` so the SVG's total height stays what the consumer
|
|
539
|
+
* configured; horizontally `initializeChartState()` picks the change up on its own.
|
|
540
|
+
*
|
|
541
|
+
* @param defaultGrid the axis whose grid this chart draws when the consumer hasn't said
|
|
542
|
+
* (`PcacAxisConfig.showGrid`): `'y'` for horizontal lines, `'x'` for vertical.
|
|
543
|
+
* @param hiddenAxisMargin what a hidden axis's sides shrink to, rather than 0. The
|
|
544
|
+
* line/area/plot charts keep 8px so a dot on the edge of the plot isn't clipped by the SVG.
|
|
545
|
+
*/
|
|
546
|
+
initializeAxisState(config: PcacAxisChartConfig, defaultGrid: 'x' | 'y', hiddenAxisMargin?: number): void;
|
|
547
|
+
/**
|
|
548
|
+
* The `PcacAxisBuilder` config for this chart's current state - everything but the scales and
|
|
549
|
+
* formats is already on the instance. Builders pass the result to `drawAxis()` (or `drawXAxis()`
|
|
550
|
+
* with a rescaled x, on zoom).
|
|
551
|
+
*/
|
|
552
|
+
axisBuilderConfig<XDomain extends AxisDomain, YDomain extends AxisDomain>(xScale: AxisScale<XDomain>, yScale: AxisScale<YDomain>, xFormat?: PcacFormatEnum, yFormat?: PcacFormatEnum): IPcacAxisBuilderConfig<XDomain, YDomain>;
|
|
553
|
+
/**
|
|
554
|
+
* Draws whichever grids the resolved axes ask for: vertical lines from the x axis's ticks,
|
|
555
|
+
* horizontal from the y's (`PcacAxisConfig.showGrid`). `which` restricts it to one axis - the
|
|
556
|
+
* line/area/plot charts redraw just the x grid against the rescaled x on zoom.
|
|
557
|
+
*/
|
|
558
|
+
drawGrids<XDomain extends AxisDomain, YDomain extends AxisDomain>(xScale: AxisScale<XDomain>, yScale: AxisScale<YDomain>, which?: 'x' | 'y' | 'both'): void;
|
|
559
|
+
/**
|
|
560
|
+
* Makes room in the margins for tick marks longer (or shorter) than D3's default. The default
|
|
561
|
+
* margins are sized around that default (`DEFAULT_TICK_SIZE`), and D3 places each tick label at
|
|
562
|
+
* tick length + padding, so a longer tick pushes its labels outward by exactly the difference -
|
|
563
|
+
* into space the margin doesn't have unless it grows by the same amount. Growing the margin here,
|
|
564
|
+
* *before* `initializeChartState()` measures the plot area, is what makes the chart shrink to fit
|
|
565
|
+
* its labels rather than pushing them off the edge of the SVG. A shorter tick hands the
|
|
566
|
+
* difference back to the plot area the same way.
|
|
567
|
+
*
|
|
568
|
+
* Horizontally that happens on its own: `initializeChartState()` derives `width` from the
|
|
569
|
+
* container minus the margins. Vertically it doesn't - `config.height` is the plot area, and
|
|
570
|
+
* the SVG is that plus the margins - so a taller bottom margin would grow the SVG instead. The
|
|
571
|
+
* delta is therefore also remembered in `reservedTickHeight` and taken back out of the plot
|
|
572
|
+
* height by `resolveHeight()`, keeping the chart's total footprint where the consumer put it.
|
|
573
|
+
*
|
|
574
|
+
* Called by `initializeAxisState()` right after `resetMargin()`, for the axes that will be
|
|
575
|
+
* drawn. Only the axis a tick size is given for is affected; `undefined` leaves that margin
|
|
576
|
+
* alone.
|
|
577
|
+
* @param xTickSize `tickSizeInner` for the bottom (x) axis, which lives in `margin.bottom`
|
|
578
|
+
* @param yTickSize `tickSizeInner` for the left (y) axis, which lives in `margin.left`
|
|
579
|
+
*/
|
|
580
|
+
reserveTickSizeMargins(xTickSize?: number, yTickSize?: number): void;
|
|
351
581
|
/**
|
|
352
582
|
* Shows the tooltip for a hovered datum, through the chart's `pcacTooltip` template when one is
|
|
353
583
|
* projected and the default key/value content otherwise. Every builder's hover handler should
|
|
@@ -409,11 +639,15 @@ declare class PcacChart {
|
|
|
409
639
|
* In some cases, that state needs to be calculated based on the content that resides in that margin.
|
|
410
640
|
* For example, labels on a horizontal bar chart are dynamic and such the margin needs to be calculated ahead of
|
|
411
641
|
* chart axis construction.
|
|
642
|
+
*
|
|
643
|
+
* Measures with the y axis's own `tickSize` (the measured box spans the tick line as well as
|
|
644
|
+
* the label, so measuring at a different length would put the labels off by the difference)
|
|
645
|
+
* and adds its `axisLabelSpace()` back on top, since the measurement replaces whatever
|
|
646
|
+
* `initializeAxisState()` reserved for the label / sub labels.
|
|
412
647
|
* @param chartElm Reference to SVG on dom
|
|
413
|
-
* @param data Generic multi-dimensional PcacData structure
|
|
414
648
|
* @param yScale D3 scale transformation object (d3.ScaleBand)
|
|
415
649
|
*/
|
|
416
|
-
setHorizontalMarginsBasedOnContent<Domain extends AxisDomain>(chartElm: ElementRef,
|
|
650
|
+
setHorizontalMarginsBasedOnContent<Domain extends AxisDomain>(chartElm: ElementRef, yScale: AxisScale<Domain>): void;
|
|
417
651
|
}
|
|
418
652
|
|
|
419
653
|
/**
|
|
@@ -430,7 +664,6 @@ declare class BarHorizontalChartBuilder extends PcacChart {
|
|
|
430
664
|
private config;
|
|
431
665
|
barClicked$: rxjs.Observable<PcacData>;
|
|
432
666
|
buildChart(chartElm: ElementRef, config: PcacBarHorizontalChartConfig): void;
|
|
433
|
-
private adjustForHiddenAxis;
|
|
434
667
|
private buildScales;
|
|
435
668
|
private drawChart;
|
|
436
669
|
private addGroups;
|
|
@@ -459,14 +692,11 @@ declare class PcacBarHorizontalChartComponent {
|
|
|
459
692
|
static ɵcmp: i0.ɵɵComponentDeclaration<PcacBarHorizontalChartComponent, "pcac-bar-horizontal-chart", never, { "config": { "alias": "config"; "required": true; "isSignal": true; }; }, { "barClicked": "barClicked"; }, ["tooltipTemplate"], never, true, never>;
|
|
460
693
|
}
|
|
461
694
|
|
|
462
|
-
declare class PcacBarVerticalChartConfig extends
|
|
695
|
+
declare class PcacBarVerticalChartConfig extends PcacAxisChartConfig {
|
|
463
696
|
domainMax: number;
|
|
464
|
-
numberOfTicks: number;
|
|
465
697
|
isStacked: boolean;
|
|
466
698
|
thresholds: PcacData[];
|
|
467
699
|
tickFormat: PcacFormatEnum;
|
|
468
|
-
hideGrid: boolean;
|
|
469
|
-
hideAxis: boolean;
|
|
470
700
|
spreadColorsPerGroup: boolean;
|
|
471
701
|
colorOverride: PcacBarVerticalChartColorOverrideConfig;
|
|
472
702
|
}
|
|
@@ -487,8 +717,6 @@ declare class BarVerticalChartBuilder extends PcacChart {
|
|
|
487
717
|
private barClickedSource;
|
|
488
718
|
barClicked$: rxjs.Observable<PcacData>;
|
|
489
719
|
buildChart(chartElm: ElementRef, config: PcacBarVerticalChartConfig): void;
|
|
490
|
-
private adjustForHiddenAxis;
|
|
491
|
-
private hasGroupLabel;
|
|
492
720
|
private buildScales;
|
|
493
721
|
private drawChart;
|
|
494
722
|
private addGroups;
|
|
@@ -575,12 +803,9 @@ declare class PcacPointImageConfig {
|
|
|
575
803
|
maxWidth: number;
|
|
576
804
|
maxHeight: number;
|
|
577
805
|
}
|
|
578
|
-
declare class PcacLineAreaChartConfig extends
|
|
806
|
+
declare class PcacLineAreaChartConfig extends PcacAxisChartConfig {
|
|
579
807
|
enableEffects: boolean;
|
|
580
808
|
enableZoom: boolean;
|
|
581
|
-
numberOfTicks: number;
|
|
582
|
-
hideGrid: boolean;
|
|
583
|
-
hideAxis: boolean;
|
|
584
809
|
yFormat: PcacFormatEnum;
|
|
585
810
|
xFormat: PcacFormatEnum;
|
|
586
811
|
yDomainMax: number | string;
|
|
@@ -648,7 +873,6 @@ declare class PcacAreaChart {
|
|
|
648
873
|
}
|
|
649
874
|
|
|
650
875
|
declare class PcacPieChartConfig extends PcacChartConfig {
|
|
651
|
-
numberOfTicks: number;
|
|
652
876
|
}
|
|
653
877
|
|
|
654
878
|
/**
|
|
@@ -688,5 +912,5 @@ declare class PcacPieChartComponent {
|
|
|
688
912
|
static ɵcmp: i0.ɵɵComponentDeclaration<PcacPieChartComponent, "pcac-pie-chart", never, { "config": { "alias": "config"; "required": true; "isSignal": true; }; }, { "sliceClicked": "sliceClicked"; }, ["tooltipTemplate"], never, true, never>;
|
|
689
913
|
}
|
|
690
914
|
|
|
691
|
-
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 };
|
|
692
|
-
export type { IPcacAxisBuilderConfig, IPcacGridBuilderConfig, PcacChartMargin, PcacTooltipContext, PcacTooltipOptions };
|
|
915
|
+
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 };
|
|
916
|
+
export type { IPcacAxisBuilderConfig, IPcacGridBuilderConfig, PcacChartMargin, PcacResolvedAxisConfig, PcacTooltipContext, PcacTooltipOptions };
|