@carbon/charts-svelte 1.8.0 → 1.9.0-next.1.0
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 +3 -6
- package/README.md +127 -235
- package/dist/AlluvialChart.svelte +20 -0
- package/dist/AlluvialChart.svelte.d.ts +25 -0
- package/dist/AreaChart.svelte +20 -0
- package/dist/AreaChart.svelte.d.ts +25 -0
- package/dist/BarChartGrouped.svelte +20 -0
- package/dist/BarChartGrouped.svelte.d.ts +25 -0
- package/dist/BarChartSimple.svelte +20 -0
- package/dist/BarChartSimple.svelte.d.ts +25 -0
- package/dist/BarChartStacked.svelte +20 -0
- package/dist/BarChartStacked.svelte.d.ts +25 -0
- package/dist/BaseChart.svelte +35 -0
- package/dist/BaseChart.svelte.d.ts +29 -0
- package/dist/BoxplotChart.svelte +20 -0
- package/dist/BoxplotChart.svelte.d.ts +25 -0
- package/dist/BubbleChart.svelte +20 -0
- package/dist/BubbleChart.svelte.d.ts +25 -0
- package/dist/BulletChart.svelte +20 -0
- package/dist/BulletChart.svelte.d.ts +25 -0
- package/dist/ChoroplethChart.svelte +20 -0
- package/dist/ChoroplethChart.svelte.d.ts +25 -0
- package/dist/CirclePackChart.svelte +20 -0
- package/dist/CirclePackChart.svelte.d.ts +25 -0
- package/dist/ComboChart.svelte +20 -0
- package/dist/ComboChart.svelte.d.ts +25 -0
- package/dist/DonutChart.svelte +20 -0
- package/dist/DonutChart.svelte.d.ts +25 -0
- package/dist/GaugeChart.svelte +20 -0
- package/dist/GaugeChart.svelte.d.ts +25 -0
- package/dist/HeatmapChart.svelte +20 -0
- package/dist/HeatmapChart.svelte.d.ts +25 -0
- package/dist/HistogramChart.svelte +20 -0
- package/dist/HistogramChart.svelte.d.ts +25 -0
- package/dist/LineChart.svelte +20 -0
- package/dist/LineChart.svelte.d.ts +25 -0
- package/dist/LollipopChart.svelte +20 -0
- package/dist/LollipopChart.svelte.d.ts +25 -0
- package/dist/MeterChart.svelte +20 -0
- package/dist/MeterChart.svelte.d.ts +25 -0
- package/dist/PieChart.svelte +20 -0
- package/dist/PieChart.svelte.d.ts +25 -0
- package/dist/RadarChart.svelte +20 -0
- package/dist/RadarChart.svelte.d.ts +25 -0
- package/dist/ScatterChart.svelte +20 -0
- package/dist/ScatterChart.svelte.d.ts +25 -0
- package/dist/StackedAreaChart.svelte +20 -0
- package/dist/StackedAreaChart.svelte.d.ts +25 -0
- package/dist/TreeChart.svelte +20 -0
- package/dist/TreeChart.svelte.d.ts +25 -0
- package/dist/TreemapChart.svelte +20 -0
- package/dist/TreemapChart.svelte.d.ts +25 -0
- package/dist/WordCloudChart.svelte +20 -0
- package/dist/WordCloudChart.svelte.d.ts +25 -0
- package/dist/index.d.ts +26 -0
- package/{src → dist}/index.js +10 -37
- package/dist/styles.css +6345 -0
- package/dist/styles.css.map +1 -0
- package/dist/styles.min.css +1 -0
- package/dist/styles.min.css.map +1 -0
- package/package.json +91 -63
- package/src/AlluvialChart.svelte +0 -16
- package/src/AreaChart.svelte +0 -16
- package/src/BarChartGrouped.svelte +0 -16
- package/src/BarChartSimple.svelte +0 -16
- package/src/BarChartStacked.svelte +0 -16
- package/src/BaseChart.svelte +0 -80
- package/src/BoxplotChart.svelte +0 -16
- package/src/BubbleChart.svelte +0 -16
- package/src/BulletChart.svelte +0 -16
- package/src/ChoroplethChart.svelte +0 -16
- package/src/CirclePackChart.svelte +0 -16
- package/src/ComboChart.svelte +0 -16
- package/src/DonutChart.svelte +0 -16
- package/src/GaugeChart.svelte +0 -16
- package/src/HeatmapChart.svelte +0 -16
- package/src/HistogramChart.svelte +0 -16
- package/src/LineChart.svelte +0 -16
- package/src/LollipopChart.svelte +0 -16
- package/src/MeterChart.svelte +0 -16
- package/src/PieChart.svelte +0 -16
- package/src/RadarChart.svelte +0 -16
- package/src/ScatterChart.svelte +0 -16
- package/src/StackedAreaChart.svelte +0 -16
- package/src/TreeChart.svelte +0 -16
- package/src/TreemapChart.svelte +0 -16
- package/src/WordCloudChart.svelte +0 -16
- package/types/AlluvialChart.d.ts +0 -5
- package/types/AreaChart.d.ts +0 -5
- package/types/BarChartGrouped.d.ts +0 -5
- package/types/BarChartSimple.d.ts +0 -5
- package/types/BarChartStacked.d.ts +0 -5
- package/types/BaseChart.d.ts +0 -69
- package/types/BoxplotChart.d.ts +0 -5
- package/types/BubbleChart.d.ts +0 -5
- package/types/BulletChart.d.ts +0 -5
- package/types/CirclePackChart.d.ts +0 -5
- package/types/ComboChart.d.ts +0 -5
- package/types/DonutChart.d.ts +0 -5
- package/types/GaugeChart.d.ts +0 -5
- package/types/HistogramChart.d.ts +0 -5
- package/types/LineChart.d.ts +0 -5
- package/types/LollipopChart.d.ts +0 -5
- package/types/MeterChart.d.ts +0 -5
- package/types/PieChart.d.ts +0 -5
- package/types/RadarChart.d.ts +0 -5
- package/types/ScatterChart.d.ts +0 -5
- package/types/StackedAreaChart.d.ts +0 -5
- package/types/TreeChart.d.ts +0 -15
- package/types/TreemapChart.d.ts +0 -5
- package/types/WordCloudChart.d.ts +0 -5
- package/types/index.d.ts +0 -23
package/CHANGELOG.md
CHANGED
|
@@ -167,8 +167,7 @@ All notable changes to this project will be documented in this file. See
|
|
|
167
167
|
- **core:** allow theme to be set via options prop
|
|
168
168
|
([#1412](https://github.com/carbon-design-system/carbon-charts/issues/1412))
|
|
169
169
|
([6288548](https://github.com/carbon-design-system/carbon-charts/commit/62885487a700e2222d51f70aea790eddd5d6d086)),
|
|
170
|
-
closes
|
|
171
|
-
[#1411](https://github.com/carbon-design-system/carbon-charts/issues/1411)
|
|
170
|
+
closes [#1411](https://github.com/carbon-design-system/carbon-charts/issues/1411)
|
|
172
171
|
|
|
173
172
|
## [1.3.2](https://github.com/carbon-design-system/carbon-charts/compare/v1.3.1...v1.3.2) (2022-06-30)
|
|
174
173
|
|
|
@@ -374,8 +373,7 @@ All notable changes to this project will be documented in this file. See
|
|
|
374
373
|
|
|
375
374
|
### Features
|
|
376
375
|
|
|
377
|
-
- **svelte:** add TypeScript definitions for Alluvial, Histogram, and Tree
|
|
378
|
-
charts
|
|
376
|
+
- **svelte:** add TypeScript definitions for Alluvial, Histogram, and Tree charts
|
|
379
377
|
([#1219](https://github.com/carbon-design-system/carbon-charts/issues/1219))
|
|
380
378
|
([3e7fcc2](https://github.com/carbon-design-system/carbon-charts/commit/3e7fcc2f16d16d67c4f39f4d4389878b5d829aba))
|
|
381
379
|
|
|
@@ -478,8 +476,7 @@ All notable changes to this project will be documented in this file. See
|
|
|
478
476
|
- **core:** create alluvial chart
|
|
479
477
|
([#1132](https://github.com/carbon-design-system/carbon-charts/issues/1132))
|
|
480
478
|
([08fa194](https://github.com/carbon-design-system/carbon-charts/commit/08fa194f1c59ab2110c0d221886fc0174c936194)),
|
|
481
|
-
closes
|
|
482
|
-
[#871](https://github.com/carbon-design-system/carbon-charts/issues/871)
|
|
479
|
+
closes [#871](https://github.com/carbon-design-system/carbon-charts/issues/871)
|
|
483
480
|
|
|
484
481
|
## [0.48.4](https://github.com/carbon-design-system/carbon-charts/compare/v0.48.3...v0.48.4) (2021-09-13)
|
|
485
482
|
|
package/README.md
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Carbon Charts Svelte
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## `@carbon/charts-svelte`
|
|
6
|
-
|
|
7
|
-
> Carbon Charting Svelte Wrappers
|
|
3
|
+
Carbon Charts Svelte is a thin Svelte wrapper around the vanilla JavScript `@carbon/charts` component library. The charts are based on D3.js, a peer dependency. Documentation is provided below and in the Storybook demos.
|
|
8
4
|
|
|
9
5
|
**[Storybook demos](https://carbon-design-system.github.io/carbon-charts/svelte)**
|
|
10
6
|
|
|
@@ -12,124 +8,78 @@
|
|
|
12
8
|
|
|
13
9
|
## Maintenance & support
|
|
14
10
|
|
|
15
|
-
These Svelte wrappers
|
|
11
|
+
These Svelte wrappers were developed by Eric Liu.
|
|
16
12
|
|
|
17
|
-
Please direct all questions regarding support, bug fixes, and feature requests
|
|
18
|
-
to [@metonym](https://github.com/metonym).
|
|
13
|
+
Please direct all questions regarding support, bug fixes, and feature requests to [@metonym](https://github.com/metonym).
|
|
19
14
|
|
|
20
15
|
## Getting started
|
|
21
16
|
|
|
22
17
|
Run the following command using [npm](https://www.npmjs.com/):
|
|
23
18
|
|
|
24
19
|
```bash
|
|
25
|
-
npm install -D @carbon/charts-svelte d3
|
|
20
|
+
npm install -D @carbon/charts-svelte @carbon/styles d3
|
|
26
21
|
```
|
|
27
22
|
|
|
28
|
-
If you prefer [Yarn](https://yarnpkg.com/en/), use the following command
|
|
29
|
-
instead:
|
|
23
|
+
If you prefer [Yarn](https://yarnpkg.com/en/), use the following command instead:
|
|
30
24
|
|
|
31
25
|
```bash
|
|
32
|
-
yarn add -D @carbon/charts-svelte d3
|
|
26
|
+
yarn add -D @carbon/charts-svelte @carbon/styles d3
|
|
33
27
|
```
|
|
34
28
|
|
|
35
|
-
|
|
36
|
-
bundled version of the library.
|
|
37
|
-
|
|
38
|
-
## Set-up
|
|
29
|
+
## Setup
|
|
39
30
|
|
|
40
|
-
This is an overview of using Carbon Charts with common Svelte
|
|
31
|
+
This is an overview of using Carbon Charts with common Svelte setups.
|
|
41
32
|
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
- [Rollup](#rollup)
|
|
45
|
-
- [Webpack](#webpack)
|
|
33
|
+
- [SvelteKit](#sveltekit)
|
|
34
|
+
- [Vite](#vite)
|
|
46
35
|
|
|
47
36
|
### SvelteKit
|
|
48
37
|
|
|
49
|
-
[SvelteKit](https://github.com/sveltejs/kit) is the official framework for
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
[SvelteKit](https://github.com/sveltejs/kit) is the official framework for building apps that
|
|
39
|
+
support client-side rendering (CSR) and server-side rendering (SSR). SvelteKit is powered by
|
|
40
|
+
[Vite](https://github.com/vitest-dev/vitest).
|
|
52
41
|
|
|
53
|
-
`@carbon/charts` and `carbon-components` should not be externalized for SSR when
|
|
54
|
-
building for production.
|
|
42
|
+
Modules `@carbon/charts` and `carbon-components` should not be externalized for SSR when building for production.
|
|
55
43
|
|
|
56
44
|
```js
|
|
57
45
|
// vite.config.js
|
|
58
|
-
import { sveltekit } from '@sveltejs/kit/vite'
|
|
46
|
+
import { sveltekit } from '@sveltejs/kit/vite'
|
|
59
47
|
|
|
60
48
|
/** @type {import('vite').UserConfig} */
|
|
61
|
-
|
|
49
|
+
const config = {
|
|
62
50
|
plugins: [sveltekit()],
|
|
63
51
|
ssr: {
|
|
64
|
-
noExternal:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
};
|
|
52
|
+
noExternal: process.env.NODE_ENV === 'production' ? ['@carbon/charts', 'carbon-components'] : []
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default config
|
|
70
57
|
```
|
|
71
58
|
|
|
72
59
|
### Vite
|
|
73
60
|
|
|
74
|
-
You can also use Vite without SvelteKit. Instruct `vite` to optimize
|
|
75
|
-
|
|
61
|
+
You can also use Vite without SvelteKit. Instruct `vite` to optimize `@carbon/charts` in
|
|
62
|
+
`vite.config.js`.
|
|
76
63
|
|
|
77
64
|
```js
|
|
78
65
|
// vite.config.js
|
|
79
|
-
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
|
66
|
+
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
|
80
67
|
|
|
81
68
|
/** @type {import('vite').UserConfig} */
|
|
82
|
-
|
|
69
|
+
const config = {
|
|
83
70
|
plugins: [svelte()],
|
|
84
|
-
optimizeDeps: {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
#### ReferenceError: process is not defined
|
|
91
|
-
|
|
92
|
-
Install and add
|
|
93
|
-
[@rollup/plugin-replace](https://github.com/rollup/plugins/tree/master/packages/replace)
|
|
94
|
-
to the list of plugins in `rollup.config.js` to avoid the
|
|
95
|
-
`process is not defined` runtime error.
|
|
96
|
-
|
|
97
|
-
This plugin statically replaces strings in bundled files with the specified
|
|
98
|
-
value.
|
|
99
|
-
|
|
100
|
-
In the example below, all instances of `process.env.NODE_ENV` will be replaced
|
|
101
|
-
with `"production"` while bundling.
|
|
102
|
-
|
|
103
|
-
```js
|
|
104
|
-
// rollup.config.js
|
|
105
|
-
import replace from '@rollup/plugin-replace';
|
|
106
|
-
|
|
107
|
-
export default {
|
|
108
|
-
// ...
|
|
109
|
-
plugins: [
|
|
110
|
-
replace({
|
|
111
|
-
preventAssignment: true,
|
|
112
|
-
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
113
|
-
}),
|
|
114
|
-
],
|
|
115
|
-
};
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
#### `this` has been rewritten to `undefined`
|
|
119
|
-
|
|
120
|
-
Set [`context: "window"`](https://rollupjs.org/guide/en/#context) to address the
|
|
121
|
-
`this has been rewritten to undefined` Rollup error.
|
|
71
|
+
optimizeDeps: {
|
|
72
|
+
include: ['@carbon/charts', 'carbon-components'],
|
|
73
|
+
exclude: ['@carbon/telemetry']
|
|
74
|
+
}
|
|
75
|
+
}
|
|
122
76
|
|
|
123
|
-
|
|
124
|
-
export default {
|
|
125
|
-
+ context: "window",
|
|
126
|
-
};
|
|
77
|
+
export default config
|
|
127
78
|
```
|
|
128
79
|
|
|
129
80
|
#### Circular dependency warnings
|
|
130
81
|
|
|
131
|
-
You may see circular dependency warnings for `d3` and `@carbon/charts` packages
|
|
132
|
-
that can be safely ignored.
|
|
82
|
+
You may see circular dependency warnings for `d3` and `@carbon/charts` packages that can be safely ignored.
|
|
133
83
|
|
|
134
84
|
Use the `onwarn` option to selectively ignore these warnings.
|
|
135
85
|
|
|
@@ -140,101 +90,64 @@ export default {
|
|
|
140
90
|
// omit circular dependency warnings emitted from
|
|
141
91
|
// "d3-*" packages and "@carbon/charts"
|
|
142
92
|
if (warning.code === 'CIRCULAR_DEPENDENCY') {
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
/node_modules\/(d3-|@carbon\/charts)/.test(id)
|
|
146
|
-
)
|
|
147
|
-
) {
|
|
148
|
-
return;
|
|
93
|
+
if (warning.ids.some((id) => /node_modules\/(d3-|@carbon\/charts)/.test(id))) {
|
|
94
|
+
return
|
|
149
95
|
}
|
|
150
96
|
}
|
|
151
97
|
|
|
152
98
|
// preserve all other warnings
|
|
153
|
-
warn(warning)
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
#### Code-splitting
|
|
159
|
-
|
|
160
|
-
If using [dynamic imports](https://rollupjs.org/guide/en/#dynamic-import), use
|
|
161
|
-
`type="module"` alongside `output.dir` for code-splitting.
|
|
162
|
-
|
|
163
|
-
```diff
|
|
164
|
-
# index.html
|
|
165
|
-
- <script src="build/bundle.js"></script>
|
|
166
|
-
+ <script type="module" src="build/index.js"></script>
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
```diff
|
|
170
|
-
# rollup.config.js
|
|
171
|
-
export default {
|
|
172
|
-
output: {
|
|
173
|
-
- format: "iife",
|
|
174
|
-
- file: "public/build/bundle.js",
|
|
175
|
-
+ dir: "public/build",
|
|
176
|
-
}
|
|
99
|
+
warn(warning)
|
|
100
|
+
}
|
|
177
101
|
}
|
|
178
102
|
```
|
|
179
103
|
|
|
180
|
-
### Webpack
|
|
181
|
-
|
|
182
|
-
[Webpack](https://github.com/webpack/webpack) is another popular application
|
|
183
|
-
bundler used to build Svelte apps.
|
|
184
|
-
|
|
185
|
-
No additional configuration should be necessary.
|
|
186
|
-
|
|
187
104
|
## Usage
|
|
188
105
|
|
|
189
|
-
Styles must be imported from both `@carbon/charts` and `@carbon/styles`.
|
|
106
|
+
Styles must be imported from both `@carbon/charts-svelte` and `@carbon/styles`.
|
|
190
107
|
|
|
191
108
|
```js
|
|
192
|
-
import '@carbon/styles/css/styles.css'
|
|
193
|
-
import '@carbon/charts/styles.css'
|
|
109
|
+
import '@carbon/styles/css/styles.css'
|
|
110
|
+
import '@carbon/charts-svelte/styles.css'
|
|
194
111
|
```
|
|
195
112
|
|
|
196
113
|
### Basic
|
|
197
114
|
|
|
198
115
|
```svelte
|
|
199
116
|
<script>
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
117
|
+
import '@carbon/styles/css/styles.css'
|
|
118
|
+
import '@carbon/charts-svelte/styles.css'
|
|
119
|
+
import { BarChartSimple } from '@carbon/charts-svelte'
|
|
203
120
|
</script>
|
|
204
121
|
|
|
205
122
|
<BarChartSimple
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
/>
|
|
222
|
-
|
|
123
|
+
data={[
|
|
124
|
+
{ group: 'Qty', value: 65000 },
|
|
125
|
+
{ group: 'More', value: 29123 },
|
|
126
|
+
{ group: 'Sold', value: 35213 },
|
|
127
|
+
{ group: 'Restocking', value: 51213 },
|
|
128
|
+
{ group: 'Misc', value: 16932 }
|
|
129
|
+
]}
|
|
130
|
+
options={{
|
|
131
|
+
title: 'Simple bar (discrete)',
|
|
132
|
+
height: '400px',
|
|
133
|
+
axes: {
|
|
134
|
+
left: { mapsTo: 'value' },
|
|
135
|
+
bottom: { mapsTo: 'group', scaleType: 'labels' }
|
|
136
|
+
}
|
|
137
|
+
}} />
|
|
223
138
|
```
|
|
224
139
|
|
|
225
140
|
### Theming
|
|
226
141
|
|
|
227
142
|
`@carbon/styles` uses
|
|
228
|
-
[CSS custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties)
|
|
229
|
-
for dynamic, client-side theming. Update the Carbon theme using the `theme`
|
|
230
|
-
prop.
|
|
143
|
+
[CSS custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) for dynamic, client-side theming. Update the Carbon theme using the `theme` prop.
|
|
231
144
|
|
|
232
145
|
Supported themes include:
|
|
233
146
|
|
|
234
|
-
-
|
|
235
|
-
-
|
|
236
|
-
-
|
|
237
|
-
-
|
|
147
|
+
- `"white"`
|
|
148
|
+
- `"g10"` (Gray 10)
|
|
149
|
+
- `"g90"` (Gray 90)
|
|
150
|
+
- `"g100"` (Gray 100)
|
|
238
151
|
|
|
239
152
|
The default theme is `"white"`.
|
|
240
153
|
|
|
@@ -250,20 +163,12 @@ The default theme is `"white"`.
|
|
|
250
163
|
|
|
251
164
|
Each Svelte chart component dispatches the following events:
|
|
252
165
|
|
|
253
|
-
-
|
|
254
|
-
-
|
|
255
|
-
-
|
|
256
|
-
destroyed
|
|
166
|
+
- **on:load**: fired when the chart is instantiated
|
|
167
|
+
- **on:update**: fired when `data` or `options` are updated
|
|
168
|
+
- **on:destroy**: fired when the component is unmounted and the chart is destroyed
|
|
257
169
|
|
|
258
170
|
```svelte
|
|
259
|
-
<BarChartSimple
|
|
260
|
-
{data}
|
|
261
|
-
{options}
|
|
262
|
-
on:load
|
|
263
|
-
on:update
|
|
264
|
-
on:destroy
|
|
265
|
-
/>
|
|
266
|
-
|
|
171
|
+
<BarChartSimple {data} {options} on:load on:update on:destroy />
|
|
267
172
|
```
|
|
268
173
|
|
|
269
174
|
### Dynamic import
|
|
@@ -273,109 +178,98 @@ Dynamically import a chart and instantiate it using the
|
|
|
273
178
|
|
|
274
179
|
```svelte
|
|
275
180
|
<script>
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
181
|
+
import '@carbon/styles/css/styles.css'
|
|
182
|
+
import '@carbon/charts-svelte/styles.css'
|
|
183
|
+
import { onMount } from 'svelte'
|
|
279
184
|
|
|
280
|
-
|
|
185
|
+
let chart
|
|
281
186
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
187
|
+
onMount(async () => {
|
|
188
|
+
const charts = await import('@carbon/charts-svelte')
|
|
189
|
+
chart = charts.BarChartSimple
|
|
190
|
+
})
|
|
286
191
|
</script>
|
|
287
192
|
|
|
288
193
|
<svelte:component
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
/>
|
|
306
|
-
|
|
194
|
+
this={chart}
|
|
195
|
+
data={[
|
|
196
|
+
{ group: 'Qty', value: 65000 },
|
|
197
|
+
{ group: 'More', value: 29123 },
|
|
198
|
+
{ group: 'Sold', value: 35213 },
|
|
199
|
+
{ group: 'Restocking', value: 51213 },
|
|
200
|
+
{ group: 'Misc', value: 16932 }
|
|
201
|
+
]}
|
|
202
|
+
options={{
|
|
203
|
+
title: 'Simple bar (discrete)',
|
|
204
|
+
height: '400px',
|
|
205
|
+
axes: {
|
|
206
|
+
left: { mapsTo: 'value' },
|
|
207
|
+
bottom: { mapsTo: 'group', scaleType: 'labels' }
|
|
208
|
+
}
|
|
209
|
+
}} />
|
|
307
210
|
```
|
|
308
211
|
|
|
309
212
|
### Event listeners
|
|
310
213
|
|
|
311
|
-
In this example, an event listener is attached to the `BarChartSimple` component
|
|
312
|
-
that fires when hovering over a bar.
|
|
214
|
+
In this example, an event listener is attached to the `BarChartSimple` component that fires when hovering over a bar.
|
|
313
215
|
|
|
314
216
|
```svelte
|
|
315
217
|
<script>
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
218
|
+
import '@carbon/styles/css/styles.css'
|
|
219
|
+
import '@carbon/charts-svelte/styles.css'
|
|
220
|
+
import { onMount } from 'svelte'
|
|
221
|
+
import { BarChartSimple } from '@carbon/charts-svelte'
|
|
320
222
|
|
|
321
|
-
|
|
223
|
+
let chart
|
|
322
224
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
225
|
+
function barMouseOver(e) {
|
|
226
|
+
console.log(e.detail)
|
|
227
|
+
}
|
|
326
228
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
229
|
+
onMount(() => {
|
|
230
|
+
return () => {
|
|
231
|
+
if (chart) chart.services.events.removeEventListener('bar-mouseover', barMouseOver)
|
|
232
|
+
}
|
|
233
|
+
})
|
|
332
234
|
|
|
333
|
-
|
|
235
|
+
$: if (chart) chart.services.events.addEventListener('bar-mouseover', barMouseOver)
|
|
334
236
|
</script>
|
|
335
237
|
|
|
336
238
|
<BarChartSimple
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
/>
|
|
354
|
-
|
|
239
|
+
bind:chart
|
|
240
|
+
data={[
|
|
241
|
+
{ group: 'Qty', value: 65000 },
|
|
242
|
+
{ group: 'More', value: 29123 },
|
|
243
|
+
{ group: 'Sold', value: 35213 },
|
|
244
|
+
{ group: 'Restocking', value: 51213 },
|
|
245
|
+
{ group: 'Misc', value: 16932 }
|
|
246
|
+
]}
|
|
247
|
+
options={{
|
|
248
|
+
title: 'Simple bar (discrete)',
|
|
249
|
+
height: '400px',
|
|
250
|
+
axes: {
|
|
251
|
+
left: { mapsTo: 'value' },
|
|
252
|
+
bottom: { mapsTo: 'group', scaleType: 'labels' }
|
|
253
|
+
}
|
|
254
|
+
}} />
|
|
355
255
|
```
|
|
356
256
|
|
|
357
|
-
##
|
|
257
|
+
## CodeSandbox examples
|
|
358
258
|
|
|
359
259
|
[Sample use cases can be seen here](https://carbon-design-system.github.io/carbon-charts/svelte).
|
|
360
260
|
|
|
361
|
-
**When opening the link above**, click on the **Edit on Codesandbox** button for
|
|
362
|
-
each demo to see an isolated project showing you how to reproduce the demo.
|
|
261
|
+
**When opening the link above**, click on the **Edit on Codesandbox** button for each demo to see an isolated project showing you how to reproduce the demo.
|
|
363
262
|
|
|
364
263
|
## Charting data & options
|
|
365
264
|
|
|
366
|
-
Although we will definitely introduce new models in the future as we start
|
|
367
|
-
shipping new components such as maps, Data and options follow the same model in
|
|
368
|
-
all charts, with minor exceptions and differences in specific components.
|
|
265
|
+
Although we will definitely introduce new models in the future as we start shipping new components such as maps, Data and options follow the same model in all charts, with minor exceptions and differences in specific components.
|
|
369
266
|
|
|
370
|
-
For instance in the case of a donut chart you're able to pass in an additional
|
|
371
|
-
field called `center` in your options configuring the donut center.
|
|
267
|
+
For instance, in the case of a donut chart, you're able to pass in an additional field called `center` in your options configuring the donut center.
|
|
372
268
|
|
|
373
269
|
For instructions on using the **tabular data format**, see
|
|
374
270
|
[here](https://carbon-design-system.github.io/carbon-charts/?path=/story/docs-tutorials--tabular-data-format)
|
|
375
271
|
|
|
376
|
-
There are
|
|
377
|
-
used,
|
|
378
|
-
[see our demo examples here](https://github.com/carbon-design-system/carbon-charts/tree/master/packages/core/demo/data).
|
|
272
|
+
There are additional options available depending on the chart type being used, [see our demo examples here](https://github.com/carbon-design-system/carbon-charts/tree/master/packages/core/demo/data).
|
|
379
273
|
|
|
380
274
|
Customizable options (specific to chart type) can be found
|
|
381
275
|
[here](https://carbon-design-system.github.io/carbon-charts/documentation/modules/_interfaces_charts_.html)
|
|
@@ -383,5 +277,3 @@ Customizable options (specific to chart type) can be found
|
|
|
383
277
|
## TypeScript support
|
|
384
278
|
|
|
385
279
|
Svelte version 3.31 or greater is required to use this library with TypeScript.
|
|
386
|
-
|
|
387
|
-
TypeScript definitions are located in the [types folder](types/).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script>import {
|
|
2
|
+
AlluvialChart as AlluvialChartCore
|
|
3
|
+
} from "@carbon/charts";
|
|
4
|
+
import BaseChart from "./BaseChart.svelte";
|
|
5
|
+
export let chart;
|
|
6
|
+
export let options;
|
|
7
|
+
export let data;
|
|
8
|
+
export let ref;
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<BaseChart
|
|
12
|
+
{...$$restProps}
|
|
13
|
+
Chart={AlluvialChartCore}
|
|
14
|
+
{options}
|
|
15
|
+
{data}
|
|
16
|
+
bind:ref
|
|
17
|
+
bind:chart
|
|
18
|
+
on:load
|
|
19
|
+
on:update
|
|
20
|
+
on:destroy />
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import { AlluvialChart as AlluvialChartCore, type AlluvialChartOptions, type ChartTabularData } from '@carbon/charts';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
chart: AlluvialChartCore;
|
|
7
|
+
options: AlluvialChartOptions;
|
|
8
|
+
data: ChartTabularData;
|
|
9
|
+
ref: HTMLDivElement;
|
|
10
|
+
};
|
|
11
|
+
events: {
|
|
12
|
+
load: CustomEvent<any>;
|
|
13
|
+
update: CustomEvent<any>;
|
|
14
|
+
destroy: CustomEvent<any>;
|
|
15
|
+
} & {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
};
|
|
18
|
+
slots: {};
|
|
19
|
+
};
|
|
20
|
+
export type AlluvialChartProps = typeof __propDef.props;
|
|
21
|
+
export type AlluvialChartEvents = typeof __propDef.events;
|
|
22
|
+
export type AlluvialChartSlots = typeof __propDef.slots;
|
|
23
|
+
export default class AlluvialChart extends SvelteComponentTyped<AlluvialChartProps, AlluvialChartEvents, AlluvialChartSlots> {
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script>import {
|
|
2
|
+
AreaChart as AreaChartCore
|
|
3
|
+
} from "@carbon/charts";
|
|
4
|
+
import BaseChart from "./BaseChart.svelte";
|
|
5
|
+
export let chart;
|
|
6
|
+
export let options;
|
|
7
|
+
export let data;
|
|
8
|
+
export let ref;
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<BaseChart
|
|
12
|
+
{...$$restProps}
|
|
13
|
+
Chart={AreaChartCore}
|
|
14
|
+
{options}
|
|
15
|
+
{data}
|
|
16
|
+
bind:ref
|
|
17
|
+
bind:chart
|
|
18
|
+
on:load
|
|
19
|
+
on:update
|
|
20
|
+
on:destroy />
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import { AreaChart as AreaChartCore, type AreaChartOptions, type ChartTabularData } from '@carbon/charts';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
chart: AreaChartCore;
|
|
7
|
+
options: AreaChartOptions;
|
|
8
|
+
data: ChartTabularData;
|
|
9
|
+
ref: HTMLDivElement;
|
|
10
|
+
};
|
|
11
|
+
events: {
|
|
12
|
+
load: CustomEvent<any>;
|
|
13
|
+
update: CustomEvent<any>;
|
|
14
|
+
destroy: CustomEvent<any>;
|
|
15
|
+
} & {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
};
|
|
18
|
+
slots: {};
|
|
19
|
+
};
|
|
20
|
+
export type AreaChartProps = typeof __propDef.props;
|
|
21
|
+
export type AreaChartEvents = typeof __propDef.events;
|
|
22
|
+
export type AreaChartSlots = typeof __propDef.slots;
|
|
23
|
+
export default class AreaChart extends SvelteComponentTyped<AreaChartProps, AreaChartEvents, AreaChartSlots> {
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script>import {
|
|
2
|
+
GroupedBarChart as GroupedBarChartCore
|
|
3
|
+
} from "@carbon/charts";
|
|
4
|
+
import BaseChart from "./BaseChart.svelte";
|
|
5
|
+
export let chart;
|
|
6
|
+
export let options;
|
|
7
|
+
export let data;
|
|
8
|
+
export let ref;
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<BaseChart
|
|
12
|
+
{...$$restProps}
|
|
13
|
+
Chart={GroupedBarChartCore}
|
|
14
|
+
{options}
|
|
15
|
+
{data}
|
|
16
|
+
bind:ref
|
|
17
|
+
bind:chart
|
|
18
|
+
on:load
|
|
19
|
+
on:update
|
|
20
|
+
on:destroy />
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import { GroupedBarChart as GroupedBarChartCore, type BarChartOptions, type ChartTabularData } from '@carbon/charts';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
chart: GroupedBarChartCore;
|
|
7
|
+
options: BarChartOptions;
|
|
8
|
+
data: ChartTabularData;
|
|
9
|
+
ref: HTMLDivElement;
|
|
10
|
+
};
|
|
11
|
+
events: {
|
|
12
|
+
load: CustomEvent<any>;
|
|
13
|
+
update: CustomEvent<any>;
|
|
14
|
+
destroy: CustomEvent<any>;
|
|
15
|
+
} & {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
};
|
|
18
|
+
slots: {};
|
|
19
|
+
};
|
|
20
|
+
export type BarChartGroupedProps = typeof __propDef.props;
|
|
21
|
+
export type BarChartGroupedEvents = typeof __propDef.events;
|
|
22
|
+
export type BarChartGroupedSlots = typeof __propDef.slots;
|
|
23
|
+
export default class BarChartGrouped extends SvelteComponentTyped<BarChartGroupedProps, BarChartGroupedEvents, BarChartGroupedSlots> {
|
|
24
|
+
}
|
|
25
|
+
export {};
|