@rokkit/chart 1.0.0-next.13 → 1.0.0-next.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +140 -46
  2. package/dist/Plot/index.d.ts +5 -0
  3. package/dist/elements/index.d.ts +6 -0
  4. package/dist/index.d.ts +14 -0
  5. package/dist/lib/brewing/axes.svelte.d.ts +72 -0
  6. package/dist/lib/brewing/bars.svelte.d.ts +54 -0
  7. package/dist/lib/brewing/dimensions.svelte.d.ts +35 -0
  8. package/dist/lib/brewing/index.svelte.d.ts +118 -0
  9. package/dist/lib/brewing/legends.svelte.d.ts +54 -0
  10. package/dist/lib/brewing/scales.svelte.d.ts +29 -0
  11. package/dist/lib/brewing/types.d.ts +162 -0
  12. package/dist/lib/context.d.ts +13 -0
  13. package/dist/lib/scales.svelte.d.ts +35 -0
  14. package/dist/lib/utils.d.ts +58 -0
  15. package/dist/old_lib/brewer.d.ts +9 -0
  16. package/dist/old_lib/chart.d.ts +40 -0
  17. package/dist/old_lib/grid.d.ts +72 -0
  18. package/dist/old_lib/index.d.ts +4 -0
  19. package/dist/old_lib/plots.d.ts +3 -0
  20. package/dist/old_lib/swatch.d.ts +285 -0
  21. package/dist/old_lib/ticks.d.ts +36 -0
  22. package/dist/old_lib/utils.d.ts +1 -0
  23. package/dist/patterns/index.d.ts +9 -0
  24. package/dist/patterns/paths/constants.d.ts +1 -0
  25. package/dist/symbols/constants/index.d.ts +1 -0
  26. package/dist/symbols/index.d.ts +5 -0
  27. package/dist/template/constants.d.ts +43 -0
  28. package/dist/template/shapes/index.d.ts +4 -0
  29. package/package.json +28 -44
  30. package/src/Plot/Axis.svelte +95 -0
  31. package/src/Plot/Bar.svelte +96 -0
  32. package/src/Plot/Grid.svelte +68 -0
  33. package/src/Plot/Legend.svelte +127 -0
  34. package/src/Plot/Root.svelte +107 -0
  35. package/src/Plot/index.js +5 -0
  36. package/src/Symbol.svelte +21 -0
  37. package/src/Texture.svelte +10 -0
  38. package/src/elements/Bar.svelte +22 -24
  39. package/src/elements/ColorRamp.svelte +20 -22
  40. package/src/elements/ContinuousLegend.svelte +20 -17
  41. package/src/elements/DefinePatterns.svelte +24 -0
  42. package/src/elements/DiscreteLegend.svelte +15 -15
  43. package/src/elements/Label.svelte +11 -8
  44. package/src/elements/SymbolGrid.svelte +27 -0
  45. package/src/elements/index.js +6 -0
  46. package/src/examples/BarChartExample.svelte +81 -0
  47. package/src/index.js +18 -16
  48. package/src/lib/brewing/axes.svelte.js +177 -0
  49. package/src/lib/brewing/bars.svelte.js +114 -0
  50. package/src/lib/brewing/dimensions.svelte.js +56 -0
  51. package/src/lib/brewing/index.svelte.js +202 -0
  52. package/src/lib/brewing/legends.svelte.js +94 -0
  53. package/src/lib/brewing/scales.svelte.js +85 -0
  54. package/src/lib/brewing/types.js +73 -0
  55. package/src/lib/context.js +132 -0
  56. package/src/lib/scales.svelte.js +122 -0
  57. package/src/lib/utils.js +96 -120
  58. package/src/old_lib/brewer.js +25 -0
  59. package/src/old_lib/chart.js +213 -0
  60. package/src/old_lib/grid.js +85 -0
  61. package/src/old_lib/index.js +4 -0
  62. package/src/old_lib/plots.js +27 -0
  63. package/src/old_lib/swatch.js +16 -0
  64. package/src/old_lib/ticks.js +46 -0
  65. package/src/old_lib/utils.js +8 -0
  66. package/src/patterns/Brick.svelte +15 -0
  67. package/src/patterns/Circles.svelte +18 -0
  68. package/src/patterns/CrossHatch.svelte +12 -0
  69. package/src/patterns/CurvedWave.svelte +7 -0
  70. package/src/patterns/Dots.svelte +20 -0
  71. package/src/patterns/OutlineCircles.svelte +13 -0
  72. package/src/patterns/Tile.svelte +16 -0
  73. package/src/patterns/Triangles.svelte +13 -0
  74. package/src/patterns/Waves.svelte +9 -0
  75. package/src/patterns/index.js +14 -0
  76. package/src/patterns/paths/NamedPattern.svelte +9 -0
  77. package/src/patterns/paths/constants.js +4 -0
  78. package/src/symbols/RoundedSquare.svelte +22 -0
  79. package/src/symbols/Shape.svelte +24 -0
  80. package/src/symbols/constants/index.js +4 -0
  81. package/src/symbols/index.js +9 -0
  82. package/src/symbols/outline.svelte +60 -0
  83. package/src/symbols/solid.svelte +60 -0
  84. package/src/template/Texture.svelte +13 -0
  85. package/src/template/constants.js +43 -0
  86. package/src/template/shapes/Circles.svelte +13 -0
  87. package/src/template/shapes/Lines.svelte +14 -0
  88. package/src/template/shapes/Path.svelte +9 -0
  89. package/src/template/shapes/Polygons.svelte +9 -0
  90. package/src/template/shapes/index.js +4 -0
  91. package/LICENSE +0 -21
  92. package/src/chart/FacetGrid.svelte +0 -51
  93. package/src/chart/Grid.svelte +0 -34
  94. package/src/chart/Legend.svelte +0 -16
  95. package/src/chart/PatternDefs.svelte +0 -13
  96. package/src/chart/Swatch.svelte +0 -93
  97. package/src/chart/SwatchButton.svelte +0 -29
  98. package/src/chart/SwatchGrid.svelte +0 -55
  99. package/src/chart/Symbol.svelte +0 -37
  100. package/src/chart/Texture.svelte +0 -16
  101. package/src/chart/TexturedShape.svelte +0 -27
  102. package/src/chart/TimelapseChart.svelte +0 -97
  103. package/src/chart/Timer.svelte +0 -27
  104. package/src/chart.js +0 -9
  105. package/src/components/charts/Axis.svelte +0 -66
  106. package/src/components/charts/Chart.svelte +0 -35
  107. package/src/components/index.js +0 -23
  108. package/src/components/lib/axis.js +0 -0
  109. package/src/components/lib/chart.js +0 -187
  110. package/src/components/lib/color.js +0 -327
  111. package/src/components/lib/funnel.js +0 -204
  112. package/src/components/lib/index.js +0 -19
  113. package/src/components/lib/pattern.js +0 -190
  114. package/src/components/lib/rollup.js +0 -55
  115. package/src/components/lib/shape.js +0 -199
  116. package/src/components/lib/summary.js +0 -145
  117. package/src/components/lib/theme.js +0 -23
  118. package/src/components/lib/timer.js +0 -41
  119. package/src/components/lib/utils.js +0 -165
  120. package/src/components/plots/BarPlot.svelte +0 -36
  121. package/src/components/plots/BoxPlot.svelte +0 -54
  122. package/src/components/plots/ScatterPlot.svelte +0 -30
  123. package/src/components/store.js +0 -70
  124. package/src/constants.js +0 -66
  125. package/src/elements/PatternDefs.svelte +0 -13
  126. package/src/elements/PatternMask.svelte +0 -20
  127. package/src/elements/Symbol.svelte +0 -38
  128. package/src/elements/Tooltip.svelte +0 -23
  129. package/src/funnel.svelte +0 -35
  130. package/src/geom.js +0 -105
  131. package/src/lib/axis.js +0 -75
  132. package/src/lib/colors.js +0 -32
  133. package/src/lib/geom.js +0 -4
  134. package/src/lib/shapes.js +0 -144
  135. package/src/lib/timer.js +0 -44
  136. package/src/lookup.js +0 -29
  137. package/src/plots/BarPlot.svelte +0 -55
  138. package/src/plots/BoxPlot.svelte +0 -0
  139. package/src/plots/FunnelPlot.svelte +0 -33
  140. package/src/plots/HeatMap.svelte +0 -5
  141. package/src/plots/HeatMapCalendar.svelte +0 -129
  142. package/src/plots/LinePlot.svelte +0 -55
  143. package/src/plots/Plot.svelte +0 -25
  144. package/src/plots/RankBarPlot.svelte +0 -38
  145. package/src/plots/ScatterPlot.svelte +0 -20
  146. package/src/plots/ViolinPlot.svelte +0 -11
  147. package/src/plots/heatmap.js +0 -70
  148. package/src/plots/index.js +0 -10
  149. package/src/swatch.js +0 -11
package/README.md CHANGED
@@ -1,55 +1,149 @@
1
- # Charts for Svelte
1
+ # @rokkit/chart
2
2
 
3
- The core idea behind the implementation is to use the respective strengths of both D3 and Svelte to build Themable, Composable, Animated, Responsive, Accessible, and Reactive Data Visualization components.
3
+ Data-driven chart components for Svelte inspired by [dc.js](https://dc-js.github.io/dc.js/docs/stock.html). This package combines the power of D3.js with the reactivity and component-based approach of Svelte.
4
4
 
5
- - [D3](https://d3js.org/) makes working with SVG a breeze. It provides a large set of utility functions for graph visualization that includes the computation of scales, interpolation, shapes, and more.
6
- - [Svelte](https://svelte.dev/) makes UI development fun again. It provides modularization, interactivity, reactivity, and responsiveness.
5
+ ## Installation
7
6
 
8
- This component library borrows concepts from the following articles, products, and repositories.
7
+ ```bash
8
+ bun add @rokkit/chart
9
+ ```
9
10
 
10
- - [Introduction to Accessible Contrast and Color for Data Visualization](https://observablehq.com/@frankelavsky/chartability-contrast-series) by [Frank Elavsky](https://observablehq.com/@frankelavsky)
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.
11
+ ## Usage
15
12
 
16
- ## Getting Started
13
+ The chart package provides a set of composable components that can be combined to create various chart types.
17
14
 
18
- Get started quickly using [degit](https://github.com/Rich-Harris/degit).
15
+ ### Basic Bar Chart Example
19
16
 
20
- ```bash
21
- degit jerrythomas/sparsh-ui/sites/playground my-app
17
+ ```svelte
18
+ <script>
19
+ import { Plot } from '@rokkit/chart'
20
+ import { dataset } from '@rokkit/data'
21
+
22
+ // Sample data
23
+ const sampleData = [
24
+ { model: 'Model A', name: 'Product 1', category: 'Electronics', count: 45 },
25
+ { model: 'Model B', name: 'Product 2', category: 'Clothing', count: 32 },
26
+ { model: 'Model C', name: 'Product 3', category: 'Electronics', count: 62 }
27
+ // More data...
28
+ ]
29
+
30
+ // Use the dataset class to process the data
31
+ let data = dataset(sampleData)
32
+ .groupBy('model')
33
+ .summarize('name', { count: (values) => values.length })
34
+ .rollup()
35
+ </script>
36
+
37
+ <Plot.Root {data} width={600} height={400} margin={{ top: 20, right: 30, bottom: 40, left: 50 }}>
38
+ <Plot.Grid direction="y" />
39
+ <Plot.Axis type="x" field="model" label="Model" />
40
+ <Plot.Axis type="y" field="count" label="Count" />
41
+ <Plot.Bar x="model" y="count" fill="category" />
42
+ <Plot.Legend title="Categories" />
43
+ </Plot.Root>
22
44
  ```
23
45
 
24
- ## Features
25
-
26
- - [x] Fill patterns
27
- - [x] Symbols
28
- - [x] Colors
29
- - [ ] Themes
30
-
31
- ### Plots
32
-
33
- - [x] Box
34
- - [ ] Violin
35
- - [x] Scatter
36
- - [ ] Line
37
- - [ ] Histogram
38
- - [ ] StackedBar
39
- - [ ] Funnel
40
-
41
- ### Chart
42
-
43
- - [x] Axis
44
- - [x] Labels
45
- - [x] Grid
46
- - [x] Ticks
47
- - [ ] Margins
48
- - [ ] Legend
49
- - [ ] Composable
50
- - [ ] Facet Grid
51
- - [ ] Combine multiple plots
52
- - [ ] Animation
53
- - [ ] Time lapse
54
- - [ ] Sliding window
55
- - [ ] Rolling window
46
+ ## Available Components
47
+
48
+ ### Plot.Root
49
+
50
+ The container component for all charts.
51
+
52
+ **Props:**
53
+
54
+ - `data` - The dataset to visualize (array or dataset object)
55
+ - `width` - Width of the chart in pixels (default: 600)
56
+ - `height` - Height of the chart in pixels (default: 400)
57
+ - `margin` - Object with top, right, bottom, left margins (default: `{ top: 20, right: 30, bottom: 40, left: 50 }`)
58
+ - `fill` - Field to use for color mapping (optional)
59
+ - `responsive` - Whether to make the chart responsive (default: true)
60
+ - `animationDuration` - Duration of animations in milliseconds (default: 300)
61
+
62
+ ### Plot.Axis
63
+
64
+ Renders an axis for the chart.
65
+
66
+ **Props:**
67
+
68
+ - `type` - Type of axis ('x' or 'y')
69
+ - `field` - Data field to use for this axis
70
+ - `label` - Axis label text
71
+ - `ticks` - Number of ticks to display (optional)
72
+ - `tickFormat` - Function to format tick labels (optional)
73
+ - `grid` - Whether to show grid lines (default: false)
74
+
75
+ ### Plot.Bar
76
+
77
+ Renders a bar chart.
78
+
79
+ **Props:**
80
+
81
+ - `x` - Field to use for x-axis values
82
+ - `y` - Field to use for y-axis values
83
+ - `fill` - Field to use for coloring the bars (optional)
84
+ - `color` - Fixed color for bars if fill is not provided (default: "#4682b4")
85
+ - `opacity` - Opacity of the bars (default: 1)
86
+ - `animationDuration` - Duration of animations in milliseconds (default: 300)
87
+ - `onClick` - Callback for click events on bars (optional)
88
+
89
+ ### Plot.Grid
90
+
91
+ Renders grid lines for the chart.
92
+
93
+ **Props:**
94
+
95
+ - `direction` - Direction of grid lines ('x', 'y', or 'both') (default: 'both')
96
+ - `xTicks` - Number of ticks for x-axis grid (optional)
97
+ - `yTicks` - Number of ticks for y-axis grid (optional)
98
+ - `color` - Color of grid lines (default: 'currentColor')
99
+ - `opacity` - Opacity of grid lines (default: 0.1)
100
+ - `lineStyle` - Line style for grid lines ('solid', 'dashed', 'dotted') (default: 'solid')
101
+
102
+ ### Plot.Legend
103
+
104
+ Renders a legend for the chart.
105
+
106
+ **Props:**
107
+
108
+ - `title` - Title for the legend (optional)
109
+ - `align` - Alignment of the legend ('left', 'right', 'center') (default: 'right')
110
+ - `verticalAlign` - Vertical position of the legend ('top', 'bottom') (default: 'top')
111
+ - `shape` - Shape for legend items ('circle', 'rect') (default: 'rect')
112
+ - `markerSize` - Size of the legend markers (default: 10)
113
+ - `onClick` - Callback when a legend item is clicked (optional)
114
+
115
+ ## Using with Rokkit Dataset Class
116
+
117
+ The chart components work seamlessly with the `@rokkit/data` package, allowing for powerful data transformations:
118
+
119
+ ```svelte
120
+ <script>
121
+ import { Plot } from '@rokkit/chart'
122
+ import { dataset } from '@rokkit/data'
123
+
124
+ let input = [
125
+ // Your raw data here
126
+ ]
127
+
128
+ $: processedData = dataset(input)
129
+ .groupBy('category')
130
+ .summarize('name', {
131
+ count: (values) => values.length,
132
+ total: (values) => values.reduce((a, b) => a + b, 0)
133
+ })
134
+ .rollup()
135
+ </script>
136
+
137
+ <Plot.Root data={processedData} fill="category">
138
+ <Plot.Axis type="x" field="category" />
139
+ <Plot.Axis type="y" field="count" />
140
+ <Plot.Bar x="category" y="count" />
141
+ </Plot.Root>
142
+ ```
143
+
144
+ ## Advanced Features
145
+
146
+ - Tooltips are automatically generated for data points
147
+ - Interactive legends for filtering data
148
+ - Responsive design by default
149
+ - Animated transitions when data changes
@@ -0,0 +1,5 @@
1
+ export { default as Root } from "./Root.svelte";
2
+ export { default as Axis } from "./Axis.svelte";
3
+ export { default as Bar } from "./Bar.svelte";
4
+ export { default as Legend } from "./Legend.svelte";
5
+ export { default as Grid } from "./Grid.svelte";
@@ -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";
@@ -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,72 @@
1
+ /**
2
+ * @typedef {import('./types').TickData} TickData
3
+ * @typedef {import('./types').AxisData} AxisData
4
+ * @typedef {import('./types').ChartScales} ChartScales
5
+ * @typedef {import('./types').ChartDimensions} ChartDimensions
6
+ */
7
+ /**
8
+ * Creates x-axis tick data for rendering
9
+ *
10
+ * @param {Object} scales - Chart scales
11
+ * @param {Function} scales.x - X-axis scale
12
+ * @param {Object} dimensions - Chart dimensions
13
+ * @param {Object} options - Axis options
14
+ * @param {number} [options.tickCount] - Number of ticks to show
15
+ * @param {Function} [options.tickFormat] - Tick formatting function
16
+ * @param {string} [options.label] - Axis label
17
+ * @returns {AxisData} Axis rendering data
18
+ */
19
+ export function createXAxis(scales: {
20
+ x: Function;
21
+ }, dimensions: Object, options?: {
22
+ tickCount?: number | undefined;
23
+ tickFormat?: Function | undefined;
24
+ label?: string | undefined;
25
+ }): AxisData;
26
+ /**
27
+ * Creates y-axis tick data for rendering
28
+ *
29
+ * @param {Object} scales - Chart scales
30
+ * @param {Function} scales.y - Y-axis scale
31
+ * @param {Object} dimensions - Chart dimensions
32
+ * @param {Object} options - Axis options
33
+ * @param {number} [options.tickCount] - Number of ticks to show
34
+ * @param {Function} [options.tickFormat] - Tick formatting function
35
+ * @param {string} [options.label] - Axis label
36
+ * @returns {AxisData} Axis rendering data
37
+ */
38
+ export function createYAxis(scales: {
39
+ y: Function;
40
+ }, dimensions: Object, options?: {
41
+ tickCount?: number | undefined;
42
+ tickFormat?: Function | undefined;
43
+ label?: string | undefined;
44
+ }): AxisData;
45
+ /**
46
+ * Creates grid line data for rendering
47
+ *
48
+ * @param {Object} scales - Chart scales
49
+ * @param {Object} dimensions - Chart dimensions
50
+ * @param {Object} options - Grid options
51
+ * @param {string} [options.direction='both'] - Grid direction ('x', 'y', or 'both')
52
+ * @param {number} [options.xTickCount] - Number of x-axis ticks
53
+ * @param {number} [options.yTickCount] - Number of y-axis ticks
54
+ * @returns {Object} Grid rendering data
55
+ */
56
+ export function createGrid(scales: Object, dimensions: Object, options?: {
57
+ direction?: string | undefined;
58
+ xTickCount?: number | undefined;
59
+ yTickCount?: number | undefined;
60
+ }): Object;
61
+ /**
62
+ * Creates DOM attributes for a tick element
63
+ *
64
+ * @param {TickData} tick - Tick data
65
+ * @param {string} axis - Axis type ('x' or 'y')
66
+ * @returns {Object} Attributes for the tick
67
+ */
68
+ export function createTickAttributes(tick: TickData, axis: string): Object;
69
+ export type TickData = import("./types").TickData;
70
+ export type AxisData = import("./types").AxisData;
71
+ export type ChartScales = import("./types").ChartScales;
72
+ export type ChartDimensions = import("./types").ChartDimensions;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @typedef {import('./types').BarData} BarData
3
+ * @typedef {import('./types').ScaleFields} ScaleFields
4
+ * @typedef {import('./types').ChartScales} ChartScales
5
+ * @typedef {import('./types').ChartDimensions} ChartDimensions
6
+ */
7
+ /**
8
+ * Creates bar data for rendering
9
+ *
10
+ * @param {Array} data - Chart data
11
+ * @param {Object} fields - Field mappings
12
+ * @param {string} fields.x - X-axis field
13
+ * @param {string} fields.y - Y-axis field
14
+ * @param {string} fields.color - Color field (optional)
15
+ * @param {Object} scales - Chart scales
16
+ * @param {Function} scales.x - X-axis scale
17
+ * @param {Function} scales.y - Y-axis scale
18
+ * @param {Function} scales.color - Color scale
19
+ * @param {Object} dimensions - Chart dimensions
20
+ * @param {string} defaultColor - Default color if no color scale is provided
21
+ * @returns {BarData[]} Bar data for rendering
22
+ */
23
+ export function createBars(data: any[], fields: {
24
+ x: string;
25
+ y: string;
26
+ color: string;
27
+ }, scales: {
28
+ x: Function;
29
+ y: Function;
30
+ color: Function;
31
+ }, dimensions: Object, defaultColor?: string): BarData[];
32
+ /**
33
+ * Filter bars based on a selection criteria
34
+ *
35
+ * @param {BarData[]} bars - Bar data array
36
+ * @param {Object} selection - Selection criteria
37
+ * @returns {BarData[]} Filtered bars
38
+ */
39
+ export function filterBars(bars: BarData[], selection: Object): BarData[];
40
+ /**
41
+ * Creates a grouped bars layout
42
+ *
43
+ * @param {Array} data - Chart data
44
+ * @param {Object} fields - Field mappings
45
+ * @param {Object} scales - Chart scales
46
+ * @param {Object} dimensions - Chart dimensions
47
+ * @param {Object} options - Options
48
+ * @returns {Object} Grouped bar data
49
+ */
50
+ export function createGroupedBars(data: any[], fields: Object, scales: Object, dimensions: Object, options?: Object): Object;
51
+ export type BarData = import("./types").BarData;
52
+ export type ScaleFields = import("./types").ScaleFields;
53
+ export type ChartScales = import("./types").ChartScales;
54
+ 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,54 @@
1
+ /**
2
+ * @typedef {import('./types').LegendItem} LegendItem
3
+ * @typedef {import('./types').LegendData} LegendData
4
+ * @typedef {import('./types').ScaleFields} ScaleFields
5
+ * @typedef {import('./types').ChartScales} ChartScales
6
+ * @typedef {import('./types').ChartDimensions} ChartDimensions
7
+ */
8
+ /**
9
+ * Creates legend data for rendering
10
+ *
11
+ * @param {Array} data - Chart data
12
+ * @param {Object} fields - Field mappings
13
+ * @param {string} fields.color - Color field
14
+ * @param {Object} scales - Chart scales
15
+ * @param {Function} scales.color - Color scale
16
+ * @param {Object} dimensions - Chart dimensions
17
+ * @param {Object} options - Legend options
18
+ * @param {string} [options.title=''] - Legend title
19
+ * @param {string} [options.align='right'] - Legend alignment ('left', 'center', or 'right')
20
+ * @param {string} [options.shape='rect'] - Legend marker shape ('rect' or 'circle')
21
+ * @param {number} [options.markerSize=10] - Size of legend markers
22
+ * @returns {LegendData} Legend rendering data
23
+ */
24
+ export function createLegend(data: any[], fields: {
25
+ color: string;
26
+ }, scales: {
27
+ color: Function;
28
+ }, dimensions: Object, options?: {
29
+ title?: string | undefined;
30
+ align?: string | undefined;
31
+ shape?: string | undefined;
32
+ markerSize?: number | undefined;
33
+ }): LegendData;
34
+ /**
35
+ * Filter data based on legend selection
36
+ *
37
+ * @param {Array} data - Chart data
38
+ * @param {string} colorField - Field used for color mapping
39
+ * @param {Array} selectedValues - Selected legend values
40
+ * @returns {Array} Filtered data
41
+ */
42
+ export function filterByLegend(data: any[], colorField: string, selectedValues: any[]): any[];
43
+ /**
44
+ * Create attributes for legend items
45
+ *
46
+ * @param {LegendItem} item - Legend item
47
+ * @returns {Object} Attributes for the legend item
48
+ */
49
+ export function createLegendItemAttributes(item: LegendItem): Object;
50
+ export type LegendItem = import("./types").LegendItem;
51
+ export type LegendData = import("./types").LegendData;
52
+ export type ScaleFields = import("./types").ScaleFields;
53
+ export type ChartScales = import("./types").ChartScales;
54
+ export type ChartDimensions = import("./types").ChartDimensions;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @typedef {import('./types').ChartScales} ChartScales
3
+ * @typedef {import('./types').ScaleFields} ScaleFields
4
+ * @typedef {import('./types').ChartDimensions} ChartDimensions
5
+ */
6
+ /**
7
+ * Creates scales based on data, fields, and dimensions
8
+ *
9
+ * @param {Array} data - Chart data
10
+ * @param {ScaleFields} fields - Field mappings
11
+ * @param {Object} dimensions - Chart dimensions
12
+ * @param {Object} options - Scale options
13
+ * @param {number} [options.padding=0.2] - Padding for band scales
14
+ * @returns {ChartScales} Chart scales
15
+ */
16
+ export function createScales(data: any[], fields: ScaleFields, dimensions: Object, options?: {
17
+ padding?: number | undefined;
18
+ }): ChartScales;
19
+ /**
20
+ * Gets the origin coordinates for the axes
21
+ *
22
+ * @param {ChartScales} scales - Chart scales
23
+ * @param {Object} dimensions - Chart dimensions
24
+ * @returns {Object} Origin coordinates
25
+ */
26
+ export function getOrigin(scales: ChartScales, dimensions: Object): Object;
27
+ export type ChartScales = import("./types").ChartScales;
28
+ export type ScaleFields = import("./types").ScaleFields;
29
+ export type ChartDimensions = import("./types").ChartDimensions;