@rokkit/chart 1.0.0-next.151 → 1.0.0-next.158

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 (86) hide show
  1. package/dist/PlotState.svelte.d.ts +26 -0
  2. package/dist/index.d.ts +6 -1
  3. package/dist/lib/brewing/BoxBrewer.svelte.d.ts +3 -5
  4. package/dist/lib/brewing/QuartileBrewer.svelte.d.ts +9 -0
  5. package/dist/lib/brewing/ViolinBrewer.svelte.d.ts +3 -4
  6. package/dist/lib/brewing/colors.d.ts +10 -1
  7. package/dist/lib/brewing/marks/points.d.ts +17 -2
  8. package/dist/lib/keyboard-nav.d.ts +15 -0
  9. package/dist/lib/plot/preset.d.ts +1 -1
  10. package/dist/lib/preset.d.ts +30 -0
  11. package/package.json +2 -1
  12. package/src/AnimatedPlot.svelte +375 -207
  13. package/src/Chart.svelte +81 -84
  14. package/src/ChartProvider.svelte +10 -0
  15. package/src/FacetPlot/Panel.svelte +30 -16
  16. package/src/FacetPlot.svelte +100 -76
  17. package/src/Plot/Area.svelte +26 -19
  18. package/src/Plot/Axis.svelte +81 -59
  19. package/src/Plot/Bar.svelte +47 -89
  20. package/src/Plot/Grid.svelte +23 -19
  21. package/src/Plot/Legend.svelte +213 -147
  22. package/src/Plot/Line.svelte +31 -21
  23. package/src/Plot/Point.svelte +35 -22
  24. package/src/Plot/Root.svelte +46 -91
  25. package/src/Plot/Timeline.svelte +82 -82
  26. package/src/Plot/Tooltip.svelte +68 -62
  27. package/src/Plot.svelte +290 -174
  28. package/src/PlotState.svelte.js +338 -265
  29. package/src/Sparkline.svelte +95 -56
  30. package/src/charts/AreaChart.svelte +22 -20
  31. package/src/charts/BarChart.svelte +23 -21
  32. package/src/charts/BoxPlot.svelte +15 -15
  33. package/src/charts/BubbleChart.svelte +17 -17
  34. package/src/charts/LineChart.svelte +20 -20
  35. package/src/charts/PieChart.svelte +30 -20
  36. package/src/charts/ScatterPlot.svelte +20 -19
  37. package/src/charts/ViolinPlot.svelte +15 -15
  38. package/src/crossfilter/CrossFilter.svelte +33 -29
  39. package/src/crossfilter/FilterBar.svelte +17 -25
  40. package/src/crossfilter/FilterHistogram.svelte +290 -0
  41. package/src/crossfilter/FilterSlider.svelte +69 -65
  42. package/src/crossfilter/createCrossFilter.svelte.js +94 -90
  43. package/src/geoms/Arc.svelte +114 -69
  44. package/src/geoms/Area.svelte +67 -39
  45. package/src/geoms/Bar.svelte +184 -126
  46. package/src/geoms/Box.svelte +101 -91
  47. package/src/geoms/LabelPill.svelte +11 -11
  48. package/src/geoms/Line.svelte +110 -86
  49. package/src/geoms/Point.svelte +130 -90
  50. package/src/geoms/Violin.svelte +51 -41
  51. package/src/geoms/lib/areas.js +122 -99
  52. package/src/geoms/lib/bars.js +195 -144
  53. package/src/index.js +21 -14
  54. package/src/lib/brewing/BoxBrewer.svelte.js +8 -50
  55. package/src/lib/brewing/CartesianBrewer.svelte.js +11 -7
  56. package/src/lib/brewing/PieBrewer.svelte.js +5 -5
  57. package/src/lib/brewing/QuartileBrewer.svelte.js +51 -0
  58. package/src/lib/brewing/ViolinBrewer.svelte.js +8 -49
  59. package/src/lib/brewing/brewer.svelte.js +242 -195
  60. package/src/lib/brewing/colors.js +34 -5
  61. package/src/lib/brewing/marks/arcs.js +28 -28
  62. package/src/lib/brewing/marks/areas.js +54 -41
  63. package/src/lib/brewing/marks/bars.js +34 -34
  64. package/src/lib/brewing/marks/boxes.js +51 -51
  65. package/src/lib/brewing/marks/lines.js +37 -30
  66. package/src/lib/brewing/marks/points.js +74 -26
  67. package/src/lib/brewing/marks/violins.js +57 -57
  68. package/src/lib/brewing/patterns.js +25 -11
  69. package/src/lib/brewing/scales.js +17 -17
  70. package/src/lib/brewing/stats.js +37 -29
  71. package/src/lib/brewing/symbols.js +1 -1
  72. package/src/lib/chart.js +2 -1
  73. package/src/lib/keyboard-nav.js +37 -0
  74. package/src/lib/plot/crossfilter.js +5 -5
  75. package/src/lib/plot/facet.js +30 -30
  76. package/src/lib/plot/frames.js +30 -29
  77. package/src/lib/plot/helpers.js +4 -4
  78. package/src/lib/plot/preset.js +48 -34
  79. package/src/lib/plot/scales.js +64 -39
  80. package/src/lib/plot/stat.js +47 -47
  81. package/src/lib/preset.js +41 -0
  82. package/src/patterns/DefinePatterns.svelte +24 -24
  83. package/src/patterns/README.md +3 -0
  84. package/src/patterns/patterns.js +328 -176
  85. package/src/patterns/scale.js +61 -32
  86. package/src/spec/chart-spec.js +64 -21
@@ -1,69 +1,108 @@
1
1
  <script>
2
- import { scaleLinear } from 'd3-scale'
3
- import { line as d3line, area as d3area, curveCatmullRom } from 'd3-shape'
2
+ import { scaleLinear } from 'd3-scale'
3
+ import { line as d3line, area as d3area, curveCatmullRom } from 'd3-shape'
4
+ import PatternDef from './patterns/PatternDef.svelte'
5
+ import { PATTERNS } from './patterns/patterns.js'
4
6
 
5
- /**
6
- * @type {number[] | object[]}
7
- */
8
- let {
9
- data = [],
10
- field = undefined,
11
- type = 'line',
12
- curve = 'linear',
13
- color = 'primary',
14
- width = 80,
15
- height = 24,
16
- min = undefined,
17
- max = undefined
18
- } = $props()
7
+ /**
8
+ * @type {number[] | object[]}
9
+ */
10
+ let {
11
+ data = [],
12
+ field = undefined,
13
+ type = 'line',
14
+ curve = 'linear',
15
+ color = 'primary',
16
+ pattern = undefined,
17
+ width = 80,
18
+ height = 24,
19
+ min = undefined,
20
+ max = undefined
21
+ } = $props()
19
22
 
20
- const values = $derived(
21
- field ? data.map((d) => Number(d[field])) : data.map(Number)
22
- )
23
+ const values = $derived(field ? data.map((d) => Number(d[field])) : data.map(Number))
23
24
 
24
- const yMin = $derived(min ?? Math.min(...values))
25
- const yMax = $derived(max ?? Math.max(...values))
25
+ const yMin = $derived(min ?? Math.min(...values))
26
+ const yMax = $derived(max ?? Math.max(...values))
26
27
 
27
- const xScale = $derived(
28
- scaleLinear().domain([0, values.length - 1]).range([0, width])
29
- )
30
- const yScale = $derived(
31
- scaleLinear().domain([yMin, yMax]).range([height, 0])
32
- )
28
+ const xScale = $derived(
29
+ scaleLinear()
30
+ .domain([0, values.length - 1])
31
+ .range([0, width])
32
+ )
33
+ const yScale = $derived(scaleLinear().domain([yMin, yMax]).range([height, 0]))
33
34
 
34
- const linePath = $derived.by(() => {
35
- const gen = d3line().x((_, i) => xScale(i)).y((v) => yScale(v))
36
- if (curve === 'smooth') gen.curve(curveCatmullRom)
37
- return gen(values)
38
- })
35
+ const linePath = $derived.by(() => {
36
+ const gen = d3line()
37
+ .x((_, i) => xScale(i))
38
+ .y((v) => yScale(v))
39
+ if (curve === 'smooth') gen.curve(curveCatmullRom)
40
+ return gen(values)
41
+ })
39
42
 
40
- const areaPath = $derived.by(() => {
41
- const gen = d3area().x((_, i) => xScale(i)).y0(height).y1((v) => yScale(v))
42
- if (curve === 'smooth') gen.curve(curveCatmullRom)
43
- return gen(values)
44
- })
43
+ const areaPath = $derived.by(() => {
44
+ const gen = d3area()
45
+ .x((_, i) => xScale(i))
46
+ .y0(height)
47
+ .y1((v) => yScale(v))
48
+ if (curve === 'smooth') gen.curve(curveCatmullRom)
49
+ return gen(values)
50
+ })
45
51
 
46
- const barWidth = $derived(Math.max(1, width / values.length - 1))
52
+ const barWidth = $derived(Math.max(1, width / values.length - 1))
47
53
 
48
- const strokeColor = $derived(`rgb(var(--color-${color}-500, 100,116,139))`)
49
- const fillColor = $derived(`rgba(var(--color-${color}-300), 0.25)`)
54
+ const strokeColor = $derived(`rgb(var(--color-${color}-500, 100,116,139))`)
55
+ const fillColor = $derived(`rgba(var(--color-${color}-300), 0.25)`)
56
+
57
+ const patternId = 'sparkline-pattern'
58
+ const patternMarks = $derived(pattern ? (PATTERNS[pattern] ?? null) : null)
50
59
  </script>
51
60
 
52
61
  <svg {width} {height} style="overflow: visible; display: block;">
53
- {#if type === 'line'}
54
- <path d={linePath} fill="none" stroke={strokeColor} stroke-width="1.5" stroke-linejoin="round" stroke-linecap="round" />
55
- {:else if type === 'area'}
56
- <path d={areaPath} fill={fillColor} stroke="none" />
57
- <path d={linePath} fill="none" stroke={strokeColor} stroke-width="1.5" stroke-linejoin="round" stroke-linecap="round" />
58
- {:else if type === 'bar'}
59
- {#each values as v, i (i)}
60
- <rect
61
- x={xScale(i) - barWidth / 2}
62
- y={yScale(v)}
63
- width={barWidth}
64
- height={height - yScale(v)}
65
- fill={strokeColor}
66
- />
67
- {/each}
68
- {/if}
62
+ {#if patternMarks}
63
+ <defs>
64
+ <PatternDef id={patternId} marks={patternMarks} stroke={strokeColor} />
65
+ </defs>
66
+ {/if}
67
+
68
+ {#if type === 'line'}
69
+ <path
70
+ d={linePath}
71
+ fill="none"
72
+ stroke={strokeColor}
73
+ stroke-width="1.5"
74
+ stroke-linejoin="round"
75
+ stroke-linecap="round"
76
+ />
77
+ {:else if type === 'area'}
78
+ <path d={areaPath} fill={patternMarks ? `url(#${patternId})` : fillColor} stroke="none" />
79
+ <path
80
+ d={linePath}
81
+ fill="none"
82
+ stroke={strokeColor}
83
+ stroke-width="1.5"
84
+ stroke-linejoin="round"
85
+ stroke-linecap="round"
86
+ />
87
+ {:else if type === 'bar'}
88
+ {#each values as v, i (i)}
89
+ <rect
90
+ x={xScale(i) - barWidth / 2}
91
+ y={yScale(v)}
92
+ width={barWidth}
93
+ height={height - yScale(v)}
94
+ fill={strokeColor}
95
+ />
96
+ {#if patternMarks}
97
+ <rect
98
+ x={xScale(i) - barWidth / 2}
99
+ y={yScale(v)}
100
+ width={barWidth}
101
+ height={height - yScale(v)}
102
+ fill="url(#{patternId})"
103
+ pointer-events="none"
104
+ />
105
+ {/if}
106
+ {/each}
107
+ {/if}
69
108
  </svg>
@@ -1,25 +1,27 @@
1
1
  <script>
2
- import Plot from '../Plot.svelte'
3
- import Area from '../geoms/Area.svelte'
2
+ import Plot from '../Plot.svelte'
3
+ import Area from '../geoms/Area.svelte'
4
4
 
5
- /** @type {import('../lib/plot/chartProps.js').LineAreaChartProps} */
6
- let {
7
- data = [],
8
- x = undefined,
9
- y = undefined,
10
- fill = undefined,
11
- stat = 'identity',
12
- curve = undefined,
13
- pattern = undefined,
14
- stack = false,
15
- width = 600,
16
- height = 400,
17
- mode = 'light',
18
- grid = true,
19
- legend = false
20
- } = $props()
5
+ /** @type {import('../lib/plot/chartProps.js').LineAreaChartProps} */
6
+ let {
7
+ data = [],
8
+ x = undefined,
9
+ y = undefined,
10
+ fill = undefined,
11
+ stat = 'identity',
12
+ curve = undefined,
13
+ pattern = undefined,
14
+ stack = false,
15
+ width = 600,
16
+ height = 400,
17
+ mode = 'light',
18
+ grid = true,
19
+ legend = false,
20
+ xFormat = undefined,
21
+ yFormat = undefined
22
+ } = $props()
21
23
  </script>
22
24
 
23
- <Plot {data} {width} {height} {mode} {grid} {legend}>
24
- <Area {x} {y} color={fill} {pattern} {stat} options={{ curve, stack }} />
25
+ <Plot {data} {width} {height} {mode} {grid} {legend} {xFormat} {yFormat}>
26
+ <Area {x} {y} color={fill} {pattern} {stat} options={{ curve, stack }} />
25
27
  </Plot>
@@ -1,26 +1,28 @@
1
1
  <script>
2
- import Plot from '../Plot.svelte'
3
- import Bar from '../geoms/Bar.svelte'
2
+ import Plot from '../Plot.svelte'
3
+ import Bar from '../geoms/Bar.svelte'
4
4
 
5
- /** @type {import('../lib/plot/chartProps.js').BarChartProps} */
6
- let {
7
- data = [],
8
- x = undefined,
9
- y = undefined,
10
- fill = undefined, // mapped to color channel
11
- pattern = undefined,
12
- width = 600,
13
- height = 400,
14
- mode = 'light',
15
- grid = true,
16
- legend = false,
17
- stat = 'identity',
18
- stack = false,
19
- label = false,
20
- tooltip = false
21
- } = $props()
5
+ /** @type {import('../lib/plot/chartProps.js').BarChartProps} */
6
+ let {
7
+ data = [],
8
+ x = undefined,
9
+ y = undefined,
10
+ fill = undefined, // mapped to color channel
11
+ pattern = undefined,
12
+ width = 600,
13
+ height = 400,
14
+ mode = 'light',
15
+ grid = true,
16
+ legend = false,
17
+ stat = 'identity',
18
+ stack = false,
19
+ label = false,
20
+ tooltip = false,
21
+ xFormat = undefined,
22
+ yFormat = undefined
23
+ } = $props()
22
24
  </script>
23
25
 
24
- <Plot {data} {width} {height} {mode} {grid} {legend} {tooltip}>
25
- <Bar {x} {y} color={fill} {pattern} {label} {stat} options={{ stack }} />
26
+ <Plot {data} {width} {height} {mode} {grid} {legend} {tooltip} {xFormat} {yFormat}>
27
+ <Bar {x} {y} color={fill} {pattern} {label} {stat} options={{ stack }} />
26
28
  </Plot>
@@ -1,21 +1,21 @@
1
1
  <script>
2
- import Plot from '../Plot.svelte'
3
- import Box from '../geoms/Box.svelte'
2
+ import Plot from '../Plot.svelte'
3
+ import Box from '../geoms/Box.svelte'
4
4
 
5
- /** @type {import('../lib/plot/chartProps.js').BoxViolinChartProps} */
6
- let {
7
- data = [],
8
- x = undefined,
9
- y = undefined,
10
- fill = undefined,
11
- width = 600,
12
- height = 400,
13
- mode = 'light',
14
- grid = true,
15
- legend = false
16
- } = $props()
5
+ /** @type {import('../lib/plot/chartProps.js').BoxViolinChartProps} */
6
+ let {
7
+ data = [],
8
+ x = undefined,
9
+ y = undefined,
10
+ fill = undefined,
11
+ width = 600,
12
+ height = 400,
13
+ mode = 'light',
14
+ grid = true,
15
+ legend = false
16
+ } = $props()
17
17
  </script>
18
18
 
19
19
  <Plot {data} {width} {height} {mode} {grid} {legend}>
20
- <Box {x} {y} {fill} />
20
+ <Box {x} {y} {fill} />
21
21
  </Plot>
@@ -1,23 +1,23 @@
1
1
  <script>
2
- import Plot from '../Plot.svelte'
3
- import Point from '../geoms/Point.svelte'
2
+ import Plot from '../Plot.svelte'
3
+ import Point from '../geoms/Point.svelte'
4
4
 
5
- /** @type {import('../lib/plot/chartProps.js').ScatterBubbleChartProps} */
6
- let {
7
- data = [],
8
- x = undefined,
9
- y = undefined,
10
- color = undefined,
11
- symbol: _symbol = undefined,
12
- size, // required: field name for bubble radius
13
- width = 600,
14
- height = 400,
15
- mode = 'light',
16
- grid = true,
17
- legend = false
18
- } = $props()
5
+ /** @type {import('../lib/plot/chartProps.js').ScatterBubbleChartProps} */
6
+ let {
7
+ data = [],
8
+ x = undefined,
9
+ y = undefined,
10
+ color = undefined,
11
+ symbol: _symbol = undefined,
12
+ size, // required: field name for bubble radius
13
+ width = 600,
14
+ height = 400,
15
+ mode = 'light',
16
+ grid = true,
17
+ legend = false
18
+ } = $props()
19
19
  </script>
20
20
 
21
21
  <Plot {data} {width} {height} {mode} {grid} {legend}>
22
- <Point {x} {y} {color} {size} />
22
+ <Point {x} {y} {color} {size} />
23
23
  </Plot>
@@ -1,26 +1,26 @@
1
1
  <script>
2
- import Plot from '../Plot.svelte'
3
- import Line from '../geoms/Line.svelte'
2
+ import Plot from '../Plot.svelte'
3
+ import Line from '../geoms/Line.svelte'
4
4
 
5
- /** @type {import('../lib/plot/chartProps.js').LineAreaChartProps} */
6
- let {
7
- data = [],
8
- x = undefined,
9
- y = undefined,
10
- color = undefined,
11
- stat = 'identity',
12
- symbol = undefined,
13
- curve = undefined, // forwarded to Line options
14
- label = false,
15
- tooltip = false,
16
- width = 600,
17
- height = 400,
18
- mode = 'light',
19
- grid = true,
20
- legend = false
21
- } = $props()
5
+ /** @type {import('../lib/plot/chartProps.js').LineAreaChartProps} */
6
+ let {
7
+ data = [],
8
+ x = undefined,
9
+ y = undefined,
10
+ color = undefined,
11
+ stat = 'identity',
12
+ symbol = undefined,
13
+ curve = undefined, // forwarded to Line options
14
+ label = false,
15
+ tooltip = false,
16
+ width = 600,
17
+ height = 400,
18
+ mode = 'light',
19
+ grid = true,
20
+ legend = false
21
+ } = $props()
22
22
  </script>
23
23
 
24
24
  <Plot {data} {width} {height} {mode} {grid} {legend} {tooltip}>
25
- <Line {x} {y} {color} {symbol} {label} {stat} options={{ curve }} />
25
+ <Line {x} {y} {color} {symbol} {label} {stat} options={{ curve }} />
26
26
  </Plot>
@@ -1,25 +1,35 @@
1
1
  <script>
2
- import Plot from '../Plot.svelte'
3
- import Arc from '../geoms/Arc.svelte'
2
+ import Plot from '../Plot.svelte'
3
+ import Arc from '../geoms/Arc.svelte'
4
4
 
5
- /** @type {import('../lib/plot/chartProps.js').PieChartProps} */
6
- let {
7
- data = [],
8
- label = undefined,
9
- y = undefined,
10
- fill = undefined,
11
- pattern = undefined,
12
- innerRadius = 0,
13
- labelFn = undefined,
14
- tooltip = false,
15
- width = 400,
16
- height = 400,
17
- mode = 'light',
18
- legend = false,
19
- stat = 'sum'
20
- } = $props()
5
+ /** @type {import('../lib/plot/chartProps.js').PieChartProps} */
6
+ let {
7
+ data = [],
8
+ label = undefined,
9
+ y = undefined,
10
+ fill = undefined,
11
+ pattern = undefined,
12
+ innerRadius = 0,
13
+ labelFn = undefined,
14
+ tooltip = false,
15
+ width = 400,
16
+ height = 400,
17
+ mode = 'light',
18
+ legend = false,
19
+ stat = 'sum'
20
+ } = $props()
21
21
  </script>
22
22
 
23
- <Plot {data} {width} {height} {mode} grid={false} axes={false} margin={{ top: 10, right: 10, bottom: 10, left: 10 }} {legend} {tooltip}>
24
- <Arc theta={y} fill={label ?? fill} {pattern} {labelFn} {stat} options={{ innerRadius }} />
23
+ <Plot
24
+ {data}
25
+ {width}
26
+ {height}
27
+ {mode}
28
+ grid={false}
29
+ axes={false}
30
+ margin={{ top: 10, right: 10, bottom: 10, left: 10 }}
31
+ {legend}
32
+ {tooltip}
33
+ >
34
+ <Arc theta={y} fill={label ?? fill} {pattern} {labelFn} {stat} options={{ innerRadius }} />
25
35
  </Plot>
@@ -1,25 +1,26 @@
1
1
  <script>
2
- import Plot from '../Plot.svelte'
3
- import Point from '../geoms/Point.svelte'
2
+ import Plot from '../Plot.svelte'
3
+ import Point from '../geoms/Point.svelte'
4
4
 
5
- /** @type {import('../lib/plot/chartProps.js').ScatterBubbleChartProps} */
6
- let {
7
- data = [],
8
- x = undefined,
9
- y = undefined,
10
- color = undefined,
11
- symbol = undefined,
12
- size = undefined,
13
- label = false,
14
- tooltip = false,
15
- width = 600,
16
- height = 400,
17
- mode = 'light',
18
- grid = true,
19
- legend = false
20
- } = $props()
5
+ /** @type {import('../lib/plot/chartProps.js').ScatterBubbleChartProps} */
6
+ let {
7
+ data = [],
8
+ x = undefined,
9
+ y = undefined,
10
+ color = undefined,
11
+ symbol = undefined,
12
+ size = undefined,
13
+ label = false,
14
+ tooltip = false,
15
+ width = 600,
16
+ height = 400,
17
+ mode = 'light',
18
+ grid = true,
19
+ legend = false,
20
+ jitter = undefined
21
+ } = $props()
21
22
  </script>
22
23
 
23
24
  <Plot {data} {width} {height} {mode} {grid} {legend} {tooltip}>
24
- <Point {x} {y} {color} {size} {symbol} {label} />
25
+ <Point {x} {y} {color} {size} {symbol} {label} options={{ jitter }} />
25
26
  </Plot>
@@ -1,21 +1,21 @@
1
1
  <script>
2
- import Plot from '../Plot.svelte'
3
- import Violin from '../geoms/Violin.svelte'
2
+ import Plot from '../Plot.svelte'
3
+ import Violin from '../geoms/Violin.svelte'
4
4
 
5
- /** @type {import('../lib/plot/chartProps.js').BoxViolinChartProps} */
6
- let {
7
- data = [],
8
- x = undefined,
9
- y = undefined,
10
- fill = undefined,
11
- width = 600,
12
- height = 400,
13
- mode = 'light',
14
- grid = true,
15
- legend = false
16
- } = $props()
5
+ /** @type {import('../lib/plot/chartProps.js').BoxViolinChartProps} */
6
+ let {
7
+ data = [],
8
+ x = undefined,
9
+ y = undefined,
10
+ fill = undefined,
11
+ width = 600,
12
+ height = 400,
13
+ mode = 'light',
14
+ grid = true,
15
+ legend = false
16
+ } = $props()
17
17
  </script>
18
18
 
19
19
  <Plot {data} {width} {height} {mode} {grid} {legend}>
20
- <Violin {x} {y} {fill} />
20
+ <Violin {x} {y} {fill} />
21
21
  </Plot>
@@ -1,38 +1,42 @@
1
1
  <script>
2
- import { setContext, untrack } from 'svelte'
3
- import { createCrossFilter } from './createCrossFilter.svelte.js'
2
+ import { setContext, untrack } from 'svelte'
3
+ import { createCrossFilter } from './createCrossFilter.svelte.js'
4
4
 
5
- /**
6
- * @type {{
7
- * crossfilter?: ReturnType<typeof createCrossFilter>,
8
- * mode?: 'dim' | 'hide',
9
- * filters?: import('./createCrossFilter.svelte.js').FilterState,
10
- * children?: import('svelte').Snippet
11
- * }}
12
- */
13
- let {
14
- crossfilter: externalCf = undefined,
15
- mode = 'dim',
16
- filters = $bindable(),
17
- children
18
- } = $props()
5
+ /**
6
+ * @type {{
7
+ * crossfilter?: ReturnType<typeof createCrossFilter>,
8
+ * mode?: 'dim' | 'hide',
9
+ * filters?: import('./createCrossFilter.svelte.js').FilterState,
10
+ * children?: import('svelte').Snippet
11
+ * }}
12
+ */
13
+ let {
14
+ crossfilter: externalCf = undefined,
15
+ mode = 'dim',
16
+ filters = $bindable(),
17
+ children
18
+ } = $props()
19
19
 
20
- // Use an externally provided instance (spec/helpers API) or create one internally.
21
- // untrack() suppresses "captures initial value" warning — intentional: the cf
22
- // instance is locked in at construction time and must not recreate on prop changes.
23
- const cf = untrack(() => externalCf ?? createCrossFilter())
20
+ // Use an externally provided instance (spec/helpers API) or create one internally.
21
+ // untrack() suppresses "captures initial value" warning — intentional: the cf
22
+ // instance is locked in at construction time and must not recreate on prop changes.
23
+ const cf = untrack(() => externalCf ?? createCrossFilter())
24
24
 
25
- // Expose the reactive filters Map to callers via bind:filters
26
- $effect(() => {
27
- filters = cf.filters
28
- })
25
+ // Expose the reactive filters Map to callers via bind:filters
26
+ $effect(() => {
27
+ filters = cf.filters
28
+ })
29
29
 
30
- setContext('crossfilter', cf)
31
- // Use a getter object so children can read .mode reactively
32
- const modeRef = { get mode() { return mode } }
33
- setContext('crossfilter-mode', modeRef)
30
+ setContext('crossfilter', cf)
31
+ // Use a getter object so children can read .mode reactively
32
+ const modeRef = {
33
+ get mode() {
34
+ return mode
35
+ }
36
+ }
37
+ setContext('crossfilter-mode', modeRef)
34
38
  </script>
35
39
 
36
40
  <div data-crossfilter data-crossfilter-mode={mode}>
37
- {@render children?.()}
41
+ {@render children?.()}
38
42
  </div>
@@ -1,32 +1,24 @@
1
1
  <script>
2
- import PlotChart from '../Plot.svelte'
3
- import Bar from '../geoms/Bar.svelte'
2
+ import PlotChart from '../Plot.svelte'
3
+ import Bar from '../geoms/Bar.svelte'
4
4
 
5
- let {
6
- data = [],
7
- field,
8
- valueField,
9
- stat = 'sum',
10
- width = 300,
11
- height = 120,
12
- mode = 'light'
13
- } = $props()
5
+ let {
6
+ data = [],
7
+ field,
8
+ valueField,
9
+ stat = 'sum',
10
+ width = 300,
11
+ height = 120,
12
+ mode = 'light'
13
+ } = $props()
14
14
 
15
- const spec = $derived({
16
- x: field,
17
- y: valueField
18
- })
15
+ const spec = $derived({
16
+ x: field,
17
+ y: valueField
18
+ })
19
19
  </script>
20
20
 
21
21
  <!-- FilterBar must be used inside a <CrossFilter> parent. Does not create its own context. -->
22
- <PlotChart
23
- {data}
24
- {spec}
25
- {width}
26
- {height}
27
- {mode}
28
- grid={false}
29
- legend={false}
30
- >
31
- <Bar x={field} y={valueField} {stat} filterable={true} />
22
+ <PlotChart {data} {spec} {width} {height} {mode} grid={false} legend={false}>
23
+ <Bar x={field} y={valueField} {stat} filterable={true} />
32
24
  </PlotChart>