@carbon/charts-svelte 1.22.18 → 1.22.19
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/CHANGELOG.md +9 -0
- package/README.md +34 -55
- package/dist/AlluvialChart.svelte +14 -8
- package/dist/AlluvialChart.svelte.d.ts +9 -35
- package/dist/AreaChart.svelte +14 -8
- package/dist/AreaChart.svelte.d.ts +9 -35
- package/dist/BarChartGrouped.svelte +14 -8
- package/dist/BarChartGrouped.svelte.d.ts +9 -35
- package/dist/BarChartSimple.svelte +14 -8
- package/dist/BarChartSimple.svelte.d.ts +9 -35
- package/dist/BarChartStacked.svelte +14 -8
- package/dist/BarChartStacked.svelte.d.ts +9 -35
- package/dist/BaseChart.svelte +23 -23
- package/dist/BaseChart.svelte.d.ts +33 -31
- package/dist/BoxplotChart.svelte +14 -8
- package/dist/BoxplotChart.svelte.d.ts +9 -35
- package/dist/BubbleChart.svelte +14 -8
- package/dist/BubbleChart.svelte.d.ts +9 -35
- package/dist/BulletChart.svelte +14 -8
- package/dist/BulletChart.svelte.d.ts +9 -35
- package/dist/ChoroplethChart.svelte +14 -8
- package/dist/ChoroplethChart.svelte.d.ts +9 -35
- package/dist/CirclePackChart.svelte +14 -8
- package/dist/CirclePackChart.svelte.d.ts +9 -35
- package/dist/ComboChart.svelte +14 -8
- package/dist/ComboChart.svelte.d.ts +9 -35
- package/dist/DonutChart.svelte +14 -8
- package/dist/DonutChart.svelte.d.ts +9 -35
- package/dist/GaugeChart.svelte +14 -8
- package/dist/GaugeChart.svelte.d.ts +9 -35
- package/dist/HeatmapChart.svelte +14 -8
- package/dist/HeatmapChart.svelte.d.ts +9 -35
- package/dist/HistogramChart.svelte +14 -8
- package/dist/HistogramChart.svelte.d.ts +9 -35
- package/dist/LineChart.svelte +14 -8
- package/dist/LineChart.svelte.d.ts +9 -35
- package/dist/LollipopChart.svelte +14 -8
- package/dist/LollipopChart.svelte.d.ts +9 -35
- package/dist/MeterChart.svelte +14 -8
- package/dist/MeterChart.svelte.d.ts +9 -35
- package/dist/PieChart.svelte +14 -8
- package/dist/PieChart.svelte.d.ts +9 -35
- package/dist/RadarChart.svelte +14 -8
- package/dist/RadarChart.svelte.d.ts +9 -35
- package/dist/ScatterChart.svelte +14 -8
- package/dist/ScatterChart.svelte.d.ts +9 -35
- package/dist/StackedAreaChart.svelte +14 -8
- package/dist/StackedAreaChart.svelte.d.ts +9 -32
- package/dist/TreeChart.svelte +14 -8
- package/dist/TreeChart.svelte.d.ts +9 -35
- package/dist/TreemapChart.svelte +14 -8
- package/dist/TreemapChart.svelte.d.ts +9 -35
- package/dist/WordCloudChart.svelte +14 -8
- package/dist/WordCloudChart.svelte.d.ts +9 -36
- package/dist/interfaces.d.ts +24 -0
- package/dist/interfaces.js +1 -0
- package/dist/styles.css +198 -0
- package/dist/styles.css.map +1 -1
- package/dist/styles.min.css +197 -0
- package/dist/styles.min.css.map +1 -1
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See
|
|
4
4
|
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 1.22.19 (2025-02-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @carbon/charts-svelte
|
|
9
|
+
|
|
10
|
+
# Change Log
|
|
11
|
+
|
|
12
|
+
All notable changes to this project will be documented in this file. See
|
|
13
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
14
|
+
|
|
6
15
|
## 1.22.18 (2025-02-18)
|
|
7
16
|
|
|
8
17
|
**Note:** Version bump only for package @carbon/charts-svelte
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
</a>
|
|
5
5
|
<h3 align="center">Carbon Charts Svelte</h3>
|
|
6
6
|
<p align="center">
|
|
7
|
-
A component library of 26 charts for Svelte and SvelteKit.
|
|
7
|
+
A component library of 26 charts for Svelte 5.20+ and SvelteKit (optionally).
|
|
8
8
|
<br /><br />
|
|
9
9
|
<a href="https://www.npmjs.com/package/@carbon/charts">
|
|
10
10
|
<img src="https://img.shields.io/npm/v/@carbon/charts.svg" />
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
## Maintenance & support
|
|
23
23
|
|
|
24
|
-
These Svelte
|
|
24
|
+
These Svelte components were developed by Eric Liu and Nate Stuyvesant.
|
|
25
25
|
|
|
26
26
|
Please direct all questions regarding support, bug fixes and feature requests to
|
|
27
27
|
[@nstuyvesant](https://github.com/nstuyvesant) and [@metonym](https://github.com/metonym).
|
|
@@ -31,40 +31,42 @@ Please direct all questions regarding support, bug fixes and feature requests to
|
|
|
31
31
|
Run the following command using [npm](https://www.npmjs.com/):
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
-
npm install -D @carbon/charts-svelte
|
|
34
|
+
npm install -D @carbon/charts-svelte@next
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
If you prefer [Yarn](https://yarnpkg.com/en/), use the following command instead:
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
|
-
yarn add -D @carbon/charts-svelte
|
|
40
|
+
yarn add -D @carbon/charts-svelte@next
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
The required styles should be imported from `@carbon/charts-svelte/styles.css`.
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
## Breaking Change
|
|
46
|
+
|
|
47
|
+
This release is for Svelte 5.20+ ONLY as it uses runes mode and passing of callback functions as
|
|
48
|
+
properties in place of event handlers. If you need support for Svelte 3 or 4, please use the
|
|
49
|
+
`latest`.
|
|
46
50
|
|
|
47
51
|
### SvelteKit
|
|
48
52
|
|
|
49
53
|
While this component library can be used with any build environments for Svelte,
|
|
50
54
|
[SvelteKit](https://kit.svelte.dev) is the official framework for building Svelte apps supporting
|
|
51
|
-
client
|
|
55
|
+
client and server-side rendering (SSR). SvelteKit is powered by [Vite](https://vitejs.dev).
|
|
52
56
|
|
|
53
57
|
The module `@carbon/charts` should not be externalized for SSR when building for production.
|
|
54
58
|
|
|
55
59
|
```js
|
|
56
|
-
// vite.config.
|
|
60
|
+
// vite.config.ts
|
|
57
61
|
import { sveltekit } from '@sveltejs/kit/vite'
|
|
62
|
+
import { defineConfig } from 'vite'
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
const config = {
|
|
64
|
+
export default defineConfig({
|
|
61
65
|
plugins: [sveltekit()],
|
|
62
66
|
ssr: {
|
|
63
67
|
noExternal: process.env.NODE_ENV === 'production' ? ['@carbon/charts'] : []
|
|
64
68
|
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default config
|
|
69
|
+
})
|
|
68
70
|
```
|
|
69
71
|
|
|
70
72
|
#### Circular dependency warnings
|
|
@@ -106,39 +108,38 @@ import '@carbon/charts-svelte/styles.css'
|
|
|
106
108
|
}} />
|
|
107
109
|
```
|
|
108
110
|
|
|
109
|
-
###
|
|
111
|
+
### Lifecycle callbacks
|
|
110
112
|
|
|
111
|
-
|
|
113
|
+
Chart components fire the following callbacks:
|
|
112
114
|
|
|
113
|
-
- **
|
|
114
|
-
- **
|
|
115
|
-
- **
|
|
115
|
+
- **onload**: When the chart is instantiated
|
|
116
|
+
- **onupdate**: When `data` or `options` are updated
|
|
117
|
+
- **ondestroy**: When the component is unmounted and the chart is destroyed
|
|
116
118
|
|
|
117
119
|
```svelte
|
|
118
|
-
<BarChartSimple {data} {options}
|
|
120
|
+
<BarChartSimple {data} {options} {onload} {onupdate} {ondestroy} />
|
|
119
121
|
```
|
|
120
122
|
|
|
121
123
|
### Dynamic import
|
|
122
124
|
|
|
123
|
-
Dynamically
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
Dynamically importing a chart within `onMount()` avoids issues with server-side rendering (SSR). The
|
|
126
|
+
reason `@carbon/charts-svelte` does not work with SRR is because its dependency `@carbon/charts`
|
|
127
|
+
expects the window object to be present for fullscreen display.
|
|
126
128
|
|
|
127
129
|
```svelte
|
|
128
130
|
<script>
|
|
129
131
|
import '@carbon/charts-svelte/styles.css'
|
|
130
132
|
import { onMount } from 'svelte'
|
|
131
133
|
|
|
132
|
-
let
|
|
134
|
+
let Chart = $state()
|
|
133
135
|
|
|
134
136
|
onMount(async () => {
|
|
135
137
|
const charts = await import('@carbon/charts-svelte')
|
|
136
|
-
|
|
138
|
+
Chart = charts.BarChartSimple
|
|
137
139
|
})
|
|
138
140
|
</script>
|
|
139
141
|
|
|
140
|
-
<
|
|
141
|
-
this={chart}
|
|
142
|
+
<Chart
|
|
142
143
|
data={[
|
|
143
144
|
{ group: 'Qty', value: 65000 },
|
|
144
145
|
{ group: 'More', value: 29123 },
|
|
@@ -168,7 +169,7 @@ hovering over a bar.
|
|
|
168
169
|
import { onMount } from 'svelte'
|
|
169
170
|
import { BarChartSimple } from '@carbon/charts-svelte'
|
|
170
171
|
|
|
171
|
-
let chart
|
|
172
|
+
let chart = $state()
|
|
172
173
|
|
|
173
174
|
function barMouseOver(e) {
|
|
174
175
|
console.log(e.detail)
|
|
@@ -202,11 +203,6 @@ hovering over a bar.
|
|
|
202
203
|
}} />
|
|
203
204
|
```
|
|
204
205
|
|
|
205
|
-
## Svelte and TypeScript support
|
|
206
|
-
|
|
207
|
-
Svelte 3.31 or greater is required to use this library with TypeScript. Svelte 5.20+ is
|
|
208
|
-
recommended.
|
|
209
|
-
|
|
210
206
|
### Enums and types
|
|
211
207
|
|
|
212
208
|
For your convenience, enums and types from `@carbon/charts` are re-exported from
|
|
@@ -228,22 +224,6 @@ const options: BarChartOptions = {
|
|
|
228
224
|
}
|
|
229
225
|
```
|
|
230
226
|
|
|
231
|
-
### Component type
|
|
232
|
-
|
|
233
|
-
Use the `ComponentType` utility type from `svelte` to extract the component type for chart
|
|
234
|
-
components.
|
|
235
|
-
|
|
236
|
-
```ts
|
|
237
|
-
import { onMount, type ComponentType } from 'svelte'
|
|
238
|
-
import type { BarChartSimple } from '@carbon/charts-svelte'
|
|
239
|
-
|
|
240
|
-
let component: ComponentType<BarChartSimple> = null
|
|
241
|
-
|
|
242
|
-
onMount(async () => {
|
|
243
|
-
component = (await import('@carbon/charts-svelte')).BarChartSimple
|
|
244
|
-
})
|
|
245
|
-
```
|
|
246
|
-
|
|
247
227
|
### Component props
|
|
248
228
|
|
|
249
229
|
Use the `ComponentProps` utility type from `svelte` to extract the props for chart components.
|
|
@@ -253,20 +233,19 @@ You can then use an
|
|
|
253
233
|
extract types for individual properties.
|
|
254
234
|
|
|
255
235
|
```ts
|
|
256
|
-
import {
|
|
236
|
+
import type { ComponentProps } from 'svelte'
|
|
257
237
|
import { BarChartSimple } from '@carbon/charts-svelte'
|
|
238
|
+
import { options } from './options'
|
|
239
|
+
import { data } from './data'
|
|
258
240
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
// Indexed access type to access the type of the `chart` property
|
|
262
|
-
let chart: ChartProps['chart'] = null
|
|
241
|
+
// Errors if these aren't the correct props expected by BarChartSimple
|
|
242
|
+
const props: ComponentProps<typeof BarChartSimple> = { options, data }
|
|
263
243
|
```
|
|
264
244
|
|
|
265
245
|
## <picture><source height="20" width="20" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ibm-telemetry/telemetry-js/main/docs/images/ibm-telemetry-dark.svg"><source height="20" width="20" media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/ibm-telemetry/telemetry-js/main/docs/images/ibm-telemetry-light.svg"><img height="20" width="20" alt="IBM Telemetry" src="https://raw.githubusercontent.com/ibm-telemetry/telemetry-js/main/docs/images/ibm-telemetry-light.svg"></picture> IBM Telemetry
|
|
266
246
|
|
|
267
|
-
This package uses IBM Telemetry to collect de-identified and anonymized metrics
|
|
268
|
-
|
|
269
|
-
collection. To opt out, see
|
|
247
|
+
This package uses IBM Telemetry to collect de-identified and anonymized metrics data. By installing
|
|
248
|
+
this package as a dependency you are agreeing to telemetry collection. To opt out, see
|
|
270
249
|
[Opting out of IBM Telemetry data collection](https://github.com/ibm-telemetry/telemetry-js/tree/main#opting-out-of-ibm-telemetry-data-collection).
|
|
271
250
|
For more information on the data being collected, please see the
|
|
272
251
|
[IBM Telemetry documentation](https://github.com/ibm-telemetry/telemetry-js/tree/main#ibm-telemetry-collection-basics).
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { AlluvialChart as AlluvialChartCore } from '@carbon/charts'
|
|
3
3
|
import BaseChart from './BaseChart.svelte'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
let {
|
|
5
|
+
data,
|
|
6
|
+
options,
|
|
7
|
+
ref = $bindable(),
|
|
8
|
+
chart = $bindable(),
|
|
9
|
+
onload,
|
|
10
|
+
onupdate,
|
|
11
|
+
ondestroy,
|
|
12
|
+
...rest
|
|
13
|
+
} = $props()
|
|
8
14
|
</script>
|
|
9
15
|
|
|
10
16
|
<BaseChart
|
|
11
|
-
{...$$restProps}
|
|
12
17
|
Chart={AlluvialChartCore}
|
|
13
18
|
{options}
|
|
14
19
|
{data}
|
|
15
20
|
bind:ref
|
|
16
21
|
bind:chart
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
{onload}
|
|
23
|
+
{onupdate}
|
|
24
|
+
{ondestroy}
|
|
25
|
+
{...rest} />
|
|
@@ -1,35 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
options: AlluvialChartOptions
|
|
11
|
-
data: ChartTabularData
|
|
12
|
-
chart?: AlluvialChartCore | undefined
|
|
13
|
-
ref?: HTMLDivElement | undefined
|
|
14
|
-
}
|
|
15
|
-
events: {
|
|
16
|
-
load: CustomEvent<null>
|
|
17
|
-
update: CustomEvent<{
|
|
18
|
-
data: ChartTabularData
|
|
19
|
-
options: import('@carbon/charts').BaseChartOptions
|
|
20
|
-
}>
|
|
21
|
-
destroy: CustomEvent<null>
|
|
22
|
-
} & {
|
|
23
|
-
[evt: string]: CustomEvent<any>
|
|
24
|
-
}
|
|
25
|
-
slots: {}
|
|
26
|
-
}
|
|
27
|
-
export type AlluvialChartProps = typeof __propDef.props
|
|
28
|
-
export type AlluvialChartEvents = typeof __propDef.events
|
|
29
|
-
export type AlluvialChartSlots = typeof __propDef.slots
|
|
30
|
-
export default class AlluvialChart extends SvelteComponentTyped<
|
|
31
|
-
AlluvialChartProps,
|
|
32
|
-
AlluvialChartEvents,
|
|
33
|
-
AlluvialChartSlots
|
|
34
|
-
> {}
|
|
35
|
-
export {}
|
|
1
|
+
import { AlluvialChart as AlluvialChartCore, type AlluvialChartOptions } from '@carbon/charts'
|
|
2
|
+
import type { ChartProps } from './interfaces'
|
|
3
|
+
declare const AlluvialChart: import('svelte').Component<
|
|
4
|
+
ChartProps<AlluvialChartCore, AlluvialChartOptions>,
|
|
5
|
+
{},
|
|
6
|
+
'ref' | 'chart'
|
|
7
|
+
>
|
|
8
|
+
type AlluvialChart = ReturnType<typeof AlluvialChart>
|
|
9
|
+
export default AlluvialChart
|
package/dist/AreaChart.svelte
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { AreaChart as AreaChartCore } from '@carbon/charts'
|
|
3
3
|
import BaseChart from './BaseChart.svelte'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
let {
|
|
5
|
+
data,
|
|
6
|
+
options,
|
|
7
|
+
ref = $bindable(),
|
|
8
|
+
chart = $bindable(),
|
|
9
|
+
onload,
|
|
10
|
+
onupdate,
|
|
11
|
+
ondestroy,
|
|
12
|
+
...rest
|
|
13
|
+
} = $props()
|
|
8
14
|
</script>
|
|
9
15
|
|
|
10
16
|
<BaseChart
|
|
11
|
-
{...$$restProps}
|
|
12
17
|
Chart={AreaChartCore}
|
|
13
18
|
{options}
|
|
14
19
|
{data}
|
|
15
20
|
bind:ref
|
|
16
21
|
bind:chart
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
{onload}
|
|
23
|
+
{onupdate}
|
|
24
|
+
{ondestroy}
|
|
25
|
+
{...rest} />
|
|
@@ -1,35 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
options: AreaChartOptions
|
|
11
|
-
data: ChartTabularData
|
|
12
|
-
chart?: AreaChartCore | undefined
|
|
13
|
-
ref?: HTMLDivElement | undefined
|
|
14
|
-
}
|
|
15
|
-
events: {
|
|
16
|
-
load: CustomEvent<null>
|
|
17
|
-
update: CustomEvent<{
|
|
18
|
-
data: ChartTabularData
|
|
19
|
-
options: import('@carbon/charts').BaseChartOptions
|
|
20
|
-
}>
|
|
21
|
-
destroy: CustomEvent<null>
|
|
22
|
-
} & {
|
|
23
|
-
[evt: string]: CustomEvent<any>
|
|
24
|
-
}
|
|
25
|
-
slots: {}
|
|
26
|
-
}
|
|
27
|
-
export type AreaChartProps = typeof __propDef.props
|
|
28
|
-
export type AreaChartEvents = typeof __propDef.events
|
|
29
|
-
export type AreaChartSlots = typeof __propDef.slots
|
|
30
|
-
export default class AreaChart extends SvelteComponentTyped<
|
|
31
|
-
AreaChartProps,
|
|
32
|
-
AreaChartEvents,
|
|
33
|
-
AreaChartSlots
|
|
34
|
-
> {}
|
|
35
|
-
export {}
|
|
1
|
+
import { AreaChart as AreaChartCore, type AreaChartOptions } from '@carbon/charts'
|
|
2
|
+
import type { ChartProps } from './interfaces'
|
|
3
|
+
declare const AreaChart: import('svelte').Component<
|
|
4
|
+
ChartProps<AreaChartCore, AreaChartOptions>,
|
|
5
|
+
{},
|
|
6
|
+
'ref' | 'chart'
|
|
7
|
+
>
|
|
8
|
+
type AreaChart = ReturnType<typeof AreaChart>
|
|
9
|
+
export default AreaChart
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { GroupedBarChart as GroupedBarChartCore } from '@carbon/charts'
|
|
3
3
|
import BaseChart from './BaseChart.svelte'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
let {
|
|
5
|
+
data,
|
|
6
|
+
options,
|
|
7
|
+
ref = $bindable(),
|
|
8
|
+
chart = $bindable(),
|
|
9
|
+
onload,
|
|
10
|
+
onupdate,
|
|
11
|
+
ondestroy,
|
|
12
|
+
...rest
|
|
13
|
+
} = $props()
|
|
8
14
|
</script>
|
|
9
15
|
|
|
10
16
|
<BaseChart
|
|
11
|
-
{...$$restProps}
|
|
12
17
|
Chart={GroupedBarChartCore}
|
|
13
18
|
{options}
|
|
14
19
|
{data}
|
|
15
20
|
bind:ref
|
|
16
21
|
bind:chart
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
{onload}
|
|
23
|
+
{onupdate}
|
|
24
|
+
{ondestroy}
|
|
25
|
+
{...rest} />
|
|
@@ -1,35 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
options: BarChartOptions
|
|
11
|
-
data: ChartTabularData
|
|
12
|
-
chart?: GroupedBarChartCore | undefined
|
|
13
|
-
ref?: HTMLDivElement | undefined
|
|
14
|
-
}
|
|
15
|
-
events: {
|
|
16
|
-
load: CustomEvent<null>
|
|
17
|
-
update: CustomEvent<{
|
|
18
|
-
data: ChartTabularData
|
|
19
|
-
options: import('@carbon/charts').BaseChartOptions
|
|
20
|
-
}>
|
|
21
|
-
destroy: CustomEvent<null>
|
|
22
|
-
} & {
|
|
23
|
-
[evt: string]: CustomEvent<any>
|
|
24
|
-
}
|
|
25
|
-
slots: {}
|
|
26
|
-
}
|
|
27
|
-
export type BarChartGroupedProps = typeof __propDef.props
|
|
28
|
-
export type BarChartGroupedEvents = typeof __propDef.events
|
|
29
|
-
export type BarChartGroupedSlots = typeof __propDef.slots
|
|
30
|
-
export default class BarChartGrouped extends SvelteComponentTyped<
|
|
31
|
-
BarChartGroupedProps,
|
|
32
|
-
BarChartGroupedEvents,
|
|
33
|
-
BarChartGroupedSlots
|
|
34
|
-
> {}
|
|
35
|
-
export {}
|
|
1
|
+
import { GroupedBarChart as GroupedBarChartCore, type BarChartOptions } from '@carbon/charts'
|
|
2
|
+
import type { ChartProps } from './interfaces'
|
|
3
|
+
declare const BarChartGrouped: import('svelte').Component<
|
|
4
|
+
ChartProps<GroupedBarChartCore, BarChartOptions>,
|
|
5
|
+
{},
|
|
6
|
+
'ref' | 'chart'
|
|
7
|
+
>
|
|
8
|
+
type BarChartGrouped = ReturnType<typeof BarChartGrouped>
|
|
9
|
+
export default BarChartGrouped
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { SimpleBarChart as SimpleBarChartCore } from '@carbon/charts'
|
|
3
3
|
import BaseChart from './BaseChart.svelte'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
let {
|
|
5
|
+
data,
|
|
6
|
+
options,
|
|
7
|
+
ref = $bindable(),
|
|
8
|
+
chart = $bindable(),
|
|
9
|
+
onload,
|
|
10
|
+
onupdate,
|
|
11
|
+
ondestroy,
|
|
12
|
+
...rest
|
|
13
|
+
} = $props()
|
|
8
14
|
</script>
|
|
9
15
|
|
|
10
16
|
<BaseChart
|
|
11
|
-
{...$$restProps}
|
|
12
17
|
Chart={SimpleBarChartCore}
|
|
13
18
|
{options}
|
|
14
19
|
{data}
|
|
15
20
|
bind:ref
|
|
16
21
|
bind:chart
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
{onload}
|
|
23
|
+
{onupdate}
|
|
24
|
+
{ondestroy}
|
|
25
|
+
{...rest} />
|
|
@@ -1,35 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
options: BarChartOptions
|
|
11
|
-
data: ChartTabularData
|
|
12
|
-
chart?: SimpleBarChartCore | undefined
|
|
13
|
-
ref?: HTMLDivElement | undefined
|
|
14
|
-
}
|
|
15
|
-
events: {
|
|
16
|
-
load: CustomEvent<null>
|
|
17
|
-
update: CustomEvent<{
|
|
18
|
-
data: ChartTabularData
|
|
19
|
-
options: import('@carbon/charts').BaseChartOptions
|
|
20
|
-
}>
|
|
21
|
-
destroy: CustomEvent<null>
|
|
22
|
-
} & {
|
|
23
|
-
[evt: string]: CustomEvent<any>
|
|
24
|
-
}
|
|
25
|
-
slots: {}
|
|
26
|
-
}
|
|
27
|
-
export type BarChartSimpleProps = typeof __propDef.props
|
|
28
|
-
export type BarChartSimpleEvents = typeof __propDef.events
|
|
29
|
-
export type BarChartSimpleSlots = typeof __propDef.slots
|
|
30
|
-
export default class BarChartSimple extends SvelteComponentTyped<
|
|
31
|
-
BarChartSimpleProps,
|
|
32
|
-
BarChartSimpleEvents,
|
|
33
|
-
BarChartSimpleSlots
|
|
34
|
-
> {}
|
|
35
|
-
export {}
|
|
1
|
+
import { SimpleBarChart as SimpleBarChartCore, type BarChartOptions } from '@carbon/charts'
|
|
2
|
+
import type { ChartProps } from './interfaces'
|
|
3
|
+
declare const BarChartSimple: import('svelte').Component<
|
|
4
|
+
ChartProps<SimpleBarChartCore, BarChartOptions>,
|
|
5
|
+
{},
|
|
6
|
+
'ref' | 'chart'
|
|
7
|
+
>
|
|
8
|
+
type BarChartSimple = ReturnType<typeof BarChartSimple>
|
|
9
|
+
export default BarChartSimple
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { StackedBarChart as StackedBarChartCore } from '@carbon/charts'
|
|
3
3
|
import BaseChart from './BaseChart.svelte'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
let {
|
|
5
|
+
data,
|
|
6
|
+
options,
|
|
7
|
+
ref = $bindable(),
|
|
8
|
+
chart = $bindable(),
|
|
9
|
+
onload,
|
|
10
|
+
onupdate,
|
|
11
|
+
ondestroy,
|
|
12
|
+
...rest
|
|
13
|
+
} = $props()
|
|
8
14
|
</script>
|
|
9
15
|
|
|
10
16
|
<BaseChart
|
|
11
|
-
{...$$restProps}
|
|
12
17
|
Chart={StackedBarChartCore}
|
|
13
18
|
{options}
|
|
14
19
|
{data}
|
|
15
20
|
bind:ref
|
|
16
21
|
bind:chart
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
{onload}
|
|
23
|
+
{onupdate}
|
|
24
|
+
{ondestroy}
|
|
25
|
+
{...rest} />
|
|
@@ -1,35 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
options: BarChartOptions
|
|
11
|
-
data: ChartTabularData
|
|
12
|
-
chart?: StackedBarChartCore | undefined
|
|
13
|
-
ref?: HTMLDivElement | undefined
|
|
14
|
-
}
|
|
15
|
-
events: {
|
|
16
|
-
load: CustomEvent<null>
|
|
17
|
-
update: CustomEvent<{
|
|
18
|
-
data: ChartTabularData
|
|
19
|
-
options: import('@carbon/charts').BaseChartOptions
|
|
20
|
-
}>
|
|
21
|
-
destroy: CustomEvent<null>
|
|
22
|
-
} & {
|
|
23
|
-
[evt: string]: CustomEvent<any>
|
|
24
|
-
}
|
|
25
|
-
slots: {}
|
|
26
|
-
}
|
|
27
|
-
export type BarChartStackedProps = typeof __propDef.props
|
|
28
|
-
export type BarChartStackedEvents = typeof __propDef.events
|
|
29
|
-
export type BarChartStackedSlots = typeof __propDef.slots
|
|
30
|
-
export default class BarChartStacked extends SvelteComponentTyped<
|
|
31
|
-
BarChartStackedProps,
|
|
32
|
-
BarChartStackedEvents,
|
|
33
|
-
BarChartStackedSlots
|
|
34
|
-
> {}
|
|
35
|
-
export {}
|
|
1
|
+
import { StackedBarChart as StackedBarChartCore, type BarChartOptions } from '@carbon/charts'
|
|
2
|
+
import type { ChartProps } from './interfaces'
|
|
3
|
+
declare const BarChartStacked: import('svelte').Component<
|
|
4
|
+
ChartProps<StackedBarChartCore, BarChartOptions>,
|
|
5
|
+
{},
|
|
6
|
+
'ref' | 'chart'
|
|
7
|
+
>
|
|
8
|
+
type BarChartStacked = ReturnType<typeof BarChartStacked>
|
|
9
|
+
export default BarChartStacked
|
package/dist/BaseChart.svelte
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import { onMount,
|
|
3
|
-
const chartHolderCssClass = 'cds--chart-holder'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
<script>
|
|
2
|
+
import { onMount, onDestroy } from 'svelte'
|
|
3
|
+
const chartHolderCssClass = 'cds--chart-holder'
|
|
4
|
+
let {
|
|
5
|
+
id = `chart-${Math.random().toString(36)}`,
|
|
6
|
+
data = [],
|
|
7
|
+
options = {},
|
|
8
|
+
ref = $bindable(),
|
|
9
|
+
chart = $bindable(),
|
|
10
|
+
Chart,
|
|
11
|
+
onload,
|
|
12
|
+
onupdate,
|
|
13
|
+
ondestroy,
|
|
14
|
+
...rest
|
|
15
|
+
} = $props()
|
|
11
16
|
onMount(() => {
|
|
12
17
|
try {
|
|
13
18
|
chart = new Chart(ref, { data, options })
|
|
14
|
-
|
|
19
|
+
onload?.()
|
|
15
20
|
} catch (error) {
|
|
16
21
|
console.error('Failed to initialize chart:', error)
|
|
17
22
|
}
|
|
18
23
|
})
|
|
19
|
-
|
|
24
|
+
$effect(() => {
|
|
20
25
|
if (chart) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
dispatch('update', { data, options })
|
|
25
|
-
} catch (error) {
|
|
26
|
-
console.error('Failed to update chart:', error)
|
|
27
|
-
}
|
|
26
|
+
chart.model.setData(data)
|
|
27
|
+
chart.model.setOptions(options)
|
|
28
|
+
onupdate?.({ data, options })
|
|
28
29
|
}
|
|
29
30
|
})
|
|
30
31
|
onDestroy(() => {
|
|
31
32
|
if (chart) {
|
|
32
|
-
dispatch('destroy')
|
|
33
|
-
// Like core's Chart.destroy() but keeps div chart holder bound to ref as it's part of this template
|
|
34
33
|
chart.components.forEach(component => component.destroy())
|
|
35
34
|
chart.model.set({ destroyed: true }, { skipUpdate: true })
|
|
36
|
-
chart =
|
|
35
|
+
chart = void 0
|
|
36
|
+
ondestroy?.()
|
|
37
37
|
}
|
|
38
38
|
})
|
|
39
39
|
</script>
|
|
40
40
|
|
|
41
|
-
<div {id} bind:this={ref} class={chartHolderCssClass} {
|
|
41
|
+
<div {id} bind:this={ref} class={chartHolderCssClass} {...rest}></div>
|