@smartnet360/svelte-components 0.0.33 → 0.0.34
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/core/Charts/ChartCard.svelte +3 -4
- package/dist/core/Charts/ChartCard.svelte.d.ts +1 -2
- package/dist/core/Charts/ChartComponent.svelte +0 -2
- package/dist/core/Charts/adapt.d.ts +1 -2
- package/dist/core/Charts/adapt.js +7 -30
- package/dist/core/Charts/charts.model.d.ts +0 -2
- package/dist/core/Charts/data-utils.js +2 -2
- package/dist/core/Charts/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
6
|
+
import type { Chart as ChartModel, ChartMarker, MovingAverageConfig } 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';
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
markers?: ChartMarker[]; // Global markers for all charts
|
|
24
24
|
plotlyLayout?: any; // Optional custom Plotly layout for styling/theming
|
|
25
25
|
enableAdaptation?: boolean; // Enable size-based adaptations (default: true)
|
|
26
|
-
configuredHoverMode?: HoverMode; // Global hover mode from layout config
|
|
27
26
|
sectionId?: string;
|
|
28
27
|
sectionMovingAverage?: MovingAverageConfig; // Section-level MA config
|
|
29
28
|
layoutMovingAverage?: MovingAverageConfig; // Layout-level MA config
|
|
@@ -33,7 +32,7 @@
|
|
|
33
32
|
runtimeShowLegend?: boolean; // Runtime control for showing legend (default: true)
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
let { chart, processedData, markers, plotlyLayout, enableAdaptation = true,
|
|
35
|
+
let { chart, processedData, markers, plotlyLayout, enableAdaptation = true, sectionId, sectionMovingAverage, layoutMovingAverage, runtimeMAOverride, runtimeShowOriginal, runtimeShowMarkers = true, runtimeShowLegend = true }: Props = $props();
|
|
37
36
|
|
|
38
37
|
// Chart container div and state
|
|
39
38
|
let chartDiv: HTMLElement;
|
|
@@ -211,7 +210,7 @@
|
|
|
211
210
|
leftSeriesCount: chart.yLeft.length,
|
|
212
211
|
rightSeriesCount: chart.yRight.length
|
|
213
212
|
},
|
|
214
|
-
{ enableAdaptation
|
|
213
|
+
{ enableAdaptation }
|
|
215
214
|
);
|
|
216
215
|
|
|
217
216
|
// Add markers to the layout only if runtime control allows
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Chart as ChartModel, ChartMarker, MovingAverageConfig
|
|
1
|
+
import type { Chart as ChartModel, ChartMarker, MovingAverageConfig } from './charts.model.js';
|
|
2
2
|
import { type ProcessedChartData } from './data-processor.js';
|
|
3
3
|
interface Props {
|
|
4
4
|
chart: ChartModel;
|
|
@@ -6,7 +6,6 @@ interface Props {
|
|
|
6
6
|
markers?: ChartMarker[];
|
|
7
7
|
plotlyLayout?: any;
|
|
8
8
|
enableAdaptation?: boolean;
|
|
9
|
-
configuredHoverMode?: HoverMode;
|
|
10
9
|
sectionId?: string;
|
|
11
10
|
sectionMovingAverage?: MovingAverageConfig;
|
|
12
11
|
layoutMovingAverage?: MovingAverageConfig;
|
|
@@ -300,7 +300,6 @@
|
|
|
300
300
|
{markers}
|
|
301
301
|
{plotlyLayout}
|
|
302
302
|
{enableAdaptation}
|
|
303
|
-
configuredHoverMode={layout.hoverMode}
|
|
304
303
|
sectionId={section.id}
|
|
305
304
|
sectionMovingAverage={section.movingAverage}
|
|
306
305
|
layoutMovingAverage={layout.movingAverage}
|
|
@@ -443,7 +442,6 @@
|
|
|
443
442
|
{markers}
|
|
444
443
|
{plotlyLayout}
|
|
445
444
|
{enableAdaptation}
|
|
446
|
-
configuredHoverMode={layout.hoverMode}
|
|
447
445
|
sectionId={activeZoom.section.id}
|
|
448
446
|
sectionMovingAverage={activeZoom.section.movingAverage}
|
|
449
447
|
layoutMovingAverage={layout.movingAverage}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Chart-specific adaptation utilities for Plotly layouts
|
|
3
3
|
* Handles size-based adaptations while preserving external styling/theming
|
|
4
4
|
*/
|
|
5
|
-
import type { ChartMarker
|
|
5
|
+
import type { ChartMarker } from './charts.model.js';
|
|
6
6
|
export interface ContainerSize {
|
|
7
7
|
width: number;
|
|
8
8
|
height: number;
|
|
@@ -13,7 +13,6 @@ export interface ChartInfo {
|
|
|
13
13
|
}
|
|
14
14
|
export interface AdaptationConfig {
|
|
15
15
|
enableAdaptation?: boolean;
|
|
16
|
-
configuredHoverMode?: HoverMode;
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
19
18
|
* Adapts a Plotly layout based on container size
|
|
@@ -5,42 +5,22 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* Adapts hover behavior based on container size and series count
|
|
7
7
|
* Optimizes tooltip display and performance for different chart sizes
|
|
8
|
-
* Respects configured hover mode, with exception for tiny charts (always 'closest' for performance)
|
|
9
8
|
*/
|
|
10
|
-
function adaptHoverBehavior(layout, containerSize, chartInfo
|
|
9
|
+
function adaptHoverBehavior(layout, containerSize, chartInfo) {
|
|
11
10
|
const { width, height } = containerSize;
|
|
12
11
|
const isTiny = width < 250 || height < 200;
|
|
13
12
|
const isSmall = width < 400 || height < 300;
|
|
14
13
|
const isMedium = width < 600 || height < 400;
|
|
15
14
|
const totalSeries = chartInfo.leftSeriesCount + chartInfo.rightSeriesCount;
|
|
16
|
-
//
|
|
15
|
+
// Priority 1: Disable hover in tiny charts (performance + UX)
|
|
17
16
|
if (isTiny) {
|
|
18
|
-
layout.hovermode = 'closest';
|
|
17
|
+
layout.hovermode = 'closest'; // Single point instead of unified
|
|
19
18
|
if (layout.hoverlabel) {
|
|
20
19
|
layout.hoverlabel.font = layout.hoverlabel.font || {};
|
|
21
20
|
layout.hoverlabel.font.size = 9; // Smaller font
|
|
22
21
|
}
|
|
23
22
|
return layout;
|
|
24
23
|
}
|
|
25
|
-
// If user configured a specific hover mode, respect it (except tiny override above)
|
|
26
|
-
if (configuredHoverMode !== undefined) {
|
|
27
|
-
layout.hovermode = configuredHoverMode;
|
|
28
|
-
// Still apply adaptive font sizing based on container size
|
|
29
|
-
if (layout.hoverlabel) {
|
|
30
|
-
layout.hoverlabel.font = layout.hoverlabel.font || {};
|
|
31
|
-
if (isSmall) {
|
|
32
|
-
layout.hoverlabel.font.size = 9;
|
|
33
|
-
}
|
|
34
|
-
else if (isMedium) {
|
|
35
|
-
layout.hoverlabel.font.size = 10;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
layout.hoverlabel.font.size = 11;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return layout;
|
|
42
|
-
}
|
|
43
|
-
// No configured mode - apply full adaptive logic (default: 'x')
|
|
44
24
|
// Priority 2: Simplify hover in small charts
|
|
45
25
|
if (isSmall) {
|
|
46
26
|
layout.hovermode = 'x'; // Single point instead of unified
|
|
@@ -52,17 +32,14 @@ function adaptHoverBehavior(layout, containerSize, chartInfo, configuredHoverMod
|
|
|
52
32
|
}
|
|
53
33
|
// Priority 3: Adaptive hover mode based on series count
|
|
54
34
|
if (totalSeries > 4 && isMedium) {
|
|
55
|
-
// Too many series in medium chart - switch to
|
|
35
|
+
// Too many series in medium chart - switch to closest
|
|
56
36
|
layout.hovermode = 'x';
|
|
57
37
|
}
|
|
58
38
|
else if (totalSeries > 8) {
|
|
59
39
|
// Very many series - even in large charts, use x
|
|
60
40
|
layout.hovermode = 'x';
|
|
61
41
|
}
|
|
62
|
-
|
|
63
|
-
// Default for large charts with reasonable series count
|
|
64
|
-
layout.hovermode = 'x';
|
|
65
|
-
}
|
|
42
|
+
// Otherwise keep default 'x unified' from base layout
|
|
66
43
|
// Priority 4: Adaptive hover label font size
|
|
67
44
|
if (layout.hoverlabel) {
|
|
68
45
|
layout.hoverlabel.font = layout.hoverlabel.font || {};
|
|
@@ -80,7 +57,7 @@ function adaptHoverBehavior(layout, containerSize, chartInfo, configuredHoverMod
|
|
|
80
57
|
* Preserves external styling while optimizing functional properties
|
|
81
58
|
*/
|
|
82
59
|
export function adaptPlotlyLayout(baseLayout, containerSize, chartInfo, config = {}) {
|
|
83
|
-
const { enableAdaptation = true
|
|
60
|
+
const { enableAdaptation = true } = config;
|
|
84
61
|
if (!enableAdaptation)
|
|
85
62
|
return baseLayout;
|
|
86
63
|
const { width, height } = containerSize;
|
|
@@ -170,7 +147,7 @@ export function adaptPlotlyLayout(baseLayout, containerSize, chartInfo, config =
|
|
|
170
147
|
}
|
|
171
148
|
}
|
|
172
149
|
// Apply adaptive hover behavior (disable in tiny, simplify in small, optimize for series count)
|
|
173
|
-
adaptHoverBehavior(adaptedLayout, containerSize, chartInfo
|
|
150
|
+
adaptHoverBehavior(adaptedLayout, containerSize, chartInfo);
|
|
174
151
|
return adaptedLayout;
|
|
175
152
|
}
|
|
176
153
|
/**
|
|
@@ -30,12 +30,10 @@ export interface Section {
|
|
|
30
30
|
movingAverage?: MovingAverageConfig;
|
|
31
31
|
}
|
|
32
32
|
export type Mode = "tabs" | "scrollspy";
|
|
33
|
-
export type HoverMode = 'x' | 'y' | 'closest' | 'x unified' | 'y unified' | false;
|
|
34
33
|
export interface Layout {
|
|
35
34
|
layoutName: string;
|
|
36
35
|
sections: Section[];
|
|
37
36
|
movingAverage?: MovingAverageConfig;
|
|
38
|
-
hoverMode?: HoverMode;
|
|
39
37
|
}
|
|
40
38
|
export interface ChartMarker {
|
|
41
39
|
date: string | Date;
|
|
@@ -90,7 +90,7 @@ export function createTimeSeriesTrace(values, timestamps, kpi, yaxis = 'y1', col
|
|
|
90
90
|
dash: yaxis === 'y1' ? 'solid' : 'dot' // Y1 = solid, Y2 = dotted
|
|
91
91
|
},
|
|
92
92
|
hovertemplate: `<b>${kpi.name}</b><br>` +
|
|
93
|
-
`Value: %{y
|
|
93
|
+
`Value: %{y:,.2f} ${kpi.unit}<br>` +
|
|
94
94
|
'<extra></extra>'
|
|
95
95
|
};
|
|
96
96
|
}
|
|
@@ -201,7 +201,7 @@ export function createDefaultPlotlyLayout(title) {
|
|
|
201
201
|
paper_bgcolor: 'rgba(0,0,0,0)',
|
|
202
202
|
plot_bgcolor: 'rgba(0,0,0,0)',
|
|
203
203
|
font: { family: 'Inter, -apple-system, BlinkMacSystemFont, sans-serif' },
|
|
204
|
-
hovermode: 'x',
|
|
204
|
+
hovermode: 'x',
|
|
205
205
|
hoverlabel: {
|
|
206
206
|
font: {
|
|
207
207
|
family: 'Inter, Segoe UI, Tahoma, Geneva, Verdana, sans-serif',
|
|
@@ -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
|
|
3
|
+
export type { Layout, Section, Chart, KPI, Mode, Scale, ChartMarker, ChartGrid, ChartPosition } 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';
|