@aquera/nile-visualization 2.9.30 → 2.9.31

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.
Files changed (167) hide show
  1. package/README.md +11 -0
  2. package/dist/src/index.d.ts +7 -8
  3. package/dist/src/index.js +2 -3
  4. package/dist/src/internal/base/forecastable-chart.d.ts +59 -0
  5. package/dist/src/internal/base/forecastable-chart.js +149 -0
  6. package/dist/src/internal/{nile-chart-base.d.ts → base/nile-chart-base.d.ts} +1 -1
  7. package/dist/src/internal/{nile-chart-base.js → base/nile-chart-base.js} +1 -1
  8. package/dist/src/internal/types/chart-area-config.type.d.ts +4 -2
  9. package/dist/src/internal/types/chart-area-spline-config.type.d.ts +4 -2
  10. package/dist/src/internal/types/chart-column-config.type.d.ts +3 -2
  11. package/dist/src/internal/types/chart-line-config.type.d.ts +3 -2
  12. package/dist/src/internal/types/chart-spline-config.type.d.ts +3 -2
  13. package/dist/src/internal/types/index.d.ts +0 -1
  14. package/dist/src/internal/types/primitive-chart-config.type.d.ts +1 -2
  15. package/dist/src/internal/{chart-adapters.d.ts → utils/chart-adapters.d.ts} +1 -1
  16. package/dist/src/internal/{chart-adapters.js → utils/chart-adapters.js} +15 -3
  17. package/dist/src/internal/utils/chart-forecast.d.ts +126 -0
  18. package/dist/src/internal/utils/chart-forecast.js +297 -0
  19. package/dist/src/internal/{dashboard-adapters.d.ts → utils/dashboard-adapters.d.ts} +1 -1
  20. package/dist/src/internal/{utils.js → utils/deep-merge.js} +1 -1
  21. package/dist/src/internal/{resolve-widget-kind.d.ts → utils/resolve-widget-kind.d.ts} +1 -1
  22. package/dist/src/internal/utils/separated-chart-config.d.ts +13 -0
  23. package/dist/src/internal/utils/separated-chart-config.js +30 -0
  24. package/dist/src/nile-ai-panel/nile-ai-panel.d.ts +1 -1
  25. package/dist/src/nile-ai-panel/nile-ai-panel.js +1 -1
  26. package/dist/src/nile-ai-sender/nile-ai-sender.d.ts +1 -1
  27. package/dist/src/nile-ai-sender/nile-ai-sender.js +1 -1
  28. package/dist/src/nile-anomaly-chart/nile-anomaly-chart.d.ts +1 -1
  29. package/dist/src/nile-anomaly-chart/nile-anomaly-chart.js +4 -4
  30. package/dist/src/nile-area-chart/nile-area-chart.d.ts +7 -6
  31. package/dist/src/nile-area-chart/nile-area-chart.js +37 -24
  32. package/dist/src/nile-area-negative-chart/nile-area-negative-chart.d.ts +1 -1
  33. package/dist/src/nile-area-negative-chart/nile-area-negative-chart.js +5 -5
  34. package/dist/src/nile-area-range-chart/nile-area-range-chart.d.ts +1 -1
  35. package/dist/src/nile-area-range-chart/nile-area-range-chart.js +5 -5
  36. package/dist/src/nile-area-spline-chart/nile-area-spline-chart.d.ts +10 -4
  37. package/dist/src/nile-area-spline-chart/nile-area-spline-chart.js +38 -27
  38. package/dist/src/nile-bar-chart/nile-bar-chart.d.ts +3 -3
  39. package/dist/src/nile-bar-chart/nile-bar-chart.js +4 -4
  40. package/dist/src/nile-bellcurve-chart/nile-bellcurve-chart.d.ts +3 -2
  41. package/dist/src/nile-bellcurve-chart/nile-bellcurve-chart.js +5 -5
  42. package/dist/src/nile-boxplot-chart/nile-boxplot-chart.d.ts +3 -2
  43. package/dist/src/nile-boxplot-chart/nile-boxplot-chart.js +5 -5
  44. package/dist/src/nile-bubble-chart/nile-bubble-chart.d.ts +3 -3
  45. package/dist/src/nile-bubble-chart/nile-bubble-chart.js +4 -4
  46. package/dist/src/nile-chart/index.d.ts +2 -2
  47. package/dist/src/nile-chart/index.js +1 -1
  48. package/dist/src/nile-chart/nile-chart-config.d.ts +21 -32
  49. package/dist/src/nile-chart/nile-chart.css.js +0 -1
  50. package/dist/src/nile-chart/nile-chart.d.ts +2 -8
  51. package/dist/src/nile-chart/nile-chart.js +54 -61
  52. package/dist/src/nile-chart-list/nile-chart-list.d.ts +1 -1
  53. package/dist/src/nile-chart-list/nile-chart-list.js +1 -1
  54. package/dist/src/nile-chart-message/nile-chart-message.d.ts +1 -1
  55. package/dist/src/nile-chart-message/nile-chart-message.js +1 -1
  56. package/dist/src/nile-cluster-chart/nile-cluster-chart.d.ts +3 -2
  57. package/dist/src/nile-cluster-chart/nile-cluster-chart.js +5 -5
  58. package/dist/src/nile-column-chart/nile-column-chart.d.ts +13 -6
  59. package/dist/src/nile-column-chart/nile-column-chart.js +43 -24
  60. package/dist/src/nile-column-drilldown-chart/nile-column-drilldown-chart.d.ts +1 -1
  61. package/dist/src/nile-column-drilldown-chart/nile-column-drilldown-chart.js +5 -5
  62. package/dist/src/nile-column-pyramid-chart/nile-column-pyramid-chart.d.ts +1 -1
  63. package/dist/src/nile-column-pyramid-chart/nile-column-pyramid-chart.js +5 -5
  64. package/dist/src/nile-column-range-chart/nile-column-range-chart.d.ts +1 -1
  65. package/dist/src/nile-column-range-chart/nile-column-range-chart.js +5 -5
  66. package/dist/src/nile-dashboard-builder/nile-dashboard-builder.d.ts +1 -1
  67. package/dist/src/nile-dashboard-builder/nile-dashboard-builder.js +2 -2
  68. package/dist/src/nile-dashboard-viewer/nile-dashboard-viewer.d.ts +1 -1
  69. package/dist/src/nile-dashboard-viewer/nile-dashboard-viewer.js +1 -1
  70. package/dist/src/nile-donut-chart/nile-donut-chart.d.ts +3 -3
  71. package/dist/src/nile-donut-chart/nile-donut-chart.js +4 -4
  72. package/dist/src/nile-dumbbell-chart/nile-dumbbell-chart.d.ts +1 -1
  73. package/dist/src/nile-dumbbell-chart/nile-dumbbell-chart.js +5 -5
  74. package/dist/src/nile-dumbbell-lower-chart/nile-dumbbell-lower-chart.d.ts +1 -1
  75. package/dist/src/nile-dumbbell-lower-chart/nile-dumbbell-lower-chart.js +5 -5
  76. package/dist/src/nile-dumbbell-upper-chart/nile-dumbbell-upper-chart.d.ts +1 -1
  77. package/dist/src/nile-dumbbell-upper-chart/nile-dumbbell-upper-chart.js +5 -5
  78. package/dist/src/nile-euler-chart/nile-euler-chart.d.ts +1 -1
  79. package/dist/src/nile-euler-chart/nile-euler-chart.js +5 -5
  80. package/dist/src/nile-executive-summary/nile-executive-summary.d.ts +1 -1
  81. package/dist/src/nile-executive-summary/nile-executive-summary.js +1 -1
  82. package/dist/src/nile-fan-chart/nile-fan-chart.d.ts +1 -1
  83. package/dist/src/nile-fan-chart/nile-fan-chart.js +5 -5
  84. package/dist/src/nile-filter-chart/nile-filter-chart.d.ts +1 -1
  85. package/dist/src/nile-filter-chart/nile-filter-chart.js +1 -1
  86. package/dist/src/nile-flame-chart/nile-flame-chart.d.ts +1 -1
  87. package/dist/src/nile-flame-chart/nile-flame-chart.js +5 -5
  88. package/dist/src/nile-funnel-chart/nile-funnel-chart.d.ts +1 -1
  89. package/dist/src/nile-funnel-chart/nile-funnel-chart.js +5 -5
  90. package/dist/src/nile-gauge-chart/nile-gauge-chart.d.ts +1 -1
  91. package/dist/src/nile-gauge-chart/nile-gauge-chart.js +4 -4
  92. package/dist/src/nile-heatmap-chart/nile-heatmap-chart.d.ts +3 -2
  93. package/dist/src/nile-heatmap-chart/nile-heatmap-chart.js +5 -5
  94. package/dist/src/nile-histogram-chart/nile-histogram-chart.d.ts +3 -2
  95. package/dist/src/nile-histogram-chart/nile-histogram-chart.js +5 -5
  96. package/dist/src/nile-inverted-area-chart/nile-inverted-area-chart.d.ts +1 -1
  97. package/dist/src/nile-inverted-area-chart/nile-inverted-area-chart.js +5 -5
  98. package/dist/src/nile-kpi-chart/nile-kpi-chart.css.js +41 -0
  99. package/dist/src/nile-kpi-chart/nile-kpi-chart.d.ts +31 -1
  100. package/dist/src/nile-kpi-chart/nile-kpi-chart.js +73 -3
  101. package/dist/src/nile-line-chart/nile-line-chart.d.ts +12 -6
  102. package/dist/src/nile-line-chart/nile-line-chart.js +44 -24
  103. package/dist/src/nile-line-column-chart/nile-line-column-chart.d.ts +1 -1
  104. package/dist/src/nile-line-column-chart/nile-line-column-chart.js +5 -5
  105. package/dist/src/nile-lollipop-chart/nile-lollipop-chart.d.ts +1 -1
  106. package/dist/src/nile-lollipop-chart/nile-lollipop-chart.js +5 -5
  107. package/dist/src/nile-map-chart/nile-map-chart.d.ts +2 -2
  108. package/dist/src/nile-map-chart/nile-map-chart.js +4 -4
  109. package/dist/src/nile-master-detail-chart/nile-master-detail-chart.d.ts +1 -1
  110. package/dist/src/nile-master-detail-chart/nile-master-detail-chart.js +5 -5
  111. package/dist/src/nile-organization-chart/nile-organization-chart.d.ts +1 -1
  112. package/dist/src/nile-organization-chart/nile-organization-chart.js +5 -5
  113. package/dist/src/nile-pie-chart/nile-pie-chart.d.ts +1 -1
  114. package/dist/src/nile-pie-chart/nile-pie-chart.js +4 -4
  115. package/dist/src/nile-polygon-chart/nile-polygon-chart.d.ts +1 -1
  116. package/dist/src/nile-polygon-chart/nile-polygon-chart.js +5 -5
  117. package/dist/src/nile-radar-chart/nile-radar-chart.d.ts +3 -3
  118. package/dist/src/nile-radar-chart/nile-radar-chart.js +4 -4
  119. package/dist/src/nile-radial-bar-chart/nile-radial-bar-chart.d.ts +3 -2
  120. package/dist/src/nile-radial-bar-chart/nile-radial-bar-chart.js +5 -5
  121. package/dist/src/nile-scatter-chart/nile-scatter-chart.d.ts +3 -3
  122. package/dist/src/nile-scatter-chart/nile-scatter-chart.js +4 -4
  123. package/dist/src/nile-spiderweb-chart/nile-spiderweb-chart.d.ts +3 -2
  124. package/dist/src/nile-spiderweb-chart/nile-spiderweb-chart.js +5 -5
  125. package/dist/src/nile-spline-chart/nile-spline-chart.d.ts +8 -6
  126. package/dist/src/nile-spline-chart/nile-spline-chart.js +36 -24
  127. package/dist/src/nile-stacked-chart/nile-stacked-chart.d.ts +3 -2
  128. package/dist/src/nile-stacked-chart/nile-stacked-chart.js +5 -5
  129. package/dist/src/nile-timeline-chart/nile-timeline-chart.d.ts +1 -1
  130. package/dist/src/nile-timeline-chart/nile-timeline-chart.js +5 -5
  131. package/dist/src/nile-trendline-chart/nile-trendline-chart.d.ts +1 -1
  132. package/dist/src/nile-trendline-chart/nile-trendline-chart.js +4 -4
  133. package/dist/src/nile-variable-pie-chart/nile-variable-pie-chart.d.ts +3 -2
  134. package/dist/src/nile-variable-pie-chart/nile-variable-pie-chart.js +5 -5
  135. package/dist/src/nile-vector-chart/nile-vector-chart.d.ts +1 -1
  136. package/dist/src/nile-vector-chart/nile-vector-chart.js +5 -5
  137. package/dist/src/nile-waterfall-chart/nile-waterfall-chart.d.ts +3 -3
  138. package/dist/src/nile-waterfall-chart/nile-waterfall-chart.js +4 -4
  139. package/dist/src/nile-widget-viewer/nile-widget-viewer.css.js +6 -2
  140. package/dist/src/nile-widget-viewer/nile-widget-viewer.d.ts +1 -1
  141. package/dist/src/nile-widget-viewer/nile-widget-viewer.js +2 -2
  142. package/dist/src/nile-xrange-chart/nile-xrange-chart.d.ts +3 -2
  143. package/dist/src/nile-xrange-chart/nile-xrange-chart.js +5 -5
  144. package/package.json +1 -2
  145. package/dist/src/internal/separated-chart-config.d.ts +0 -5
  146. package/dist/src/internal/separated-chart-config.js +0 -16
  147. package/dist/src/internal/types/chart-forecast-config.type.d.ts +0 -35
  148. package/dist/src/internal/types/chart-forecast-config.type.js +0 -2
  149. package/dist/src/nile-forecast-chart/index.d.ts +0 -2
  150. package/dist/src/nile-forecast-chart/index.js +0 -2
  151. package/dist/src/nile-forecast-chart/nile-forecast-chart.css.d.ts +0 -1
  152. package/dist/src/nile-forecast-chart/nile-forecast-chart.css.js +0 -46
  153. package/dist/src/nile-forecast-chart/nile-forecast-chart.d.ts +0 -90
  154. package/dist/src/nile-forecast-chart/nile-forecast-chart.js +0 -551
  155. /package/dist/src/internal/{nile-element.d.ts → base/nile-element.d.ts} +0 -0
  156. /package/dist/src/internal/{nile-element.js → base/nile-element.js} +0 -0
  157. /package/dist/src/internal/{chart-events.d.ts → utils/chart-events.d.ts} +0 -0
  158. /package/dist/src/internal/{chart-events.js → utils/chart-events.js} +0 -0
  159. /package/dist/src/internal/{chart-runtime.d.ts → utils/chart-runtime.d.ts} +0 -0
  160. /package/dist/src/internal/{chart-runtime.js → utils/chart-runtime.js} +0 -0
  161. /package/dist/src/internal/{dashboard-adapters.js → utils/dashboard-adapters.js} +0 -0
  162. /package/dist/src/internal/{utils.d.ts → utils/deep-merge.d.ts} +0 -0
  163. /package/dist/src/internal/{highcharts-provider.d.ts → utils/highcharts-provider.d.ts} +0 -0
  164. /package/dist/src/internal/{highcharts-provider.js → utils/highcharts-provider.js} +0 -0
  165. /package/dist/src/internal/{resolve-widget-kind.js → utils/resolve-widget-kind.js} +0 -0
  166. /package/dist/src/internal/{responsive-defaults.d.ts → utils/responsive-defaults.d.ts} +0 -0
  167. /package/dist/src/internal/{responsive-defaults.js → utils/responsive-defaults.js} +0 -0
@@ -1,90 +0,0 @@
1
- import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
2
- import type Highcharts from 'highcharts';
3
- import NileElement from '../internal/nile-element.js';
4
- import type { SeparatedChartConfigInputType } from '../internal/types/separated-chart-config-input.type.js';
5
- import type { LegendConfig } from '../internal/types/index.js';
6
- export type ForecastPoint = [number, number];
7
- export type ForecastSeriesType = 'line' | 'spline' | 'area' | 'areaspline' | 'column';
8
- export type ForecastDashStyle = Highcharts.DashStyleValue;
9
- export interface ForecastSeriesData {
10
- name: string;
11
- data: ForecastPoint[];
12
- type?: ForecastSeriesType;
13
- axis?: 'primary' | 'secondary';
14
- color?: string;
15
- forecastColor?: string;
16
- forecastDashStyle?: ForecastDashStyle;
17
- valueSuffix?: string;
18
- lineWidth?: number;
19
- showMarkers?: boolean;
20
- fillOpacity?: number;
21
- }
22
- export declare const FORECAST_NOW_LINE_COLOR = "var(--nile-colors-primary-600, var(--ng-colors-fg-brand-primary-600))";
23
- export declare class NileForecastChart extends NileElement {
24
- static styles: CSSResultGroup;
25
- private _hc;
26
- private chart;
27
- private resizeObserver;
28
- private chartContainer;
29
- config: SeparatedChartConfigInputType | null;
30
- chartTitle: string;
31
- chartSubtitle: string;
32
- data: ForecastSeriesData[];
33
- forecastData: ForecastSeriesData[];
34
- options: Highcharts.Options;
35
- loading: boolean;
36
- height: string;
37
- forecastStart: number | null;
38
- forecastDashStyle: ForecastDashStyle;
39
- showNowLine: boolean;
40
- nowLabel: string;
41
- nowLineColor: string;
42
- forecastBandLabel: string;
43
- forecastBandColor: string;
44
- xAxisTitle: string;
45
- yAxisTitle: string;
46
- secondaryAxisTitle: string;
47
- secondaryAxisMin: number | null;
48
- timezone: string;
49
- zoom: boolean;
50
- showLegend: boolean;
51
- legend: LegendConfig | null;
52
- chartBg: string;
53
- chartBorderRadius: string | number;
54
- chartBorder: string;
55
- chartShadow: string;
56
- chartPadding: string | number;
57
- chartMinHeight: string | number;
58
- loadingText: string;
59
- loadingColor: string;
60
- loadingFontSize: string | number;
61
- loadingFontFamily: string;
62
- loadingBg: string;
63
- private _syncCssVars;
64
- private applyConfig;
65
- connectedCallback(): void;
66
- disconnectedCallback(): void;
67
- protected firstUpdated(): void;
68
- protected updated(changedProperties: PropertyValues): void;
69
- setForecast(series: ForecastSeriesData[], forecastStart?: number | null): void;
70
- clearForecast(): void;
71
- private startFromSetForecast;
72
- private zoomed;
73
- private setZoomed;
74
- private xExtremes;
75
- resetZoom(): void;
76
- private observedContainer;
77
- private syncResizeObserver;
78
- private resolveSeries;
79
- private lastTimestamp;
80
- private buildOptions;
81
- private initInFlight;
82
- private initChart;
83
- private destroyChart;
84
- render(): TemplateResult;
85
- }
86
- declare global {
87
- interface HTMLElementTagNameMap {
88
- 'nile-forecast-chart': NileForecastChart;
89
- }
90
- }
@@ -1,551 +0,0 @@
1
- import { __decorate } from "tslib";
2
- import { customElement, property, query } from 'lit/decorators.js';
3
- import { html } from 'lit';
4
- import { getHighcharts } from '../internal/highcharts-provider.js';
5
- import NileElement from '../internal/nile-element.js';
6
- import { applySeparatedChartConfig } from '../internal/separated-chart-config.js';
7
- import { deepMerge } from '../internal/utils.js';
8
- import { resolveColorPaletteColors } from '../internal/color-palettes/index.js';
9
- import { styles } from './nile-forecast-chart.css.js';
10
- export const FORECAST_NOW_LINE_COLOR = 'var(--nile-colors-primary-600, var(--ng-colors-fg-brand-primary-600))';
11
- const AXIS_LABEL_COLOR = 'var(--nile-colors-neutral-500, var(--ng-colors-text-tertiary-600))';
12
- const FORECAST_BAND_COLOR = 'color-mix(in srgb, var(--nile-colors-primary-600, var(--ng-componentcolors-utility-brand-600)) 6%, transparent)';
13
- const AXIS_LABEL_FONT_SIZE = 'var(--nile-type-scale-2, var(--ng-font-size-text-xs))';
14
- let NileForecastChart = class NileForecastChart extends NileElement {
15
- constructor() {
16
- super(...arguments);
17
- this._hc = null;
18
- this.chart = null;
19
- this.resizeObserver = null;
20
- this.config = null;
21
- this.chartTitle = '';
22
- this.chartSubtitle = '';
23
- this.data = [];
24
- this.forecastData = [];
25
- this.options = {};
26
- this.loading = false;
27
- this.height = '400px';
28
- this.forecastStart = null;
29
- this.forecastDashStyle = 'Dot';
30
- this.showNowLine = true;
31
- this.nowLabel = 'Now';
32
- this.nowLineColor = FORECAST_NOW_LINE_COLOR;
33
- this.forecastBandLabel = '';
34
- this.forecastBandColor = '';
35
- this.xAxisTitle = '';
36
- this.yAxisTitle = '';
37
- this.secondaryAxisTitle = '';
38
- this.secondaryAxisMin = null;
39
- this.timezone = '';
40
- this.zoom = true;
41
- this.showLegend = true;
42
- this.legend = null;
43
- this.chartBg = '';
44
- this.chartBorderRadius = '';
45
- this.chartBorder = '';
46
- this.chartShadow = '';
47
- this.chartPadding = '';
48
- this.chartMinHeight = '';
49
- this.loadingText = 'Loading...';
50
- this.loadingColor = '';
51
- this.loadingFontSize = '';
52
- this.loadingFontFamily = '';
53
- this.loadingBg = '';
54
- this.startFromSetForecast = false;
55
- this.zoomed = false;
56
- this.observedContainer = null;
57
- this.initInFlight = false;
58
- }
59
- _syncCssVars() {
60
- const set = (prop, val) => {
61
- const s = typeof val === 'number'
62
- ? (Number.isFinite(val) ? `${val}px` : '')
63
- : String(val ?? '').trim();
64
- if (s)
65
- this.style.setProperty(prop, s);
66
- else
67
- this.style.removeProperty(prop);
68
- };
69
- set('--nile-chart-bg', this.chartBg);
70
- set('--nile-chart-border-radius', this.chartBorderRadius);
71
- set('--nile-chart-border', this.chartBorder);
72
- set('--nile-chart-shadow', this.chartShadow);
73
- set('--nile-chart-padding', this.chartPadding);
74
- set('--nile-chart-min-height', this.chartMinHeight);
75
- set('--nile-chart-loading-color', this.loadingColor);
76
- set('--nile-chart-loading-font-size', this.loadingFontSize);
77
- set('--nile-chart-loading-font-family', this.loadingFontFamily);
78
- set('--nile-chart-loading-bg', this.loadingBg);
79
- }
80
- applyConfig(cfg) {
81
- applySeparatedChartConfig(this, cfg);
82
- }
83
- connectedCallback() {
84
- super.connectedCallback();
85
- if (this.config)
86
- this.applyConfig(this.config);
87
- }
88
- disconnectedCallback() {
89
- super.disconnectedCallback();
90
- this.destroyChart();
91
- this.resizeObserver?.disconnect();
92
- this.resizeObserver = null;
93
- this.observedContainer = null;
94
- }
95
- firstUpdated() {
96
- this._syncCssVars();
97
- this.initChart();
98
- this.syncResizeObserver();
99
- }
100
- updated(changedProperties) {
101
- this.syncResizeObserver();
102
- if (changedProperties.has('config') && this.config) {
103
- this.applyConfig(this.config);
104
- return;
105
- }
106
- const props = [
107
- 'data',
108
- 'forecastData',
109
- 'chartTitle',
110
- 'chartSubtitle',
111
- 'options',
112
- 'height',
113
- 'forecastStart',
114
- 'forecastDashStyle',
115
- 'showNowLine',
116
- 'nowLabel',
117
- 'nowLineColor',
118
- 'forecastBandLabel',
119
- 'forecastBandColor',
120
- 'xAxisTitle',
121
- 'yAxisTitle',
122
- 'secondaryAxisTitle',
123
- 'secondaryAxisMin',
124
- 'timezone',
125
- 'showLegend',
126
- 'legend',
127
- 'zoom',
128
- 'loading',
129
- ];
130
- const cssVarProps = ['chartBg', 'chartBorderRadius', 'chartBorder', 'chartShadow', 'chartPadding', 'chartMinHeight',
131
- 'loadingText', 'loadingColor', 'loadingFontSize', 'loadingFontFamily', 'loadingBg'];
132
- if (cssVarProps.some(p => changedProperties.has(p)))
133
- this._syncCssVars();
134
- const objectProps = new Set(['data', 'forecastData', 'options', 'legend']);
135
- const reallyChanged = (p) => {
136
- if (!changedProperties.has(p))
137
- return false;
138
- if (!objectProps.has(p))
139
- return true;
140
- const oldV = changedProperties.get(p);
141
- const newV = this[p];
142
- try {
143
- return JSON.stringify(oldV) !== JSON.stringify(newV);
144
- }
145
- catch {
146
- return oldV !== newV;
147
- }
148
- };
149
- if (!props.some(reallyChanged))
150
- return;
151
- if (this.loading) {
152
- this.destroyChart();
153
- return;
154
- }
155
- if (this.chart) {
156
- this.chart.update(this.buildOptions(), true, true);
157
- }
158
- else {
159
- this.initChart();
160
- }
161
- }
162
- setForecast(series, forecastStart) {
163
- if (forecastStart !== undefined) {
164
- this.forecastStart = forecastStart;
165
- this.startFromSetForecast = forecastStart !== null;
166
- }
167
- this.forecastData = series;
168
- }
169
- clearForecast() {
170
- this.forecastData = [];
171
- if (this.startFromSetForecast) {
172
- this.forecastStart = null;
173
- this.startFromSetForecast = false;
174
- }
175
- }
176
- setZoomed(value) {
177
- if (this.zoomed === value)
178
- return;
179
- this.zoomed = value;
180
- this.emit('nile-forecast-zoom', { zoomed: value });
181
- }
182
- xExtremes() {
183
- let dataMin = Infinity;
184
- let dataMax = -Infinity;
185
- for (const { s } of this.resolveSeries().entries) {
186
- for (const p of s.data ?? []) {
187
- const x = p[0];
188
- if (x < dataMin)
189
- dataMin = x;
190
- if (x > dataMax)
191
- dataMax = x;
192
- }
193
- }
194
- return dataMin === Infinity ? { dataMin: 0, dataMax: 0 } : { dataMin, dataMax };
195
- }
196
- resetZoom() {
197
- if (!this.chart)
198
- return;
199
- this.chart.xAxis[0].setExtremes(undefined, undefined);
200
- this.setZoomed(false);
201
- const { dataMin, dataMax } = this.xExtremes();
202
- this.emit('nile-chart-selection', { min: dataMin, max: dataMax });
203
- }
204
- syncResizeObserver() {
205
- const target = this.chartContainer ?? null;
206
- if (target === this.observedContainer)
207
- return;
208
- this.resizeObserver?.disconnect();
209
- this.observedContainer = target;
210
- if (!target)
211
- return;
212
- if (!this.resizeObserver) {
213
- this.resizeObserver = new ResizeObserver(() => {
214
- this.chart?.reflow();
215
- });
216
- }
217
- this.resizeObserver.observe(target);
218
- }
219
- resolveSeries() {
220
- const projected = this.forecastData ?? [];
221
- const explicit = typeof this.forecastStart === 'number' && Number.isFinite(this.forecastStart)
222
- ? this.forecastStart
223
- : null;
224
- if (!projected.length) {
225
- const start = explicit ?? Date.now();
226
- const hasForecast = this.data.some(s => s.data?.some(p => p[0] > start));
227
- return {
228
- entries: this.data.map(s => ({ s, projectedOnly: false })),
229
- start,
230
- hasForecast,
231
- };
232
- }
233
- const byName = new Map(projected.map(s => [s.name, s]));
234
- const entries = this.data.map(s => {
235
- const add = byName.get(s.name);
236
- if (!add?.data?.length)
237
- return { s, projectedOnly: false };
238
- byName.delete(s.name);
239
- const { name: _name, data: _data, ...overrides } = add;
240
- return {
241
- s: { ...s, ...overrides, data: [...s.data, ...add.data].sort((a, b) => a[0] - b[0]) },
242
- projectedOnly: false,
243
- };
244
- });
245
- for (const s of byName.values())
246
- entries.push({ s, projectedOnly: true });
247
- let lastMeasured = null;
248
- for (const s of this.data) {
249
- if (!projected.some(p => p.name === s.name))
250
- continue;
251
- const point = s.data?.[s.data.length - 1];
252
- if (point && (lastMeasured === null || point[0] > lastMeasured))
253
- lastMeasured = point[0];
254
- }
255
- return { entries, start: explicit ?? lastMeasured ?? Date.now(), hasForecast: true };
256
- }
257
- lastTimestamp(all) {
258
- let max = null;
259
- for (const s of all) {
260
- const point = s.data?.[s.data.length - 1];
261
- if (point && (max === null || point[0] > max))
262
- max = point[0];
263
- }
264
- return max;
265
- }
266
- buildOptions() {
267
- const self = this;
268
- const { entries, start, hasForecast } = this.resolveSeries();
269
- const resolved = entries.map(e => e.s);
270
- const hasSecondary = resolved.some(s => s.axis === 'secondary');
271
- const bandEnd = this.lastTimestamp(resolved);
272
- const showBand = hasForecast
273
- && (this.forecastBandLabel || this.forecastBandColor)
274
- && bandEnd !== null
275
- && bandEnd > start;
276
- const xAxis = {
277
- type: 'datetime',
278
- title: { text: this.xAxisTitle || undefined },
279
- plotLines: this.showNowLine && hasForecast
280
- ? [
281
- {
282
- value: start,
283
- color: this.nowLineColor,
284
- width: 2,
285
- dashStyle: 'Dash',
286
- zIndex: 5,
287
- ...(this.nowLabel
288
- ? { label: { text: this.nowLabel, rotation: 0, y: 20, style: { color: AXIS_LABEL_COLOR, fontSize: AXIS_LABEL_FONT_SIZE } } }
289
- : {}),
290
- },
291
- ]
292
- : [],
293
- plotBands: showBand
294
- ? [
295
- {
296
- from: start,
297
- to: bandEnd,
298
- color: this.forecastBandColor || FORECAST_BAND_COLOR,
299
- ...(this.forecastBandLabel
300
- ? { label: { text: this.forecastBandLabel, style: { color: AXIS_LABEL_COLOR, fontSize: AXIS_LABEL_FONT_SIZE } } }
301
- : {}),
302
- },
303
- ]
304
- : [],
305
- };
306
- const yAxis = [
307
- { title: { text: this.yAxisTitle || undefined } },
308
- ];
309
- if (hasSecondary) {
310
- yAxis.push({
311
- title: { text: this.secondaryAxisTitle || undefined },
312
- opposite: true,
313
- gridLineWidth: 0,
314
- ...(this.secondaryAxisMin !== null ? { min: this.secondaryAxisMin } : {}),
315
- });
316
- }
317
- const series = entries.map(({ s, projectedOnly }) => {
318
- const type = s.type ?? 'line';
319
- const isColumn = type === 'column';
320
- const isArea = type === 'area' || type === 'areaspline';
321
- const forecastZone = isColumn
322
- ? (s.forecastColor ? { color: s.forecastColor } : {})
323
- : { dashStyle: s.forecastDashStyle ?? this.forecastDashStyle };
324
- return {
325
- type: type,
326
- name: s.name,
327
- data: [...(s.data ?? [])],
328
- ...(s.color ? { color: s.color } : {}),
329
- yAxis: s.axis === 'secondary' ? 1 : 0,
330
- zIndex: isColumn ? 1 : 2,
331
- zoneAxis: 'x',
332
- zones: projectedOnly || !hasForecast ? [] : [{ value: start }, forecastZone],
333
- ...(s.lineWidth !== undefined ? { lineWidth: s.lineWidth } : {}),
334
- ...(s.valueSuffix ? { tooltip: { valueSuffix: s.valueSuffix } } : {}),
335
- ...(isColumn
336
- ? { borderWidth: 0 }
337
- : { marker: { enabled: s.showMarkers ?? false } }),
338
- ...(isArea ? { fillOpacity: s.fillOpacity ?? 0.2 } : {}),
339
- ...(projectedOnly ? forecastZone : {}),
340
- };
341
- });
342
- const paletteColors = resolveColorPaletteColors({ theme: 'default' }, entries.length);
343
- return deepMerge({
344
- ...(paletteColors ? { colors: paletteColors } : {}),
345
- chart: {
346
- ...(this.height ? { height: this.height } : {}),
347
- ...(this.zoom
348
- ? {
349
- zoomType: 'x',
350
- resetZoomButton: { theme: { display: 'none' } },
351
- events: {
352
- selection(event) {
353
- const ext = event.xAxis?.[0];
354
- if (!ext) {
355
- self.setZoomed(false);
356
- return false;
357
- }
358
- this.xAxis[0].setExtremes(ext.min, ext.max);
359
- self.setZoomed(true);
360
- self.emit('nile-chart-selection', { min: ext.min, max: ext.max });
361
- return false;
362
- },
363
- },
364
- }
365
- : {}),
366
- },
367
- ...(this.timezone ? { time: { timezone: this.timezone } } : {}),
368
- title: { text: this.chartTitle || undefined },
369
- subtitle: { text: this.chartSubtitle || undefined },
370
- legend: (() => { const { show, ...rest } = this.legend ?? {}; return { enabled: show ?? this.showLegend, ...rest }; })(),
371
- tooltip: { shared: true, crosshairs: true },
372
- xAxis,
373
- yAxis,
374
- plotOptions: {
375
- series: {
376
- cursor: 'pointer',
377
- point: {
378
- events: {
379
- click() {
380
- self.emit('nile-chart-click', {
381
- point: this,
382
- x: this.x,
383
- value: this.y,
384
- seriesName: this.series.name,
385
- forecast: this.x > start,
386
- });
387
- },
388
- },
389
- },
390
- },
391
- },
392
- series,
393
- credits: { enabled: false },
394
- }, this.options);
395
- }
396
- async initChart() {
397
- if (this.loading || !this.chartContainer || this.chart || this.initInFlight)
398
- return;
399
- this.initInFlight = true;
400
- try {
401
- if (!this._hc) {
402
- try {
403
- this._hc = await getHighcharts();
404
- }
405
- catch (err) {
406
- console.error('[nile-forecast-chart] Highcharts failed to load. Nothing rendered.', err);
407
- this.emit('nile-chart-error', { error: err });
408
- return;
409
- }
410
- }
411
- if (!this.isConnected || this.loading || !this.chartContainer)
412
- return;
413
- this.chart = this._hc.chart(this.chartContainer, this.buildOptions());
414
- this.emit('nile-chart-ready', { chart: this.chart });
415
- }
416
- finally {
417
- this.initInFlight = false;
418
- }
419
- }
420
- destroyChart() {
421
- if (this.chart) {
422
- this.chart.destroy();
423
- this.chart = null;
424
- }
425
- this.setZoomed(false);
426
- }
427
- render() {
428
- if (this.loading) {
429
- return html `<div
430
- class="chart-loading"
431
- part="loading"
432
- role="status"
433
- aria-live="polite"
434
- aria-busy="true"
435
- style="height:${this.height}"
436
- >${this.loadingText}</div>`;
437
- }
438
- return html `<div class="chart-container"></div>`;
439
- }
440
- };
441
- NileForecastChart.styles = styles;
442
- __decorate([
443
- query('.chart-container')
444
- ], NileForecastChart.prototype, "chartContainer", void 0);
445
- __decorate([
446
- property({ type: Object })
447
- ], NileForecastChart.prototype, "config", void 0);
448
- __decorate([
449
- property({ type: String, attribute: 'chart-title' })
450
- ], NileForecastChart.prototype, "chartTitle", void 0);
451
- __decorate([
452
- property({ type: String, attribute: 'chart-subtitle' })
453
- ], NileForecastChart.prototype, "chartSubtitle", void 0);
454
- __decorate([
455
- property({ type: Array })
456
- ], NileForecastChart.prototype, "data", void 0);
457
- __decorate([
458
- property({ type: Array, attribute: 'forecast-data' })
459
- ], NileForecastChart.prototype, "forecastData", void 0);
460
- __decorate([
461
- property({ type: Object })
462
- ], NileForecastChart.prototype, "options", void 0);
463
- __decorate([
464
- property({ type: Boolean, reflect: true })
465
- ], NileForecastChart.prototype, "loading", void 0);
466
- __decorate([
467
- property({ type: String })
468
- ], NileForecastChart.prototype, "height", void 0);
469
- __decorate([
470
- property({ type: Number, attribute: 'forecast-start' })
471
- ], NileForecastChart.prototype, "forecastStart", void 0);
472
- __decorate([
473
- property({ type: String, attribute: 'forecast-dash-style' })
474
- ], NileForecastChart.prototype, "forecastDashStyle", void 0);
475
- __decorate([
476
- property({ type: Boolean, attribute: 'show-now-line' })
477
- ], NileForecastChart.prototype, "showNowLine", void 0);
478
- __decorate([
479
- property({ type: String, attribute: 'now-label' })
480
- ], NileForecastChart.prototype, "nowLabel", void 0);
481
- __decorate([
482
- property({ type: String, attribute: 'now-line-color' })
483
- ], NileForecastChart.prototype, "nowLineColor", void 0);
484
- __decorate([
485
- property({ type: String, attribute: 'forecast-band-label' })
486
- ], NileForecastChart.prototype, "forecastBandLabel", void 0);
487
- __decorate([
488
- property({ type: String, attribute: 'forecast-band-color' })
489
- ], NileForecastChart.prototype, "forecastBandColor", void 0);
490
- __decorate([
491
- property({ type: String, attribute: 'x-axis-title' })
492
- ], NileForecastChart.prototype, "xAxisTitle", void 0);
493
- __decorate([
494
- property({ type: String, attribute: 'y-axis-title' })
495
- ], NileForecastChart.prototype, "yAxisTitle", void 0);
496
- __decorate([
497
- property({ type: String, attribute: 'secondary-axis-title' })
498
- ], NileForecastChart.prototype, "secondaryAxisTitle", void 0);
499
- __decorate([
500
- property({ type: Number, attribute: 'secondary-axis-min' })
501
- ], NileForecastChart.prototype, "secondaryAxisMin", void 0);
502
- __decorate([
503
- property({ type: String })
504
- ], NileForecastChart.prototype, "timezone", void 0);
505
- __decorate([
506
- property({ type: Boolean })
507
- ], NileForecastChart.prototype, "zoom", void 0);
508
- __decorate([
509
- property({ type: Boolean, attribute: 'show-legend' })
510
- ], NileForecastChart.prototype, "showLegend", void 0);
511
- __decorate([
512
- property({ type: Object })
513
- ], NileForecastChart.prototype, "legend", void 0);
514
- __decorate([
515
- property({ type: String, attribute: 'chart-bg' })
516
- ], NileForecastChart.prototype, "chartBg", void 0);
517
- __decorate([
518
- property({ type: String, attribute: 'chart-border-radius' })
519
- ], NileForecastChart.prototype, "chartBorderRadius", void 0);
520
- __decorate([
521
- property({ type: String, attribute: 'chart-border' })
522
- ], NileForecastChart.prototype, "chartBorder", void 0);
523
- __decorate([
524
- property({ type: String, attribute: 'chart-shadow' })
525
- ], NileForecastChart.prototype, "chartShadow", void 0);
526
- __decorate([
527
- property({ type: String, attribute: 'chart-padding' })
528
- ], NileForecastChart.prototype, "chartPadding", void 0);
529
- __decorate([
530
- property({ type: String, attribute: 'chart-min-height' })
531
- ], NileForecastChart.prototype, "chartMinHeight", void 0);
532
- __decorate([
533
- property({ type: String, attribute: 'loading-text' })
534
- ], NileForecastChart.prototype, "loadingText", void 0);
535
- __decorate([
536
- property({ type: String, attribute: 'loading-color' })
537
- ], NileForecastChart.prototype, "loadingColor", void 0);
538
- __decorate([
539
- property({ type: String, attribute: 'loading-font-size' })
540
- ], NileForecastChart.prototype, "loadingFontSize", void 0);
541
- __decorate([
542
- property({ type: String, attribute: 'loading-font-family' })
543
- ], NileForecastChart.prototype, "loadingFontFamily", void 0);
544
- __decorate([
545
- property({ type: String, attribute: 'loading-bg' })
546
- ], NileForecastChart.prototype, "loadingBg", void 0);
547
- NileForecastChart = __decorate([
548
- customElement('nile-forecast-chart')
549
- ], NileForecastChart);
550
- export { NileForecastChart };
551
- //# sourceMappingURL=nile-forecast-chart.js.map