@rokkit/chart 1.0.0-next.16 → 1.0.0-next.160

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 (173) hide show
  1. package/README.md +150 -46
  2. package/package.json +42 -45
  3. package/src/AnimatedPlot.svelte +383 -0
  4. package/src/Chart.svelte +95 -0
  5. package/src/ChartProvider.svelte +10 -0
  6. package/src/FacetPlot/Panel.svelte +37 -0
  7. package/src/FacetPlot.svelte +114 -0
  8. package/src/Plot/Arc.svelte +29 -0
  9. package/src/Plot/Area.svelte +32 -0
  10. package/src/Plot/Axis.svelte +95 -0
  11. package/src/Plot/Bar.svelte +54 -0
  12. package/src/Plot/Grid.svelte +34 -0
  13. package/src/Plot/Legend.svelte +233 -0
  14. package/src/Plot/Line.svelte +37 -0
  15. package/src/Plot/Point.svelte +40 -0
  16. package/src/Plot/Root.svelte +62 -0
  17. package/src/Plot/Timeline.svelte +95 -0
  18. package/src/Plot/Tooltip.svelte +87 -0
  19. package/src/Plot/index.js +9 -0
  20. package/src/Plot.svelte +297 -0
  21. package/src/PlotState.svelte.js +350 -0
  22. package/src/Sparkline.svelte +108 -0
  23. package/src/Symbol.svelte +21 -0
  24. package/src/Texture.svelte +18 -0
  25. package/src/charts/AreaChart.svelte +27 -0
  26. package/src/charts/BarChart.svelte +28 -0
  27. package/src/charts/BoxPlot.svelte +21 -0
  28. package/src/charts/BubbleChart.svelte +23 -0
  29. package/src/charts/LineChart.svelte +26 -0
  30. package/src/charts/PieChart.svelte +35 -0
  31. package/src/charts/ScatterPlot.svelte +26 -0
  32. package/src/charts/ViolinPlot.svelte +21 -0
  33. package/src/crossfilter/CrossFilter.svelte +42 -0
  34. package/src/crossfilter/FilterBar.svelte +24 -0
  35. package/src/crossfilter/FilterHistogram.svelte +290 -0
  36. package/src/crossfilter/FilterSlider.svelte +83 -0
  37. package/src/crossfilter/createCrossFilter.svelte.js +124 -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 +4 -8
  44. package/src/elements/SymbolGrid.svelte +22 -0
  45. package/src/elements/index.js +6 -0
  46. package/src/examples/BarChartExample.svelte +81 -0
  47. package/src/geoms/Arc.svelte +126 -0
  48. package/src/geoms/Area.svelte +78 -0
  49. package/src/geoms/Bar.svelte +200 -0
  50. package/src/geoms/Box.svelte +113 -0
  51. package/src/geoms/LabelPill.svelte +17 -0
  52. package/src/geoms/Line.svelte +123 -0
  53. package/src/geoms/Point.svelte +145 -0
  54. package/src/geoms/Violin.svelte +56 -0
  55. package/src/geoms/lib/areas.js +154 -0
  56. package/src/geoms/lib/bars.js +223 -0
  57. package/src/index.js +74 -16
  58. package/src/lib/brewer.js +25 -0
  59. package/src/lib/brewing/BoxBrewer.svelte.js +14 -0
  60. package/src/lib/brewing/CartesianBrewer.svelte.js +21 -0
  61. package/src/lib/brewing/PieBrewer.svelte.js +14 -0
  62. package/src/lib/brewing/QuartileBrewer.svelte.js +51 -0
  63. package/src/lib/brewing/ViolinBrewer.svelte.js +14 -0
  64. package/src/lib/brewing/axes.svelte.js +270 -0
  65. package/src/lib/brewing/bars.svelte.js +201 -0
  66. package/src/lib/brewing/brewer.svelte.js +277 -0
  67. package/src/lib/brewing/colors.js +51 -0
  68. package/src/lib/brewing/dimensions.svelte.js +56 -0
  69. package/src/lib/brewing/index.svelte.js +205 -0
  70. package/src/lib/brewing/legends.svelte.js +137 -0
  71. package/src/lib/brewing/marks/arcs.js +43 -0
  72. package/src/lib/brewing/marks/areas.js +72 -0
  73. package/src/lib/brewing/marks/bars.js +49 -0
  74. package/src/lib/brewing/marks/boxes.js +75 -0
  75. package/src/lib/brewing/marks/lines.js +55 -0
  76. package/src/lib/brewing/marks/points.js +105 -0
  77. package/src/lib/brewing/marks/violins.js +90 -0
  78. package/src/lib/brewing/patterns.js +45 -0
  79. package/src/lib/brewing/scales.js +51 -0
  80. package/src/lib/brewing/scales.svelte.js +82 -0
  81. package/src/lib/brewing/stats.js +74 -0
  82. package/src/lib/brewing/symbols.js +10 -0
  83. package/src/lib/brewing/types.js +73 -0
  84. package/src/lib/chart.js +221 -0
  85. package/src/lib/context.js +131 -0
  86. package/src/lib/grid.js +85 -0
  87. package/src/lib/keyboard-nav.js +37 -0
  88. package/src/lib/plot/chartProps.js +76 -0
  89. package/src/lib/plot/crossfilter.js +16 -0
  90. package/src/lib/plot/facet.js +58 -0
  91. package/src/lib/plot/frames.js +81 -0
  92. package/src/lib/plot/helpers.js +14 -0
  93. package/src/lib/plot/preset.js +67 -0
  94. package/src/lib/plot/scales.js +81 -0
  95. package/src/lib/plot/stat.js +92 -0
  96. package/src/lib/plot/types.js +65 -0
  97. package/src/lib/preset.js +41 -0
  98. package/src/lib/scales.svelte.js +151 -0
  99. package/src/lib/swatch.js +13 -0
  100. package/src/lib/ticks.js +46 -0
  101. package/src/lib/utils.js +111 -118
  102. package/src/lib/xscale.js +31 -0
  103. package/src/patterns/DefinePatterns.svelte +32 -0
  104. package/src/patterns/PatternDef.svelte +27 -0
  105. package/src/patterns/index.js +4 -0
  106. package/src/patterns/patterns.js +360 -0
  107. package/src/patterns/scale.js +116 -0
  108. package/src/spec/chart-spec.js +72 -0
  109. package/src/symbols/RoundedSquare.svelte +33 -0
  110. package/src/symbols/Shape.svelte +37 -0
  111. package/src/symbols/constants/index.js +4 -0
  112. package/src/symbols/index.js +9 -0
  113. package/src/symbols/outline.svelte +60 -0
  114. package/src/symbols/solid.svelte +60 -0
  115. package/LICENSE +0 -21
  116. package/src/chart/FacetGrid.svelte +0 -51
  117. package/src/chart/Grid.svelte +0 -34
  118. package/src/chart/Legend.svelte +0 -16
  119. package/src/chart/PatternDefs.svelte +0 -13
  120. package/src/chart/Swatch.svelte +0 -93
  121. package/src/chart/SwatchButton.svelte +0 -29
  122. package/src/chart/SwatchGrid.svelte +0 -55
  123. package/src/chart/Symbol.svelte +0 -37
  124. package/src/chart/Texture.svelte +0 -16
  125. package/src/chart/TexturedShape.svelte +0 -27
  126. package/src/chart/TimelapseChart.svelte +0 -97
  127. package/src/chart/Timer.svelte +0 -27
  128. package/src/chart.js +0 -9
  129. package/src/components/charts/Axis.svelte +0 -66
  130. package/src/components/charts/Chart.svelte +0 -35
  131. package/src/components/index.js +0 -23
  132. package/src/components/lib/axis.js +0 -0
  133. package/src/components/lib/chart.js +0 -187
  134. package/src/components/lib/color.js +0 -327
  135. package/src/components/lib/funnel.js +0 -204
  136. package/src/components/lib/index.js +0 -19
  137. package/src/components/lib/pattern.js +0 -190
  138. package/src/components/lib/rollup.js +0 -55
  139. package/src/components/lib/shape.js +0 -199
  140. package/src/components/lib/summary.js +0 -145
  141. package/src/components/lib/theme.js +0 -23
  142. package/src/components/lib/timer.js +0 -41
  143. package/src/components/lib/utils.js +0 -165
  144. package/src/components/plots/BarPlot.svelte +0 -36
  145. package/src/components/plots/BoxPlot.svelte +0 -54
  146. package/src/components/plots/ScatterPlot.svelte +0 -30
  147. package/src/components/store.js +0 -70
  148. package/src/constants.js +0 -66
  149. package/src/elements/PatternDefs.svelte +0 -13
  150. package/src/elements/PatternMask.svelte +0 -20
  151. package/src/elements/Symbol.svelte +0 -38
  152. package/src/elements/Tooltip.svelte +0 -23
  153. package/src/funnel.svelte +0 -35
  154. package/src/geom.js +0 -105
  155. package/src/lib/axis.js +0 -75
  156. package/src/lib/colors.js +0 -32
  157. package/src/lib/geom.js +0 -4
  158. package/src/lib/shapes.js +0 -144
  159. package/src/lib/timer.js +0 -44
  160. package/src/lookup.js +0 -29
  161. package/src/plots/BarPlot.svelte +0 -55
  162. package/src/plots/BoxPlot.svelte +0 -0
  163. package/src/plots/FunnelPlot.svelte +0 -33
  164. package/src/plots/HeatMap.svelte +0 -5
  165. package/src/plots/HeatMapCalendar.svelte +0 -129
  166. package/src/plots/LinePlot.svelte +0 -55
  167. package/src/plots/Plot.svelte +0 -25
  168. package/src/plots/RankBarPlot.svelte +0 -38
  169. package/src/plots/ScatterPlot.svelte +0 -20
  170. package/src/plots/ViolinPlot.svelte +0 -11
  171. package/src/plots/heatmap.js +0 -70
  172. package/src/plots/index.js +0 -10
  173. package/src/swatch.js +0 -11
package/README.md CHANGED
@@ -1,55 +1,159 @@
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 D3 chart components for Svelte 5, inspired by the composable approach of [dc.js](https://dc-js.github.io/dc.js/).
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
+ ## Install
7
6
 
8
- This component library borrows concepts from the following articles, products, and repositories.
7
+ ```bash
8
+ bun add @rokkit/chart
9
+ # or
10
+ npm install @rokkit/chart
11
+ ```
9
12
 
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.
13
+ ## Overview
15
14
 
16
- ## Getting Started
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
- Get started quickly using [degit](https://github.com/Rich-Harris/degit).
17
+ ## Usage
19
18
 
20
- ```bash
21
- degit jerrythomas/sparsh-ui/sites/playground my-app
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
- ## 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
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.
package/package.json CHANGED
@@ -1,63 +1,60 @@
1
1
  {
2
2
  "name": "@rokkit/chart",
3
- "version": "1.0.0-next.16",
4
- "description": "Components for making interactive charts.",
3
+ "version": "1.0.0-next.160",
4
+ "type": "module",
5
+ "description": "Data-driven chart components",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/jerrythomas/rokkit.git"
9
+ },
5
10
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
11
  "license": "MIT",
7
- "main": "src/index.js",
8
- "svelte": "src/index.js",
9
- "module": "src/index.js",
10
- "types": "dist/index.d.ts",
11
- "type": "module",
12
+ "npm": {
13
+ "publish": false
14
+ },
12
15
  "publishConfig": {
13
16
  "access": "public"
14
17
  },
15
- "devDependencies": {
16
- "@sveltejs/vite-plugin-svelte": "^2.0.2",
17
- "@testing-library/svelte": "^3.2.2",
18
- "@vitest/ui": "~0.12.10",
19
- "eslint": "^8.33.0",
20
- "js-yaml": "^4.1.0",
21
- "jsdom": "^19.0.0",
22
- "svelte": "^3.55.1",
23
- "typescript": "^4.9.5",
24
- "vite": "^4.1.1",
25
- "vitest": "~0.19.1",
26
- "shared-config": "1.0.0",
27
- "eslint-config-shared": "1.0.0"
28
- },
29
- "dependencies": {
30
- "d3-array": "^3.2.2",
31
- "d3-collection": "^1.0.7",
32
- "d3-scale": "^4.0.2",
33
- "d3-shape": "^3.2.0",
34
- "date-fns": "^2.29.3",
35
- "ramda": "^0.28.0",
36
- "yootils": "^0.3.1",
37
- "@rokkit/core": "1.0.0-next.16"
18
+ "scripts": {
19
+ "prepublishOnly": "cp ../../LICENSE . && bun clean && bun tsc --project tsconfig.build.json",
20
+ "postpublish": "rm -f LICENSE",
21
+ "clean": "rm -rf dist",
22
+ "build": "bun prepublishOnly"
38
23
  },
39
24
  "files": [
40
25
  "src/**/*.js",
41
26
  "src/**/*.svelte",
42
- "!src/fixtures",
43
- "!src/mocks",
44
- "!src/**/*.spec.js"
27
+ "dist/**/*.d.ts",
28
+ "README.md",
29
+ "package.json",
30
+ "LICENSE"
45
31
  ],
46
32
  "exports": {
47
- "./src": "./src",
48
33
  "./package.json": "./package.json",
49
34
  ".": {
50
35
  "types": "./dist/index.d.ts",
51
- "import": "./src/index.js"
52
- }
36
+ "import": "./src/index.js",
37
+ "svelte": "./src/index.js"
38
+ },
39
+ "./patterns": "./src/patterns/index.js",
40
+ "./symbols": "./src/symbols/index.js",
41
+ "./symbols/*": "./src/symbols/*",
42
+ "./patterns/*": "./src/patterns/*",
43
+ "./charts/*": "./src/charts/*"
53
44
  },
54
- "scripts": {
55
- "lint": "prettier --check --plugin-search-dir=. . && eslint .",
56
- "format": "prettier --write --plugin-search-dir=. .",
57
- "test:ci": "vitest run",
58
- "test:ui": "vitest --ui",
59
- "test": "vitest",
60
- "coverage": "vitest run --coverage",
61
- "upgrade": "pnpm upgrade"
45
+ "dependencies": {
46
+ "@rokkit/core": "latest",
47
+ "@rokkit/data": "latest",
48
+ "@rokkit/states": "latest",
49
+ "d3-array": "^3.2.4",
50
+ "d3-axis": "^3.0.0",
51
+ "d3-format": "^3.1.2",
52
+ "d3-scale": "^4.0.2",
53
+ "d3-scale-chromatic": "^3.1.0",
54
+ "d3-selection": "^3.0.0",
55
+ "d3-shape": "^3.2.0",
56
+ "d3-transition": "^3.0.1",
57
+ "d3-zoom": "^3.0.0",
58
+ "ramda": "^0.32.0"
62
59
  }
63
- }
60
+ }