@rokkit/chart 1.3.8 → 1.3.9

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 (130) 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/PlotState.svelte.d.ts +14 -2
  7. package/dist/PlotState.svelte.js +46 -4
  8. package/dist/charts/AreaChart.svelte +8 -1
  9. package/dist/charts/AreaChart.svelte.d.ts +5 -0
  10. package/dist/charts/BarChart.svelte +8 -1
  11. package/dist/charts/BarChart.svelte.d.ts +5 -0
  12. package/dist/charts/BoxPlot.svelte +3 -1
  13. package/dist/charts/BoxPlot.svelte.d.ts +1 -0
  14. package/dist/charts/BubbleChart.svelte +3 -1
  15. package/dist/charts/BubbleChart.svelte.d.ts +1 -0
  16. package/dist/charts/LineChart.svelte +3 -1
  17. package/dist/charts/LineChart.svelte.d.ts +1 -0
  18. package/dist/charts/PieChart.svelte +4 -2
  19. package/dist/charts/PieChart.svelte.d.ts +1 -0
  20. package/dist/charts/ScatterPlot.svelte +3 -1
  21. package/dist/charts/ScatterPlot.svelte.d.ts +1 -0
  22. package/dist/charts/ViolinPlot.svelte +3 -1
  23. package/dist/charts/ViolinPlot.svelte.d.ts +1 -0
  24. package/dist/geoms/Arc.svelte +21 -55
  25. package/dist/geoms/Arc.svelte.d.ts +4 -4
  26. package/dist/geoms/Area.svelte +45 -44
  27. package/dist/geoms/Area.svelte.d.ts +8 -1
  28. package/dist/geoms/Bar.svelte +33 -56
  29. package/dist/geoms/Bar.svelte.d.ts +9 -0
  30. package/dist/geoms/Box.svelte +118 -131
  31. package/dist/geoms/Box.svelte.d.ts +5 -3
  32. package/dist/geoms/Candlestick.svelte +22 -77
  33. package/dist/geoms/Candlestick.svelte.d.ts +2 -0
  34. package/dist/geoms/Heatmap.svelte +21 -66
  35. package/dist/geoms/Heatmap.svelte.d.ts +2 -0
  36. package/dist/geoms/Hexbin.svelte +20 -100
  37. package/dist/geoms/Hexbin.svelte.d.ts +2 -0
  38. package/dist/geoms/Jitter.svelte +21 -36
  39. package/dist/geoms/Jitter.svelte.d.ts +5 -3
  40. package/dist/geoms/Line.svelte +27 -31
  41. package/dist/geoms/Line.svelte.d.ts +5 -0
  42. package/dist/geoms/Point.svelte +31 -66
  43. package/dist/geoms/Point.svelte.d.ts +5 -1
  44. package/dist/geoms/Ribbon.svelte +30 -124
  45. package/dist/geoms/Ribbon.svelte.d.ts +2 -0
  46. package/dist/geoms/Rule.svelte +5 -1
  47. package/dist/geoms/Rule.svelte.d.ts +3 -0
  48. package/dist/geoms/Violin.svelte +21 -40
  49. package/dist/geoms/Violin.svelte.d.ts +5 -3
  50. package/dist/geoms/Waterfall.svelte +19 -80
  51. package/dist/geoms/Waterfall.svelte.d.ts +2 -0
  52. package/dist/geoms/lib/GeomState.svelte.d.ts +51 -0
  53. package/dist/geoms/lib/GeomState.svelte.js +79 -0
  54. package/dist/geoms/lib/aesthetics.d.ts +36 -0
  55. package/dist/geoms/lib/aesthetics.js +45 -0
  56. package/dist/geoms/lib/areas.d.ts +1 -1
  57. package/dist/geoms/lib/areas.js +4 -2
  58. package/dist/geoms/lib/bars.d.ts +2 -2
  59. package/dist/geoms/lib/bars.js +13 -8
  60. package/dist/geoms/lib/marks/arc.d.ts +24 -0
  61. package/dist/geoms/lib/marks/arc.js +28 -0
  62. package/dist/geoms/lib/marks/area.d.ts +23 -0
  63. package/dist/geoms/lib/marks/area.js +38 -0
  64. package/dist/geoms/lib/marks/bar.d.ts +16 -0
  65. package/dist/geoms/lib/marks/bar.js +43 -0
  66. package/dist/geoms/lib/marks/box.d.ts +14 -0
  67. package/dist/geoms/lib/marks/box.js +30 -0
  68. package/dist/geoms/lib/marks/candlestick.d.ts +27 -0
  69. package/dist/geoms/lib/marks/candlestick.js +52 -0
  70. package/dist/geoms/lib/marks/heatmap.d.ts +24 -0
  71. package/dist/geoms/lib/marks/heatmap.js +41 -0
  72. package/dist/geoms/lib/marks/hexbin.d.ts +29 -0
  73. package/dist/geoms/lib/marks/hexbin.js +62 -0
  74. package/dist/geoms/lib/marks/jitter.d.ts +21 -0
  75. package/dist/geoms/lib/marks/jitter.js +36 -0
  76. package/dist/geoms/lib/marks/line.d.ts +26 -0
  77. package/dist/geoms/lib/marks/line.js +25 -0
  78. package/dist/geoms/lib/marks/point.d.ts +25 -0
  79. package/dist/geoms/lib/marks/point.js +58 -0
  80. package/dist/geoms/lib/marks/ribbon.d.ts +31 -0
  81. package/dist/geoms/lib/marks/ribbon.js +77 -0
  82. package/dist/geoms/lib/marks/violin.d.ts +13 -0
  83. package/dist/geoms/lib/marks/violin.js +31 -0
  84. package/dist/geoms/lib/marks/waterfall.d.ts +25 -0
  85. package/dist/geoms/lib/marks/waterfall.js +58 -0
  86. package/dist/index.d.ts +1 -8
  87. package/dist/index.js +1 -8
  88. package/dist/lib/preset.d.ts +11 -1
  89. package/dist/lib/preset.js +16 -4
  90. package/package.json +1 -1
  91. package/dist/Plot/Arc.svelte +0 -30
  92. package/dist/Plot/Arc.svelte.d.ts +0 -18
  93. package/dist/lib/brewer.d.ts +0 -9
  94. package/dist/lib/brewer.js +0 -25
  95. package/dist/lib/brewing/BoxBrewer.svelte.d.ts +0 -8
  96. package/dist/lib/brewing/BoxBrewer.svelte.js +0 -14
  97. package/dist/lib/brewing/CartesianBrewer.svelte.d.ts +0 -8
  98. package/dist/lib/brewing/CartesianBrewer.svelte.js +0 -21
  99. package/dist/lib/brewing/PieBrewer.svelte.d.ts +0 -8
  100. package/dist/lib/brewing/PieBrewer.svelte.js +0 -14
  101. package/dist/lib/brewing/QuartileBrewer.svelte.d.ts +0 -9
  102. package/dist/lib/brewing/QuartileBrewer.svelte.js +0 -51
  103. package/dist/lib/brewing/ViolinBrewer.svelte.d.ts +0 -8
  104. package/dist/lib/brewing/ViolinBrewer.svelte.js +0 -14
  105. package/dist/lib/brewing/axes.svelte.d.ts +0 -66
  106. package/dist/lib/brewing/axes.svelte.js +0 -270
  107. package/dist/lib/brewing/bars.svelte.d.ts +0 -56
  108. package/dist/lib/brewing/bars.svelte.js +0 -201
  109. package/dist/lib/brewing/brewer.svelte.d.ts +0 -124
  110. package/dist/lib/brewing/brewer.svelte.js +0 -277
  111. package/dist/lib/brewing/dimensions.svelte.d.ts +0 -35
  112. package/dist/lib/brewing/dimensions.svelte.js +0 -56
  113. package/dist/lib/brewing/index.svelte.d.ts +0 -118
  114. package/dist/lib/brewing/index.svelte.js +0 -205
  115. package/dist/lib/brewing/legends.svelte.d.ts +0 -48
  116. package/dist/lib/brewing/legends.svelte.js +0 -137
  117. package/dist/lib/brewing/marks/areas.d.ts +0 -31
  118. package/dist/lib/brewing/marks/areas.js +0 -72
  119. package/dist/lib/brewing/marks/bars.d.ts +0 -1
  120. package/dist/lib/brewing/marks/bars.js +0 -49
  121. package/dist/lib/brewing/scales.svelte.d.ts +0 -24
  122. package/dist/lib/brewing/scales.svelte.js +0 -82
  123. package/dist/lib/context.d.ts +0 -13
  124. package/dist/lib/context.js +0 -131
  125. package/dist/lib/plot/chartProps.d.ts +0 -177
  126. package/dist/lib/plot/chartProps.js +0 -76
  127. package/dist/lib/scales.svelte.d.ts +0 -35
  128. package/dist/lib/scales.svelte.js +0 -151
  129. package/dist/lib/ticks.d.ts +0 -36
  130. package/dist/lib/ticks.js +0 -46
@@ -1,124 +0,0 @@
1
- export function buildLegendGroups(channels: any, colorMap: any, patternMap: any, symbolMap: any): {
2
- field: any;
3
- items: any;
4
- }[];
5
- export class ChartBrewer {
6
- /**
7
- * Override in subclasses to apply stat aggregation.
8
- * @param {Object[]} data
9
- * @param {Object} channels
10
- * @param {string|Function} stat
11
- * @returns {Object[]}
12
- */
13
- transform(data: Object[], _channels: any, _stat: any): Object[];
14
- /** Aggregated data — all derived marks read this, not #rawData */
15
- processedData: Object[];
16
- /** Exposes channels to subclasses for use in their own $derived properties */
17
- get channels(): {};
18
- /** @type {Map<unknown, {fill:string,stroke:string}>} */
19
- colorMap: Map<unknown, {
20
- fill: string;
21
- stroke: string;
22
- }>;
23
- /** @type {Map<unknown, string>} */
24
- patternMap: Map<unknown, string>;
25
- /**
26
- * Unified pattern defs for ChartPatternDefs.
27
- * When fill and pattern map the same field, pattern key = color key (simple case).
28
- * When they differ, each unique (fillKey, patternKey) pair gets its own pattern def
29
- * so bars/areas can have distinct colors per region AND distinct textures per category.
30
- * @type {Array<{ id: string, name: string, fill: string, stroke: string }>}
31
- */
32
- patternDefs: Array<{
33
- id: string;
34
- name: string;
35
- fill: string;
36
- stroke: string;
37
- }>;
38
- /** @type {Map<unknown, string>} */
39
- symbolMap: Map<unknown, string>;
40
- get innerWidth(): number;
41
- get innerHeight(): number;
42
- xScale: import("d3-scale").ScaleBand<string> | (number[] & import("d3-scale").ScaleLinear<number, number, never>) | null;
43
- yScale: import("d3-scale").ScaleLinear<number, number, never> | null;
44
- sizeScale: import("d3-scale").ScalePower<number, number, never> | null;
45
- bars: any;
46
- lines: {
47
- d: string | null;
48
- fill: string;
49
- stroke: string;
50
- points: {
51
- x: number;
52
- y: number;
53
- data: Record<string, unknown>;
54
- i: number;
55
- }[];
56
- key?: unknown;
57
- }[];
58
- areas: {
59
- d: string | null;
60
- fill: any;
61
- stroke: string;
62
- key: any;
63
- colorKey: any;
64
- patternKey: any;
65
- patternId: string | null;
66
- }[] | {
67
- d: never;
68
- fill: any;
69
- stroke: string;
70
- colorKey: null;
71
- patternKey: null;
72
- patternId: null;
73
- }[];
74
- arcs: {
75
- d: string | null;
76
- fill: string;
77
- stroke: string;
78
- key: unknown;
79
- patternId: string | null;
80
- pct: number;
81
- centroid: [number, number];
82
- data: Record<string, unknown>;
83
- }[];
84
- points: {
85
- data: Record<string, unknown>;
86
- cx: number;
87
- cy: number;
88
- r: number;
89
- fill: string;
90
- stroke: string;
91
- symbolPath: string | null;
92
- key: unknown;
93
- }[];
94
- legendGroups: {
95
- field: any;
96
- items: any;
97
- }[];
98
- get margin(): {
99
- top: number;
100
- right: number;
101
- bottom: number;
102
- left: number;
103
- };
104
- get width(): number;
105
- get height(): number;
106
- get mode(): string;
107
- /**
108
- * @param {{ data?: Object[], channels?: Object, width?: number, height?: number, mode?: string, margin?: Object, layers?: Object[], curve?: string, stat?: string|Function }} opts
109
- * Supported channel keys: `x`, `y`, `fill`, `color`, `pattern`, `symbol`, `size`, `label`.
110
- * `frame` is reserved for future animation use (no-op).
111
- */
112
- update(opts?: {
113
- data?: Object[];
114
- channels?: Object;
115
- width?: number;
116
- height?: number;
117
- mode?: string;
118
- margin?: Object;
119
- layers?: Object[];
120
- curve?: string;
121
- stat?: string | Function;
122
- }): void;
123
- #private;
124
- }
@@ -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 };