@reshape-biotech/design-system 2.7.4 → 2.7.5
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/components/graphs/bar-chart/BarChart.svelte +21 -14
- package/dist/components/graphs/bar-chart/BarChart.svelte.d.ts +3 -0
- package/dist/components/graphs/bar-chart/StackedBarChart.svelte +71 -18
- package/dist/components/graphs/bar-chart/StackedBarChart.svelte.d.ts +9 -1
- package/package.json +1 -1
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
grid?: EChartsOption['grid'];
|
|
18
18
|
captureInterval?: number;
|
|
19
19
|
shouldDim?: (key: string) => boolean;
|
|
20
|
+
additionalSeries?: EChartsOption['series'][];
|
|
21
|
+
tooltipFormatter?: (params: any) => string;
|
|
22
|
+
yAxisOptions?: EChartsOption['yAxis'];
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
let {
|
|
@@ -27,7 +30,9 @@
|
|
|
27
30
|
yAxisName,
|
|
28
31
|
captureInterval,
|
|
29
32
|
shouldDim = () => false,
|
|
30
|
-
|
|
33
|
+
additionalSeries,
|
|
34
|
+
tooltipFormatter,
|
|
35
|
+
yAxisOptions,
|
|
31
36
|
...props
|
|
32
37
|
}: BarChartProps = $props();
|
|
33
38
|
|
|
@@ -72,24 +77,25 @@
|
|
|
72
77
|
};
|
|
73
78
|
|
|
74
79
|
const chartSeries: BarSeriesOption[] = $derived.by(() => {
|
|
75
|
-
const seriesData = data.map((item) => item.value);
|
|
76
80
|
const seriesColors = data.map(
|
|
77
81
|
(item, index) =>
|
|
78
82
|
colors?.[item[xAxisName!] as string] ??
|
|
79
83
|
defaultColorRotationArray[index % defaultColorRotationArray.length]
|
|
80
84
|
);
|
|
81
85
|
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
];
|
|
92
|
-
|
|
86
|
+
const primarySeries: BarSeriesOption = {
|
|
87
|
+
name: yAxisName,
|
|
88
|
+
type: 'bar',
|
|
89
|
+
data: data.map((item, index) =>
|
|
90
|
+
createBarDataItem(item.value, seriesColors[index], String(item[xAxisName!]))
|
|
91
|
+
),
|
|
92
|
+
emphasis: { disabled: true },
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
if (!additionalSeries) return [primarySeries];
|
|
96
|
+
|
|
97
|
+
const flattened = additionalSeries.flat().filter((s): s is BarSeriesOption => !!s);
|
|
98
|
+
return [primarySeries, ...flattened];
|
|
93
99
|
});
|
|
94
100
|
|
|
95
101
|
const formatTooltip = createTooltipFormatter({
|
|
@@ -110,7 +116,7 @@
|
|
|
110
116
|
borderWidth: 0,
|
|
111
117
|
borderRadius: 6,
|
|
112
118
|
extraCssText: `box-shadow: ${boxShadow.menu}`,
|
|
113
|
-
formatter: formatTooltip,
|
|
119
|
+
formatter: tooltipFormatter || formatTooltip,
|
|
114
120
|
},
|
|
115
121
|
grid: {
|
|
116
122
|
containLabel: true,
|
|
@@ -155,6 +161,7 @@
|
|
|
155
161
|
type: 'dashed',
|
|
156
162
|
},
|
|
157
163
|
},
|
|
164
|
+
...(yAxisOptions || {}),
|
|
158
165
|
},
|
|
159
166
|
textStyle: {
|
|
160
167
|
color: textColor['secondary'],
|
|
@@ -11,6 +11,9 @@ interface BarChartProps extends Omit<GenericChartProps, 'timeIndex'> {
|
|
|
11
11
|
grid?: EChartsOption['grid'];
|
|
12
12
|
captureInterval?: number;
|
|
13
13
|
shouldDim?: (key: string) => boolean;
|
|
14
|
+
additionalSeries?: EChartsOption['series'][];
|
|
15
|
+
tooltipFormatter?: (params: any) => string;
|
|
16
|
+
yAxisOptions?: EChartsOption['yAxis'];
|
|
14
17
|
}
|
|
15
18
|
declare const BarChart: import("svelte").Component<BarChartProps, {}, "">;
|
|
16
19
|
type BarChart = ReturnType<typeof BarChart>;
|
|
@@ -4,19 +4,23 @@
|
|
|
4
4
|
import type { EChartsOption, BarSeriesOption, CallbackDataParams } from '../../../echarts-config';
|
|
5
5
|
import { formattedDurationCompact } from '../utils/duration';
|
|
6
6
|
|
|
7
|
+
type StackedData = number | null | { value: number | null; itemStyle?: any; emphasis?: any };
|
|
7
8
|
type StackedSeriesItem = {
|
|
8
9
|
name: string;
|
|
9
|
-
data:
|
|
10
|
+
data: StackedData[];
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
interface StackedBarChartProps extends GenericChartProps {
|
|
13
14
|
xAxisCategories: (string | number)[];
|
|
14
15
|
series: StackedSeriesItem[];
|
|
15
|
-
colors?: Record<string, string>;
|
|
16
|
+
colors?: Record<string, string>;
|
|
16
17
|
rotateXAxisLabels?: boolean;
|
|
17
18
|
grid?: EChartsOption['grid'];
|
|
18
19
|
captureInterval?: number;
|
|
19
20
|
shouldDim?: (key: string) => boolean;
|
|
21
|
+
additionalSeries?: EChartsOption['series'][];
|
|
22
|
+
tooltipFormatter?: (params: any) => string;
|
|
23
|
+
yAxisOptions?: EChartsOption['yAxis'];
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
let {
|
|
@@ -26,6 +30,9 @@
|
|
|
26
30
|
rotateXAxisLabels = false,
|
|
27
31
|
captureInterval,
|
|
28
32
|
shouldDim = () => false,
|
|
33
|
+
additionalSeries,
|
|
34
|
+
tooltipFormatter,
|
|
35
|
+
yAxisOptions,
|
|
29
36
|
...props
|
|
30
37
|
}: StackedBarChartProps = $props();
|
|
31
38
|
|
|
@@ -56,24 +63,41 @@
|
|
|
56
63
|
})
|
|
57
64
|
: undefined;
|
|
58
65
|
|
|
59
|
-
const createBarDataItem = (value:
|
|
60
|
-
value
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
const createBarDataItem = (value: StackedData, color: string, key: string) => {
|
|
67
|
+
if (value && typeof value === 'object' && 'value' in value) {
|
|
68
|
+
const existing = value as any;
|
|
69
|
+
const mergedItemStyle = {
|
|
70
|
+
borderRadius: 2,
|
|
71
|
+
borderWidth: 0.5,
|
|
72
|
+
borderColor: borderColor['white'],
|
|
73
|
+
opacity: shouldDim(key) ? 0.3 : 1,
|
|
74
|
+
color,
|
|
75
|
+
...(existing.itemStyle || {}),
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
...existing,
|
|
79
|
+
itemStyle: mergedItemStyle,
|
|
80
|
+
emphasis: { disabled: true, ...(existing.emphasis || {}) },
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
value: value as number | null,
|
|
85
|
+
itemStyle: {
|
|
86
|
+
color,
|
|
87
|
+
borderRadius: 2,
|
|
88
|
+
borderWidth: 0.5,
|
|
89
|
+
borderColor: borderColor['white'],
|
|
90
|
+
opacity: shouldDim(key) ? 0.3 : 1,
|
|
91
|
+
},
|
|
92
|
+
emphasis: {
|
|
93
|
+
disabled: true,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
};
|
|
72
97
|
|
|
73
98
|
const chartSeries: BarSeriesOption[] = $derived.by(() => {
|
|
74
|
-
|
|
99
|
+
const base = series.map((seriesItem, index): BarSeriesOption => {
|
|
75
100
|
let seriesColor: string;
|
|
76
|
-
// Use provided color for the series name if available, otherwise rotate through defaults
|
|
77
101
|
if (colors && colors[seriesItem.name]) {
|
|
78
102
|
seriesColor = colors[seriesItem.name];
|
|
79
103
|
} else {
|
|
@@ -87,6 +111,34 @@
|
|
|
87
111
|
data: seriesItem.data.map((val) => createBarDataItem(val, seriesColor, seriesItem.name)),
|
|
88
112
|
};
|
|
89
113
|
});
|
|
114
|
+
if (!additionalSeries) return base;
|
|
115
|
+
|
|
116
|
+
const flattened = additionalSeries.flat().filter((s): s is BarSeriesOption => !!s);
|
|
117
|
+
|
|
118
|
+
const primaryStack = base[0]?.stack || 'total';
|
|
119
|
+
|
|
120
|
+
const adjusted = flattened.map((s) => {
|
|
121
|
+
if (s.type === 'bar') {
|
|
122
|
+
const anyData =
|
|
123
|
+
Array.isArray(s.data) && s.data.some((d) => !!d && (d as any).value != null);
|
|
124
|
+
if (!anyData) {
|
|
125
|
+
return {
|
|
126
|
+
stack: primaryStack,
|
|
127
|
+
barGap: '-100%',
|
|
128
|
+
silent: true,
|
|
129
|
+
...s,
|
|
130
|
+
} as BarSeriesOption;
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
stack: primaryStack,
|
|
134
|
+
barGap: '-100%',
|
|
135
|
+
...s,
|
|
136
|
+
} as BarSeriesOption;
|
|
137
|
+
}
|
|
138
|
+
return s;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
return [...base, ...adjusted];
|
|
90
142
|
});
|
|
91
143
|
|
|
92
144
|
const formatTooltip = (params: CallbackDataParams | CallbackDataParams[]): string => {
|
|
@@ -148,7 +200,7 @@
|
|
|
148
200
|
extraCssText: `box-shadow: ${boxShadow.menu}`,
|
|
149
201
|
borderWidth: 0,
|
|
150
202
|
borderRadius: 6,
|
|
151
|
-
formatter: formatTooltip,
|
|
203
|
+
formatter: tooltipFormatter || formatTooltip,
|
|
152
204
|
},
|
|
153
205
|
grid: {
|
|
154
206
|
containLabel: true,
|
|
@@ -193,6 +245,7 @@
|
|
|
193
245
|
type: 'dashed',
|
|
194
246
|
},
|
|
195
247
|
},
|
|
248
|
+
...(yAxisOptions || {}),
|
|
196
249
|
},
|
|
197
250
|
textStyle: {
|
|
198
251
|
color: textColor['secondary'],
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { type GenericChartProps } from '../chart/Chart.svelte';
|
|
2
2
|
import type { EChartsOption } from '../../../echarts-config';
|
|
3
|
+
type StackedData = number | null | {
|
|
4
|
+
value: number | null;
|
|
5
|
+
itemStyle?: any;
|
|
6
|
+
emphasis?: any;
|
|
7
|
+
};
|
|
3
8
|
type StackedSeriesItem = {
|
|
4
9
|
name: string;
|
|
5
|
-
data:
|
|
10
|
+
data: StackedData[];
|
|
6
11
|
};
|
|
7
12
|
interface StackedBarChartProps extends GenericChartProps {
|
|
8
13
|
xAxisCategories: (string | number)[];
|
|
@@ -12,6 +17,9 @@ interface StackedBarChartProps extends GenericChartProps {
|
|
|
12
17
|
grid?: EChartsOption['grid'];
|
|
13
18
|
captureInterval?: number;
|
|
14
19
|
shouldDim?: (key: string) => boolean;
|
|
20
|
+
additionalSeries?: EChartsOption['series'][];
|
|
21
|
+
tooltipFormatter?: (params: any) => string;
|
|
22
|
+
yAxisOptions?: EChartsOption['yAxis'];
|
|
15
23
|
}
|
|
16
24
|
declare const StackedBarChart: import("svelte").Component<StackedBarChartProps, {}, "">;
|
|
17
25
|
type StackedBarChart = ReturnType<typeof StackedBarChart>;
|