@smartnet360/svelte-components 0.0.37 → 0.0.38
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/dist/apps/site-check/SiteCheck.svelte +7 -6
- package/dist/apps/site-check/SiteCheck.svelte.d.ts +2 -1
- package/dist/apps/site-check/default-cell-styling.d.ts +6 -0
- package/dist/apps/site-check/default-cell-styling.js +24 -0
- package/dist/apps/site-check/default-cell-styling.json +20 -0
- package/dist/apps/site-check/helper.d.ts +3 -2
- package/dist/apps/site-check/helper.js +13 -13
- package/dist/apps/site-check/index.d.ts +2 -1
- package/dist/apps/site-check/index.js +4 -2
- package/dist/apps/site-check/transforms.d.ts +13 -0
- package/dist/apps/site-check/transforms.js +40 -0
- package/dist/core/Charts/ChartCard.svelte +7 -5
- package/dist/core/Charts/ChartCard.svelte.d.ts +3 -1
- package/dist/core/Charts/ChartComponent.svelte +3 -1
- package/dist/core/Charts/adapt.js +19 -27
- package/dist/core/Charts/charts.model.d.ts +9 -0
- package/dist/core/Charts/data-utils.d.ts +4 -4
- package/dist/core/Charts/data-utils.js +40 -8
- package/dist/core/Charts/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
<script lang="ts">
|
|
4
4
|
import { TreeView, createTreeStore } from '../../core/TreeView';
|
|
5
|
-
import { ChartComponent, type Layout } from '../../core/Charts';
|
|
6
|
-
import { buildTreeNodes, filterChartData, transformChartData, type CellTrafficRecord } from './index';
|
|
5
|
+
import { ChartComponent, type Layout, type CellStylingConfig } from '../../core/Charts';
|
|
6
|
+
import { buildTreeNodes, filterChartData, transformChartData, type CellTrafficRecord, defaultCellStyling } from './index';
|
|
7
7
|
import { expandLayoutForCells } from './helper';
|
|
8
8
|
import { log } from '../../core/logger';
|
|
9
9
|
import { onMount } from 'svelte';
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
baseLayout: Layout;
|
|
15
15
|
baseMetrics: string[];
|
|
16
16
|
mode: Mode;
|
|
17
|
+
cellStyling?: CellStylingConfig; // Optional cell styling config (defaults to defaultCellStyling)
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
let { rawData, baseLayout, baseMetrics, mode = "scrollspy" }: Props = $props();
|
|
20
|
+
let { rawData, baseLayout, baseMetrics, mode = "scrollspy", cellStyling = defaultCellStyling }: Props = $props();
|
|
20
21
|
|
|
21
22
|
let treeStore = $state<ReturnType<typeof createTreeStore> | null>(null);
|
|
22
23
|
|
|
@@ -74,12 +75,12 @@
|
|
|
74
75
|
|
|
75
76
|
// Expand layout based on selected cells
|
|
76
77
|
let chartLayout = $derived.by(() => {
|
|
77
|
-
const expanded = expandLayoutForCells(baseLayout, filteredData);
|
|
78
|
+
const expanded = expandLayoutForCells(baseLayout, filteredData, cellStyling);
|
|
78
79
|
log('📐 Chart Layout:', {
|
|
79
|
-
grid: expanded.grid,
|
|
80
80
|
sectionsCount: expanded.sections.length,
|
|
81
81
|
totalCharts: expanded.sections.reduce((sum, s) => sum + s.charts.length, 0),
|
|
82
|
-
firstSection: expanded.sections[0]
|
|
82
|
+
firstSection: expanded.sections[0],
|
|
83
|
+
cellStylingEnabled: !!cellStyling
|
|
83
84
|
});
|
|
84
85
|
return expanded;
|
|
85
86
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Layout } from '../../core/Charts';
|
|
1
|
+
import { type Layout, type CellStylingConfig } from '../../core/Charts';
|
|
2
2
|
import { type CellTrafficRecord } from './index';
|
|
3
3
|
import type { Mode } from '../../index.js';
|
|
4
4
|
interface Props {
|
|
@@ -6,6 +6,7 @@ interface Props {
|
|
|
6
6
|
baseLayout: Layout;
|
|
7
7
|
baseMetrics: string[];
|
|
8
8
|
mode: Mode;
|
|
9
|
+
cellStyling?: CellStylingConfig;
|
|
9
10
|
}
|
|
10
11
|
declare const SiteCheck: import("svelte").Component<Props, {}, "">;
|
|
11
12
|
type SiteCheck = ReturnType<typeof SiteCheck>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default cell styling configuration for SiteCheck component
|
|
3
|
+
* Provides band colors and sector line styles for network cells
|
|
4
|
+
*/
|
|
5
|
+
export const defaultCellStyling = {
|
|
6
|
+
bandColors: {
|
|
7
|
+
"LTE700": "#DC2626",
|
|
8
|
+
"LTE800": "#EA580C",
|
|
9
|
+
"LTE900": "#D97706",
|
|
10
|
+
"LTE1800": "#2563EB",
|
|
11
|
+
"LTE2100": "#7C3AED",
|
|
12
|
+
"LTE2600": "#DB2777",
|
|
13
|
+
"NR700": "#B91C1C",
|
|
14
|
+
"NR2100": "#059669",
|
|
15
|
+
"NR3500": "#0891B2",
|
|
16
|
+
"NR26000": "#BE185D"
|
|
17
|
+
},
|
|
18
|
+
sectorLineStyles: {
|
|
19
|
+
"1": "solid",
|
|
20
|
+
"2": "dash",
|
|
21
|
+
"3": "dot",
|
|
22
|
+
"4": "dashdot"
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bandColors": {
|
|
3
|
+
"LTE700": "#DC2626",
|
|
4
|
+
"LTE800": "#EA580C",
|
|
5
|
+
"LTE900": "#D97706",
|
|
6
|
+
"LTE1800": "#2563EB",
|
|
7
|
+
"LTE2100": "#7C3AED",
|
|
8
|
+
"LTE2600": "#DB2777",
|
|
9
|
+
"NR700": "#B91C1C",
|
|
10
|
+
"NR2100": "#059669",
|
|
11
|
+
"NR3500": "#0891B2",
|
|
12
|
+
"NR26000": "#BE185D"
|
|
13
|
+
},
|
|
14
|
+
"sectorLineStyles": {
|
|
15
|
+
"1": "solid",
|
|
16
|
+
"2": "dash",
|
|
17
|
+
"3": "dot",
|
|
18
|
+
"4": "dashdot"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Layout } from '../../core/Charts';
|
|
1
|
+
import type { Layout, CellStylingConfig } from '../../core/Charts';
|
|
2
2
|
import type { CellTrafficRecord } from './';
|
|
3
3
|
/**
|
|
4
4
|
* Expand base layout configuration with dynamic KPIs based on selected cells
|
|
@@ -6,9 +6,10 @@ import type { CellTrafficRecord } from './';
|
|
|
6
6
|
*
|
|
7
7
|
* @param baseLayout - The base layout configuration from JSON
|
|
8
8
|
* @param data - Filtered cell traffic records for selected cells
|
|
9
|
+
* @param stylingConfig - Optional cell styling configuration (band colors, sector line styles)
|
|
9
10
|
* @returns Expanded layout with cell-specific KPIs
|
|
10
11
|
*/
|
|
11
|
-
export declare function expandLayoutForCells(baseLayout: Layout, data: CellTrafficRecord[]): Layout;
|
|
12
|
+
export declare function expandLayoutForCells(baseLayout: Layout, data: CellTrafficRecord[], stylingConfig?: CellStylingConfig): Layout;
|
|
12
13
|
/**
|
|
13
14
|
* Extract base metric names from a layout configuration
|
|
14
15
|
* Returns unique metric rawNames that need to be pivoted
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { createStyledKPI } from './transforms.js';
|
|
1
2
|
/**
|
|
2
3
|
* Expand base layout configuration with dynamic KPIs based on selected cells
|
|
3
4
|
* Takes a base layout (with one KPI per metric) and expands it to include one KPI per cell
|
|
4
5
|
*
|
|
5
6
|
* @param baseLayout - The base layout configuration from JSON
|
|
6
7
|
* @param data - Filtered cell traffic records for selected cells
|
|
8
|
+
* @param stylingConfig - Optional cell styling configuration (band colors, sector line styles)
|
|
7
9
|
* @returns Expanded layout with cell-specific KPIs
|
|
8
10
|
*/
|
|
9
|
-
export function expandLayoutForCells(baseLayout, data) {
|
|
11
|
+
export function expandLayoutForCells(baseLayout, data, stylingConfig) {
|
|
10
12
|
// Get unique cells and their metadata
|
|
11
13
|
const cellMap = new Map();
|
|
12
14
|
data.forEach((record) => {
|
|
@@ -22,8 +24,8 @@ export function expandLayoutForCells(baseLayout, data) {
|
|
|
22
24
|
...section,
|
|
23
25
|
charts: section.charts.map((chart) => ({
|
|
24
26
|
...chart,
|
|
25
|
-
yLeft: expandKPIs(chart.yLeft, cells),
|
|
26
|
-
yRight: expandKPIs(chart.yRight, cells)
|
|
27
|
+
yLeft: expandKPIs(chart.yLeft, cells, stylingConfig),
|
|
28
|
+
yRight: expandKPIs(chart.yRight, cells, stylingConfig)
|
|
27
29
|
}))
|
|
28
30
|
}))
|
|
29
31
|
};
|
|
@@ -31,22 +33,20 @@ export function expandLayoutForCells(baseLayout, data) {
|
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* Expand a single KPI into multiple KPIs (one per cell)
|
|
36
|
+
* Now uses createStyledKPI to apply band colors and sector line styles
|
|
34
37
|
*
|
|
35
38
|
* @param baseKPIs - Array of base KPIs from layout
|
|
36
39
|
* @param cells - Array of [cellName, record] tuples
|
|
37
|
-
* @
|
|
40
|
+
* @param stylingConfig - Optional cell styling configuration
|
|
41
|
+
* @returns Expanded array of KPIs with cell-specific styling
|
|
38
42
|
*/
|
|
39
|
-
function expandKPIs(baseKPIs, cells) {
|
|
43
|
+
function expandKPIs(baseKPIs, cells, stylingConfig) {
|
|
40
44
|
const expandedKPIs = [];
|
|
41
45
|
baseKPIs.forEach((baseKPI) => {
|
|
42
|
-
cells.forEach(([cellName, record]
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
scale: baseKPI.scale,
|
|
47
|
-
unit: baseKPI.unit,
|
|
48
|
-
color: getColorForIndex(index)
|
|
49
|
-
});
|
|
46
|
+
cells.forEach(([cellName, record]) => {
|
|
47
|
+
// Use createStyledKPI to apply band color and sector line style
|
|
48
|
+
const styledKPI = createStyledKPI(baseKPI.rawName, record, baseKPI.unit, stylingConfig);
|
|
49
|
+
expandedKPIs.push(styledKPI);
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
52
|
return expandedKPIs;
|
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { default as SiteCheck } from './SiteCheck.svelte';
|
|
6
6
|
export { loadCellTrafficData, getUniqueSites, getUniqueCells, groupDataByCell, type CellTrafficRecord } from './data-loader.js';
|
|
7
|
-
export { buildTreeNodes, filterChartData, transformChartData } from './transforms.js';
|
|
7
|
+
export { buildTreeNodes, filterChartData, transformChartData, createStyledKPI } from './transforms.js';
|
|
8
8
|
export { expandLayoutForCells, extractBaseMetrics } from './helper.js';
|
|
9
|
+
export { defaultCellStyling } from './default-cell-styling.js';
|
|
@@ -7,6 +7,8 @@ export { default as SiteCheck } from './SiteCheck.svelte';
|
|
|
7
7
|
// Data loading
|
|
8
8
|
export { loadCellTrafficData, getUniqueSites, getUniqueCells, groupDataByCell } from './data-loader.js';
|
|
9
9
|
// Data transforms
|
|
10
|
-
export { buildTreeNodes, filterChartData, transformChartData } from './transforms.js';
|
|
11
|
-
// Helper
|
|
10
|
+
export { buildTreeNodes, filterChartData, transformChartData, createStyledKPI } from './transforms.js';
|
|
11
|
+
// Helper functions
|
|
12
12
|
export { expandLayoutForCells, extractBaseMetrics } from './helper.js';
|
|
13
|
+
// Default cell styling configuration
|
|
14
|
+
export { defaultCellStyling } from './default-cell-styling.js';
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Converts raw CSV data to TreeView nodes and Chart configurations
|
|
4
4
|
*/
|
|
5
5
|
import type { TreeNode } from '../../core/TreeView';
|
|
6
|
+
import type { KPI, CellStylingConfig } from '../../core/Charts';
|
|
6
7
|
import type { CellTrafficRecord } from './data-loader';
|
|
7
8
|
/**
|
|
8
9
|
* Build hierarchical tree structure: Site → Sector (Azimuth) → Cell (Band)
|
|
@@ -22,3 +23,15 @@ export declare function filterChartData(data: CellTrafficRecord[], checkedPaths:
|
|
|
22
23
|
* @param baseMetrics - Array of metric names to pivot (e.g., ['dlGBytes', 'ulGBytes'])
|
|
23
24
|
*/
|
|
24
25
|
export declare function transformChartData(data: CellTrafficRecord[], baseMetrics: string[]): any[];
|
|
26
|
+
/**
|
|
27
|
+
* Apply cell styling based on band and sector
|
|
28
|
+
* Modifies KPI objects to include color (from band) and lineStyle (from sector)
|
|
29
|
+
* Updates KPI name to format: Band_Azimuth°
|
|
30
|
+
*
|
|
31
|
+
* @param metricName - Base metric name (e.g., 'dlGBytes')
|
|
32
|
+
* @param cellRecord - Cell traffic record with band, sector, azimuth metadata
|
|
33
|
+
* @param unit - Unit string for the metric
|
|
34
|
+
* @param stylingConfig - Optional cell styling configuration (band colors, sector line styles)
|
|
35
|
+
* @returns Styled KPI object
|
|
36
|
+
*/
|
|
37
|
+
export declare function createStyledKPI(metricName: string, cellRecord: CellTrafficRecord, unit: string, stylingConfig?: CellStylingConfig): KPI;
|
|
@@ -173,3 +173,43 @@ export function transformChartData(data, baseMetrics) {
|
|
|
173
173
|
});
|
|
174
174
|
return pivotedData;
|
|
175
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Apply cell styling based on band and sector
|
|
178
|
+
* Modifies KPI objects to include color (from band) and lineStyle (from sector)
|
|
179
|
+
* Updates KPI name to format: Band_Azimuth°
|
|
180
|
+
*
|
|
181
|
+
* @param metricName - Base metric name (e.g., 'dlGBytes')
|
|
182
|
+
* @param cellRecord - Cell traffic record with band, sector, azimuth metadata
|
|
183
|
+
* @param unit - Unit string for the metric
|
|
184
|
+
* @param stylingConfig - Optional cell styling configuration (band colors, sector line styles)
|
|
185
|
+
* @returns Styled KPI object
|
|
186
|
+
*/
|
|
187
|
+
export function createStyledKPI(metricName, cellRecord, unit, stylingConfig) {
|
|
188
|
+
const { band, sector, azimuth, cellName } = cellRecord;
|
|
189
|
+
// Get color from band (if config provided)
|
|
190
|
+
const color = stylingConfig?.bandColors?.[band];
|
|
191
|
+
// Get line style from sector (if config provided)
|
|
192
|
+
const lineStyle = stylingConfig?.sectorLineStyles?.[sector.toString()];
|
|
193
|
+
// Format name as: Band_Azimuth°
|
|
194
|
+
const displayName = `${band}_${azimuth}°`;
|
|
195
|
+
// Build KPI with cell-specific styling
|
|
196
|
+
const kpi = {
|
|
197
|
+
rawName: `${metricName}_${cellName}`, // Column name in pivoted data
|
|
198
|
+
name: displayName,
|
|
199
|
+
scale: 'absolute',
|
|
200
|
+
unit,
|
|
201
|
+
...(color && { color }),
|
|
202
|
+
...(lineStyle && { lineStyle })
|
|
203
|
+
};
|
|
204
|
+
log('🎨 Styled KPI created', {
|
|
205
|
+
metricName,
|
|
206
|
+
cellName,
|
|
207
|
+
displayName,
|
|
208
|
+
band,
|
|
209
|
+
sector,
|
|
210
|
+
azimuth,
|
|
211
|
+
color,
|
|
212
|
+
lineStyle
|
|
213
|
+
});
|
|
214
|
+
return kpi;
|
|
215
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<script lang="ts">
|
|
4
4
|
import { onMount, createEventDispatcher } from 'svelte';
|
|
5
5
|
import Plotly from 'plotly.js-dist-min';
|
|
6
|
-
import type { Chart as ChartModel, ChartMarker, MovingAverageConfig } from './charts.model.js';
|
|
6
|
+
import type { Chart as ChartModel, ChartMarker, MovingAverageConfig, HoverMode } from './charts.model.js';
|
|
7
7
|
import { createTimeSeriesTraceWithMA, getYAxisTitle, createDefaultPlotlyLayout } from './data-utils.js';
|
|
8
8
|
import { adaptPlotlyLayout, addMarkersToLayout, type ContainerSize } from './adapt.js';
|
|
9
9
|
import { getKPIValues, type ProcessedChartData } from './data-processor.js';
|
|
@@ -27,13 +27,15 @@
|
|
|
27
27
|
sectionId?: string;
|
|
28
28
|
sectionMovingAverage?: MovingAverageConfig; // Section-level MA config
|
|
29
29
|
layoutMovingAverage?: MovingAverageConfig; // Layout-level MA config
|
|
30
|
+
layoutHoverMode?: HoverMode; // Layout-level hover mode config
|
|
31
|
+
layoutColoredHover?: boolean; // Layout-level colored hover config (default: true)
|
|
30
32
|
runtimeMAOverride?: MovingAverageConfig | null; // Runtime override from global controls
|
|
31
33
|
runtimeShowOriginal?: boolean; // Runtime control for showing original lines
|
|
32
34
|
runtimeShowMarkers?: boolean; // Runtime control for showing markers (default: true)
|
|
33
35
|
runtimeShowLegend?: boolean; // Runtime control for showing legend (default: true)
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
let { chart, processedData, markers, plotlyLayout, enableAdaptation = true, sectionId, sectionMovingAverage, layoutMovingAverage, runtimeMAOverride, runtimeShowOriginal, runtimeShowMarkers = true, runtimeShowLegend = true }: Props = $props();
|
|
38
|
+
let { chart, processedData, markers, plotlyLayout, enableAdaptation = true, sectionId, sectionMovingAverage, layoutMovingAverage, layoutHoverMode, layoutColoredHover = true, runtimeMAOverride, runtimeShowOriginal, runtimeShowMarkers = true, runtimeShowLegend = true }: Props = $props();
|
|
37
39
|
|
|
38
40
|
// Chart container div and state
|
|
39
41
|
let chartDiv: HTMLElement;
|
|
@@ -162,7 +164,7 @@
|
|
|
162
164
|
// Add left Y-axis traces (with moving average support)
|
|
163
165
|
resolvedKPIs.left.forEach(kpi => {
|
|
164
166
|
const values = getKPIValues(processedData, kpi);
|
|
165
|
-
const kpiTraces = createTimeSeriesTraceWithMA(values, timestamps, kpi, 'y1', colorIndex, chartType, stackGroup);
|
|
167
|
+
const kpiTraces = createTimeSeriesTraceWithMA(values, timestamps, kpi, 'y1', colorIndex, chartType, stackGroup, layoutColoredHover);
|
|
166
168
|
traces.push(...kpiTraces);
|
|
167
169
|
colorIndex++;
|
|
168
170
|
});
|
|
@@ -170,13 +172,13 @@
|
|
|
170
172
|
// Add right Y-axis traces (with moving average support)
|
|
171
173
|
resolvedKPIs.right.forEach(kpi => {
|
|
172
174
|
const values = getKPIValues(processedData, kpi);
|
|
173
|
-
const kpiTraces = createTimeSeriesTraceWithMA(values, timestamps, kpi, 'y2', colorIndex, chartType, stackGroup);
|
|
175
|
+
const kpiTraces = createTimeSeriesTraceWithMA(values, timestamps, kpi, 'y2', colorIndex, chartType, stackGroup, layoutColoredHover);
|
|
174
176
|
traces.push(...kpiTraces);
|
|
175
177
|
colorIndex++;
|
|
176
178
|
});
|
|
177
179
|
|
|
178
180
|
// Create default modern layout using the centralized function
|
|
179
|
-
const defaultLayout: any = createDefaultPlotlyLayout(chart.title);
|
|
181
|
+
const defaultLayout: any = createDefaultPlotlyLayout(chart.title, layoutHoverMode);
|
|
180
182
|
|
|
181
183
|
// Override specific properties for this chart
|
|
182
184
|
defaultLayout.yaxis.title = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Chart as ChartModel, ChartMarker, MovingAverageConfig } from './charts.model.js';
|
|
1
|
+
import type { Chart as ChartModel, ChartMarker, MovingAverageConfig, HoverMode } from './charts.model.js';
|
|
2
2
|
import { type ProcessedChartData } from './data-processor.js';
|
|
3
3
|
interface Props {
|
|
4
4
|
chart: ChartModel;
|
|
@@ -9,6 +9,8 @@ interface Props {
|
|
|
9
9
|
sectionId?: string;
|
|
10
10
|
sectionMovingAverage?: MovingAverageConfig;
|
|
11
11
|
layoutMovingAverage?: MovingAverageConfig;
|
|
12
|
+
layoutHoverMode?: HoverMode;
|
|
13
|
+
layoutColoredHover?: boolean;
|
|
12
14
|
runtimeMAOverride?: MovingAverageConfig | null;
|
|
13
15
|
runtimeShowOriginal?: boolean;
|
|
14
16
|
runtimeShowMarkers?: boolean;
|
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
sections: layout.sections.length,
|
|
65
65
|
totalCharts: layout.sections.reduce((sum, s) => sum + s.charts.length, 0),
|
|
66
66
|
enableAdaptation,
|
|
67
|
-
showGlobalControls
|
|
67
|
+
showGlobalControls,
|
|
68
|
+
layoutHoverMode: layout.hoverMode
|
|
68
69
|
});
|
|
69
70
|
});
|
|
70
71
|
|
|
@@ -327,6 +328,7 @@
|
|
|
327
328
|
sectionId={section.id}
|
|
328
329
|
sectionMovingAverage={section.movingAverage}
|
|
329
330
|
layoutMovingAverage={layout.movingAverage}
|
|
331
|
+
layoutHoverMode={layout.hoverMode}
|
|
330
332
|
runtimeMAOverride={effectiveMAOverride}
|
|
331
333
|
runtimeShowOriginal={globalControls.movingAverage?.showOriginal}
|
|
332
334
|
runtimeShowMarkers={globalControls.markers?.enabled}
|
|
@@ -4,46 +4,36 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Adapts hover behavior based on container size and series count
|
|
7
|
-
*
|
|
7
|
+
* Preserves user's configured hover mode unless adaptation is critical for performance/UX
|
|
8
8
|
*/
|
|
9
|
-
function adaptHoverBehavior(layout, containerSize, chartInfo) {
|
|
9
|
+
function adaptHoverBehavior(layout, containerSize, chartInfo, originalHoverMode) {
|
|
10
10
|
const { width, height } = containerSize;
|
|
11
11
|
const isTiny = width < 250 || height < 200;
|
|
12
12
|
const isSmall = width < 400 || height < 300;
|
|
13
13
|
const isMedium = width < 600 || height < 400;
|
|
14
14
|
const totalSeries = chartInfo.leftSeriesCount + chartInfo.rightSeriesCount;
|
|
15
|
-
//
|
|
16
|
-
if (isTiny) {
|
|
17
|
-
layout.hovermode = 'closest'; // Single point instead of unified
|
|
18
|
-
if (layout.hoverlabel) {
|
|
19
|
-
layout.hoverlabel.font = layout.hoverlabel.font || {};
|
|
20
|
-
layout.hoverlabel.font.size = 9; // Smaller font
|
|
21
|
-
}
|
|
22
|
-
return layout;
|
|
23
|
-
}
|
|
24
|
-
// Priority 2: Simplify hover in small charts
|
|
15
|
+
// Only override hover mode in critical cases for performance/UX
|
|
25
16
|
if (isSmall) {
|
|
26
|
-
|
|
17
|
+
// Force 'closest' in small charts for performance and readability
|
|
18
|
+
layout.hovermode = 'closest';
|
|
27
19
|
if (layout.hoverlabel) {
|
|
28
20
|
layout.hoverlabel.font = layout.hoverlabel.font || {};
|
|
29
|
-
layout.hoverlabel.font.size = 9;
|
|
21
|
+
layout.hoverlabel.font.size = 9;
|
|
30
22
|
}
|
|
31
23
|
return layout;
|
|
32
24
|
}
|
|
33
|
-
//
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
layout.hovermode = 'x';
|
|
37
|
-
}
|
|
38
|
-
else if (totalSeries > 8) {
|
|
39
|
-
// Very many series - even in large charts, use x
|
|
40
|
-
layout.hovermode = 'x';
|
|
25
|
+
// For all other sizes, preserve the user's configured hover mode
|
|
26
|
+
if (originalHoverMode !== undefined) {
|
|
27
|
+
layout.hovermode = originalHoverMode;
|
|
41
28
|
}
|
|
42
|
-
//
|
|
43
|
-
//
|
|
29
|
+
// If no original hover mode provided, keep whatever is in the layout
|
|
30
|
+
// Only adapt font sizes, not hover behavior for non-tiny charts
|
|
44
31
|
if (layout.hoverlabel) {
|
|
45
32
|
layout.hoverlabel.font = layout.hoverlabel.font || {};
|
|
46
|
-
if (
|
|
33
|
+
if (isSmall) {
|
|
34
|
+
layout.hoverlabel.font.size = 9;
|
|
35
|
+
}
|
|
36
|
+
else if (isMedium) {
|
|
47
37
|
layout.hoverlabel.font.size = 10;
|
|
48
38
|
}
|
|
49
39
|
else {
|
|
@@ -62,6 +52,8 @@ export function adaptPlotlyLayout(baseLayout, containerSize, chartInfo, config =
|
|
|
62
52
|
return baseLayout;
|
|
63
53
|
const { width, height } = containerSize;
|
|
64
54
|
const adaptedLayout = { ...baseLayout };
|
|
55
|
+
// Preserve the original hover mode before any adaptations
|
|
56
|
+
const originalHoverMode = baseLayout.hovermode;
|
|
65
57
|
// Size categories for adaptation rules
|
|
66
58
|
const isTiny = width < 250 || height < 200;
|
|
67
59
|
const isSmall = width < 400 || height < 300;
|
|
@@ -146,8 +138,8 @@ export function adaptPlotlyLayout(baseLayout, containerSize, chartInfo, config =
|
|
|
146
138
|
adaptedLayout.legend.font.size = 11;
|
|
147
139
|
}
|
|
148
140
|
}
|
|
149
|
-
// Apply adaptive hover behavior (
|
|
150
|
-
adaptHoverBehavior(adaptedLayout, containerSize, chartInfo);
|
|
141
|
+
// Apply adaptive hover behavior (preserve user config except in tiny charts)
|
|
142
|
+
adaptHoverBehavior(adaptedLayout, containerSize, chartInfo, originalHoverMode);
|
|
151
143
|
return adaptedLayout;
|
|
152
144
|
}
|
|
153
145
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type Scale = "percent" | "absolute";
|
|
2
|
+
export type LineStyle = 'solid' | 'dash' | 'dot' | 'dashdot' | 'longdash' | 'longdashdot';
|
|
2
3
|
export interface MovingAverageConfig {
|
|
3
4
|
enabled: boolean;
|
|
4
5
|
window: number;
|
|
@@ -11,6 +12,7 @@ export interface KPI {
|
|
|
11
12
|
scale: Scale;
|
|
12
13
|
unit: string;
|
|
13
14
|
color?: string;
|
|
15
|
+
lineStyle?: LineStyle;
|
|
14
16
|
movingAverage?: MovingAverageConfig;
|
|
15
17
|
}
|
|
16
18
|
export type ChartPosition = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
@@ -33,10 +35,13 @@ export interface Section {
|
|
|
33
35
|
movingAverage?: MovingAverageConfig;
|
|
34
36
|
}
|
|
35
37
|
export type Mode = "tabs" | "scrollspy";
|
|
38
|
+
export type HoverMode = 'x' | 'y' | 'closest' | 'x unified' | 'y unified' | false;
|
|
36
39
|
export interface Layout {
|
|
37
40
|
layoutName: string;
|
|
38
41
|
sections: Section[];
|
|
39
42
|
movingAverage?: MovingAverageConfig;
|
|
43
|
+
hoverMode?: HoverMode;
|
|
44
|
+
coloredHover?: boolean;
|
|
40
45
|
}
|
|
41
46
|
export interface ChartMarker {
|
|
42
47
|
date: string | Date;
|
|
@@ -59,3 +64,7 @@ export interface GlobalChartControls {
|
|
|
59
64
|
enabled: boolean;
|
|
60
65
|
};
|
|
61
66
|
}
|
|
67
|
+
export interface CellStylingConfig {
|
|
68
|
+
bandColors: Record<string, string>;
|
|
69
|
+
sectorLineStyles: Record<string, LineStyle>;
|
|
70
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { KPI } from './charts.model.js';
|
|
1
|
+
import type { KPI, HoverMode } from './charts.model.js';
|
|
2
2
|
export declare function processKPIData(data: any[], kpi: KPI): number[];
|
|
3
3
|
export declare function calculateMovingAverage(values: number[], window: number): number[];
|
|
4
|
-
export declare function createTimeSeriesTrace(values: number[], timestamps: any[], kpi: KPI, yaxis?: 'y1' | 'y2', colorIndex?: number, chartType?: string, stackGroup?: string): any;
|
|
4
|
+
export declare function createTimeSeriesTrace(values: number[], timestamps: any[], kpi: KPI, yaxis?: 'y1' | 'y2', colorIndex?: number, chartType?: string, stackGroup?: string, coloredHover?: boolean): any;
|
|
5
5
|
/**
|
|
6
6
|
* Create time series trace(s) with optional moving average
|
|
7
7
|
* @param values - Pre-processed numeric values array for the KPI
|
|
@@ -13,7 +13,7 @@ export declare function createTimeSeriesTrace(values: number[], timestamps: any[
|
|
|
13
13
|
* @param stackGroup - Optional stack group identifier
|
|
14
14
|
* @returns Array of traces (original + MA if configured)
|
|
15
15
|
*/
|
|
16
|
-
export declare function createTimeSeriesTraceWithMA(values: number[], timestamps: any[], kpi: KPI, yaxis?: 'y1' | 'y2', colorIndex?: number, chartType?: string, stackGroup?: string): any[];
|
|
16
|
+
export declare function createTimeSeriesTraceWithMA(values: number[], timestamps: any[], kpi: KPI, yaxis?: 'y1' | 'y2', colorIndex?: number, chartType?: string, stackGroup?: string, coloredHover?: boolean): any[];
|
|
17
17
|
export declare function getYAxisTitle(kpis: KPI[]): string;
|
|
18
18
|
export declare function formatValue(value: number, scale: 'percent' | 'absolute', unit: string): string;
|
|
19
|
-
export declare function createDefaultPlotlyLayout(title?: string): any;
|
|
19
|
+
export declare function createDefaultPlotlyLayout(title?: string, hoverMode?: HoverMode, coloredHover?: boolean): any;
|
|
@@ -72,7 +72,7 @@ export function calculateMovingAverage(values, window) {
|
|
|
72
72
|
maCache.set(cacheKey, result);
|
|
73
73
|
return result;
|
|
74
74
|
}
|
|
75
|
-
export function createTimeSeriesTrace(values, timestamps, kpi, yaxis = 'y1', colorIndex = 0, chartType = 'line', stackGroup) {
|
|
75
|
+
export function createTimeSeriesTrace(values, timestamps, kpi, yaxis = 'y1', colorIndex = 0, chartType = 'line', stackGroup, coloredHover = true) {
|
|
76
76
|
// Use KPI color if provided, otherwise cycle through modern colors
|
|
77
77
|
const traceColor = kpi.color || modernColors[colorIndex % modernColors.length];
|
|
78
78
|
// Base trace configuration
|
|
@@ -85,6 +85,18 @@ export function createTimeSeriesTrace(values, timestamps, kpi, yaxis = 'y1', col
|
|
|
85
85
|
`Value: %{y:,.2f} ${kpi.unit}<br>` +
|
|
86
86
|
'<extra></extra>'
|
|
87
87
|
};
|
|
88
|
+
// Add colored hover styling if enabled
|
|
89
|
+
if (coloredHover) {
|
|
90
|
+
baseTrace.hoverlabel = {
|
|
91
|
+
bgcolor: traceColor,
|
|
92
|
+
bordercolor: traceColor,
|
|
93
|
+
font: {
|
|
94
|
+
color: '#ffffff', // White text for better contrast
|
|
95
|
+
family: 'Inter, Segoe UI, Tahoma, Geneva, Verdana, sans-serif',
|
|
96
|
+
size: 11
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
88
100
|
// Configure based on chart type
|
|
89
101
|
switch (chartType) {
|
|
90
102
|
case 'stacked-area':
|
|
@@ -138,7 +150,7 @@ export function createTimeSeriesTrace(values, timestamps, kpi, yaxis = 'y1', col
|
|
|
138
150
|
width: 3,
|
|
139
151
|
shape: 'spline',
|
|
140
152
|
smoothing: 0.3,
|
|
141
|
-
dash: yaxis === 'y1' ? 'solid' : 'dot'
|
|
153
|
+
dash: kpi.lineStyle || (yaxis === 'y1' ? 'solid' : 'dot')
|
|
142
154
|
}
|
|
143
155
|
};
|
|
144
156
|
}
|
|
@@ -154,12 +166,12 @@ export function createTimeSeriesTrace(values, timestamps, kpi, yaxis = 'y1', col
|
|
|
154
166
|
* @param stackGroup - Optional stack group identifier
|
|
155
167
|
* @returns Array of traces (original + MA if configured)
|
|
156
168
|
*/
|
|
157
|
-
export function createTimeSeriesTraceWithMA(values, timestamps, kpi, yaxis = 'y1', colorIndex = 0, chartType = 'line', stackGroup) {
|
|
169
|
+
export function createTimeSeriesTraceWithMA(values, timestamps, kpi, yaxis = 'y1', colorIndex = 0, chartType = 'line', stackGroup, coloredHover = true) {
|
|
158
170
|
const traces = [];
|
|
159
171
|
const traceColor = kpi.color || modernColors[colorIndex % modernColors.length];
|
|
160
172
|
// Add original trace (unless explicitly disabled)
|
|
161
173
|
if (!kpi.movingAverage || kpi.movingAverage.showOriginal !== false) {
|
|
162
|
-
const originalTrace = createTimeSeriesTrace(values, timestamps, kpi, yaxis, colorIndex, chartType, stackGroup);
|
|
174
|
+
const originalTrace = createTimeSeriesTrace(values, timestamps, kpi, yaxis, colorIndex, chartType, stackGroup, coloredHover);
|
|
163
175
|
// If MA is enabled, make the original line slightly transparent
|
|
164
176
|
if (kpi.movingAverage?.enabled) {
|
|
165
177
|
originalTrace.opacity = 0.4;
|
|
@@ -190,7 +202,18 @@ export function createTimeSeriesTraceWithMA(values, timestamps, kpi, yaxis = 'y1
|
|
|
190
202
|
},
|
|
191
203
|
hovertemplate: `<b>${maLabel}</b><br>` +
|
|
192
204
|
`Value: %{y:,.2f} ${kpi.unit}<br>` +
|
|
193
|
-
'<extra></extra>'
|
|
205
|
+
'<extra></extra>',
|
|
206
|
+
...(coloredHover && {
|
|
207
|
+
hoverlabel: {
|
|
208
|
+
bgcolor: traceColor,
|
|
209
|
+
bordercolor: traceColor,
|
|
210
|
+
font: {
|
|
211
|
+
color: '#ffffff',
|
|
212
|
+
family: 'Inter, Segoe UI, Tahoma, Geneva, Verdana, sans-serif',
|
|
213
|
+
size: 11
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
})
|
|
194
217
|
};
|
|
195
218
|
traces.push(maTrace);
|
|
196
219
|
}
|
|
@@ -209,7 +232,7 @@ export function formatValue(value, scale, unit) {
|
|
|
209
232
|
}
|
|
210
233
|
return `${value.toLocaleString()}${unit}`;
|
|
211
234
|
}
|
|
212
|
-
export function createDefaultPlotlyLayout(title) {
|
|
235
|
+
export function createDefaultPlotlyLayout(title, hoverMode, coloredHover = true) {
|
|
213
236
|
return {
|
|
214
237
|
title: title ? {
|
|
215
238
|
text: title,
|
|
@@ -254,8 +277,17 @@ export function createDefaultPlotlyLayout(title) {
|
|
|
254
277
|
paper_bgcolor: 'rgba(0,0,0,0)',
|
|
255
278
|
plot_bgcolor: 'rgba(0,0,0,0)',
|
|
256
279
|
font: { family: 'Inter, -apple-system, BlinkMacSystemFont, sans-serif' },
|
|
257
|
-
hovermode: 'x',
|
|
258
|
-
hoverlabel: {
|
|
280
|
+
hovermode: hoverMode !== undefined ? hoverMode : 'x',
|
|
281
|
+
hoverlabel: coloredHover ? {
|
|
282
|
+
// When coloredHover is enabled, let each trace control its own hover colors
|
|
283
|
+
font: {
|
|
284
|
+
family: 'Inter, Segoe UI, Tahoma, Geneva, Verdana, sans-serif',
|
|
285
|
+
size: 11
|
|
286
|
+
// color will be set per trace when coloredHover is true
|
|
287
|
+
}
|
|
288
|
+
// bgcolor and bordercolor will be set per trace when coloredHover is true
|
|
289
|
+
} : {
|
|
290
|
+
// Default hover styling when coloredHover is disabled
|
|
259
291
|
font: {
|
|
260
292
|
family: 'Inter, Segoe UI, Tahoma, Geneva, Verdana, sans-serif',
|
|
261
293
|
size: 11,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default as ChartComponent } from './ChartComponent.svelte';
|
|
2
2
|
export { default as ChartCard } from './ChartCard.svelte';
|
|
3
|
-
export type { Layout, Section, Chart, KPI, Mode, Scale, ChartMarker, ChartGrid, ChartPosition } from './charts.model.js';
|
|
3
|
+
export type { Layout, Section, Chart, KPI, Mode, Scale, ChartMarker, ChartGrid, ChartPosition, HoverMode, LineStyle, CellStylingConfig } from './charts.model.js';
|
|
4
4
|
export { createTimeSeriesTrace, getYAxisTitle, formatValue, processKPIData, createDefaultPlotlyLayout } from './data-utils.js';
|
|
5
5
|
export { adaptPlotlyLayout, getSizeCategory, createMarkerShapes, createMarkerAnnotations, addMarkersToLayout } from './adapt.js';
|
|
6
6
|
export type { ContainerSize, ChartInfo, AdaptationConfig } from './adapt.js';
|