@reshape-biotech/design-system 0.0.52 → 1.1.1

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 (184) hide show
  1. package/dist/components/activity/Activity.stories.svelte +21 -8
  2. package/dist/components/activity/Activity.svelte +49 -9
  3. package/dist/components/activity/Activity.svelte.d.ts +1 -1
  4. package/dist/components/avatar/Avatar.stories.svelte +7 -17
  5. package/dist/components/avatar/Avatar.svelte +2 -2
  6. package/dist/components/avatar/Avatar.svelte.d.ts +2 -2
  7. package/dist/components/banner/Banner.stories.svelte +5 -5
  8. package/dist/components/button/Button.stories.svelte +54 -21
  9. package/dist/components/button/Button.svelte +58 -11
  10. package/dist/components/button/Button.svelte.d.ts +4 -3
  11. package/dist/components/card/Card.stories.svelte +130 -0
  12. package/dist/components/card/Card.stories.svelte.d.ts +19 -0
  13. package/dist/components/card/Card.svelte +25 -0
  14. package/dist/components/card/Card.svelte.d.ts +10 -0
  15. package/dist/components/card/index.d.ts +1 -0
  16. package/dist/components/card/index.js +1 -0
  17. package/dist/components/checkbox/Checkbox.stories.svelte +22 -0
  18. package/dist/components/checkbox/Checkbox.stories.svelte.d.ts +19 -0
  19. package/dist/components/checkbox/Checkbox.svelte +24 -0
  20. package/dist/components/checkbox/Checkbox.svelte.d.ts +5 -0
  21. package/dist/components/checkbox/index.d.ts +1 -0
  22. package/dist/components/checkbox/index.js +1 -0
  23. package/dist/components/collapsible/Collapsible.stories.svelte +5 -4
  24. package/dist/components/collapsible/components/collapsible-trigger.svelte +1 -1
  25. package/dist/components/combobox/Combobox.stories.svelte +7 -5
  26. package/dist/components/combobox/components/combobox-add.svelte +2 -1
  27. package/dist/components/combobox/components/combobox-content.svelte +4 -0
  28. package/dist/components/combobox/types.d.ts +2 -0
  29. package/dist/components/datepicker/DatePicker.stories.svelte +8 -14
  30. package/dist/components/divider/Divider.stories.svelte +1 -3
  31. package/dist/components/divider/Divider.svelte +8 -2
  32. package/dist/components/divider/Divider.svelte.d.ts +2 -0
  33. package/dist/components/drawer/Drawer.stories.svelte +3 -3
  34. package/dist/components/dropdown/Dropdown.stories.svelte +8 -8
  35. package/dist/components/empty-content/EmptyContent.stories.svelte +2 -2
  36. package/dist/components/graphs/bar-chart/BarChart.stories.svelte +81 -0
  37. package/dist/components/graphs/bar-chart/BarChart.stories.svelte.d.ts +19 -0
  38. package/dist/components/graphs/bar-chart/BarChart.svelte +136 -0
  39. package/dist/components/graphs/bar-chart/BarChart.svelte.d.ts +15 -0
  40. package/dist/components/graphs/bar-chart/StackedBarChart.stories.svelte +42 -0
  41. package/dist/components/graphs/bar-chart/StackedBarChart.stories.svelte.d.ts +19 -0
  42. package/dist/components/graphs/bar-chart/StackedBarChart.svelte +177 -0
  43. package/dist/components/graphs/bar-chart/StackedBarChart.svelte.d.ts +16 -0
  44. package/dist/components/graphs/chart/Chart.stories.svelte +31 -23
  45. package/dist/components/graphs/chart/Chart.svelte +104 -32
  46. package/dist/components/graphs/chart/Chart.svelte.d.ts +15 -5
  47. package/dist/components/graphs/index.d.ts +3 -0
  48. package/dist/components/graphs/index.js +3 -0
  49. package/dist/components/graphs/line/LineChart.stories.svelte +107 -15
  50. package/dist/components/graphs/line/LineChart.svelte +90 -51
  51. package/dist/components/graphs/line/LineChart.svelte.d.ts +6 -13
  52. package/dist/components/graphs/matrix/Matrix.stories.svelte +156 -0
  53. package/dist/components/graphs/matrix/Matrix.stories.svelte.d.ts +19 -0
  54. package/dist/components/graphs/matrix/Matrix.svelte +149 -0
  55. package/dist/components/graphs/matrix/Matrix.svelte.d.ts +24 -0
  56. package/dist/components/graphs/matrix/index.d.ts +3 -0
  57. package/dist/components/graphs/matrix/index.js +3 -0
  58. package/dist/components/graphs/multiline/MultiLineChart.stories.svelte +130 -18
  59. package/dist/components/graphs/multiline/MultiLineChart.svelte +187 -50
  60. package/dist/components/graphs/multiline/MultiLineChart.svelte.d.ts +9 -12
  61. package/dist/components/graphs/scatterplot/Scatterplot.stories.svelte +68 -41
  62. package/dist/components/graphs/scatterplot/Scatterplot.svelte +312 -45
  63. package/dist/components/graphs/scatterplot/Scatterplot.svelte.d.ts +23 -13
  64. package/dist/components/graphs/utils/tooltipFormatter.d.ts +10 -0
  65. package/dist/components/graphs/utils/tooltipFormatter.js +52 -0
  66. package/dist/components/icon-button/IconButton.stories.svelte +6 -6
  67. package/dist/components/icon-button/IconButton.svelte +50 -9
  68. package/dist/components/icon-button/IconButton.svelte.d.ts +3 -5
  69. package/dist/components/icons/AnalysisIcon.stories.svelte +15 -21
  70. package/dist/components/icons/AnalysisIcon.svelte +53 -43
  71. package/dist/components/icons/Icon.stories.svelte +4 -4
  72. package/dist/components/icons/Icon.svelte +1 -1
  73. package/dist/components/icons/PrincipalIcon.svelte +96 -0
  74. package/dist/components/icons/PrincipalIcon.svelte.d.ts +10 -0
  75. package/dist/components/icons/custom/Halo.svelte +14 -8
  76. package/dist/components/icons/custom/Halo.svelte.d.ts +7 -25
  77. package/dist/components/icons/custom/Well.svelte +14 -6
  78. package/dist/components/icons/custom/Well.svelte.d.ts +7 -25
  79. package/dist/components/icons/index.d.ts +3 -2
  80. package/dist/components/icons/index.js +26 -0
  81. package/dist/components/input/Input.stories.svelte +16 -22
  82. package/dist/components/input/Input.svelte +140 -134
  83. package/dist/components/input/Input.svelte.d.ts +12 -13
  84. package/dist/components/label/Label.stories.svelte +28 -0
  85. package/dist/components/label/Label.stories.svelte.d.ts +19 -0
  86. package/dist/components/label/Label.svelte +17 -0
  87. package/dist/components/label/Label.svelte.d.ts +9 -0
  88. package/dist/components/list/List.stories.svelte +3 -3
  89. package/dist/components/logo/Logo.stories.svelte +1 -1
  90. package/dist/components/manual-cfu-counter/ManualCFUCounter.stories.svelte +125 -0
  91. package/dist/components/manual-cfu-counter/ManualCFUCounter.stories.svelte.d.ts +3 -0
  92. package/dist/components/manual-cfu-counter/ManualCFUCounter.svelte +577 -0
  93. package/dist/components/manual-cfu-counter/ManualCFUCounter.svelte.d.ts +16 -0
  94. package/dist/components/manual-cfu-counter/index.d.ts +1 -0
  95. package/dist/components/manual-cfu-counter/index.js +1 -0
  96. package/dist/components/manual-cfu-counter/test/ManualCFUCounterTestWrapper.svelte +22 -0
  97. package/dist/components/manual-cfu-counter/test/ManualCFUCounterTestWrapper.svelte.d.ts +19 -0
  98. package/dist/components/markdown/Markdown.stories.svelte +1 -1
  99. package/dist/components/markdown/Markdown.svelte +1 -1
  100. package/dist/components/modal/Modal.stories.svelte +2 -2
  101. package/dist/components/modal/Modal.svelte +27 -22
  102. package/dist/components/modal/Modal.svelte.d.ts +4 -1
  103. package/dist/components/notification-popup/NotificationPopup.stories.svelte +1 -1
  104. package/dist/components/pill/Pill.stories.svelte +13 -0
  105. package/dist/components/pill/Pill.stories.svelte.d.ts +19 -0
  106. package/dist/components/progress-circle/ProgressCircle.stories.svelte +15 -0
  107. package/dist/components/progress-circle/ProgressCircle.stories.svelte.d.ts +19 -0
  108. package/dist/components/required-status-indicator/RequiredStatusIndicator.stories.svelte +28 -0
  109. package/dist/components/required-status-indicator/RequiredStatusIndicator.stories.svelte.d.ts +19 -0
  110. package/dist/components/required-status-indicator/RequiredStatusIndicator.svelte +22 -0
  111. package/dist/components/required-status-indicator/RequiredStatusIndicator.svelte.d.ts +8 -0
  112. package/dist/components/required-status-indicator/index.d.ts +1 -0
  113. package/dist/components/required-status-indicator/index.js +1 -0
  114. package/dist/components/segmented-control-buttons/SegmentedControlButtons.stories.svelte +3 -3
  115. package/dist/components/select/Select.stories.svelte +12 -12
  116. package/dist/components/select/Select.svelte +0 -2
  117. package/dist/components/select-new/Select.stories.svelte +219 -0
  118. package/dist/components/select-new/Select.stories.svelte.d.ts +19 -0
  119. package/dist/components/select-new/components/Group.svelte +23 -0
  120. package/dist/components/select-new/components/Group.svelte.d.ts +10 -0
  121. package/dist/components/select-new/components/MultiSelectTrigger.svelte +66 -0
  122. package/dist/components/select-new/components/MultiSelectTrigger.svelte.d.ts +17 -0
  123. package/dist/components/select-new/components/SelectContent.svelte +33 -0
  124. package/dist/components/select-new/components/SelectContent.svelte.d.ts +10 -0
  125. package/dist/components/select-new/components/SelectGroupHeading.svelte +19 -0
  126. package/dist/components/select-new/components/SelectGroupHeading.svelte.d.ts +9 -0
  127. package/dist/components/select-new/components/SelectItem.svelte +41 -0
  128. package/dist/components/select-new/components/SelectItem.svelte.d.ts +9 -0
  129. package/dist/components/select-new/components/SelectTrigger.svelte +48 -0
  130. package/dist/components/select-new/components/SelectTrigger.svelte.d.ts +12 -0
  131. package/dist/components/select-new/index.d.ts +10 -0
  132. package/dist/components/select-new/index.js +12 -0
  133. package/dist/components/select-new/types.d.ts +25 -0
  134. package/dist/components/select-new/types.js +1 -0
  135. package/dist/components/sjsf-wrappers/SjsfNumberInputWrapper.svelte +92 -0
  136. package/dist/components/sjsf-wrappers/SjsfNumberInputWrapper.svelte.d.ts +3 -0
  137. package/dist/components/sjsf-wrappers/SjsfTextInputWrapper.svelte +65 -0
  138. package/dist/components/sjsf-wrappers/SjsfTextInputWrapper.svelte.d.ts +3 -0
  139. package/dist/components/sjsf-wrappers/index.d.ts +2 -0
  140. package/dist/components/sjsf-wrappers/index.js +2 -0
  141. package/dist/components/sjsf-wrappers/sjsfCustomTheme.d.ts +2 -0
  142. package/dist/components/sjsf-wrappers/sjsfCustomTheme.js +8 -0
  143. package/dist/components/skeleton-loader/SkeletonLoader.stories.svelte +4 -4
  144. package/dist/components/slider/Slider.stories.svelte +4 -4
  145. package/dist/components/spinner/Spinner.stories.svelte +13 -0
  146. package/dist/components/spinner/Spinner.stories.svelte.d.ts +19 -0
  147. package/dist/components/stat-card/StatCard.stories.svelte +27 -19
  148. package/dist/components/stat-card/StatCard.svelte +100 -6
  149. package/dist/components/stat-card/StatCard.svelte.d.ts +3 -0
  150. package/dist/components/status-badge/StatusBadge.stories.svelte +6 -6
  151. package/dist/components/status-badge/StatusBadge.svelte +5 -3
  152. package/dist/components/table/Table.stories.svelte +1 -1
  153. package/dist/components/table/components/Td.svelte +3 -2
  154. package/dist/components/table/components/Td.svelte.d.ts +1 -0
  155. package/dist/components/table/components/Tr.svelte +3 -2
  156. package/dist/components/table/components/Tr.svelte.d.ts +1 -0
  157. package/dist/components/tabs/Tabs.stories.svelte +1 -1
  158. package/dist/components/tag/Tag.stories.svelte +38 -7
  159. package/dist/components/tag/Tag.svelte +34 -21
  160. package/dist/components/tag/Tag.svelte.d.ts +1 -1
  161. package/dist/components/textarea/Textarea.stories.svelte +97 -0
  162. package/dist/components/textarea/Textarea.stories.svelte.d.ts +19 -0
  163. package/dist/components/textarea/Textarea.svelte +94 -0
  164. package/dist/components/textarea/Textarea.svelte.d.ts +17 -0
  165. package/dist/components/textarea/index.d.ts +1 -0
  166. package/dist/components/textarea/index.js +1 -0
  167. package/dist/components/toggle/Toggle.stories.svelte +1 -1
  168. package/dist/components/toggle/Toggle.svelte +3 -2
  169. package/dist/components/toggle/Toggle.svelte.d.ts +1 -0
  170. package/dist/components/toggle-icon-button/ToggleIconButton.stories.svelte +173 -0
  171. package/dist/components/toggle-icon-button/ToggleIconButton.stories.svelte.d.ts +19 -0
  172. package/dist/components/toggle-icon-button/ToggleIconButton.svelte +117 -0
  173. package/dist/components/toggle-icon-button/ToggleIconButton.svelte.d.ts +15 -0
  174. package/dist/components/toggle-icon-button/index.d.ts +3 -0
  175. package/dist/components/toggle-icon-button/index.js +3 -0
  176. package/dist/components/tooltip/Tooltip.stories.svelte +6 -6
  177. package/dist/components/tooltip/Tooltip.svelte +1 -1
  178. package/dist/index.d.ts +7 -0
  179. package/dist/index.js +7 -0
  180. package/dist/tailwind-safelist.js +2 -0
  181. package/dist/tailwind.preset.d.ts +2 -0
  182. package/dist/tokens.d.ts +4 -0
  183. package/dist/tokens.js +3 -1
  184. package/package.json +1 -2
@@ -0,0 +1,136 @@
1
+ <script lang="ts">
2
+ import { textColor, borderColor } from '../../../tokens';
3
+ import Chart, { type GenericChartProps } from '../chart/Chart.svelte';
4
+ import type { EChartsOption, BarSeriesOption } from 'echarts';
5
+ import { createTooltipFormatter } from '../utils/tooltipFormatter';
6
+
7
+ type DataItem = {
8
+ value: number;
9
+ [key: string]: string | number; // Allows other properties, like the one used for xAxisName
10
+ };
11
+
12
+ interface BarChartProps extends Omit<GenericChartProps, 'timeIndex'> {
13
+ data: DataItem[];
14
+ colors?: Record<string, string>; // Optional: Color mapping per x-axis category
15
+ rotateXAxisLabels?: boolean;
16
+ grid?: EChartsOption['grid'];
17
+ }
18
+
19
+ let {
20
+ data,
21
+ colors,
22
+ rotateXAxisLabels = false,
23
+ xAxisName,
24
+ yAxisName,
25
+ ...props
26
+ }: BarChartProps = $props();
27
+
28
+ const defaultColors: Record<string, string> = {
29
+ blue: textColor['icon-blue'],
30
+ accent: textColor['icon-accent'],
31
+ orange: textColor['icon-orange'],
32
+ sky: textColor['icon-sky'],
33
+ lilac: textColor['icon-lilac'],
34
+ plum: textColor['icon-plum'],
35
+ pear: textColor['icon-pear']
36
+ };
37
+ const defaultColorRotationArray = $derived(Object.values(defaultColors));
38
+
39
+ const xAxisData = $derived(data.map((item) => item[xAxisName]));
40
+
41
+ const createBarDataItem = (value: number | null, color: string) => ({
42
+ value,
43
+ itemStyle: {
44
+ color,
45
+ borderRadius: [2, 2, 0, 0]
46
+ },
47
+ emphasis: {
48
+ disabled: true
49
+ }
50
+ });
51
+
52
+ const chartSeries: BarSeriesOption[] = $derived.by(() => {
53
+ const seriesData = data.map((item) => item.value);
54
+ const seriesColors = data.map(
55
+ (item, index) =>
56
+ colors?.[item[xAxisName] as string] ??
57
+ defaultColorRotationArray[index % defaultColorRotationArray.length]
58
+ );
59
+
60
+ const singleSeries: BarSeriesOption[] = [
61
+ {
62
+ name: yAxisName,
63
+ type: 'bar',
64
+ data: seriesData.map((value, index) => createBarDataItem(value, seriesColors[index])),
65
+ emphasis: { disabled: true }
66
+ }
67
+ ];
68
+ return singleSeries;
69
+ });
70
+
71
+ const formatTooltip = createTooltipFormatter({
72
+ yAxisName: yAxisName,
73
+ yAxisUnit: props.yAxisUnit
74
+ });
75
+
76
+ const options: EChartsOption = $derived.by(() => {
77
+ return {
78
+ tooltip: {
79
+ trigger: 'item',
80
+ axisPointer: {
81
+ type: 'shadow'
82
+ },
83
+ borderWidth: 0,
84
+ extraCssText: 'box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); padding: 8px;',
85
+ formatter: formatTooltip
86
+ },
87
+ grid: {
88
+ containLabel: true,
89
+ left: '3%',
90
+ right: '4%',
91
+ bottom: '3%',
92
+ top: '10%',
93
+ ...props.grid
94
+ },
95
+ xAxis: {
96
+ type: 'category',
97
+ data: xAxisData,
98
+ axisTick: {
99
+ show: false,
100
+ alignWithLabel: true
101
+ },
102
+ axisLabel: {
103
+ fontSize: 12,
104
+ color: textColor['secondary'],
105
+ show: true,
106
+ ...(rotateXAxisLabels
107
+ ? { rotate: 90, overflow: 'break', width: 60, padding: [0, 40, 0, 0] }
108
+ : { rotate: 0, overflow: 'truncate', ellipsis: '...', width: 80 })
109
+ },
110
+ axisLine: {
111
+ show: false
112
+ }
113
+ },
114
+ yAxis: {
115
+ type: 'value',
116
+ axisLabel: {
117
+ fontSize: 12,
118
+ color: textColor['secondary']
119
+ },
120
+ axisLine: {
121
+ show: false
122
+ },
123
+ splitLine: {
124
+ lineStyle: {
125
+ color: borderColor['static'],
126
+ type: 'dashed'
127
+ }
128
+ }
129
+ },
130
+ series: chartSeries,
131
+ color: defaultColorRotationArray
132
+ };
133
+ });
134
+ </script>
135
+
136
+ <Chart {options} {...props} {xAxisName} {yAxisName} />
@@ -0,0 +1,15 @@
1
+ import { type GenericChartProps } from '../chart/Chart.svelte';
2
+ import type { EChartsOption } from 'echarts';
3
+ type DataItem = {
4
+ value: number;
5
+ [key: string]: string | number;
6
+ };
7
+ interface BarChartProps extends Omit<GenericChartProps, 'timeIndex'> {
8
+ data: DataItem[];
9
+ colors?: Record<string, string>;
10
+ rotateXAxisLabels?: boolean;
11
+ grid?: EChartsOption['grid'];
12
+ }
13
+ declare const BarChart: import("svelte").Component<BarChartProps, {}, "">;
14
+ type BarChart = ReturnType<typeof BarChart>;
15
+ export default BarChart;
@@ -0,0 +1,42 @@
1
+ <script lang="ts" context="module">
2
+ import { defineMeta } from '@storybook/addon-svelte-csf';
3
+ import { textColor } from '../../../tokens';
4
+ import StackedBarChart from './StackedBarChart.svelte';
5
+
6
+ const { Story } = defineMeta({
7
+ title: 'Design System/Graphs/StackedBarChart',
8
+ component: StackedBarChart,
9
+ tags: ['autodocs']
10
+ });
11
+
12
+ const stackedChartProps = {
13
+ xAxisCategories: ['ID 1', 'ID 2', 'ID 3', 'ID 4'],
14
+ series: [
15
+ { name: 'Halo', data: [120, 132, 101, 134] },
16
+ { name: 'Spot', data: [220, 182, 191, 234] },
17
+ { name: 'Microbial', data: [150, 232, 201, 154] }
18
+ ]
19
+ };
20
+
21
+ const seriesColors = {
22
+ Halo: textColor['icon-warning'],
23
+ Spot: textColor['icon-tertiary'],
24
+ Microbial: textColor['icon-lime']
25
+ };
26
+ </script>
27
+
28
+ <Story
29
+ name="Default Colors"
30
+ args={{ ...stackedChartProps, height: '400px', xAxisName: 'ID', yAxisName: 'Count' }}
31
+ />
32
+
33
+ <Story
34
+ name="Custom Colors"
35
+ args={{
36
+ ...stackedChartProps,
37
+ height: '400px',
38
+ colors: seriesColors,
39
+ xAxisName: 'ID',
40
+ yAxisName: 'Count'
41
+ }}
42
+ />
@@ -0,0 +1,19 @@
1
+ import StackedBarChart from './StackedBarChart.svelte';
2
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
+ $$bindings?: Bindings;
5
+ } & Exports;
6
+ (internal: unknown, props: {
7
+ $$events?: Events;
8
+ $$slots?: Slots;
9
+ }): Exports & {
10
+ $set?: any;
11
+ $on?: any;
12
+ };
13
+ z_$$bindings?: Bindings;
14
+ }
15
+ declare const StackedBarChart: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
16
+ [evt: string]: CustomEvent<any>;
17
+ }, {}, {}, string>;
18
+ type StackedBarChart = InstanceType<typeof StackedBarChart>;
19
+ export default StackedBarChart;
@@ -0,0 +1,177 @@
1
+ <script lang="ts">
2
+ import { textColor, borderColor } from '../../../tokens';
3
+ import Chart, { type GenericChartProps } from '../chart/Chart.svelte';
4
+ import type { EChartsOption, BarSeriesOption } from 'echarts';
5
+ import type { CallbackDataParams } from 'echarts/types/dist/shared';
6
+
7
+ type StackedSeriesItem = {
8
+ name: string;
9
+ data: (number | null)[];
10
+ };
11
+
12
+ type StackedBarChartProps = {
13
+ xAxisCategories: (string | number)[];
14
+ series: StackedSeriesItem[];
15
+ colors?: Record<string, string>; // Optional: Color mapping per series name
16
+ rotateXAxisLabels?: boolean;
17
+ grid?: EChartsOption['grid'];
18
+ } & Omit<GenericChartProps, 'timeIndex'>;
19
+
20
+ let {
21
+ xAxisCategories,
22
+ series,
23
+ colors,
24
+ rotateXAxisLabels = false,
25
+ ...props
26
+ }: StackedBarChartProps = $props();
27
+
28
+ const defaultColors: Record<string, string> = {
29
+ blue: textColor['icon-blue'],
30
+ accent: textColor['icon-accent'],
31
+ orange: textColor['icon-orange'],
32
+ sky: textColor['icon-sky'],
33
+ lilac: textColor['icon-lilac'],
34
+ plum: textColor['icon-plum'],
35
+ pear: textColor['icon-pear']
36
+ };
37
+ const defaultColorRotationArray = $derived(Object.values(defaultColors));
38
+
39
+ const xAxisData = $derived(xAxisCategories);
40
+
41
+ const createBarDataItem = (value: number | null, color: string) => ({
42
+ value,
43
+ itemStyle: {
44
+ color,
45
+ borderRadius: [2, 2, 0, 0]
46
+ },
47
+ emphasis: {
48
+ disabled: true
49
+ }
50
+ });
51
+
52
+ const chartSeries: BarSeriesOption[] = $derived.by(() => {
53
+ return series.map((seriesItem, index): BarSeriesOption => {
54
+ let seriesColor: string;
55
+ // Use provided color for the series name if available, otherwise rotate through defaults
56
+ if (colors && colors[seriesItem.name]) {
57
+ seriesColor = colors[seriesItem.name];
58
+ } else {
59
+ seriesColor = defaultColorRotationArray[index % defaultColorRotationArray.length];
60
+ }
61
+ return {
62
+ name: seriesItem.name,
63
+ type: 'bar',
64
+ stack: 'total',
65
+ emphasis: { focus: 'none', disabled: true },
66
+ data: seriesItem.data.map((val) => createBarDataItem(val, seriesColor))
67
+ };
68
+ });
69
+ });
70
+
71
+ const formatTooltip = (params: CallbackDataParams | CallbackDataParams[]): string => {
72
+ if (typeof params !== 'object' || params === null) {
73
+ return '';
74
+ }
75
+
76
+ // ECharts passes an array for axis trigger, single object for item
77
+ const paramArray = Array.isArray(params) ? params : [params];
78
+ if (paramArray.length === 0) return '';
79
+
80
+ const firstParam = paramArray[0];
81
+ const categoryName = firstParam.name;
82
+
83
+ let tooltipContent = `<div style="font-weight:bold; margin-bottom: 5px;">${categoryName}</div>`;
84
+
85
+ // Sort tooltip items by value descending for readability
86
+ paramArray.sort((a, b) => (b.value as number) - (a.value as number));
87
+
88
+ paramArray.forEach((p) => {
89
+ if (p.value == null) return;
90
+
91
+ const seriesName = p.seriesName ?? '';
92
+ const value = p.value;
93
+ let color = p.color as string | undefined;
94
+
95
+ // Attempt to find the originally assigned color for consistency
96
+ if (!color) {
97
+ if (colors && colors[seriesName]) {
98
+ color = colors[seriesName];
99
+ } else {
100
+ // Fallback: find index in original series data to get default color
101
+ const seriesIndex = series.findIndex((s) => s.name === seriesName);
102
+ if (seriesIndex !== -1) {
103
+ color = defaultColorRotationArray[seriesIndex % defaultColorRotationArray.length];
104
+ } else {
105
+ color = textColor['icon-blue']; // Use a default color as final fallback
106
+ }
107
+ }
108
+ }
109
+
110
+ const marker = `<span style="display:inline-block;margin-right:5px;border-radius:2px;width:10px;height:10px;background-color:${color};"></span>`;
111
+ tooltipContent += `<div>${marker}${seriesName}: <span style="font-weight:500;">${value}</span></div>`;
112
+ });
113
+
114
+ return tooltipContent;
115
+ };
116
+
117
+ const options: EChartsOption = $derived.by(() => {
118
+ return {
119
+ tooltip: {
120
+ trigger: 'axis', // Trigger per category for stacked charts
121
+ axisPointer: {
122
+ type: 'none'
123
+ },
124
+ borderWidth: 0,
125
+ extraCssText: 'box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); padding: 8px;',
126
+ formatter: formatTooltip
127
+ },
128
+ grid: {
129
+ containLabel: true,
130
+ left: '3%',
131
+ right: '4%',
132
+ bottom: '3%',
133
+ top: '10%',
134
+ ...props.grid
135
+ },
136
+ xAxis: {
137
+ type: 'category',
138
+ data: xAxisData,
139
+ axisTick: {
140
+ show: false,
141
+ alignWithLabel: true
142
+ },
143
+ axisLabel: {
144
+ fontSize: 12,
145
+ color: textColor['secondary'],
146
+ show: true,
147
+ ...(rotateXAxisLabels
148
+ ? { rotate: 90, overflow: 'break', width: 60, padding: [0, 40, 0, 0] }
149
+ : { rotate: 0, overflow: 'truncate', ellipsis: '...', width: 80 })
150
+ },
151
+ axisLine: {
152
+ show: false
153
+ }
154
+ },
155
+ yAxis: {
156
+ type: 'value',
157
+ axisLabel: {
158
+ fontSize: 12,
159
+ color: textColor['secondary']
160
+ },
161
+ axisLine: {
162
+ show: false
163
+ },
164
+ splitLine: {
165
+ lineStyle: {
166
+ color: borderColor['static'],
167
+ type: 'dashed'
168
+ }
169
+ }
170
+ },
171
+ series: chartSeries,
172
+ color: defaultColorRotationArray
173
+ };
174
+ });
175
+ </script>
176
+
177
+ <Chart {options} {...props} />
@@ -0,0 +1,16 @@
1
+ import { type GenericChartProps } from '../chart/Chart.svelte';
2
+ import type { EChartsOption } from 'echarts';
3
+ type StackedSeriesItem = {
4
+ name: string;
5
+ data: (number | null)[];
6
+ };
7
+ type StackedBarChartProps = {
8
+ xAxisCategories: (string | number)[];
9
+ series: StackedSeriesItem[];
10
+ colors?: Record<string, string>;
11
+ rotateXAxisLabels?: boolean;
12
+ grid?: EChartsOption['grid'];
13
+ } & Omit<GenericChartProps, 'timeIndex'>;
14
+ declare const StackedBarChart: import("svelte").Component<StackedBarChartProps, {}, "">;
15
+ type StackedBarChart = ReturnType<typeof StackedBarChart>;
16
+ export default StackedBarChart;
@@ -26,6 +26,12 @@
26
26
  ]
27
27
  };
28
28
 
29
+ const defaultProps = {
30
+ xAxisName: 'Day',
31
+ yAxisName: 'Value',
32
+ height: '400px'
33
+ };
34
+
29
35
  const lineOptions = {
30
36
  xAxis: { type: 'category' as const, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'] },
31
37
  yAxis: { type: 'value' as const },
@@ -43,38 +49,33 @@
43
49
  </script>
44
50
 
45
51
  <!-- Basic Usage -->
46
- <Story name="Default">
47
- <Chart options={baseOptions} />
48
- </Story>
52
+ <Story name="Default" args={{ options: baseOptions, ...defaultProps }} />
49
53
 
50
54
  <!-- Custom Size -->
51
- <Story name="Custom Size">
52
- <Chart options={baseOptions} width="600px" height="400px" />
53
- </Story>
55
+ <Story name="Custom Size" args={{ options: baseOptions, ...defaultProps }} />
54
56
 
55
57
  <!-- Loading State -->
56
- <Story name="Loading State">
57
- <Chart options={baseOptions} loading={true} />
58
- </Story>
58
+ <Story name="Loading State" args={{ options: baseOptions, ...defaultProps, loading: true }} />
59
59
 
60
60
  <!-- With Events -->
61
- <Story name="With Click Events">
62
- <Chart
63
- options={baseOptions}
64
- onitemclick={handleClick}
65
- onmouseover={(params) => console.log('Hover:', params)}
66
- />
67
- </Story>
61
+ <Story
62
+ name="With Click Events"
63
+ args={{
64
+ options: baseOptions,
65
+ ...defaultProps,
66
+ onitemclick: handleClick,
67
+ onmouseover: (params) => console.log('Hover:', params)
68
+ }}
69
+ />
68
70
 
69
71
  <!-- Different Chart Types -->
70
- <Story name="Line Chart">
71
- <Chart options={lineOptions} />
72
- </Story>
72
+ <Story name="Line Chart" args={{ options: lineOptions, ...defaultProps }} />
73
73
 
74
74
  <!-- Theme Example -->
75
- <Story name="Dark Theme">
75
+ <Story name="Dark Theme" asChild>
76
76
  <div style="background: #333; padding: 20px;">
77
77
  <Chart
78
+ {...defaultProps}
78
79
  options={{
79
80
  ...baseOptions,
80
81
  backgroundColor: '#333',
@@ -89,16 +90,16 @@
89
90
  </Story>
90
91
 
91
92
  <!-- Responsive Example -->
92
- <Story name="Responsive">
93
+ <Story name="Responsive" asChild>
93
94
  <div
94
95
  style="resize: both; overflow: auto; min-width: 300px; min-height: 200px; border: 1px solid #ccc;"
95
96
  >
96
- <Chart options={baseOptions} autoResize={true} />
97
+ <Chart options={baseOptions} autoResize={true} xAxisName="Day" yAxisName="Value" />
97
98
  </div>
98
99
  </Story>
99
100
 
100
101
  <!-- Multiple Series -->
101
- <Story name="Multiple Series">
102
+ <Story name="Multiple Series" asChild>
102
103
  <Chart
103
104
  options={{
104
105
  ...baseOptions,
@@ -124,5 +125,12 @@
124
125
  ],
125
126
  legend: { data: ['Series 1', 'Series 2'] }
126
127
  }}
128
+ {...defaultProps}
127
129
  />
128
130
  </Story>
131
+
132
+ <Story name="With Current Location" asChild>
133
+ <div style="height: 300px; width: 500px;">
134
+ <Chart options={baseOptions} {...defaultProps} timeIndex={2} />
135
+ </div>
136
+ </Story>