@rokkit/chart 1.3.7 → 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 (162) hide show
  1. package/dist/AnimatedPlot.svelte +26 -8
  2. package/dist/AnimatedPlot.svelte.d.ts +5 -0
  3. package/dist/Chart.svelte +51 -65
  4. package/dist/FacetPlot.svelte +1 -1
  5. package/dist/Plot/Axis.svelte +19 -10
  6. package/dist/Plot/Root.svelte +67 -46
  7. package/dist/Plot/Root.svelte.d.ts +29 -2
  8. package/dist/Plot/Timeline.svelte +39 -13
  9. package/dist/Plot/index.d.ts +5 -5
  10. package/dist/Plot/index.js +5 -5
  11. package/dist/Plot.svelte +95 -178
  12. package/dist/Plot.svelte.d.ts +4 -0
  13. package/dist/PlotState.svelte.d.ts +29 -1
  14. package/dist/PlotState.svelte.js +163 -19
  15. package/dist/PlotSurface.svelte +162 -0
  16. package/dist/PlotSurface.svelte.d.ts +25 -0
  17. package/dist/charts/AreaChart.svelte +12 -2
  18. package/dist/charts/AreaChart.svelte.d.ts +6 -0
  19. package/dist/charts/BarChart.svelte +40 -4
  20. package/dist/charts/BarChart.svelte.d.ts +15 -1
  21. package/dist/charts/BoxPlot.svelte +7 -3
  22. package/dist/charts/BoxPlot.svelte.d.ts +2 -0
  23. package/dist/charts/BubbleChart.svelte +37 -4
  24. package/dist/charts/BubbleChart.svelte.d.ts +12 -1
  25. package/dist/charts/LineChart.svelte +4 -2
  26. package/dist/charts/LineChart.svelte.d.ts +1 -0
  27. package/dist/charts/PieChart.svelte +5 -3
  28. package/dist/charts/PieChart.svelte.d.ts +1 -0
  29. package/dist/charts/ScatterPlot.svelte +35 -4
  30. package/dist/charts/ScatterPlot.svelte.d.ts +11 -1
  31. package/dist/charts/ViolinPlot.svelte +7 -3
  32. package/dist/charts/ViolinPlot.svelte.d.ts +2 -0
  33. package/dist/examples/BarChartExample.svelte +1 -1
  34. package/dist/geoms/Arc.svelte +21 -54
  35. package/dist/geoms/Arc.svelte.d.ts +4 -4
  36. package/dist/geoms/Area.svelte +45 -44
  37. package/dist/geoms/Area.svelte.d.ts +8 -1
  38. package/dist/geoms/Bar.svelte +33 -45
  39. package/dist/geoms/Bar.svelte.d.ts +9 -0
  40. package/dist/geoms/Box.svelte +103 -61
  41. package/dist/geoms/Box.svelte.d.ts +12 -3
  42. package/dist/geoms/Candlestick.svelte +26 -75
  43. package/dist/geoms/Candlestick.svelte.d.ts +2 -0
  44. package/dist/geoms/Heatmap.svelte +21 -66
  45. package/dist/geoms/Heatmap.svelte.d.ts +2 -0
  46. package/dist/geoms/Hexbin.svelte +20 -100
  47. package/dist/geoms/Hexbin.svelte.d.ts +2 -0
  48. package/dist/geoms/Jitter.svelte +67 -0
  49. package/dist/geoms/Jitter.svelte.d.ts +17 -0
  50. package/dist/geoms/Line.svelte +27 -31
  51. package/dist/geoms/Line.svelte.d.ts +5 -0
  52. package/dist/geoms/Point.svelte +31 -60
  53. package/dist/geoms/Point.svelte.d.ts +5 -1
  54. package/dist/geoms/Ribbon.svelte +30 -124
  55. package/dist/geoms/Ribbon.svelte.d.ts +2 -0
  56. package/dist/geoms/Rule.svelte +117 -0
  57. package/dist/geoms/Rule.svelte.d.ts +19 -0
  58. package/dist/geoms/Violin.svelte +36 -31
  59. package/dist/geoms/Violin.svelte.d.ts +10 -3
  60. package/dist/geoms/Waterfall.svelte +25 -79
  61. package/dist/geoms/Waterfall.svelte.d.ts +2 -0
  62. package/dist/geoms/lib/GeomState.svelte.d.ts +51 -0
  63. package/dist/geoms/lib/GeomState.svelte.js +79 -0
  64. package/dist/geoms/lib/aesthetics.d.ts +36 -0
  65. package/dist/geoms/lib/aesthetics.js +45 -0
  66. package/dist/geoms/lib/areas.d.ts +6 -2
  67. package/dist/geoms/lib/areas.js +20 -12
  68. package/dist/geoms/lib/bars.d.ts +18 -3
  69. package/dist/geoms/lib/bars.js +80 -101
  70. package/dist/geoms/lib/marks/arc.d.ts +24 -0
  71. package/dist/geoms/lib/marks/arc.js +28 -0
  72. package/dist/geoms/lib/marks/area.d.ts +23 -0
  73. package/dist/geoms/lib/marks/area.js +38 -0
  74. package/dist/geoms/lib/marks/bar.d.ts +16 -0
  75. package/dist/geoms/lib/marks/bar.js +43 -0
  76. package/dist/geoms/lib/marks/box.d.ts +14 -0
  77. package/dist/geoms/lib/marks/box.js +30 -0
  78. package/dist/geoms/lib/marks/candlestick.d.ts +27 -0
  79. package/dist/geoms/lib/marks/candlestick.js +52 -0
  80. package/dist/geoms/lib/marks/heatmap.d.ts +24 -0
  81. package/dist/geoms/lib/marks/heatmap.js +41 -0
  82. package/dist/geoms/lib/marks/hexbin.d.ts +29 -0
  83. package/dist/geoms/lib/marks/hexbin.js +62 -0
  84. package/dist/geoms/lib/marks/jitter.d.ts +21 -0
  85. package/dist/geoms/lib/marks/jitter.js +36 -0
  86. package/dist/geoms/lib/marks/line.d.ts +26 -0
  87. package/dist/geoms/lib/marks/line.js +25 -0
  88. package/dist/geoms/lib/marks/point.d.ts +25 -0
  89. package/dist/geoms/lib/marks/point.js +58 -0
  90. package/dist/geoms/lib/marks/ribbon.d.ts +31 -0
  91. package/dist/geoms/lib/marks/ribbon.js +77 -0
  92. package/dist/geoms/lib/marks/violin.d.ts +13 -0
  93. package/dist/geoms/lib/marks/violin.js +31 -0
  94. package/dist/geoms/lib/marks/waterfall.d.ts +25 -0
  95. package/dist/geoms/lib/marks/waterfall.js +58 -0
  96. package/dist/index.d.ts +25 -12
  97. package/dist/index.js +26 -13
  98. package/dist/lib/brewing/marks/arcs.js +7 -1
  99. package/dist/lib/brewing/marks/boxes.d.ts +11 -2
  100. package/dist/lib/brewing/marks/boxes.js +32 -11
  101. package/dist/lib/brewing/marks/lines.d.ts +4 -1
  102. package/dist/lib/brewing/marks/lines.js +18 -15
  103. package/dist/lib/brewing/marks/swarm.d.ts +32 -0
  104. package/dist/lib/brewing/marks/swarm.js +125 -0
  105. package/dist/lib/brewing/marks/violins.d.ts +4 -20
  106. package/dist/lib/brewing/marks/violins.js +41 -25
  107. package/dist/lib/brewing/stats.d.ts +3 -1
  108. package/dist/lib/brewing/stats.js +28 -11
  109. package/dist/lib/plot/scales.js +12 -7
  110. package/dist/lib/plot/types.d.ts +9 -1
  111. package/dist/lib/plot/types.js +3 -1
  112. package/dist/lib/preset.d.ts +11 -1
  113. package/dist/lib/preset.js +16 -4
  114. package/package.json +1 -1
  115. package/dist/Plot/Arc.svelte +0 -30
  116. package/dist/Plot/Arc.svelte.d.ts +0 -18
  117. package/dist/Plot/Area.svelte +0 -54
  118. package/dist/Plot/Area.svelte.d.ts +0 -14
  119. package/dist/Plot/Bar.svelte +0 -69
  120. package/dist/Plot/Bar.svelte.d.ts +0 -11
  121. package/dist/Plot/Line.svelte +0 -54
  122. package/dist/Plot/Line.svelte.d.ts +0 -13
  123. package/dist/Plot/Point.svelte +0 -58
  124. package/dist/Plot/Point.svelte.d.ts +0 -13
  125. package/dist/lib/brewer.d.ts +0 -9
  126. package/dist/lib/brewer.js +0 -25
  127. package/dist/lib/brewing/BoxBrewer.svelte.d.ts +0 -8
  128. package/dist/lib/brewing/BoxBrewer.svelte.js +0 -14
  129. package/dist/lib/brewing/CartesianBrewer.svelte.d.ts +0 -8
  130. package/dist/lib/brewing/CartesianBrewer.svelte.js +0 -21
  131. package/dist/lib/brewing/PieBrewer.svelte.d.ts +0 -8
  132. package/dist/lib/brewing/PieBrewer.svelte.js +0 -14
  133. package/dist/lib/brewing/QuartileBrewer.svelte.d.ts +0 -9
  134. package/dist/lib/brewing/QuartileBrewer.svelte.js +0 -51
  135. package/dist/lib/brewing/ViolinBrewer.svelte.d.ts +0 -8
  136. package/dist/lib/brewing/ViolinBrewer.svelte.js +0 -14
  137. package/dist/lib/brewing/axes.svelte.d.ts +0 -66
  138. package/dist/lib/brewing/axes.svelte.js +0 -270
  139. package/dist/lib/brewing/bars.svelte.d.ts +0 -56
  140. package/dist/lib/brewing/bars.svelte.js +0 -201
  141. package/dist/lib/brewing/brewer.svelte.d.ts +0 -124
  142. package/dist/lib/brewing/brewer.svelte.js +0 -277
  143. package/dist/lib/brewing/dimensions.svelte.d.ts +0 -35
  144. package/dist/lib/brewing/dimensions.svelte.js +0 -56
  145. package/dist/lib/brewing/index.svelte.d.ts +0 -118
  146. package/dist/lib/brewing/index.svelte.js +0 -205
  147. package/dist/lib/brewing/legends.svelte.d.ts +0 -48
  148. package/dist/lib/brewing/legends.svelte.js +0 -137
  149. package/dist/lib/brewing/marks/areas.d.ts +0 -31
  150. package/dist/lib/brewing/marks/areas.js +0 -72
  151. package/dist/lib/brewing/marks/bars.d.ts +0 -1
  152. package/dist/lib/brewing/marks/bars.js +0 -49
  153. package/dist/lib/brewing/scales.svelte.d.ts +0 -24
  154. package/dist/lib/brewing/scales.svelte.js +0 -82
  155. package/dist/lib/context.d.ts +0 -13
  156. package/dist/lib/context.js +0 -131
  157. package/dist/lib/plot/chartProps.d.ts +0 -177
  158. package/dist/lib/plot/chartProps.js +0 -76
  159. package/dist/lib/scales.svelte.d.ts +0 -35
  160. package/dist/lib/scales.svelte.js +0 -151
  161. package/dist/lib/ticks.d.ts +0 -36
  162. package/dist/lib/ticks.js +0 -46
@@ -9,11 +9,13 @@
9
9
  x?: string
10
10
  y?: string
11
11
  fill?: string
12
+ alpha?: number
12
13
  width?: number
13
14
  height?: number
14
15
  mode?: 'light' | 'dark'
15
16
  grid?: boolean
16
17
  legend?: boolean
18
+ tooltip?: boolean | ((data: Row) => string)
17
19
  yFormat?: (v: unknown) => string
18
20
  yTicks?: number
19
21
  minorTicks?: boolean
@@ -24,17 +26,19 @@
24
26
  x = undefined,
25
27
  y = undefined,
26
28
  fill = undefined,
29
+ alpha = undefined,
27
30
  width = 600,
28
31
  height = 400,
29
- mode = 'light',
32
+ mode = undefined,
30
33
  grid = true,
31
34
  legend = false,
35
+ tooltip = false,
32
36
  yFormat = undefined,
33
37
  yTicks = undefined,
34
38
  minorTicks = false
35
39
  }: Props = $props()
36
40
  </script>
37
41
 
38
- <Plot {data} {width} {height} {mode} {grid} {legend} {yFormat} {yTicks} {minorTicks}>
39
- <Box {x} {y} {fill} />
42
+ <Plot {data} {width} {height} {mode} {grid} {legend} {tooltip} {yFormat} {yTicks} {minorTicks}>
43
+ <Box {x} {y} {fill} {alpha} />
40
44
  </Plot>
@@ -4,11 +4,13 @@ type Props = {
4
4
  x?: string;
5
5
  y?: string;
6
6
  fill?: string;
7
+ alpha?: number;
7
8
  width?: number;
8
9
  height?: number;
9
10
  mode?: 'light' | 'dark';
10
11
  grid?: boolean;
11
12
  legend?: boolean;
13
+ tooltip?: boolean | ((data: Row) => string);
12
14
  yFormat?: (v: unknown) => string;
13
15
  yTicks?: number;
14
16
  minorTicks?: boolean;
@@ -4,6 +4,7 @@
4
4
 
5
5
  type Row = Record<string, unknown>
6
6
  type Format = (v: unknown) => string
7
+ type Method = string | number | { type: string; [k: string]: unknown }
7
8
 
8
9
  type Props = {
9
10
  data?: Row[]
@@ -12,16 +13,23 @@
12
13
  color?: string
13
14
  symbol?: string
14
15
  size?: string
16
+ alpha?: number
15
17
  width?: number
16
18
  height?: number
17
19
  mode?: 'light' | 'dark'
18
20
  grid?: boolean
19
21
  legend?: boolean
22
+ tooltip?: boolean | ((data: Row) => string)
23
+ highlight?: 'first' | 'last' | 'min' | 'max' | number | ((row: Row, i: number) => boolean)
24
+ trend?: Method | Method[]
20
25
  xFormat?: Format
21
26
  yFormat?: Format
22
27
  xTicks?: number
23
28
  yTicks?: number
24
29
  minorTicks?: boolean
30
+ onselect?: (detail: unknown) => void
31
+ selectable?: boolean
32
+ selected?: Row[]
25
33
  }
26
34
 
27
35
  let {
@@ -31,19 +39,44 @@
31
39
  color = undefined,
32
40
  symbol: _symbol = undefined,
33
41
  size, // required: field name for bubble radius
42
+ alpha = undefined,
34
43
  width = 600,
35
44
  height = 400,
36
- mode = 'light',
45
+ mode = undefined,
37
46
  grid = true,
38
47
  legend = false,
48
+ tooltip = false,
49
+ highlight = undefined,
50
+ trend = undefined,
39
51
  xFormat = undefined,
40
52
  yFormat = undefined,
41
53
  xTicks = undefined,
42
54
  yTicks = undefined,
43
- minorTicks = false
55
+ minorTicks = false,
56
+ onselect = undefined,
57
+ selectable = false,
58
+ selected = $bindable([])
44
59
  }: Props = $props()
45
60
  </script>
46
61
 
47
- <Plot {data} {width} {height} {mode} {grid} {legend} {xFormat} {yFormat} {xTicks} {yTicks} {minorTicks}>
48
- <Point {x} {y} {color} {size} />
62
+ <Plot
63
+ {data}
64
+ {width}
65
+ {height}
66
+ {mode}
67
+ {grid}
68
+ {legend}
69
+ {tooltip}
70
+ {highlight}
71
+ {trend}
72
+ {xFormat}
73
+ {yFormat}
74
+ {xTicks}
75
+ {yTicks}
76
+ {minorTicks}
77
+ {onselect}
78
+ {selectable}
79
+ bind:selected
80
+ >
81
+ <Point {x} {y} {color} {size} {alpha} />
49
82
  </Plot>
@@ -1,5 +1,9 @@
1
1
  type Row = Record<string, unknown>;
2
2
  type Format = (v: unknown) => string;
3
+ type Method = string | number | {
4
+ type: string;
5
+ [k: string]: unknown;
6
+ };
3
7
  type Props = {
4
8
  data?: Row[];
5
9
  x?: string;
@@ -7,17 +11,24 @@ type Props = {
7
11
  color?: string;
8
12
  symbol?: string;
9
13
  size?: string;
14
+ alpha?: number;
10
15
  width?: number;
11
16
  height?: number;
12
17
  mode?: 'light' | 'dark';
13
18
  grid?: boolean;
14
19
  legend?: boolean;
20
+ tooltip?: boolean | ((data: Row) => string);
21
+ highlight?: 'first' | 'last' | 'min' | 'max' | number | ((row: Row, i: number) => boolean);
22
+ trend?: Method | Method[];
15
23
  xFormat?: Format;
16
24
  yFormat?: Format;
17
25
  xTicks?: number;
18
26
  yTicks?: number;
19
27
  minorTicks?: boolean;
28
+ onselect?: (detail: unknown) => void;
29
+ selectable?: boolean;
30
+ selected?: Row[];
20
31
  };
21
- declare const BubbleChart: import("svelte").Component<Props, {}, "">;
32
+ declare const BubbleChart: import("svelte").Component<Props, {}, "selected">;
22
33
  type BubbleChart = ReturnType<typeof BubbleChart>;
23
34
  export default BubbleChart;
@@ -12,6 +12,7 @@
12
12
  y?: string
13
13
  color?: string
14
14
  stat?: string
15
+ alpha?: number
15
16
  symbol?: string
16
17
  curve?: 'linear' | 'smooth' | 'step'
17
18
  label?: boolean | string | ((data: Row) => unknown)
@@ -39,13 +40,14 @@
39
40
  y = undefined,
40
41
  color = undefined,
41
42
  stat = 'identity',
43
+ alpha = undefined,
42
44
  symbol = undefined,
43
45
  curve = undefined, // forwarded to Line options
44
46
  label = false,
45
47
  tooltip = false,
46
48
  width = 600,
47
49
  height = 400,
48
- mode = 'light',
50
+ mode = undefined,
49
51
  grid = true,
50
52
  legend = false,
51
53
  highlight = undefined,
@@ -82,5 +84,5 @@
82
84
  {selectable}
83
85
  bind:selected
84
86
  >
85
- <Line {x} {y} {color} {symbol} {label} {stat} options={{ curve }} />
87
+ <Line {x} {y} {color} {symbol} {label} {stat} {alpha} options={{ curve }} />
86
88
  </Plot>
@@ -10,6 +10,7 @@ type Props = {
10
10
  y?: string;
11
11
  color?: string;
12
12
  stat?: string;
13
+ alpha?: number;
13
14
  symbol?: string;
14
15
  curve?: 'linear' | 'smooth' | 'step';
15
16
  label?: boolean | string | ((data: Row) => unknown);
@@ -18,6 +18,7 @@
18
18
  mode?: 'light' | 'dark'
19
19
  legend?: boolean
20
20
  stat?: string
21
+ alpha?: number
21
22
  }
22
23
 
23
24
  let {
@@ -31,9 +32,10 @@
31
32
  tooltip = false,
32
33
  width = 400,
33
34
  height = 400,
34
- mode = 'light',
35
+ mode = undefined,
35
36
  legend = false,
36
- stat = 'sum'
37
+ stat = 'sum',
38
+ alpha = undefined
37
39
  }: Props = $props()
38
40
  </script>
39
41
 
@@ -48,5 +50,5 @@
48
50
  {legend}
49
51
  {tooltip}
50
52
  >
51
- <Arc theta={y} fill={label ?? fill} {pattern} {labelFn} {stat} options={{ innerRadius }} />
53
+ <Arc theta={y} fill={label ?? fill} {pattern} {labelFn} {stat} {alpha} options={{ innerRadius }} />
52
54
  </Plot>
@@ -13,6 +13,7 @@ type Props = {
13
13
  mode?: 'light' | 'dark';
14
14
  legend?: boolean;
15
15
  stat?: string;
16
+ alpha?: number;
16
17
  };
17
18
  declare const PieChart: import("svelte").Component<Props, {}, "">;
18
19
  type PieChart = ReturnType<typeof PieChart>;
@@ -4,6 +4,7 @@
4
4
 
5
5
  type Row = Record<string, unknown>
6
6
  type Format = (v: unknown) => string
7
+ type Method = string | number | { type: string; [k: string]: unknown }
7
8
 
8
9
  type Props = {
9
10
  data?: Row[]
@@ -12,6 +13,7 @@
12
13
  color?: string
13
14
  symbol?: string
14
15
  size?: string
16
+ alpha?: number
15
17
  label?: boolean | string | ((data: Row) => unknown)
16
18
  tooltip?: boolean | ((data: Row) => string)
17
19
  width?: number
@@ -20,11 +22,16 @@
20
22
  grid?: boolean
21
23
  legend?: boolean
22
24
  jitter?: { width?: number; height?: number } | null
25
+ highlight?: 'first' | 'last' | 'min' | 'max' | number | ((row: Row, i: number) => boolean)
26
+ trend?: Method | Method[]
23
27
  xFormat?: Format
24
28
  yFormat?: Format
25
29
  xTicks?: number
26
30
  yTicks?: number
27
31
  minorTicks?: boolean
32
+ onselect?: (detail: unknown) => void
33
+ selectable?: boolean
34
+ selected?: Row[]
28
35
  }
29
36
 
30
37
  let {
@@ -34,22 +41,46 @@
34
41
  color = undefined,
35
42
  symbol = undefined,
36
43
  size = undefined,
44
+ alpha = undefined,
37
45
  label = false,
38
46
  tooltip = false,
39
47
  width = 600,
40
48
  height = 400,
41
- mode = 'light',
49
+ mode = undefined,
42
50
  grid = true,
43
51
  legend = false,
44
52
  jitter = undefined,
53
+ highlight = undefined,
54
+ trend = undefined,
45
55
  xFormat = undefined,
46
56
  yFormat = undefined,
47
57
  xTicks = undefined,
48
58
  yTicks = undefined,
49
- minorTicks = false
59
+ minorTicks = false,
60
+ onselect = undefined,
61
+ selectable = false,
62
+ selected = $bindable([])
50
63
  }: Props = $props()
51
64
  </script>
52
65
 
53
- <Plot {data} {width} {height} {mode} {grid} {legend} {tooltip} {xFormat} {yFormat} {xTicks} {yTicks} {minorTicks}>
54
- <Point {x} {y} {color} {size} {symbol} {label} options={{ jitter }} />
66
+ <Plot
67
+ {data}
68
+ {width}
69
+ {height}
70
+ {mode}
71
+ {grid}
72
+ {legend}
73
+ {tooltip}
74
+ {highlight}
75
+ {trend}
76
+ {xFormat}
77
+ {yFormat}
78
+ {xTicks}
79
+ {yTicks}
80
+ {minorTicks}
81
+ {onselect}
82
+ {selectable}
83
+ bind:selected
84
+ >
85
+ <Point {x} {y} {color} {size} {symbol} {label} {alpha} options={{ jitter }} />
55
86
  </Plot>
@@ -1,5 +1,9 @@
1
1
  type Row = Record<string, unknown>;
2
2
  type Format = (v: unknown) => string;
3
+ type Method = string | number | {
4
+ type: string;
5
+ [k: string]: unknown;
6
+ };
3
7
  type Props = {
4
8
  data?: Row[];
5
9
  x?: string;
@@ -7,6 +11,7 @@ type Props = {
7
11
  color?: string;
8
12
  symbol?: string;
9
13
  size?: string;
14
+ alpha?: number;
10
15
  label?: boolean | string | ((data: Row) => unknown);
11
16
  tooltip?: boolean | ((data: Row) => string);
12
17
  width?: number;
@@ -18,12 +23,17 @@ type Props = {
18
23
  width?: number;
19
24
  height?: number;
20
25
  } | null;
26
+ highlight?: 'first' | 'last' | 'min' | 'max' | number | ((row: Row, i: number) => boolean);
27
+ trend?: Method | Method[];
21
28
  xFormat?: Format;
22
29
  yFormat?: Format;
23
30
  xTicks?: number;
24
31
  yTicks?: number;
25
32
  minorTicks?: boolean;
33
+ onselect?: (detail: unknown) => void;
34
+ selectable?: boolean;
35
+ selected?: Row[];
26
36
  };
27
- declare const ScatterPlot: import("svelte").Component<Props, {}, "">;
37
+ declare const ScatterPlot: import("svelte").Component<Props, {}, "selected">;
28
38
  type ScatterPlot = ReturnType<typeof ScatterPlot>;
29
39
  export default ScatterPlot;
@@ -9,11 +9,13 @@
9
9
  x?: string
10
10
  y?: string
11
11
  fill?: string
12
+ alpha?: number
12
13
  width?: number
13
14
  height?: number
14
15
  mode?: 'light' | 'dark'
15
16
  grid?: boolean
16
17
  legend?: boolean
18
+ tooltip?: boolean | ((data: Row) => string)
17
19
  yFormat?: (v: unknown) => string
18
20
  yTicks?: number
19
21
  minorTicks?: boolean
@@ -24,17 +26,19 @@
24
26
  x = undefined,
25
27
  y = undefined,
26
28
  fill = undefined,
29
+ alpha = undefined,
27
30
  width = 600,
28
31
  height = 400,
29
- mode = 'light',
32
+ mode = undefined,
30
33
  grid = true,
31
34
  legend = false,
35
+ tooltip = false,
32
36
  yFormat = undefined,
33
37
  yTicks = undefined,
34
38
  minorTicks = false
35
39
  }: Props = $props()
36
40
  </script>
37
41
 
38
- <Plot {data} {width} {height} {mode} {grid} {legend} {yFormat} {yTicks} {minorTicks}>
39
- <Violin {x} {y} {fill} />
42
+ <Plot {data} {width} {height} {mode} {grid} {legend} {tooltip} {yFormat} {yTicks} {minorTicks}>
43
+ <Violin {x} {y} {fill} {alpha} />
40
44
  </Plot>
@@ -4,11 +4,13 @@ type Props = {
4
4
  x?: string;
5
5
  y?: string;
6
6
  fill?: string;
7
+ alpha?: number;
7
8
  width?: number;
8
9
  height?: number;
9
10
  mode?: 'light' | 'dark';
10
11
  grid?: boolean;
11
12
  legend?: boolean;
13
+ tooltip?: boolean | ((data: Row) => string);
12
14
  yFormat?: (v: unknown) => string;
13
15
  yTicks?: number;
14
16
  minorTicks?: boolean;
@@ -36,7 +36,7 @@
36
36
  <Plot.Grid />
37
37
  <Plot.Axis type="x" label="Product Category" />
38
38
  <Plot.Axis type="y" label="Number of Products" />
39
- <Plot.Bar {data} x="category" y="count" fill="category" />
39
+ <Plot.Bar x="category" y="count" fill="category" />
40
40
  <Plot.Legend labels={{ category: 'Categories' }} />
41
41
  </Plot.Root>
42
42
  </div>
@@ -1,19 +1,20 @@
1
1
  <script lang="ts">
2
2
  import { getContext, onMount, onDestroy } from 'svelte'
3
3
  import type { PlotState } from '../PlotState.svelte.js'
4
- import { buildArcs } from '../lib/brewing/marks/arcs.js'
4
+ import { GeomState } from './lib/GeomState.svelte.js'
5
+ import { buildArcMarks } from './lib/marks/arc.js'
5
6
 
6
7
  type Row = Record<string, unknown>
7
8
 
8
- /**
9
- * `fill` is the primary prop name; `color` is accepted as an alias for
10
- * spec-driven usage (Plot.svelte passes `color` to all geoms generically).
11
- */
12
9
  type Props = {
13
10
  theta?: string
11
+ /** Slice interior aesthetic (field). */
14
12
  fill?: string
13
+ /** Accepted as an alias for `fill`. */
15
14
  color?: string
16
15
  pattern?: string
16
+ /** Fixed slice opacity 0–1; defaults to the per-geom preset (arc = 1). */
17
+ alpha?: number
17
18
  stat?: string
18
19
  labelFn?: (data: Row) => string
19
20
  options?: { innerRadius?: number }
@@ -25,57 +26,30 @@
25
26
  fill,
26
27
  color,
27
28
  pattern,
29
+ alpha,
28
30
  labelFn = undefined,
29
31
  stat = 'identity',
30
32
  options = {},
31
33
  onselect = undefined
32
34
  }: Props = $props()
33
35
 
34
- const fillField = $derived(fill ?? color)
35
-
36
36
  const plotState = getContext<PlotState>('plot-state')
37
- let id = $state<string | null>(null)
38
-
39
- onMount(() => {
40
- id = plotState.registerGeom({
41
- type: 'arc',
42
- channels: { color: fillField, y: theta, pattern },
43
- stat,
44
- options
45
- })
46
- })
47
- onDestroy(() => {
48
- if (id) plotState.unregisterGeom(id)
49
- })
50
37
 
51
- $effect(() => {
52
- if (id) plotState.updateGeom(id, { channels: { color: fillField, y: theta, pattern }, stat })
53
- })
38
+ const geom = new GeomState(plotState, () => ({
39
+ type: 'arc',
40
+ channels: { y: theta, color, fill, pattern },
41
+ stat,
42
+ options: { innerRadius: options.innerRadius ?? 0 },
43
+ alpha,
44
+ build: buildArcMarks
45
+ }))
46
+ onMount(geom.register)
47
+ onDestroy(geom.destroy)
48
+ $effect(geom.sync)
54
49
 
55
- const data = $derived(id ? plotState.geomData(id) : [])
56
- const colors = $derived(plotState.colors)
57
- const patterns = $derived(plotState.patterns)
50
+ const arcs = $derived(geom.marks)
58
51
  const w = $derived(plotState.innerWidth)
59
52
  const h = $derived(plotState.innerHeight)
60
-
61
- const arcs = $derived.by(() => {
62
- if (!data?.length) return []
63
- // Guard: skip until data catches up after a fill-field change.
64
- // When fillField changes, the $effect updates the geom asynchronously, but
65
- // this derived runs first with stale data whose rows don't have the new
66
- // field — causing all keys to be undefined (duplicate key error).
67
- if (fillField && !(fillField in data[0])) return []
68
- const innerRadius = ((options.innerRadius ?? 0) * Math.min(w, h)) / 2
69
- return buildArcs(
70
- data,
71
- { color: fillField, y: theta, pattern },
72
- colors,
73
- w,
74
- h,
75
- { innerRadius },
76
- patterns
77
- )
78
- })
79
53
  </script>
80
54
 
81
55
  {#if arcs.length > 0}
@@ -85,6 +59,7 @@
85
59
  <path
86
60
  d={arc.d}
87
61
  fill={arc.fill}
62
+ fill-opacity={arc.alpha}
88
63
  stroke={arc.stroke}
89
64
  stroke-width="1"
90
65
  role={onselect ? 'button' : 'presentation'}
@@ -115,15 +90,7 @@
115
90
  pointer-events="none"
116
91
  data-plot-element="arc-label"
117
92
  >
118
- <rect
119
- x={-lw / 2}
120
- y="-9"
121
- width={lw}
122
- height="18"
123
- rx="4"
124
- fill="white"
125
- fill-opacity="0.82"
126
- />
93
+ <rect x={-lw / 2} y="-9" width={lw} height="18" rx="4" fill="white" fill-opacity="0.82" />
127
94
  <text
128
95
  text-anchor="middle"
129
96
  dominant-baseline="central"
@@ -1,13 +1,13 @@
1
1
  type Row = Record<string, unknown>;
2
- /**
3
- * `fill` is the primary prop name; `color` is accepted as an alias for
4
- * spec-driven usage (Plot.svelte passes `color` to all geoms generically).
5
- */
6
2
  type Props = {
7
3
  theta?: string;
4
+ /** Slice interior aesthetic (field). */
8
5
  fill?: string;
6
+ /** Accepted as an alias for `fill`. */
9
7
  color?: string;
10
8
  pattern?: string;
9
+ /** Fixed slice opacity 0–1; defaults to the per-geom preset (arc = 1). */
10
+ alpha?: number;
11
11
  stat?: string;
12
12
  labelFn?: (data: Row) => string;
13
13
  options?: {