@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,5 +1,6 @@
1
1
  import { pie, arc } from 'd3-shape'
2
2
  import { toPatternId } from '../../brewing/patterns.js'
3
+ import { literalColor, markEntry } from '../colors.js'
3
4
 
4
5
  /**
5
6
  * Builds arc geometry for pie/donut charts.
@@ -14,6 +15,8 @@ import { toPatternId } from '../../brewing/patterns.js'
14
15
  */
15
16
  export function buildArcs(data, channels, colors, width, height, opts = {}, patterns) {
16
17
  const { color: lf, y: yf } = channels
18
+ // A literal color paints every slice directly; a field indexes the palette scale.
19
+ const lit = literalColor(lf)
17
20
  const radius = Math.min(width, height) / 2
18
21
  // innerRadius: a value <= 1 is a fraction of the radius (responsive donut);
19
22
  // a value > 1 is absolute pixels. Clamp below the outer radius so a bad value
@@ -29,11 +32,13 @@ export function buildArcs(data, channels, colors, width, height, opts = {}, patt
29
32
  // Label radius: midpoint between inner and outer (or 70% out for solid pie)
30
33
  const labelRadius = innerRadius > 0 ? (innerRadius + radius) / 2 : radius * 0.65
31
34
  const labelArc = arc().innerRadius(labelRadius).outerRadius(labelRadius)
32
- return slices.map((slice) => {
33
- const key = slice.data[lf]
34
- const colorEntry = colors?.get(key) ?? { fill: '#888', stroke: '#fff' }
35
+ return slices.map((slice, i) => {
36
+ // With a literal color there's no category field, so key each slice by index to keep
37
+ // them distinct (patterns, which are field-keyed, don't apply to a single literal fill).
38
+ const key = lit ? i : slice.data[lf]
39
+ const colorEntry = markEntry(lit, key, colors, { fill: '#888', stroke: '#fff' })
35
40
  const patternId =
36
- key !== null && key !== undefined && patterns?.has(key) ? toPatternId(String(key)) : null
41
+ !lit && key !== null && key !== undefined && patterns?.has(key) ? toPatternId(String(key)) : null
37
42
  const pct = Math.round(((slice.endAngle - slice.startAngle) / total) * 100)
38
43
  const [cx, cy] = labelArc.centroid(slice)
39
44
  return {
@@ -1,4 +1,5 @@
1
1
  import { toPatternId } from '../patterns.js'
2
+ import { literalColor, markEntry } from '../colors.js'
2
3
 
3
4
  /**
4
5
  * Builds box geometry for box plot charts.
@@ -23,9 +24,12 @@ import { toPatternId } from '../patterns.js'
23
24
  */
24
25
  export function buildBoxes(data, channels, xScale, yScale, colors, opts = {}) {
25
26
  const { x: xf, fill: ff, pattern: pf } = channels
27
+ // A literal fill colours every box directly; a field sub-groups within each x-band.
28
+ const lit = literalColor(ff)
29
+ const field = lit ? undefined : ff
26
30
  const { side = 'center', width, patterns } = opts
27
31
  const bw = typeof xScale.bandwidth === 'function' ? xScale.bandwidth() : 20
28
- const grouped = ff && ff !== xf
32
+ const grouped = field && field !== xf
29
33
  // Offset the box centre to the middle of the chosen half-lane.
30
34
  const laneOffset = (unit) => (side === 'left' ? -unit / 4 : side === 'right' ? unit / 4 : 0)
31
35
  // Texture fill: patternId per box from the pattern channel value (null = solid fill).
@@ -46,7 +50,7 @@ export function buildBoxes(data, channels, xScale, yScale, colors, opts = {}) {
46
50
  const subIndex = fillValues.indexOf(fillVal)
47
51
  const bandStart = xScale(d[xf]) ?? 0
48
52
  const cx = bandStart + subIndex * subBandWidth + subBandWidth / 2 + laneOffset(subBandWidth)
49
- const colorEntry = colors?.get(fillVal) ?? { fill: '#aaa', stroke: '#666' }
53
+ const colorEntry = markEntry(lit, fillVal, colors, { fill: '#aaa', stroke: '#666' })
50
54
 
51
55
  return {
52
56
  data: d,
@@ -71,8 +75,8 @@ export function buildBoxes(data, channels, xScale, yScale, colors, opts = {}) {
71
75
  const whiskerWidth = width !== undefined ? boxWidth * 0.5 : bw * 0.3
72
76
 
73
77
  return data.map((d) => {
74
- const fillKey = ff ? d[ff] : d[xf]
75
- const colorEntry = colors?.get(fillKey) ?? { fill: '#aaa', stroke: '#666' }
78
+ const fillKey = field ? d[field] : d[xf]
79
+ const colorEntry = markEntry(lit, fillKey, colors, { fill: '#aaa', stroke: '#666' })
76
80
  const cx =
77
81
  (xScale(d[xf]) ?? 0) +
78
82
  (typeof xScale.bandwidth === 'function' ? bw / 2 : 0) +
@@ -1,4 +1,5 @@
1
1
  import { line, curveCatmullRom, curveStep } from 'd3-shape'
2
+ import { literalColor } from '../colors.js'
2
3
 
3
4
  /**
4
5
  * @param {Object[]} data
@@ -10,7 +11,12 @@ import { line, curveCatmullRom, curveStep } from 'd3-shape'
10
11
  * @returns {{ d: string | null, fill: string, stroke: string, points: {x:number, y:number, data: Record<string, unknown>, i: number}[], key?: unknown }[]}
11
12
  */
12
13
  export function buildLines(data, channels, xScale, yScale, colors, curve, place = (x, y) => ({ x, y })) {
13
- const { x: xf, y: yf, color: cf } = channels
14
+ const { x: xf, y: yf } = channels
15
+ // A literal color (var()/oklch()/hex/currentColor) is NOT a data field — it's the exact
16
+ // stroke the caller wants for THIS geom. Don't group the series on it, and don't fall
17
+ // back to the shared color scale (which is one value across all geoms); use it directly.
18
+ const lit = literalColor(channels.color)
19
+ const cf = lit ? undefined : channels.color
14
20
  const xPos = (d) =>
15
21
  typeof xScale.bandwidth === 'function' ? xScale(d[xf]) + xScale.bandwidth() / 2 : xScale(d[xf])
16
22
  // Screen points, sorted by the x-channel position, each mapped through place() so the
@@ -25,6 +31,10 @@ export function buildLines(data, channels, xScale, yScale, colors, curve, place
25
31
  }
26
32
  const makeGen = () => {
27
33
  const gen = line()
34
+ // A null y-value is a GAP (a missing period), not a zero: break the path there
35
+ // (d3 `.defined`) instead of letting yScale(null) collapse it onto the 0 baseline.
36
+ // A genuine 0 stays defined and plots.
37
+ .defined((p) => Number.isFinite(p.y) && (yf === undefined || yf === null || (p.data?.[yf] !== undefined && p.data?.[yf] !== null)))
28
38
  .x((p) => p.x)
29
39
  .y((p) => p.y)
30
40
  if (curve === 'smooth') gen.curve(curveCatmullRom)
@@ -34,7 +44,8 @@ export function buildLines(data, channels, xScale, yScale, colors, curve, place
34
44
 
35
45
  if (!cf) {
36
46
  const pts = screenPoints(data)
37
- const stroke = colors?.values().next().value?.stroke ?? '#888'
47
+ // A literal color IS the stroke; a single-series field uses the shared shade.
48
+ const stroke = lit ?? colors?.values().next().value?.stroke ?? '#888'
38
49
  return [{ d: makeGen()(pts), fill: 'none', stroke, points: pts }]
39
50
  }
40
51
  const groups = groupBy(data, cf)
@@ -8,6 +8,7 @@ import {
8
8
  symbolStar
9
9
  } from 'd3-shape'
10
10
  import { defaultPreset } from '../../preset.js'
11
+ import { literalColor, markEntry } from '../colors.js'
11
12
 
12
13
  const SYMBOL_TYPES = [
13
14
  symbolCircle,
@@ -84,9 +85,13 @@ export function buildPoints(
84
85
  jitter = null
85
86
  ) {
86
87
  const { x: xf, y: yf, color: cf, size: sf, symbol: symf } = channels
88
+ // A literal color (var()/oklch()/#hex/currentColor) is the exact fill for every point,
89
+ // not a field to group on — apply it directly instead of looking it up in the scale.
90
+ const lit = literalColor(cf)
91
+ const field = lit ? undefined : cf
87
92
  return data.map((d, i) => {
88
- const colorKey = cf ? d[cf] : null
89
- const colorEntry = colors?.get(colorKey) ?? { fill: '#888', stroke: '#444' }
93
+ const colorKey = field ? d[field] : null
94
+ const colorEntry = markEntry(lit, colorKey, colors, { fill: '#888', stroke: '#444' })
90
95
  const r = sf && sizeScale ? sizeScale(d[sf]) : defaultRadius
91
96
  const shapeName = symf && symbolMap ? (symbolMap.get(d[symf]) ?? 'circle') : null
92
97
  const symbolPath = shapeName ? buildSymbolPath(shapeName, r) : null
@@ -1,4 +1,5 @@
1
1
  import { ascending } from 'd3-array'
2
+ import { literalColor, markEntry } from '../colors.js'
2
3
 
3
4
  /**
4
5
  * Deterministic pseudo-random in [0, 1) from a non-negative integer seed.
@@ -28,6 +29,9 @@ function hashUnit(n) {
28
29
  */
29
30
  export function buildSwarm(data, channels, xScale, yScale, colors, opts = {}) {
30
31
  const { x: xf, y: yf, fill: ff } = channels
32
+ // A literal fill colours every point directly; otherwise group on the fill field.
33
+ const lit = literalColor(ff)
34
+ const field = lit ? undefined : ff
31
35
  const { method = 'jitter', r = 2, side = 'center' } = opts
32
36
  const bw = typeof xScale.bandwidth === 'function' ? xScale.bandwidth() : 40
33
37
  // One-sided layouts get the full half-band on their side; centred straddles ±halfBand.
@@ -51,8 +55,8 @@ export function buildSwarm(data, channels, xScale, yScale, colors, opts = {}) {
51
55
  : rows.map((_, i) => jitterOffset(hashUnit(i), halfBand, side))
52
56
 
53
57
  rows.forEach((d, i) => {
54
- const fillKey = ff ? d[ff] : xVal
55
- const colorEntry = colors?.get(fillKey) ?? { fill: '#aaa', stroke: '#666' }
58
+ const fillKey = field ? d[field] : xVal
59
+ const colorEntry = markEntry(lit, fillKey, colors, { fill: '#aaa', stroke: '#666' })
56
60
  result.push({
57
61
  data: d,
58
62
  cx: center + offsets[i],
@@ -1,5 +1,6 @@
1
1
  import { line, curveCatmullRom } from 'd3-shape'
2
2
  import { toPatternId } from '../patterns.js'
3
+ import { literalColor, markEntry } from '../colors.js'
3
4
 
4
5
  // Relative widths at each stat anchor (fraction of max half-width)
5
6
  const DENSITY_AT = { iqr_min: 0.08, q1: 0.55, median: 1.0, q3: 0.55, iqr_max: 0.08 }
@@ -49,8 +50,11 @@ export function buildViolins(
49
50
  patterns
50
51
  ) {
51
52
  const { x: xf, fill: ff, pattern: pf } = channels
53
+ // A literal fill colours every violin directly; a field sub-groups within each x-band.
54
+ const lit = literalColor(ff)
55
+ const field = lit ? undefined : ff
52
56
  const bw = typeof xScale.bandwidth === 'function' ? xScale.bandwidth() : 40
53
- const grouped = ff && ff !== xf
57
+ const grouped = field && field !== xf
54
58
  // Texture fill: patternId per violin from the pattern channel value (null = solid fill).
55
59
  const patternIdFor = (d) => {
56
60
  const key = pf ? d[pf] : null
@@ -73,7 +77,7 @@ export function buildViolins(
73
77
  const subIndex = fillValues.indexOf(fillVal)
74
78
  const bandStart = xScale(d[xf]) ?? 0
75
79
  const cx = bandStart + subIndex * subBandWidth + subBandWidth / 2
76
- const colorEntry = colors?.get(fillVal) ?? { fill: '#aaa', stroke: '#666' }
80
+ const colorEntry = markEntry(lit, fillVal, colors, { fill: '#aaa', stroke: '#666' })
77
81
 
78
82
  return {
79
83
  data: d,
@@ -90,8 +94,8 @@ export function buildViolins(
90
94
  const halfMax = bw * 0.45
91
95
 
92
96
  return data.map((d) => {
93
- const fillKey = ff ? d[ff] : d[xf]
94
- const colorEntry = colors?.get(fillKey) ?? { fill: '#aaa', stroke: '#666' }
97
+ const fillKey = field ? d[field] : d[xf]
98
+ const colorEntry = markEntry(lit, fillKey, colors, { fill: '#aaa', stroke: '#666' })
95
99
  const cx = (xScale(d[xf]) ?? 0) + (typeof xScale.bandwidth === 'function' ? bw / 2 : 0)
96
100
 
97
101
  return {
@@ -21,9 +21,19 @@ export namespace defaultPreset {
21
21
  }
22
22
  namespace opacity {
23
23
  let area: number;
24
+ let bar: number;
25
+ let line: number;
26
+ let point: number;
27
+ let arc: number;
24
28
  let box: number;
25
29
  let violin: number;
26
- let point: number;
30
+ let jitter: number;
31
+ let heatmap: number;
32
+ let candlestick: number;
33
+ let hexbin: number;
34
+ let ribbon: number;
35
+ let waterfall: number;
36
+ let rule: number;
27
37
  }
28
38
  let patterns: string[];
29
39
  let symbols: string[];
@@ -7,11 +7,23 @@ export const defaultPreset = {
7
7
  light: { fill: '300', stroke: '700' },
8
8
  dark: { fill: '500', stroke: '200' }
9
9
  },
10
+ // Per-geom default mark opacity. `alpha` (a fixed 0–1 prop on each geom / Plot.Root)
11
+ // overrides these; solid marks default to 1 so `alpha` is the single opacity knob.
10
12
  opacity: {
11
- area: 0.6,
12
- box: 0.5,
13
- violin: 0.5,
14
- point: 0.8
13
+ area: 0.6,
14
+ bar: 1,
15
+ line: 1,
16
+ point: 0.8,
17
+ arc: 1,
18
+ box: 0.5,
19
+ violin: 0.5,
20
+ jitter: 0.8,
21
+ heatmap: 1,
22
+ candlestick: 1,
23
+ hexbin: 1,
24
+ ribbon: 0.5,
25
+ waterfall: 1,
26
+ rule: 1
15
27
  },
16
28
  patterns: ['diagonal', 'dots', 'triangles', 'hatch', 'lattice', 'swell',
17
29
  'checkerboard', 'waves', 'petals', 'brick', 'diamonds', 'tile',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/chart",
3
- "version": "1.3.8",
3
+ "version": "1.3.10",
4
4
  "type": "module",
5
5
  "description": "Data-driven chart components",
6
6
  "repository": {
@@ -1,30 +0,0 @@
1
- <script lang="ts">
2
- import { getContext } from 'svelte'
3
- import type { ChartBrewer } from '../lib/brewing/brewer.svelte.js'
4
-
5
- const brewer = getContext<ChartBrewer>('chart-brewer')
6
- </script>
7
-
8
- {#if brewer && brewer.arcs && brewer.arcs.length > 0}
9
- <g
10
- class="chart-arcs"
11
- data-plot-type="arc"
12
- transform="translate({brewer.width / 2}, {brewer.height / 2})"
13
- >
14
- {#each brewer.arcs as arc (arc.key)}
15
- <path
16
- d={arc.d}
17
- fill={arc.fill}
18
- stroke={arc.stroke}
19
- stroke-width="1"
20
- data-plot-element="arc"
21
- />
22
- {/each}
23
- </g>
24
- {/if}
25
-
26
- <style>
27
- .chart-arcs {
28
- pointer-events: none;
29
- }
30
- </style>
@@ -1,18 +0,0 @@
1
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
- $$bindings?: Bindings;
4
- } & Exports;
5
- (internal: unknown, props: {
6
- $$events?: Events;
7
- $$slots?: Slots;
8
- }): Exports & {
9
- $set?: any;
10
- $on?: any;
11
- };
12
- z_$$bindings?: Bindings;
13
- }
14
- declare const Arc: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
- [evt: string]: CustomEvent<any>;
16
- }, {}, {}, string>;
17
- type Arc = InstanceType<typeof Arc>;
18
- export default Arc;
@@ -1,9 +0,0 @@
1
- /**
2
- * Get fill patterns for a set of values
3
- *
4
- * @param {Array} values - Array of values
5
- * @param {Object} swatch - Object with keys for color, gray, and pattern
6
- * @param {Boolean} gray - Boolean to determine if gray or color
7
- * @returns {Object} - Object with keys for pattern and color
8
- */
9
- export function getFillPatterns(values: any[], swatch: Object, gray?: boolean): Object;
@@ -1,25 +0,0 @@
1
- /**
2
- * Get fill patterns for a set of values
3
- *
4
- * @param {Array} values - Array of values
5
- * @param {Object} swatch - Object with keys for color, gray, and pattern
6
- * @param {Boolean} gray - Boolean to determine if gray or color
7
- * @returns {Object} - Object with keys for pattern and color
8
- */
9
- export function getFillPatterns(values, swatch, gray = false) {
10
- const colors = gray ? swatch.keys.gray : swatch.keys.color
11
- const max_colors = colors.length
12
- const max_patterns = swatch.keys.pattern.length
13
-
14
- const mix = values
15
- .map((value, index) => ({
16
- [value]: {
17
- pattern: swatch.keys.pattern[index % max_patterns],
18
- color: colors[index % max_colors]
19
- }
20
- }))
21
- .reduce((acc, current) => ({ ...acc, ...current }), {})
22
- return mix
23
- }
24
-
25
- // export function getStrokePatterns() {}
@@ -1,8 +0,0 @@
1
- /**
2
- * Brewer for box plots.
3
- * fill = box interior color, color = whisker/outline stroke.
4
- */
5
- export class BoxBrewer extends QuartileBrewer {
6
- boxes: any[];
7
- }
8
- import { QuartileBrewer } from './QuartileBrewer.svelte.js';
@@ -1,14 +0,0 @@
1
- import { QuartileBrewer } from './QuartileBrewer.svelte.js'
2
- import { buildBoxes } from './marks/boxes.js'
3
-
4
- /**
5
- * Brewer for box plots.
6
- * fill = box interior color, color = whisker/outline stroke.
7
- */
8
- export class BoxBrewer extends QuartileBrewer {
9
- boxes = $derived(
10
- this.xScale && this.yScale
11
- ? buildBoxes(this.processedData, this.channels, this.xScale, this.yScale, this.colorMap)
12
- : []
13
- )
14
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Brewer for cartesian charts (Bar, Line, Area).
3
- * Groups by x (and fill/color if set) and applies the given stat.
4
- */
5
- export class CartesianBrewer extends ChartBrewer {
6
- transform(data: any, channels: any, stat: any): any;
7
- }
8
- import { ChartBrewer } from './brewer.svelte.js';
@@ -1,21 +0,0 @@
1
- import { SvelteSet } from 'svelte/reactivity'
2
- import { ChartBrewer } from './brewer.svelte.js'
3
- import { applyAggregate } from './stats.js'
4
-
5
- /**
6
- * Brewer for cartesian charts (Bar, Line, Area).
7
- * Groups by x (and fill/color if set) and applies the given stat.
8
- */
9
- export class CartesianBrewer extends ChartBrewer {
10
- transform(data, channels, stat) {
11
- if (stat === 'identity' || !channels.x || !channels.y) return data
12
- // Group by all mapped aesthetic dimensions so they survive aggregation.
13
- // e.g. x=region, fill=region, pattern=quarter → by=['region','quarter']
14
- const by = [
15
- ...new SvelteSet(
16
- [channels.x, channels.fill, channels.color, channels.pattern].filter(Boolean)
17
- )
18
- ]
19
- return applyAggregate(data, { by, value: channels.y, stat })
20
- }
21
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Brewer for pie charts. Always aggregates by the label field.
3
- * 'identity' is not meaningful for pie charts — falls back to 'sum'.
4
- */
5
- export class PieBrewer extends ChartBrewer {
6
- transform(data: any, channels: any, stat: any): any;
7
- }
8
- import { ChartBrewer } from './brewer.svelte.js';
@@ -1,14 +0,0 @@
1
- import { ChartBrewer } from './brewer.svelte.js'
2
- import { applyAggregate } from './stats.js'
3
-
4
- /**
5
- * Brewer for pie charts. Always aggregates by the label field.
6
- * 'identity' is not meaningful for pie charts — falls back to 'sum'.
7
- */
8
- export class PieBrewer extends ChartBrewer {
9
- transform(data, channels, stat) {
10
- if (!channels.label || !channels.y) return data
11
- const effectiveStat = stat === 'identity' ? 'sum' : (stat ?? 'sum')
12
- return applyAggregate(data, { by: [channels.label], value: channels.y, stat: effectiveStat })
13
- }
14
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Shared base for box and violin plots.
3
- * Groups by x + fill (primary) or x + color (fallback) and computes quartile statistics.
4
- * Subclasses add their mark-specific $derived (boxes, violins, etc.).
5
- */
6
- export class QuartileBrewer extends ChartBrewer {
7
- transform(data: any, channels: any): any;
8
- }
9
- import { ChartBrewer } from './brewer.svelte.js';
@@ -1,51 +0,0 @@
1
- import { quantile, ascending } from 'd3-array'
2
- import { dataset } from '@rokkit/data'
3
- import { ChartBrewer } from './brewer.svelte.js'
4
- import { buildXScale, buildYScale } from './scales.js'
5
-
6
- function sortedQuantile(values, p) {
7
- return quantile([...values].sort(ascending), p)
8
- }
9
-
10
- /**
11
- * Shared base for box and violin plots.
12
- * Groups by x + fill (primary) or x + color (fallback) and computes quartile statistics.
13
- * Subclasses add their mark-specific $derived (boxes, violins, etc.).
14
- */
15
- export class QuartileBrewer extends ChartBrewer {
16
- transform(data, channels) {
17
- if (!channels.x || !channels.y) return data
18
- const by = [channels.x, channels.fill ?? channels.color].filter(Boolean)
19
- return dataset(data)
20
- .groupBy(...by)
21
- .summarize((row) => row[channels.y], {
22
- q1: (v) => sortedQuantile(v, 0.25),
23
- median: (v) => sortedQuantile(v, 0.5),
24
- q3: (v) => sortedQuantile(v, 0.75),
25
- iqr_min: (v) => {
26
- const q1 = sortedQuantile(v, 0.25)
27
- const q3 = sortedQuantile(v, 0.75)
28
- return q1 - 1.5 * (q3 - q1)
29
- },
30
- iqr_max: (v) => {
31
- const q1 = sortedQuantile(v, 0.25)
32
- const q3 = sortedQuantile(v, 0.75)
33
- return q3 + 1.5 * (q3 - q1)
34
- }
35
- })
36
- .rollup()
37
- .select()
38
- }
39
-
40
- xScale = $derived(
41
- this.channels.x && this.processedData.length > 0
42
- ? buildXScale(this.processedData, this.channels.x, this.innerWidth)
43
- : null
44
- )
45
-
46
- yScale = $derived(
47
- this.channels.y && this.processedData.length > 0
48
- ? buildYScale(this.processedData, 'iqr_max', this.innerHeight)
49
- : null
50
- )
51
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Brewer for violin plots.
3
- * fill = violin body color, color = outline stroke.
4
- */
5
- export class ViolinBrewer extends QuartileBrewer {
6
- violins: any;
7
- }
8
- import { QuartileBrewer } from './QuartileBrewer.svelte.js';
@@ -1,14 +0,0 @@
1
- import { QuartileBrewer } from './QuartileBrewer.svelte.js'
2
- import { buildViolins } from './marks/violins.js'
3
-
4
- /**
5
- * Brewer for violin plots.
6
- * fill = violin body color, color = outline stroke.
7
- */
8
- export class ViolinBrewer extends QuartileBrewer {
9
- violins = $derived(
10
- this.xScale && this.yScale
11
- ? buildViolins(this.processedData, this.channels, this.xScale, this.yScale, this.colorMap)
12
- : []
13
- )
14
- }
@@ -1,66 +0,0 @@
1
- /**
2
- * Creates x-axis tick data for rendering
3
- *
4
- * @param {Object} scales - Chart scales
5
- * @param {Function} scales.x - X-axis scale
6
- * @param {Object} dimensions - Chart dimensions
7
- * @param {Object} options - Axis options
8
- * @param {number} [options.tickCount] - Number of ticks to show
9
- * @param {Function} [options.tickFormat] - Tick formatting function
10
- * @param {string} [options.label] - Axis label
11
- * @returns {AxisData} Axis rendering data
12
- */
13
- export function createXAxis(scales: {
14
- x: Function;
15
- }, dimensions: Object, options: {
16
- tickCount?: number | undefined;
17
- tickFormat?: Function | undefined;
18
- label?: string | undefined;
19
- }): AxisData;
20
- /**
21
- * Creates y-axis tick data for rendering
22
- *
23
- * @param {Object} scales - Chart scales
24
- * @param {Function} scales.y - Y-axis scale
25
- * @param {Object} dimensions - Chart dimensions
26
- * @param {Object} options - Axis options
27
- * @param {number} [options.tickCount] - Number of ticks to show
28
- * @param {Function} [options.tickFormat] - Tick formatting function
29
- * @param {string} [options.label] - Axis label
30
- * @returns {AxisData} Axis rendering data
31
- */
32
- export function createYAxis(scales: {
33
- y: Function;
34
- }, dimensions: Object, options: {
35
- tickCount?: number | undefined;
36
- tickFormat?: Function | undefined;
37
- label?: string | undefined;
38
- }): AxisData;
39
- /**
40
- * Creates grid line data for rendering
41
- *
42
- * @param {Object} scales - Chart scales
43
- * @param {Object} dimensions - Chart dimensions
44
- * @param {Object} options - Grid options
45
- * @param {string} [options.direction='both'] - Grid direction ('x', 'y', or 'both')
46
- * @param {number} [options.xTickCount] - Number of x-axis ticks
47
- * @param {number} [options.yTickCount] - Number of y-axis ticks
48
- * @returns {Object} Grid rendering data
49
- */
50
- export function createGrid(scales: Object, dimensions: Object, options: {
51
- direction?: string | undefined;
52
- xTickCount?: number | undefined;
53
- yTickCount?: number | undefined;
54
- }): Object;
55
- /**
56
- * Creates DOM attributes for a tick element
57
- *
58
- * @param {TickData} tick - Tick data
59
- * @param {string} axis - Axis type ('x' or 'y')
60
- * @returns {Object} Attributes for the tick
61
- */
62
- export function createTickAttributes(tick: TickData, axis: string): Object;
63
- export type TickData = import("./types").TickData;
64
- export type AxisData = import("./types").AxisData;
65
- export type ChartScales = import("./types").ChartScales;
66
- export type ChartDimensions = import("./types").ChartDimensions;