@rokkit/chart 1.1.17 → 1.1.19

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 (156) hide show
  1. package/dist/AnimatedPlot.svelte.d.ts +35 -0
  2. package/dist/Chart.svelte.d.ts +21 -0
  3. package/dist/ChartExporter.svelte.d.ts +22 -0
  4. package/dist/ChartLegend.svelte.d.ts +30 -0
  5. package/dist/ChartProvider.svelte.d.ts +10 -0
  6. package/dist/FacetPlot/Panel.svelte.d.ts +22 -0
  7. package/dist/FacetPlot.svelte.d.ts +32 -0
  8. package/dist/Plot/Arc.svelte.d.ts +18 -0
  9. package/dist/Plot/Area.svelte.d.ts +14 -0
  10. package/dist/Plot/Axis.svelte.d.ts +13 -0
  11. package/dist/Plot/Bar.svelte.d.ts +11 -0
  12. package/dist/Plot/Grid.svelte.d.ts +3 -0
  13. package/dist/Plot/Legend.svelte.d.ts +6 -0
  14. package/dist/Plot/Line.svelte.d.ts +13 -0
  15. package/dist/Plot/Point.svelte.d.ts +13 -0
  16. package/dist/Plot/Root.svelte.d.ts +21 -0
  17. package/dist/Plot/Timeline.svelte.d.ts +13 -0
  18. package/dist/Plot/Tooltip.svelte.d.ts +7 -0
  19. package/dist/Plot.svelte.d.ts +34 -0
  20. package/dist/PlotState.svelte.d.ts +0 -3
  21. package/dist/Sparkline.svelte.d.ts +16 -0
  22. package/dist/Symbol.svelte.d.ts +12 -0
  23. package/dist/Texture.svelte.d.ts +12 -0
  24. package/dist/charts/AreaChart.svelte.d.ts +25 -0
  25. package/dist/charts/BarChart.svelte.d.ts +26 -0
  26. package/dist/charts/BoxPlot.svelte.d.ts +18 -0
  27. package/dist/charts/BubbleChart.svelte.d.ts +23 -0
  28. package/dist/charts/LineChart.svelte.d.ts +26 -0
  29. package/dist/charts/PieChart.svelte.d.ts +19 -0
  30. package/dist/charts/ScatterPlot.svelte.d.ts +29 -0
  31. package/dist/charts/ViolinPlot.svelte.d.ts +18 -0
  32. package/dist/crossfilter/CrossFilter.svelte.d.ts +12 -0
  33. package/dist/crossfilter/FilterBar.svelte.d.ts +12 -0
  34. package/dist/crossfilter/FilterHistogram.svelte.d.ts +19 -0
  35. package/dist/crossfilter/FilterSlider.svelte.d.ts +15 -0
  36. package/dist/elements/Bar.svelte.d.ts +17 -0
  37. package/dist/elements/ColorRamp.svelte.d.ts +17 -0
  38. package/dist/elements/ContinuousLegend.svelte.d.ts +18 -0
  39. package/dist/elements/DefinePatterns.svelte.d.ts +21 -0
  40. package/dist/elements/DiscreteLegend.svelte.d.ts +17 -0
  41. package/dist/elements/Label.svelte.d.ts +11 -0
  42. package/dist/elements/SymbolGrid.svelte.d.ts +8 -0
  43. package/dist/examples/BarChartExample.svelte.d.ts +18 -0
  44. package/dist/geoms/Arc.svelte.d.ts +20 -0
  45. package/dist/geoms/Area.svelte.d.ts +16 -0
  46. package/dist/geoms/Bar.svelte.d.ts +23 -0
  47. package/dist/geoms/Box.svelte.d.ts +12 -0
  48. package/dist/geoms/Candlestick.svelte.d.ts +20 -0
  49. package/dist/geoms/Heatmap.svelte.d.ts +13 -0
  50. package/dist/geoms/Hexbin.svelte.d.ts +13 -0
  51. package/dist/geoms/LabelPill.svelte.d.ts +9 -0
  52. package/dist/geoms/Line.svelte.d.ts +24 -0
  53. package/dist/geoms/Point.svelte.d.ts +30 -0
  54. package/dist/geoms/Ribbon.svelte.d.ts +16 -0
  55. package/dist/geoms/Violin.svelte.d.ts +12 -0
  56. package/dist/geoms/Waterfall.svelte.d.ts +18 -0
  57. package/dist/geoms/lib/areas.d.ts +5 -3
  58. package/dist/lib/brewing/brewer.svelte.d.ts +24 -15
  59. package/dist/lib/brewing/marks/arcs.d.ts +16 -6
  60. package/dist/lib/brewing/marks/areas.d.ts +2 -2
  61. package/dist/lib/brewing/marks/boxes.d.ts +3 -3
  62. package/dist/lib/brewing/marks/lines.d.ts +6 -6
  63. package/dist/lib/brewing/marks/points.d.ts +13 -12
  64. package/dist/lib/brewing/marks/violins.d.ts +3 -3
  65. package/dist/lib/brewing/scales.d.ts +3 -3
  66. package/dist/lib/chart.d.ts +2 -2
  67. package/dist/lib/keyboard-nav.d.ts +1 -1
  68. package/dist/lib/plot/facet.d.ts +2 -2
  69. package/dist/lib/plot/frames.d.ts +9 -9
  70. package/dist/lib/plot/scales.d.ts +3 -3
  71. package/dist/lib/plot/types.d.ts +7 -4
  72. package/dist/lib/scales.svelte.d.ts +2 -2
  73. package/dist/lib/utils.d.ts +7 -1
  74. package/dist/lib/xscale.d.ts +1 -1
  75. package/dist/patterns/DefinePatterns.svelte.d.ts +7 -0
  76. package/dist/patterns/PatternDef.svelte.d.ts +11 -0
  77. package/dist/spec/chart-spec.d.ts +22 -0
  78. package/dist/symbols/RoundedSquare.svelte.d.ts +11 -0
  79. package/dist/symbols/Shape.svelte.d.ts +18 -0
  80. package/dist/symbols/constants/index.d.ts +1 -1
  81. package/dist/symbols/index.d.ts +2 -2
  82. package/dist/symbols/outline.svelte.d.ts +18 -0
  83. package/dist/symbols/solid.svelte.d.ts +18 -0
  84. package/package.json +22 -3
  85. package/src/AnimatedPlot.svelte +49 -43
  86. package/src/Chart.svelte +34 -22
  87. package/src/ChartExporter.svelte +19 -16
  88. package/src/ChartLegend.svelte +24 -20
  89. package/src/ChartProvider.svelte +10 -2
  90. package/src/FacetPlot/Panel.svelte +23 -3
  91. package/src/FacetPlot.svelte +29 -26
  92. package/src/Plot/Arc.svelte +3 -2
  93. package/src/Plot/Area.svelte +30 -8
  94. package/src/Plot/Axis.svelte +26 -45
  95. package/src/Plot/Bar.svelte +20 -5
  96. package/src/Plot/Grid.svelte +5 -4
  97. package/src/Plot/Legend.svelte +8 -4
  98. package/src/Plot/Line.svelte +24 -7
  99. package/src/Plot/Point.svelte +24 -6
  100. package/src/Plot/Root.svelte +17 -2
  101. package/src/Plot/Timeline.svelte +13 -14
  102. package/src/Plot/Tooltip.svelte +12 -6
  103. package/src/Plot.svelte +58 -40
  104. package/src/PlotState.svelte.js +6 -2
  105. package/src/Sparkline.svelte +22 -8
  106. package/src/Symbol.svelte +15 -5
  107. package/src/Texture.svelte +12 -2
  108. package/src/charts/AreaChart.svelte +26 -3
  109. package/src/charts/BarChart.svelte +27 -3
  110. package/src/charts/BoxPlot.svelte +19 -3
  111. package/src/charts/BubbleChart.svelte +24 -3
  112. package/src/charts/LineChart.svelte +27 -3
  113. package/src/charts/PieChart.svelte +20 -3
  114. package/src/charts/ScatterPlot.svelte +27 -3
  115. package/src/charts/ViolinPlot.svelte +19 -3
  116. package/src/crossfilter/CrossFilter.svelte +13 -10
  117. package/src/crossfilter/FilterBar.svelte +14 -3
  118. package/src/crossfilter/FilterHistogram.svelte +49 -24
  119. package/src/crossfilter/FilterSlider.svelte +16 -5
  120. package/src/elements/Bar.svelte +16 -2
  121. package/src/elements/ColorRamp.svelte +28 -4
  122. package/src/elements/ContinuousLegend.svelte +20 -3
  123. package/src/elements/DefinePatterns.svelte +23 -7
  124. package/src/elements/DiscreteLegend.svelte +18 -2
  125. package/src/elements/Label.svelte +11 -2
  126. package/src/elements/SymbolGrid.svelte +13 -4
  127. package/src/examples/BarChartExample.svelte +12 -15
  128. package/src/geoms/Arc.svelte +18 -5
  129. package/src/geoms/Area.svelte +38 -20
  130. package/src/geoms/Bar.svelte +40 -23
  131. package/src/geoms/Box.svelte +13 -4
  132. package/src/geoms/Candlestick.svelte +27 -7
  133. package/src/geoms/Heatmap.svelte +20 -9
  134. package/src/geoms/Hexbin.svelte +35 -13
  135. package/src/geoms/LabelPill.svelte +9 -3
  136. package/src/geoms/Line.svelte +27 -10
  137. package/src/geoms/Point.svelte +33 -13
  138. package/src/geoms/Ribbon.svelte +26 -8
  139. package/src/geoms/Violin.svelte +13 -4
  140. package/src/geoms/Waterfall.svelte +32 -12
  141. package/src/geoms/lib/areas.js +2 -2
  142. package/src/lib/brewing/marks/arcs.js +3 -2
  143. package/src/lib/brewing/marks/boxes.js +1 -1
  144. package/src/lib/brewing/marks/lines.js +2 -2
  145. package/src/lib/brewing/marks/points.js +3 -2
  146. package/src/lib/brewing/marks/violins.js +1 -1
  147. package/src/lib/plot/facet.js +1 -1
  148. package/src/lib/plot/frames.js +4 -4
  149. package/src/lib/plot/types.js +6 -3
  150. package/src/lib/utils.js +7 -1
  151. package/src/patterns/DefinePatterns.svelte +9 -4
  152. package/src/patterns/PatternDef.svelte +11 -3
  153. package/src/symbols/RoundedSquare.svelte +15 -4
  154. package/src/symbols/Shape.svelte +21 -3
  155. package/src/symbols/outline.svelte +2 -0
  156. package/src/symbols/solid.svelte +2 -0
@@ -1,5 +1,23 @@
1
- <script>
1
+ <script lang="ts">
2
2
  import { getContext, onMount, onDestroy } from 'svelte'
3
+ import type { PlotState } from '../PlotState.svelte.js'
4
+
5
+ type Options = {
6
+ positiveColor?: string
7
+ negativeColor?: string
8
+ totalColor?: string
9
+ totalField?: string
10
+ connectorWidth?: number
11
+ }
12
+
13
+ type Props = {
14
+ x?: string
15
+ y?: string
16
+ color?: string
17
+ fill?: string
18
+ stat?: string
19
+ options?: Options
20
+ }
3
21
 
4
22
  let {
5
23
  x,
@@ -8,7 +26,7 @@
8
26
  fill: fillProp = undefined,
9
27
  stat = 'identity',
10
28
  options = {}
11
- } = $props()
29
+ }: Props = $props()
12
30
 
13
31
  const positiveColor = $derived(options.positiveColor ?? '#22c55e')
14
32
  const negativeColor = $derived(options.negativeColor ?? '#ef4444')
@@ -16,8 +34,8 @@
16
34
  const totalField = $derived(options.totalField ?? undefined)
17
35
  const connectorWidth = $derived(options.connectorWidth ?? 0.5)
18
36
 
19
- const plotState = getContext('plot-state')
20
- let id = $state(null)
37
+ const plotState = getContext<PlotState>('plot-state')
38
+ let id = $state<string | null>(null)
21
39
 
22
40
  onMount(() => {
23
41
  id = plotState.registerGeom({
@@ -49,21 +67,23 @@
49
67
 
50
68
  let cumulative = 0
51
69
  return data.map((d, i) => {
52
- const xVal = d[x]
53
- const yVal = Number(d[y])
70
+ const xVal = d[x ?? '']
71
+ const yVal = Number(d[y ?? ''])
54
72
  const isTotal = totalField ? Boolean(d[totalField]) : false
55
73
  const xPos = xScale(xVal) ?? 0
56
- let barTop, barBottom, fill
74
+ let barTop: number
75
+ let barBottom: number
76
+ let fill: string
57
77
 
58
78
  if (isTotal) {
59
- barTop = yScale(Math.max(0, cumulative))
60
- barBottom = yScale(0)
79
+ barTop = yScale(Math.max(0, cumulative)) ?? 0
80
+ barBottom = yScale(0) ?? 0
61
81
  fill = totalColor
62
82
  } else {
63
83
  const start = cumulative
64
84
  cumulative += yVal
65
- barTop = yScale(Math.max(start, cumulative))
66
- barBottom = yScale(Math.min(start, cumulative))
85
+ barTop = yScale(Math.max(start, cumulative)) ?? 0
86
+ barBottom = yScale(Math.min(start, cumulative)) ?? 0
67
87
  fill = yVal >= 0 ? positiveColor : negativeColor
68
88
  }
69
89
 
@@ -95,7 +115,7 @@
95
115
  onmouseenter={() => plotState.setHovered(bar.data)}
96
116
  onmouseleave={() => plotState.clearHovered()}
97
117
  >
98
- <title>{bar.data[x]}: {bar.data[y]}</title>
118
+ <title>{bar.data[x ?? '']}: {bar.data[y ?? '']}</title>
99
119
  </rect>
100
120
  <!-- Connector line to next bar -->
101
121
  {#if i < bars.length - 1}
@@ -5,7 +5,7 @@ import { toPatternId } from '../../lib/brewing/patterns.js'
5
5
  * Builds area path geometry for multi-series area charts.
6
6
  *
7
7
  * @param {Object[]} data
8
- * @param {{ x: string, y: string, color?: string }} channels
8
+ * @param {{ x: string, y: string, color?: string, pattern?: string }} channels
9
9
  * @param {Function} xScale
10
10
  * @param {Function} yScale
11
11
  * @param {Map<unknown, {fill: string, stroke: string}>} colors
@@ -80,7 +80,7 @@ export function buildAreas(data, channels, xScale, yScale, colors, curve, patter
80
80
  * Builds stacked area paths using d3 stack layout.
81
81
  *
82
82
  * @param {Object[]} data
83
- * @param {{ x: string, y: string, color: string }} channels
83
+ * @param {{ x: string, y: string, color?: string, pattern?: string }} channels
84
84
  * @param {Function} xScale
85
85
  * @param {Function} yScale
86
86
  * @param {Map<unknown, {fill: string, stroke: string}>} colors
@@ -3,13 +3,14 @@ import { toPatternId } from '../../brewing/patterns.js'
3
3
 
4
4
  /**
5
5
  * Builds arc geometry for pie/donut charts.
6
- * @param {Object[]} data
7
- * @param {{ color: string, y: string, pattern?: string }} channels
6
+ * @param {Record<string, unknown>[]} data
7
+ * @param {{ color?: string, y?: string, pattern?: string }} channels
8
8
  * @param {Map} colors
9
9
  * @param {number} width
10
10
  * @param {number} height
11
11
  * @param {{ innerRadius?: number }} opts
12
12
  * @param {Map<unknown, string>} [patterns]
13
+ * @returns {{ d: string | null, fill: string, stroke: string, key: unknown, patternId: string | null, pct: number, centroid: [number, number], data: Record<string, unknown> }[]}
13
14
  */
14
15
  export function buildArcs(data, channels, colors, width, height, opts = {}, patterns) {
15
16
  const { color: lf, y: yf } = channels
@@ -8,7 +8,7 @@
8
8
  * Box body uses the lighter fill shade; whiskers and median use the darker stroke shade.
9
9
  *
10
10
  * @param {Object[]} data - Pre-aggregated rows with quartile fields
11
- * @param {{ x: string, fill?: string }} channels
11
+ * @param {{ x?: string, fill?: string }} channels
12
12
  * `fill` drives the box and whisker color (defaults to x-field).
13
13
  * @param {import('d3-scale').ScaleBand} xScale
14
14
  * @param {import('d3-scale').ScaleLinear} yScale
@@ -2,12 +2,12 @@ import { line, curveCatmullRom, curveStep } from 'd3-shape'
2
2
 
3
3
  /**
4
4
  * @param {Object[]} data
5
- * @param {{ x: string, y: string, color?: string }} channels
5
+ * @param {{ x?: string, y?: string, color?: string }} channels
6
6
  * @param {Function} xScale
7
7
  * @param {Function} yScale
8
8
  * @param {Map} colors
9
9
  * @param {'linear'|'smooth'|'step'} [curve]
10
- * @returns {{ d: string, fill: string, stroke: string, points: {x:number, y:number, data:Object}[], key?: unknown }[]}
10
+ * @returns {{ d: string | null, fill: string, stroke: string, points: {x:number, y:number, data: Record<string, unknown>}[], key?: unknown }[]}
11
11
  */
12
12
  export function buildLines(data, channels, xScale, yScale, colors, curve) {
13
13
  const { x: xf, y: yf, color: cf } = channels
@@ -61,8 +61,8 @@ export function jitterOffset(i, range) {
61
61
 
62
62
  /**
63
63
  * Builds point geometry for scatter/bubble charts.
64
- * @param {Object[]} data
65
- * @param {{ x: string, y: string, color?: string, size?: string, symbol?: string }} channels
64
+ * @param {Record<string, unknown>[]} data
65
+ * @param {{ x?: string, y?: string, color?: string, size?: string, symbol?: string }} channels
66
66
  * @param {Function} xScale
67
67
  * @param {Function} yScale
68
68
  * @param {Map} colors
@@ -70,6 +70,7 @@ export function jitterOffset(i, range) {
70
70
  * @param {Map<unknown, string>|null} symbolMap — maps symbol field value → shape name
71
71
  * @param {number} defaultRadius
72
72
  * @param {{ width?: number, height?: number }|null} jitter
73
+ * @returns {{ data: Record<string, unknown>, cx: number, cy: number, r: number, fill: string, stroke: string, symbolPath: string | null, key: unknown }[]}
73
74
  */
74
75
  export function buildPoints(
75
76
  data,
@@ -13,7 +13,7 @@ const ANCHOR_ORDER = ['iqr_max', 'q3', 'median', 'q1', 'iqr_min']
13
13
  * Violin body uses the lighter fill shade; outline uses the darker stroke shade.
14
14
  *
15
15
  * @param {Object[]} data
16
- * @param {{ x: string, fill?: string }} channels
16
+ * @param {{ x?: string, fill?: string }} channels
17
17
  * `fill` drives violin interior and outline (defaults to x-field).
18
18
  * @param {import('d3-scale').ScaleBand} xScale
19
19
  * @param {import('d3-scale').ScaleLinear} yScale
@@ -6,7 +6,7 @@ import { extent } from 'd3-array'
6
6
  *
7
7
  * @param {Object[]} data
8
8
  * @param {string} field
9
- * @returns {Map<unknown, Object[]>}
9
+ * @returns {Map<unknown, Record<string, unknown>[]>}
10
10
  */
11
11
  export function splitByField(data, field) {
12
12
  const map = new Map()
@@ -7,7 +7,7 @@ import { dataset } from '@rokkit/data'
7
7
  *
8
8
  * @param {Object[]} data
9
9
  * @param {string} timeField
10
- * @returns {Map<unknown, Object[]>}
10
+ * @returns {Map<unknown, Record<string, unknown>[]>}
11
11
  */
12
12
  export function extractFrames(data, timeField) {
13
13
  const map = new Map()
@@ -28,9 +28,9 @@ export function extractFrames(data, timeField) {
28
28
  * with no further per-frame normalization needed.
29
29
  *
30
30
  * @param {Object[]} data - pre-aggregated rows, one per (x, color?, byField)
31
- * @param {{ x?: string, y: string, color?: string }} channels
31
+ * @param {{ x?: string, y?: string, color?: string }} channels
32
32
  * @param {string} byField - the frame field (e.g. 'year')
33
- * @returns {Object[]}
33
+ * @returns {Record<string, unknown>[]}
34
34
  */
35
35
  export function completeFrames(data, channels, byField) {
36
36
  const { x: xf, y: yf, color: cf } = channels
@@ -62,7 +62,7 @@ export function completeFrames(data, channels, byField) {
62
62
  * be negative.
63
63
  *
64
64
  * @param {Object[]} data - full dataset (before frame extraction)
65
- * @param {{ x: string, y: string }} channels
65
+ * @param {{ x?: string, y?: string }} channels
66
66
  * @returns {{ xDomain: unknown[], yDomain: [number, number] }}
67
67
  */
68
68
  export function computeStaticDomains(data, channels) {
@@ -12,12 +12,13 @@
12
12
  * @property {string} [symbol]
13
13
  * @property {string} [pattern]
14
14
  * @property {string} [stat] - Built-in or helpers.stats key
15
+ * @property {boolean | string} [label]
15
16
  * @property {Record<string, unknown>} [options]
16
17
  */
17
18
 
18
19
  /**
19
20
  * @typedef {Object} PlotSpec
20
- * @property {Record<string, unknown>[]} data
21
+ * @property {Record<string, unknown>[]} [data]
21
22
  * @property {string} [x]
22
23
  * @property {string} [y]
23
24
  * @property {string} [color]
@@ -36,13 +37,15 @@
36
37
  * @property {string} [colorScheme]
37
38
  * @property {number} [colorMidpoint]
38
39
  * @property {unknown[]} [colorDomain]
39
- * @property {GeomSpec[]} geoms
40
+ * @property {GeomSpec[]} [geoms]
40
41
  * @property {{ by: string, cols?: number, scales?: 'fixed'|'free'|'free_x'|'free_y' }} [facet]
41
42
  * @property {{ by: string, duration?: number, loop?: boolean }} [animate]
42
43
  * @property {boolean} [grid]
43
44
  * @property {boolean} [legend]
44
45
  * @property {boolean} [tooltip]
45
46
  * @property {string} [title]
47
+ * @property {string} [summary]
48
+ * @property {'horizontal'|'vertical'} [orientation]
46
49
  * @property {string} [preset]
47
50
  * @property {number} [width]
48
51
  * @property {number} [height]
@@ -54,7 +57,7 @@
54
57
  * @property {Record<string, (values: unknown[]) => unknown>} [stats]
55
58
  * @property {Record<string, (v: unknown) => string>} [format]
56
59
  * @property {(d: Record<string, unknown>) => string} [tooltip]
57
- * @property {Record<string, unknown>} [geoms] Svelte components keyed by type name
60
+ * @property {Record<string, import('svelte').Component<any>>} [geoms] Svelte components keyed by type name
58
61
  * @property {unknown} [colorScale] d3 scale override
59
62
  * @property {{ colors: string[], patterns: string[], symbols: string[] }} [preset]
60
63
  * @property {Record<string, { colors: string[], patterns: string[], symbols: string[] }>} [presets]
package/src/lib/utils.js CHANGED
@@ -142,9 +142,15 @@ export function transform(x, y) {
142
142
 
143
143
  import { scaledPath } from '@rokkit/core'
144
144
 
145
+ /**
146
+ * Builds a collection of size-scaling path generators keyed by shape name.
147
+ *
148
+ * @param {Record<string, string|number|(string|number)[]>} paths
149
+ * @returns {Record<string, (size: number) => string|number>}
150
+ */
145
151
  export function scaledPathCollection(paths) {
146
152
  return Object.entries(paths).reduce(
147
153
  (acc, [key, value]) => ({ ...acc, [key]: (s) => scaledPath(s, value) }),
148
- {}
154
+ /** @type {Record<string, (size: number) => string|number>} */ ({})
149
155
  )
150
156
  }
@@ -1,13 +1,18 @@
1
- <script>
1
+ <script lang="ts">
2
2
  import { getContext } from 'svelte'
3
+ import type { PatternMark } from './patterns.js'
4
+ import type { PlotState } from '../PlotState.svelte.js'
3
5
  import { toPatternId } from '../lib/brewing/patterns.js'
4
6
  import { PATTERNS } from './patterns.js'
5
7
  import PatternDef from './PatternDef.svelte'
6
8
 
7
- /** @type {{ patterns?: Record<string, import('./patterns.js').PatternMark[]> }} */
8
- let { patterns = PATTERNS } = $props()
9
+ type Props = {
10
+ patterns?: Record<string, PatternMark[]>
11
+ }
9
12
 
10
- const state = getContext('plot-state')
13
+ let { patterns = PATTERNS }: Props = $props()
14
+
15
+ const state = getContext<PlotState>('plot-state')
11
16
 
12
17
  const patternDefs = $derived.by(() => {
13
18
  const defs = []
@@ -1,8 +1,16 @@
1
- <script>
1
+ <script lang="ts">
2
+ import type { PatternMark } from './patterns.js'
2
3
  import { scaleMark, resolveMarkAttrs } from './scale.js'
3
4
 
4
- /** @type {{ id: string, marks?: import('./patterns.js').PatternMark[], size?: number, stroke?: string, thickness?: number }} */
5
- let { id, marks = [], size = 10, stroke = '#444', thickness = 0.5 } = $props()
5
+ type Props = {
6
+ id: string
7
+ marks?: PatternMark[]
8
+ size?: number
9
+ stroke?: string
10
+ thickness?: number
11
+ }
12
+
13
+ let { id, marks = [], size = 10, stroke = '#444', thickness = 0.5 }: Props = $props()
6
14
 
7
15
  const resolvedMarks = $derived(
8
16
  marks.map((m) => resolveMarkAttrs(scaleMark(m, size), { fill: stroke, stroke, thickness }))
@@ -1,4 +1,14 @@
1
- <script>
1
+ <script lang="ts">
2
+ import type { SVGAttributes } from 'svelte/elements'
3
+
4
+ export interface Props extends Omit<SVGAttributes<SVGRectElement>, 'x' | 'y' | 'fill' | 'stroke'> {
5
+ x?: number
6
+ y?: number
7
+ size?: number
8
+ fill?: string
9
+ stroke?: string
10
+ }
11
+
2
12
  let {
3
13
  x = 0,
4
14
  y = 0,
@@ -10,10 +20,9 @@
10
20
  onmouseleave,
11
21
  onfocus,
12
22
  ...restProps
13
- } = $props()
23
+ }: Props = $props()
14
24
 
15
25
  let r = $derived(size * 3.534)
16
- let props = $derived({ rx: r * 0.1, ry: r * 0.1, ...restProps })
17
26
  </script>
18
27
 
19
28
  <rect
@@ -23,7 +32,9 @@
23
32
  height={r * 2}
24
33
  {fill}
25
34
  {stroke}
26
- {...props}
35
+ rx={r * 0.1}
36
+ ry={r * 0.1}
37
+ {...restProps}
27
38
  role="button"
28
39
  {onclick}
29
40
  {onmouseover}
@@ -1,6 +1,22 @@
1
- <script>
1
+ <script lang="ts">
2
+ import type { SVGAttributes } from 'svelte/elements'
2
3
  import { namedShapes } from './constants'
3
4
 
5
+ export type Props = {
6
+ x?: number
7
+ y?: number
8
+ size?: number
9
+ fill?: string
10
+ stroke?: string
11
+ thickness?: number
12
+ name?: string
13
+ onclick?: SVGAttributes<SVGPathElement>['onclick']
14
+ onmouseover?: SVGAttributes<SVGPathElement>['onmouseover']
15
+ onmouseleave?: SVGAttributes<SVGPathElement>['onmouseleave']
16
+ onfocus?: SVGAttributes<SVGPathElement>['onfocus']
17
+ onblur?: SVGAttributes<SVGPathElement>['onblur']
18
+ }
19
+
4
20
  let {
5
21
  x = 0,
6
22
  y = 0,
@@ -14,9 +30,11 @@
14
30
  onmouseleave,
15
31
  onfocus,
16
32
  onblur
17
- } = $props()
33
+ }: Props = $props()
18
34
 
19
- let d = $derived(name in namedShapes ? namedShapes[name](size) : namedShapes['circle'](size))
35
+ let d = $derived(
36
+ String(name in namedShapes ? namedShapes[name](size) : namedShapes['circle'](size))
37
+ )
20
38
  </script>
21
39
 
22
40
  <!-- svelte-ignore a11y_click_events_have_key_events -->
@@ -1,3 +1,5 @@
1
+ <script lang="ts"></script>
2
+
1
3
  <svg
2
4
  class="plot"
3
5
  fill="currentColor"
@@ -1,3 +1,5 @@
1
+ <script lang="ts"></script>
2
+
1
3
  <svg
2
4
  class="plot"
3
5
  fill="currentColor"