@makolabs/ripple 0.0.1 → 0.0.4
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/README.md +575 -8
- package/dist/adapters/storage/BaseAdapter.d.ts +20 -0
- package/dist/adapters/storage/BaseAdapter.js +171 -0
- package/dist/adapters/storage/S3Adapter.d.ts +21 -0
- package/dist/adapters/storage/S3Adapter.js +194 -0
- package/dist/adapters/storage/index.d.ts +3 -0
- package/dist/adapters/storage/index.js +3 -0
- package/dist/adapters/storage/types.d.ts +102 -0
- package/dist/adapters/storage/types.js +4 -0
- package/dist/button/Button.svelte +48 -0
- package/dist/button/Button.svelte.d.ts +4 -0
- package/dist/button/button.d.ts +113 -0
- package/dist/button/button.js +168 -0
- package/dist/charts/Chart.svelte +545 -0
- package/dist/charts/Chart.svelte.d.ts +4 -0
- package/dist/drawer/Drawer.svelte +224 -0
- package/dist/drawer/Drawer.svelte.d.ts +4 -0
- package/dist/drawer/drawer.d.ts +160 -0
- package/dist/drawer/drawer.js +80 -0
- package/dist/elements/accordion/Accordion.svelte +98 -0
- package/dist/elements/accordion/Accordion.svelte.d.ts +4 -0
- package/dist/elements/accordion/accordion.d.ts +227 -0
- package/dist/elements/accordion/accordion.js +138 -0
- package/dist/elements/alert/Alert.svelte +57 -0
- package/dist/elements/alert/Alert.svelte.d.ts +4 -0
- package/dist/elements/badge/Badge.svelte +43 -0
- package/dist/elements/badge/Badge.svelte.d.ts +4 -0
- package/dist/elements/badge/badge.d.ts +181 -0
- package/dist/elements/badge/badge.js +65 -0
- package/dist/elements/dropdown/Dropdown.svelte +234 -0
- package/dist/elements/dropdown/Dropdown.svelte.d.ts +4 -0
- package/dist/elements/dropdown/Select.svelte +333 -0
- package/dist/elements/dropdown/Select.svelte.d.ts +4 -0
- package/dist/elements/dropdown/dropdown.d.ts +251 -0
- package/dist/elements/dropdown/dropdown.js +95 -0
- package/dist/elements/dropdown/select.d.ts +200 -0
- package/dist/elements/dropdown/select.js +82 -0
- package/dist/elements/file-upload/FileUpload.svelte +135 -0
- package/dist/elements/file-upload/FileUpload.svelte.d.ts +4 -0
- package/dist/elements/file-upload/FilesPreview.svelte +93 -0
- package/dist/elements/file-upload/FilesPreview.svelte.d.ts +4 -0
- package/dist/elements/progress/Progress.svelte +145 -0
- package/dist/elements/progress/Progress.svelte.d.ts +4 -0
- package/dist/elements/timeline/Timeline.svelte +92 -0
- package/dist/elements/timeline/Timeline.svelte.d.ts +7 -0
- package/dist/file-browser/FileBrowser.svelte +877 -0
- package/dist/file-browser/FileBrowser.svelte.d.ts +14 -0
- package/dist/file-browser/index.d.ts +1 -0
- package/dist/file-browser/index.js +1 -0
- package/dist/filters/CompactFilters.svelte +147 -0
- package/dist/filters/CompactFilters.svelte.d.ts +4 -0
- package/dist/filters/index.d.ts +1 -0
- package/dist/filters/index.js +1 -0
- package/dist/forms/Checkbox.svelte +54 -0
- package/dist/forms/Checkbox.svelte.d.ts +4 -0
- package/dist/forms/DateRange.svelte +493 -0
- package/dist/forms/DateRange.svelte.d.ts +4 -0
- package/dist/forms/Form.svelte +39 -0
- package/dist/forms/Form.svelte.d.ts +4 -0
- package/dist/forms/Input.svelte +86 -0
- package/dist/forms/Input.svelte.d.ts +4 -0
- package/dist/forms/NumberInput.svelte +159 -0
- package/dist/forms/NumberInput.svelte.d.ts +4 -0
- package/dist/forms/RadioInputs.svelte +64 -0
- package/dist/forms/RadioInputs.svelte.d.ts +4 -0
- package/dist/forms/RadioPill.svelte +66 -0
- package/dist/forms/RadioPill.svelte.d.ts +4 -0
- package/dist/forms/Slider.svelte +342 -0
- package/dist/forms/Slider.svelte.d.ts +4 -0
- package/dist/forms/Tags.svelte +181 -0
- package/dist/forms/Tags.svelte.d.ts +4 -0
- package/dist/forms/Toggle.svelte +132 -0
- package/dist/forms/Toggle.svelte.d.ts +4 -0
- package/dist/forms/slider.d.ts +143 -0
- package/dist/forms/slider.js +62 -0
- package/dist/header/Breadcrumbs.svelte +73 -0
- package/dist/header/Breadcrumbs.svelte.d.ts +4 -0
- package/dist/header/PageHeader.svelte +68 -0
- package/dist/header/PageHeader.svelte.d.ts +4 -0
- package/dist/header/breadcrumbs.d.ts +226 -0
- package/dist/header/breadcrumbs.js +87 -0
- package/dist/helper/cls.d.ts +1 -0
- package/dist/helper/cls.js +4 -0
- package/dist/helper/date.d.ts +7 -0
- package/dist/helper/date.js +15 -0
- package/dist/helper/nav.svelte.d.ts +6 -0
- package/dist/helper/nav.svelte.js +23 -0
- package/dist/index.d.ts +856 -1
- package/dist/index.js +78 -1
- package/dist/layout/card/Card.svelte +41 -0
- package/dist/layout/card/Card.svelte.d.ts +4 -0
- package/dist/layout/card/MetricCard.svelte +64 -0
- package/dist/layout/card/MetricCard.svelte.d.ts +4 -0
- package/dist/layout/card/StatsCard.svelte +266 -0
- package/dist/layout/card/StatsCard.svelte.d.ts +4 -0
- package/dist/layout/card/card.d.ts +128 -0
- package/dist/layout/card/card.js +51 -0
- package/dist/layout/card/metric-card.d.ts +49 -0
- package/dist/layout/card/metric-card.js +10 -0
- package/dist/layout/card/stats-card.d.ts +191 -0
- package/dist/layout/card/stats-card.js +73 -0
- package/dist/layout/navbar/Navbar.svelte +206 -0
- package/dist/layout/navbar/Navbar.svelte.d.ts +4 -0
- package/dist/layout/navbar/navbar.d.ts +205 -0
- package/dist/layout/navbar/navbar.js +98 -0
- package/dist/layout/sidebar/NavGroup.svelte +91 -0
- package/dist/layout/sidebar/NavGroup.svelte.d.ts +4 -0
- package/dist/layout/sidebar/NavItem.svelte +29 -0
- package/dist/layout/sidebar/NavItem.svelte.d.ts +4 -0
- package/dist/layout/sidebar/Sidebar.svelte +193 -0
- package/dist/layout/sidebar/Sidebar.svelte.d.ts +4 -0
- package/dist/layout/table/Cells.svelte +111 -0
- package/dist/layout/table/Cells.svelte.d.ts +27 -0
- package/dist/layout/table/Table.svelte +790 -0
- package/dist/layout/table/Table.svelte.d.ts +4 -0
- package/dist/layout/table/table.d.ts +256 -0
- package/dist/layout/table/table.js +141 -0
- package/dist/layout/tabs/Tab.svelte +60 -0
- package/dist/layout/tabs/Tab.svelte.d.ts +4 -0
- package/dist/layout/tabs/TabContent.svelte +30 -0
- package/dist/layout/tabs/TabContent.svelte.d.ts +4 -0
- package/dist/layout/tabs/TabGroup.svelte +62 -0
- package/dist/layout/tabs/TabGroup.svelte.d.ts +4 -0
- package/dist/layout/tabs/tabs.d.ts +140 -0
- package/dist/layout/tabs/tabs.js +298 -0
- package/dist/modal/Modal.svelte +207 -0
- package/dist/modal/Modal.svelte.d.ts +4 -0
- package/dist/modal/modal.d.ts +211 -0
- package/dist/modal/modal.js +81 -0
- package/dist/sonner/sonner.svelte +13 -0
- package/dist/sonner/sonner.svelte.d.ts +4 -0
- package/dist/types/variants.d.ts +1 -0
- package/dist/types/variants.js +1 -0
- package/dist/utils/Portal.svelte +108 -0
- package/dist/utils/Portal.svelte.d.ts +8 -0
- package/dist/utils/dateUtils.d.ts +7 -0
- package/dist/utils/dateUtils.js +26 -0
- package/dist/variants.d.ts +30 -0
- package/dist/variants.js +36 -0
- package/package.json +39 -6
- package/dist/layout/Card.svelte +0 -179
- package/dist/layout/Card.svelte.d.ts +0 -208
- package/dist/layout/index.d.ts +0 -1
- package/dist/layout/index.js +0 -1
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { tv } from 'tailwind-variants';
|
|
2
|
+
import { Color, Size } from '../variants.js';
|
|
3
|
+
export const buttonVariants = tv({
|
|
4
|
+
base: `
|
|
5
|
+
inline-flex items-center justify-center font-medium transition-colors focus-visible:outline-none
|
|
6
|
+
focus-visible:ring-2 focus-visible:ring-offset-2 cursor-pointer
|
|
7
|
+
`,
|
|
8
|
+
variants: {
|
|
9
|
+
variant: {
|
|
10
|
+
solid: '',
|
|
11
|
+
outline: 'border bg-transparent',
|
|
12
|
+
ghost: 'bg-transparent hover:bg-opacity-10',
|
|
13
|
+
link: 'bg-transparent underline-offset-4 hover:underline shadow-none'
|
|
14
|
+
},
|
|
15
|
+
color: {
|
|
16
|
+
[Color.DEFAULT]: 'bg-default-900 text-white hover:bg-default-800 focus-visible:ring-default-500',
|
|
17
|
+
[Color.PRIMARY]: 'bg-primary-600 text-white hover:bg-primary-700 focus-visible:ring-primary-500',
|
|
18
|
+
[Color.SECONDARY]: 'bg-secondary-600 text-white hover:bg-secondary-700 focus-visible:ring-secondary-500',
|
|
19
|
+
[Color.INFO]: 'bg-info-600 text-white hover:bg-info-700 focus-visible:ring-info-500',
|
|
20
|
+
[Color.SUCCESS]: 'bg-success-600 text-white hover:bg-success-700 focus-visible:ring-success-500',
|
|
21
|
+
[Color.WARNING]: 'bg-warning-600 text-white hover:bg-warning-700 focus-visible:ring-warning-500',
|
|
22
|
+
[Color.DANGER]: 'bg-danger-600 text-white hover:bg-danger-700 focus-visible:ring-danger-500'
|
|
23
|
+
},
|
|
24
|
+
size: {
|
|
25
|
+
[Size.XS]: 'h-7 px-2 text-xs',
|
|
26
|
+
[Size.SM]: 'h-8 px-3 text-sm',
|
|
27
|
+
[Size.BASE]: 'h-9 px-4 text-sm',
|
|
28
|
+
[Size.LG]: 'h-10 px-5 text-base',
|
|
29
|
+
[Size.XL]: 'h-12 px-6 text-lg',
|
|
30
|
+
[Size.XXL]: 'h-14 px-8 text-xl'
|
|
31
|
+
},
|
|
32
|
+
rounded: {
|
|
33
|
+
none: 'rounded-none',
|
|
34
|
+
xs: 'rounded-xs',
|
|
35
|
+
sm: 'rounded-sm',
|
|
36
|
+
base: 'rounded-md',
|
|
37
|
+
lg: 'rounded-lg',
|
|
38
|
+
xl: 'rounded-xl',
|
|
39
|
+
'2xl': 'rounded-2xl',
|
|
40
|
+
full: 'rounded-full'
|
|
41
|
+
},
|
|
42
|
+
isLoading: {
|
|
43
|
+
true: 'animate-pulse'
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
compoundVariants: [
|
|
47
|
+
// Remove background for non-solid variants
|
|
48
|
+
{
|
|
49
|
+
variant: ['outline', 'ghost', 'link'],
|
|
50
|
+
class: 'bg-transparent hover:bg-transparent'
|
|
51
|
+
},
|
|
52
|
+
// Outline variants
|
|
53
|
+
{
|
|
54
|
+
variant: 'outline',
|
|
55
|
+
color: 'default',
|
|
56
|
+
class: 'border-default-200 text-default-700 hover:bg-default-50 hover:border-default-300 focus-visible:ring-default-300'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
variant: 'outline',
|
|
60
|
+
color: 'primary',
|
|
61
|
+
class: 'border-primary-200 text-primary-700 hover:bg-primary-50 hover:border-primary-300 focus-visible:ring-primary-300'
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
variant: 'outline',
|
|
65
|
+
color: 'secondary',
|
|
66
|
+
class: 'border-secondary-200 text-secondary-700 hover:bg-secondary-50 hover:border-secondary-300 focus-visible:ring-secondary-300'
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
variant: 'outline',
|
|
70
|
+
color: 'info',
|
|
71
|
+
class: 'border-info-200 text-info-700 hover:bg-info-50 hover:border-info-300 focus-visible:ring-info-300'
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
variant: 'outline',
|
|
75
|
+
color: 'success',
|
|
76
|
+
class: 'border-success-200 text-success-700 hover:bg-success-50 hover:border-success-300 focus-visible:ring-success-300'
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
variant: 'outline',
|
|
80
|
+
color: 'warning',
|
|
81
|
+
class: 'border-warning-200 text-warning-700 hover:bg-warning-50 hover:border-warning-300 focus-visible:ring-warning-300'
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
variant: 'outline',
|
|
85
|
+
color: 'danger',
|
|
86
|
+
class: 'border-danger-200 text-danger-700 hover:bg-danger-50 hover:border-danger-300 focus-visible:ring-danger-300'
|
|
87
|
+
},
|
|
88
|
+
// Ghost variants
|
|
89
|
+
{
|
|
90
|
+
variant: 'ghost',
|
|
91
|
+
color: 'default',
|
|
92
|
+
class: 'text-default-700 hover:bg-default-100 focus-visible:ring-default-300'
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
variant: 'ghost',
|
|
96
|
+
color: 'primary',
|
|
97
|
+
class: 'text-primary-700 hover:bg-primary-100 focus-visible:ring-primary-300'
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
variant: 'ghost',
|
|
101
|
+
color: 'secondary',
|
|
102
|
+
class: 'text-secondary-700 hover:bg-secondary-100 focus-visible:ring-secondary-300'
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
variant: 'ghost',
|
|
106
|
+
color: 'info',
|
|
107
|
+
class: 'text-info-700 hover:bg-info-100 focus-visible:ring-info-300'
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
variant: 'ghost',
|
|
111
|
+
color: 'success',
|
|
112
|
+
class: 'text-success-700 hover:bg-success-100 focus-visible:ring-success-300'
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
variant: 'ghost',
|
|
116
|
+
color: 'warning',
|
|
117
|
+
class: 'text-warning-700 hover:bg-warning-100 focus-visible:ring-warning-300'
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
variant: 'ghost',
|
|
121
|
+
color: 'danger',
|
|
122
|
+
class: 'text-danger-700 hover:bg-danger-100 focus-visible:ring-danger-300'
|
|
123
|
+
},
|
|
124
|
+
// Link variants
|
|
125
|
+
{
|
|
126
|
+
variant: 'link',
|
|
127
|
+
color: 'default',
|
|
128
|
+
class: 'text-default-700 hover:text-default-800 focus-visible:ring-default-300'
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
variant: 'link',
|
|
132
|
+
color: 'primary',
|
|
133
|
+
class: 'text-primary-700 hover:text-primary-800 focus-visible:ring-primary-300'
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
variant: 'link',
|
|
137
|
+
color: 'secondary',
|
|
138
|
+
class: 'text-secondary-700 hover:text-secondary-800 focus-visible:ring-secondary-300'
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
variant: 'link',
|
|
142
|
+
color: 'info',
|
|
143
|
+
class: 'text-info-700 hover:text-info-800 focus-visible:ring-info-300'
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
variant: 'link',
|
|
147
|
+
color: 'success',
|
|
148
|
+
class: 'text-success-700 hover:text-success-800 focus-visible:ring-success-300'
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
variant: 'link',
|
|
152
|
+
color: 'warning',
|
|
153
|
+
class: 'text-warning-700 hover:text-warning-800 focus-visible:ring-warning-300'
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
variant: 'link',
|
|
157
|
+
color: 'danger',
|
|
158
|
+
class: 'text-danger-700 hover:text-danger-800 focus-visible:ring-danger-300'
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
defaultVariants: {
|
|
162
|
+
variant: 'solid',
|
|
163
|
+
color: 'default',
|
|
164
|
+
size: 'base',
|
|
165
|
+
rounded: 'base',
|
|
166
|
+
isLoading: false
|
|
167
|
+
}
|
|
168
|
+
});
|
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, onDestroy, tick } from 'svelte';
|
|
3
|
+
import { cn } from '../helper/cls.js';
|
|
4
|
+
import * as echarts from 'echarts/core';
|
|
5
|
+
// @ts-expect-error - ECharts types are not available
|
|
6
|
+
import { LineChart, BarChart, PieChart } from 'echarts/charts';
|
|
7
|
+
import {
|
|
8
|
+
// @ts-expect-error - ECharts types are not available
|
|
9
|
+
GridComponent,
|
|
10
|
+
// @ts-expect-error - ECharts types are not available
|
|
11
|
+
TooltipComponent,
|
|
12
|
+
// @ts-expect-error - ECharts types are not available
|
|
13
|
+
TitleComponent,
|
|
14
|
+
// @ts-expect-error - ECharts types are not available
|
|
15
|
+
LegendComponent,
|
|
16
|
+
// @ts-expect-error - ECharts types are not available
|
|
17
|
+
DataZoomComponent,
|
|
18
|
+
// @ts-expect-error - ECharts types are not available
|
|
19
|
+
ToolboxComponent,
|
|
20
|
+
// @ts-expect-error - ECharts types are not available
|
|
21
|
+
MarkLineComponent,
|
|
22
|
+
// @ts-expect-error - ECharts types are not available
|
|
23
|
+
MarkPointComponent,
|
|
24
|
+
// @ts-expect-error - ECharts types are not available
|
|
25
|
+
GraphicComponent
|
|
26
|
+
} from 'echarts/components';
|
|
27
|
+
// @ts-expect-error - ECharts types are not available
|
|
28
|
+
import { SVGRenderer } from 'echarts/renderers';
|
|
29
|
+
import {
|
|
30
|
+
type ChartProps,
|
|
31
|
+
type ChartColorString,
|
|
32
|
+
type ChartColors,
|
|
33
|
+
type SeriesConfig
|
|
34
|
+
} from '../index.js';
|
|
35
|
+
import { defaultChartColors } from '../variants.js';
|
|
36
|
+
|
|
37
|
+
// @ts-expect-error - ECharts types are not available
|
|
38
|
+
echarts.use([
|
|
39
|
+
LineChart,
|
|
40
|
+
BarChart,
|
|
41
|
+
PieChart,
|
|
42
|
+
GridComponent,
|
|
43
|
+
TooltipComponent,
|
|
44
|
+
TitleComponent,
|
|
45
|
+
LegendComponent,
|
|
46
|
+
DataZoomComponent,
|
|
47
|
+
ToolboxComponent,
|
|
48
|
+
MarkLineComponent,
|
|
49
|
+
MarkPointComponent,
|
|
50
|
+
SVGRenderer,
|
|
51
|
+
GraphicComponent
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
let {
|
|
55
|
+
data = [],
|
|
56
|
+
config,
|
|
57
|
+
height = '400px',
|
|
58
|
+
width = '100%',
|
|
59
|
+
class: className = '',
|
|
60
|
+
colors = {},
|
|
61
|
+
onpointclick,
|
|
62
|
+
onchartrender
|
|
63
|
+
}: ChartProps<any> = $props();
|
|
64
|
+
|
|
65
|
+
const theme = 'light';
|
|
66
|
+
const AnimationDuration = 1200;
|
|
67
|
+
|
|
68
|
+
const xAxis = $derived(config.xAxis);
|
|
69
|
+
const yAxis = $derived(config.yAxis);
|
|
70
|
+
const series = $derived(config.series);
|
|
71
|
+
|
|
72
|
+
const grid = $derived(
|
|
73
|
+
config.grid || {
|
|
74
|
+
horizontal: true,
|
|
75
|
+
vertical: false,
|
|
76
|
+
containLabel: true
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
const legend = $derived({
|
|
80
|
+
show: true,
|
|
81
|
+
position: 'top',
|
|
82
|
+
orient: 'horizontal',
|
|
83
|
+
...(config.legend || {})
|
|
84
|
+
});
|
|
85
|
+
const tooltip = $derived(
|
|
86
|
+
config.tooltip || {
|
|
87
|
+
show: true,
|
|
88
|
+
trigger: 'axis',
|
|
89
|
+
formatter: undefined
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
const toolbox = $derived(
|
|
93
|
+
config.toolbox || {
|
|
94
|
+
show: false,
|
|
95
|
+
features: {
|
|
96
|
+
saveAsImage: true,
|
|
97
|
+
dataView: false,
|
|
98
|
+
dataZoom: false,
|
|
99
|
+
magicType: true,
|
|
100
|
+
restore: true
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// Check if we have a pie/donut chart
|
|
106
|
+
const hasPieChart = $derived(series.some((s) => s.type === 'pie'));
|
|
107
|
+
|
|
108
|
+
let chartContainer: HTMLDivElement;
|
|
109
|
+
// @ts-expect-error - ECharts types are not available
|
|
110
|
+
let chart: echarts.ECharts;
|
|
111
|
+
let resizeObserver: ResizeObserver;
|
|
112
|
+
|
|
113
|
+
const chartColors: ChartColors = { ...defaultChartColors, ...colors };
|
|
114
|
+
const baseColors = [
|
|
115
|
+
chartColors.health,
|
|
116
|
+
chartColors.other,
|
|
117
|
+
chartColors.property,
|
|
118
|
+
chartColors.auto,
|
|
119
|
+
chartColors.life,
|
|
120
|
+
chartColors.default
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
function getColor(color?: ChartColorString): string | undefined {
|
|
124
|
+
return color ? chartColors[color as keyof ChartColors] || color : undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function getAreaStyle(seriesConfig: SeriesConfig<any>) {
|
|
128
|
+
if (!seriesConfig.color) return undefined;
|
|
129
|
+
if (!seriesConfig.showArea) return undefined;
|
|
130
|
+
|
|
131
|
+
const baseLinearAreaStyle = {
|
|
132
|
+
type: 'linear',
|
|
133
|
+
x: 0,
|
|
134
|
+
y: 0,
|
|
135
|
+
x2: 0,
|
|
136
|
+
y2: 1
|
|
137
|
+
};
|
|
138
|
+
const color = getColor(seriesConfig.color);
|
|
139
|
+
const opacity = seriesConfig.areaOpacity || 0.2;
|
|
140
|
+
const opacityHex = Math.floor(opacity * 255)
|
|
141
|
+
.toString(16)
|
|
142
|
+
.padStart(2, '0');
|
|
143
|
+
return {
|
|
144
|
+
color: {
|
|
145
|
+
...baseLinearAreaStyle,
|
|
146
|
+
colorStops: [
|
|
147
|
+
{
|
|
148
|
+
offset: 0,
|
|
149
|
+
color: color + opacityHex
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
offset: 1,
|
|
153
|
+
color: color + '00'
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function getSeriesColors(count: number): string[] {
|
|
161
|
+
let colors = [...baseColors];
|
|
162
|
+
while (colors.length < count) {
|
|
163
|
+
const index = colors.length % baseColors.length;
|
|
164
|
+
const baseColor = baseColors[index];
|
|
165
|
+
const r = parseInt(baseColor.slice(1, 3), 16);
|
|
166
|
+
const g = parseInt(baseColor.slice(3, 5), 16);
|
|
167
|
+
const b = parseInt(baseColor.slice(5, 7), 16);
|
|
168
|
+
const factor = 0.8 + (colors.length / baseColors.length) * 0.4;
|
|
169
|
+
const newColor = `#${Math.min(255, Math.floor(r * factor))
|
|
170
|
+
.toString(16)
|
|
171
|
+
.padStart(2, '0')}${Math.min(255, Math.floor(g * factor))
|
|
172
|
+
.toString(16)
|
|
173
|
+
.padStart(2, '0')}${Math.min(255, Math.floor(b * factor))
|
|
174
|
+
.toString(16)
|
|
175
|
+
.padStart(2, '0')}`;
|
|
176
|
+
colors.push(newColor);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return colors.slice(0, count);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function formatValue(value: any, format?: (value: any) => string, unit?: string): string {
|
|
183
|
+
if (format) {
|
|
184
|
+
return format(value);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (unit) {
|
|
188
|
+
return `${value}${unit}`;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return String(value);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function configureSeries(): any[] {
|
|
195
|
+
return series.map((seriesConfig) => {
|
|
196
|
+
const seriesType = seriesConfig.type || 'line';
|
|
197
|
+
|
|
198
|
+
if (seriesType === 'pie') {
|
|
199
|
+
const pieData = data.map((item) => ({
|
|
200
|
+
value: item[seriesConfig.dataKey],
|
|
201
|
+
name: item[xAxis?.dataKey] || item.label
|
|
202
|
+
}));
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
name: seriesConfig.name || seriesConfig.dataKey,
|
|
206
|
+
type: 'pie',
|
|
207
|
+
radius: seriesConfig.radius || ['0%', '70%'],
|
|
208
|
+
avoidLabelOverlap: true,
|
|
209
|
+
itemStyle: {
|
|
210
|
+
borderRadius: 4,
|
|
211
|
+
borderWidth: 2,
|
|
212
|
+
borderColor: '#fff',
|
|
213
|
+
color: getColor(seriesConfig.color)
|
|
214
|
+
},
|
|
215
|
+
label: {
|
|
216
|
+
show: seriesConfig.showLabel !== undefined ? seriesConfig.showLabel : true
|
|
217
|
+
},
|
|
218
|
+
labelLine: {
|
|
219
|
+
show: seriesConfig.showLabel !== undefined ? seriesConfig.showLabel : true
|
|
220
|
+
},
|
|
221
|
+
data: pieData,
|
|
222
|
+
animation: true,
|
|
223
|
+
animationDuration: AnimationDuration,
|
|
224
|
+
emphasis: seriesConfig.emphasis || { focus: 'series' }
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const isHorizontalBar = seriesType === 'horizontal-bar';
|
|
229
|
+
const actualType = isHorizontalBar ? 'bar' : seriesType;
|
|
230
|
+
|
|
231
|
+
const seriesData = data.map((item) => ({
|
|
232
|
+
value: item[seriesConfig.dataKey],
|
|
233
|
+
name: item[xAxis.dataKey]
|
|
234
|
+
}));
|
|
235
|
+
|
|
236
|
+
const barSeriesCount = series.filter(
|
|
237
|
+
(s) => s.type === 'bar' || s.type === 'horizontal-bar'
|
|
238
|
+
).length;
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
name: seriesConfig.name || seriesConfig.dataKey,
|
|
242
|
+
type: actualType,
|
|
243
|
+
yAxisIndex: seriesConfig.yAxisIndex || 0,
|
|
244
|
+
data: seriesData,
|
|
245
|
+
stack: seriesConfig.stack,
|
|
246
|
+
color: getColor(seriesConfig.color),
|
|
247
|
+
emphasis: seriesConfig.emphasis || { focus: 'series' },
|
|
248
|
+
animation: true,
|
|
249
|
+
animationDuration: AnimationDuration,
|
|
250
|
+
|
|
251
|
+
...(actualType === 'line' && {
|
|
252
|
+
smooth: seriesConfig.smooth !== undefined ? seriesConfig.smooth : true,
|
|
253
|
+
showSymbol: seriesConfig.showSymbol !== undefined ? seriesConfig.showSymbol : true,
|
|
254
|
+
symbolSize: 6,
|
|
255
|
+
lineStyle: {
|
|
256
|
+
width: seriesConfig.lineWidth || 2,
|
|
257
|
+
color: getColor(seriesConfig.color),
|
|
258
|
+
type: seriesConfig.lineStyle?.type || 'solid'
|
|
259
|
+
},
|
|
260
|
+
areaStyle: getAreaStyle(seriesConfig)
|
|
261
|
+
}),
|
|
262
|
+
|
|
263
|
+
...(actualType === 'bar' && {
|
|
264
|
+
name: seriesConfig.name || seriesConfig.dataKey,
|
|
265
|
+
type: actualType,
|
|
266
|
+
yAxisIndex: seriesConfig.yAxisIndex || 0,
|
|
267
|
+
data: seriesData,
|
|
268
|
+
stack: null,
|
|
269
|
+
barWidth:
|
|
270
|
+
seriesConfig.barWidth ||
|
|
271
|
+
(barSeriesCount > 3 ? '15%' : barSeriesCount > 1 ? '25%' : '60%'),
|
|
272
|
+
barCategoryGap: '20%',
|
|
273
|
+
barGap: '10%',
|
|
274
|
+
color: getColor(seriesConfig.color),
|
|
275
|
+
itemStyle: {
|
|
276
|
+
color: getColor(seriesConfig.color),
|
|
277
|
+
borderRadius: [4, 4, 0, 0],
|
|
278
|
+
opacity: seriesConfig.opacity || 1
|
|
279
|
+
}
|
|
280
|
+
}),
|
|
281
|
+
|
|
282
|
+
label: {
|
|
283
|
+
show: seriesConfig.showLabel || false,
|
|
284
|
+
position: actualType === 'line' ? 'top' : 'inside',
|
|
285
|
+
// @ts-expect-error - ECharts types are not available
|
|
286
|
+
formatter: (params) => {
|
|
287
|
+
const yAxisIndex = seriesConfig.yAxisIndex || 0;
|
|
288
|
+
const axisConfig = yAxis[yAxisIndex];
|
|
289
|
+
return formatValue(params.value, axisConfig.format, axisConfig.unit);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function defaultFormatter(params: any) {
|
|
297
|
+
if (Array.isArray(params)) {
|
|
298
|
+
const item = params[0];
|
|
299
|
+
let html = `<div style="font-weight: bold; margin-bottom: 5px;">${item.name}</div>`;
|
|
300
|
+
|
|
301
|
+
params.forEach((param) => {
|
|
302
|
+
const seriesItem = series.find(
|
|
303
|
+
(s) => s.name === param.seriesName || s.dataKey === param.seriesName
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
if (seriesItem?.type === 'pie') {
|
|
307
|
+
html += `<div style="display: flex; align-items: center; margin: 3px 0;">
|
|
308
|
+
<span style="display: inline-block; width: 10px; height: 10px; background: ${param.color}; border-radius: 50%; margin-right: 5px;"></span>
|
|
309
|
+
<span>${param.seriesName}: ${param.value} (${param.percent}%)</span>
|
|
310
|
+
</div>`;
|
|
311
|
+
} else {
|
|
312
|
+
const yAxisIndex = seriesItem?.yAxisIndex || 0;
|
|
313
|
+
const axisConfig = yAxis[yAxisIndex];
|
|
314
|
+
const formattedValue = formatValue(param.value, axisConfig.format, axisConfig.unit);
|
|
315
|
+
|
|
316
|
+
html += `<div style="display: flex; align-items: center; margin: 3px 0;">
|
|
317
|
+
<span style="display: inline-block; width: 10px; height: 10px; background: ${param.color}; border-radius: 50%; margin-right: 5px;"></span>
|
|
318
|
+
<span>${param.seriesName}: ${formattedValue}</span>
|
|
319
|
+
</div>`;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
return html;
|
|
324
|
+
} else {
|
|
325
|
+
if (params.seriesType === 'pie') {
|
|
326
|
+
return `${params.name}: ${params.value} (${params.percent}%)`;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const seriesItem = series.find(
|
|
330
|
+
(s) => s.name === params.seriesName || s.dataKey === params.seriesName
|
|
331
|
+
);
|
|
332
|
+
const yAxisIndex = seriesItem?.yAxisIndex || 0;
|
|
333
|
+
const axisConfig = yAxis[yAxisIndex];
|
|
334
|
+
const formattedValue = formatValue(params.value, axisConfig.format, axisConfig.unit);
|
|
335
|
+
|
|
336
|
+
return `${params.seriesName}: ${formattedValue}`;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function updateChart() {
|
|
341
|
+
if (!chart || !data || !series) return;
|
|
342
|
+
|
|
343
|
+
const colorPalette = getSeriesColors(series.length);
|
|
344
|
+
|
|
345
|
+
if (hasPieChart) {
|
|
346
|
+
// Configure for pie chart
|
|
347
|
+
const pieOptions = {
|
|
348
|
+
color: colorPalette,
|
|
349
|
+
|
|
350
|
+
tooltip: {
|
|
351
|
+
show: tooltip.show,
|
|
352
|
+
trigger: 'item',
|
|
353
|
+
formatter: tooltip.formatter || '{b}: {c} ({d}%)'
|
|
354
|
+
},
|
|
355
|
+
|
|
356
|
+
legend: {
|
|
357
|
+
show: legend.show,
|
|
358
|
+
type: 'scroll',
|
|
359
|
+
orient: legend.orient,
|
|
360
|
+
...(legend.position === 'top' && { top: 0, left: 'center' }),
|
|
361
|
+
...(legend.position === 'bottom' && { bottom: 0, left: 'center' }),
|
|
362
|
+
...(legend.position === 'left' && { left: 0, top: 'middle' }),
|
|
363
|
+
...(legend.position === 'right' && { right: 0, top: 'middle' })
|
|
364
|
+
},
|
|
365
|
+
|
|
366
|
+
series: configureSeries()
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
// Add center text if specified in the first pie series
|
|
370
|
+
const pieSeriesWithCenterText = series.find((s) => s.type === 'pie' && s.centerText);
|
|
371
|
+
if (pieSeriesWithCenterText?.centerText) {
|
|
372
|
+
// @ts-expect-error - ECharts types are not available
|
|
373
|
+
pieOptions.graphic = {
|
|
374
|
+
elements: [
|
|
375
|
+
{
|
|
376
|
+
type: 'text',
|
|
377
|
+
left: 'center',
|
|
378
|
+
top: 'center',
|
|
379
|
+
style: {
|
|
380
|
+
text: pieSeriesWithCenterText.centerText,
|
|
381
|
+
fontSize: 20,
|
|
382
|
+
fontWeight: 'bold'
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
]
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
chart.setOption(pieOptions, true);
|
|
390
|
+
} else {
|
|
391
|
+
// Regular chart configuration
|
|
392
|
+
const categories = data.map((item) => item[xAxis.dataKey]);
|
|
393
|
+
|
|
394
|
+
const options = {
|
|
395
|
+
color: colorPalette,
|
|
396
|
+
|
|
397
|
+
tooltip: {
|
|
398
|
+
show: tooltip.show,
|
|
399
|
+
trigger: tooltip.trigger,
|
|
400
|
+
formatter: tooltip.formatter || defaultFormatter
|
|
401
|
+
},
|
|
402
|
+
|
|
403
|
+
legend: {
|
|
404
|
+
show: legend.show,
|
|
405
|
+
type: 'scroll',
|
|
406
|
+
orient: legend.orient,
|
|
407
|
+
...(legend.position === 'top' && { top: 0, left: 'center' }),
|
|
408
|
+
...(legend.position === 'bottom' && { bottom: 0, left: 'center' }),
|
|
409
|
+
...(legend.position === 'left' && { left: 0, top: 'middle' }),
|
|
410
|
+
...(legend.position === 'right' && { right: 0, top: 'middle' })
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
grid: {
|
|
414
|
+
top: legend.position === 'top' ? '15%' : grid.top || '10%',
|
|
415
|
+
right: grid.right || '3%',
|
|
416
|
+
bottom: legend.position === 'bottom' ? '15%' : grid.bottom || '10%',
|
|
417
|
+
left: grid.left || '3%',
|
|
418
|
+
containLabel: grid.containLabel !== undefined ? grid.containLabel : true
|
|
419
|
+
},
|
|
420
|
+
|
|
421
|
+
xAxis: {
|
|
422
|
+
type: 'category',
|
|
423
|
+
data: categories,
|
|
424
|
+
axisLabel: {
|
|
425
|
+
...(xAxis.tick && {
|
|
426
|
+
fontSize: xAxis.tick.fontSize,
|
|
427
|
+
rotate: xAxis.tick.rotate,
|
|
428
|
+
interval: xAxis.tick.interval
|
|
429
|
+
}),
|
|
430
|
+
formatter: xAxis.format || '{value}'
|
|
431
|
+
},
|
|
432
|
+
boundaryGap: series.every((s) => s.type === 'line')
|
|
433
|
+
? false
|
|
434
|
+
: series.some((s) => s.type === 'bar' || s.type === 'horizontal-bar')
|
|
435
|
+
? true
|
|
436
|
+
: undefined,
|
|
437
|
+
name: xAxis.label,
|
|
438
|
+
nameLocation: 'middle',
|
|
439
|
+
nameGap: 30,
|
|
440
|
+
splitLine: {
|
|
441
|
+
show: grid.vertical || false
|
|
442
|
+
},
|
|
443
|
+
axisLine: xAxis.axisLine || {
|
|
444
|
+
show: false
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
|
|
448
|
+
yAxis: yAxis.map((axis, index) => ({
|
|
449
|
+
type: 'value',
|
|
450
|
+
name: axis.label,
|
|
451
|
+
nameLocation: 'middle',
|
|
452
|
+
nameGap: 50,
|
|
453
|
+
nameRotate: 90,
|
|
454
|
+
position: axis.position || (index === 0 ? 'left' : 'right'),
|
|
455
|
+
min: axis.min,
|
|
456
|
+
max: axis.max,
|
|
457
|
+
axisLine: axis.axisLine || {
|
|
458
|
+
show: false
|
|
459
|
+
},
|
|
460
|
+
axisLabel: {
|
|
461
|
+
// @ts-expect-error - ECharts types are not available
|
|
462
|
+
formatter: (value) => formatValue(value, axis.format, axis.unit)
|
|
463
|
+
},
|
|
464
|
+
splitLine: {
|
|
465
|
+
show: index === 0 ? grid.horizontal || true : false
|
|
466
|
+
}
|
|
467
|
+
})),
|
|
468
|
+
|
|
469
|
+
toolbox: toolbox.show
|
|
470
|
+
? {
|
|
471
|
+
feature: {
|
|
472
|
+
...(toolbox.features?.saveAsImage && { saveAsImage: {} }),
|
|
473
|
+
...(toolbox.features?.dataView && { dataView: { readOnly: false } }),
|
|
474
|
+
...(toolbox.features?.dataZoom && { dataZoom: { yAxisIndex: 'none' } }),
|
|
475
|
+
...(toolbox.features?.magicType && {
|
|
476
|
+
magicType: { type: ['line', 'bar', 'stack'] }
|
|
477
|
+
}),
|
|
478
|
+
...(toolbox.features?.restore && { restore: {} })
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
: undefined,
|
|
482
|
+
|
|
483
|
+
series: configureSeries()
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
chart.setOption(options, true);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
if (onchartrender) {
|
|
490
|
+
onchartrender({
|
|
491
|
+
detail: {
|
|
492
|
+
chart,
|
|
493
|
+
options: chart.getOption()
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
onMount(() => {
|
|
500
|
+
// @ts-expect-error - ECharts types are not available
|
|
501
|
+
chart = echarts.init(chartContainer, theme);
|
|
502
|
+
|
|
503
|
+
// Instantly triggering resizes disables animation, hence the timeout
|
|
504
|
+
setTimeout(() => {
|
|
505
|
+
resizeObserver = new ResizeObserver(() => {
|
|
506
|
+
chart?.resize();
|
|
507
|
+
});
|
|
508
|
+
resizeObserver.observe(chartContainer);
|
|
509
|
+
}, AnimationDuration);
|
|
510
|
+
|
|
511
|
+
updateChart();
|
|
512
|
+
// @ts-expect-error - ECharts types are not available
|
|
513
|
+
chart.on('click', (params) => {
|
|
514
|
+
if (onpointclick) {
|
|
515
|
+
onpointclick({
|
|
516
|
+
detail: {
|
|
517
|
+
seriesIndex: params.seriesIndex,
|
|
518
|
+
dataIndex: params.dataIndex,
|
|
519
|
+
seriesName: params.seriesName,
|
|
520
|
+
name: params.name,
|
|
521
|
+
value: params.value,
|
|
522
|
+
originalData: data[params.dataIndex]
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
$effect(() => {
|
|
530
|
+
if (chart && data && series) {
|
|
531
|
+
updateChart();
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
onDestroy(() => {
|
|
536
|
+
resizeObserver?.disconnect();
|
|
537
|
+
chart?.dispose();
|
|
538
|
+
});
|
|
539
|
+
</script>
|
|
540
|
+
|
|
541
|
+
<div
|
|
542
|
+
class={cn('advanced-chart', className)}
|
|
543
|
+
style="height: {height}; width: {width}"
|
|
544
|
+
bind:this={chartContainer}
|
|
545
|
+
></div>
|