@rokkit/chart 1.3.8 → 1.3.10

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 (140) hide show
  1. package/dist/Chart.svelte +50 -64
  2. package/dist/Plot/Root.svelte +4 -1
  3. package/dist/Plot/Root.svelte.d.ts +2 -0
  4. package/dist/Plot/index.d.ts +1 -1
  5. package/dist/Plot/index.js +1 -1
  6. package/dist/Plot.svelte +4 -1
  7. package/dist/Plot.svelte.d.ts +2 -0
  8. package/dist/PlotState.svelte.d.ts +14 -2
  9. package/dist/PlotState.svelte.js +81 -5
  10. package/dist/charts/AreaChart.svelte +8 -1
  11. package/dist/charts/AreaChart.svelte.d.ts +5 -0
  12. package/dist/charts/BarChart.svelte +8 -1
  13. package/dist/charts/BarChart.svelte.d.ts +5 -0
  14. package/dist/charts/BoxPlot.svelte +3 -1
  15. package/dist/charts/BoxPlot.svelte.d.ts +1 -0
  16. package/dist/charts/BubbleChart.svelte +3 -1
  17. package/dist/charts/BubbleChart.svelte.d.ts +1 -0
  18. package/dist/charts/LineChart.svelte +3 -1
  19. package/dist/charts/LineChart.svelte.d.ts +1 -0
  20. package/dist/charts/PieChart.svelte +4 -2
  21. package/dist/charts/PieChart.svelte.d.ts +1 -0
  22. package/dist/charts/ScatterPlot.svelte +3 -1
  23. package/dist/charts/ScatterPlot.svelte.d.ts +1 -0
  24. package/dist/charts/ViolinPlot.svelte +3 -1
  25. package/dist/charts/ViolinPlot.svelte.d.ts +1 -0
  26. package/dist/geoms/Arc.svelte +21 -55
  27. package/dist/geoms/Arc.svelte.d.ts +4 -4
  28. package/dist/geoms/Area.svelte +45 -44
  29. package/dist/geoms/Area.svelte.d.ts +8 -1
  30. package/dist/geoms/Bar.svelte +33 -56
  31. package/dist/geoms/Bar.svelte.d.ts +9 -0
  32. package/dist/geoms/Box.svelte +118 -131
  33. package/dist/geoms/Box.svelte.d.ts +5 -3
  34. package/dist/geoms/Candlestick.svelte +22 -77
  35. package/dist/geoms/Candlestick.svelte.d.ts +2 -0
  36. package/dist/geoms/Heatmap.svelte +21 -66
  37. package/dist/geoms/Heatmap.svelte.d.ts +2 -0
  38. package/dist/geoms/Hexbin.svelte +20 -100
  39. package/dist/geoms/Hexbin.svelte.d.ts +2 -0
  40. package/dist/geoms/Jitter.svelte +21 -36
  41. package/dist/geoms/Jitter.svelte.d.ts +5 -3
  42. package/dist/geoms/Line.svelte +27 -31
  43. package/dist/geoms/Line.svelte.d.ts +5 -0
  44. package/dist/geoms/Point.svelte +31 -66
  45. package/dist/geoms/Point.svelte.d.ts +5 -1
  46. package/dist/geoms/Ribbon.svelte +30 -124
  47. package/dist/geoms/Ribbon.svelte.d.ts +2 -0
  48. package/dist/geoms/Rule.svelte +5 -1
  49. package/dist/geoms/Rule.svelte.d.ts +3 -0
  50. package/dist/geoms/Violin.svelte +21 -40
  51. package/dist/geoms/Violin.svelte.d.ts +5 -3
  52. package/dist/geoms/Waterfall.svelte +19 -80
  53. package/dist/geoms/Waterfall.svelte.d.ts +2 -0
  54. package/dist/geoms/lib/GeomState.svelte.d.ts +51 -0
  55. package/dist/geoms/lib/GeomState.svelte.js +79 -0
  56. package/dist/geoms/lib/aesthetics.d.ts +36 -0
  57. package/dist/geoms/lib/aesthetics.js +45 -0
  58. package/dist/geoms/lib/areas.d.ts +1 -1
  59. package/dist/geoms/lib/areas.js +18 -5
  60. package/dist/geoms/lib/bars.d.ts +2 -2
  61. package/dist/geoms/lib/bars.js +37 -17
  62. package/dist/geoms/lib/marks/arc.d.ts +24 -0
  63. package/dist/geoms/lib/marks/arc.js +28 -0
  64. package/dist/geoms/lib/marks/area.d.ts +23 -0
  65. package/dist/geoms/lib/marks/area.js +38 -0
  66. package/dist/geoms/lib/marks/bar.d.ts +16 -0
  67. package/dist/geoms/lib/marks/bar.js +43 -0
  68. package/dist/geoms/lib/marks/box.d.ts +14 -0
  69. package/dist/geoms/lib/marks/box.js +30 -0
  70. package/dist/geoms/lib/marks/candlestick.d.ts +27 -0
  71. package/dist/geoms/lib/marks/candlestick.js +52 -0
  72. package/dist/geoms/lib/marks/heatmap.d.ts +24 -0
  73. package/dist/geoms/lib/marks/heatmap.js +47 -0
  74. package/dist/geoms/lib/marks/hexbin.d.ts +29 -0
  75. package/dist/geoms/lib/marks/hexbin.js +62 -0
  76. package/dist/geoms/lib/marks/jitter.d.ts +21 -0
  77. package/dist/geoms/lib/marks/jitter.js +36 -0
  78. package/dist/geoms/lib/marks/line.d.ts +26 -0
  79. package/dist/geoms/lib/marks/line.js +25 -0
  80. package/dist/geoms/lib/marks/point.d.ts +25 -0
  81. package/dist/geoms/lib/marks/point.js +58 -0
  82. package/dist/geoms/lib/marks/ribbon.d.ts +32 -0
  83. package/dist/geoms/lib/marks/ribbon.js +80 -0
  84. package/dist/geoms/lib/marks/violin.d.ts +13 -0
  85. package/dist/geoms/lib/marks/violin.js +31 -0
  86. package/dist/geoms/lib/marks/waterfall.d.ts +25 -0
  87. package/dist/geoms/lib/marks/waterfall.js +58 -0
  88. package/dist/index.d.ts +1 -8
  89. package/dist/index.js +1 -8
  90. package/dist/lib/brewing/colors.d.ts +31 -1
  91. package/dist/lib/brewing/colors.js +34 -1
  92. package/dist/lib/brewing/marks/arcs.js +9 -4
  93. package/dist/lib/brewing/marks/boxes.js +8 -4
  94. package/dist/lib/brewing/marks/lines.js +13 -2
  95. package/dist/lib/brewing/marks/points.js +7 -2
  96. package/dist/lib/brewing/marks/swarm.js +6 -2
  97. package/dist/lib/brewing/marks/violins.js +8 -4
  98. package/dist/lib/preset.d.ts +11 -1
  99. package/dist/lib/preset.js +16 -4
  100. package/package.json +1 -1
  101. package/dist/Plot/Arc.svelte +0 -30
  102. package/dist/Plot/Arc.svelte.d.ts +0 -18
  103. package/dist/lib/brewer.d.ts +0 -9
  104. package/dist/lib/brewer.js +0 -25
  105. package/dist/lib/brewing/BoxBrewer.svelte.d.ts +0 -8
  106. package/dist/lib/brewing/BoxBrewer.svelte.js +0 -14
  107. package/dist/lib/brewing/CartesianBrewer.svelte.d.ts +0 -8
  108. package/dist/lib/brewing/CartesianBrewer.svelte.js +0 -21
  109. package/dist/lib/brewing/PieBrewer.svelte.d.ts +0 -8
  110. package/dist/lib/brewing/PieBrewer.svelte.js +0 -14
  111. package/dist/lib/brewing/QuartileBrewer.svelte.d.ts +0 -9
  112. package/dist/lib/brewing/QuartileBrewer.svelte.js +0 -51
  113. package/dist/lib/brewing/ViolinBrewer.svelte.d.ts +0 -8
  114. package/dist/lib/brewing/ViolinBrewer.svelte.js +0 -14
  115. package/dist/lib/brewing/axes.svelte.d.ts +0 -66
  116. package/dist/lib/brewing/axes.svelte.js +0 -270
  117. package/dist/lib/brewing/bars.svelte.d.ts +0 -56
  118. package/dist/lib/brewing/bars.svelte.js +0 -201
  119. package/dist/lib/brewing/brewer.svelte.d.ts +0 -124
  120. package/dist/lib/brewing/brewer.svelte.js +0 -277
  121. package/dist/lib/brewing/dimensions.svelte.d.ts +0 -35
  122. package/dist/lib/brewing/dimensions.svelte.js +0 -56
  123. package/dist/lib/brewing/index.svelte.d.ts +0 -118
  124. package/dist/lib/brewing/index.svelte.js +0 -205
  125. package/dist/lib/brewing/legends.svelte.d.ts +0 -48
  126. package/dist/lib/brewing/legends.svelte.js +0 -137
  127. package/dist/lib/brewing/marks/areas.d.ts +0 -31
  128. package/dist/lib/brewing/marks/areas.js +0 -72
  129. package/dist/lib/brewing/marks/bars.d.ts +0 -1
  130. package/dist/lib/brewing/marks/bars.js +0 -49
  131. package/dist/lib/brewing/scales.svelte.d.ts +0 -24
  132. package/dist/lib/brewing/scales.svelte.js +0 -82
  133. package/dist/lib/context.d.ts +0 -13
  134. package/dist/lib/context.js +0 -131
  135. package/dist/lib/plot/chartProps.d.ts +0 -177
  136. package/dist/lib/plot/chartProps.js +0 -76
  137. package/dist/lib/scales.svelte.d.ts +0 -35
  138. package/dist/lib/scales.svelte.js +0 -151
  139. package/dist/lib/ticks.d.ts +0 -36
  140. package/dist/lib/ticks.js +0 -46
@@ -1,277 +0,0 @@
1
- import { SvelteMap, SvelteSet } from 'svelte/reactivity'
2
- import { distinct, assignColors } from './colors.js'
3
- import { assignPatterns, toPatternId, PATTERN_ORDER } from './patterns.js'
4
- import { assignSymbols } from './symbols.js'
5
- import { buildXScale, buildYScale, buildSizeScale } from './scales.js'
6
- import { buildBars } from './marks/bars.js'
7
- import { buildLines } from './marks/lines.js'
8
- import { buildAreas } from './marks/areas.js'
9
- import { buildArcs } from './marks/arcs.js'
10
- import { buildPoints } from './marks/points.js'
11
-
12
- const DEFAULT_MARGIN = { top: 20, right: 20, bottom: 40, left: 50 }
13
-
14
- /**
15
- * Groups aesthetic channel mappings by field name, merging aesthetics that
16
- * share the same field into one legend section.
17
- *
18
- * @param {{ fill?: string, color?: string, pattern?: string, symbol?: string }} channels
19
- * `fill` takes precedence over `color` for polygon charts (bars, areas, pie slices).
20
- * @param {Map<unknown, {fill:string, stroke:string}>} colorMap
21
- * @param {Map<unknown, string>} patternMap
22
- * @param {Map<unknown, string>} symbolMap
23
- * @returns {{ field: string, items: { label: string, fill: string|null, stroke: string|null, patternId: string|null, shape: string|null }[] }[]}
24
- */
25
- function addAesthetic(byField, field, aesthetic, keys) {
26
- if (byField.has(field)) {
27
- byField.get(field).aesthetics.push(aesthetic)
28
- } else {
29
- byField.set(field, { aesthetics: [aesthetic], keys })
30
- }
31
- }
32
-
33
- function buildLegendItem(key, aesthetics, colorMap, patternMap, symbolMap) {
34
- const hasColor = aesthetics.includes('color')
35
- return {
36
- label: String(key),
37
- fill: hasColor ? (colorMap.get(key)?.fill ?? null) : null,
38
- stroke: hasColor ? (colorMap.get(key)?.stroke ?? null) : null,
39
- patternId: aesthetics.includes('pattern') && patternMap.has(key) ? toPatternId(key) : null,
40
- shape: aesthetics.includes('symbol') ? (symbolMap.get(key) ?? 'circle') : null
41
- }
42
- }
43
-
44
- export function buildLegendGroups(channels, colorMap, patternMap, symbolMap) {
45
- const cf = channels.fill ?? channels.color
46
- const { pattern: pf, symbol: sf } = channels
47
- const byField = new SvelteMap()
48
-
49
- if (cf) byField.set(cf, { aesthetics: ['color'], keys: [...colorMap.keys()] })
50
- if (pf) addAesthetic(byField, pf, 'pattern', [...patternMap.keys()])
51
- if (sf) addAesthetic(byField, sf, 'symbol', [...symbolMap.keys()])
52
-
53
- return [...byField.entries()]
54
- .map(([field, { aesthetics, keys }]) => ({
55
- field,
56
- items: keys
57
- .filter((k) => k !== null && k !== undefined)
58
- .map((key) => buildLegendItem(key, aesthetics, colorMap, patternMap, symbolMap))
59
- }))
60
- .filter((group) => group.items.length > 0)
61
- }
62
-
63
- export class ChartBrewer {
64
- #rawData = $state([])
65
- #channels = $state({})
66
- #width = $state(600)
67
- #height = $state(400)
68
- #mode = $state('light')
69
- #margin = $state(DEFAULT_MARGIN)
70
- #layers = $state([])
71
- #curve = $state(/** @type {'linear'|'smooth'|'step'|undefined} */ (undefined))
72
- #stat = $state('identity')
73
-
74
- /**
75
- * Override in subclasses to apply stat aggregation.
76
- * @param {Object[]} data
77
- * @param {Object} channels
78
- * @param {string|Function} stat
79
- * @returns {Object[]}
80
- */
81
- transform(data, _channels, _stat) {
82
- return data
83
- }
84
-
85
- /** Aggregated data — all derived marks read this, not #rawData */
86
- processedData = $derived(this.transform(this.#rawData, this.#channels, this.#stat))
87
-
88
- /** Exposes channels to subclasses for use in their own $derived properties */
89
- get channels() {
90
- return this.#channels
91
- }
92
-
93
- // Maps are built from rawData so the legend always reflects the full set of
94
- // original values — independent of whichever stat aggregation is applied.
95
- // e.g. pattern=quarter with stat=sum still shows all 8 quarters in the legend.
96
-
97
- /** @type {Map<unknown, {fill:string,stroke:string}>} */
98
- colorMap = $derived(
99
- (this.#channels.fill ?? this.#channels.color)
100
- ? assignColors(
101
- distinct(this.#rawData, this.#channels.fill ?? this.#channels.color),
102
- this.#mode
103
- )
104
- : new SvelteMap()
105
- )
106
-
107
- /** @type {Map<unknown, string>} */
108
- patternMap = $derived(
109
- this.#channels.pattern
110
- ? assignPatterns(distinct(this.#rawData, this.#channels.pattern))
111
- : new SvelteMap()
112
- )
113
-
114
- /**
115
- * Unified pattern defs for ChartPatternDefs.
116
- * When fill and pattern map the same field, pattern key = color key (simple case).
117
- * When they differ, each unique (fillKey, patternKey) pair gets its own pattern def
118
- * so bars/areas can have distinct colors per region AND distinct textures per category.
119
- * @type {Array<{ id: string, name: string, fill: string, stroke: string }>}
120
- */
121
- patternDefs = $derived(
122
- (() => {
123
- const pf = this.#channels.pattern
124
- const ff = this.#channels.fill ?? this.#channels.color
125
- if (!pf || this.patternMap.size === 0) return []
126
- if (!ff || pf === ff) {
127
- // Same field: pattern key = fill key — simple 1:1 lookup
128
- return Array.from(this.patternMap.entries()).map(([key, name]) => {
129
- const color = this.colorMap.get(key) ?? { fill: '#ddd', stroke: '#666' }
130
- return { id: toPatternId(key), name, fill: color.fill, stroke: color.stroke }
131
- })
132
- }
133
- // Different fields: need two sets of defs in the SVG:
134
- // 1. Simple defs (neutral background) — referenced by legend swatches via toPatternId(patternKey)
135
- // 2. Composite defs (fill-colored background) — referenced by bars via toPatternId(fillKey::patternKey)
136
- const defs = []
137
- for (const [pk, name] of this.patternMap.entries()) {
138
- defs.push({ id: toPatternId(pk), name, fill: '#ddd', stroke: '#666' })
139
- }
140
- const seenComposite = new SvelteSet()
141
- for (const d of this.processedData) {
142
- const fk = d[ff]
143
- const pk = d[pf]
144
- if (pk === null || pk === undefined) continue
145
- const compositeKey = `${fk}::${pk}`
146
- if (seenComposite.has(compositeKey)) continue
147
- seenComposite.add(compositeKey)
148
- const name = this.patternMap.get(pk) ?? PATTERN_ORDER[0]
149
- const color = this.colorMap.get(fk) ?? { fill: '#ddd', stroke: '#666' }
150
- defs.push({ id: toPatternId(compositeKey), name, fill: color.fill, stroke: color.stroke })
151
- }
152
- return defs
153
- })()
154
- )
155
-
156
- /** @type {Map<unknown, string>} */
157
- symbolMap = $derived(
158
- this.#channels.symbol
159
- ? assignSymbols(distinct(this.#rawData, this.#channels.symbol))
160
- : new SvelteMap()
161
- )
162
-
163
- get innerWidth() {
164
- return this.#width - this.#margin.left - this.#margin.right
165
- }
166
- get innerHeight() {
167
- return this.#height - this.#margin.top - this.#margin.bottom
168
- }
169
-
170
- xScale = $derived(
171
- this.#channels.x ? buildXScale(this.processedData, this.#channels.x, this.innerWidth) : null
172
- )
173
-
174
- yScale = $derived(
175
- this.#channels.y
176
- ? buildYScale(this.processedData, this.#channels.y, this.innerHeight, this.#layers)
177
- : null
178
- )
179
-
180
- sizeScale = $derived(
181
- this.#channels.size ? buildSizeScale(this.processedData, this.#channels.size) : null
182
- )
183
-
184
- bars = $derived(
185
- this.xScale && this.yScale
186
- ? buildBars(
187
- this.processedData,
188
- this.#channels,
189
- this.xScale,
190
- this.yScale,
191
- this.colorMap,
192
- this.patternMap
193
- )
194
- : []
195
- )
196
-
197
- lines = $derived(
198
- this.xScale && this.yScale
199
- ? buildLines(
200
- this.processedData,
201
- this.#channels,
202
- this.xScale,
203
- this.yScale,
204
- this.colorMap,
205
- this.#curve
206
- )
207
- : []
208
- )
209
-
210
- areas = $derived(
211
- this.xScale && this.yScale
212
- ? buildAreas(
213
- this.processedData,
214
- this.#channels,
215
- this.xScale,
216
- this.yScale,
217
- this.colorMap,
218
- this.#curve,
219
- this.patternMap
220
- )
221
- : []
222
- )
223
-
224
- arcs = $derived(
225
- this.#channels.y
226
- ? buildArcs(this.processedData, this.#channels, this.colorMap, this.#width, this.#height)
227
- : []
228
- )
229
-
230
- points = $derived(
231
- this.xScale && this.yScale
232
- ? buildPoints(
233
- this.processedData,
234
- this.#channels,
235
- this.xScale,
236
- this.yScale,
237
- this.colorMap,
238
- this.sizeScale,
239
- this.symbolMap
240
- )
241
- : []
242
- )
243
-
244
- legendGroups = $derived(
245
- buildLegendGroups(this.#channels, this.colorMap, this.patternMap, this.symbolMap)
246
- )
247
-
248
- get margin() {
249
- return this.#margin
250
- }
251
- get width() {
252
- return this.#width
253
- }
254
- get height() {
255
- return this.#height
256
- }
257
- get mode() {
258
- return this.#mode
259
- }
260
-
261
- /**
262
- * @param {{ data?: Object[], channels?: Object, width?: number, height?: number, mode?: string, margin?: Object, layers?: Object[], curve?: string, stat?: string|Function }} opts
263
- * Supported channel keys: `x`, `y`, `fill`, `color`, `pattern`, `symbol`, `size`, `label`.
264
- * `frame` is reserved for future animation use (no-op).
265
- */
266
- update(opts = {}) {
267
- if (opts.data !== undefined) this.#rawData = opts.data
268
- if (opts.channels !== undefined) this.#channels = opts.channels
269
- if (opts.width !== undefined) this.#width = opts.width
270
- if (opts.height !== undefined) this.#height = opts.height
271
- if (opts.mode !== undefined) this.#mode = opts.mode
272
- if (opts.margin !== undefined) this.#margin = { ...DEFAULT_MARGIN, ...opts.margin }
273
- if (opts.layers !== undefined) this.#layers = opts.layers
274
- if (opts.curve !== undefined) this.#curve = opts.curve
275
- if (opts.stat !== undefined) this.#stat = opts.stat
276
- }
277
- }
@@ -1,35 +0,0 @@
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;
@@ -1,56 +0,0 @@
1
- import {} from './types.js'
2
-
3
- /**
4
- * @typedef {import('./types').ChartMargin} ChartMargin
5
- * @typedef {import('./types').ChartDimensions} ChartDimensions
6
- */
7
-
8
- /**
9
- * Default chart margin
10
- * @type {ChartMargin}
11
- */
12
- export const DEFAULT_MARGIN = { top: 20, right: 30, bottom: 40, left: 50 }
13
-
14
- /**
15
- * Creates chart dimensions based on width, height and margins
16
- *
17
- * @param {number} width - Total chart width
18
- * @param {number} height - Total chart height
19
- * @param {ChartMargin} margin - Chart margins
20
- * @returns {ChartDimensions} Chart dimensions
21
- */
22
- export function createDimensions(width = 600, height = 400, margin = DEFAULT_MARGIN) {
23
- return {
24
- width,
25
- height,
26
- margin: { ...margin },
27
- innerWidth: width - margin.left - margin.right,
28
- innerHeight: height - margin.top - margin.bottom
29
- }
30
- }
31
-
32
- /**
33
- * Updates existing dimensions with new values
34
- *
35
- * @param {ChartDimensions} dimensions - Current dimensions
36
- * @param {Object} updates - Values to update
37
- * @param {number} [updates.width] - New width
38
- * @param {number} [updates.height] - New height
39
- * @param {ChartMargin} [updates.margin] - New margin
40
- * @returns {ChartDimensions} Updated dimensions
41
- */
42
- export function updateDimensions(dimensions, updates = {}) {
43
- const newDimensions = { ...dimensions }
44
-
45
- if (updates.width !== undefined) newDimensions.width = updates.width
46
- if (updates.height !== undefined) newDimensions.height = updates.height
47
- if (updates.margin !== undefined) newDimensions.margin = { ...updates.margin }
48
-
49
- // Recalculate inner dimensions
50
- newDimensions.innerWidth =
51
- newDimensions.width - newDimensions.margin.left - newDimensions.margin.right
52
- newDimensions.innerHeight =
53
- newDimensions.height - newDimensions.margin.top - newDimensions.margin.bottom
54
-
55
- return newDimensions
56
- }
@@ -1,118 +0,0 @@
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 };
@@ -1,205 +0,0 @@
1
- import { createDimensions, updateDimensions } from './dimensions.svelte.js'
2
- import { createScales, getOrigin } from './scales.svelte.js'
3
- import { createBars, filterBars, createGroupedBars } from './bars.svelte.js'
4
- import { createXAxis, createYAxis, createGrid, createTickAttributes } from './axes.svelte.js'
5
- import { createLegend, filterByLegend, createLegendItemAttributes } from './legends.svelte.js'
6
-
7
- /**
8
- * Chart Brewing - A collection of pure functions for chart data preparation
9
- */
10
- export {
11
- // Dimensions
12
- createDimensions,
13
- updateDimensions,
14
-
15
- // Scales
16
- createScales,
17
- getOrigin,
18
-
19
- // Bars
20
- createBars,
21
- filterBars,
22
- createGroupedBars,
23
-
24
- // Axes
25
- createXAxis,
26
- createYAxis,
27
- createGrid,
28
- createTickAttributes,
29
-
30
- // Legends
31
- createLegend,
32
- filterByLegend,
33
- createLegendItemAttributes
34
- }
35
-
36
- /**
37
- * Main class that manages chart state and provides access to all brewing functions
38
- */
39
- export class ChartBrewer {
40
- #data = []
41
- #dimensions = createDimensions()
42
- #scales = { x: null, y: null, color: null }
43
- #fields = { x: null, y: null, color: null }
44
- #options = {
45
- padding: 0.2,
46
- animationDuration: 300
47
- }
48
-
49
- /**
50
- * Creates a new ChartBrewer instance
51
- *
52
- * @param {Object} options Configuration options
53
- */
54
- constructor(options = {}) {
55
- this.#dimensions = createDimensions(options.width, options.height, options.margin)
56
-
57
- if (options.padding !== undefined) this.#options.padding = options.padding
58
- if (options.animationDuration !== undefined)
59
- this.#options.animationDuration = options.animationDuration
60
- }
61
-
62
- /**
63
- * Sets the data for the chart
64
- *
65
- * @param {Array} data Data array
66
- * @returns {ChartBrewer} this for method chaining
67
- */
68
- setData(data) {
69
- this.#data = Array.isArray(data) ? data : []
70
- return this
71
- }
72
-
73
- /**
74
- * Sets the field mappings for axes and color
75
- *
76
- * @param {Object} fields Field mappings
77
- * @returns {ChartBrewer} this for method chaining
78
- */
79
- setFields({ x, y, color }) {
80
- if (x !== undefined) this.#fields.x = x
81
- if (y !== undefined) this.#fields.y = y
82
- if (color !== undefined) this.#fields.color = color
83
- return this
84
- }
85
-
86
- /**
87
- * Sets the dimensions of the chart
88
- *
89
- * @param {Object} dimensions Chart dimensions
90
- * @returns {ChartBrewer} this for method chaining
91
- */
92
- setDimensions({ width, height, margin }) {
93
- this.#dimensions = updateDimensions(this.#dimensions, { width, height, margin })
94
- return this
95
- }
96
-
97
- /**
98
- * Creates scales based on data and dimensions
99
- *
100
- * @returns {ChartBrewer} this for method chaining
101
- */
102
- createScales() {
103
- this.#scales = createScales(this.#data, this.#fields, this.#dimensions, {
104
- padding: this.#options.padding
105
- })
106
- return this
107
- }
108
-
109
- /**
110
- * Creates bar data for rendering
111
- *
112
- * @returns {Array} Data for rendering bars
113
- */
114
- createBars() {
115
- return createBars(this.#data, this.#fields, this.#scales, { dimensions: this.#dimensions })
116
- }
117
-
118
- /**
119
- * Creates x-axis tick data for rendering
120
- *
121
- * @param {Object} options Axis options
122
- * @returns {Object} Axis rendering data
123
- */
124
- createXAxis(options = {}) {
125
- return createXAxis(this.#scales, this.#dimensions, options)
126
- }
127
-
128
- /**
129
- * Creates y-axis tick data for rendering
130
- *
131
- * @param {Object} options Axis options
132
- * @returns {Object} Axis rendering data
133
- */
134
- createYAxis(options = {}) {
135
- return createYAxis(this.#scales, this.#dimensions, options)
136
- }
137
-
138
- /**
139
- * Creates grid line data for rendering
140
- *
141
- * @param {Object} options Grid options
142
- * @returns {Object} Grid rendering data
143
- */
144
- createGrid(options = {}) {
145
- return createGrid(this.#scales, this.#dimensions, options)
146
- }
147
-
148
- /**
149
- * Creates legend data for rendering
150
- *
151
- * @param {Object} options Legend options
152
- * @returns {Object} Legend rendering data
153
- */
154
- createLegend(options = {}) {
155
- return createLegend(this.#data, this.#fields, this.#scales, {
156
- ...options,
157
- dimensions: this.#dimensions
158
- })
159
- }
160
-
161
- /**
162
- * Gets all chart dimensions
163
- *
164
- * @returns {Object} Chart dimensions
165
- */
166
- getDimensions() {
167
- return { ...this.#dimensions }
168
- }
169
-
170
- /**
171
- * Gets all chart scales
172
- *
173
- * @returns {Object} Chart scales
174
- */
175
- getScales() {
176
- return { ...this.#scales }
177
- }
178
-
179
- /**
180
- * Gets the animation duration
181
- *
182
- * @returns {number} Animation duration in ms
183
- */
184
- getAnimationDuration() {
185
- return this.#options.animationDuration
186
- }
187
-
188
- /**
189
- * Gets the data being used
190
- *
191
- * @returns {Array} Chart data
192
- */
193
- getData() {
194
- return [...this.#data]
195
- }
196
-
197
- /**
198
- * Gets the fields configuration
199
- *
200
- * @returns {Object} Fields configuration
201
- */
202
- getFields() {
203
- return { ...this.#fields }
204
- }
205
- }