@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.
- package/dist/AnimatedPlot.svelte +26 -8
- package/dist/AnimatedPlot.svelte.d.ts +5 -0
- package/dist/Chart.svelte +51 -65
- package/dist/FacetPlot.svelte +1 -1
- package/dist/Plot/Axis.svelte +19 -10
- package/dist/Plot/Root.svelte +67 -46
- package/dist/Plot/Root.svelte.d.ts +29 -2
- package/dist/Plot/Timeline.svelte +39 -13
- package/dist/Plot/index.d.ts +5 -5
- package/dist/Plot/index.js +5 -5
- package/dist/Plot.svelte +95 -178
- package/dist/Plot.svelte.d.ts +4 -0
- package/dist/PlotState.svelte.d.ts +29 -1
- package/dist/PlotState.svelte.js +163 -19
- package/dist/PlotSurface.svelte +162 -0
- package/dist/PlotSurface.svelte.d.ts +25 -0
- package/dist/charts/AreaChart.svelte +12 -2
- package/dist/charts/AreaChart.svelte.d.ts +6 -0
- package/dist/charts/BarChart.svelte +40 -4
- package/dist/charts/BarChart.svelte.d.ts +15 -1
- package/dist/charts/BoxPlot.svelte +7 -3
- package/dist/charts/BoxPlot.svelte.d.ts +2 -0
- package/dist/charts/BubbleChart.svelte +37 -4
- package/dist/charts/BubbleChart.svelte.d.ts +12 -1
- package/dist/charts/LineChart.svelte +4 -2
- package/dist/charts/LineChart.svelte.d.ts +1 -0
- package/dist/charts/PieChart.svelte +5 -3
- package/dist/charts/PieChart.svelte.d.ts +1 -0
- package/dist/charts/ScatterPlot.svelte +35 -4
- package/dist/charts/ScatterPlot.svelte.d.ts +11 -1
- package/dist/charts/ViolinPlot.svelte +7 -3
- package/dist/charts/ViolinPlot.svelte.d.ts +2 -0
- package/dist/examples/BarChartExample.svelte +1 -1
- package/dist/geoms/Arc.svelte +21 -54
- package/dist/geoms/Arc.svelte.d.ts +4 -4
- package/dist/geoms/Area.svelte +45 -44
- package/dist/geoms/Area.svelte.d.ts +8 -1
- package/dist/geoms/Bar.svelte +33 -45
- package/dist/geoms/Bar.svelte.d.ts +9 -0
- package/dist/geoms/Box.svelte +103 -61
- package/dist/geoms/Box.svelte.d.ts +12 -3
- package/dist/geoms/Candlestick.svelte +26 -75
- package/dist/geoms/Candlestick.svelte.d.ts +2 -0
- package/dist/geoms/Heatmap.svelte +21 -66
- package/dist/geoms/Heatmap.svelte.d.ts +2 -0
- package/dist/geoms/Hexbin.svelte +20 -100
- package/dist/geoms/Hexbin.svelte.d.ts +2 -0
- package/dist/geoms/Jitter.svelte +67 -0
- package/dist/geoms/Jitter.svelte.d.ts +17 -0
- package/dist/geoms/Line.svelte +27 -31
- package/dist/geoms/Line.svelte.d.ts +5 -0
- package/dist/geoms/Point.svelte +31 -60
- package/dist/geoms/Point.svelte.d.ts +5 -1
- package/dist/geoms/Ribbon.svelte +30 -124
- package/dist/geoms/Ribbon.svelte.d.ts +2 -0
- package/dist/geoms/Rule.svelte +117 -0
- package/dist/geoms/Rule.svelte.d.ts +19 -0
- package/dist/geoms/Violin.svelte +36 -31
- package/dist/geoms/Violin.svelte.d.ts +10 -3
- package/dist/geoms/Waterfall.svelte +25 -79
- package/dist/geoms/Waterfall.svelte.d.ts +2 -0
- package/dist/geoms/lib/GeomState.svelte.d.ts +51 -0
- package/dist/geoms/lib/GeomState.svelte.js +79 -0
- package/dist/geoms/lib/aesthetics.d.ts +36 -0
- package/dist/geoms/lib/aesthetics.js +45 -0
- package/dist/geoms/lib/areas.d.ts +6 -2
- package/dist/geoms/lib/areas.js +20 -12
- package/dist/geoms/lib/bars.d.ts +18 -3
- package/dist/geoms/lib/bars.js +80 -101
- package/dist/geoms/lib/marks/arc.d.ts +24 -0
- package/dist/geoms/lib/marks/arc.js +28 -0
- package/dist/geoms/lib/marks/area.d.ts +23 -0
- package/dist/geoms/lib/marks/area.js +38 -0
- package/dist/geoms/lib/marks/bar.d.ts +16 -0
- package/dist/geoms/lib/marks/bar.js +43 -0
- package/dist/geoms/lib/marks/box.d.ts +14 -0
- package/dist/geoms/lib/marks/box.js +30 -0
- package/dist/geoms/lib/marks/candlestick.d.ts +27 -0
- package/dist/geoms/lib/marks/candlestick.js +52 -0
- package/dist/geoms/lib/marks/heatmap.d.ts +24 -0
- package/dist/geoms/lib/marks/heatmap.js +41 -0
- package/dist/geoms/lib/marks/hexbin.d.ts +29 -0
- package/dist/geoms/lib/marks/hexbin.js +62 -0
- package/dist/geoms/lib/marks/jitter.d.ts +21 -0
- package/dist/geoms/lib/marks/jitter.js +36 -0
- package/dist/geoms/lib/marks/line.d.ts +26 -0
- package/dist/geoms/lib/marks/line.js +25 -0
- package/dist/geoms/lib/marks/point.d.ts +25 -0
- package/dist/geoms/lib/marks/point.js +58 -0
- package/dist/geoms/lib/marks/ribbon.d.ts +31 -0
- package/dist/geoms/lib/marks/ribbon.js +77 -0
- package/dist/geoms/lib/marks/violin.d.ts +13 -0
- package/dist/geoms/lib/marks/violin.js +31 -0
- package/dist/geoms/lib/marks/waterfall.d.ts +25 -0
- package/dist/geoms/lib/marks/waterfall.js +58 -0
- package/dist/index.d.ts +25 -12
- package/dist/index.js +26 -13
- package/dist/lib/brewing/marks/arcs.js +7 -1
- package/dist/lib/brewing/marks/boxes.d.ts +11 -2
- package/dist/lib/brewing/marks/boxes.js +32 -11
- package/dist/lib/brewing/marks/lines.d.ts +4 -1
- package/dist/lib/brewing/marks/lines.js +18 -15
- package/dist/lib/brewing/marks/swarm.d.ts +32 -0
- package/dist/lib/brewing/marks/swarm.js +125 -0
- package/dist/lib/brewing/marks/violins.d.ts +4 -20
- package/dist/lib/brewing/marks/violins.js +41 -25
- package/dist/lib/brewing/stats.d.ts +3 -1
- package/dist/lib/brewing/stats.js +28 -11
- package/dist/lib/plot/scales.js +12 -7
- package/dist/lib/plot/types.d.ts +9 -1
- package/dist/lib/plot/types.js +3 -1
- package/dist/lib/preset.d.ts +11 -1
- package/dist/lib/preset.js +16 -4
- package/package.json +1 -1
- package/dist/Plot/Arc.svelte +0 -30
- package/dist/Plot/Arc.svelte.d.ts +0 -18
- package/dist/Plot/Area.svelte +0 -54
- package/dist/Plot/Area.svelte.d.ts +0 -14
- package/dist/Plot/Bar.svelte +0 -69
- package/dist/Plot/Bar.svelte.d.ts +0 -11
- package/dist/Plot/Line.svelte +0 -54
- package/dist/Plot/Line.svelte.d.ts +0 -13
- package/dist/Plot/Point.svelte +0 -58
- package/dist/Plot/Point.svelte.d.ts +0 -13
- package/dist/lib/brewer.d.ts +0 -9
- package/dist/lib/brewer.js +0 -25
- package/dist/lib/brewing/BoxBrewer.svelte.d.ts +0 -8
- package/dist/lib/brewing/BoxBrewer.svelte.js +0 -14
- package/dist/lib/brewing/CartesianBrewer.svelte.d.ts +0 -8
- package/dist/lib/brewing/CartesianBrewer.svelte.js +0 -21
- package/dist/lib/brewing/PieBrewer.svelte.d.ts +0 -8
- package/dist/lib/brewing/PieBrewer.svelte.js +0 -14
- package/dist/lib/brewing/QuartileBrewer.svelte.d.ts +0 -9
- package/dist/lib/brewing/QuartileBrewer.svelte.js +0 -51
- package/dist/lib/brewing/ViolinBrewer.svelte.d.ts +0 -8
- package/dist/lib/brewing/ViolinBrewer.svelte.js +0 -14
- package/dist/lib/brewing/axes.svelte.d.ts +0 -66
- package/dist/lib/brewing/axes.svelte.js +0 -270
- package/dist/lib/brewing/bars.svelte.d.ts +0 -56
- package/dist/lib/brewing/bars.svelte.js +0 -201
- package/dist/lib/brewing/brewer.svelte.d.ts +0 -124
- package/dist/lib/brewing/brewer.svelte.js +0 -277
- package/dist/lib/brewing/dimensions.svelte.d.ts +0 -35
- package/dist/lib/brewing/dimensions.svelte.js +0 -56
- package/dist/lib/brewing/index.svelte.d.ts +0 -118
- package/dist/lib/brewing/index.svelte.js +0 -205
- package/dist/lib/brewing/legends.svelte.d.ts +0 -48
- package/dist/lib/brewing/legends.svelte.js +0 -137
- package/dist/lib/brewing/marks/areas.d.ts +0 -31
- package/dist/lib/brewing/marks/areas.js +0 -72
- package/dist/lib/brewing/marks/bars.d.ts +0 -1
- package/dist/lib/brewing/marks/bars.js +0 -49
- package/dist/lib/brewing/scales.svelte.d.ts +0 -24
- package/dist/lib/brewing/scales.svelte.js +0 -82
- package/dist/lib/context.d.ts +0 -13
- package/dist/lib/context.js +0 -131
- package/dist/lib/plot/chartProps.d.ts +0 -177
- package/dist/lib/plot/chartProps.js +0 -76
- package/dist/lib/scales.svelte.d.ts +0 -35
- package/dist/lib/scales.svelte.js +0 -151
- package/dist/lib/ticks.d.ts +0 -36
- package/dist/lib/ticks.js +0 -46
package/dist/lib/preset.d.ts
CHANGED
|
@@ -21,9 +21,19 @@ export namespace defaultPreset {
|
|
|
21
21
|
}
|
|
22
22
|
namespace opacity {
|
|
23
23
|
let area: number;
|
|
24
|
+
let bar: number;
|
|
25
|
+
let line: number;
|
|
26
|
+
let point: number;
|
|
27
|
+
let arc: number;
|
|
24
28
|
let box: number;
|
|
25
29
|
let violin: number;
|
|
26
|
-
let
|
|
30
|
+
let jitter: number;
|
|
31
|
+
let heatmap: number;
|
|
32
|
+
let candlestick: number;
|
|
33
|
+
let hexbin: number;
|
|
34
|
+
let ribbon: number;
|
|
35
|
+
let waterfall: number;
|
|
36
|
+
let rule: number;
|
|
27
37
|
}
|
|
28
38
|
let patterns: string[];
|
|
29
39
|
let symbols: string[];
|
package/dist/lib/preset.js
CHANGED
|
@@ -7,11 +7,23 @@ export const defaultPreset = {
|
|
|
7
7
|
light: { fill: '300', stroke: '700' },
|
|
8
8
|
dark: { fill: '500', stroke: '200' }
|
|
9
9
|
},
|
|
10
|
+
// Per-geom default mark opacity. `alpha` (a fixed 0–1 prop on each geom / Plot.Root)
|
|
11
|
+
// overrides these; solid marks default to 1 so `alpha` is the single opacity knob.
|
|
10
12
|
opacity: {
|
|
11
|
-
area:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
point:
|
|
13
|
+
area: 0.6,
|
|
14
|
+
bar: 1,
|
|
15
|
+
line: 1,
|
|
16
|
+
point: 0.8,
|
|
17
|
+
arc: 1,
|
|
18
|
+
box: 0.5,
|
|
19
|
+
violin: 0.5,
|
|
20
|
+
jitter: 0.8,
|
|
21
|
+
heatmap: 1,
|
|
22
|
+
candlestick: 1,
|
|
23
|
+
hexbin: 1,
|
|
24
|
+
ribbon: 0.5,
|
|
25
|
+
waterfall: 1,
|
|
26
|
+
rule: 1
|
|
15
27
|
},
|
|
16
28
|
patterns: ['diagonal', 'dots', 'triangles', 'hatch', 'lattice', 'swell',
|
|
17
29
|
'checkerboard', 'waves', 'petals', 'brick', 'diamonds', 'tile',
|
package/package.json
CHANGED
package/dist/Plot/Arc.svelte
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { getContext } from 'svelte'
|
|
3
|
-
import type { ChartBrewer } from '../lib/brewing/brewer.svelte.js'
|
|
4
|
-
|
|
5
|
-
const brewer = getContext<ChartBrewer>('chart-brewer')
|
|
6
|
-
</script>
|
|
7
|
-
|
|
8
|
-
{#if brewer && brewer.arcs && brewer.arcs.length > 0}
|
|
9
|
-
<g
|
|
10
|
-
class="chart-arcs"
|
|
11
|
-
data-plot-type="arc"
|
|
12
|
-
transform="translate({brewer.width / 2}, {brewer.height / 2})"
|
|
13
|
-
>
|
|
14
|
-
{#each brewer.arcs as arc (arc.key)}
|
|
15
|
-
<path
|
|
16
|
-
d={arc.d}
|
|
17
|
-
fill={arc.fill}
|
|
18
|
-
stroke={arc.stroke}
|
|
19
|
-
stroke-width="1"
|
|
20
|
-
data-plot-element="arc"
|
|
21
|
-
/>
|
|
22
|
-
{/each}
|
|
23
|
-
</g>
|
|
24
|
-
{/if}
|
|
25
|
-
|
|
26
|
-
<style>
|
|
27
|
-
.chart-arcs {
|
|
28
|
-
pointer-events: none;
|
|
29
|
-
}
|
|
30
|
-
</style>
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
-
$$bindings?: Bindings;
|
|
4
|
-
} & Exports;
|
|
5
|
-
(internal: unknown, props: {
|
|
6
|
-
$$events?: Events;
|
|
7
|
-
$$slots?: Slots;
|
|
8
|
-
}): Exports & {
|
|
9
|
-
$set?: any;
|
|
10
|
-
$on?: any;
|
|
11
|
-
};
|
|
12
|
-
z_$$bindings?: Bindings;
|
|
13
|
-
}
|
|
14
|
-
declare const Arc: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
|
-
[evt: string]: CustomEvent<any>;
|
|
16
|
-
}, {}, {}, string>;
|
|
17
|
-
type Arc = InstanceType<typeof Arc>;
|
|
18
|
-
export default Arc;
|
package/dist/Plot/Area.svelte
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { getContext } from 'svelte'
|
|
3
|
-
import { area as d3Area, type CurveFactory } from 'd3-shape'
|
|
4
|
-
import type { PlotState } from '../PlotState.svelte.js'
|
|
5
|
-
|
|
6
|
-
type Datum = Record<string, unknown> | number
|
|
7
|
-
|
|
8
|
-
type Props = {
|
|
9
|
-
data?: Datum[]
|
|
10
|
-
x?: string
|
|
11
|
-
y?: string
|
|
12
|
-
y0?: string
|
|
13
|
-
fill?: string
|
|
14
|
-
opacity?: number
|
|
15
|
-
curve?: CurveFactory
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let {
|
|
19
|
-
data = [],
|
|
20
|
-
x = undefined,
|
|
21
|
-
y = undefined,
|
|
22
|
-
y0 = undefined,
|
|
23
|
-
fill = 'steelblue',
|
|
24
|
-
opacity = 0.7,
|
|
25
|
-
curve = undefined
|
|
26
|
-
}: Props = $props()
|
|
27
|
-
|
|
28
|
-
const state = getContext<PlotState>('plot-state')
|
|
29
|
-
|
|
30
|
-
const accessor = (d: Datum, field: string | undefined): unknown =>
|
|
31
|
-
field && typeof d === 'object' ? d[field] : d
|
|
32
|
-
|
|
33
|
-
const path = $derived.by(() => {
|
|
34
|
-
if (!state?.xScale || !state?.yScale || !data?.length) return null
|
|
35
|
-
const xScale = state.xScale
|
|
36
|
-
const yScale = state.yScale
|
|
37
|
-
const innerHeight = state.innerHeight
|
|
38
|
-
const areaGen = d3Area<Datum>()
|
|
39
|
-
.x((d) => xScale(accessor(d, x)) ?? 0)
|
|
40
|
-
.y1((d) => yScale(accessor(d, y)) ?? 0)
|
|
41
|
-
.y0((d) =>
|
|
42
|
-
y0 !== undefined
|
|
43
|
-
? (yScale((typeof d === 'object' ? d[y0] : undefined) ?? y0) ?? innerHeight)
|
|
44
|
-
: innerHeight
|
|
45
|
-
)
|
|
46
|
-
.defined((d) => d != null)
|
|
47
|
-
if (curve) areaGen.curve(curve)
|
|
48
|
-
return areaGen(data)
|
|
49
|
-
})
|
|
50
|
-
</script>
|
|
51
|
-
|
|
52
|
-
{#if path}
|
|
53
|
-
<path d={path} {fill} {opacity} stroke="none" data-plot-element="area" />
|
|
54
|
-
{/if}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type CurveFactory } from 'd3-shape';
|
|
2
|
-
type Datum = Record<string, unknown> | number;
|
|
3
|
-
type Props = {
|
|
4
|
-
data?: Datum[];
|
|
5
|
-
x?: string;
|
|
6
|
-
y?: string;
|
|
7
|
-
y0?: string;
|
|
8
|
-
fill?: string;
|
|
9
|
-
opacity?: number;
|
|
10
|
-
curve?: CurveFactory;
|
|
11
|
-
};
|
|
12
|
-
declare const Area: import("svelte").Component<Props, {}, "">;
|
|
13
|
-
type Area = ReturnType<typeof Area>;
|
|
14
|
-
export default Area;
|
package/dist/Plot/Bar.svelte
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { getContext } from 'svelte'
|
|
3
|
-
import type { PlotState } from '../PlotState.svelte.js'
|
|
4
|
-
|
|
5
|
-
type Datum = Record<string, unknown> | number
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
data?: Datum[]
|
|
9
|
-
x?: string
|
|
10
|
-
y?: string
|
|
11
|
-
fill?: string
|
|
12
|
-
opacity?: number
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
let { data = undefined, x = undefined, y = undefined, fill = 'steelblue', opacity = 1 }: Props =
|
|
16
|
-
$props()
|
|
17
|
-
|
|
18
|
-
const state = getContext<PlotState>('plot-state')
|
|
19
|
-
|
|
20
|
-
const accessor = (d: Datum, field: string | undefined): unknown =>
|
|
21
|
-
field && typeof d === 'object' ? d[field] : d
|
|
22
|
-
|
|
23
|
-
const bars = $derived.by(() => {
|
|
24
|
-
if (!state?.xScale || !state?.yScale) return []
|
|
25
|
-
const xScale = state.xScale
|
|
26
|
-
const yScale = state.yScale
|
|
27
|
-
const innerHeight = state.innerHeight
|
|
28
|
-
const src = data ?? []
|
|
29
|
-
if (!src.length) return []
|
|
30
|
-
|
|
31
|
-
const bw = typeof xScale.bandwidth === 'function' ? xScale.bandwidth() : 20
|
|
32
|
-
const padding = typeof xScale.bandwidth === 'function' ? bw * 0.05 : 0
|
|
33
|
-
|
|
34
|
-
// Baseline at y=0 when domain spans zero (supports negative bars)
|
|
35
|
-
const yDomain = typeof yScale.bandwidth !== 'function' ? yScale.domain?.() : null
|
|
36
|
-
const baseline =
|
|
37
|
-
yDomain && yDomain[0] <= 0 && yDomain[yDomain.length - 1] >= 0
|
|
38
|
-
? (yScale(0) ?? innerHeight)
|
|
39
|
-
: innerHeight
|
|
40
|
-
|
|
41
|
-
return src.map((d) => {
|
|
42
|
-
const xVal = accessor(d, x)
|
|
43
|
-
const yVal = accessor(d, y)
|
|
44
|
-
const xPos = (xScale(xVal) ?? 0) + padding
|
|
45
|
-
const yPos = yScale(yVal) ?? baseline
|
|
46
|
-
return {
|
|
47
|
-
x: xPos,
|
|
48
|
-
y: Math.min(yPos, baseline),
|
|
49
|
-
width: bw * 0.9,
|
|
50
|
-
height: Math.abs(baseline - yPos),
|
|
51
|
-
label: `${xVal}: ${yVal}`
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
</script>
|
|
56
|
-
|
|
57
|
-
{#each bars as bar, i (i)}
|
|
58
|
-
<rect
|
|
59
|
-
x={bar.x}
|
|
60
|
-
y={bar.y}
|
|
61
|
-
width={bar.width}
|
|
62
|
-
height={bar.height}
|
|
63
|
-
{fill}
|
|
64
|
-
{opacity}
|
|
65
|
-
data-plot-element="bar"
|
|
66
|
-
role="graphics-symbol"
|
|
67
|
-
aria-label={bar.label}
|
|
68
|
-
/>
|
|
69
|
-
{/each}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type Datum = Record<string, unknown> | number;
|
|
2
|
-
type Props = {
|
|
3
|
-
data?: Datum[];
|
|
4
|
-
x?: string;
|
|
5
|
-
y?: string;
|
|
6
|
-
fill?: string;
|
|
7
|
-
opacity?: number;
|
|
8
|
-
};
|
|
9
|
-
declare const Bar: import("svelte").Component<Props, {}, "">;
|
|
10
|
-
type Bar = ReturnType<typeof Bar>;
|
|
11
|
-
export default Bar;
|
package/dist/Plot/Line.svelte
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { getContext } from 'svelte'
|
|
3
|
-
import { line as d3Line, type CurveFactory } from 'd3-shape'
|
|
4
|
-
import type { PlotState } from '../PlotState.svelte.js'
|
|
5
|
-
|
|
6
|
-
type Datum = Record<string, unknown> | number
|
|
7
|
-
|
|
8
|
-
type Props = {
|
|
9
|
-
data?: Datum[]
|
|
10
|
-
x?: string
|
|
11
|
-
y?: string
|
|
12
|
-
stroke?: string
|
|
13
|
-
strokeWidth?: number
|
|
14
|
-
curve?: CurveFactory
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
let {
|
|
18
|
-
data = [],
|
|
19
|
-
x = undefined,
|
|
20
|
-
y = undefined,
|
|
21
|
-
stroke = 'steelblue',
|
|
22
|
-
strokeWidth = 2,
|
|
23
|
-
curve = undefined
|
|
24
|
-
}: Props = $props()
|
|
25
|
-
|
|
26
|
-
const state = getContext<PlotState>('plot-state')
|
|
27
|
-
|
|
28
|
-
const accessor = (d: Datum, field: string | undefined): unknown =>
|
|
29
|
-
field && typeof d === 'object' ? d[field] : d
|
|
30
|
-
|
|
31
|
-
const path = $derived.by(() => {
|
|
32
|
-
if (!state?.xScale || !state?.yScale || !data?.length) return null
|
|
33
|
-
const xScale = state.xScale
|
|
34
|
-
const yScale = state.yScale
|
|
35
|
-
const lineGen = d3Line<Datum>()
|
|
36
|
-
.x((d) => xScale(accessor(d, x)) ?? 0)
|
|
37
|
-
.y((d) => yScale(accessor(d, y)) ?? 0)
|
|
38
|
-
.defined((d) => d != null)
|
|
39
|
-
if (curve) lineGen.curve(curve)
|
|
40
|
-
return lineGen(data)
|
|
41
|
-
})
|
|
42
|
-
</script>
|
|
43
|
-
|
|
44
|
-
{#if path}
|
|
45
|
-
<path
|
|
46
|
-
d={path}
|
|
47
|
-
fill="none"
|
|
48
|
-
{stroke}
|
|
49
|
-
stroke-width={strokeWidth}
|
|
50
|
-
stroke-linejoin="round"
|
|
51
|
-
stroke-linecap="round"
|
|
52
|
-
data-plot-element="line"
|
|
53
|
-
/>
|
|
54
|
-
{/if}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type CurveFactory } from 'd3-shape';
|
|
2
|
-
type Datum = Record<string, unknown> | number;
|
|
3
|
-
type Props = {
|
|
4
|
-
data?: Datum[];
|
|
5
|
-
x?: string;
|
|
6
|
-
y?: string;
|
|
7
|
-
stroke?: string;
|
|
8
|
-
strokeWidth?: number;
|
|
9
|
-
curve?: CurveFactory;
|
|
10
|
-
};
|
|
11
|
-
declare const Line: import("svelte").Component<Props, {}, "">;
|
|
12
|
-
type Line = ReturnType<typeof Line>;
|
|
13
|
-
export default Line;
|
package/dist/Plot/Point.svelte
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { getContext } from 'svelte'
|
|
3
|
-
import type { PlotState } from '../PlotState.svelte.js'
|
|
4
|
-
|
|
5
|
-
type Datum = Record<string, unknown> | number
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
data?: Datum[]
|
|
9
|
-
x?: string
|
|
10
|
-
y?: string
|
|
11
|
-
r?: number
|
|
12
|
-
fill?: string
|
|
13
|
-
stroke?: string
|
|
14
|
-
strokeWidth?: number
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
let {
|
|
18
|
-
data = [],
|
|
19
|
-
x = undefined,
|
|
20
|
-
y = undefined,
|
|
21
|
-
r = 4,
|
|
22
|
-
fill = 'steelblue',
|
|
23
|
-
stroke = 'white',
|
|
24
|
-
strokeWidth = 1
|
|
25
|
-
}: Props = $props()
|
|
26
|
-
|
|
27
|
-
const state = getContext<PlotState>('plot-state')
|
|
28
|
-
|
|
29
|
-
const accessor = (d: Datum, field: string | undefined): unknown =>
|
|
30
|
-
field && typeof d === 'object' ? d[field] : d
|
|
31
|
-
|
|
32
|
-
const points = $derived.by(() => {
|
|
33
|
-
if (!state?.xScale || !state?.yScale || !data?.length) return []
|
|
34
|
-
const xScale = state.xScale
|
|
35
|
-
const yScale = state.yScale
|
|
36
|
-
return data
|
|
37
|
-
.map((d) => ({
|
|
38
|
-
cx: xScale(accessor(d, x)) ?? null,
|
|
39
|
-
cy: yScale(accessor(d, y)) ?? null,
|
|
40
|
-
label: `(${accessor(d, x)}, ${accessor(d, y)})`
|
|
41
|
-
}))
|
|
42
|
-
.filter((p) => p.cx !== null && p.cy !== null)
|
|
43
|
-
})
|
|
44
|
-
</script>
|
|
45
|
-
|
|
46
|
-
{#each points as pt, i (i)}
|
|
47
|
-
<circle
|
|
48
|
-
cx={pt.cx}
|
|
49
|
-
cy={pt.cy}
|
|
50
|
-
{r}
|
|
51
|
-
{fill}
|
|
52
|
-
{stroke}
|
|
53
|
-
stroke-width={strokeWidth}
|
|
54
|
-
data-plot-element="point"
|
|
55
|
-
role="graphics-symbol"
|
|
56
|
-
aria-label={pt.label}
|
|
57
|
-
/>
|
|
58
|
-
{/each}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
type Datum = Record<string, unknown> | number;
|
|
2
|
-
type Props = {
|
|
3
|
-
data?: Datum[];
|
|
4
|
-
x?: string;
|
|
5
|
-
y?: string;
|
|
6
|
-
r?: number;
|
|
7
|
-
fill?: string;
|
|
8
|
-
stroke?: string;
|
|
9
|
-
strokeWidth?: number;
|
|
10
|
-
};
|
|
11
|
-
declare const Point: import("svelte").Component<Props, {}, "">;
|
|
12
|
-
type Point = ReturnType<typeof Point>;
|
|
13
|
-
export default Point;
|
package/dist/lib/brewer.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get fill patterns for a set of values
|
|
3
|
-
*
|
|
4
|
-
* @param {Array} values - Array of values
|
|
5
|
-
* @param {Object} swatch - Object with keys for color, gray, and pattern
|
|
6
|
-
* @param {Boolean} gray - Boolean to determine if gray or color
|
|
7
|
-
* @returns {Object} - Object with keys for pattern and color
|
|
8
|
-
*/
|
|
9
|
-
export function getFillPatterns(values: any[], swatch: Object, gray?: boolean): Object;
|
package/dist/lib/brewer.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get fill patterns for a set of values
|
|
3
|
-
*
|
|
4
|
-
* @param {Array} values - Array of values
|
|
5
|
-
* @param {Object} swatch - Object with keys for color, gray, and pattern
|
|
6
|
-
* @param {Boolean} gray - Boolean to determine if gray or color
|
|
7
|
-
* @returns {Object} - Object with keys for pattern and color
|
|
8
|
-
*/
|
|
9
|
-
export function getFillPatterns(values, swatch, gray = false) {
|
|
10
|
-
const colors = gray ? swatch.keys.gray : swatch.keys.color
|
|
11
|
-
const max_colors = colors.length
|
|
12
|
-
const max_patterns = swatch.keys.pattern.length
|
|
13
|
-
|
|
14
|
-
const mix = values
|
|
15
|
-
.map((value, index) => ({
|
|
16
|
-
[value]: {
|
|
17
|
-
pattern: swatch.keys.pattern[index % max_patterns],
|
|
18
|
-
color: colors[index % max_colors]
|
|
19
|
-
}
|
|
20
|
-
}))
|
|
21
|
-
.reduce((acc, current) => ({ ...acc, ...current }), {})
|
|
22
|
-
return mix
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// export function getStrokePatterns() {}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { QuartileBrewer } from './QuartileBrewer.svelte.js'
|
|
2
|
-
import { buildBoxes } from './marks/boxes.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Brewer for box plots.
|
|
6
|
-
* fill = box interior color, color = whisker/outline stroke.
|
|
7
|
-
*/
|
|
8
|
-
export class BoxBrewer extends QuartileBrewer {
|
|
9
|
-
boxes = $derived(
|
|
10
|
-
this.xScale && this.yScale
|
|
11
|
-
? buildBoxes(this.processedData, this.channels, this.xScale, this.yScale, this.colorMap)
|
|
12
|
-
: []
|
|
13
|
-
)
|
|
14
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Brewer for cartesian charts (Bar, Line, Area).
|
|
3
|
-
* Groups by x (and fill/color if set) and applies the given stat.
|
|
4
|
-
*/
|
|
5
|
-
export class CartesianBrewer extends ChartBrewer {
|
|
6
|
-
transform(data: any, channels: any, stat: any): any;
|
|
7
|
-
}
|
|
8
|
-
import { ChartBrewer } from './brewer.svelte.js';
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { SvelteSet } from 'svelte/reactivity'
|
|
2
|
-
import { ChartBrewer } from './brewer.svelte.js'
|
|
3
|
-
import { applyAggregate } from './stats.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Brewer for cartesian charts (Bar, Line, Area).
|
|
7
|
-
* Groups by x (and fill/color if set) and applies the given stat.
|
|
8
|
-
*/
|
|
9
|
-
export class CartesianBrewer extends ChartBrewer {
|
|
10
|
-
transform(data, channels, stat) {
|
|
11
|
-
if (stat === 'identity' || !channels.x || !channels.y) return data
|
|
12
|
-
// Group by all mapped aesthetic dimensions so they survive aggregation.
|
|
13
|
-
// e.g. x=region, fill=region, pattern=quarter → by=['region','quarter']
|
|
14
|
-
const by = [
|
|
15
|
-
...new SvelteSet(
|
|
16
|
-
[channels.x, channels.fill, channels.color, channels.pattern].filter(Boolean)
|
|
17
|
-
)
|
|
18
|
-
]
|
|
19
|
-
return applyAggregate(data, { by, value: channels.y, stat })
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Brewer for pie charts. Always aggregates by the label field.
|
|
3
|
-
* 'identity' is not meaningful for pie charts — falls back to 'sum'.
|
|
4
|
-
*/
|
|
5
|
-
export class PieBrewer extends ChartBrewer {
|
|
6
|
-
transform(data: any, channels: any, stat: any): any;
|
|
7
|
-
}
|
|
8
|
-
import { ChartBrewer } from './brewer.svelte.js';
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ChartBrewer } from './brewer.svelte.js'
|
|
2
|
-
import { applyAggregate } from './stats.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Brewer for pie charts. Always aggregates by the label field.
|
|
6
|
-
* 'identity' is not meaningful for pie charts — falls back to 'sum'.
|
|
7
|
-
*/
|
|
8
|
-
export class PieBrewer extends ChartBrewer {
|
|
9
|
-
transform(data, channels, stat) {
|
|
10
|
-
if (!channels.label || !channels.y) return data
|
|
11
|
-
const effectiveStat = stat === 'identity' ? 'sum' : (stat ?? 'sum')
|
|
12
|
-
return applyAggregate(data, { by: [channels.label], value: channels.y, stat: effectiveStat })
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared base for box and violin plots.
|
|
3
|
-
* Groups by x + fill (primary) or x + color (fallback) and computes quartile statistics.
|
|
4
|
-
* Subclasses add their mark-specific $derived (boxes, violins, etc.).
|
|
5
|
-
*/
|
|
6
|
-
export class QuartileBrewer extends ChartBrewer {
|
|
7
|
-
transform(data: any, channels: any): any;
|
|
8
|
-
}
|
|
9
|
-
import { ChartBrewer } from './brewer.svelte.js';
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { quantile, ascending } from 'd3-array'
|
|
2
|
-
import { dataset } from '@rokkit/data'
|
|
3
|
-
import { ChartBrewer } from './brewer.svelte.js'
|
|
4
|
-
import { buildXScale, buildYScale } from './scales.js'
|
|
5
|
-
|
|
6
|
-
function sortedQuantile(values, p) {
|
|
7
|
-
return quantile([...values].sort(ascending), p)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Shared base for box and violin plots.
|
|
12
|
-
* Groups by x + fill (primary) or x + color (fallback) and computes quartile statistics.
|
|
13
|
-
* Subclasses add their mark-specific $derived (boxes, violins, etc.).
|
|
14
|
-
*/
|
|
15
|
-
export class QuartileBrewer extends ChartBrewer {
|
|
16
|
-
transform(data, channels) {
|
|
17
|
-
if (!channels.x || !channels.y) return data
|
|
18
|
-
const by = [channels.x, channels.fill ?? channels.color].filter(Boolean)
|
|
19
|
-
return dataset(data)
|
|
20
|
-
.groupBy(...by)
|
|
21
|
-
.summarize((row) => row[channels.y], {
|
|
22
|
-
q1: (v) => sortedQuantile(v, 0.25),
|
|
23
|
-
median: (v) => sortedQuantile(v, 0.5),
|
|
24
|
-
q3: (v) => sortedQuantile(v, 0.75),
|
|
25
|
-
iqr_min: (v) => {
|
|
26
|
-
const q1 = sortedQuantile(v, 0.25)
|
|
27
|
-
const q3 = sortedQuantile(v, 0.75)
|
|
28
|
-
return q1 - 1.5 * (q3 - q1)
|
|
29
|
-
},
|
|
30
|
-
iqr_max: (v) => {
|
|
31
|
-
const q1 = sortedQuantile(v, 0.25)
|
|
32
|
-
const q3 = sortedQuantile(v, 0.75)
|
|
33
|
-
return q3 + 1.5 * (q3 - q1)
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
.rollup()
|
|
37
|
-
.select()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
xScale = $derived(
|
|
41
|
-
this.channels.x && this.processedData.length > 0
|
|
42
|
-
? buildXScale(this.processedData, this.channels.x, this.innerWidth)
|
|
43
|
-
: null
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
yScale = $derived(
|
|
47
|
-
this.channels.y && this.processedData.length > 0
|
|
48
|
-
? buildYScale(this.processedData, 'iqr_max', this.innerHeight)
|
|
49
|
-
: null
|
|
50
|
-
)
|
|
51
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { QuartileBrewer } from './QuartileBrewer.svelte.js'
|
|
2
|
-
import { buildViolins } from './marks/violins.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Brewer for violin plots.
|
|
6
|
-
* fill = violin body color, color = outline stroke.
|
|
7
|
-
*/
|
|
8
|
-
export class ViolinBrewer extends QuartileBrewer {
|
|
9
|
-
violins = $derived(
|
|
10
|
-
this.xScale && this.yScale
|
|
11
|
-
? buildViolins(this.processedData, this.channels, this.xScale, this.yScale, this.colorMap)
|
|
12
|
-
: []
|
|
13
|
-
)
|
|
14
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates x-axis tick data for rendering
|
|
3
|
-
*
|
|
4
|
-
* @param {Object} scales - Chart scales
|
|
5
|
-
* @param {Function} scales.x - X-axis scale
|
|
6
|
-
* @param {Object} dimensions - Chart dimensions
|
|
7
|
-
* @param {Object} options - Axis options
|
|
8
|
-
* @param {number} [options.tickCount] - Number of ticks to show
|
|
9
|
-
* @param {Function} [options.tickFormat] - Tick formatting function
|
|
10
|
-
* @param {string} [options.label] - Axis label
|
|
11
|
-
* @returns {AxisData} Axis rendering data
|
|
12
|
-
*/
|
|
13
|
-
export function createXAxis(scales: {
|
|
14
|
-
x: Function;
|
|
15
|
-
}, dimensions: Object, options: {
|
|
16
|
-
tickCount?: number | undefined;
|
|
17
|
-
tickFormat?: Function | undefined;
|
|
18
|
-
label?: string | undefined;
|
|
19
|
-
}): AxisData;
|
|
20
|
-
/**
|
|
21
|
-
* Creates y-axis tick data for rendering
|
|
22
|
-
*
|
|
23
|
-
* @param {Object} scales - Chart scales
|
|
24
|
-
* @param {Function} scales.y - Y-axis scale
|
|
25
|
-
* @param {Object} dimensions - Chart dimensions
|
|
26
|
-
* @param {Object} options - Axis options
|
|
27
|
-
* @param {number} [options.tickCount] - Number of ticks to show
|
|
28
|
-
* @param {Function} [options.tickFormat] - Tick formatting function
|
|
29
|
-
* @param {string} [options.label] - Axis label
|
|
30
|
-
* @returns {AxisData} Axis rendering data
|
|
31
|
-
*/
|
|
32
|
-
export function createYAxis(scales: {
|
|
33
|
-
y: Function;
|
|
34
|
-
}, dimensions: Object, options: {
|
|
35
|
-
tickCount?: number | undefined;
|
|
36
|
-
tickFormat?: Function | undefined;
|
|
37
|
-
label?: string | undefined;
|
|
38
|
-
}): AxisData;
|
|
39
|
-
/**
|
|
40
|
-
* Creates grid line data for rendering
|
|
41
|
-
*
|
|
42
|
-
* @param {Object} scales - Chart scales
|
|
43
|
-
* @param {Object} dimensions - Chart dimensions
|
|
44
|
-
* @param {Object} options - Grid options
|
|
45
|
-
* @param {string} [options.direction='both'] - Grid direction ('x', 'y', or 'both')
|
|
46
|
-
* @param {number} [options.xTickCount] - Number of x-axis ticks
|
|
47
|
-
* @param {number} [options.yTickCount] - Number of y-axis ticks
|
|
48
|
-
* @returns {Object} Grid rendering data
|
|
49
|
-
*/
|
|
50
|
-
export function createGrid(scales: Object, dimensions: Object, options: {
|
|
51
|
-
direction?: string | undefined;
|
|
52
|
-
xTickCount?: number | undefined;
|
|
53
|
-
yTickCount?: number | undefined;
|
|
54
|
-
}): Object;
|
|
55
|
-
/**
|
|
56
|
-
* Creates DOM attributes for a tick element
|
|
57
|
-
*
|
|
58
|
-
* @param {TickData} tick - Tick data
|
|
59
|
-
* @param {string} axis - Axis type ('x' or 'y')
|
|
60
|
-
* @returns {Object} Attributes for the tick
|
|
61
|
-
*/
|
|
62
|
-
export function createTickAttributes(tick: TickData, axis: string): Object;
|
|
63
|
-
export type TickData = import("./types").TickData;
|
|
64
|
-
export type AxisData = import("./types").AxisData;
|
|
65
|
-
export type ChartScales = import("./types").ChartScales;
|
|
66
|
-
export type ChartDimensions = import("./types").ChartDimensions;
|