@aquera/nile-visualization 2.9.50 → 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 +4 -0
- package/dist/src/internal/types/chart-master-detail-config.type.d.ts +8 -0
- package/dist/src/nile-chart/nile-chart-config.d.ts +8 -0
- package/dist/src/nile-chart/nile-chart.d.ts +12 -0
- package/dist/src/nile-chart/nile-chart.js +78 -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.d.ts +67 -3
- package/dist/src/nile-master-detail-chart/nile-master-detail-chart.js +171 -27
- package/dist/src/nile-master-detail-chart/nile-master-detail-chart.test.js +139 -0
- package/package.json +1 -1
|
@@ -18,6 +18,21 @@ export const MASTER_DETAIL_SERIES_TYPES = [
|
|
|
18
18
|
'bar',
|
|
19
19
|
];
|
|
20
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;
|
|
21
36
|
/**
|
|
22
37
|
* @tag nile-master-detail-chart
|
|
23
38
|
* @summary A detail chart above an overview (master) strip; dragging on the strip zooms the detail.
|
|
@@ -38,8 +53,6 @@ export const MASTER_DETAIL_X_AXIS_TYPES = ['datetime', 'linear', 'logarithmic',
|
|
|
38
53
|
*
|
|
39
54
|
* @dependency nile-slider - `navigator-slider` renders a `nile-slider` from `@aquera/nile-elements`; register it in the app.
|
|
40
55
|
*/
|
|
41
|
-
/** Right spacing (px) reserved on the chart under the zoom control: 32px control + 8px offset + 8px gap. */
|
|
42
|
-
const NAV_CONTROL_GUTTER = 48;
|
|
43
56
|
let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
44
57
|
constructor() {
|
|
45
58
|
super(...arguments);
|
|
@@ -82,6 +95,25 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
82
95
|
* `navigator-controls` and `navigator-slider`.
|
|
83
96
|
*/
|
|
84
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;
|
|
85
117
|
/**
|
|
86
118
|
* Opening window when any navigator feature (`navigator-controls`, `navigator-slider`, `navigator-pan-buttons`) is on and no `selection-min` / `selection-max` is set:
|
|
87
119
|
* a fraction of the range (`0.25`) or, on a datetime axis, a duration (`30m`, `12h`, `7d`, `2w`),
|
|
@@ -117,6 +149,10 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
117
149
|
this.loadingFontSize = '';
|
|
118
150
|
this.loadingFontFamily = '';
|
|
119
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;
|
|
120
156
|
}
|
|
121
157
|
setZoomed(value) {
|
|
122
158
|
if (this.zoomed === value)
|
|
@@ -386,8 +422,7 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
386
422
|
else {
|
|
387
423
|
const m = /^(\d+(?:\.\d+)?)\s*(m|h|d|w)$/i.exec(v);
|
|
388
424
|
if (m && this.xAxisType === 'datetime') {
|
|
389
|
-
const
|
|
390
|
-
const width = Number(m[1]) * unit[m[2].toLowerCase()];
|
|
425
|
+
const width = Number(m[1]) * DURATION_UNITS[m[2].toLowerCase()];
|
|
391
426
|
if (width > 0 && width < dataMax - dataMin)
|
|
392
427
|
min = dataMax - width;
|
|
393
428
|
}
|
|
@@ -681,18 +716,70 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
681
716
|
if (w)
|
|
682
717
|
this._applyWindow(w.lo, w.hi);
|
|
683
718
|
}
|
|
684
|
-
/**
|
|
685
|
-
|
|
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) {
|
|
686
757
|
const cur = this._windowIndices();
|
|
687
758
|
if (!cur)
|
|
688
759
|
return;
|
|
689
760
|
const xs = this._allXs();
|
|
690
|
-
const
|
|
691
|
-
const
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
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
|
+
}
|
|
696
783
|
}
|
|
697
784
|
this._applyWindow(w.lo, w.hi);
|
|
698
785
|
}
|
|
@@ -719,32 +806,70 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
719
806
|
const xs = this._allXs();
|
|
720
807
|
const last = xs.length - 1;
|
|
721
808
|
const cur = this._windowIndices() ?? { lo: 0, hi: last };
|
|
722
|
-
const sMin = this._toScale(xs[0]);
|
|
723
|
-
const room = this._toScale(xs[last]) - sMin - (this._toScale(xs[cur.hi]) - this._toScale(xs[cur.lo]));
|
|
724
809
|
const atStart = cur.lo <= 0;
|
|
725
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
|
+
}
|
|
726
817
|
return {
|
|
727
818
|
full: atStart && atEnd,
|
|
728
819
|
atStart,
|
|
729
820
|
atEnd,
|
|
730
821
|
atMinWidth: cur.hi - cur.lo <= 1,
|
|
731
|
-
sliderValue
|
|
822
|
+
sliderValue,
|
|
732
823
|
};
|
|
733
824
|
}
|
|
734
|
-
/**
|
|
735
|
-
|
|
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() {
|
|
736
830
|
const cur = this._windowIndices();
|
|
737
|
-
if (!cur)
|
|
738
|
-
return;
|
|
739
831
|
const xs = this._allXs();
|
|
832
|
+
if (!cur || xs.length < 2)
|
|
833
|
+
return null;
|
|
740
834
|
const sMin = this._toScale(xs[0]);
|
|
741
835
|
const width = this._toScale(xs[cur.hi]) - this._toScale(xs[cur.lo]);
|
|
742
836
|
const room = this._toScale(xs[xs.length - 1]) - sMin - width;
|
|
743
|
-
if (room
|
|
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)
|
|
744
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;
|
|
745
864
|
const value = Number(event.detail.value) || 0;
|
|
746
|
-
|
|
747
|
-
this.
|
|
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();
|
|
748
873
|
}
|
|
749
874
|
/** Drag-to-pan on the detail pane: the window follows the pointer, keeping its width. */
|
|
750
875
|
get _canDragPan() {
|
|
@@ -801,9 +926,9 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
801
926
|
else if (key === 'ArrowRight')
|
|
802
927
|
this.panBy(1);
|
|
803
928
|
else if (key === '+' || key === '=')
|
|
804
|
-
this.zoomBy(
|
|
929
|
+
this.zoomBy(1 / this._zoomFactor);
|
|
805
930
|
else if (key === '-' || key === '_')
|
|
806
|
-
this.zoomBy(
|
|
931
|
+
this.zoomBy(this._zoomFactor);
|
|
807
932
|
else
|
|
808
933
|
return;
|
|
809
934
|
e.preventDefault();
|
|
@@ -834,13 +959,19 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
834
959
|
@click=${() => this.panBy(direction)}
|
|
835
960
|
><nile-glyph name=${icon} method="stroke" size="16" color="currentColor"></nile-glyph></button>`;
|
|
836
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
|
+
}
|
|
837
968
|
/** Bar under the master pane: optional ‹ pan, slider, › pan — each part on its own property. */
|
|
838
969
|
_renderNavigatorBar() {
|
|
839
970
|
const nav = this._navState;
|
|
840
971
|
return html `<div class="navigator-bar" part="navigator-bar" role="toolbar" aria-label="Chart navigation">
|
|
841
972
|
${this.navigatorPanButtons ? this._panButton('ng-chevron-left', 'Pan back', nav.atStart, -1) : nothing}
|
|
842
973
|
${this.navigatorSlider
|
|
843
|
-
? keyed(
|
|
974
|
+
? keyed(this._currentSliderKey(nav), html `<nile-slider
|
|
844
975
|
class="navigator-slider"
|
|
845
976
|
part="navigator-slider"
|
|
846
977
|
aria-label="Visible range position"
|
|
@@ -848,6 +979,7 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
848
979
|
.maxValue=${1000}
|
|
849
980
|
.value=${nav.sliderValue}
|
|
850
981
|
?disabled=${nav.full}
|
|
982
|
+
@nile-change=${this._onSliderInput}
|
|
851
983
|
@nile-change-end=${this._onSliderChange}
|
|
852
984
|
></nile-slider>`)
|
|
853
985
|
: html `<span class="navigator-bar-spacer"></span>`}
|
|
@@ -858,8 +990,8 @@ let NileMasterDetailChart = class NileMasterDetailChart extends NileElement {
|
|
|
858
990
|
_renderZoomControls() {
|
|
859
991
|
const nav = this._navState;
|
|
860
992
|
return html `<div class="navigator" part="navigator" role="toolbar" aria-label="Chart zoom" aria-orientation="vertical">
|
|
861
|
-
${this._navButton('ng-plus', 'Zoom in', nav.atMinWidth, () => this.zoomBy(
|
|
862
|
-
${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))}
|
|
863
995
|
</div>`;
|
|
864
996
|
}
|
|
865
997
|
async initCharts() {
|
|
@@ -1018,6 +1150,18 @@ __decorate([
|
|
|
1018
1150
|
__decorate([
|
|
1019
1151
|
property({ type: Boolean, reflect: true, attribute: 'navigator-pan-buttons' })
|
|
1020
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);
|
|
1021
1165
|
__decorate([
|
|
1022
1166
|
property({ type: String, attribute: 'navigator-default-window' })
|
|
1023
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' },
|
|
@@ -714,4 +715,142 @@ describe('NileMasterDetailChart — independent slider and pan buttons', () => {
|
|
|
714
715
|
expect(bar(el)).to.not.be.null;
|
|
715
716
|
});
|
|
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
|
+
});
|
|
717
856
|
//# sourceMappingURL=nile-master-detail-chart.test.js.map
|