@aquera/nile-visualization 2.9.49 → 2.9.52
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/README.md +7 -0
- package/dist/src/internal/types/chart-master-detail-config.type.d.ts +12 -0
- package/dist/src/nile-chart/nile-chart-config.d.ts +12 -0
- package/dist/src/nile-chart/nile-chart.d.ts +12 -0
- package/dist/src/nile-chart/nile-chart.js +80 -1
- package/dist/src/nile-kpi-chart/nile-kpi-chart.d.ts +45 -0
- package/dist/src/nile-kpi-chart/nile-kpi-chart.js +121 -29
- package/dist/src/nile-kpi-chart/nile-kpi-chart.test.d.ts +1 -0
- package/dist/src/nile-kpi-chart/nile-kpi-chart.test.js +92 -0
- package/dist/src/nile-master-detail-chart/nile-master-detail-chart.css.js +60 -0
- package/dist/src/nile-master-detail-chart/nile-master-detail-chart.d.ts +86 -4
- package/dist/src/nile-master-detail-chart/nile-master-detail-chart.js +252 -22
- package/dist/src/nile-master-detail-chart/nile-master-detail-chart.test.js +200 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { customElement, property, query, state } from 'lit/decorators.js';
|
|
3
3
|
import { html, nothing } from 'lit';
|
|
4
|
+
import { keyed } from 'lit/directives/keyed.js';
|
|
4
5
|
import { getHighcharts } from '../internal/utils/highcharts-provider.js';
|
|
5
6
|
import NileElement from '../internal/base/nile-element.js';
|
|
6
7
|
import { applySeparatedChartConfig } from '../internal/utils/separated-chart-config.js';
|
|
@@ -17,6 +18,21 @@ export const MASTER_DETAIL_SERIES_TYPES = [
|
|
|
17
18
|
'bar',
|
|
18
19
|
];
|
|
19
20
|
export const MASTER_DETAIL_X_AXIS_TYPES = ['datetime', 'linear', 'logarithmic', 'category'];
|
|
21
|
+
/** Every CSS part `nile-master-detail-chart` renders; `nile-chart` re-exports them as `master-detail-<part>`. */
|
|
22
|
+
export const MASTER_DETAIL_CHART_PARTS = [
|
|
23
|
+
'detail-container',
|
|
24
|
+
'master-container',
|
|
25
|
+
'master-toggle',
|
|
26
|
+
'navigator',
|
|
27
|
+
'navigator-button',
|
|
28
|
+
'navigator-bar',
|
|
29
|
+
'navigator-slider',
|
|
30
|
+
'navigator-pan-button',
|
|
31
|
+
];
|
|
32
|
+
/** Duration units accepted by `navigator-default-window`, `navigator-pan-step` and `navigator-slider-step`. */
|
|
33
|
+
const DURATION_UNITS = { m: 6e4, h: 36e5, d: 864e5, w: 6048e5 };
|
|
34
|
+
/** Right spacing (px) reserved on the chart under the zoom control: 32px control + 8px offset + 8px gap. */
|
|
35
|
+
const NAV_CONTROL_GUTTER = 48;
|
|
20
36
|
/**
|
|
21
37
|
* @tag nile-master-detail-chart
|
|
22
38
|
* @summary A detail chart above an overview (master) strip; dragging on the strip zooms the detail.
|
|
@@ -30,9 +46,13 @@ export const MASTER_DETAIL_X_AXIS_TYPES = ['datetime', 'linear', 'logarithmic',
|
|
|
30
46
|
* @csspart master-toggle - The show/hide button for the master strip (`master-collapsible`).
|
|
31
47
|
* @csspart navigator - The map-style zoom buttons (+ / −) over the top-right corner of the chart (`navigator-controls`).
|
|
32
48
|
* @csspart navigator-button - Each zoom button (`Zoom in`, `Zoom out`) inside the `navigator` control.
|
|
49
|
+
* @csspart navigator-bar - The bar under the master pane holding the slider and / or pan buttons
|
|
50
|
+
* (`navigator-slider`, `navigator-pan-buttons`).
|
|
51
|
+
* @csspart navigator-slider - The `nile-slider` that positions the window (`navigator-slider`).
|
|
52
|
+
* @csspart navigator-pan-button - Each pan button (`Pan back`, `Pan forward`) in the bar (`navigator-pan-buttons`).
|
|
53
|
+
*
|
|
54
|
+
* @dependency nile-slider - `navigator-slider` renders a `nile-slider` from `@aquera/nile-elements`; register it in the app.
|
|
33
55
|
*/
|
|
34
|
-
/** Right spacing (px) reserved on the chart under the zoom control: 32px control + 8px offset + 8px gap. */
|
|
35
|
-
const NAV_CONTROL_GUTTER = 48;
|
|
36
56
|
let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
37
57
|
constructor() {
|
|
38
58
|
super(...arguments);
|
|
@@ -63,9 +83,39 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
63
83
|
this.masterType = 'area';
|
|
64
84
|
this.masterOnly = false;
|
|
65
85
|
this.masterCollapsible = false;
|
|
86
|
+
/** Map-style + / − zoom over the chart's top-right corner, drag-to-pan and keyboard pan / zoom. */
|
|
66
87
|
this.navigatorControls = false;
|
|
67
88
|
/**
|
|
68
|
-
*
|
|
89
|
+
* A slider under the master pane that moves the visible window along the data. Independent of
|
|
90
|
+
* `navigator-controls` and `navigator-pan-buttons`; disabled while the window covers the full range.
|
|
91
|
+
*/
|
|
92
|
+
this.navigatorSlider = false;
|
|
93
|
+
/**
|
|
94
|
+
* ‹ / › buttons under the master pane that pan the window by 25% of its width. Independent of
|
|
95
|
+
* `navigator-controls` and `navigator-slider`.
|
|
96
|
+
*/
|
|
97
|
+
this.navigatorPanButtons = false;
|
|
98
|
+
/**
|
|
99
|
+
* How far one pan moves (the ‹ / › buttons, ← / → keys and `panBy()`): a percentage of the visible window
|
|
100
|
+
* (`25%`, the default), a fraction (`0.5`), a number of data points (`1pt`, `3pt`), or on a datetime axis a
|
|
101
|
+
* duration (`30m`, `6h`, `1d`, `1w`). Invalid values fall back to `25%`. Every pan moves at least one data point.
|
|
102
|
+
*/
|
|
103
|
+
this.navigatorPanStep = '25%';
|
|
104
|
+
/**
|
|
105
|
+
* Granularity of `navigator-slider`. Empty (default) is smooth. Otherwise the window's start moves in steps:
|
|
106
|
+
* a percentage of the slider travel (`10%` = 11 stops), a fraction (`0.1`), a number of data points (`1pt`),
|
|
107
|
+
* or on a datetime axis a duration (`1d`) counted from the first data point. Invalid values mean smooth.
|
|
108
|
+
*/
|
|
109
|
+
this.navigatorSliderStep = '';
|
|
110
|
+
/** Move the window while the slider thumb is dragged, not only when it is released. */
|
|
111
|
+
this.navigatorSliderLive = false;
|
|
112
|
+
/**
|
|
113
|
+
* Zoom factor for the + / − buttons and keys: `2` (default) halves / doubles the window, `1.5` is gentler,
|
|
114
|
+
* `4` is coarser. Values ≤ 1 fall back to `2`.
|
|
115
|
+
*/
|
|
116
|
+
this.navigatorZoomStep = 2;
|
|
117
|
+
/**
|
|
118
|
+
* Opening window when any navigator feature (`navigator-controls`, `navigator-slider`, `navigator-pan-buttons`) is on and no `selection-min` / `selection-max` is set:
|
|
69
119
|
* a fraction of the range (`0.25`) or, on a datetime axis, a duration (`30m`, `12h`, `7d`, `2w`),
|
|
70
120
|
* ending at the latest data. Empty opens on the full range.
|
|
71
121
|
*/
|
|
@@ -99,6 +149,10 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
99
149
|
this.loadingFontSize = '';
|
|
100
150
|
this.loadingFontFamily = '';
|
|
101
151
|
this.loadingBg = '';
|
|
152
|
+
/** True while the slider thumb is being dragged in live mode, so the slider isn't re-created mid-drag. */
|
|
153
|
+
this._sliderDragging = false;
|
|
154
|
+
this._sliderKey = '';
|
|
155
|
+
this._sliderFrame = 0;
|
|
102
156
|
}
|
|
103
157
|
setZoomed(value) {
|
|
104
158
|
if (this.zoomed === value)
|
|
@@ -113,10 +167,14 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
113
167
|
this.masterChart?.reflow();
|
|
114
168
|
}
|
|
115
169
|
}
|
|
116
|
-
/**
|
|
170
|
+
/** True when any navigator feature is on. */
|
|
171
|
+
get _anyNavigator() {
|
|
172
|
+
return this.navigatorControls || this.navigatorSlider || this.navigatorPanButtons;
|
|
173
|
+
}
|
|
174
|
+
/** Re-renders only when a navigator is shown, so plain charts skip the extra update. */
|
|
117
175
|
_trackWindow(min, max) {
|
|
118
176
|
this._window = { min, max };
|
|
119
|
-
if (this.
|
|
177
|
+
if (this._anyNavigator)
|
|
120
178
|
this.requestUpdate();
|
|
121
179
|
}
|
|
122
180
|
_cssLength(val) {
|
|
@@ -204,6 +262,8 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
204
262
|
'selectionMax',
|
|
205
263
|
'navigatorDefaultWindow',
|
|
206
264
|
'navigatorControls',
|
|
265
|
+
'navigatorSlider',
|
|
266
|
+
'navigatorPanButtons',
|
|
207
267
|
'detailTitle',
|
|
208
268
|
'masterTitle',
|
|
209
269
|
'maskFill',
|
|
@@ -362,8 +422,7 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
362
422
|
else {
|
|
363
423
|
const m = /^(\d+(?:\.\d+)?)\s*(m|h|d|w)$/i.exec(v);
|
|
364
424
|
if (m && this.xAxisType === 'datetime') {
|
|
365
|
-
const
|
|
366
|
-
const width = Number(m[1]) * unit[m[2].toLowerCase()];
|
|
425
|
+
const width = Number(m[1]) * DURATION_UNITS[m[2].toLowerCase()];
|
|
367
426
|
if (width > 0 && width < dataMax - dataMin)
|
|
368
427
|
min = dataMax - width;
|
|
369
428
|
}
|
|
@@ -375,7 +434,7 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
375
434
|
}
|
|
376
435
|
defaultSelection() {
|
|
377
436
|
const { dataMin, dataMax } = this.dataExtremes();
|
|
378
|
-
if (this.
|
|
437
|
+
if (this._anyNavigator && this.selectionMin == null && this.selectionMax == null) {
|
|
379
438
|
const win = this._defaultWindow();
|
|
380
439
|
if (win)
|
|
381
440
|
return win;
|
|
@@ -657,18 +716,70 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
657
716
|
if (w)
|
|
658
717
|
this._applyWindow(w.lo, w.hi);
|
|
659
718
|
}
|
|
660
|
-
/**
|
|
661
|
-
|
|
719
|
+
/**
|
|
720
|
+
* Parses a navigator step: `25%`, a fraction (`0.25`), data points (`3pt`), or a datetime duration
|
|
721
|
+
* (`6h`, `1d`). `null` when empty or invalid (durations need a datetime axis).
|
|
722
|
+
*/
|
|
723
|
+
_parseStep(v) {
|
|
724
|
+
const s = String(v ?? '').trim().toLowerCase();
|
|
725
|
+
if (!s)
|
|
726
|
+
return null;
|
|
727
|
+
let m = /^(\d+(?:\.\d+)?)\s*%$/.exec(s);
|
|
728
|
+
if (m) {
|
|
729
|
+
const f = Number(m[1]) / 100;
|
|
730
|
+
return f > 0 ? { kind: 'fraction', value: f } : null;
|
|
731
|
+
}
|
|
732
|
+
m = /^(\d+)\s*(?:pt|pts|points?)$/.exec(s);
|
|
733
|
+
if (m) {
|
|
734
|
+
const n = Number(m[1]);
|
|
735
|
+
return n >= 1 ? { kind: 'points', value: n } : null;
|
|
736
|
+
}
|
|
737
|
+
m = /^(\d+(?:\.\d+)?)\s*(m|h|d|w)$/.exec(s);
|
|
738
|
+
if (m) {
|
|
739
|
+
if (this.xAxisType !== 'datetime')
|
|
740
|
+
return null;
|
|
741
|
+
const ms = Number(m[1]) * DURATION_UNITS[m[2]];
|
|
742
|
+
return ms > 0 ? { kind: 'duration', value: ms } : null;
|
|
743
|
+
}
|
|
744
|
+
const n = Number(s);
|
|
745
|
+
return Number.isFinite(n) && n > 0 ? { kind: 'fraction', value: n } : null;
|
|
746
|
+
}
|
|
747
|
+
/** Zoom factor used by the + / − buttons and keys. */
|
|
748
|
+
get _zoomFactor() {
|
|
749
|
+
const f = Number(this.navigatorZoomStep);
|
|
750
|
+
return Number.isFinite(f) && f > 1 ? f : 2;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Move the window toward the start (`-1`) or end (`1`), keeping its width. The distance is `step` if given,
|
|
754
|
+
* else `navigator-pan-step` (default 25% of the window); at least one data point.
|
|
755
|
+
*/
|
|
756
|
+
panBy(direction, step) {
|
|
662
757
|
const cur = this._windowIndices();
|
|
663
758
|
if (!cur)
|
|
664
759
|
return;
|
|
665
760
|
const xs = this._allXs();
|
|
666
|
-
const
|
|
667
|
-
const
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
761
|
+
const last = xs.length - 1;
|
|
762
|
+
const parsed = this._parseStep(step ?? this.navigatorPanStep) ?? { kind: 'fraction', value: 0.25 };
|
|
763
|
+
let w;
|
|
764
|
+
if (parsed.kind === 'points') {
|
|
765
|
+
const k = Math.round(parsed.value);
|
|
766
|
+
const shift = direction > 0 ? Math.min(k, last - cur.hi) : -Math.min(k, cur.lo);
|
|
767
|
+
w = { lo: cur.lo + shift, hi: cur.hi + shift };
|
|
768
|
+
}
|
|
769
|
+
else {
|
|
770
|
+
if (parsed.kind === 'duration') {
|
|
771
|
+
const d = parsed.value * direction;
|
|
772
|
+
w = this._snapWindow(xs[cur.lo] + d, xs[cur.hi] + d);
|
|
773
|
+
}
|
|
774
|
+
else {
|
|
775
|
+
const a = this._toScale(xs[cur.lo]);
|
|
776
|
+
const b = this._toScale(xs[cur.hi]);
|
|
777
|
+
const d = (b - a) * parsed.value * direction;
|
|
778
|
+
w = this._snapWindow(this._fromScale(a + d), this._fromScale(b + d));
|
|
779
|
+
}
|
|
780
|
+
if (w.lo === cur.lo && w.hi === cur.hi && cur.lo + direction >= 0 && cur.hi + direction <= last) {
|
|
781
|
+
w = { lo: cur.lo + direction, hi: cur.hi + direction };
|
|
782
|
+
}
|
|
672
783
|
}
|
|
673
784
|
this._applyWindow(w.lo, w.hi);
|
|
674
785
|
}
|
|
@@ -695,11 +806,71 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
695
806
|
const xs = this._allXs();
|
|
696
807
|
const last = xs.length - 1;
|
|
697
808
|
const cur = this._windowIndices() ?? { lo: 0, hi: last };
|
|
809
|
+
const atStart = cur.lo <= 0;
|
|
810
|
+
const atEnd = cur.hi >= last;
|
|
811
|
+
const model = this._sliderModel();
|
|
812
|
+
let sliderValue = 0;
|
|
813
|
+
if (model) {
|
|
814
|
+
const pos = Math.min(model.positions, Math.round((this._toScale(xs[cur.lo]) - model.sMin) / model.stepWidth));
|
|
815
|
+
sliderValue = Math.round((pos / model.positions) * 1000);
|
|
816
|
+
}
|
|
698
817
|
return {
|
|
699
|
-
full:
|
|
818
|
+
full: atStart && atEnd,
|
|
819
|
+
atStart,
|
|
820
|
+
atEnd,
|
|
700
821
|
atMinWidth: cur.hi - cur.lo <= 1,
|
|
822
|
+
sliderValue,
|
|
701
823
|
};
|
|
702
824
|
}
|
|
825
|
+
/**
|
|
826
|
+
* The slider's stops: the free room (data range minus window width, on the axis scale) split by
|
|
827
|
+
* `navigator-slider-step`. Smooth (no step) is 1000 stops. `null` when the window fills the range.
|
|
828
|
+
*/
|
|
829
|
+
_sliderModel() {
|
|
830
|
+
const cur = this._windowIndices();
|
|
831
|
+
const xs = this._allXs();
|
|
832
|
+
if (!cur || xs.length < 2)
|
|
833
|
+
return null;
|
|
834
|
+
const sMin = this._toScale(xs[0]);
|
|
835
|
+
const width = this._toScale(xs[cur.hi]) - this._toScale(xs[cur.lo]);
|
|
836
|
+
const room = this._toScale(xs[xs.length - 1]) - sMin - width;
|
|
837
|
+
if (!(room > 0))
|
|
838
|
+
return null;
|
|
839
|
+
const step = this._parseStep(this.navigatorSliderStep);
|
|
840
|
+
let stepWidth = room / 1000;
|
|
841
|
+
if (step?.kind === 'fraction')
|
|
842
|
+
stepWidth = room * step.value;
|
|
843
|
+
else if (step?.kind === 'duration' && !this._isLogX)
|
|
844
|
+
stepWidth = step.value;
|
|
845
|
+
else if (step?.kind === 'points' && !this._isLogX)
|
|
846
|
+
stepWidth = step.value * (this.pointStep(xs) || room / 1000);
|
|
847
|
+
stepWidth = Math.min(stepWidth, room);
|
|
848
|
+
const positions = Math.max(1, Math.ceil(room / stepWidth - 1e-9));
|
|
849
|
+
return { positions, stepWidth, sMin, room, width };
|
|
850
|
+
}
|
|
851
|
+
/** Moves the window to slider value `value` (0–1000), rounded to the nearest stop; the width is kept. */
|
|
852
|
+
_applySliderValue(value) {
|
|
853
|
+
const model = this._sliderModel();
|
|
854
|
+
if (!model)
|
|
855
|
+
return;
|
|
856
|
+
const pos = Math.round((Math.min(Math.max(value, 0), 1000) / 1000) * model.positions);
|
|
857
|
+
const a = Math.min(model.sMin + pos * model.stepWidth, model.sMin + model.room);
|
|
858
|
+
this._setWindow(this._fromScale(a), this._fromScale(a + model.width));
|
|
859
|
+
}
|
|
860
|
+
_onSliderInput(event) {
|
|
861
|
+
if (!this.navigatorSliderLive)
|
|
862
|
+
return;
|
|
863
|
+
this._sliderDragging = true;
|
|
864
|
+
const value = Number(event.detail.value) || 0;
|
|
865
|
+
cancelAnimationFrame(this._sliderFrame);
|
|
866
|
+
this._sliderFrame = requestAnimationFrame(() => this._applySliderValue(value));
|
|
867
|
+
}
|
|
868
|
+
_onSliderChange(event) {
|
|
869
|
+
cancelAnimationFrame(this._sliderFrame);
|
|
870
|
+
this._sliderDragging = false;
|
|
871
|
+
this._applySliderValue(Number(event.detail.value) || 0);
|
|
872
|
+
this.requestUpdate();
|
|
873
|
+
}
|
|
703
874
|
/** Drag-to-pan on the detail pane: the window follows the pointer, keeping its width. */
|
|
704
875
|
get _canDragPan() {
|
|
705
876
|
return this.navigatorControls && !this.masterOnly && this._allXs().length >= 2;
|
|
@@ -755,9 +926,9 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
755
926
|
else if (key === 'ArrowRight')
|
|
756
927
|
this.panBy(1);
|
|
757
928
|
else if (key === '+' || key === '=')
|
|
758
|
-
this.zoomBy(
|
|
929
|
+
this.zoomBy(1 / this._zoomFactor);
|
|
759
930
|
else if (key === '-' || key === '_')
|
|
760
|
-
this.zoomBy(
|
|
931
|
+
this.zoomBy(this._zoomFactor);
|
|
761
932
|
else
|
|
762
933
|
return;
|
|
763
934
|
e.preventDefault();
|
|
@@ -777,12 +948,50 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
777
948
|
@click=${onClick}
|
|
778
949
|
><nile-glyph name=${icon} method="stroke" size="16" color="currentColor"></nile-glyph></button>`;
|
|
779
950
|
}
|
|
951
|
+
_panButton(icon, label, disabled, direction) {
|
|
952
|
+
return html `<button
|
|
953
|
+
type="button"
|
|
954
|
+
class="navigator-pan-button"
|
|
955
|
+
part="navigator-pan-button"
|
|
956
|
+
aria-label=${label}
|
|
957
|
+
title=${label}
|
|
958
|
+
?disabled=${disabled}
|
|
959
|
+
@click=${() => this.panBy(direction)}
|
|
960
|
+
><nile-glyph name=${icon} method="stroke" size="16" color="currentColor"></nile-glyph></button>`;
|
|
961
|
+
}
|
|
962
|
+
/** The slider re-renders (re-positions its thumb) when its value changes, except mid-drag in live mode. */
|
|
963
|
+
_currentSliderKey(nav) {
|
|
964
|
+
if (!this._sliderDragging)
|
|
965
|
+
this._sliderKey = `${nav.sliderValue}:${nav.full}`;
|
|
966
|
+
return this._sliderKey;
|
|
967
|
+
}
|
|
968
|
+
/** Bar under the master pane: optional ‹ pan, slider, › pan — each part on its own property. */
|
|
969
|
+
_renderNavigatorBar() {
|
|
970
|
+
const nav = this._navState;
|
|
971
|
+
return html `<div class="navigator-bar" part="navigator-bar" role="toolbar" aria-label="Chart navigation">
|
|
972
|
+
${this.navigatorPanButtons ? this._panButton('ng-chevron-left', 'Pan back', nav.atStart, -1) : nothing}
|
|
973
|
+
${this.navigatorSlider
|
|
974
|
+
? keyed(this._currentSliderKey(nav), html `<nile-slider
|
|
975
|
+
class="navigator-slider"
|
|
976
|
+
part="navigator-slider"
|
|
977
|
+
aria-label="Visible range position"
|
|
978
|
+
.minValue=${0}
|
|
979
|
+
.maxValue=${1000}
|
|
980
|
+
.value=${nav.sliderValue}
|
|
981
|
+
?disabled=${nav.full}
|
|
982
|
+
@nile-change=${this._onSliderInput}
|
|
983
|
+
@nile-change-end=${this._onSliderChange}
|
|
984
|
+
></nile-slider>`)
|
|
985
|
+
: html `<span class="navigator-bar-spacer"></span>`}
|
|
986
|
+
${this.navigatorPanButtons ? this._panButton('ng-chevron-right', 'Pan forward', nav.atEnd, 1) : nothing}
|
|
987
|
+
</div>`;
|
|
988
|
+
}
|
|
780
989
|
/** Map-style + / − zoom buttons, overlaid on the top-right corner of the chart. */
|
|
781
990
|
_renderZoomControls() {
|
|
782
991
|
const nav = this._navState;
|
|
783
992
|
return html `<div class="navigator" part="navigator" role="toolbar" aria-label="Chart zoom" aria-orientation="vertical">
|
|
784
|
-
${this._navButton('ng-plus', 'Zoom in', nav.atMinWidth, () => this.zoomBy(
|
|
785
|
-
${this._navButton('ng-minus', 'Zoom out', nav.full, () => this.zoomBy(
|
|
993
|
+
${this._navButton('ng-plus', 'Zoom in', nav.atMinWidth, () => this.zoomBy(1 / this._zoomFactor))}
|
|
994
|
+
${this._navButton('ng-minus', 'Zoom out', nav.full, () => this.zoomBy(this._zoomFactor))}
|
|
786
995
|
</div>`;
|
|
787
996
|
}
|
|
788
997
|
async initCharts() {
|
|
@@ -830,7 +1039,9 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
830
1039
|
if (!this._typesValid)
|
|
831
1040
|
return nothing;
|
|
832
1041
|
const masterHidden = !this.masterOnly && this.masterCollapsed;
|
|
833
|
-
const
|
|
1042
|
+
const enoughData = this._allXs().length >= 2;
|
|
1043
|
+
const showNav = this.navigatorControls && enoughData;
|
|
1044
|
+
const showBar = (this.navigatorSlider || this.navigatorPanButtons) && enoughData;
|
|
834
1045
|
const pannable = showNav && !this.masterOnly && !this._navState.full;
|
|
835
1046
|
const navLabel = 'Chart. Arrow keys pan, plus and minus zoom.';
|
|
836
1047
|
const detailClasses = [
|
|
@@ -877,6 +1088,7 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
877
1088
|
@keydown=${this.masterOnly ? this._onNavKeydown : nothing}
|
|
878
1089
|
></div>
|
|
879
1090
|
${showNav ? this._renderZoomControls() : nothing}
|
|
1091
|
+
${showBar ? this._renderNavigatorBar() : nothing}
|
|
880
1092
|
</div>`;
|
|
881
1093
|
}
|
|
882
1094
|
};
|
|
@@ -932,6 +1144,24 @@ __decorate([
|
|
|
932
1144
|
__decorate([
|
|
933
1145
|
property({ type: Boolean, reflect: true, attribute: 'navigator-controls' })
|
|
934
1146
|
], NileMasterDetailChart.prototype, "navigatorControls", void 0);
|
|
1147
|
+
__decorate([
|
|
1148
|
+
property({ type: Boolean, reflect: true, attribute: 'navigator-slider' })
|
|
1149
|
+
], NileMasterDetailChart.prototype, "navigatorSlider", void 0);
|
|
1150
|
+
__decorate([
|
|
1151
|
+
property({ type: Boolean, reflect: true, attribute: 'navigator-pan-buttons' })
|
|
1152
|
+
], NileMasterDetailChart.prototype, "navigatorPanButtons", void 0);
|
|
1153
|
+
__decorate([
|
|
1154
|
+
property({ type: String, attribute: 'navigator-pan-step' })
|
|
1155
|
+
], NileMasterDetailChart.prototype, "navigatorPanStep", void 0);
|
|
1156
|
+
__decorate([
|
|
1157
|
+
property({ type: String, attribute: 'navigator-slider-step' })
|
|
1158
|
+
], NileMasterDetailChart.prototype, "navigatorSliderStep", void 0);
|
|
1159
|
+
__decorate([
|
|
1160
|
+
property({ type: Boolean, attribute: 'navigator-slider-live' })
|
|
1161
|
+
], NileMasterDetailChart.prototype, "navigatorSliderLive", void 0);
|
|
1162
|
+
__decorate([
|
|
1163
|
+
property({ type: Number, attribute: 'navigator-zoom-step' })
|
|
1164
|
+
], NileMasterDetailChart.prototype, "navigatorZoomStep", void 0);
|
|
935
1165
|
__decorate([
|
|
936
1166
|
property({ type: String, attribute: 'navigator-default-window' })
|
|
937
1167
|
], NileMasterDetailChart.prototype, "navigatorDefaultWindow", void 0);
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import { expect, fixture, html } from '@open-wc/testing';
|
|
15
15
|
import './nile-master-detail-chart';
|
|
16
16
|
import '../nile-chart/nile-chart';
|
|
17
|
+
import { MASTER_DETAIL_CHART_PARTS } from './nile-master-detail-chart';
|
|
17
18
|
const host = (el) => el;
|
|
18
19
|
const SERIES = [
|
|
19
20
|
{ name: 'Alpha', data: [{ x: 1, y: 10 }, { x: 2, y: 20 }, { x: 3, y: 30 }], color: '#ff0000' },
|
|
@@ -653,4 +654,203 @@ describe('NileMasterDetailChart — navigator snapping, log scale, categories, s
|
|
|
653
654
|
expect(navigatorPart(two)).to.not.be.null;
|
|
654
655
|
});
|
|
655
656
|
});
|
|
657
|
+
describe('NileMasterDetailChart — independent slider and pan buttons', () => {
|
|
658
|
+
const bar = (el) => el.shadowRoot.querySelector('[part~="navigator-bar"]');
|
|
659
|
+
const slider = (el) => el.shadowRoot.querySelector('[part~="navigator-bar"] nile-slider');
|
|
660
|
+
const panBtn = (el, label) => el.shadowRoot.querySelector(`[part~="navigator-bar"] [aria-label="${label}"]`);
|
|
661
|
+
const win = (el) => el._window;
|
|
662
|
+
it('S1. renders no bar by default, nor with navigator-controls alone', async () => {
|
|
663
|
+
expect(bar(await mount({ series: DT_SERIES }))).to.be.null;
|
|
664
|
+
expect(bar(await mount({ series: DT_SERIES, navigatorControls: true }))).to.be.null;
|
|
665
|
+
});
|
|
666
|
+
it('S2. navigator-slider alone: slider, no pan buttons, no + / − control', async () => {
|
|
667
|
+
const el = await mount({ series: DT_SERIES, navigatorSlider: true });
|
|
668
|
+
expect(slider(el)).to.not.be.null;
|
|
669
|
+
expect(panBtn(el, 'Pan back')).to.be.null;
|
|
670
|
+
expect(panBtn(el, 'Pan forward')).to.be.null;
|
|
671
|
+
expect(navigatorPart(el)).to.be.null;
|
|
672
|
+
});
|
|
673
|
+
it('S3. navigator-pan-buttons alone: ‹ › buttons, no slider, no + / − control', async () => {
|
|
674
|
+
const el = await mount({ series: DT_SERIES, navigatorPanButtons: true });
|
|
675
|
+
expect(panBtn(el, 'Pan back')).to.not.be.null;
|
|
676
|
+
expect(panBtn(el, 'Pan forward')).to.not.be.null;
|
|
677
|
+
expect(slider(el)).to.be.null;
|
|
678
|
+
expect(navigatorPart(el)).to.be.null;
|
|
679
|
+
});
|
|
680
|
+
it('S4. all three together: + / − overlay plus bar with ‹ slider ›, in that order', async () => {
|
|
681
|
+
const el = await mount({ series: DT_SERIES, navigatorControls: true, navigatorSlider: true, navigatorPanButtons: true });
|
|
682
|
+
expect(navigatorPart(el)).to.not.be.null;
|
|
683
|
+
const kids = [...bar(el).children].map((c) => c.getAttribute('aria-label'));
|
|
684
|
+
expect(kids).to.deep.equal(['Pan back', 'Visible range position', 'Pan forward']);
|
|
685
|
+
});
|
|
686
|
+
it('S5. full range: slider and both pan buttons disabled', async () => {
|
|
687
|
+
const el = await mount({ series: DT_SERIES, navigatorSlider: true, navigatorPanButtons: true });
|
|
688
|
+
expect(isDisabled(slider(el))).to.be.true;
|
|
689
|
+
expect(panBtn(el, 'Pan back').disabled).to.be.true;
|
|
690
|
+
expect(panBtn(el, 'Pan forward').disabled).to.be.true;
|
|
691
|
+
});
|
|
692
|
+
it('S6. navigator-default-window applies with only the slider on', async () => {
|
|
693
|
+
const el = await mount({ series: DT_SERIES, navigatorSlider: true, navigatorDefaultWindow: '2d' });
|
|
694
|
+
expect(win(el)).to.deep.equal({ min: DT_MAX - 2 * DAY, max: DT_MAX });
|
|
695
|
+
expect(isDisabled(slider(el))).to.be.false;
|
|
696
|
+
});
|
|
697
|
+
it('S7. pan back button moves the window earlier and enables pan forward', async () => {
|
|
698
|
+
const el = await mount({ series: DT_SERIES, navigatorPanButtons: true, navigatorDefaultWindow: '2d' });
|
|
699
|
+
expect(panBtn(el, 'Pan forward').disabled).to.be.true;
|
|
700
|
+
const seen = selectionSpy(el);
|
|
701
|
+
panBtn(el, 'Pan back').click();
|
|
702
|
+
await el.updateComplete;
|
|
703
|
+
expect(win(el)).to.deep.equal({ min: DT_MAX - 3 * DAY, max: DT_MAX - DAY });
|
|
704
|
+
expect(seen.length).to.equal(1);
|
|
705
|
+
expect(panBtn(el, 'Pan forward').disabled).to.be.false;
|
|
706
|
+
});
|
|
707
|
+
it('S8. moving the slider to 0 puts the window at the start, keeping its width', async () => {
|
|
708
|
+
const el = await mount({ series: DT_SERIES, navigatorSlider: true, navigatorDefaultWindow: '2d' });
|
|
709
|
+
slider(el).dispatchEvent(new CustomEvent('nile-change-end', { detail: { value: 0 } }));
|
|
710
|
+
await el.updateComplete;
|
|
711
|
+
expect(win(el)).to.deep.equal({ min: DT_MIN, max: DT_MIN + 2 * DAY });
|
|
712
|
+
});
|
|
713
|
+
it('S9. the bar shows in master-only mode', async () => {
|
|
714
|
+
const el = await mount({ series: DT_SERIES, masterOnly: true, navigatorSlider: true, navigatorPanButtons: true });
|
|
715
|
+
expect(bar(el)).to.not.be.null;
|
|
716
|
+
});
|
|
717
|
+
});
|
|
718
|
+
describe('NileMasterDetailChart — navigator step controls', () => {
|
|
719
|
+
const win = (el) => el._window;
|
|
720
|
+
const barBtn = (el, label) => el.shadowRoot.querySelector(`[part~="navigator-bar"] [aria-label="${label}"]`);
|
|
721
|
+
const slider = (el) => el.shadowRoot.querySelector('[part~="navigator-bar"] nile-slider');
|
|
722
|
+
const frame = () => new Promise((r) => requestAnimationFrame(() => r()));
|
|
723
|
+
const panBack = async (props) => {
|
|
724
|
+
const el = await mount({ series: DT_SERIES, navigatorPanButtons: true, ...props });
|
|
725
|
+
barBtn(el, 'Pan back').click();
|
|
726
|
+
await el.updateComplete;
|
|
727
|
+
return win(el);
|
|
728
|
+
};
|
|
729
|
+
it('P1. default pan step is 25% of the window', async () => {
|
|
730
|
+
expect(await panBack({ navigatorDefaultWindow: '4d' })).to.deep.equal({ min: DT_MAX - 5 * DAY, max: DT_MAX - DAY });
|
|
731
|
+
});
|
|
732
|
+
it('P2. navigator-pan-step as a percentage or a fraction', async () => {
|
|
733
|
+
const want = { min: DT_MAX - 6 * DAY, max: DT_MAX - 2 * DAY };
|
|
734
|
+
expect(await panBack({ navigatorDefaultWindow: '4d', navigatorPanStep: '50%' })).to.deep.equal(want);
|
|
735
|
+
expect(await panBack({ navigatorDefaultWindow: '4d', navigatorPanStep: '0.5' })).to.deep.equal(want);
|
|
736
|
+
});
|
|
737
|
+
it('P3. navigator-pan-step in data points and as a duration', async () => {
|
|
738
|
+
expect(await panBack({ navigatorDefaultWindow: '2d', navigatorPanStep: '2pt' }))
|
|
739
|
+
.to.deep.equal({ min: DT_MAX - 4 * DAY, max: DT_MAX - 2 * DAY });
|
|
740
|
+
expect(await panBack({ navigatorDefaultWindow: '2d', navigatorPanStep: '3d' }))
|
|
741
|
+
.to.deep.equal({ min: DT_MAX - 5 * DAY, max: DT_MAX - 3 * DAY });
|
|
742
|
+
});
|
|
743
|
+
it('P4. an invalid pan step falls back to 25%', async () => {
|
|
744
|
+
expect(await panBack({ navigatorDefaultWindow: '4d', navigatorPanStep: 'abc' }))
|
|
745
|
+
.to.deep.equal({ min: DT_MAX - 5 * DAY, max: DT_MAX - DAY });
|
|
746
|
+
});
|
|
747
|
+
it('P5. a points step clamps at the start and keeps the width', async () => {
|
|
748
|
+
expect(await panBack({ selectionMin: DT_MIN + DAY, selectionMax: DT_MIN + 3 * DAY, navigatorPanStep: '3pt' }))
|
|
749
|
+
.to.deep.equal({ min: DT_MIN, max: DT_MIN + 2 * DAY });
|
|
750
|
+
});
|
|
751
|
+
it('P6. arrow keys and panBy(dir, step) use the step', async () => {
|
|
752
|
+
const el = await mount({ series: DT_SERIES, navigatorControls: true, navigatorDefaultWindow: '2d', navigatorPanStep: '2pt' });
|
|
753
|
+
detailPane(el).dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft', bubbles: true }));
|
|
754
|
+
await el.updateComplete;
|
|
755
|
+
expect(win(el)).to.deep.equal({ min: DT_MAX - 4 * DAY, max: DT_MAX - 2 * DAY });
|
|
756
|
+
el.panBy(1, '1pt');
|
|
757
|
+
expect(win(el)).to.deep.equal({ min: DT_MAX - 3 * DAY, max: DT_MAX - DAY });
|
|
758
|
+
});
|
|
759
|
+
it('P7. changing the pan step does not reset the window', async () => {
|
|
760
|
+
const el = await mount({ series: DT_SERIES, navigatorPanButtons: true, navigatorDefaultWindow: '2d' });
|
|
761
|
+
barBtn(el, 'Pan back').click();
|
|
762
|
+
const before = win(el);
|
|
763
|
+
el.navigatorPanStep = '50%';
|
|
764
|
+
await el.updateComplete;
|
|
765
|
+
expect(win(el)).to.deep.equal(before);
|
|
766
|
+
});
|
|
767
|
+
it('S1. smooth slider (default) lands on the nearest data point', async () => {
|
|
768
|
+
const el = await mount({ series: DT_SERIES, navigatorSlider: true, navigatorDefaultWindow: '2d' });
|
|
769
|
+
slider(el).dispatchEvent(new CustomEvent('nile-change-end', { detail: { value: 300 } }));
|
|
770
|
+
expect(win(el)).to.deep.equal({ min: DT_MIN + 2 * DAY, max: DT_MIN + 4 * DAY });
|
|
771
|
+
});
|
|
772
|
+
it('S2. navigator-slider-step as a percentage snaps to stops and moves the thumb to the stop', async () => {
|
|
773
|
+
const el = await mount({ series: DT_SERIES, navigatorSlider: true, navigatorDefaultWindow: '2d', navigatorSliderStep: '50%' });
|
|
774
|
+
slider(el).dispatchEvent(new CustomEvent('nile-change-end', { detail: { value: 300 } }));
|
|
775
|
+
await el.updateComplete;
|
|
776
|
+
expect(win(el)).to.deep.equal({ min: DT_MIN + 3 * DAY, max: DT_MIN + 5 * DAY });
|
|
777
|
+
expect(slider(el).value).to.equal(500);
|
|
778
|
+
});
|
|
779
|
+
it('S3. navigator-slider-step as a duration or data points', async () => {
|
|
780
|
+
const el = await mount({ series: DT_SERIES, navigatorSlider: true, navigatorDefaultWindow: '2d', navigatorSliderStep: '3d' });
|
|
781
|
+
slider(el).dispatchEvent(new CustomEvent('nile-change-end', { detail: { value: 300 } }));
|
|
782
|
+
expect(win(el)).to.deep.equal({ min: DT_MIN + 3 * DAY, max: DT_MIN + 5 * DAY });
|
|
783
|
+
const pts = await mount({ series: DT_SERIES, navigatorSlider: true, navigatorDefaultWindow: '2d', navigatorSliderStep: '2pt' });
|
|
784
|
+
slider(pts).dispatchEvent(new CustomEvent('nile-change-end', { detail: { value: 300 } }));
|
|
785
|
+
expect(win(pts)).to.deep.equal({ min: DT_MIN + 2 * DAY, max: DT_MIN + 4 * DAY });
|
|
786
|
+
});
|
|
787
|
+
it('S4. without navigator-slider-live, dragging (nile-change) does not move the window', async () => {
|
|
788
|
+
const el = await mount({ series: DT_SERIES, navigatorSlider: true, navigatorDefaultWindow: '2d' });
|
|
789
|
+
slider(el).dispatchEvent(new CustomEvent('nile-change', { detail: { value: 0 } }));
|
|
790
|
+
await frame();
|
|
791
|
+
expect(win(el)).to.deep.equal({ min: DT_MAX - 2 * DAY, max: DT_MAX });
|
|
792
|
+
});
|
|
793
|
+
it('S5. navigator-slider-live moves the window while dragging and keeps the same slider element', async () => {
|
|
794
|
+
const el = await mount({ series: DT_SERIES, navigatorSlider: true, navigatorSliderLive: true, navigatorDefaultWindow: '2d' });
|
|
795
|
+
const s = slider(el);
|
|
796
|
+
const seen = selectionSpy(el);
|
|
797
|
+
s.dispatchEvent(new CustomEvent('nile-change', { detail: { value: 0 } }));
|
|
798
|
+
await frame();
|
|
799
|
+
await el.updateComplete;
|
|
800
|
+
expect(win(el)).to.deep.equal({ min: DT_MIN, max: DT_MIN + 2 * DAY });
|
|
801
|
+
expect(seen.length).to.equal(1);
|
|
802
|
+
expect(slider(el), 'slider not re-created mid-drag').to.equal(s);
|
|
803
|
+
s.dispatchEvent(new CustomEvent('nile-change-end', { detail: { value: 0 } }));
|
|
804
|
+
await el.updateComplete;
|
|
805
|
+
expect(win(el)).to.deep.equal({ min: DT_MIN, max: DT_MIN + 2 * DAY });
|
|
806
|
+
});
|
|
807
|
+
it('Z1. navigator-zoom-step sets the + / − factor; invalid falls back to 2', async () => {
|
|
808
|
+
const width = async (props) => {
|
|
809
|
+
const el = await mount({ series: DT_SERIES, navigatorControls: true, ...props });
|
|
810
|
+
btn(el, 'Zoom in').click();
|
|
811
|
+
const w = win(el);
|
|
812
|
+
return (w.max - w.min) / DAY;
|
|
813
|
+
};
|
|
814
|
+
expect(await width({})).to.equal(4);
|
|
815
|
+
expect(await width({ navigatorZoomStep: 4 })).to.equal(2);
|
|
816
|
+
expect(await width({ navigatorZoomStep: 0.5 })).to.equal(4);
|
|
817
|
+
});
|
|
818
|
+
it('C1. <nile-chart> passes the step keys through', async () => {
|
|
819
|
+
const el = await fixture(html `<nile-chart style="display:block;width:600px;height:400px"></nile-chart>`);
|
|
820
|
+
el.config = {
|
|
821
|
+
chart: {
|
|
822
|
+
type: 'master-detail', series: SERIES, navigatorSlider: true, navigatorPanButtons: true,
|
|
823
|
+
navigatorPanStep: '1pt', navigatorSliderStep: '10%', navigatorSliderLive: true, navigatorZoomStep: 3,
|
|
824
|
+
},
|
|
825
|
+
};
|
|
826
|
+
await el.updateComplete;
|
|
827
|
+
await el.updateComplete;
|
|
828
|
+
const inner = el.shadowRoot.querySelector('nile-master-detail-chart');
|
|
829
|
+
expect(inner.navigatorPanStep).to.equal('1pt');
|
|
830
|
+
expect(inner.navigatorSliderStep).to.equal('10%');
|
|
831
|
+
expect(inner.navigatorSliderLive).to.be.true;
|
|
832
|
+
expect(inner.navigatorZoomStep).to.equal(3);
|
|
833
|
+
});
|
|
834
|
+
});
|
|
835
|
+
describe('NileMasterDetailChart — CSS parts', () => {
|
|
836
|
+
it('MASTER_DETAIL_CHART_PARTS lists exactly the parts it renders', async () => {
|
|
837
|
+
const el = await mount({
|
|
838
|
+
series: DT_SERIES, navigatorControls: true, navigatorSlider: true, navigatorPanButtons: true,
|
|
839
|
+
masterCollapsible: true, navigatorDefaultWindow: '2d',
|
|
840
|
+
});
|
|
841
|
+
const seen = new Set([...el.shadowRoot.querySelectorAll('[part]')].flatMap((n) => n.getAttribute('part').split(/\s+/)));
|
|
842
|
+
expect([...seen].sort()).to.deep.equal([...MASTER_DETAIL_CHART_PARTS].sort());
|
|
843
|
+
});
|
|
844
|
+
it('<nile-chart> tags it and re-exports every part with a master-detail- prefix', async () => {
|
|
845
|
+
const el = await fixture(html `<nile-chart style="display:block;width:600px;height:400px"></nile-chart>`);
|
|
846
|
+
el.config = { chart: { type: 'master-detail', series: SERIES } };
|
|
847
|
+
await el.updateComplete;
|
|
848
|
+
await el.updateComplete;
|
|
849
|
+
const inner = el.shadowRoot.querySelector('nile-master-detail-chart');
|
|
850
|
+
expect(inner.getAttribute('part')).to.equal('chart master-detail-chart');
|
|
851
|
+
const map = inner.getAttribute('exportparts');
|
|
852
|
+
for (const p of MASTER_DETAIL_CHART_PARTS)
|
|
853
|
+
expect(map).to.contain(`${p}: master-detail-${p}`);
|
|
854
|
+
});
|
|
855
|
+
});
|
|
656
856
|
//# sourceMappingURL=nile-master-detail-chart.test.js.map
|