@rokkit/chart 1.0.0-next.14 → 1.0.0-next.140
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/LICENSE +1 -1
- package/README.md +150 -46
- package/dist/Plot/index.d.ts +5 -0
- package/dist/elements/index.d.ts +6 -0
- package/dist/index.d.ts +14 -0
- package/dist/lib/brewing/axes.svelte.d.ts +66 -0
- package/dist/lib/brewing/bars.svelte.d.ts +56 -0
- package/dist/lib/brewing/dimensions.svelte.d.ts +35 -0
- package/dist/lib/brewing/index.svelte.d.ts +118 -0
- package/dist/lib/brewing/legends.svelte.d.ts +48 -0
- package/dist/lib/brewing/scales.svelte.d.ts +24 -0
- package/dist/lib/brewing/types.d.ts +162 -0
- package/dist/lib/context.d.ts +13 -0
- package/dist/lib/scales.svelte.d.ts +35 -0
- package/dist/lib/utils.d.ts +60 -0
- package/dist/old_lib/brewer.d.ts +9 -0
- package/dist/old_lib/chart.d.ts +40 -0
- package/dist/old_lib/grid.d.ts +72 -0
- package/dist/old_lib/index.d.ts +4 -0
- package/dist/old_lib/plots.d.ts +3 -0
- package/dist/old_lib/swatch.d.ts +285 -0
- package/dist/old_lib/ticks.d.ts +36 -0
- package/dist/old_lib/utils.d.ts +1 -0
- package/dist/patterns/index.d.ts +9 -0
- package/dist/patterns/paths/constants.d.ts +1 -0
- package/dist/symbols/constants/index.d.ts +1 -0
- package/dist/symbols/index.d.ts +5 -0
- package/dist/template/constants.d.ts +43 -0
- package/dist/template/shapes/index.d.ts +4 -0
- package/package.json +34 -44
- package/src/Plot/Axis.svelte +95 -0
- package/src/Plot/Bar.svelte +96 -0
- package/src/Plot/Grid.svelte +68 -0
- package/src/Plot/Legend.svelte +127 -0
- package/src/Plot/Root.svelte +107 -0
- package/src/Plot/index.js +5 -0
- package/src/Symbol.svelte +21 -0
- package/src/Texture.svelte +18 -0
- package/src/elements/Bar.svelte +22 -24
- package/src/elements/ColorRamp.svelte +20 -22
- package/src/elements/ContinuousLegend.svelte +20 -17
- package/src/elements/DefinePatterns.svelte +24 -0
- package/src/elements/DiscreteLegend.svelte +15 -15
- package/src/elements/Label.svelte +4 -8
- package/src/elements/SymbolGrid.svelte +23 -0
- package/src/elements/index.js +6 -0
- package/src/examples/BarChartExample.svelte +81 -0
- package/src/index.js +18 -16
- package/src/lib/brewing/axes.svelte.js +265 -0
- package/src/lib/brewing/bars.svelte.js +177 -0
- package/src/lib/brewing/dimensions.svelte.js +56 -0
- package/src/lib/brewing/index.svelte.js +205 -0
- package/src/lib/brewing/legends.svelte.js +137 -0
- package/src/lib/brewing/scales.svelte.js +106 -0
- package/src/lib/brewing/types.js +73 -0
- package/src/lib/context.js +133 -0
- package/src/lib/scales.svelte.js +172 -0
- package/src/lib/utils.js +107 -120
- package/src/old_lib/brewer.js +25 -0
- package/src/old_lib/chart.js +213 -0
- package/src/old_lib/grid.js +85 -0
- package/src/old_lib/index.js +4 -0
- package/src/old_lib/plots.js +27 -0
- package/src/old_lib/swatch.js +16 -0
- package/src/old_lib/ticks.js +46 -0
- package/src/old_lib/utils.js +8 -0
- package/src/patterns/Brick.svelte +15 -0
- package/src/patterns/Circles.svelte +18 -0
- package/src/patterns/CrossHatch.svelte +12 -0
- package/src/patterns/CurvedWave.svelte +7 -0
- package/src/patterns/Dots.svelte +20 -0
- package/src/patterns/OutlineCircles.svelte +13 -0
- package/src/patterns/README.md +3 -0
- package/src/patterns/Tile.svelte +16 -0
- package/src/patterns/Triangles.svelte +13 -0
- package/src/patterns/Waves.svelte +9 -0
- package/src/patterns/index.js +14 -0
- package/src/patterns/paths/NamedPattern.svelte +9 -0
- package/src/patterns/paths/constants.js +4 -0
- package/src/symbols/RoundedSquare.svelte +33 -0
- package/src/symbols/Shape.svelte +37 -0
- package/src/symbols/constants/index.js +4 -0
- package/src/symbols/index.js +9 -0
- package/src/symbols/outline.svelte +60 -0
- package/src/symbols/solid.svelte +60 -0
- package/src/template/Texture.svelte +13 -0
- package/src/template/constants.js +43 -0
- package/src/template/shapes/Circles.svelte +15 -0
- package/src/template/shapes/Lines.svelte +16 -0
- package/src/template/shapes/Path.svelte +9 -0
- package/src/template/shapes/Polygons.svelte +15 -0
- package/src/template/shapes/index.js +4 -0
- package/src/chart/FacetGrid.svelte +0 -51
- package/src/chart/Grid.svelte +0 -34
- package/src/chart/Legend.svelte +0 -16
- package/src/chart/PatternDefs.svelte +0 -13
- package/src/chart/Swatch.svelte +0 -93
- package/src/chart/SwatchButton.svelte +0 -29
- package/src/chart/SwatchGrid.svelte +0 -55
- package/src/chart/Symbol.svelte +0 -37
- package/src/chart/Texture.svelte +0 -16
- package/src/chart/TexturedShape.svelte +0 -27
- package/src/chart/TimelapseChart.svelte +0 -97
- package/src/chart/Timer.svelte +0 -27
- package/src/chart.js +0 -9
- package/src/components/charts/Axis.svelte +0 -66
- package/src/components/charts/Chart.svelte +0 -35
- package/src/components/index.js +0 -23
- package/src/components/lib/axis.js +0 -0
- package/src/components/lib/chart.js +0 -187
- package/src/components/lib/color.js +0 -327
- package/src/components/lib/funnel.js +0 -204
- package/src/components/lib/index.js +0 -19
- package/src/components/lib/pattern.js +0 -190
- package/src/components/lib/rollup.js +0 -55
- package/src/components/lib/shape.js +0 -199
- package/src/components/lib/summary.js +0 -145
- package/src/components/lib/theme.js +0 -23
- package/src/components/lib/timer.js +0 -41
- package/src/components/lib/utils.js +0 -165
- package/src/components/plots/BarPlot.svelte +0 -36
- package/src/components/plots/BoxPlot.svelte +0 -54
- package/src/components/plots/ScatterPlot.svelte +0 -30
- package/src/components/store.js +0 -70
- package/src/constants.js +0 -66
- package/src/elements/PatternDefs.svelte +0 -13
- package/src/elements/PatternMask.svelte +0 -20
- package/src/elements/Symbol.svelte +0 -38
- package/src/elements/Tooltip.svelte +0 -23
- package/src/funnel.svelte +0 -35
- package/src/geom.js +0 -105
- package/src/lib/axis.js +0 -75
- package/src/lib/colors.js +0 -32
- package/src/lib/geom.js +0 -4
- package/src/lib/shapes.js +0 -144
- package/src/lib/timer.js +0 -44
- package/src/lookup.js +0 -29
- package/src/plots/BarPlot.svelte +0 -55
- package/src/plots/BoxPlot.svelte +0 -0
- package/src/plots/FunnelPlot.svelte +0 -33
- package/src/plots/HeatMap.svelte +0 -5
- package/src/plots/HeatMapCalendar.svelte +0 -129
- package/src/plots/LinePlot.svelte +0 -55
- package/src/plots/Plot.svelte +0 -25
- package/src/plots/RankBarPlot.svelte +0 -38
- package/src/plots/ScatterPlot.svelte +0 -20
- package/src/plots/ViolinPlot.svelte +0 -11
- package/src/plots/heatmap.js +0 -70
- package/src/plots/index.js +0 -10
- package/src/swatch.js +0 -11
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,55 +1,159 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @rokkit/chart
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Data-driven D3 chart components for Svelte 5, inspired by the composable approach of [dc.js](https://dc-js.github.io/dc.js/).
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
- [Svelte](https://svelte.dev/) makes UI development fun again. It provides modularization, interactivity, reactivity, and responsiveness.
|
|
5
|
+
## Install
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
```bash
|
|
8
|
+
bun add @rokkit/chart
|
|
9
|
+
# or
|
|
10
|
+
npm install @rokkit/chart
|
|
11
|
+
```
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
- [Animated, Responsive, and Reactive Data Visualization with Svelte](https://www.infoq.com/news/2020/10/svelte-d3-animation-data-vis/)
|
|
12
|
-
- [Barchart Race using Svelte & D3](https://t.co/iIoJw4f7Jc?amp=1) by [Amelia Wattenberger](https://mobile.twitter.com/Wattenberger) & [Russell Goldenberg](https://mobile.twitter.com/codenberg)
|
|
13
|
-
- [The D3.js Graph Gallery](https://www.d3-graph-gallery.com/index.html)
|
|
14
|
-
- [DC.js](https://dc-js.github.io/dc.js/) is an awesome implementation of interactive animated charts using D3.
|
|
13
|
+
## Overview
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
`@rokkit/chart` provides composable SVG chart components built on D3. All components are placed inside `Plot.Root`, which manages shared state (scales, dimensions, color mapping) via Svelte context. Child components read from that context — you do not wire them together manually.
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
## Usage
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
### Basic bar chart
|
|
20
|
+
|
|
21
|
+
```svelte
|
|
22
|
+
<script>
|
|
23
|
+
import { Plot } from '@rokkit/chart'
|
|
24
|
+
|
|
25
|
+
const data = [
|
|
26
|
+
{ month: 'Jan', sales: 120, returns: 30 },
|
|
27
|
+
{ month: 'Feb', sales: 150, returns: 20 },
|
|
28
|
+
{ month: 'Mar', sales: 90, returns: 40 }
|
|
29
|
+
]
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<Plot.Root {data} width={600} height={400} fill="month">
|
|
33
|
+
<Plot.Grid />
|
|
34
|
+
<Plot.Axis type="x" field="month" label="Month" />
|
|
35
|
+
<Plot.Axis type="y" field="sales" label="Sales" />
|
|
36
|
+
<Plot.Bar x="month" y="sales" />
|
|
37
|
+
<Plot.Legend />
|
|
38
|
+
</Plot.Root>
|
|
22
39
|
```
|
|
23
40
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
### Using `@rokkit/data` for preprocessing
|
|
42
|
+
|
|
43
|
+
```svelte
|
|
44
|
+
<script>
|
|
45
|
+
import { Plot } from '@rokkit/chart'
|
|
46
|
+
import { dataset } from '@rokkit/data'
|
|
47
|
+
|
|
48
|
+
const raw = [
|
|
49
|
+
{ category: 'Electronics', name: 'A', revenue: 450 },
|
|
50
|
+
{ category: 'Clothing', name: 'B', revenue: 320 },
|
|
51
|
+
{ category: 'Electronics', name: 'C', revenue: 620 }
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
const data = dataset(raw)
|
|
55
|
+
.groupBy('category')
|
|
56
|
+
.summarize('name', { total: (vals) => vals.reduce((s, v) => s + v.revenue, 0) })
|
|
57
|
+
.rollup()
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<Plot.Root {data} fill="category" width={500} height={350}>
|
|
61
|
+
<Plot.Axis type="x" field="category" />
|
|
62
|
+
<Plot.Axis type="y" field="total" />
|
|
63
|
+
<Plot.Bar x="category" y="total" />
|
|
64
|
+
<Plot.Legend />
|
|
65
|
+
</Plot.Root>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Using `ChartBrewer` for advanced control
|
|
69
|
+
|
|
70
|
+
`ChartBrewer` is the reactive state manager that `Plot.Root` uses internally. Use it directly when you need programmatic access to scales, axes, or legend state outside of the component tree.
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import { ChartBrewer, createScales, createBars } from '@rokkit/chart'
|
|
74
|
+
|
|
75
|
+
const brewer = new ChartBrewer({
|
|
76
|
+
width: 600,
|
|
77
|
+
height: 400,
|
|
78
|
+
margin: { top: 20, right: 30, bottom: 40, left: 50 },
|
|
79
|
+
padding: 0.2,
|
|
80
|
+
animationDuration: 300
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
brewer.setData(data)
|
|
84
|
+
brewer.setFields({ x: 'month', y: 'sales', color: 'month' })
|
|
85
|
+
brewer.createScales()
|
|
86
|
+
|
|
87
|
+
const scales = brewer.getScales()
|
|
88
|
+
const dimensions = brewer.getDimensions()
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## API
|
|
92
|
+
|
|
93
|
+
### Components (`Plot` namespace)
|
|
94
|
+
|
|
95
|
+
| Component | Description |
|
|
96
|
+
| ------------- | --------------------------------------------------------- |
|
|
97
|
+
| `Plot.Root` | Chart container. Manages dimensions, scales, and context. |
|
|
98
|
+
| `Plot.Bar` | Bar series. Reads x/y fields and renders SVG rects. |
|
|
99
|
+
| `Plot.Axis` | X or Y axis with optional label and tick formatting. |
|
|
100
|
+
| `Plot.Grid` | Background grid lines derived from axis scales. |
|
|
101
|
+
| `Plot.Legend` | Color legend; clicking items filters the visible series. |
|
|
102
|
+
|
|
103
|
+
### `Plot.Root` props
|
|
104
|
+
|
|
105
|
+
| Prop | Type | Default | Description |
|
|
106
|
+
| ------------------- | ------------------ | ------------------------------------- | --------------------------------------------------------------------- |
|
|
107
|
+
| `data` | `array \| dataset` | `[]` | Chart data. Accepts a plain array or a `@rokkit/data` dataset object. |
|
|
108
|
+
| `width` | `number` | `600` | SVG width in pixels. |
|
|
109
|
+
| `height` | `number` | `400` | SVG height in pixels. |
|
|
110
|
+
| `margin` | `object` | `{top:20,right:30,bottom:40,left:50}` | Chart margins. |
|
|
111
|
+
| `fill` | `string` | `null` | Field name used for color mapping. |
|
|
112
|
+
| `responsive` | `boolean` | `true` | Resize with the container. |
|
|
113
|
+
| `animationDuration` | `number` | `300` | Transition duration in ms. |
|
|
114
|
+
|
|
115
|
+
### `Plot.Bar` props
|
|
116
|
+
|
|
117
|
+
| Prop | Type | Default | Description |
|
|
118
|
+
| ------------------- | ---------- | ----------- | --------------------------------------------- |
|
|
119
|
+
| `x` | `string` | — | Field for x-axis values. |
|
|
120
|
+
| `y` | `string` | — | Field for y-axis values. |
|
|
121
|
+
| `fill` | `string` | — | Field for color mapping (overrides root). |
|
|
122
|
+
| `color` | `string` | `'#4682b4'` | Fallback bar color when no fill field is set. |
|
|
123
|
+
| `opacity` | `number` | `1` | Bar opacity. |
|
|
124
|
+
| `animationDuration` | `number` | `300` | Per-bar transition duration in ms. |
|
|
125
|
+
| `onClick` | `function` | `null` | Click handler; receives the data row. |
|
|
126
|
+
|
|
127
|
+
### `Plot.Axis` props
|
|
128
|
+
|
|
129
|
+
| Prop | Type | Default | Description |
|
|
130
|
+
| ------------ | ------------ | ------- | --------------------------------- |
|
|
131
|
+
| `type` | `'x' \| 'y'` | `'x'` | Axis orientation. |
|
|
132
|
+
| `field` | `string` | — | Data field this axis represents. |
|
|
133
|
+
| `label` | `string` | `''` | Axis label. |
|
|
134
|
+
| `ticks` | `number` | — | Suggested tick count. |
|
|
135
|
+
| `tickFormat` | `function` | — | D3 tick formatter. |
|
|
136
|
+
| `grid` | `boolean` | `false` | Render grid lines from this axis. |
|
|
137
|
+
|
|
138
|
+
### Utility functions
|
|
139
|
+
|
|
140
|
+
| Export | Description |
|
|
141
|
+
| ----------------------------------------- | ------------------------------------------- |
|
|
142
|
+
| `createDimensions(width, height, margin)` | Compute chart area dimensions with margins |
|
|
143
|
+
| `createScales(data, fields, dimensions)` | Generate D3 band/linear scales |
|
|
144
|
+
| `createBars(data, scales, fields)` | Compute bar x/y/width/height attributes |
|
|
145
|
+
| `createGroupedBars(data, scales, fields)` | Compute grouped bar layout |
|
|
146
|
+
| `createLegend(data, colorScale)` | Build legend item array |
|
|
147
|
+
| `filterByLegend(data, activeItems)` | Filter data rows by active legend selection |
|
|
148
|
+
| `createXAxis(scale, options)` | Build D3 x-axis descriptor |
|
|
149
|
+
| `createYAxis(scale, options)` | Build D3 y-axis descriptor |
|
|
150
|
+
| `createGrid(scales, dimensions)` | Build grid line descriptors |
|
|
151
|
+
|
|
152
|
+
## Dependencies
|
|
153
|
+
|
|
154
|
+
- `d3-scale`, `d3-axis`, `d3-format`, `d3-selection`, `d3-array`, `d3-transition`, `d3-scale-chromatic`
|
|
155
|
+
- `@rokkit/core`, `@rokkit/data`, `@rokkit/states`
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
Part of [Rokkit](https://github.com/jerrythomas/rokkit) — a Svelte 5 component library and design system.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as Bar } from "./Bar.svelte";
|
|
2
|
+
export { default as ColorRamp } from "./ColorRamp.svelte";
|
|
3
|
+
export { default as ContinuousLegend } from "./ContinuousLegend.svelte";
|
|
4
|
+
export { default as Label } from "./Label.svelte";
|
|
5
|
+
export { default as DefinePatterns } from "./DefinePatterns.svelte";
|
|
6
|
+
export { default as SymbolGrid } from "./SymbolGrid.svelte";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export namespace Plot {
|
|
2
|
+
export { Root };
|
|
3
|
+
export { Axis };
|
|
4
|
+
export { Bar };
|
|
5
|
+
export { Grid };
|
|
6
|
+
export { Legend };
|
|
7
|
+
}
|
|
8
|
+
export { ChartBrewer } from "./lib/brewing/index.svelte.js";
|
|
9
|
+
export * from "./lib/brewing/index.svelte.js";
|
|
10
|
+
import Root from './Plot/Root.svelte';
|
|
11
|
+
import Axis from './Plot/Axis.svelte';
|
|
12
|
+
import Bar from './Plot/Bar.svelte';
|
|
13
|
+
import Grid from './Plot/Grid.svelte';
|
|
14
|
+
import Legend from './Plot/Legend.svelte';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates x-axis tick data for rendering
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} scales - Chart scales
|
|
5
|
+
* @param {Function} scales.x - X-axis scale
|
|
6
|
+
* @param {Object} dimensions - Chart dimensions
|
|
7
|
+
* @param {Object} options - Axis options
|
|
8
|
+
* @param {number} [options.tickCount] - Number of ticks to show
|
|
9
|
+
* @param {Function} [options.tickFormat] - Tick formatting function
|
|
10
|
+
* @param {string} [options.label] - Axis label
|
|
11
|
+
* @returns {AxisData} Axis rendering data
|
|
12
|
+
*/
|
|
13
|
+
export function createXAxis(scales: {
|
|
14
|
+
x: Function;
|
|
15
|
+
}, dimensions: Object, options: {
|
|
16
|
+
tickCount?: number | undefined;
|
|
17
|
+
tickFormat?: Function | undefined;
|
|
18
|
+
label?: string | undefined;
|
|
19
|
+
}): AxisData;
|
|
20
|
+
/**
|
|
21
|
+
* Creates y-axis tick data for rendering
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} scales - Chart scales
|
|
24
|
+
* @param {Function} scales.y - Y-axis scale
|
|
25
|
+
* @param {Object} dimensions - Chart dimensions
|
|
26
|
+
* @param {Object} options - Axis options
|
|
27
|
+
* @param {number} [options.tickCount] - Number of ticks to show
|
|
28
|
+
* @param {Function} [options.tickFormat] - Tick formatting function
|
|
29
|
+
* @param {string} [options.label] - Axis label
|
|
30
|
+
* @returns {AxisData} Axis rendering data
|
|
31
|
+
*/
|
|
32
|
+
export function createYAxis(scales: {
|
|
33
|
+
y: Function;
|
|
34
|
+
}, dimensions: Object, options: {
|
|
35
|
+
tickCount?: number | undefined;
|
|
36
|
+
tickFormat?: Function | undefined;
|
|
37
|
+
label?: string | undefined;
|
|
38
|
+
}): AxisData;
|
|
39
|
+
/**
|
|
40
|
+
* Creates grid line data for rendering
|
|
41
|
+
*
|
|
42
|
+
* @param {Object} scales - Chart scales
|
|
43
|
+
* @param {Object} dimensions - Chart dimensions
|
|
44
|
+
* @param {Object} options - Grid options
|
|
45
|
+
* @param {string} [options.direction='both'] - Grid direction ('x', 'y', or 'both')
|
|
46
|
+
* @param {number} [options.xTickCount] - Number of x-axis ticks
|
|
47
|
+
* @param {number} [options.yTickCount] - Number of y-axis ticks
|
|
48
|
+
* @returns {Object} Grid rendering data
|
|
49
|
+
*/
|
|
50
|
+
export function createGrid(scales: Object, dimensions: Object, options: {
|
|
51
|
+
direction?: string | undefined;
|
|
52
|
+
xTickCount?: number | undefined;
|
|
53
|
+
yTickCount?: number | undefined;
|
|
54
|
+
}): Object;
|
|
55
|
+
/**
|
|
56
|
+
* Creates DOM attributes for a tick element
|
|
57
|
+
*
|
|
58
|
+
* @param {TickData} tick - Tick data
|
|
59
|
+
* @param {string} axis - Axis type ('x' or 'y')
|
|
60
|
+
* @returns {Object} Attributes for the tick
|
|
61
|
+
*/
|
|
62
|
+
export function createTickAttributes(tick: TickData, axis: string): Object;
|
|
63
|
+
export type TickData = import("./types").TickData;
|
|
64
|
+
export type AxisData = import("./types").AxisData;
|
|
65
|
+
export type ChartScales = import("./types").ChartScales;
|
|
66
|
+
export type ChartDimensions = import("./types").ChartDimensions;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates bar data for rendering
|
|
3
|
+
*
|
|
4
|
+
* @param {Array} data - Chart data
|
|
5
|
+
* @param {Object} fields - Field mappings
|
|
6
|
+
* @param {string} fields.x - X-axis field
|
|
7
|
+
* @param {string} fields.y - Y-axis field
|
|
8
|
+
* @param {string} fields.color - Color field (optional)
|
|
9
|
+
* @param {Object} scales - Chart scales
|
|
10
|
+
* @param {Function} scales.x - X-axis scale
|
|
11
|
+
* @param {Function} scales.y - Y-axis scale
|
|
12
|
+
* @param {Function} scales.color - Color scale
|
|
13
|
+
* @param {Object} options - Options including dimensions and defaultColor
|
|
14
|
+
* @param {Object} options.dimensions - Chart dimensions
|
|
15
|
+
* @param {string} [options.defaultColor='#4682b4'] - Default color if no color scale
|
|
16
|
+
* @returns {BarData[]} Bar data for rendering
|
|
17
|
+
*/
|
|
18
|
+
export function createBars(data: any[], fields: {
|
|
19
|
+
x: string;
|
|
20
|
+
y: string;
|
|
21
|
+
color: string;
|
|
22
|
+
}, scales: {
|
|
23
|
+
x: Function;
|
|
24
|
+
y: Function;
|
|
25
|
+
color: Function;
|
|
26
|
+
}, options: {
|
|
27
|
+
dimensions: Object;
|
|
28
|
+
defaultColor?: string | undefined;
|
|
29
|
+
}): BarData[];
|
|
30
|
+
/**
|
|
31
|
+
* Filter bars based on a selection criteria
|
|
32
|
+
*
|
|
33
|
+
* @param {BarData[]} bars - Bar data array
|
|
34
|
+
* @param {Object} selection - Selection criteria
|
|
35
|
+
* @returns {BarData[]} Filtered bars
|
|
36
|
+
*/
|
|
37
|
+
export function filterBars(bars: BarData[], selection: Object): BarData[];
|
|
38
|
+
/**
|
|
39
|
+
* Creates a grouped bars layout
|
|
40
|
+
*
|
|
41
|
+
* @param {Array} data - Chart data
|
|
42
|
+
* @param {Object} fields - Field mappings
|
|
43
|
+
* @param {Object} scales - Chart scales
|
|
44
|
+
* @param {Object} options - Options including dimensions and padding
|
|
45
|
+
* @param {Object} options.dimensions - Chart dimensions
|
|
46
|
+
* @param {number} [options.padding=0.1] - Padding between bars in a group
|
|
47
|
+
* @returns {Object} Grouped bar data
|
|
48
|
+
*/
|
|
49
|
+
export function createGroupedBars(data: any[], fields: Object, scales: Object, options: {
|
|
50
|
+
dimensions: Object;
|
|
51
|
+
padding?: number | undefined;
|
|
52
|
+
}): Object;
|
|
53
|
+
export type BarData = import("./types").BarData;
|
|
54
|
+
export type ScaleFields = import("./types").ScaleFields;
|
|
55
|
+
export type ChartScales = import("./types").ChartScales;
|
|
56
|
+
export type ChartDimensions = import("./types").ChartDimensions;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates chart dimensions based on width, height and margins
|
|
3
|
+
*
|
|
4
|
+
* @param {number} width - Total chart width
|
|
5
|
+
* @param {number} height - Total chart height
|
|
6
|
+
* @param {ChartMargin} margin - Chart margins
|
|
7
|
+
* @returns {ChartDimensions} Chart dimensions
|
|
8
|
+
*/
|
|
9
|
+
export function createDimensions(width?: number, height?: number, margin?: ChartMargin): ChartDimensions;
|
|
10
|
+
/**
|
|
11
|
+
* Updates existing dimensions with new values
|
|
12
|
+
*
|
|
13
|
+
* @param {ChartDimensions} dimensions - Current dimensions
|
|
14
|
+
* @param {Object} updates - Values to update
|
|
15
|
+
* @param {number} [updates.width] - New width
|
|
16
|
+
* @param {number} [updates.height] - New height
|
|
17
|
+
* @param {ChartMargin} [updates.margin] - New margin
|
|
18
|
+
* @returns {ChartDimensions} Updated dimensions
|
|
19
|
+
*/
|
|
20
|
+
export function updateDimensions(dimensions: ChartDimensions, updates?: {
|
|
21
|
+
width?: number | undefined;
|
|
22
|
+
height?: number | undefined;
|
|
23
|
+
margin?: import("./types.js").ChartMargin | undefined;
|
|
24
|
+
}): ChartDimensions;
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {import('./types').ChartMargin} ChartMargin
|
|
27
|
+
* @typedef {import('./types').ChartDimensions} ChartDimensions
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Default chart margin
|
|
31
|
+
* @type {ChartMargin}
|
|
32
|
+
*/
|
|
33
|
+
export const DEFAULT_MARGIN: ChartMargin;
|
|
34
|
+
export type ChartMargin = import("./types").ChartMargin;
|
|
35
|
+
export type ChartDimensions = import("./types").ChartDimensions;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main class that manages chart state and provides access to all brewing functions
|
|
3
|
+
*/
|
|
4
|
+
export class ChartBrewer {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new ChartBrewer instance
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} options Configuration options
|
|
9
|
+
*/
|
|
10
|
+
constructor(options?: Object);
|
|
11
|
+
/**
|
|
12
|
+
* Sets the data for the chart
|
|
13
|
+
*
|
|
14
|
+
* @param {Array} data Data array
|
|
15
|
+
* @returns {ChartBrewer} this for method chaining
|
|
16
|
+
*/
|
|
17
|
+
setData(data: any[]): ChartBrewer;
|
|
18
|
+
/**
|
|
19
|
+
* Sets the field mappings for axes and color
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} fields Field mappings
|
|
22
|
+
* @returns {ChartBrewer} this for method chaining
|
|
23
|
+
*/
|
|
24
|
+
setFields({ x, y, color }: Object): ChartBrewer;
|
|
25
|
+
/**
|
|
26
|
+
* Sets the dimensions of the chart
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} dimensions Chart dimensions
|
|
29
|
+
* @returns {ChartBrewer} this for method chaining
|
|
30
|
+
*/
|
|
31
|
+
setDimensions({ width, height, margin }: Object): ChartBrewer;
|
|
32
|
+
/**
|
|
33
|
+
* Creates scales based on data and dimensions
|
|
34
|
+
*
|
|
35
|
+
* @returns {ChartBrewer} this for method chaining
|
|
36
|
+
*/
|
|
37
|
+
createScales(): ChartBrewer;
|
|
38
|
+
/**
|
|
39
|
+
* Creates bar data for rendering
|
|
40
|
+
*
|
|
41
|
+
* @returns {Array} Data for rendering bars
|
|
42
|
+
*/
|
|
43
|
+
createBars(): any[];
|
|
44
|
+
/**
|
|
45
|
+
* Creates x-axis tick data for rendering
|
|
46
|
+
*
|
|
47
|
+
* @param {Object} options Axis options
|
|
48
|
+
* @returns {Object} Axis rendering data
|
|
49
|
+
*/
|
|
50
|
+
createXAxis(options?: Object): Object;
|
|
51
|
+
/**
|
|
52
|
+
* Creates y-axis tick data for rendering
|
|
53
|
+
*
|
|
54
|
+
* @param {Object} options Axis options
|
|
55
|
+
* @returns {Object} Axis rendering data
|
|
56
|
+
*/
|
|
57
|
+
createYAxis(options?: Object): Object;
|
|
58
|
+
/**
|
|
59
|
+
* Creates grid line data for rendering
|
|
60
|
+
*
|
|
61
|
+
* @param {Object} options Grid options
|
|
62
|
+
* @returns {Object} Grid rendering data
|
|
63
|
+
*/
|
|
64
|
+
createGrid(options?: Object): Object;
|
|
65
|
+
/**
|
|
66
|
+
* Creates legend data for rendering
|
|
67
|
+
*
|
|
68
|
+
* @param {Object} options Legend options
|
|
69
|
+
* @returns {Object} Legend rendering data
|
|
70
|
+
*/
|
|
71
|
+
createLegend(options?: Object): Object;
|
|
72
|
+
/**
|
|
73
|
+
* Gets all chart dimensions
|
|
74
|
+
*
|
|
75
|
+
* @returns {Object} Chart dimensions
|
|
76
|
+
*/
|
|
77
|
+
getDimensions(): Object;
|
|
78
|
+
/**
|
|
79
|
+
* Gets all chart scales
|
|
80
|
+
*
|
|
81
|
+
* @returns {Object} Chart scales
|
|
82
|
+
*/
|
|
83
|
+
getScales(): Object;
|
|
84
|
+
/**
|
|
85
|
+
* Gets the animation duration
|
|
86
|
+
*
|
|
87
|
+
* @returns {number} Animation duration in ms
|
|
88
|
+
*/
|
|
89
|
+
getAnimationDuration(): number;
|
|
90
|
+
/**
|
|
91
|
+
* Gets the data being used
|
|
92
|
+
*
|
|
93
|
+
* @returns {Array} Chart data
|
|
94
|
+
*/
|
|
95
|
+
getData(): any[];
|
|
96
|
+
/**
|
|
97
|
+
* Gets the fields configuration
|
|
98
|
+
*
|
|
99
|
+
* @returns {Object} Fields configuration
|
|
100
|
+
*/
|
|
101
|
+
getFields(): Object;
|
|
102
|
+
#private;
|
|
103
|
+
}
|
|
104
|
+
import { createDimensions } from './dimensions.svelte.js';
|
|
105
|
+
import { updateDimensions } from './dimensions.svelte.js';
|
|
106
|
+
import { createScales } from './scales.svelte.js';
|
|
107
|
+
import { getOrigin } from './scales.svelte.js';
|
|
108
|
+
import { createBars } from './bars.svelte.js';
|
|
109
|
+
import { filterBars } from './bars.svelte.js';
|
|
110
|
+
import { createGroupedBars } from './bars.svelte.js';
|
|
111
|
+
import { createXAxis } from './axes.svelte.js';
|
|
112
|
+
import { createYAxis } from './axes.svelte.js';
|
|
113
|
+
import { createGrid } from './axes.svelte.js';
|
|
114
|
+
import { createTickAttributes } from './axes.svelte.js';
|
|
115
|
+
import { createLegend } from './legends.svelte.js';
|
|
116
|
+
import { filterByLegend } from './legends.svelte.js';
|
|
117
|
+
import { createLegendItemAttributes } from './legends.svelte.js';
|
|
118
|
+
export { createDimensions, updateDimensions, createScales, getOrigin, createBars, filterBars, createGroupedBars, createXAxis, createYAxis, createGrid, createTickAttributes, createLegend, filterByLegend, createLegendItemAttributes };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates legend data for rendering
|
|
3
|
+
*
|
|
4
|
+
* @param {Array} data - Chart data
|
|
5
|
+
* @param {Object} fields - Field mappings
|
|
6
|
+
* @param {string} fields.color - Color field
|
|
7
|
+
* @param {Object} scales - Chart scales
|
|
8
|
+
* @param {Function} scales.color - Color scale
|
|
9
|
+
* @param {Object} options - Legend options including dimensions
|
|
10
|
+
* @param {Object} options.dimensions - Chart dimensions
|
|
11
|
+
* @param {string} [options.title=''] - Legend title
|
|
12
|
+
* @param {string} [options.align='right'] - Legend alignment ('left', 'center', or 'right')
|
|
13
|
+
* @param {string} [options.shape='rect'] - Legend marker shape ('rect' or 'circle')
|
|
14
|
+
* @param {number} [options.markerSize=10] - Size of legend markers
|
|
15
|
+
* @returns {LegendData} Legend rendering data
|
|
16
|
+
*/
|
|
17
|
+
export function createLegend(data: any[], fields: {
|
|
18
|
+
color: string;
|
|
19
|
+
}, scales: {
|
|
20
|
+
color: Function;
|
|
21
|
+
}, options: {
|
|
22
|
+
dimensions: Object;
|
|
23
|
+
title?: string | undefined;
|
|
24
|
+
align?: string | undefined;
|
|
25
|
+
shape?: string | undefined;
|
|
26
|
+
markerSize?: number | undefined;
|
|
27
|
+
}): LegendData;
|
|
28
|
+
/**
|
|
29
|
+
* Filter data based on legend selection
|
|
30
|
+
*
|
|
31
|
+
* @param {Array} data - Chart data
|
|
32
|
+
* @param {string} colorField - Field used for color mapping
|
|
33
|
+
* @param {Array} selectedValues - Selected legend values
|
|
34
|
+
* @returns {Array} Filtered data
|
|
35
|
+
*/
|
|
36
|
+
export function filterByLegend(data: any[], colorField: string, selectedValues: any[]): any[];
|
|
37
|
+
/**
|
|
38
|
+
* Create attributes for legend items
|
|
39
|
+
*
|
|
40
|
+
* @param {LegendItem} item - Legend item
|
|
41
|
+
* @returns {Object} Attributes for the legend item
|
|
42
|
+
*/
|
|
43
|
+
export function createLegendItemAttributes(item: LegendItem): Object;
|
|
44
|
+
export type LegendItem = import("./types").LegendItem;
|
|
45
|
+
export type LegendData = import("./types").LegendData;
|
|
46
|
+
export type ScaleFields = import("./types").ScaleFields;
|
|
47
|
+
export type ChartScales = import("./types").ChartScales;
|
|
48
|
+
export type ChartDimensions = import("./types").ChartDimensions;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates scales based on data, fields, and dimensions
|
|
3
|
+
*
|
|
4
|
+
* @param {Array} data - Chart data
|
|
5
|
+
* @param {ScaleFields} fields - Field mappings
|
|
6
|
+
* @param {Object} dimensions - Chart dimensions
|
|
7
|
+
* @param {Object} options - Scale options
|
|
8
|
+
* @param {number} [options.padding=0.2] - Padding for band scales
|
|
9
|
+
* @returns {ChartScales} Chart scales
|
|
10
|
+
*/
|
|
11
|
+
export function createScales(data: any[], fields: ScaleFields, dimensions: Object, options?: {
|
|
12
|
+
padding?: number | undefined;
|
|
13
|
+
}): ChartScales;
|
|
14
|
+
/**
|
|
15
|
+
* Gets the origin coordinates for the axes
|
|
16
|
+
*
|
|
17
|
+
* @param {ChartScales} scales - Chart scales
|
|
18
|
+
* @param {Object} dimensions - Chart dimensions
|
|
19
|
+
* @returns {Object} Origin coordinates
|
|
20
|
+
*/
|
|
21
|
+
export function getOrigin(scales: ChartScales, dimensions: Object): Object;
|
|
22
|
+
export type ChartScales = import("./types").ChartScales;
|
|
23
|
+
export type ScaleFields = import("./types").ScaleFields;
|
|
24
|
+
export type ChartDimensions = import("./types").ChartDimensions;
|