@pioneer-code/pioneer-charts 22.2.13 → 22.2.15
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/LICENSE +21 -0
- package/README.md +12 -7
- package/fesm2022/pioneer-code-pioneer-charts.mjs +691 -386
- package/fesm2022/pioneer-code-pioneer-charts.mjs.map +1 -1
- package/package.json +13 -4
- package/scss/pie-chart/pie-chart.component.scss +0 -4
- package/types/pioneer-code-pioneer-charts.d.ts +105 -670
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, inject, ApplicationRef, DOCUMENT, DestroyRef, afterNextRender, TemplateRef, Directive, input, viewChild, contentChild, effect, ViewEncapsulation, Component, model, output, computed } from '@angular/core';
|
|
2
|
+
import { Injectable, signal, untracked, inject, ApplicationRef, DOCUMENT, DestroyRef, afterNextRender, TemplateRef, Directive, input, viewChild, contentChild, effect, ViewEncapsulation, Component, model, output, computed } from '@angular/core';
|
|
3
|
+
import { takeUntilDestroyed, outputFromObservable } from '@angular/core/rxjs-interop';
|
|
3
4
|
import { color } from 'd3-color';
|
|
4
|
-
import { scaleLinear, scaleBand } from 'd3-scale';
|
|
5
|
+
import { scaleLinear, scaleBand, scaleTime } from 'd3-scale';
|
|
5
6
|
import { select } from 'd3-selection';
|
|
6
|
-
import { transition } from 'd3-transition';
|
|
7
|
+
import { transition, active } from 'd3-transition';
|
|
7
8
|
import { Subject } from 'rxjs';
|
|
8
9
|
import { axisLeft, axisBottom } from 'd3-axis';
|
|
9
10
|
import { format } from 'd3-format';
|
|
10
|
-
import { takeUntilDestroyed, outputFromObservable } from '@angular/core/rxjs-interop';
|
|
11
11
|
import { debounceTime } from 'rxjs/operators';
|
|
12
12
|
import { range } from 'd3-array';
|
|
13
|
-
import { scaleTime, zoom } from 'd3';
|
|
14
13
|
import { line, area, arc, pie } from 'd3-shape';
|
|
14
|
+
import { zoom } from 'd3-zoom';
|
|
15
15
|
import { interpolate } from 'd3-interpolate';
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -19,10 +19,10 @@ import { interpolate } from 'd3-interpolate';
|
|
|
19
19
|
* INewChart extends IChart
|
|
20
20
|
*/
|
|
21
21
|
class PcacChartConfig {
|
|
22
|
+
data = [];
|
|
22
23
|
/**
|
|
23
24
|
* Height in pixels
|
|
24
25
|
*/
|
|
25
|
-
data = [];
|
|
26
26
|
height = 200;
|
|
27
27
|
/**
|
|
28
28
|
* When true, `height` becomes a *minimum* height: if the container the chart is placed in is
|
|
@@ -39,6 +39,12 @@ class PcacChartConfig {
|
|
|
39
39
|
* initializer still applies to anything constructed via `new`.
|
|
40
40
|
*/
|
|
41
41
|
heightFull = false;
|
|
42
|
+
/**
|
|
43
|
+
* What the chart shows, for screen readers - e.g. `'Sales by month, 2026'`. The chart's `<svg>` is
|
|
44
|
+
* announced as one image with this name; when it isn't set, the chart's type is used (`'Bar
|
|
45
|
+
* chart'`, `'Pie chart'`, ...). Optional for the same reason as `heightFull`.
|
|
46
|
+
*/
|
|
47
|
+
ariaLabel;
|
|
42
48
|
}
|
|
43
49
|
/**
|
|
44
50
|
* Up to three short labels placed along an axis by position rather than by value: `min` at its
|
|
@@ -267,13 +273,85 @@ var PcacFormatEnum;
|
|
|
267
273
|
PcacFormatEnum["DateTime"] = "dateTime";
|
|
268
274
|
PcacFormatEnum["Fahrenheit"] = "fahrenheit";
|
|
269
275
|
/**
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
* e.g. 0 = 12am, 1 = 1am, 13 = 1pm, 23 = 11pm
|
|
276
|
+
* Hours of the day, 0-24, labelled on a 12 hour clock: 0 = 12am, 1 = 1am, 13 = 1pm, 24 = 12am.
|
|
277
|
+
* A value between hours shows its minutes (2.5 = 2:30am).
|
|
273
278
|
*/
|
|
274
279
|
PcacFormatEnum["OneDayHours"] = "oneDayHours";
|
|
275
280
|
})(PcacFormatEnum || (PcacFormatEnum = {}));
|
|
276
281
|
|
|
282
|
+
/**
|
|
283
|
+
* `Percentage` values are fractions - `0.25` is 25% - on the axis and in the tooltip alike.
|
|
284
|
+
* `~` trims trailing zeros, so 0.07 reads `7%` rather than `7.000000%`.
|
|
285
|
+
*/
|
|
286
|
+
const formatPercent = format('~%');
|
|
287
|
+
/**
|
|
288
|
+
* An hour of the day, 0-24, on a 12-hour clock: 0 and 24 are `12am`, 13 is `1pm`, and a
|
|
289
|
+
* fractional hour gets its minutes (`2.5` is `2:30am`) rather than reading `2.5am`.
|
|
290
|
+
*/
|
|
291
|
+
function formatHourOfDay(value) {
|
|
292
|
+
let totalMinutes = Math.round(value * 60);
|
|
293
|
+
totalMinutes = ((totalMinutes % 1440) + 1440) % 1440;
|
|
294
|
+
const hour24 = Math.floor(totalMinutes / 60);
|
|
295
|
+
const minutes = totalMinutes % 60;
|
|
296
|
+
const hour = hour24 % 12 === 0 ? 12 : hour24 % 12;
|
|
297
|
+
const period = hour24 < 12 ? 'am' : 'pm';
|
|
298
|
+
return minutes === 0 ? `${hour}${period}` : `${hour}:${String(minutes).padStart(2, '0')}${period}`;
|
|
299
|
+
}
|
|
300
|
+
/** Plain numbers with thousands separators - `1,500`, `0.05` - for the `Decimal` format. */
|
|
301
|
+
const formatDecimal = format(',~f');
|
|
302
|
+
/**
|
|
303
|
+
* A single value (not a tick) in `pcacFormat`, the way an axis in that format labels it - so a
|
|
304
|
+
* tooltip reads like the axis it's measured against. Returns null for the formats that have no
|
|
305
|
+
* formatting of their own, and for a value the format can't read as a number, which callers show
|
|
306
|
+
* as it is.
|
|
307
|
+
*/
|
|
308
|
+
function formatValue(pcacFormat, value) {
|
|
309
|
+
const numeric = typeof value === 'number' || (typeof value === 'string' && value.trim() !== '')
|
|
310
|
+
? Number(value)
|
|
311
|
+
: NaN;
|
|
312
|
+
switch (pcacFormat) {
|
|
313
|
+
case PcacFormatEnum.Percentage:
|
|
314
|
+
return Number.isFinite(numeric) ? formatPercent(numeric) : null;
|
|
315
|
+
case PcacFormatEnum.Decimal:
|
|
316
|
+
return Number.isFinite(numeric) ? formatDecimal(numeric) : null;
|
|
317
|
+
case PcacFormatEnum.OneDayHours:
|
|
318
|
+
return Number.isFinite(numeric) ? formatHourOfDay(numeric) : null;
|
|
319
|
+
case PcacFormatEnum.Minutes:
|
|
320
|
+
return Number.isFinite(numeric) ? value + 'm' : null;
|
|
321
|
+
case PcacFormatEnum.Fahrenheit:
|
|
322
|
+
return Number.isFinite(numeric) ? value + ' F' : null;
|
|
323
|
+
default:
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* The tick label format for an axis in `format`, shared by both axes (so a format means the same
|
|
329
|
+
* thing on x and y) and by anything that labels a value on that axis, like the line/area hover
|
|
330
|
+
* crosshair. Returns null for the formats that keep D3's default labels.
|
|
331
|
+
*
|
|
332
|
+
* Numeric formats take their precision from the scale's tick step where the scale has one: a
|
|
333
|
+
* fixed precision is fine for a whole domain but breaks down once zoom narrows it to a few units.
|
|
334
|
+
*/
|
|
335
|
+
function axisTickFormat(pcacFormat, scale, ticks) {
|
|
336
|
+
const withTicks = scale;
|
|
337
|
+
switch (pcacFormat) {
|
|
338
|
+
case PcacFormatEnum.Percentage:
|
|
339
|
+
return withTicks.tickFormat ? withTicks.tickFormat(ticks, '~%') : (d) => formatPercent(Number(d));
|
|
340
|
+
case PcacFormatEnum.Decimal:
|
|
341
|
+
// Plain numbers with thousands separators - `1,500`, `0.05` - rather than SI prefixes, which
|
|
342
|
+
// turned a differential of 0.05 into `50m` (reading as minutes, like the Minutes format).
|
|
343
|
+
return withTicks.tickFormat ? withTicks.tickFormat(ticks, ',~f') : (d) => formatDecimal(Number(d));
|
|
344
|
+
case PcacFormatEnum.Minutes:
|
|
345
|
+
return (d) => d + 'm';
|
|
346
|
+
case PcacFormatEnum.Fahrenheit:
|
|
347
|
+
return (d) => d + ' F';
|
|
348
|
+
case PcacFormatEnum.OneDayHours:
|
|
349
|
+
return (d) => formatHourOfDay(Number(d));
|
|
350
|
+
default:
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
277
355
|
class PcacAxisBuilder {
|
|
278
356
|
drawAxis(config) {
|
|
279
357
|
this.drawXAxis(config);
|
|
@@ -299,16 +377,9 @@ class PcacAxisBuilder {
|
|
|
299
377
|
if (config.yAxis.tickSize !== undefined) {
|
|
300
378
|
yAxis.tickSizeInner(config.yAxis.tickSize);
|
|
301
379
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
break;
|
|
306
|
-
case PcacFormatEnum.Minutes:
|
|
307
|
-
yAxis.tickFormat((d) => d + 'm');
|
|
308
|
-
break;
|
|
309
|
-
case PcacFormatEnum.Fahrenheit:
|
|
310
|
-
yAxis.tickFormat((d) => d + ' F');
|
|
311
|
-
break;
|
|
380
|
+
const yFormat = axisTickFormat(config.yAxis.format, config.yScale, config.yAxis.ticks);
|
|
381
|
+
if (yFormat) {
|
|
382
|
+
yAxis.tickFormat(yFormat);
|
|
312
383
|
}
|
|
313
384
|
const group = config.svg.append('g')
|
|
314
385
|
.attr('class', 'pcac-y-axis')
|
|
@@ -328,27 +399,9 @@ class PcacAxisBuilder {
|
|
|
328
399
|
if (config.xAxis.tickSize !== undefined) {
|
|
329
400
|
xAxis.tickSizeInner(config.xAxis.tickSize);
|
|
330
401
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
break;
|
|
335
|
-
case PcacFormatEnum.Minutes:
|
|
336
|
-
xAxis.tickFormat((d) => d + 'm');
|
|
337
|
-
break;
|
|
338
|
-
case PcacFormatEnum.Fahrenheit:
|
|
339
|
-
xAxis.tickFormat((d) => d + ' F');
|
|
340
|
-
break;
|
|
341
|
-
case PcacFormatEnum.OneDayHours:
|
|
342
|
-
xAxis.tickFormat((d) => {
|
|
343
|
-
const h = d;
|
|
344
|
-
const hour = h % 12 === 0 ? 12 : h % 12;
|
|
345
|
-
const period = h < 12 ? 'am' : 'pm';
|
|
346
|
-
return `${hour}${period}`;
|
|
347
|
-
});
|
|
348
|
-
break;
|
|
349
|
-
case PcacFormatEnum.Decimal:
|
|
350
|
-
xAxis.tickFormat(decimalTickFormat(config.xScale, config.xAxis.ticks));
|
|
351
|
-
break;
|
|
402
|
+
const xFormat = axisTickFormat(config.xAxis.format, config.xScale, config.xAxis.ticks);
|
|
403
|
+
if (xFormat) {
|
|
404
|
+
xAxis.tickFormat(xFormat);
|
|
352
405
|
}
|
|
353
406
|
const group = config.svg.append('g')
|
|
354
407
|
.attr('class', 'pcac-x-axis')
|
|
@@ -395,10 +448,10 @@ class PcacAxisBuilder {
|
|
|
395
448
|
text('pcac-axis-sub-label', layout.length, edge, 'end', sub.max);
|
|
396
449
|
}
|
|
397
450
|
}
|
|
398
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
399
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
451
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacAxisBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
452
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacAxisBuilder, providedIn: 'root' });
|
|
400
453
|
}
|
|
401
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
454
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacAxisBuilder, decorators: [{
|
|
402
455
|
type: Injectable,
|
|
403
456
|
args: [{
|
|
404
457
|
providedIn: 'root',
|
|
@@ -419,20 +472,6 @@ function applyColors(group, axis) {
|
|
|
419
472
|
.style('--pcac-axis-label-color', () => axis.labelColor ?? null)
|
|
420
473
|
.style('--pcac-axis-sub-label-color', () => axis.subLabelColor ?? null);
|
|
421
474
|
}
|
|
422
|
-
/**
|
|
423
|
-
* Tick labels for a `Decimal` axis: SI-prefixed (`1.5k`), with the precision taken from the
|
|
424
|
-
* scale's own tick step rather than fixed. A fixed two significant digits (`.2s`) is fine for a
|
|
425
|
-
* whole domain but breaks down once zoom narrows it to a few units - ticks at 10.5, 11, 11.5, 12
|
|
426
|
-
* all rounded to `10 11 12 12`. `~` trims trailing zeros so a coarse step still reads `5 10 15`,
|
|
427
|
-
* not `5.0 10.0 15.0`. Falls back to the fixed format for a scale without `tickFormat` (a
|
|
428
|
-
* `Decimal` axis is always linear in practice, but the config type only promises `AxisScale`).
|
|
429
|
-
*/
|
|
430
|
-
function decimalTickFormat(scale, ticks) {
|
|
431
|
-
const withTicks = scale;
|
|
432
|
-
const formatTick = withTicks.tickFormat ? withTicks.tickFormat(ticks, '~s') : (d) => format('.2s')(d);
|
|
433
|
-
// The prefix comes from the domain's largest value, which would label the origin `0k`.
|
|
434
|
-
return (d) => (Number(d) === 0 ? '0' : formatTick(d));
|
|
435
|
-
}
|
|
436
475
|
|
|
437
476
|
/** Where along its axis each grid line sits, in pixels. */
|
|
438
477
|
function gridLines(scale, numberOfTicks) {
|
|
@@ -460,8 +499,7 @@ class PcacGridBuilder {
|
|
|
460
499
|
.attr('transform', (x) => (`translate(${x}, 0)`))
|
|
461
500
|
.append('svg:line')
|
|
462
501
|
.attr('y1', 0)
|
|
463
|
-
.attr('y2', config.height)
|
|
464
|
-
.attr('class', (d, i) => (i === 0 ? 'pcac-grid-rule-last' : ''));
|
|
502
|
+
.attr('y2', config.height);
|
|
465
503
|
}
|
|
466
504
|
/**
|
|
467
505
|
* Horizontal lines, one per y-axis tick (or category), running the plot's full width.
|
|
@@ -478,13 +516,12 @@ class PcacGridBuilder {
|
|
|
478
516
|
.attr('y1', (y) => y)
|
|
479
517
|
.attr('y2', (y) => y)
|
|
480
518
|
.attr('x1', 0)
|
|
481
|
-
.attr('x2', config.width)
|
|
482
|
-
.attr('class', (_, i) => (i === 0 ? 'pcac-grid-rule-last' : ''));
|
|
519
|
+
.attr('x2', config.width);
|
|
483
520
|
}
|
|
484
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
485
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
521
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacGridBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
522
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacGridBuilder, providedIn: 'root' });
|
|
486
523
|
}
|
|
487
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
524
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacGridBuilder, decorators: [{
|
|
488
525
|
type: Injectable,
|
|
489
526
|
args: [{
|
|
490
527
|
providedIn: 'root',
|
|
@@ -500,6 +537,22 @@ class PcacColorService {
|
|
|
500
537
|
orange = '#ffa177';
|
|
501
538
|
blue = '#55d8fe';
|
|
502
539
|
alert = 'red';
|
|
540
|
+
/**
|
|
541
|
+
* Bumped by every setter, and read by the getters, so anything reading colors inside a reactive
|
|
542
|
+
* context tracks palette changes: the legend's `colorScale` computed recomputes, and every chart
|
|
543
|
+
* (whose build runs in an `effect`) redraws - together, rather than the legend keeping the old
|
|
544
|
+
* swatches while newly built charts took the new palette.
|
|
545
|
+
*/
|
|
546
|
+
version = signal(0, /* @ts-ignore */
|
|
547
|
+
...(ngDevMode ? [{ debugName: "version" }] : /* istanbul ignore next */ []));
|
|
548
|
+
/**
|
|
549
|
+
* Bumps `version` from a setter. `untracked`, because Angular forbids writing a signal inside a
|
|
550
|
+
* `computed` - and a consumer deriving its theme reactively (`computed(() => { setScale(...);
|
|
551
|
+
* ... })`) called these setters there without error before they were reactive.
|
|
552
|
+
*/
|
|
553
|
+
changed() {
|
|
554
|
+
untracked(() => this.version.update((v) => v + 1));
|
|
555
|
+
}
|
|
503
556
|
/** A consumer's own scale from `setScale()`; replaces the default palette while set. */
|
|
504
557
|
customScale = null;
|
|
505
558
|
/**
|
|
@@ -522,6 +575,7 @@ class PcacColorService {
|
|
|
522
575
|
* @param numberOfNodes Number of items in dynamically build collection of colors
|
|
523
576
|
*/
|
|
524
577
|
getColorScale(numberOfNodes) {
|
|
578
|
+
this.version();
|
|
525
579
|
const palette = [];
|
|
526
580
|
for (let i = 0; i < numberOfNodes; i++) {
|
|
527
581
|
const mark = i % this.scale.length;
|
|
@@ -530,6 +584,7 @@ class PcacColorService {
|
|
|
530
584
|
return palette;
|
|
531
585
|
}
|
|
532
586
|
getAlert() {
|
|
587
|
+
this.version();
|
|
533
588
|
return this.alert;
|
|
534
589
|
}
|
|
535
590
|
/**
|
|
@@ -540,36 +595,45 @@ class PcacColorService {
|
|
|
540
595
|
*/
|
|
541
596
|
setScale(colors) {
|
|
542
597
|
this.customScale = colors.length ? [...colors] : null;
|
|
598
|
+
this.changed();
|
|
543
599
|
}
|
|
544
600
|
/** @deprecated No chart reads the primary color; it isn't part of the palette. */
|
|
545
601
|
setPrimary(color) {
|
|
546
602
|
this.primary = color;
|
|
603
|
+
this.changed();
|
|
547
604
|
}
|
|
548
605
|
setPrimaryLight(color) {
|
|
549
606
|
this.primaryLight = color;
|
|
607
|
+
this.changed();
|
|
550
608
|
}
|
|
551
609
|
setSuccess(color) {
|
|
552
610
|
this.success = color;
|
|
611
|
+
this.changed();
|
|
553
612
|
}
|
|
554
613
|
setDanger(color) {
|
|
555
614
|
this.danger = color;
|
|
615
|
+
this.changed();
|
|
556
616
|
}
|
|
557
617
|
setWarning(color) {
|
|
558
618
|
this.warning = color;
|
|
619
|
+
this.changed();
|
|
559
620
|
}
|
|
560
621
|
setOrange(color) {
|
|
561
622
|
this.orange = color;
|
|
623
|
+
this.changed();
|
|
562
624
|
}
|
|
563
625
|
setBlue(color) {
|
|
564
626
|
this.blue = color;
|
|
627
|
+
this.changed();
|
|
565
628
|
}
|
|
566
629
|
setAlert(color) {
|
|
567
630
|
this.alert = color;
|
|
631
|
+
this.changed();
|
|
568
632
|
}
|
|
569
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
570
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
633
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacColorService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
634
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacColorService, providedIn: 'root' });
|
|
571
635
|
}
|
|
572
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
636
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacColorService, decorators: [{
|
|
573
637
|
type: Injectable,
|
|
574
638
|
args: [{
|
|
575
639
|
providedIn: 'root',
|
|
@@ -581,10 +645,10 @@ class PcacTransitionService {
|
|
|
581
645
|
getTransitionDuration() {
|
|
582
646
|
return this.transitionDuration;
|
|
583
647
|
}
|
|
584
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
585
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
648
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTransitionService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
649
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTransitionService, providedIn: 'root' });
|
|
586
650
|
}
|
|
587
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
651
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTransitionService, decorators: [{
|
|
588
652
|
type: Injectable,
|
|
589
653
|
args: [{
|
|
590
654
|
providedIn: 'root',
|
|
@@ -609,7 +673,8 @@ class PcacTooltipBuilder {
|
|
|
609
673
|
get tooltip() {
|
|
610
674
|
this.shell ??= select(this.document.body)
|
|
611
675
|
.append('div')
|
|
612
|
-
.attr('class', 'pcac-d3-tooltip')
|
|
676
|
+
.attr('class', 'pcac-d3-tooltip')
|
|
677
|
+
.attr('role', 'tooltip');
|
|
613
678
|
return this.shell;
|
|
614
679
|
}
|
|
615
680
|
/**
|
|
@@ -620,14 +685,22 @@ class PcacTooltipBuilder {
|
|
|
620
685
|
*/
|
|
621
686
|
view = null;
|
|
622
687
|
viewTemplate = null;
|
|
688
|
+
/**
|
|
689
|
+
* Whatever showed the tooltip last (a chart passes itself), so `hideTooltip(owner)` from any
|
|
690
|
+
* other chart leaves it alone. The element is shared by every chart on the page: without this, a
|
|
691
|
+
* chart rebuilding or being destroyed would close the tooltip another chart is showing.
|
|
692
|
+
*/
|
|
693
|
+
owner = null;
|
|
623
694
|
/** Space left between the tooltip and whatever it's placed next to (the cursor or an anchor). */
|
|
624
695
|
static GAP = 8;
|
|
625
696
|
/**
|
|
626
697
|
* Shows the tooltip for a hovered datum. Renders `template` when the chart has one projected;
|
|
627
698
|
* otherwise falls back to the default key/value content, formatted per `valueFormat`/`keyFormat`.
|
|
628
699
|
* Placed beside `anchor` when one is given (see `positionBeside`), else above the event's position.
|
|
700
|
+
* `owner` is what's showing it (see `hideTooltip`).
|
|
629
701
|
*/
|
|
630
|
-
showTooltip(event, template, context, valueFormat, keyFormat, anchor) {
|
|
702
|
+
showTooltip(event, template, context, valueFormat, keyFormat, anchor, owner) {
|
|
703
|
+
this.owner = owner ?? null;
|
|
631
704
|
if (template) {
|
|
632
705
|
this.renderTemplate(template, context);
|
|
633
706
|
}
|
|
@@ -643,13 +716,15 @@ class PcacTooltipBuilder {
|
|
|
643
716
|
}
|
|
644
717
|
}
|
|
645
718
|
/**
|
|
646
|
-
*
|
|
647
|
-
*
|
|
719
|
+
* Hides the tooltip. Given an `owner`, only if that owner is the one showing it - so a chart can
|
|
720
|
+
* release the tooltip on rebuild or destroy without closing one another chart has open. Without
|
|
721
|
+
* an owner it always hides.
|
|
648
722
|
*/
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
723
|
+
hideTooltip(owner) {
|
|
724
|
+
if (owner !== undefined && owner !== this.owner) {
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
this.owner = null;
|
|
653
728
|
if (!this.shell) {
|
|
654
729
|
// Never shown, so there's nothing to hide - and no reason to create the element just to.
|
|
655
730
|
return;
|
|
@@ -729,12 +804,25 @@ class PcacTooltipBuilder {
|
|
|
729
804
|
}
|
|
730
805
|
/**
|
|
731
806
|
* Centers the tooltip horizontally on the cursor and sits it just above. Measured from the real
|
|
732
|
-
* box rather than fixed offsets so it works for content of any size.
|
|
807
|
+
* box rather than fixed offsets so it works for content of any size. Kept on screen like
|
|
808
|
+
* `positionBeside`: slid in from whichever side edge it would cross (the left one winning if it's
|
|
809
|
+
* wider than the viewport), and dropped below the cursor when there's no room above - hovering
|
|
810
|
+
* a bar at the page's edge used to cut the tooltip off.
|
|
733
811
|
*/
|
|
734
812
|
positionAbove(shell, event) {
|
|
813
|
+
const gap = PcacTooltipBuilder.GAP;
|
|
814
|
+
const width = shell.offsetWidth;
|
|
815
|
+
const height = shell.offsetHeight;
|
|
816
|
+
const viewport = this.document.documentElement;
|
|
817
|
+
const scrollX = this.document.defaultView?.scrollX ?? 0;
|
|
818
|
+
const scrollY = this.document.defaultView?.scrollY ?? 0;
|
|
819
|
+
const centered = event.pageX - width / 2;
|
|
820
|
+
const left = Math.max(scrollX, Math.min(centered, scrollX + viewport.clientWidth - width));
|
|
821
|
+
const above = event.pageY - height - gap;
|
|
822
|
+
const top = above >= scrollY ? above : event.pageY + gap;
|
|
735
823
|
this.tooltip
|
|
736
|
-
.style('left',
|
|
737
|
-
.style('top',
|
|
824
|
+
.style('left', left + 'px')
|
|
825
|
+
.style('top', top + 'px');
|
|
738
826
|
}
|
|
739
827
|
/**
|
|
740
828
|
* Places the tooltip diagonally off one corner of `anchor`'s rendered box, so it never covers
|
|
@@ -768,28 +856,29 @@ class PcacTooltipBuilder {
|
|
|
768
856
|
getBarTipData(data, valueFormat, keyFormat) {
|
|
769
857
|
let value = data.value;
|
|
770
858
|
let key = data.key;
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
859
|
+
// Formatted the way the value's axis labels it (see `formatValue`), so the tooltip for a
|
|
860
|
+
// point reads like the axis it sits against - `1:30pm`, not `13.5`, on a OneDayHours axis.
|
|
861
|
+
// A missing value stays blank rather than being formatted as `0%` / `null F`.
|
|
862
|
+
if (value !== null && value !== undefined) {
|
|
863
|
+
value = formatValue(valueFormat, value) ?? value;
|
|
864
|
+
}
|
|
865
|
+
if (key !== null && key !== undefined && key !== '') {
|
|
866
|
+
// A key that doesn't parse as a date is shown as it is, rather than as "Invalid Date".
|
|
867
|
+
if (keyFormat === PcacFormatEnum.DateTime && !Number.isNaN(new Date(key).getTime())) {
|
|
868
|
+
key = new Date(key).toLocaleDateString('en-US', {
|
|
869
|
+
day: '2-digit',
|
|
870
|
+
month: '2-digit',
|
|
871
|
+
year: 'numeric',
|
|
872
|
+
hour: '2-digit',
|
|
873
|
+
minute: '2-digit',
|
|
874
|
+
second: '2-digit'
|
|
875
|
+
});
|
|
779
876
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
day: '2-digit',
|
|
786
|
-
month: '2-digit',
|
|
787
|
-
year: 'numeric',
|
|
788
|
-
hour: '2-digit',
|
|
789
|
-
minute: '2-digit',
|
|
790
|
-
second: '2-digit'
|
|
791
|
-
});
|
|
792
|
-
break;
|
|
877
|
+
else if (keyFormat === PcacFormatEnum.Decimal) {
|
|
878
|
+
// Only where the key *is* the x value. Every other x format positions points by index,
|
|
879
|
+
// so its axis labels the index, not the key - formatting the key would only make it
|
|
880
|
+
// disagree with the axis (and tag text keys with a unit: `Mon` read `Monm` on Minutes).
|
|
881
|
+
key = formatValue(keyFormat, key) ?? key;
|
|
793
882
|
}
|
|
794
883
|
}
|
|
795
884
|
// A key of 0 (e.g. hour 0) is a real key; only a missing or empty one leaves the line out.
|
|
@@ -798,16 +887,24 @@ class PcacTooltipBuilder {
|
|
|
798
887
|
value: value === null || value === undefined ? '' : String(value),
|
|
799
888
|
};
|
|
800
889
|
}
|
|
801
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
802
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
890
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
891
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipBuilder, providedIn: 'root' });
|
|
803
892
|
}
|
|
804
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
893
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipBuilder, decorators: [{
|
|
805
894
|
type: Injectable,
|
|
806
895
|
args: [{
|
|
807
896
|
providedIn: 'root',
|
|
808
897
|
}]
|
|
809
898
|
}] });
|
|
810
899
|
|
|
900
|
+
/** The most of its container's width a chart's measured left (label) margin may take. */
|
|
901
|
+
const MAX_LABEL_MARGIN_SHARE = 0.5;
|
|
902
|
+
/** D3's gap between a tick and its label (`axis.tickPadding()`), which the builders never change. */
|
|
903
|
+
const TICK_PADDING = 3;
|
|
904
|
+
/** D3's default tick length (`axis.tickSizeInner()`), used while an axis's `tickSize` isn't set. */
|
|
905
|
+
const DEFAULT_TICK_SIZE = 6;
|
|
906
|
+
// Decorated only so Angular accepts its `ngOnDestroy` hook, which the builders extending it inherit;
|
|
907
|
+
// never provided itself - each builder is provided by its own chart component.
|
|
811
908
|
class PcacChart {
|
|
812
909
|
axisBuilder = inject(PcacAxisBuilder);
|
|
813
910
|
gridBuilder = inject(PcacGridBuilder);
|
|
@@ -832,7 +929,20 @@ class PcacChart {
|
|
|
832
929
|
width = 400;
|
|
833
930
|
height = 400;
|
|
834
931
|
colors = [];
|
|
932
|
+
/**
|
|
933
|
+
* How wide a y-axis tick label may be once `setHorizontalMarginsBasedOnContent` has capped the
|
|
934
|
+
* margin, or `null` while the labels fit as they are. See `truncateYTickLabels`.
|
|
935
|
+
*/
|
|
936
|
+
yTickLabelMaxWidth = null;
|
|
835
937
|
startData = [];
|
|
938
|
+
/** The chart's accessible name when its config gives no `ariaLabel`; each builder names its type. */
|
|
939
|
+
chartTypeLabel = 'Chart';
|
|
940
|
+
/** Grows the palette to at least `count` colors, repeating it as `getColorScale` does. */
|
|
941
|
+
ensureColorCount(count) {
|
|
942
|
+
if (this.colors.length < count) {
|
|
943
|
+
this.colors = this.colorService.getColorScale(count);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
836
946
|
/**
|
|
837
947
|
* Swaps a consumer's `colorOverride` in for the theme palette `initializeChartState` set, in
|
|
838
948
|
* order. Checks `length` rather than truthiness: every config class defaults its override to
|
|
@@ -1041,33 +1151,54 @@ class PcacChart {
|
|
|
1041
1151
|
index: options.index,
|
|
1042
1152
|
parentIndex: options.parentIndex ?? null,
|
|
1043
1153
|
coincident: options.coincident ?? [],
|
|
1044
|
-
}, options.valueFormat, options.keyFormat, options.anchor);
|
|
1154
|
+
}, options.valueFormat, options.keyFormat, options.anchor, this);
|
|
1045
1155
|
}
|
|
1156
|
+
/** Hides the tooltip if this chart is the one showing it; another chart's is left alone. */
|
|
1046
1157
|
hideTooltip() {
|
|
1047
|
-
this.tooltipBuilder.hideTooltip();
|
|
1158
|
+
this.tooltipBuilder.hideTooltip(this);
|
|
1048
1159
|
}
|
|
1049
1160
|
/**
|
|
1050
|
-
*
|
|
1051
|
-
*
|
|
1052
|
-
*
|
|
1053
|
-
* been laid out yet, so its `clientWidth` measures 0 — this happens when a chart mounts
|
|
1054
|
-
* already holding data (e.g. behind a loading gate) and its first `ngOnChanges` fires before
|
|
1055
|
-
* the browser has committed layout for its own just-created DOM node. Callers should bail out
|
|
1056
|
-
* of their build on `false` rather than proceeding with a degenerate width; `PcacChartResizeService`
|
|
1057
|
-
* (wired up by every chart component) retries the build once the container has a real size.
|
|
1058
|
-
* @param chartElm Reference to SVG on dom
|
|
1059
|
-
* @param config Chart specific configuration
|
|
1161
|
+
* Builders are provided per chart component, so Angular calls this when the component is
|
|
1162
|
+
* destroyed. A chart removed while hovered (an `@if` flip, a route change) gets no `mouseout`,
|
|
1163
|
+
* so without this its tooltip - and any consumer template view in it - would stay on screen.
|
|
1060
1164
|
*/
|
|
1165
|
+
ngOnDestroy() {
|
|
1166
|
+
this.hideTooltip();
|
|
1167
|
+
}
|
|
1061
1168
|
/**
|
|
1062
1169
|
* Removes whatever the chart last drew, for a build with no data to draw. Builders call it
|
|
1063
1170
|
* rather than just returning, which left the previous data on screen when a consumer emptied
|
|
1064
1171
|
* the chart (e.g. a filter that now matches nothing).
|
|
1065
1172
|
*/
|
|
1066
1173
|
clearChart(chartElm) {
|
|
1174
|
+
this.hideTooltip();
|
|
1067
1175
|
select(chartElm.nativeElement).select('g').remove();
|
|
1068
1176
|
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Prior to building a chart, we need to initialize the state of the chart.
|
|
1179
|
+
*
|
|
1180
|
+
* Returns `false` (and leaves `width`/`height`/`colors` untouched) if the container hasn't
|
|
1181
|
+
* been laid out yet, so its `clientWidth` measures 0 — this happens when a chart mounts
|
|
1182
|
+
* already holding data (e.g. behind a loading gate) and its first build `effect` run fires
|
|
1183
|
+
* before the browser has committed layout for its own just-created DOM node. Callers should
|
|
1184
|
+
* bail out of their build on `false` rather than proceeding with a degenerate width;
|
|
1185
|
+
* `PcacChartResizeService` (wired up by every chart component) retries the build once the
|
|
1186
|
+
* container has a real size.
|
|
1187
|
+
* @param chartElm Reference to SVG on dom
|
|
1188
|
+
* @param config Chart specific configuration
|
|
1189
|
+
*/
|
|
1069
1190
|
initializeChartState(chartElm, config) {
|
|
1191
|
+
// The rebuild removes the hovered element, which gets no mouseout to close its tooltip.
|
|
1192
|
+
this.hideTooltip();
|
|
1070
1193
|
select(chartElm.nativeElement).select('g').remove();
|
|
1194
|
+
// One color per group or per series within a group, whichever needs more. Bar charts, which
|
|
1195
|
+
// color by series across groups, top this up with `ensureColorCount()`. Read before the width
|
|
1196
|
+
// check below, even though a build that fails it draws nothing: this runs inside each chart
|
|
1197
|
+
// component's build `effect`, and reading the palette is what makes that effect redraw the
|
|
1198
|
+
// chart when the palette changes (see `PcacColorService`) - including a chart whose first
|
|
1199
|
+
// build found its container not laid out yet. (A loop rather than `Math.max(...)` over the
|
|
1200
|
+
// groups: spreading one argument per group overflows the call stack at a few hundred thousand.)
|
|
1201
|
+
const colors = this.colorService.getColorScale(config.data.reduce((max, d) => Math.max(max, d.data?.length ?? 0), config.data.length));
|
|
1071
1202
|
const container = chartElm.nativeElement.parentNode;
|
|
1072
1203
|
const containerWidth = container.clientWidth;
|
|
1073
1204
|
const measuredWidth = containerWidth - this.margin.left - this.margin.right;
|
|
@@ -1079,10 +1210,12 @@ class PcacChart {
|
|
|
1079
1210
|
return false;
|
|
1080
1211
|
}
|
|
1081
1212
|
this.width = measuredWidth;
|
|
1213
|
+
// Announced as a single image with a name, rather than as a pile of unlabelled shapes.
|
|
1214
|
+
select(chartElm.nativeElement)
|
|
1215
|
+
.attr('role', 'img')
|
|
1216
|
+
.attr('aria-label', config.ariaLabel || this.chartTypeLabel);
|
|
1082
1217
|
this.height = this.resolveHeight(container, config);
|
|
1083
|
-
|
|
1084
|
-
// largest group, since bars index colors by their position within their own group.
|
|
1085
|
-
this.colors = this.colorService.getColorScale(Math.max(config.data.length, ...config.data.map((d) => d.data?.length ?? 0)));
|
|
1218
|
+
this.colors = colors;
|
|
1086
1219
|
this.lastContainerWidth = containerWidth;
|
|
1087
1220
|
this.lastContainerHeight = container.clientHeight;
|
|
1088
1221
|
this.lastHeightFull = config.heightFull === true;
|
|
@@ -1120,9 +1253,10 @@ class PcacChart {
|
|
|
1120
1253
|
* `PcacChartResizeService`'s `ResizeObserver` is guaranteed to fire once as soon as it starts
|
|
1121
1254
|
* observing — that's what lets a chart recover from the 0-width race described on
|
|
1122
1255
|
* `initializeChartState`, but it also means that "routine" first callback usually lands
|
|
1123
|
-
* moments after `
|
|
1124
|
-
* check, that redundant callback would restart the chart's enter transition
|
|
1125
|
-
* no visual change. Only
|
|
1256
|
+
* moments after the component's build `effect` already built successfully at the same width.
|
|
1257
|
+
* Without this check, that redundant callback would restart the chart's enter transition
|
|
1258
|
+
* mid-animation for no visual change. Only that effect (which reacts to config, not size) should
|
|
1259
|
+
* skip this check.
|
|
1126
1260
|
* @param chartElm Reference to SVG on dom
|
|
1127
1261
|
*/
|
|
1128
1262
|
containerSizeChanged(chartElm) {
|
|
@@ -1175,10 +1309,16 @@ class PcacChart {
|
|
|
1175
1309
|
* the label, so measuring at a different length would put the labels off by the difference)
|
|
1176
1310
|
* and adds its `axisLabelSpace()` back on top, since the measurement replaces whatever
|
|
1177
1311
|
* `initializeAxisState()` reserved for the label / sub labels.
|
|
1312
|
+
*
|
|
1313
|
+
* The margin never takes more than `MAX_LABEL_MARGIN_SHARE` of the container: labels wider than
|
|
1314
|
+
* that are cut off at the chart's left edge rather than squeezing the plot to nothing (it used
|
|
1315
|
+
* to go to a negative width, and no bars drew at all). Returns `false`, like
|
|
1316
|
+
* `initializeChartState()`, if there is still no room left to draw in.
|
|
1178
1317
|
* @param chartElm Reference to SVG on dom
|
|
1179
1318
|
* @param yScale D3 scale transformation object (d3.ScaleBand)
|
|
1180
1319
|
*/
|
|
1181
1320
|
setHorizontalMarginsBasedOnContent(chartElm, yScale) {
|
|
1321
|
+
this.yTickLabelMaxWidth = null;
|
|
1182
1322
|
const axisY = axisLeft(yScale).ticks(5);
|
|
1183
1323
|
if (this.yAxis.tickSize !== undefined) {
|
|
1184
1324
|
axisY.tickSizeInner(this.yAxis.tickSize);
|
|
@@ -1198,17 +1338,72 @@ class PcacChart {
|
|
|
1198
1338
|
// double-counted it, and since `margin` persists on the builder between builds, the amount
|
|
1199
1339
|
// double-counted grew on the next rebuild - the plot area came out narrower than the
|
|
1200
1340
|
// container allowed and then shrank further after the first resize.
|
|
1201
|
-
const
|
|
1341
|
+
const containerWidth = this.width + this.margin.left + this.margin.right;
|
|
1342
|
+
const labelSpace = axisLabelSpace(this.yAxis);
|
|
1343
|
+
const left = Math.min(max + labelSpace, containerWidth * MAX_LABEL_MARGIN_SHARE);
|
|
1202
1344
|
this.width = this.width + this.margin.left - left;
|
|
1203
1345
|
this.margin.left = left;
|
|
1346
|
+
if (left < max + labelSpace) {
|
|
1347
|
+
// Capped: the labels are shortened to what's left between the axis title's band and the
|
|
1348
|
+
// ticks (see `truncateYTickLabels`), rather than running on past the chart's edge - and
|
|
1349
|
+
// over the title.
|
|
1350
|
+
const tickOverhead = Math.max(this.yAxis.tickSize ?? DEFAULT_TICK_SIZE, 0) + TICK_PADDING;
|
|
1351
|
+
this.yTickLabelMaxWidth = Math.max(0, left - labelSpace - tickOverhead);
|
|
1352
|
+
}
|
|
1353
|
+
return this.width > 0;
|
|
1204
1354
|
}
|
|
1355
|
+
/**
|
|
1356
|
+
* Shortens every y-axis tick label wider than the room `setHorizontalMarginsBasedOnContent` left
|
|
1357
|
+
* for it, ending it in "…". Call after the axis is drawn. Does nothing when the labels fit.
|
|
1358
|
+
*/
|
|
1359
|
+
truncateYTickLabels() {
|
|
1360
|
+
const maxWidth = this.yTickLabelMaxWidth;
|
|
1361
|
+
if (maxWidth === null) {
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
this.svg.selectAll('.pcac-y-axis .tick text').each(function () {
|
|
1365
|
+
fitText(this, maxWidth);
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChart, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1369
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChart });
|
|
1370
|
+
}
|
|
1371
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChart, decorators: [{
|
|
1372
|
+
type: Injectable
|
|
1373
|
+
}] });
|
|
1374
|
+
/**
|
|
1375
|
+
* Shortens `text` to the longest prefix that, with "…" appended, fits in `maxWidth` - just "…"
|
|
1376
|
+
* if nothing does. Measured with `getComputedTextLength()`, so the text must be rendered; left
|
|
1377
|
+
* alone where that isn't available (a DOM without layout).
|
|
1378
|
+
*/
|
|
1379
|
+
function fitText(text, maxWidth) {
|
|
1380
|
+
if (typeof text.getComputedTextLength !== 'function' || text.getComputedTextLength() <= maxWidth) {
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
const full = text.textContent ?? '';
|
|
1384
|
+
const withEllipsis = (length) => full.slice(0, length).trimEnd() + '…';
|
|
1385
|
+
let fits = 0;
|
|
1386
|
+
let tooLong = full.length;
|
|
1387
|
+
while (tooLong - fits > 1) {
|
|
1388
|
+
const mid = Math.floor((fits + tooLong) / 2);
|
|
1389
|
+
text.textContent = withEllipsis(mid);
|
|
1390
|
+
if (text.getComputedTextLength() <= maxWidth) {
|
|
1391
|
+
fits = mid;
|
|
1392
|
+
}
|
|
1393
|
+
else {
|
|
1394
|
+
tooLong = mid;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
text.textContent = withEllipsis(fits);
|
|
1205
1398
|
}
|
|
1206
1399
|
|
|
1207
1400
|
/**
|
|
1208
1401
|
* How long each bar is drawn: its value, or 0 when it can't be drawn - a null or non-numeric
|
|
1209
1402
|
* value, or `hide` set on the bar or on its whole group. A hidden bar keeps its slot (and so its
|
|
1210
1403
|
* color) and just draws nothing, the same way a hidden line/area/plot series keeps its place.
|
|
1211
|
-
*
|
|
1404
|
+
* A negative value is drawn as 0 too: the bar charts only draw upward from a 0 baseline, and a
|
|
1405
|
+
* negative size was an invalid SVG `height`/`width` (the bar vanished with a console error) that
|
|
1406
|
+
* also pulled the rest of a stack down over the bars before it.
|
|
1212
1407
|
*
|
|
1213
1408
|
* Keyed by the bar's own `PcacData` object so D3 callbacks (which only get the datum) can look
|
|
1214
1409
|
* their size up directly.
|
|
@@ -1218,7 +1413,7 @@ function barSizes(groups) {
|
|
|
1218
1413
|
for (const group of groups) {
|
|
1219
1414
|
for (const bar of group.data ?? []) {
|
|
1220
1415
|
const value = Number(bar.value ?? 0);
|
|
1221
|
-
sizes.set(bar, group.hide || bar.hide || !Number.isFinite(value) ? 0 : value);
|
|
1416
|
+
sizes.set(bar, group.hide || bar.hide || !Number.isFinite(value) ? 0 : Math.max(0, value));
|
|
1222
1417
|
}
|
|
1223
1418
|
}
|
|
1224
1419
|
return sizes;
|
|
@@ -1302,6 +1497,27 @@ function seriesKeys(groups) {
|
|
|
1302
1497
|
}
|
|
1303
1498
|
return [...keys];
|
|
1304
1499
|
}
|
|
1500
|
+
/**
|
|
1501
|
+
* Whether every bar has a key that is unique within its own group - what coloring bars by series
|
|
1502
|
+
* key needs. Without that (keys left `null`, as `PcacData` defaults them, or repeated within a
|
|
1503
|
+
* group, as stacked data often has), coloring by key would paint every bar sharing a key the
|
|
1504
|
+
* same color, so the bars fall back to being colored by their position in the group.
|
|
1505
|
+
*/
|
|
1506
|
+
function hasDistinctSeriesKeys(groups) {
|
|
1507
|
+
return groups.every((group) => {
|
|
1508
|
+
const keys = (group.data ?? []).map((bar) => bar.key);
|
|
1509
|
+
return keys.every((key) => key !== null && key !== undefined && key !== '')
|
|
1510
|
+
&& new Set(keys).size === keys.length;
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1513
|
+
/**
|
|
1514
|
+
* Whether a band scale spanning `length` pixels across `count` bands can round them to whole
|
|
1515
|
+
* pixels. Rounding gives crisp bar edges, but it floors the step - so with more bands than pixels
|
|
1516
|
+
* every band collapses to 0 and nothing draws. Only rounded while each band gets at least 2px.
|
|
1517
|
+
*/
|
|
1518
|
+
function canRoundBands(length, count) {
|
|
1519
|
+
return count > 0 && length / count >= 2;
|
|
1520
|
+
}
|
|
1305
1521
|
|
|
1306
1522
|
/**
|
|
1307
1523
|
* Provided per-component (see PcacBarHorizontalChartComponent's `providers`), not root-scoped:
|
|
@@ -1314,22 +1530,30 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1314
1530
|
yScaleStacked;
|
|
1315
1531
|
yScaleGrouped;
|
|
1316
1532
|
barClickedSource = new Subject();
|
|
1317
|
-
config;
|
|
1318
1533
|
barClicked$ = this.barClickedSource.asObservable();
|
|
1534
|
+
chartTypeLabel = 'Bar chart';
|
|
1319
1535
|
buildChart(chartElm, config) {
|
|
1320
1536
|
if (!config?.data?.length) {
|
|
1321
1537
|
this.clearChart(chartElm);
|
|
1322
1538
|
return;
|
|
1323
1539
|
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1540
|
+
// Shallow copy, as the vertical chart does: initializeAxisState() rewrites `height`, which
|
|
1541
|
+
// must not land on the consumer's config - but the data stays the consumer's own objects, so
|
|
1542
|
+
// `barClicked` and the tooltip hand back the very `PcacData` they passed in. (A JSON deep copy
|
|
1543
|
+
// used to hand back clones, which never matched the consumer's data by identity.)
|
|
1544
|
+
config = { ...config };
|
|
1545
|
+
this.initializeAxisState(config, 'x');
|
|
1546
|
+
if (!this.initializeChartState(chartElm, config)) {
|
|
1327
1547
|
return;
|
|
1328
1548
|
}
|
|
1549
|
+
this.ensureColorCount(seriesKeys(config.data).length);
|
|
1329
1550
|
this.applyColorOverride(config.colorOverride?.colors);
|
|
1330
|
-
this.buildScales(chartElm,
|
|
1331
|
-
|
|
1551
|
+
if (!this.buildScales(chartElm, config)) {
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
this.drawChart(chartElm, config);
|
|
1332
1555
|
}
|
|
1556
|
+
/** Returns `false` if the container leaves no room to draw in once the labels are measured. */
|
|
1333
1557
|
buildScales(chartElm, config) {
|
|
1334
1558
|
// Bars grow from 0, so only `domainMax` is read; `xAxis.domainMin` is ignored.
|
|
1335
1559
|
this.xScale = scaleLinear()
|
|
@@ -1337,20 +1561,25 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1337
1561
|
this.yScaleStacked = scaleBand()
|
|
1338
1562
|
.domain(config.data.map((d) => d.key))
|
|
1339
1563
|
.range([this.height, 0])
|
|
1564
|
+
// Rounded to whole pixels for crisp bar edges, while there's room to (see canRoundBands).
|
|
1565
|
+
.round(canRoundBands(this.height, config.data.length))
|
|
1340
1566
|
.padding(0.1);
|
|
1341
1567
|
this.yScaleGrouped = scaleBand()
|
|
1342
1568
|
.padding(0.05)
|
|
1343
|
-
.
|
|
1569
|
+
.range([0, this.yScaleStacked.bandwidth()])
|
|
1570
|
+
.round(canRoundBands(this.yScaleStacked.bandwidth(), seriesKeys(config.data).length))
|
|
1344
1571
|
.domain(seriesKeys(config.data));
|
|
1345
1572
|
// The left margin is sized to the y axis's labels - unless there is no y axis to size it to
|
|
1346
|
-
if (!this.yAxis.hide) {
|
|
1347
|
-
|
|
1573
|
+
if (!this.yAxis.hide && !this.setHorizontalMarginsBasedOnContent(chartElm, this.yScaleStacked)) {
|
|
1574
|
+
return false;
|
|
1348
1575
|
}
|
|
1349
1576
|
this.xScale.range([0, this.width]);
|
|
1577
|
+
return true;
|
|
1350
1578
|
}
|
|
1351
1579
|
drawChart(chartElm, config) {
|
|
1352
1580
|
this.buildContainer(chartElm);
|
|
1353
1581
|
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.xScale, this.yScaleStacked));
|
|
1582
|
+
this.truncateYTickLabels();
|
|
1354
1583
|
this.drawGrids(this.xScale, this.yScaleStacked);
|
|
1355
1584
|
this.addGroups(config);
|
|
1356
1585
|
this.axisBuilder.raiseAxes(this.svg);
|
|
@@ -1393,60 +1622,53 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1393
1622
|
const starts = config.isStacked ? stackStarts(config.data, sizes) : new Map();
|
|
1394
1623
|
const startOf = (d) => starts.get(d) ?? 0;
|
|
1395
1624
|
const endOf = (d) => startOf(d) + (sizes.get(d) ?? 0);
|
|
1625
|
+
// Colored by series - the bar's key's place among every group's keys, the same slot it's drawn
|
|
1626
|
+
// in - rather than by its position in its own group, which differs when groups hold different
|
|
1627
|
+
// series. By position after all when the keys can't tell series apart (see
|
|
1628
|
+
// `hasDistinctSeriesKeys`), and with `spreadColorsPerGroup`, by group instead.
|
|
1629
|
+
const keys = seriesKeys(config.data);
|
|
1630
|
+
const byKey = hasDistinctSeriesKeys(config.data);
|
|
1631
|
+
const fillOf = (d, bar) => {
|
|
1632
|
+
if (config.spreadColorsPerGroup) {
|
|
1633
|
+
return this.colors[Number(bar.parentNode.getAttribute('data-group-id'))];
|
|
1634
|
+
}
|
|
1635
|
+
return this.colors[byKey ? keys.indexOf(d.key) : Number(bar.getAttribute('data-group-bar-id'))];
|
|
1636
|
+
};
|
|
1396
1637
|
groups.enter().append('rect')
|
|
1397
1638
|
.attr('class', 'pcac-bar')
|
|
1398
1639
|
.attr('x', (d) => this.xScale(startOf(d)))
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1640
|
+
// A stacked bar spans its whole group, which is already translated into place; looking its
|
|
1641
|
+
// series key up in the group band put it off in another group's slot whenever the key
|
|
1642
|
+
// matched a group key.
|
|
1643
|
+
.attr('y', (d) => config.isStacked ? 0 : this.yScaleGrouped(d.key) ?? 0)
|
|
1403
1644
|
.attr('data-group-bar-id', (_, i) => {
|
|
1404
1645
|
return i;
|
|
1405
1646
|
})
|
|
1406
1647
|
.attr('height', !config.isStacked ? this.yScaleGrouped.bandwidth() : this.yScaleStacked.bandwidth())
|
|
1407
|
-
.style('fill', (d
|
|
1408
|
-
|
|
1409
|
-
const groupIndex = parseInt(n[0].parentNode.getAttribute('data-group-id'), 10);
|
|
1410
|
-
return this.colors[groupIndex];
|
|
1411
|
-
}
|
|
1412
|
-
return this.colors[i];
|
|
1648
|
+
.style('fill', function (d) {
|
|
1649
|
+
return fillOf(d, this);
|
|
1413
1650
|
})
|
|
1414
1651
|
.attr('width', 0)
|
|
1415
|
-
|
|
1652
|
+
// The hover fades run as their own named transition: an unnamed one would cancel the enter
|
|
1653
|
+
// transition still growing the bar, leaving it part-grown until the next rebuild.
|
|
1654
|
+
.on('mouseover', function (_event, d) {
|
|
1655
|
+
const fill = fillOf(d, this);
|
|
1416
1656
|
select(this)
|
|
1417
|
-
.transition()
|
|
1418
|
-
.duration(self.transitionService.getTransitionDuration() /
|
|
1419
|
-
.style('fill', ()
|
|
1420
|
-
if (config.spreadColorsPerGroup) {
|
|
1421
|
-
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
1422
|
-
const c = color(self.colors[groupIndex]);
|
|
1423
|
-
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
1424
|
-
return ct;
|
|
1425
|
-
}
|
|
1426
|
-
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
1427
|
-
const c = color(self.colors[groupIndex]);
|
|
1428
|
-
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
1429
|
-
return ct;
|
|
1430
|
-
});
|
|
1657
|
+
.transition('hover')
|
|
1658
|
+
.duration(self.transitionService.getTransitionDuration() / 5)
|
|
1659
|
+
.style('fill', color(fill)?.darker(1).toString() ?? fill);
|
|
1431
1660
|
})
|
|
1432
1661
|
.on('mousemove', function (event, d) {
|
|
1433
1662
|
const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
|
|
1434
1663
|
const index = Number(this.getAttribute('data-group-bar-id'));
|
|
1435
1664
|
self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.xAxis.format });
|
|
1436
1665
|
})
|
|
1437
|
-
.on('mouseout', function () {
|
|
1666
|
+
.on('mouseout', function (_event, d) {
|
|
1438
1667
|
self.hideTooltip();
|
|
1439
1668
|
select(this)
|
|
1440
|
-
.transition()
|
|
1669
|
+
.transition('hover')
|
|
1441
1670
|
.duration(self.transitionService.getTransitionDuration() / 5)
|
|
1442
|
-
.style('fill', ()
|
|
1443
|
-
if (config.spreadColorsPerGroup) {
|
|
1444
|
-
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
1445
|
-
return self.colors[groupIndex];
|
|
1446
|
-
}
|
|
1447
|
-
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
1448
|
-
return self.colors[groupIndex];
|
|
1449
|
-
});
|
|
1671
|
+
.style('fill', fillOf(d, this));
|
|
1450
1672
|
})
|
|
1451
1673
|
.on('click', (_event, d) => {
|
|
1452
1674
|
this.barClickedSource.next(d);
|
|
@@ -1503,6 +1725,10 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1503
1725
|
.attr('data-group-threshold-id', (_, i) => {
|
|
1504
1726
|
return i;
|
|
1505
1727
|
})
|
|
1728
|
+
// Placed in its bar's slot up front - only its value (`x`) animates. Set on the transition,
|
|
1729
|
+
// it slid in from the top of the group, where the vertical chart's appear in place.
|
|
1730
|
+
// ScaleBand can return undefined for a key outside its domain; `.attr()` needs null, not undefined.
|
|
1731
|
+
.attr('y', (d) => this.yScaleGrouped(d.key) ?? null)
|
|
1506
1732
|
.attr('height', this.yScaleGrouped.bandwidth());
|
|
1507
1733
|
rects.filter(function () {
|
|
1508
1734
|
return thresholdOf(this) === null;
|
|
@@ -1518,10 +1744,6 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1518
1744
|
})
|
|
1519
1745
|
.transition()
|
|
1520
1746
|
.duration(this.transitionService.getTransitionDuration())
|
|
1521
|
-
.attr('y', (d) => {
|
|
1522
|
-
// ScaleBand can return undefined for a key outside its domain; `.attr()` needs null, not undefined.
|
|
1523
|
-
return this.yScaleGrouped(d.key) ?? null;
|
|
1524
|
-
})
|
|
1525
1747
|
.attr('x', (_, i, nodes) => {
|
|
1526
1748
|
return this.xScale(Number(thresholdOf(nodes[i])?.value));
|
|
1527
1749
|
});
|
|
@@ -1542,10 +1764,10 @@ class BarHorizontalChartBuilder extends PcacChart {
|
|
|
1542
1764
|
this.hideTooltip();
|
|
1543
1765
|
});
|
|
1544
1766
|
}
|
|
1545
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1546
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
1767
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarHorizontalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
1768
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarHorizontalChartBuilder });
|
|
1547
1769
|
}
|
|
1548
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1770
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarHorizontalChartBuilder, decorators: [{
|
|
1549
1771
|
type: Injectable
|
|
1550
1772
|
}] });
|
|
1551
1773
|
|
|
@@ -1555,7 +1777,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
|
|
|
1555
1777
|
* A plain `window:resize` listener (the previous approach) misses any layout-driven size change
|
|
1556
1778
|
* that isn't a viewport resize — a sidebar collapsing, a tab becoming active, a flex/grid reflow.
|
|
1557
1779
|
* It also can't help a chart that mounts already holding data (e.g. behind a loading gate): that
|
|
1558
|
-
* chart's first `
|
|
1780
|
+
* chart's first build `effect` run can fire before the browser has committed layout for its own
|
|
1559
1781
|
* just-created DOM node, so `PcacChart.initializeChartState()` measures a 0-width container and
|
|
1560
1782
|
* bails out with nothing drawn — and with no resize ever firing, nothing retries it.
|
|
1561
1783
|
*
|
|
@@ -1598,10 +1820,10 @@ class PcacChartResizeService {
|
|
|
1598
1820
|
destroyRef.onDestroy(() => observer.disconnect());
|
|
1599
1821
|
});
|
|
1600
1822
|
}
|
|
1601
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1602
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
1823
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChartResizeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1824
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChartResizeService, providedIn: 'root' });
|
|
1603
1825
|
}
|
|
1604
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1826
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacChartResizeService, decorators: [{
|
|
1605
1827
|
type: Injectable,
|
|
1606
1828
|
args: [{ providedIn: 'root' }]
|
|
1607
1829
|
}] });
|
|
@@ -1651,10 +1873,10 @@ class PcacTooltipDirective {
|
|
|
1651
1873
|
static ngTemplateContextGuard(_dir, _ctx) {
|
|
1652
1874
|
return true;
|
|
1653
1875
|
}
|
|
1654
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1655
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.
|
|
1876
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1877
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.0", type: PcacTooltipDirective, isStandalone: true, selector: "ng-template[pcacTooltip]", ngImport: i0 });
|
|
1656
1878
|
}
|
|
1657
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1879
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacTooltipDirective, decorators: [{
|
|
1658
1880
|
type: Directive,
|
|
1659
1881
|
args: [{
|
|
1660
1882
|
selector: 'ng-template[pcacTooltip]'
|
|
@@ -1698,10 +1920,10 @@ class PcacBarHorizontalChartComponent {
|
|
|
1698
1920
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
1699
1921
|
}
|
|
1700
1922
|
}
|
|
1701
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1702
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
1923
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1924
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacBarHorizontalChartComponent, isStandalone: true, selector: "pcac-bar-horizontal-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { barClicked: "barClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [BarHorizontalChartBuilder], queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, 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"], encapsulation: i0.ViewEncapsulation.None });
|
|
1703
1925
|
}
|
|
1704
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
1926
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarHorizontalChartComponent, decorators: [{
|
|
1705
1927
|
type: Component,
|
|
1706
1928
|
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"] }]
|
|
1707
1929
|
}], 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 }] }] } });
|
|
@@ -1728,6 +1950,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1728
1950
|
yScale;
|
|
1729
1951
|
barClickedSource = new Subject();
|
|
1730
1952
|
barClicked$ = this.barClickedSource.asObservable();
|
|
1953
|
+
chartTypeLabel = 'Bar chart';
|
|
1731
1954
|
buildChart(chartElm, config) {
|
|
1732
1955
|
if (!config?.data?.length) {
|
|
1733
1956
|
this.clearChart(chartElm);
|
|
@@ -1741,6 +1964,7 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1741
1964
|
if (!this.initializeChartState(chartElm, config)) {
|
|
1742
1965
|
return;
|
|
1743
1966
|
}
|
|
1967
|
+
this.ensureColorCount(seriesKeys(config.data).length);
|
|
1744
1968
|
this.applyColorOverride(config.colorOverride?.colors);
|
|
1745
1969
|
this.buildScales(config);
|
|
1746
1970
|
this.drawChart(chartElm, config);
|
|
@@ -1754,11 +1978,14 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1754
1978
|
.domain([this.yAxis.domainMax, 0]);
|
|
1755
1979
|
this.xScaleStacked = scaleBand()
|
|
1756
1980
|
.domain(config.data.map((d) => d.key))
|
|
1757
|
-
.
|
|
1981
|
+
.range([0, this.width])
|
|
1982
|
+
// Rounded to whole pixels for crisp bar edges, while there's room to (see canRoundBands).
|
|
1983
|
+
.round(canRoundBands(this.width, config.data.length))
|
|
1758
1984
|
.padding(0.1);
|
|
1759
1985
|
this.xScaleGrouped = scaleBand()
|
|
1760
1986
|
.padding(0.2)
|
|
1761
|
-
.
|
|
1987
|
+
.range([0, this.xScaleStacked.bandwidth()])
|
|
1988
|
+
.round(canRoundBands(this.xScaleStacked.bandwidth(), seriesKeys(config.data).length))
|
|
1762
1989
|
.domain(seriesKeys(config.data));
|
|
1763
1990
|
}
|
|
1764
1991
|
drawChart(chartElm, config) {
|
|
@@ -1808,70 +2035,60 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1808
2035
|
const starts = config.isStacked ? stackStarts(config.data, sizes) : new Map();
|
|
1809
2036
|
const startOf = (d) => starts.get(d) ?? 0;
|
|
1810
2037
|
const endOf = (d) => startOf(d) + (sizes.get(d) ?? 0);
|
|
2038
|
+
// Colored by series - the bar's key's place among every group's keys, the same slot it's drawn
|
|
2039
|
+
// in - rather than by its position in its own group, which differs when groups hold different
|
|
2040
|
+
// series. By position after all when the keys can't tell series apart (see
|
|
2041
|
+
// `hasDistinctSeriesKeys`), and with `spreadColorsPerGroup`, by group instead.
|
|
2042
|
+
const keys = seriesKeys(config.data);
|
|
2043
|
+
const byKey = hasDistinctSeriesKeys(config.data);
|
|
2044
|
+
const fillOf = (d, bar) => {
|
|
2045
|
+
if (config.spreadColorsPerGroup) {
|
|
2046
|
+
return this.colors[Number(bar.parentNode.getAttribute('data-group-id'))];
|
|
2047
|
+
}
|
|
2048
|
+
return this.colors[byKey ? keys.indexOf(d.key) : Number(bar.getAttribute('data-group-bar-id'))];
|
|
2049
|
+
};
|
|
1811
2050
|
group.enter().append('rect')
|
|
1812
2051
|
.attr('class', 'pcac-bar')
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
2052
|
+
// A stacked bar spans its whole group, which is already translated into place; looking its
|
|
2053
|
+
// series key up in the group band put it off in another group's slot whenever the key
|
|
2054
|
+
// matched a group key.
|
|
2055
|
+
.attr('x', (d) => config.isStacked ? 0 : this.xScaleGrouped(d.key) ?? 0)
|
|
1817
2056
|
.attr('data-group-bar-id', (_, i) => {
|
|
1818
2057
|
return i;
|
|
1819
2058
|
})
|
|
1820
|
-
.style('fill', (d
|
|
1821
|
-
|
|
1822
|
-
const groupIndex = parseInt(n[0].parentNode.getAttribute('data-group-id'), 10);
|
|
1823
|
-
return this.colors[groupIndex];
|
|
1824
|
-
}
|
|
1825
|
-
return this.colors[i];
|
|
2059
|
+
.style('fill', function (d) {
|
|
2060
|
+
return fillOf(d, this);
|
|
1826
2061
|
})
|
|
1827
2062
|
.attr('y', () => {
|
|
1828
2063
|
return this.height;
|
|
1829
2064
|
})
|
|
1830
2065
|
.attr('height', 0)
|
|
1831
|
-
|
|
2066
|
+
// The hover fades run as their own named transition: an unnamed one would cancel the enter
|
|
2067
|
+
// transition still growing the bar, leaving it part-grown until the next rebuild.
|
|
2068
|
+
.on('mouseover', function (_event, d) {
|
|
2069
|
+
const fill = fillOf(d, this);
|
|
1832
2070
|
select(this)
|
|
1833
|
-
.transition()
|
|
2071
|
+
.transition('hover')
|
|
1834
2072
|
.duration(self.transitionService.getTransitionDuration() / 5)
|
|
1835
|
-
.style('fill', ()
|
|
1836
|
-
if (config.spreadColorsPerGroup) {
|
|
1837
|
-
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
1838
|
-
const c = color(self.colors[groupIndex]);
|
|
1839
|
-
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
1840
|
-
return ct;
|
|
1841
|
-
}
|
|
1842
|
-
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
1843
|
-
const c = color(self.colors[groupIndex]);
|
|
1844
|
-
const ct = c ? c.darker(1).toString() : self.colors[groupIndex];
|
|
1845
|
-
return ct;
|
|
1846
|
-
});
|
|
2073
|
+
.style('fill', color(fill)?.darker(1).toString() ?? fill);
|
|
1847
2074
|
})
|
|
1848
2075
|
.on('mousemove', function (event, d) {
|
|
1849
2076
|
const groupIndex = Number(this.parentNode.getAttribute('data-group-id'));
|
|
1850
2077
|
const index = Number(this.getAttribute('data-group-bar-id'));
|
|
1851
2078
|
self.showTooltip(event, d, { index, parent: config.data[groupIndex], parentIndex: groupIndex, valueFormat: self.yAxis.format });
|
|
1852
2079
|
})
|
|
1853
|
-
.on('mouseout', function () {
|
|
2080
|
+
.on('mouseout', function (_event, d) {
|
|
1854
2081
|
self.hideTooltip();
|
|
1855
2082
|
select(this)
|
|
1856
|
-
.transition()
|
|
2083
|
+
.transition('hover')
|
|
1857
2084
|
.duration(self.transitionService.getTransitionDuration() / 5)
|
|
1858
|
-
.style('fill', ()
|
|
1859
|
-
if (config.spreadColorsPerGroup) {
|
|
1860
|
-
const groupIndex = parseInt(this.parentNode.getAttribute('data-group-id'), 10);
|
|
1861
|
-
return self.colors[groupIndex];
|
|
1862
|
-
}
|
|
1863
|
-
const groupIndex = parseInt(this.getAttribute('data-group-bar-id'), 10);
|
|
1864
|
-
return self.colors[groupIndex];
|
|
1865
|
-
});
|
|
2085
|
+
.style('fill', fillOf(d, this));
|
|
1866
2086
|
})
|
|
1867
2087
|
.on('click', (_, d) => {
|
|
1868
2088
|
this.barClickedSource.next(d);
|
|
1869
2089
|
})
|
|
1870
2090
|
.transition()
|
|
1871
2091
|
.duration(this.transitionService.getTransitionDuration())
|
|
1872
|
-
// .transition(
|
|
1873
|
-
// transition().duration(this.transitionService.getTransitionDuration())
|
|
1874
|
-
// )
|
|
1875
2092
|
.attr('width', !config.isStacked ? this.xScaleGrouped.bandwidth() : this.xScaleStacked.bandwidth())
|
|
1876
2093
|
.attr('y', (d) => {
|
|
1877
2094
|
return this.yScale(endOf(d));
|
|
@@ -1977,10 +2194,10 @@ class BarVerticalChartBuilder extends PcacChart {
|
|
|
1977
2194
|
return '3px';
|
|
1978
2195
|
});
|
|
1979
2196
|
}
|
|
1980
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
1981
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
2197
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
2198
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder });
|
|
1982
2199
|
}
|
|
1983
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
2200
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: BarVerticalChartBuilder, decorators: [{
|
|
1984
2201
|
type: Injectable
|
|
1985
2202
|
}] });
|
|
1986
2203
|
|
|
@@ -2021,10 +2238,10 @@ class PcacBarVerticalChartComponent {
|
|
|
2021
2238
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
2022
2239
|
}
|
|
2023
2240
|
}
|
|
2024
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
2025
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
2241
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2242
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacBarVerticalChartComponent, isStandalone: true, selector: "pcac-bar-vertical-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { barClicked: "barClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, providers: [BarVerticalChartBuilder], queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, 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"], encapsulation: i0.ViewEncapsulation.None });
|
|
2026
2243
|
}
|
|
2027
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
2244
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacBarVerticalChartComponent, decorators: [{
|
|
2028
2245
|
type: Component,
|
|
2029
2246
|
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"] }]
|
|
2030
2247
|
}], 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 }] }] } });
|
|
@@ -2039,6 +2256,10 @@ class PcacBarVerticalChartColorOverrideConfig {
|
|
|
2039
2256
|
colors = [];
|
|
2040
2257
|
}
|
|
2041
2258
|
|
|
2259
|
+
// Only what a consumer configures, binds or styles with. The chart plumbing - the `PcacChart`
|
|
2260
|
+
// base class and the builders, the axis/grid/tooltip/transition/resize services, and the
|
|
2261
|
+
// resolved-config helpers - is internal, so it can change without breaking anyone.
|
|
2262
|
+
|
|
2042
2263
|
class PcacLegendConfigItem {
|
|
2043
2264
|
label;
|
|
2044
2265
|
checked = true;
|
|
@@ -2060,10 +2281,10 @@ class PcacLegend {
|
|
|
2060
2281
|
this.config.set({ ...this.config(), items });
|
|
2061
2282
|
this.itemClicked.emit(items);
|
|
2062
2283
|
}
|
|
2063
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
2064
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.
|
|
2284
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2285
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.0", type: PcacLegend, isStandalone: true, selector: "pcac-legend", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { config: "configChange", itemClicked: "itemClicked" }, ngImport: i0, template: "<div class=\"pcac-legend-label\"><small>{{config().heading}}</small></div>\n@for(item of config().items; track $index; let i = $index; let last = $last;) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-item-last]=\"last\" [class.pcac-legend-unchecked]=\"!item.checked\"\n role=\"switch\" [attr.aria-checked]=\"item.checked\" tabindex=\"0\" (click)=\"onItemClicked(i)\"\n (keydown.enter)=\"onItemClicked(i)\" (keydown.space)=\"onItemClicked(i); $event.preventDefault()\">\n @let color = item.colorOverride ? item.colorOverride : colorScale()[i];\n <div class=\"pcac-legend-circle\" [style.backgroundColor]=\"color\"></div>\n <small>{{ item.label }}</small>\n</div>\n}\n", styles: [":host{display:flex;align-items:center}.pcac-legend-label{margin-right:8px;margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;margin-right:8px}.pcac-legend-item:hover .pcac-legend-circle{box-shadow:0 0 6px #0000004d;transform:scale(1.2)}.pcac-legend-circle{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;transition:box-shadow .3s ease,transform .3s ease}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item-last{margin-right:0}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] });
|
|
2065
2286
|
}
|
|
2066
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
2287
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLegend, decorators: [{
|
|
2067
2288
|
type: Component,
|
|
2068
2289
|
args: [{ selector: 'pcac-legend', template: "<div class=\"pcac-legend-label\"><small>{{config().heading}}</small></div>\n@for(item of config().items; track $index; let i = $index; let last = $last;) {\n<div class=\"pcac-legend-item\" [class.pcac-legend-item-last]=\"last\" [class.pcac-legend-unchecked]=\"!item.checked\"\n role=\"switch\" [attr.aria-checked]=\"item.checked\" tabindex=\"0\" (click)=\"onItemClicked(i)\"\n (keydown.enter)=\"onItemClicked(i)\" (keydown.space)=\"onItemClicked(i); $event.preventDefault()\">\n @let color = item.colorOverride ? item.colorOverride : colorScale()[i];\n <div class=\"pcac-legend-circle\" [style.backgroundColor]=\"color\"></div>\n <small>{{ item.label }}</small>\n</div>\n}\n", styles: [":host{display:flex;align-items:center}.pcac-legend-label{margin-right:8px;margin-bottom:2.5px}.pcac-legend-item{cursor:pointer;display:flex;align-items:center;margin-right:8px}.pcac-legend-item:hover .pcac-legend-circle{box-shadow:0 0 6px #0000004d;transform:scale(1.2)}.pcac-legend-circle{display:inline-block;width:12px;height:12px;border-radius:50%;margin-right:4px;transition:box-shadow .3s ease,transform .3s ease}.pcac-legend-unchecked{opacity:.5}.pcac-legend-item-last{margin-right:0}.pcac-legend-item:focus-visible{outline:2px solid currentColor;outline-offset:2px}\n"] }]
|
|
2069
2290
|
}], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }, { type: i0.Output, args: ["configChange"] }], itemClicked: [{ type: i0.Output, args: ["itemClicked"] }] } });
|
|
@@ -2160,45 +2381,73 @@ class PcacLineAreaChartConfig extends PcacAxisChartConfig {
|
|
|
2160
2381
|
pointRange;
|
|
2161
2382
|
}
|
|
2162
2383
|
|
|
2384
|
+
/**
|
|
2385
|
+
* Whether a point has an x key to position by. An explicit emptiness check, not truthiness: a
|
|
2386
|
+
* Decimal key of `0` is a perfectly good coordinate (the left edge of a `domainMin: 0` axis) and
|
|
2387
|
+
* used to be read as "no key" - drawn at pixel 0 whatever the domain, and pinned there under zoom.
|
|
2388
|
+
*/
|
|
2389
|
+
function hasKey(data) {
|
|
2390
|
+
return data.key !== null && data.key !== undefined && data.key !== '';
|
|
2391
|
+
}
|
|
2392
|
+
function getXFormat(type, data, index, xScale) {
|
|
2393
|
+
switch (type) {
|
|
2394
|
+
case PcacFormatEnum.DateTime:
|
|
2395
|
+
if (hasKey(data)) {
|
|
2396
|
+
return xScale(new Date(data.key));
|
|
2397
|
+
}
|
|
2398
|
+
return 0;
|
|
2399
|
+
case PcacFormatEnum.Decimal:
|
|
2400
|
+
if (hasKey(data)) {
|
|
2401
|
+
return xScale(Number(data.key));
|
|
2402
|
+
}
|
|
2403
|
+
return 0;
|
|
2404
|
+
default:
|
|
2405
|
+
return xScale(index);
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
/** Whether a point has a numeric value to draw at. */
|
|
2410
|
+
function hasValue(d) {
|
|
2411
|
+
return d.value !== null && d.value !== undefined && d.value !== '' && Number.isFinite(Number(d.value));
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2163
2414
|
/**
|
|
2164
2415
|
* Provided per-component (see PcacLineAreaChartComponent's `providers`), not root-scoped: this
|
|
2165
|
-
* holds mutable per-chart-instance state (`config`, `
|
|
2416
|
+
* holds mutable per-chart-instance state (`config`, `series`) despite looking like a stateless
|
|
2166
2417
|
* helper. A root singleton would be shared and clobbered by every `<pcac-line-area-chart>`
|
|
2167
2418
|
* rendered at once — each instance's hover effects would end up reading/writing whichever
|
|
2168
2419
|
* chart's `buildEffects()` ran last, not their own.
|
|
2169
2420
|
*/
|
|
2170
2421
|
class PlaChartEffectsBuilder {
|
|
2171
2422
|
config;
|
|
2172
|
-
//
|
|
2173
|
-
//
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
lines = [];
|
|
2423
|
+
// The series that get an effect group, each with its index in `config.data` (which is what its
|
|
2424
|
+
// line's color is picked by, so a skipped empty series doesn't shift the colors after it).
|
|
2425
|
+
series = [];
|
|
2426
|
+
/** Where the cursor last was over the plot, while the crosshair is showing; null otherwise. */
|
|
2427
|
+
lastMousePos = null;
|
|
2178
2428
|
buildEffects(config) {
|
|
2179
2429
|
this.config = config;
|
|
2180
|
-
this.
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
// wrong path.
|
|
2185
|
-
this.config.svg.selectAll('.line, .area')
|
|
2186
|
-
.filter((d) => d?.length !== 0)
|
|
2187
|
-
.each((d, i, n) => {
|
|
2188
|
-
this.lines.push(n[i]);
|
|
2189
|
-
});
|
|
2430
|
+
this.lastMousePos = null;
|
|
2431
|
+
this.series = config.data
|
|
2432
|
+
.map((data, index) => ({ data, index }))
|
|
2433
|
+
.filter(({ data }) => data.data.length > 0);
|
|
2190
2434
|
this.buildCollection();
|
|
2191
2435
|
this.buildCanvas();
|
|
2192
2436
|
}
|
|
2193
2437
|
/**
|
|
2194
|
-
* Swaps in the scales a zoom has rescaled. The crosshair
|
|
2195
|
-
*
|
|
2196
|
-
*
|
|
2197
|
-
* the pixel against the original domain.
|
|
2438
|
+
* Swaps in the scales a zoom has rescaled. The crosshair positions and labels its points
|
|
2439
|
+
* against the scales, so a zoom has to hand them over here or it would track the unzoomed
|
|
2440
|
+
* lines.
|
|
2198
2441
|
*/
|
|
2199
2442
|
updateScales(x, y) {
|
|
2200
2443
|
this.config.x = x;
|
|
2201
2444
|
this.config.y = y;
|
|
2445
|
+
// A wheel zoom moves the lines under a cursor that stays put, and sends no mousemove - so the
|
|
2446
|
+
// crosshair is re-read at the same spot, or it would sit on the pre-zoom values until the
|
|
2447
|
+
// mouse next moved.
|
|
2448
|
+
if (this.lastMousePos) {
|
|
2449
|
+
this.onMouseMove(this.lastMousePos);
|
|
2450
|
+
}
|
|
2202
2451
|
}
|
|
2203
2452
|
buildCollection() {
|
|
2204
2453
|
const collection = this.config.svg.append('g')
|
|
@@ -2206,18 +2455,14 @@ class PlaChartEffectsBuilder {
|
|
|
2206
2455
|
collection.append('path')
|
|
2207
2456
|
.attr('class', 'effect-line');
|
|
2208
2457
|
const mousePerLine = collection.selectAll('.effect-group')
|
|
2209
|
-
.data(this.
|
|
2210
|
-
return elm.data.length > 0;
|
|
2211
|
-
}))
|
|
2458
|
+
.data(this.series)
|
|
2212
2459
|
.enter().append('g')
|
|
2213
2460
|
.attr('class', 'effect-group')
|
|
2214
|
-
.attr('style', (
|
|
2461
|
+
.attr('style', ({ data }) => data.hide ? 'display: none' : null);
|
|
2215
2462
|
mousePerLine.append('circle')
|
|
2216
2463
|
.attr('r', 7)
|
|
2217
2464
|
.attr('class', 'effect-circle')
|
|
2218
|
-
.style('stroke', (
|
|
2219
|
-
return this.config.colors[i];
|
|
2220
|
-
});
|
|
2465
|
+
.style('stroke', ({ index }) => this.config.colors[index]);
|
|
2221
2466
|
mousePerLine.append('text')
|
|
2222
2467
|
.attr('class', 'effect-text')
|
|
2223
2468
|
.attr('y', 1.5)
|
|
@@ -2257,6 +2502,7 @@ class PlaChartEffectsBuilder {
|
|
|
2257
2502
|
.style('opacity', '1');
|
|
2258
2503
|
}
|
|
2259
2504
|
hideEffects() {
|
|
2505
|
+
this.lastMousePos = null;
|
|
2260
2506
|
this.config.svg.select('.effect-line')
|
|
2261
2507
|
.style('opacity', '0');
|
|
2262
2508
|
this.config.svg.selectAll('.effect-group circle')
|
|
@@ -2265,6 +2511,7 @@ class PlaChartEffectsBuilder {
|
|
|
2265
2511
|
.style('opacity', '0');
|
|
2266
2512
|
}
|
|
2267
2513
|
onMouseMove(mousePos) {
|
|
2514
|
+
this.lastMousePos = mousePos;
|
|
2268
2515
|
this.updateLine(mousePos);
|
|
2269
2516
|
this.updateEffects(mousePos);
|
|
2270
2517
|
}
|
|
@@ -2274,43 +2521,77 @@ class PlaChartEffectsBuilder {
|
|
|
2274
2521
|
}
|
|
2275
2522
|
updateEffects(mousePos) {
|
|
2276
2523
|
this.config.svg.selectAll('.effect-group')
|
|
2277
|
-
.
|
|
2278
|
-
const
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
let beginning = 0;
|
|
2286
|
-
let end = line.getTotalLength();
|
|
2287
|
-
let pos;
|
|
2288
|
-
while (true) {
|
|
2289
|
-
const target = Math.floor((beginning + end) / 2);
|
|
2290
|
-
pos = line.getPointAtLength(target);
|
|
2291
|
-
if ((target === end || target === beginning) && pos.x !== mousePos[0]) {
|
|
2292
|
-
break;
|
|
2293
|
-
}
|
|
2294
|
-
if (pos.x > mousePos[0]) {
|
|
2295
|
-
end = target;
|
|
2296
|
-
}
|
|
2297
|
-
else if (pos.x < mousePos[0]) {
|
|
2298
|
-
beginning = target;
|
|
2299
|
-
}
|
|
2300
|
-
else {
|
|
2301
|
-
break;
|
|
2302
|
-
}
|
|
2524
|
+
.each((series, index, nodes) => {
|
|
2525
|
+
const group = select(nodes[index]);
|
|
2526
|
+
const value = this.valueAt(series.data.data, mousePos[0]);
|
|
2527
|
+
// No value under the cursor (a gap in the series): nothing to mark, so the group is
|
|
2528
|
+
// hidden rather than left at its last position.
|
|
2529
|
+
group.attr('visibility', value === null ? 'hidden' : null);
|
|
2530
|
+
if (value === null) {
|
|
2531
|
+
return;
|
|
2303
2532
|
}
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
.text(textTarget.toFixed(0));
|
|
2307
|
-
return 'translate(' + mousePos[0] + ',' + pos.y + ')';
|
|
2533
|
+
group.attr('transform', 'translate(' + mousePos[0] + ',' + this.config.y(value) + ')');
|
|
2534
|
+
group.select('text').text(this.formatValue(value));
|
|
2308
2535
|
});
|
|
2309
2536
|
}
|
|
2310
|
-
|
|
2311
|
-
|
|
2537
|
+
/**
|
|
2538
|
+
* The series' value at plot x `mouseX`, interpolated along the segment of the line that spans it
|
|
2539
|
+
* - the same (linear) join the line/area draws between two consecutive points - or null if it
|
|
2540
|
+
* falls in a gap, where the line isn't drawn. Beyond the line's leftmost/rightmost point it holds
|
|
2541
|
+
* that point's value.
|
|
2542
|
+
*
|
|
2543
|
+
* Works on the segments in data order and never assumes x increases along them: DateTime or
|
|
2544
|
+
* Decimal data can come newest-first (or in any order), and the line still joins consecutive
|
|
2545
|
+
* points - reading "the first point" as the leftmost one showed the newest value everywhere.
|
|
2546
|
+
*
|
|
2547
|
+
* Worked out from the data rather than by walking the drawn path: an area's outline doubles
|
|
2548
|
+
* back along its baseline, so a search over the path's geometry could land on the bottom edge
|
|
2549
|
+
* and read the wrong value.
|
|
2550
|
+
*/
|
|
2551
|
+
valueAt(points, mouseX) {
|
|
2552
|
+
const xAt = (i) => getXFormat(this.config.xFormat, points[i], i, this.config.x);
|
|
2553
|
+
const valueOf = (i) => Number(points[i].value);
|
|
2554
|
+
const drawn = points.map((_, i) => i).filter((i) => hasValue(points[i]));
|
|
2555
|
+
if (!drawn.length) {
|
|
2556
|
+
return null;
|
|
2557
|
+
}
|
|
2558
|
+
// A segment joins two points next to each other in the data, both with a value - a point
|
|
2559
|
+
// without one between them breaks the line (`defined(hasValue)`).
|
|
2560
|
+
for (let i = 1; i < points.length; i++) {
|
|
2561
|
+
if (!hasValue(points[i - 1]) || !hasValue(points[i])) {
|
|
2562
|
+
continue;
|
|
2563
|
+
}
|
|
2564
|
+
const [xa, xb] = [xAt(i - 1), xAt(i)];
|
|
2565
|
+
if (mouseX < Math.min(xa, xb) || mouseX > Math.max(xa, xb)) {
|
|
2566
|
+
continue;
|
|
2567
|
+
}
|
|
2568
|
+
const [va, vb] = [valueOf(i - 1), valueOf(i)];
|
|
2569
|
+
return xb === xa ? vb : va + (vb - va) * (mouseX - xa) / (xb - xa);
|
|
2570
|
+
}
|
|
2571
|
+
const leftmost = drawn.reduce((min, i) => (xAt(i) < xAt(min) ? i : min));
|
|
2572
|
+
const rightmost = drawn.reduce((max, i) => (xAt(i) > xAt(max) ? i : max));
|
|
2573
|
+
if (mouseX <= xAt(leftmost)) {
|
|
2574
|
+
return valueOf(leftmost);
|
|
2575
|
+
}
|
|
2576
|
+
if (mouseX >= xAt(rightmost)) {
|
|
2577
|
+
return valueOf(rightmost);
|
|
2578
|
+
}
|
|
2579
|
+
return null;
|
|
2580
|
+
}
|
|
2581
|
+
/**
|
|
2582
|
+
* The crosshair's value, formatted the way the y axis labels its ticks - same format, same
|
|
2583
|
+
* step-based precision - rather than rounded to a whole number, which read a 0-1 axis as 0 or 1.
|
|
2584
|
+
*/
|
|
2585
|
+
formatValue(value) {
|
|
2586
|
+
const y = this.config.y;
|
|
2587
|
+
const formatter = axisTickFormat(this.config.yFormat, y, this.config.yTicks)
|
|
2588
|
+
?? y.tickFormat(this.config.yTicks);
|
|
2589
|
+
return formatter(value);
|
|
2590
|
+
}
|
|
2591
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartEffectsBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2592
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartEffectsBuilder });
|
|
2312
2593
|
}
|
|
2313
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
2594
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartEffectsBuilder, decorators: [{
|
|
2314
2595
|
type: Injectable
|
|
2315
2596
|
}] });
|
|
2316
2597
|
|
|
@@ -2372,6 +2653,10 @@ class PlaChartScales {
|
|
|
2372
2653
|
* `format`/`domainMin`/`domainMax` defaults are already applied - see `PcacLineAreaChartConfig`
|
|
2373
2654
|
* for what each format does with them.
|
|
2374
2655
|
*/
|
|
2656
|
+
/** The number of points in the longest series. */
|
|
2657
|
+
function longestSeriesLength(data) {
|
|
2658
|
+
return data.reduce((max, series) => Math.max(max, series.data.length), 0);
|
|
2659
|
+
}
|
|
2375
2660
|
class PlaChartScalesBuilder {
|
|
2376
2661
|
build(xAxis, yAxis, data, chartWidth, chartHeight) {
|
|
2377
2662
|
const resp = new PlaChartScales();
|
|
@@ -2390,9 +2675,11 @@ class PlaChartScalesBuilder {
|
|
|
2390
2675
|
.domain([xAxis.domainMin, xAxis.domainMax])
|
|
2391
2676
|
.range([0, chartWidth]);
|
|
2392
2677
|
default:
|
|
2393
|
-
// DatasetLength and every other format position points by index
|
|
2678
|
+
// DatasetLength and every other format position points by index - across the longest
|
|
2679
|
+
// series, not the first, which may be shorter or empty (an empty one gave [0, -1], an
|
|
2680
|
+
// inverted scale that pushed every point off the plot).
|
|
2394
2681
|
return scaleLinear()
|
|
2395
|
-
.domain([0,
|
|
2682
|
+
.domain([0, Math.max(0, longestSeriesLength(data) - 1)])
|
|
2396
2683
|
.range([0, chartWidth]);
|
|
2397
2684
|
}
|
|
2398
2685
|
}
|
|
@@ -2403,36 +2690,6 @@ class PlaChartScalesBuilder {
|
|
|
2403
2690
|
}
|
|
2404
2691
|
}
|
|
2405
2692
|
|
|
2406
|
-
/**
|
|
2407
|
-
* Whether a point has an x key to position by. An explicit emptiness check, not truthiness: a
|
|
2408
|
-
* Decimal key of `0` is a perfectly good coordinate (the left edge of a `domainMin: 0` axis) and
|
|
2409
|
-
* used to be read as "no key" - drawn at pixel 0 whatever the domain, and pinned there under zoom.
|
|
2410
|
-
*/
|
|
2411
|
-
function hasKey(data) {
|
|
2412
|
-
return data.key !== null && data.key !== undefined && data.key !== '';
|
|
2413
|
-
}
|
|
2414
|
-
function getXFormat(type, data, index, xScale) {
|
|
2415
|
-
switch (type) {
|
|
2416
|
-
case PcacFormatEnum.DateTime:
|
|
2417
|
-
if (hasKey(data)) {
|
|
2418
|
-
return xScale(new Date(data.key));
|
|
2419
|
-
}
|
|
2420
|
-
return 0;
|
|
2421
|
-
case PcacFormatEnum.Decimal:
|
|
2422
|
-
if (hasKey(data)) {
|
|
2423
|
-
return xScale(Number(data.key));
|
|
2424
|
-
}
|
|
2425
|
-
return 0;
|
|
2426
|
-
default:
|
|
2427
|
-
return xScale(index);
|
|
2428
|
-
}
|
|
2429
|
-
}
|
|
2430
|
-
|
|
2431
|
-
/** Whether a point has a numeric value to draw at. */
|
|
2432
|
-
function hasValue(d) {
|
|
2433
|
-
return d.value !== null && d.value !== undefined && d.value !== '' && Number.isFinite(Number(d.value));
|
|
2434
|
-
}
|
|
2435
|
-
|
|
2436
2693
|
function buildLineGenerator(format, scales) {
|
|
2437
2694
|
return line()
|
|
2438
2695
|
// A point with no numeric value leaves a gap rather than a NaN in the path, which browsers stop
|
|
@@ -2648,10 +2905,12 @@ function findCoincidentGroups(series, xFormat) {
|
|
|
2648
2905
|
return;
|
|
2649
2906
|
}
|
|
2650
2907
|
s.data.forEach((data, index) => {
|
|
2651
|
-
|
|
2908
|
+
// Same test as the line/dots use, so a point that isn't drawn (`''`, NaN) never joins a ring.
|
|
2909
|
+
if (!hasValue(data)) {
|
|
2652
2910
|
return;
|
|
2653
2911
|
}
|
|
2654
|
-
|
|
2912
|
+
// By numeric value, so `5` and `'5'` - drawn at the same spot - are recognized as sharing it.
|
|
2913
|
+
const key = `${xPositionKey(xFormat, data, index)}|${Number(data.value)}`;
|
|
2655
2914
|
let members = byPosition.get(key);
|
|
2656
2915
|
if (!members) {
|
|
2657
2916
|
members = [];
|
|
@@ -2739,12 +2998,6 @@ function clamp(value, min, max) {
|
|
|
2739
2998
|
return Math.min(Math.max(value, min), max);
|
|
2740
2999
|
}
|
|
2741
3000
|
|
|
2742
|
-
/**
|
|
2743
|
-
* Provided per-component (see PcacLineAreaChartComponent's `providers`), not root-scoped: this
|
|
2744
|
-
* builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
|
|
2745
|
-
* height, colors, svg). A root singleton would be shared and clobbered by every
|
|
2746
|
-
* <pcac-line-area-chart> rendered at once.
|
|
2747
|
-
*/
|
|
2748
3001
|
/** Half the theme's 2px line stroke: how far the lines/areas/fan-outs clip-path reaches past the plot. */
|
|
2749
3002
|
const PLOT_CLIP_ALLOWANCE = 1;
|
|
2750
3003
|
/**
|
|
@@ -2758,6 +3011,18 @@ const DOT_GROW_TRANSITION = 'pcac-dot-grow';
|
|
|
2758
3011
|
const DOT_HOVER_TRANSITION = 'pcac-dot-hover';
|
|
2759
3012
|
/** See `revealAfterEntry`. */
|
|
2760
3013
|
const REVEAL_TRANSITION = 'pcac-reveal';
|
|
3014
|
+
/** Each chart type's accessible name when its config gives no `ariaLabel`. */
|
|
3015
|
+
const CHART_TYPE_LABELS = {
|
|
3016
|
+
[PcacLineAreaPlotChartConfigType.Line]: 'Line chart',
|
|
3017
|
+
[PcacLineAreaPlotChartConfigType.Area]: 'Area chart',
|
|
3018
|
+
[PcacLineAreaPlotChartConfigType.Plot]: 'Plot chart',
|
|
3019
|
+
};
|
|
3020
|
+
/**
|
|
3021
|
+
* Provided per-component (see PcacLineAreaChartComponent's `providers`), not root-scoped: this
|
|
3022
|
+
* builder extends PcacChart, which holds mutable per-chart-instance state (margin, width,
|
|
3023
|
+
* height, colors, svg). A root singleton would be shared and clobbered by every
|
|
3024
|
+
* <pcac-line-area-chart> rendered at once.
|
|
3025
|
+
*/
|
|
2761
3026
|
class PlaChartBuilder extends PcacChart {
|
|
2762
3027
|
effectsBuilder = inject(PlaChartEffectsBuilder);
|
|
2763
3028
|
scales;
|
|
@@ -2766,7 +3031,16 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2766
3031
|
zoomBehavior;
|
|
2767
3032
|
dotClickedSource = new Subject();
|
|
2768
3033
|
config;
|
|
2769
|
-
|
|
3034
|
+
/**
|
|
3035
|
+
* Numbers this chart's clip-path ids (and, through `plotClipPathId`, its range gradients'),
|
|
3036
|
+
* which have to be unique in the whole page: `url(#id)` resolves to the first match in the
|
|
3037
|
+
* document, so a duplicate would clip one chart with another's rect. A per-instance counter
|
|
3038
|
+
* rather than the timestamp-plus-random stamp this used to be, which two charts rebuilding in
|
|
3039
|
+
* the same millisecond (every chart on a page reacts to a window resize at once) could share.
|
|
3040
|
+
*/
|
|
3041
|
+
static nextInstanceId = 0;
|
|
3042
|
+
instanceId = ++PlaChartBuilder.nextInstanceId;
|
|
3043
|
+
clipPathId;
|
|
2770
3044
|
/**
|
|
2771
3045
|
* A second clip-path for everything that isn't a point - lines, areas, fan-out anchors and
|
|
2772
3046
|
* spokes: the plot area plus `PLOT_CLIP_ALLOWANCE`. These have no business past the axes; the
|
|
@@ -2802,6 +3076,12 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2802
3076
|
pointRange = null;
|
|
2803
3077
|
/** Each drawn range's `.point-range` group, by its point, so hover can find the one to focus. */
|
|
2804
3078
|
rangeGroupOf = new Map();
|
|
3079
|
+
/**
|
|
3080
|
+
* Whether this build has the hover crosshair: `enableEffects`, on a line or area chart. A plot
|
|
3081
|
+
* chart has no line for it to follow, so it gets none - its circles had nowhere to go and sat
|
|
3082
|
+
* stacked in the plot's top-left corner.
|
|
3083
|
+
*/
|
|
3084
|
+
effectsEnabled = false;
|
|
2805
3085
|
dotClicked$ = this.dotClickedSource.asObservable();
|
|
2806
3086
|
buildChart(chartElm, config, type) {
|
|
2807
3087
|
if (!config?.data?.length) {
|
|
@@ -2813,7 +3093,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2813
3093
|
// no mouseout, so its tooltip is closed here (see `leavePoint`).
|
|
2814
3094
|
this.leavePoint();
|
|
2815
3095
|
this.config = JSON.parse(JSON.stringify(config));
|
|
2816
|
-
this.startData = range(this.config.data
|
|
3096
|
+
this.startData = range(longestSeriesLength(this.config.data)).map(() => ({
|
|
2817
3097
|
key: '',
|
|
2818
3098
|
value: 0,
|
|
2819
3099
|
hide: false,
|
|
@@ -2821,6 +3101,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2821
3101
|
}));
|
|
2822
3102
|
// A hidden axis keeps 8px rather than 0 so a dot on the edge of the plot isn't clipped
|
|
2823
3103
|
this.initializeAxisState(this.config, 'y', 8);
|
|
3104
|
+
this.chartTypeLabel = CHART_TYPE_LABELS[type];
|
|
2824
3105
|
this.resolvePointLayout(type);
|
|
2825
3106
|
this.reservePointSpace();
|
|
2826
3107
|
this.pointRange = this.config.pointRange ? { ...new PcacPointRangeConfig(), ...this.config.pointRange } : null;
|
|
@@ -2862,10 +3143,12 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2862
3143
|
// used to do, and which also overwrote the original generators' x accessor for good) is
|
|
2863
3144
|
// only right for the default DatasetLength format; a DateTime/Decimal chart's lines
|
|
2864
3145
|
// drifted away from its dots as soon as it was zoomed.
|
|
3146
|
+
// Interrupted first: a zoom during the enter transition would otherwise have the rest of
|
|
3147
|
+
// that transition keep drawing the unzoomed shape over this one.
|
|
2865
3148
|
const zoomedLine = buildLineGenerator(this.xAxis.format, zoomedScales);
|
|
2866
3149
|
const zoomedArea = buildAreaGenerator(this.xAxis.format, zoomedScales, this.height);
|
|
2867
|
-
this.svg.selectAll('.line').attr('d', (d) => zoomedLine(d));
|
|
2868
|
-
this.svg.selectAll('.area').attr('d', (d) => zoomedArea(d));
|
|
3150
|
+
this.svg.selectAll('.line').interrupt().attr('d', (d) => zoomedLine(d));
|
|
3151
|
+
this.svg.selectAll('.area').interrupt().attr('d', (d) => zoomedArea(d));
|
|
2869
3152
|
// Update dots / point images. Nested selectAll (not a flat svg.selectAll('.point')) so
|
|
2870
3153
|
// that `i` is the point's index *within its own series* - the x format default
|
|
2871
3154
|
// (DatasetLength) positions by index, and a flat selection would number every series'
|
|
@@ -2881,9 +3164,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2881
3164
|
.selectAll('.fan-out-spoke')
|
|
2882
3165
|
.attr('x2', (member) => this.spokeEnd(member, zoomedScales).dx)
|
|
2883
3166
|
.attr('y2', (member) => this.spokeEnd(member, zoomedScales).dy);
|
|
2884
|
-
// The hover crosshair
|
|
2885
|
-
|
|
2886
|
-
if (this.config.enableEffects) {
|
|
3167
|
+
// The hover crosshair positions and labels against the scales, so it takes the zoomed ones.
|
|
3168
|
+
if (this.effectsEnabled) {
|
|
2887
3169
|
this.effectsBuilder.updateScales(newX, newY);
|
|
2888
3170
|
}
|
|
2889
3171
|
// Ranges are drawn in plot coordinates rather than hung off a translate, so every one is
|
|
@@ -2905,7 +3187,8 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2905
3187
|
this.axisBuilder.drawAxis(this.axisBuilderConfig(this.scales.x, this.scales.y));
|
|
2906
3188
|
this.drawGrids(this.scales.x, this.scales.y);
|
|
2907
3189
|
this.drawLineArea(config, type);
|
|
2908
|
-
|
|
3190
|
+
this.effectsEnabled = !!config.enableEffects && type !== PcacLineAreaPlotChartConfigType.Plot;
|
|
3191
|
+
if (this.effectsEnabled) {
|
|
2909
3192
|
this.effectsBuilder.buildEffects({
|
|
2910
3193
|
svg: this.svg,
|
|
2911
3194
|
height: this.height,
|
|
@@ -2913,7 +3196,10 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2913
3196
|
data: config.data,
|
|
2914
3197
|
colors: this.colors,
|
|
2915
3198
|
x: this.scales.x,
|
|
2916
|
-
y: this.scales.y
|
|
3199
|
+
y: this.scales.y,
|
|
3200
|
+
xFormat: this.xAxis.format,
|
|
3201
|
+
yFormat: this.yAxis.format,
|
|
3202
|
+
yTicks: this.yAxis.ticks,
|
|
2917
3203
|
});
|
|
2918
3204
|
}
|
|
2919
3205
|
// Axes above the lines/areas (so an axis line isn't covered by a series sitting at x = 0),
|
|
@@ -2973,10 +3259,10 @@ class PlaChartBuilder extends PcacChart {
|
|
|
2973
3259
|
this.reserveEdgeSpace({ top: halfHeight, bottom: halfHeight, left: halfWidth, right: halfWidth });
|
|
2974
3260
|
}
|
|
2975
3261
|
createReusableClipPath() {
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
this.
|
|
2979
|
-
this.
|
|
3262
|
+
// The previous build's <defs> went with the rest of its drawing (see initializeChartState),
|
|
3263
|
+
// so the same ids are free again.
|
|
3264
|
+
this.clipPathId = `pcac-clip-${this.instanceId}`;
|
|
3265
|
+
this.plotClipPathId = `pcac-clip-plot-${this.instanceId}`;
|
|
2980
3266
|
const defs = this.svg.append('defs');
|
|
2981
3267
|
defs.append('clipPath')
|
|
2982
3268
|
.attr('id', this.clipPathId)
|
|
@@ -3043,15 +3329,15 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3043
3329
|
.append('path')
|
|
3044
3330
|
.datum(lineData)
|
|
3045
3331
|
.attr('class', 'line')
|
|
3332
|
+
// Set up front rather than on the transition, so a zoom interrupting it (see the zoom
|
|
3333
|
+
// handler) doesn't leave the line uncolored, or a hidden one showing.
|
|
3334
|
+
.attr('stroke', this.colors[index])
|
|
3335
|
+
.attr('fill', 'none')
|
|
3336
|
+
.attr('style', hide ? 'display: none' : null)
|
|
3046
3337
|
.attr('d', this.lineGenerator(this.startData))
|
|
3047
3338
|
.transition()
|
|
3048
3339
|
.duration(this.transitionService.getTransitionDuration())
|
|
3049
|
-
.attr('d', this.lineGenerator)
|
|
3050
|
-
.attr('stroke', () => {
|
|
3051
|
-
return this.colors[index];
|
|
3052
|
-
})
|
|
3053
|
-
.attr('fill', 'none')
|
|
3054
|
-
.attr('style', () => hide ? 'display: none' : null);
|
|
3340
|
+
.attr('d', this.lineGenerator);
|
|
3055
3341
|
}
|
|
3056
3342
|
drawArea(lineData, index, hide = false) {
|
|
3057
3343
|
this.svg.append('g')
|
|
@@ -3100,7 +3386,9 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3100
3386
|
.style('--pcac-point-range-series-color', () => this.colors[seriesIndex])
|
|
3101
3387
|
.style('display', () => series.hide ? 'none' : null);
|
|
3102
3388
|
series.data.forEach((point) => {
|
|
3103
|
-
|
|
3389
|
+
// A point with no value draws no dot (see `pointDisplay`), so it draws no range either -
|
|
3390
|
+
// one would stand around a coordinate with nothing on it (on the baseline, for `''`).
|
|
3391
|
+
if (point.range && hasValue(point)) {
|
|
3104
3392
|
this.rangeGroupOf.set(point, seriesGroup.append('g').attr('class', 'point-range').node());
|
|
3105
3393
|
}
|
|
3106
3394
|
});
|
|
@@ -3220,7 +3508,7 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3220
3508
|
const series = config.data[index];
|
|
3221
3509
|
const points = this.svg.append('g')
|
|
3222
3510
|
.attr('class', 'dots')
|
|
3223
|
-
.attr('clip-path', `url(#${this.clipPathId})`)
|
|
3511
|
+
.attr('clip-path', `url(#${this.clipPathId})`)
|
|
3224
3512
|
.attr('style', series.hide ? 'display: none' : null)
|
|
3225
3513
|
.selectAll('.point')
|
|
3226
3514
|
.data(series.data)
|
|
@@ -3326,9 +3614,13 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3326
3614
|
* the clip-path's buffer do the work, showed a point up to a whole half-mark beyond the axis
|
|
3327
3615
|
* with its center already outside. Also takes it out of hover's reach, as a hidden group
|
|
3328
3616
|
* receives no pointer events.
|
|
3617
|
+
*
|
|
3618
|
+
* A point with no value to plot isn't drawn at all - the same test the line/area uses to leave
|
|
3619
|
+
* a gap (`hasValue`). An empty string used to slip through: the scale reads `''` as 0, so the
|
|
3620
|
+
* line left a gap while a dot sat (hoverable) on the baseline.
|
|
3329
3621
|
*/
|
|
3330
3622
|
pointDisplay(d, i, scales) {
|
|
3331
|
-
return this.pointVisible(d, i, scales) ? null : 'none';
|
|
3623
|
+
return hasValue(d) && this.pointVisible(d, i, scales) ? null : 'none';
|
|
3332
3624
|
}
|
|
3333
3625
|
pointVisible(d, i, scales) {
|
|
3334
3626
|
const { x, y } = this.markCenter(d, i, scales);
|
|
@@ -3388,10 +3680,10 @@ class PlaChartBuilder extends PcacChart {
|
|
|
3388
3680
|
.filter((member) => member.data !== d)
|
|
3389
3681
|
.map((member) => ({ data: member.data, parent: member.series, index: member.index, parentIndex: member.seriesIndex }));
|
|
3390
3682
|
}
|
|
3391
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3392
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
3683
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
3684
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartBuilder });
|
|
3393
3685
|
}
|
|
3394
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3686
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PlaChartBuilder, decorators: [{
|
|
3395
3687
|
type: Injectable
|
|
3396
3688
|
}] });
|
|
3397
3689
|
|
|
@@ -3440,10 +3732,10 @@ class PcacLineAreaChartComponent {
|
|
|
3440
3732
|
this.chartBuilder.buildChart(this.chartElm(), config, this.type());
|
|
3441
3733
|
}
|
|
3442
3734
|
}
|
|
3443
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3444
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
3735
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3736
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", 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:var(--pcac-fan-out-spoke-color, #ced4da);stroke-width:1px}.pcac-line-area-chart .fan-out-anchor{fill:var(--pcac-fan-out-anchor-color, #6c757d)}.pcac-line-area-chart .point-ranges .point-range-series{--pcac-point-range-resolved-color: var(--pcac-point-range-color, var(--pcac-point-range-series-color))}.pcac-line-area-chart .point-ranges .point-range{opacity:var(--pcac-point-range-resting-opacity, 1);transition:opacity .15s ease-out}.pcac-line-area-chart .point-ranges .point-range.is-focused{opacity:1}.pcac-line-area-chart .point-ranges.pcac-range-hover{--pcac-point-range-resting-opacity: 0}.pcac-line-area-chart .point-ranges.pcac-range-faint{--pcac-point-range-resting-opacity: var(--pcac-point-range-faint-opacity, .2)}.pcac-line-area-chart .point-ranges.pcac-range-always.has-focus .point-range:not(.is-focused){opacity:.5}.pcac-line-area-chart .point-ranges .point-range-whisker,.pcac-line-area-chart .point-ranges .point-range-cap{stroke:var(--pcac-point-range-resolved-color);stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-box{fill:var(--pcac-point-range-resolved-color);fill-opacity:.1;stroke:var(--pcac-point-range-resolved-color);stroke-opacity:.7;stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-stop{stop-color:var(--pcac-point-range-resolved-color)}.pcac-line-area-chart .point-ranges .is-focused .point-range-whisker,.pcac-line-area-chart .point-ranges .is-focused .point-range-cap,.pcac-line-area-chart .point-ranges .is-focused .point-range-box{stroke-width:1.75px}.pcac-line-area-chart .point-ranges .is-focused .point-range-box{fill-opacity:.18}@media(prefers-reduced-motion:reduce){.pcac-line-area-chart .point-ranges .point-range{transition:none}}.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 });
|
|
3445
3737
|
}
|
|
3446
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3738
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineAreaChartComponent, decorators: [{
|
|
3447
3739
|
type: Component,
|
|
3448
3740
|
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:var(--pcac-fan-out-spoke-color, #ced4da);stroke-width:1px}.pcac-line-area-chart .fan-out-anchor{fill:var(--pcac-fan-out-anchor-color, #6c757d)}.pcac-line-area-chart .point-ranges .point-range-series{--pcac-point-range-resolved-color: var(--pcac-point-range-color, var(--pcac-point-range-series-color))}.pcac-line-area-chart .point-ranges .point-range{opacity:var(--pcac-point-range-resting-opacity, 1);transition:opacity .15s ease-out}.pcac-line-area-chart .point-ranges .point-range.is-focused{opacity:1}.pcac-line-area-chart .point-ranges.pcac-range-hover{--pcac-point-range-resting-opacity: 0}.pcac-line-area-chart .point-ranges.pcac-range-faint{--pcac-point-range-resting-opacity: var(--pcac-point-range-faint-opacity, .2)}.pcac-line-area-chart .point-ranges.pcac-range-always.has-focus .point-range:not(.is-focused){opacity:.5}.pcac-line-area-chart .point-ranges .point-range-whisker,.pcac-line-area-chart .point-ranges .point-range-cap{stroke:var(--pcac-point-range-resolved-color);stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-box{fill:var(--pcac-point-range-resolved-color);fill-opacity:.1;stroke:var(--pcac-point-range-resolved-color);stroke-opacity:.7;stroke-width:1.25px}.pcac-line-area-chart .point-ranges .point-range-stop{stop-color:var(--pcac-point-range-resolved-color)}.pcac-line-area-chart .point-ranges .is-focused .point-range-whisker,.pcac-line-area-chart .point-ranges .is-focused .point-range-cap,.pcac-line-area-chart .point-ranges .is-focused .point-range-box{stroke-width:1.75px}.pcac-line-area-chart .point-ranges .is-focused .point-range-box{fill-opacity:.18}@media(prefers-reduced-motion:reduce){.pcac-line-area-chart .point-ranges .point-range{transition:none}}.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"] }]
|
|
3449
3741
|
}], 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 }] }] } });
|
|
@@ -3459,10 +3751,10 @@ class PcacPlotChart {
|
|
|
3459
3751
|
*/
|
|
3460
3752
|
tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
|
|
3461
3753
|
...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
|
|
3462
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3463
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
3754
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPlotChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3755
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacPlotChart, isStandalone: true, selector: "pcac-plot-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], ngImport: i0, template: "<pcac-line-area-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Plot\" (dotClicked)=\"dotClicked.emit($event)\"/>", dependencies: [{ kind: "component", type: PcacLineAreaChartComponent, selector: "pcac-line-area-chart", inputs: ["config", "type", "tooltipTemplate"], outputs: ["dotClicked"] }] });
|
|
3464
3756
|
}
|
|
3465
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3757
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPlotChart, decorators: [{
|
|
3466
3758
|
type: Component,
|
|
3467
3759
|
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)\"/>" }]
|
|
3468
3760
|
}], 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 }] }] } });
|
|
@@ -3478,10 +3770,10 @@ class PcacLineChart {
|
|
|
3478
3770
|
*/
|
|
3479
3771
|
tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
|
|
3480
3772
|
...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
|
|
3481
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3482
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
3773
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3774
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacLineChart, isStandalone: true, selector: "pcac-line-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], ngImport: i0, template: "<pcac-line-area-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Line\" (dotClicked)=\"dotClicked.emit($event)\" />", dependencies: [{ kind: "component", type: PcacLineAreaChartComponent, selector: "pcac-line-area-chart", inputs: ["config", "type", "tooltipTemplate"], outputs: ["dotClicked"] }] });
|
|
3483
3775
|
}
|
|
3484
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3776
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacLineChart, decorators: [{
|
|
3485
3777
|
type: Component,
|
|
3486
3778
|
args: [{ selector: 'pcac-line-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, imports: [PcacLineAreaChartComponent], template: "<pcac-line-area-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Line\" (dotClicked)=\"dotClicked.emit($event)\" />" }]
|
|
3487
3779
|
}], 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 }] }] } });
|
|
@@ -3500,10 +3792,10 @@ class PcacAreaChart {
|
|
|
3500
3792
|
*/
|
|
3501
3793
|
tooltipTemplate = contentChild(PcacTooltipDirective, /* @ts-ignore */
|
|
3502
3794
|
...(ngDevMode ? [{ debugName: "tooltipTemplate" }] : /* istanbul ignore next */ []));
|
|
3503
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3504
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
3795
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacAreaChart, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3796
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacAreaChart, isStandalone: true, selector: "pcac-area-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { dotClicked: "dotClicked" }, host: { properties: { "class.pcac-height-full": "config().heightFull" } }, queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], ngImport: i0, template: "<pcac-line-area-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Area\" (dotClicked)=\"dotClicked.emit($event)\" />", dependencies: [{ kind: "component", type: PcacLineAreaChartComponent, selector: "pcac-line-area-chart", inputs: ["config", "type", "tooltipTemplate"], outputs: ["dotClicked"] }] });
|
|
3505
3797
|
}
|
|
3506
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
3798
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacAreaChart, decorators: [{
|
|
3507
3799
|
type: Component,
|
|
3508
3800
|
args: [{ selector: 'pcac-area-chart', host: { '[class.pcac-height-full]': 'config().heightFull' }, imports: [PcacLineAreaChartComponent], template: "<pcac-line-area-chart [config]=\"config()\" [tooltipTemplate]=\"tooltipTemplate()?.templateRef\" [type]=\"types.Area\" (dotClicked)=\"dotClicked.emit($event)\" />" }]
|
|
3509
3801
|
}], 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 }] }] } });
|
|
@@ -3584,6 +3876,7 @@ class PieChartBuilder extends PcacChart {
|
|
|
3584
3876
|
pieAngles;
|
|
3585
3877
|
sliceClickedSource = new Subject();
|
|
3586
3878
|
sliceClicked$ = this.sliceClickedSource.asObservable();
|
|
3879
|
+
chartTypeLabel = 'Pie chart';
|
|
3587
3880
|
buildChart(chartElm, config) {
|
|
3588
3881
|
if (!config?.data?.length) {
|
|
3589
3882
|
this.clearChart(chartElm);
|
|
@@ -3598,7 +3891,7 @@ class PieChartBuilder extends PcacChart {
|
|
|
3598
3891
|
return;
|
|
3599
3892
|
}
|
|
3600
3893
|
this.applyColorOverride(config.colorOverride);
|
|
3601
|
-
this.radius = Math.min(
|
|
3894
|
+
this.radius = Math.min(this.height, this.width) / 2;
|
|
3602
3895
|
this.buildShapes(config.donut);
|
|
3603
3896
|
this.drawChart(chartElm, config);
|
|
3604
3897
|
if (config.donut && this.innerRadius > 0) {
|
|
@@ -3607,16 +3900,18 @@ class PieChartBuilder extends PcacChart {
|
|
|
3607
3900
|
}
|
|
3608
3901
|
buildShapes(donut) {
|
|
3609
3902
|
const radiusOffset = 10;
|
|
3610
|
-
|
|
3903
|
+
// Never negative: in a container under 20px the offset would otherwise turn the pie inside out.
|
|
3904
|
+
const outerRadius = Math.max(0, this.radius - radiusOffset);
|
|
3611
3905
|
const ratio = donut ? (donut.innerRadius ?? new PcacPieDonutConfig().innerRadius) : 0;
|
|
3612
3906
|
// Sized against the resting slice, so the hole stays put when a hovered slice grows outward.
|
|
3613
3907
|
this.innerRadius = Math.max(0, outerRadius * Math.min(Math.max(ratio, 0), MAX_DONUT_INNER_RADIUS));
|
|
3614
3908
|
this.arcShape = arc()
|
|
3615
3909
|
.innerRadius(this.innerRadius)
|
|
3616
3910
|
.outerRadius(outerRadius);
|
|
3911
|
+
// A pie too small to draw anything at rest (see above) doesn't pop out a disc on hover either.
|
|
3617
3912
|
this.arcOverShape = arc()
|
|
3618
3913
|
.innerRadius(this.innerRadius)
|
|
3619
|
-
.outerRadius(outerRadius + radiusOffset);
|
|
3914
|
+
.outerRadius(outerRadius > 0 ? outerRadius + radiusOffset : 0);
|
|
3620
3915
|
this.pieAngles = pie()
|
|
3621
3916
|
.sort(null)
|
|
3622
3917
|
// A hidden slice takes no angle but keeps its index - and so its color, matching a legend -
|
|
@@ -3638,7 +3933,16 @@ class PieChartBuilder extends PcacChart {
|
|
|
3638
3933
|
const t = transition().duration(self.transitionService.getTransitionDuration() / 3);
|
|
3639
3934
|
const c = color(self.colors[d.index]);
|
|
3640
3935
|
const ct = c ? c.darker(1).toString() : self.colors[d.index];
|
|
3641
|
-
select(this)
|
|
3936
|
+
const slice = select(this);
|
|
3937
|
+
// Hovered mid-way through the enter sweep, the slice is finished first: growing it straight
|
|
3938
|
+
// from its part-swept path morphed it oddly on the way out to the hover shape. Only then -
|
|
3939
|
+
// re-entering a slice mid-way through its hover shrink must grow it from where it is, not
|
|
3940
|
+
// snap it back to rest first (which flickered).
|
|
3941
|
+
if (active(this, 'enter')) {
|
|
3942
|
+
slice.interrupt('enter').attr('d', self.arcShape(d));
|
|
3943
|
+
}
|
|
3944
|
+
slice
|
|
3945
|
+
.transition(t)
|
|
3642
3946
|
.attr('d', self.arcOverShape)
|
|
3643
3947
|
.style('fill', ct);
|
|
3644
3948
|
})
|
|
@@ -3656,7 +3960,8 @@ class PieChartBuilder extends PcacChart {
|
|
|
3656
3960
|
.on('click', (_event, d) => {
|
|
3657
3961
|
this.sliceClickedSource.next(d.data);
|
|
3658
3962
|
})
|
|
3659
|
-
|
|
3963
|
+
// Named, so the hover transitions (unnamed) and the check above can tell it apart from them.
|
|
3964
|
+
.transition('enter')
|
|
3660
3965
|
.duration(this.transitionService.getTransitionDuration())
|
|
3661
3966
|
.attrTween('d', (b) => {
|
|
3662
3967
|
return this.tweenChart(b);
|
|
@@ -3721,10 +4026,10 @@ class PieChartBuilder extends PcacChart {
|
|
|
3721
4026
|
const i = interpolate({ startAngle: 0, endAngle: 0 }, b);
|
|
3722
4027
|
return (t) => this.arcShape(i(t)) ?? '';
|
|
3723
4028
|
}
|
|
3724
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3725
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.
|
|
4029
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieChartBuilder, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
4030
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieChartBuilder });
|
|
3726
4031
|
}
|
|
3727
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
4032
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PieChartBuilder, decorators: [{
|
|
3728
4033
|
type: Injectable
|
|
3729
4034
|
}] });
|
|
3730
4035
|
|
|
@@ -3765,12 +4070,12 @@ class PcacPieChartComponent {
|
|
|
3765
4070
|
this.chartBuilder.buildChart(this.chartElm(), config);
|
|
3766
4071
|
}
|
|
3767
4072
|
}
|
|
3768
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
3769
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.
|
|
4073
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
4074
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.2.0", type: PcacPieChartComponent, isStandalone: true, selector: "pcac-pie-chart", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { sliceClicked: "sliceClicked" }, providers: [PieChartBuilder], queries: [{ propertyName: "tooltipTemplate", first: true, predicate: PcacTooltipDirective, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "chartElm", first: true, predicate: ["chart"], descendants: true, isSignal: true }], ngImport: i0, template: "<section class=\"pcac-pie-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-pie-chart svg{width:100%;display:block}\n"], encapsulation: i0.ViewEncapsulation.None });
|
|
3770
4075
|
}
|
|
3771
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
4076
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PcacPieChartComponent, decorators: [{
|
|
3772
4077
|
type: Component,
|
|
3773
|
-
args: [{ selector: 'pcac-pie-chart', encapsulation: ViewEncapsulation.None, providers: [PieChartBuilder], template: "<section class=\"pcac-pie-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-pie-chart svg{width:100%;display:block}
|
|
4078
|
+
args: [{ selector: 'pcac-pie-chart', encapsulation: ViewEncapsulation.None, providers: [PieChartBuilder], template: "<section class=\"pcac-pie-chart\">\n <svg #chart></svg>\n</section>\n\n", styles: [".pcac-pie-chart svg{width:100%;display:block}\n"] }]
|
|
3774
4079
|
}], 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 }] }] } });
|
|
3775
4080
|
|
|
3776
4081
|
/*
|
|
@@ -3781,5 +4086,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImpor
|
|
|
3781
4086
|
* Generated bundle index. Do not edit.
|
|
3782
4087
|
*/
|
|
3783
4088
|
|
|
3784
|
-
export {
|
|
4089
|
+
export { PcacAreaChart, PcacAreaChartConfig, PcacAxisChartConfig, PcacAxisConfig, PcacAxisSubLabels, PcacBarHorizontalChartColorOverrideConfig, PcacBarHorizontalChartComponent, PcacBarHorizontalChartConfig, PcacBarVerticalChartColorOverrideConfig, PcacBarVerticalChartComponent, PcacBarVerticalChartConfig, PcacChartConfig, PcacColorService, PcacData, PcacDataRange, PcacFormatEnum, PcacLegend, PcacLegendConfig, PcacLegendConfigItem, PcacLineChart, PcacLineChartConfig, PcacPieChartComponent, PcacPieChartConfig, PcacPieDonutConfig, PcacPlotChart, PcacPlotChartConfig, PcacPointFanOutConfig, PcacPointImageConfig, PcacPointRangeConfig, PcacPointRangeShow, PcacPointRangeStyle, PcacRangeBounds, PcacTooltipDirective };
|
|
3785
4090
|
//# sourceMappingURL=pioneer-code-pioneer-charts.mjs.map
|