@rokkit/chart 1.1.18 → 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.
- package/dist/AnimatedPlot.svelte.d.ts +35 -0
- package/dist/Chart.svelte.d.ts +21 -0
- package/dist/ChartExporter.svelte.d.ts +22 -0
- package/dist/ChartLegend.svelte.d.ts +30 -0
- package/dist/ChartProvider.svelte.d.ts +10 -0
- package/dist/FacetPlot/Panel.svelte.d.ts +22 -0
- package/dist/FacetPlot.svelte.d.ts +32 -0
- package/dist/Plot/Arc.svelte.d.ts +18 -0
- package/dist/Plot/Area.svelte.d.ts +14 -0
- package/dist/Plot/Axis.svelte.d.ts +13 -0
- package/dist/Plot/Bar.svelte.d.ts +11 -0
- package/dist/Plot/Grid.svelte.d.ts +3 -0
- package/dist/Plot/Legend.svelte.d.ts +6 -0
- package/dist/Plot/Line.svelte.d.ts +13 -0
- package/dist/Plot/Point.svelte.d.ts +13 -0
- package/dist/Plot/Root.svelte.d.ts +21 -0
- package/dist/Plot/Timeline.svelte.d.ts +13 -0
- package/dist/Plot/Tooltip.svelte.d.ts +7 -0
- package/dist/Plot.svelte.d.ts +34 -0
- package/dist/PlotState.svelte.d.ts +0 -3
- package/dist/Sparkline.svelte.d.ts +16 -0
- package/dist/Symbol.svelte.d.ts +12 -0
- package/dist/Texture.svelte.d.ts +12 -0
- package/dist/charts/AreaChart.svelte.d.ts +25 -0
- package/dist/charts/BarChart.svelte.d.ts +26 -0
- package/dist/charts/BoxPlot.svelte.d.ts +18 -0
- package/dist/charts/BubbleChart.svelte.d.ts +23 -0
- package/dist/charts/LineChart.svelte.d.ts +26 -0
- package/dist/charts/PieChart.svelte.d.ts +19 -0
- package/dist/charts/ScatterPlot.svelte.d.ts +29 -0
- package/dist/charts/ViolinPlot.svelte.d.ts +18 -0
- package/dist/crossfilter/CrossFilter.svelte.d.ts +12 -0
- package/dist/crossfilter/FilterBar.svelte.d.ts +12 -0
- package/dist/crossfilter/FilterHistogram.svelte.d.ts +19 -0
- package/dist/crossfilter/FilterSlider.svelte.d.ts +15 -0
- package/dist/elements/Bar.svelte.d.ts +17 -0
- package/dist/elements/ColorRamp.svelte.d.ts +17 -0
- package/dist/elements/ContinuousLegend.svelte.d.ts +18 -0
- package/dist/elements/DefinePatterns.svelte.d.ts +21 -0
- package/dist/elements/DiscreteLegend.svelte.d.ts +17 -0
- package/dist/elements/Label.svelte.d.ts +11 -0
- package/dist/elements/SymbolGrid.svelte.d.ts +8 -0
- package/dist/examples/BarChartExample.svelte.d.ts +18 -0
- package/dist/geoms/Arc.svelte.d.ts +20 -0
- package/dist/geoms/Area.svelte.d.ts +16 -0
- package/dist/geoms/Bar.svelte.d.ts +23 -0
- package/dist/geoms/Box.svelte.d.ts +12 -0
- package/dist/geoms/Candlestick.svelte.d.ts +20 -0
- package/dist/geoms/Heatmap.svelte.d.ts +13 -0
- package/dist/geoms/Hexbin.svelte.d.ts +13 -0
- package/dist/geoms/LabelPill.svelte.d.ts +9 -0
- package/dist/geoms/Line.svelte.d.ts +24 -0
- package/dist/geoms/Point.svelte.d.ts +30 -0
- package/dist/geoms/Ribbon.svelte.d.ts +16 -0
- package/dist/geoms/Violin.svelte.d.ts +12 -0
- package/dist/geoms/Waterfall.svelte.d.ts +18 -0
- package/dist/geoms/lib/areas.d.ts +5 -3
- package/dist/lib/brewing/brewer.svelte.d.ts +24 -15
- package/dist/lib/brewing/marks/arcs.d.ts +16 -6
- package/dist/lib/brewing/marks/areas.d.ts +2 -2
- package/dist/lib/brewing/marks/boxes.d.ts +3 -3
- package/dist/lib/brewing/marks/lines.d.ts +6 -6
- package/dist/lib/brewing/marks/points.d.ts +13 -12
- package/dist/lib/brewing/marks/violins.d.ts +3 -3
- package/dist/lib/brewing/scales.d.ts +3 -3
- package/dist/lib/chart.d.ts +2 -2
- package/dist/lib/keyboard-nav.d.ts +1 -1
- package/dist/lib/plot/facet.d.ts +2 -2
- package/dist/lib/plot/frames.d.ts +9 -9
- package/dist/lib/plot/scales.d.ts +3 -3
- package/dist/lib/plot/types.d.ts +7 -4
- package/dist/lib/scales.svelte.d.ts +2 -2
- package/dist/lib/utils.d.ts +7 -1
- package/dist/lib/xscale.d.ts +1 -1
- package/dist/patterns/DefinePatterns.svelte.d.ts +7 -0
- package/dist/patterns/PatternDef.svelte.d.ts +11 -0
- package/dist/spec/chart-spec.d.ts +22 -0
- package/dist/symbols/RoundedSquare.svelte.d.ts +11 -0
- package/dist/symbols/Shape.svelte.d.ts +18 -0
- package/dist/symbols/constants/index.d.ts +1 -1
- package/dist/symbols/index.d.ts +2 -2
- package/dist/symbols/outline.svelte.d.ts +18 -0
- package/dist/symbols/solid.svelte.d.ts +18 -0
- package/package.json +22 -3
- package/src/AnimatedPlot.svelte +49 -43
- package/src/Chart.svelte +34 -22
- package/src/ChartExporter.svelte +19 -16
- package/src/ChartLegend.svelte +24 -20
- package/src/ChartProvider.svelte +10 -2
- package/src/FacetPlot/Panel.svelte +23 -3
- package/src/FacetPlot.svelte +29 -26
- package/src/Plot/Arc.svelte +3 -2
- package/src/Plot/Area.svelte +30 -8
- package/src/Plot/Axis.svelte +26 -45
- package/src/Plot/Bar.svelte +20 -5
- package/src/Plot/Grid.svelte +5 -4
- package/src/Plot/Legend.svelte +8 -4
- package/src/Plot/Line.svelte +24 -7
- package/src/Plot/Point.svelte +24 -6
- package/src/Plot/Root.svelte +17 -2
- package/src/Plot/Timeline.svelte +13 -14
- package/src/Plot/Tooltip.svelte +12 -6
- package/src/Plot.svelte +41 -32
- package/src/PlotState.svelte.js +6 -2
- package/src/Sparkline.svelte +22 -8
- package/src/Symbol.svelte +15 -5
- package/src/Texture.svelte +12 -2
- package/src/charts/AreaChart.svelte +26 -3
- package/src/charts/BarChart.svelte +27 -3
- package/src/charts/BoxPlot.svelte +19 -3
- package/src/charts/BubbleChart.svelte +24 -3
- package/src/charts/LineChart.svelte +27 -3
- package/src/charts/PieChart.svelte +20 -3
- package/src/charts/ScatterPlot.svelte +27 -3
- package/src/charts/ViolinPlot.svelte +19 -3
- package/src/crossfilter/CrossFilter.svelte +13 -10
- package/src/crossfilter/FilterBar.svelte +14 -3
- package/src/crossfilter/FilterHistogram.svelte +49 -24
- package/src/crossfilter/FilterSlider.svelte +16 -5
- package/src/elements/Bar.svelte +16 -2
- package/src/elements/ColorRamp.svelte +28 -4
- package/src/elements/ContinuousLegend.svelte +20 -3
- package/src/elements/DefinePatterns.svelte +23 -7
- package/src/elements/DiscreteLegend.svelte +18 -2
- package/src/elements/Label.svelte +11 -2
- package/src/elements/SymbolGrid.svelte +13 -4
- package/src/examples/BarChartExample.svelte +12 -15
- package/src/geoms/Arc.svelte +18 -5
- package/src/geoms/Area.svelte +38 -20
- package/src/geoms/Bar.svelte +40 -23
- package/src/geoms/Box.svelte +13 -4
- package/src/geoms/Candlestick.svelte +27 -7
- package/src/geoms/Heatmap.svelte +20 -9
- package/src/geoms/Hexbin.svelte +35 -13
- package/src/geoms/LabelPill.svelte +9 -3
- package/src/geoms/Line.svelte +27 -10
- package/src/geoms/Point.svelte +33 -13
- package/src/geoms/Ribbon.svelte +26 -8
- package/src/geoms/Violin.svelte +13 -4
- package/src/geoms/Waterfall.svelte +32 -12
- package/src/geoms/lib/areas.js +2 -2
- package/src/lib/brewing/marks/arcs.js +3 -2
- package/src/lib/brewing/marks/boxes.js +1 -1
- package/src/lib/brewing/marks/lines.js +2 -2
- package/src/lib/brewing/marks/points.js +3 -2
- package/src/lib/brewing/marks/violins.js +1 -1
- package/src/lib/plot/facet.js +1 -1
- package/src/lib/plot/frames.js +4 -4
- package/src/lib/plot/types.js +6 -3
- package/src/lib/utils.js +7 -1
- package/src/patterns/DefinePatterns.svelte +9 -4
- package/src/patterns/PatternDef.svelte +11 -3
- package/src/symbols/RoundedSquare.svelte +15 -4
- package/src/symbols/Shape.svelte +21 -3
- package/src/symbols/outline.svelte +2 -0
- 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
|
|
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}
|
package/src/geoms/lib/areas.js
CHANGED
|
@@ -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
|
|
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 {
|
|
7
|
-
* @param {{ color
|
|
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
|
|
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
|
|
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:
|
|
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 {
|
|
65
|
-
* @param {{ x
|
|
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
|
|
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
|
package/src/lib/plot/facet.js
CHANGED
package/src/lib/plot/frames.js
CHANGED
|
@@ -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,
|
|
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
|
|
31
|
+
* @param {{ x?: string, y?: string, color?: string }} channels
|
|
32
32
|
* @param {string} byField - the frame field (e.g. 'year')
|
|
33
|
-
* @returns {
|
|
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
|
|
65
|
+
* @param {{ x?: string, y?: string }} channels
|
|
66
66
|
* @returns {{ xDomain: unknown[], yDomain: [number, number] }}
|
|
67
67
|
*/
|
|
68
68
|
export function computeStaticDomains(data, channels) {
|
package/src/lib/plot/types.js
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
8
|
-
|
|
9
|
+
type Props = {
|
|
10
|
+
patterns?: Record<string, PatternMark[]>
|
|
11
|
+
}
|
|
9
12
|
|
|
10
|
-
|
|
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
|
-
|
|
5
|
-
|
|
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
|
-
{
|
|
35
|
+
rx={r * 0.1}
|
|
36
|
+
ry={r * 0.1}
|
|
37
|
+
{...restProps}
|
|
27
38
|
role="button"
|
|
28
39
|
{onclick}
|
|
29
40
|
{onmouseover}
|
package/src/symbols/Shape.svelte
CHANGED
|
@@ -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(
|
|
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 -->
|