svelteplot 0.0.1-alpha.9 → 0.1.3-next.12
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/LICENSE.md +5 -0
- package/README.md +3 -35
- package/dist/Mark.svelte +292 -0
- package/dist/Mark.svelte.d.ts +22 -0
- package/dist/Plot.svelte +148 -156
- package/dist/Plot.svelte.d.ts +15 -15
- package/dist/constants.d.ts +15 -0
- package/dist/constants.js +110 -0
- package/dist/core/Facet.svelte +59 -0
- package/dist/core/Facet.svelte.d.ts +18 -0
- package/dist/core/FacetAxes.svelte +66 -0
- package/dist/core/FacetAxes.svelte.d.ts +4 -0
- package/dist/core/FacetGrid.svelte +86 -0
- package/dist/core/FacetGrid.svelte.d.ts +13 -0
- package/dist/core/Plot.svelte +568 -0
- package/dist/core/Plot.svelte.d.ts +14 -0
- package/dist/helpers/arrowPath.d.ts +14 -0
- package/dist/helpers/arrowPath.js +129 -0
- package/dist/helpers/autoProjection.d.ts +19 -0
- package/dist/helpers/autoProjection.js +87 -0
- package/dist/helpers/autoScales.d.ts +23 -0
- package/dist/helpers/autoScales.js +203 -0
- package/dist/helpers/autoTicks.d.ts +3 -0
- package/dist/helpers/autoTicks.js +40 -0
- package/dist/helpers/autoTimeFormat.d.ts +2 -2
- package/dist/helpers/autoTimeFormat.js +34 -5
- package/dist/helpers/callWithProps.d.ts +8 -0
- package/dist/helpers/callWithProps.js +13 -0
- package/dist/helpers/colors.js +17 -2
- package/dist/helpers/curves.d.ts +3 -0
- package/dist/helpers/curves.js +42 -0
- package/dist/helpers/data.d.ts +9 -0
- package/dist/helpers/data.js +16 -0
- package/dist/helpers/facets.d.ts +12 -0
- package/dist/helpers/facets.js +49 -0
- package/dist/helpers/formats.d.ts +3 -0
- package/dist/helpers/formats.js +3 -0
- package/dist/helpers/getBaseStyles.d.ts +7 -2
- package/dist/helpers/getBaseStyles.js +34 -10
- package/dist/helpers/getLogTicks.js +5 -5
- package/dist/helpers/group.d.ts +6 -0
- package/dist/helpers/group.js +53 -0
- package/dist/helpers/index.d.ts +18 -0
- package/dist/helpers/index.js +55 -0
- package/dist/helpers/isRawValue.d.ts +2 -0
- package/dist/helpers/isRawValue.js +5 -0
- package/dist/helpers/isValid.d.ts +6 -0
- package/dist/helpers/isValid.js +6 -0
- package/dist/helpers/math.d.ts +19 -0
- package/dist/helpers/math.js +116 -0
- package/dist/helpers/mergeDeep.d.ts +1 -1
- package/dist/helpers/noise.d.ts +1 -0
- package/dist/helpers/noise.js +72 -0
- package/dist/helpers/projection.d.ts +33 -0
- package/dist/helpers/projection.js +100 -0
- package/dist/helpers/reduce.d.ts +10 -0
- package/dist/helpers/reduce.js +85 -0
- package/dist/helpers/regressionLoess.d.ts +12 -0
- package/dist/helpers/regressionLoess.js +47 -0
- package/dist/helpers/removeIdenticalLines.d.ts +8 -1
- package/dist/helpers/removeIdenticalLines.js +14 -7
- package/dist/helpers/resolve.d.ts +21 -0
- package/dist/helpers/resolve.js +156 -0
- package/dist/helpers/roundedRect.d.ts +9 -0
- package/dist/helpers/roundedRect.js +31 -0
- package/dist/helpers/scales.d.ts +42 -0
- package/dist/helpers/scales.js +311 -0
- package/dist/helpers/time.d.ts +6 -0
- package/dist/helpers/time.js +282 -0
- package/dist/helpers/typeChecks.d.ts +8 -5
- package/dist/helpers/typeChecks.js +27 -6
- package/dist/index.d.ts +49 -1
- package/dist/index.js +53 -2
- package/dist/marks/Area.svelte +146 -0
- package/dist/marks/Area.svelte.d.ts +30 -0
- package/dist/marks/AreaX.svelte +27 -0
- package/dist/marks/AreaX.svelte.d.ts +12 -0
- package/dist/marks/AreaY.svelte +38 -0
- package/dist/marks/AreaY.svelte.d.ts +19 -0
- package/dist/marks/Arrow.svelte +139 -0
- package/dist/marks/Arrow.svelte.d.ts +44 -0
- package/dist/marks/AxisX.svelte +198 -93
- package/dist/marks/AxisX.svelte.d.ts +17 -16
- package/dist/marks/AxisY.svelte +176 -62
- package/dist/marks/AxisY.svelte.d.ts +17 -14
- package/dist/marks/BarX.svelte +93 -0
- package/dist/marks/BarX.svelte.d.ts +4 -0
- package/dist/marks/BarY.svelte +103 -0
- package/dist/marks/BarY.svelte.d.ts +25 -0
- package/dist/marks/BollingerX.svelte +44 -0
- package/dist/marks/BollingerX.svelte.d.ts +18 -0
- package/dist/marks/BollingerY.svelte +39 -0
- package/dist/marks/BollingerY.svelte.d.ts +18 -0
- package/dist/marks/BoxX.svelte +89 -0
- package/dist/marks/BoxX.svelte.d.ts +4 -0
- package/dist/marks/BoxY.svelte +110 -0
- package/dist/marks/BoxY.svelte.d.ts +29 -0
- package/dist/marks/Cell.svelte +110 -0
- package/dist/marks/Cell.svelte.d.ts +16 -0
- package/dist/marks/CellX.svelte +24 -0
- package/dist/marks/CellX.svelte.d.ts +3 -0
- package/dist/marks/CellY.svelte +24 -0
- package/dist/marks/CellY.svelte.d.ts +3 -0
- package/dist/marks/ColorLegend.svelte +148 -27
- package/dist/marks/ColorLegend.svelte.d.ts +12 -13
- package/dist/marks/CustomMark.svelte +43 -0
- package/dist/marks/CustomMark.svelte.d.ts +16 -0
- package/dist/marks/CustomMarkHTML.svelte +103 -0
- package/dist/marks/CustomMarkHTML.svelte.d.ts +17 -0
- package/dist/marks/DifferenceY.svelte +144 -0
- package/dist/marks/DifferenceY.svelte.d.ts +30 -0
- package/dist/marks/Dot.svelte +128 -73
- package/dist/marks/Dot.svelte.d.ts +24 -14
- package/dist/marks/DotX.svelte +15 -3
- package/dist/marks/DotX.svelte.d.ts +8 -16
- package/dist/marks/DotY.svelte +8 -3
- package/dist/marks/DotY.svelte.d.ts +5 -17
- package/dist/marks/Frame.svelte +39 -31
- package/dist/marks/Frame.svelte.d.ts +7 -14
- package/dist/marks/Geo.svelte +102 -0
- package/dist/marks/Geo.svelte.d.ts +10 -0
- package/dist/marks/Graticule.svelte +28 -0
- package/dist/marks/Graticule.svelte.d.ts +9 -0
- package/dist/marks/GridX.svelte +67 -36
- package/dist/marks/GridX.svelte.d.ts +7 -18
- package/dist/marks/GridY.svelte +64 -25
- package/dist/marks/GridY.svelte.d.ts +7 -14
- package/dist/marks/HTMLTooltip.svelte +91 -0
- package/dist/marks/HTMLTooltip.svelte.d.ts +11 -0
- package/dist/marks/Line.svelte +219 -58
- package/dist/marks/Line.svelte.d.ts +30 -14
- package/dist/marks/LineX.svelte +8 -8
- package/dist/marks/LineX.svelte.d.ts +4 -17
- package/dist/marks/LineY.svelte +7 -8
- package/dist/marks/LineY.svelte.d.ts +4 -17
- package/dist/marks/Link.svelte +180 -0
- package/dist/marks/Link.svelte.d.ts +21 -0
- package/dist/marks/Pointer.svelte +126 -0
- package/dist/marks/Pointer.svelte.d.ts +23 -0
- package/dist/marks/Rect.svelte +103 -0
- package/dist/marks/Rect.svelte.d.ts +15 -0
- package/dist/marks/RectX.svelte +33 -0
- package/dist/marks/RectX.svelte.d.ts +15 -0
- package/dist/marks/RectY.svelte +33 -0
- package/dist/marks/RectY.svelte.d.ts +15 -0
- package/dist/marks/RegressionX.svelte +26 -0
- package/dist/marks/RegressionX.svelte.d.ts +4 -0
- package/dist/marks/RegressionY.svelte +26 -0
- package/dist/marks/RegressionY.svelte.d.ts +4 -0
- package/dist/marks/RuleX.svelte +52 -28
- package/dist/marks/RuleX.svelte.d.ts +14 -14
- package/dist/marks/RuleY.svelte +52 -28
- package/dist/marks/RuleY.svelte.d.ts +14 -14
- package/dist/marks/Sphere.svelte +8 -0
- package/dist/marks/Sphere.svelte.d.ts +51 -0
- package/dist/marks/Spike.svelte +15 -0
- package/dist/marks/Spike.svelte.d.ts +4 -0
- package/dist/marks/SymbolLegend.svelte +27 -12
- package/dist/marks/SymbolLegend.svelte.d.ts +8 -14
- package/dist/marks/Text.svelte +189 -0
- package/dist/marks/Text.svelte.d.ts +26 -0
- package/dist/marks/TickX.svelte +89 -0
- package/dist/marks/TickX.svelte.d.ts +22 -0
- package/dist/marks/TickY.svelte +90 -0
- package/dist/marks/TickY.svelte.d.ts +22 -0
- package/dist/marks/Vector.svelte +219 -0
- package/dist/marks/Vector.svelte.d.ts +31 -0
- package/dist/marks/helpers/BaseAxisX.svelte +210 -0
- package/dist/marks/helpers/BaseAxisX.svelte.d.ts +24 -0
- package/dist/marks/helpers/BaseAxisY.svelte +187 -0
- package/dist/marks/helpers/BaseAxisY.svelte.d.ts +23 -0
- package/dist/marks/helpers/CanvasLayer.svelte +38 -0
- package/dist/marks/helpers/CanvasLayer.svelte.d.ts +13 -0
- package/dist/marks/helpers/DotCanvas.svelte +184 -0
- package/dist/marks/helpers/DotCanvas.svelte.d.ts +11 -0
- package/dist/marks/helpers/GeoCanvas.svelte +165 -0
- package/dist/marks/helpers/GeoCanvas.svelte.d.ts +13 -0
- package/dist/marks/helpers/GroupMultiple.svelte +17 -0
- package/dist/marks/helpers/GroupMultiple.svelte.d.ts +9 -0
- package/dist/marks/helpers/Marker.svelte +93 -0
- package/dist/marks/helpers/Marker.svelte.d.ts +10 -0
- package/dist/marks/helpers/MarkerPath.svelte +141 -0
- package/dist/marks/helpers/MarkerPath.svelte.d.ts +44 -0
- package/dist/marks/helpers/Regression.svelte +174 -0
- package/dist/marks/helpers/Regression.svelte.d.ts +26 -0
- package/dist/marks/helpers/events.d.ts +8 -0
- package/dist/marks/helpers/events.js +74 -0
- package/dist/transforms/bin.d.ts +51 -0
- package/dist/transforms/bin.js +171 -0
- package/dist/transforms/bollinger.d.ts +21 -0
- package/dist/transforms/bollinger.js +53 -0
- package/dist/transforms/centroid.d.ts +9 -0
- package/dist/transforms/centroid.js +13 -0
- package/dist/transforms/facet.d.ts +1 -0
- package/dist/transforms/facet.js +1 -0
- package/dist/transforms/filter.d.ts +2 -0
- package/dist/transforms/filter.js +8 -0
- package/dist/transforms/group.d.ts +66 -0
- package/dist/transforms/group.js +109 -0
- package/dist/transforms/interval.d.ts +11 -0
- package/dist/transforms/interval.js +34 -0
- package/dist/transforms/jitter.d.ts +1 -0
- package/dist/transforms/jitter.js +1 -0
- package/dist/transforms/map.d.ts +10 -0
- package/dist/transforms/map.js +89 -0
- package/dist/transforms/normalize.d.ts +9 -0
- package/dist/transforms/normalize.js +86 -0
- package/dist/transforms/recordize.d.ts +15 -0
- package/dist/transforms/recordize.js +78 -0
- package/dist/transforms/rename.d.ts +14 -0
- package/dist/transforms/rename.js +42 -0
- package/dist/transforms/select.d.ts +35 -0
- package/dist/transforms/select.js +55 -0
- package/dist/transforms/shift.d.ts +13 -0
- package/dist/transforms/shift.js +45 -0
- package/dist/transforms/sort.d.ts +28 -0
- package/dist/transforms/sort.js +66 -0
- package/dist/transforms/stack.d.ts +10 -0
- package/dist/transforms/stack.js +110 -0
- package/dist/transforms/window.d.ts +24 -0
- package/dist/transforms/window.js +73 -0
- package/dist/types.d.ts +625 -188
- package/dist/ui/Checkbox.svelte +6 -0
- package/dist/ui/Checkbox.svelte.d.ts +13 -0
- package/dist/ui/RadioInput.svelte +27 -0
- package/dist/ui/RadioInput.svelte.d.ts +9 -0
- package/dist/ui/Select.svelte +27 -0
- package/dist/ui/Select.svelte.d.ts +9 -0
- package/dist/ui/Slider.svelte +47 -0
- package/dist/ui/Slider.svelte.d.ts +11 -0
- package/dist/ui/Spiral.svelte +46 -0
- package/dist/ui/Spiral.svelte.d.ts +15 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +4 -0
- package/package.json +81 -42
- package/LICENSE +0 -11
- package/dist/classes/Channel.svelte.js +0 -74
- package/dist/classes/Mark.svelte.js +0 -17
- package/dist/classes/Plot.svelte.js +0 -98
- package/dist/contants.d.ts +0 -3
- package/dist/contants.js +0 -40
- package/dist/helpers/GroupMultiple.svelte +0 -8
- package/dist/helpers/GroupMultiple.svelte.d.ts +0 -19
- package/dist/helpers/createScale.d.ts +0 -5
- package/dist/helpers/createScale.js +0 -57
- package/dist/helpers/resolveChannel.d.ts +0 -2
- package/dist/helpers/resolveChannel.js +0 -28
- package/dist/helpers/wrapArray.d.ts +0 -2
- package/dist/helpers/wrapArray.js +0 -4
- package/dist/marks/BaseMark.svelte +0 -22
- package/dist/marks/BaseMark.svelte.d.ts +0 -19
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type {
|
|
3
|
+
BaseMarkProps,
|
|
4
|
+
ChannelAccessor,
|
|
5
|
+
ConstantAccessor,
|
|
6
|
+
CurveName,
|
|
7
|
+
DataRecord,
|
|
8
|
+
PlotContext
|
|
9
|
+
} from '../types.js';
|
|
10
|
+
import { Line, Area } from '../index.js';
|
|
11
|
+
import { randomId, coalesce } from '../helpers/index.js';
|
|
12
|
+
import { getContext } from 'svelte';
|
|
13
|
+
import { extent, max, min } from 'd3-array';
|
|
14
|
+
import { resolveChannel } from '../helpers/resolve.js';
|
|
15
|
+
import type { CurveFactory } from 'd3-shape';
|
|
16
|
+
|
|
17
|
+
type DifferenceYMarkProps = {
|
|
18
|
+
data: DataRecord[];
|
|
19
|
+
/*
|
|
20
|
+
* the horizontal position of the comparison; bound to the x scale
|
|
21
|
+
*/
|
|
22
|
+
x1: ChannelAccessor;
|
|
23
|
+
/**
|
|
24
|
+
* the horizontal position of the metric; bound to the x scale
|
|
25
|
+
*/
|
|
26
|
+
x2: ChannelAccessor;
|
|
27
|
+
x: ChannelAccessor;
|
|
28
|
+
/**
|
|
29
|
+
* the vertical position of the comparison; bound to the y scale
|
|
30
|
+
*/
|
|
31
|
+
y1: ChannelAccessor;
|
|
32
|
+
/**
|
|
33
|
+
* the vertical position of the metric; bound to the y scale
|
|
34
|
+
*/
|
|
35
|
+
y2: ChannelAccessor;
|
|
36
|
+
y: ChannelAccessor;
|
|
37
|
+
positiveFill?: string;
|
|
38
|
+
positiveFillOpacity?: number;
|
|
39
|
+
negativeFill?: string;
|
|
40
|
+
negativeFillOpacity?: number;
|
|
41
|
+
stroke: boolean | ChannelAccessor;
|
|
42
|
+
curve?: CurveName | CurveFactory;
|
|
43
|
+
tension?: number;
|
|
44
|
+
} & BaseMarkProps;
|
|
45
|
+
|
|
46
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
47
|
+
let plot = $derived(getPlotState());
|
|
48
|
+
|
|
49
|
+
let { data, stroke, class: className = null, ...options }: DifferenceYMarkProps = $props();
|
|
50
|
+
let { x, x1, x2, y, y1, y2 } = $derived(options);
|
|
51
|
+
|
|
52
|
+
const x1x2Differ = $derived((x1 == null || x2 == null) && x1 !== x2);
|
|
53
|
+
|
|
54
|
+
const xExtent = $derived(
|
|
55
|
+
x1x2Differ && x != null ? extent(data, (d) => resolveChannel('x', d, options)) : null
|
|
56
|
+
);
|
|
57
|
+
const x1Extent = $derived(
|
|
58
|
+
x1x2Differ && x1 != null ? extent(data, (d) => resolveChannel('x1', d, options)) : null
|
|
59
|
+
);
|
|
60
|
+
const x2Extent = $derived(
|
|
61
|
+
x1x2Differ && x2 != null ? extent(data, (d) => resolveChannel('x2', d, options)) : null
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const maxMin = $derived(
|
|
65
|
+
max([xExtent, x1Extent, x2Extent].filter((d) => d != null).map((d) => d[0]))
|
|
66
|
+
);
|
|
67
|
+
const minMax = $derived(
|
|
68
|
+
min([xExtent, x1Extent, x2Extent].filter((d) => d != null).map((d) => d[1]))
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const croppedX1 = $derived(
|
|
72
|
+
x1x2Differ
|
|
73
|
+
? data.filter((d) => {
|
|
74
|
+
const x1val = resolveChannel(x1 != null ? 'x1' : 'x', d, options);
|
|
75
|
+
return x1val >= maxMin && x1val <= minMax;
|
|
76
|
+
})
|
|
77
|
+
: data
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const croppedX2 = $derived(
|
|
81
|
+
x1x2Differ
|
|
82
|
+
? data.filter((d) => {
|
|
83
|
+
const x2val = resolveChannel(x2 != null ? 'x2' : 'x', d, options);
|
|
84
|
+
return x2val >= maxMin && x2val <= minMax;
|
|
85
|
+
})
|
|
86
|
+
: data
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const id = randomId();
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<g class="positive difference {className || ''}">
|
|
93
|
+
<!-- pos clips goes from bottom of plot area to the line 2 -->
|
|
94
|
+
<clipPath id="pos-clip-{id}">
|
|
95
|
+
<Area
|
|
96
|
+
data={croppedX2}
|
|
97
|
+
{...options}
|
|
98
|
+
fill={options.positiveFill || 'red'}
|
|
99
|
+
x1={coalesce(x2, x)}
|
|
100
|
+
y1={coalesce(y2, y)}
|
|
101
|
+
y2={{ scale: null, value: plot.options.marginTop + plot.facetHeight }} />
|
|
102
|
+
</clipPath>
|
|
103
|
+
<!-- pos area goes from top to line 1 -->
|
|
104
|
+
<Area
|
|
105
|
+
clipPath="url(#pos-clip-{id})"
|
|
106
|
+
data={croppedX1}
|
|
107
|
+
{...options}
|
|
108
|
+
fill={options.positiveFill || 'pink'}
|
|
109
|
+
fillOpacity={coalesce(options.positiveFillOpacity, 1)}
|
|
110
|
+
x1={coalesce(x1, x2, x)}
|
|
111
|
+
y1={{ scale: null, value: 0 }}
|
|
112
|
+
y2={coalesce(y1, x1x2Differ ? coalesce(y2, y) : 0)} />
|
|
113
|
+
</g>
|
|
114
|
+
<g class="negative difference {className || ''}">
|
|
115
|
+
<!-- neg clips goes from bottom of plot area to the line 1 -->
|
|
116
|
+
<clipPath id="neg-clip-{id}">
|
|
117
|
+
<Area
|
|
118
|
+
data={croppedX1}
|
|
119
|
+
{...options}
|
|
120
|
+
fill={options.negativeFill || 'blue'}
|
|
121
|
+
x1={coalesce(x1, x2, x)}
|
|
122
|
+
y1={coalesce(y1, x1x2Differ ? coalesce(y2, y) : 0)}
|
|
123
|
+
y2={{ scale: null, value: plot.options.marginTop + plot.facetHeight }} />
|
|
124
|
+
</clipPath>
|
|
125
|
+
<!-- neg area goes from top to line 2 -->
|
|
126
|
+
<Area
|
|
127
|
+
clipPath="url(#neg-clip-{id})"
|
|
128
|
+
data={croppedX2}
|
|
129
|
+
{...options}
|
|
130
|
+
fill={options.negativeFill || 'cyan'}
|
|
131
|
+
fillOpacity={coalesce(options.negativeFillOpacity, 1)}
|
|
132
|
+
x1={coalesce(x2, x)}
|
|
133
|
+
y1={{ scale: null, value: 0 }}
|
|
134
|
+
y2={coalesce(y2, y)} />
|
|
135
|
+
</g>
|
|
136
|
+
{#if stroke != null}
|
|
137
|
+
<!-- set stroke to false to hide the line -->
|
|
138
|
+
<Line
|
|
139
|
+
data={croppedX2}
|
|
140
|
+
{...options}
|
|
141
|
+
stroke={stroke === true ? 'currentColor' : stroke}
|
|
142
|
+
x={coalesce(x2, x)}
|
|
143
|
+
y={coalesce(y2, y)} />
|
|
144
|
+
{/if}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BaseMarkProps, ChannelAccessor, CurveName, DataRecord } from '../types.js';
|
|
2
|
+
import type { CurveFactory } from 'd3-shape';
|
|
3
|
+
type DifferenceYMarkProps = {
|
|
4
|
+
data: DataRecord[];
|
|
5
|
+
x1: ChannelAccessor;
|
|
6
|
+
/**
|
|
7
|
+
* the horizontal position of the metric; bound to the x scale
|
|
8
|
+
*/
|
|
9
|
+
x2: ChannelAccessor;
|
|
10
|
+
x: ChannelAccessor;
|
|
11
|
+
/**
|
|
12
|
+
* the vertical position of the comparison; bound to the y scale
|
|
13
|
+
*/
|
|
14
|
+
y1: ChannelAccessor;
|
|
15
|
+
/**
|
|
16
|
+
* the vertical position of the metric; bound to the y scale
|
|
17
|
+
*/
|
|
18
|
+
y2: ChannelAccessor;
|
|
19
|
+
y: ChannelAccessor;
|
|
20
|
+
positiveFill?: string;
|
|
21
|
+
positiveFillOpacity?: number;
|
|
22
|
+
negativeFill?: string;
|
|
23
|
+
negativeFillOpacity?: number;
|
|
24
|
+
stroke: boolean | ChannelAccessor;
|
|
25
|
+
curve?: CurveName | CurveFactory;
|
|
26
|
+
tension?: number;
|
|
27
|
+
} & BaseMarkProps;
|
|
28
|
+
declare const DifferenceY: import("svelte").Component<DifferenceYMarkProps, {}, "">;
|
|
29
|
+
type DifferenceY = ReturnType<typeof DifferenceY>;
|
|
30
|
+
export default DifferenceY;
|
package/dist/marks/Dot.svelte
CHANGED
|
@@ -1,82 +1,137 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, type Snippet } from 'svelte';
|
|
3
|
+
import type {
|
|
4
|
+
PlotContext,
|
|
5
|
+
DataRecord,
|
|
6
|
+
BaseMarkProps,
|
|
7
|
+
ConstantAccessor,
|
|
8
|
+
ChannelAccessor,
|
|
9
|
+
FacetContext,
|
|
10
|
+
PlotDefaults
|
|
11
|
+
} from '../types.js';
|
|
12
|
+
import {
|
|
13
|
+
resolveChannel,
|
|
14
|
+
resolveProp,
|
|
15
|
+
resolveScaledStyles,
|
|
16
|
+
resolveStyles
|
|
17
|
+
} from '../helpers/resolve.js';
|
|
18
|
+
import { maybeSymbol } from '../helpers/symbols.js';
|
|
19
|
+
import { symbol as d3Symbol } from 'd3-shape';
|
|
20
|
+
import { projectXY } from '../helpers/scales.js';
|
|
21
|
+
import { sort } from '../index.js';
|
|
22
|
+
import Mark from '../Mark.svelte';
|
|
23
|
+
import DotCanvas from './helpers/DotCanvas.svelte';
|
|
24
|
+
import { maybeData, testFilter, isValid } from '../helpers/index.js';
|
|
25
|
+
import { recordizeXY } from '../transforms/recordize.js';
|
|
26
|
+
import { addEventHandlers } from './helpers/events.js';
|
|
27
|
+
|
|
28
|
+
type DotProps = BaseMarkProps & {
|
|
29
|
+
data: DataRecord[];
|
|
30
|
+
x: ChannelAccessor;
|
|
31
|
+
y: ChannelAccessor;
|
|
32
|
+
r?: ChannelAccessor;
|
|
33
|
+
fill?: ChannelAccessor;
|
|
34
|
+
stroke?: ChannelAccessor;
|
|
35
|
+
symbol?: ChannelAccessor | Snippet<[number, string]>;
|
|
36
|
+
children?: Snippet;
|
|
37
|
+
dx?: ConstantAccessor<number>;
|
|
38
|
+
dy?: ConstantAccessor<number>;
|
|
39
|
+
canvas: boolean;
|
|
40
|
+
dotClass: ConstantAccessor<string>;
|
|
41
|
+
in: any;
|
|
42
|
+
inParams: any;
|
|
43
|
+
out: any;
|
|
44
|
+
outParams: any;
|
|
45
|
+
transition: any;
|
|
46
|
+
wrap: Snippet;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
let {
|
|
50
|
+
data = [{}],
|
|
51
|
+
canvas = false,
|
|
52
|
+
class: className = '',
|
|
53
|
+
dotClass = null,
|
|
54
|
+
in: tIn = undefined,
|
|
55
|
+
inParams = undefined,
|
|
56
|
+
out: tOut = undefined,
|
|
57
|
+
outParams = undefined,
|
|
58
|
+
...options
|
|
59
|
+
}: DotProps = $props();
|
|
60
|
+
|
|
61
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
62
|
+
let plot = $derived(getPlotState());
|
|
63
|
+
|
|
64
|
+
function getSymbolPath(symbolType, size) {
|
|
65
|
+
return d3Symbol(maybeSymbol(symbolType), size)();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const { getTestFacet } = getContext<FacetContext>('svelteplot/facet');
|
|
69
|
+
const { dotRadius } = getContext<PlotDefaults>('svelteplot/_defaults');
|
|
70
|
+
let testFacet = $derived(getTestFacet());
|
|
71
|
+
|
|
72
|
+
const args = $derived(
|
|
73
|
+
// todo: move sorting to Mark
|
|
74
|
+
sort(
|
|
75
|
+
recordizeXY({
|
|
76
|
+
data: maybeData(data),
|
|
77
|
+
// sort by descending radius by default
|
|
78
|
+
...(options.r ? { sort: { channel: '-r' } } : {}),
|
|
79
|
+
...options,
|
|
80
|
+
...(options.fill === true ? { fill: 'currentColor' } : {})
|
|
81
|
+
})
|
|
82
|
+
)
|
|
83
|
+
);
|
|
26
84
|
</script>
|
|
27
85
|
|
|
28
|
-
<
|
|
86
|
+
<Mark
|
|
29
87
|
type="dot"
|
|
30
|
-
{
|
|
88
|
+
required={['x', 'y']}
|
|
31
89
|
channels={[
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
90
|
+
'x',
|
|
91
|
+
'y',
|
|
92
|
+
'r',
|
|
93
|
+
'symbol',
|
|
94
|
+
'fill',
|
|
95
|
+
'opacity',
|
|
96
|
+
'stroke',
|
|
97
|
+
'fillOpacity',
|
|
98
|
+
'strokeOpacity'
|
|
37
99
|
]}
|
|
38
|
-
{
|
|
39
|
-
{
|
|
40
|
-
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
transform="translate({[plot.xScale(cx), plot.yScale(cy)]})"
|
|
70
|
-
/>
|
|
100
|
+
defaults={{ r: dotRadius, symbol: 'circle' }}
|
|
101
|
+
{...args}>
|
|
102
|
+
{#snippet children({ mark, usedScales, scaledData })}
|
|
103
|
+
<g class="dots {className || ''}">
|
|
104
|
+
{#if canvas}
|
|
105
|
+
<DotCanvas data={args.data} {mark} {plot} {testFacet} {usedScales} />
|
|
106
|
+
{:else}
|
|
107
|
+
{#each scaledData as d}
|
|
108
|
+
{#if d.valid && isValid(d.r)}
|
|
109
|
+
{@const [style, styleClass] = resolveStyles(
|
|
110
|
+
plot,
|
|
111
|
+
d,
|
|
112
|
+
{ strokeWidth: 1.6, ...args },
|
|
113
|
+
'stroke',
|
|
114
|
+
usedScales
|
|
115
|
+
)}
|
|
116
|
+
<path
|
|
117
|
+
transform="translate({d.x}, {d.y})"
|
|
118
|
+
d={getSymbolPath(d.symbol, d.r ** 2 * Math.PI)}
|
|
119
|
+
class={[
|
|
120
|
+
dotClass ? resolveProp(dotClass, d.datum, null) : null,
|
|
121
|
+
styleClass
|
|
122
|
+
]}
|
|
123
|
+
{style}
|
|
124
|
+
use:addEventHandlers={{
|
|
125
|
+
getPlotState,
|
|
126
|
+
options: args,
|
|
127
|
+
datum: d.datum
|
|
128
|
+
}} />
|
|
129
|
+
{/if}
|
|
130
|
+
{/each}
|
|
71
131
|
{/if}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
</
|
|
132
|
+
</g>
|
|
133
|
+
{/snippet}
|
|
134
|
+
</Mark>
|
|
75
135
|
|
|
76
136
|
<style>
|
|
77
|
-
path {
|
|
78
|
-
fill: none;
|
|
79
|
-
stroke: none;
|
|
80
|
-
stroke-width: 1.6px;
|
|
81
|
-
}
|
|
82
137
|
</style>
|
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { DataRecord, BaseMarkProps, ConstantAccessor, ChannelAccessor } from '../types.js';
|
|
3
|
+
type DotProps = BaseMarkProps & {
|
|
4
|
+
data: DataRecord[];
|
|
5
|
+
x: ChannelAccessor;
|
|
6
|
+
y: ChannelAccessor;
|
|
7
|
+
r?: ChannelAccessor;
|
|
8
|
+
fill?: ChannelAccessor;
|
|
9
|
+
stroke?: ChannelAccessor;
|
|
10
|
+
symbol?: ChannelAccessor | Snippet<[number, string]>;
|
|
11
|
+
children?: Snippet;
|
|
12
|
+
dx?: ConstantAccessor<number>;
|
|
13
|
+
dy?: ConstantAccessor<number>;
|
|
14
|
+
canvas: boolean;
|
|
15
|
+
dotClass: ConstantAccessor<string>;
|
|
16
|
+
in: any;
|
|
17
|
+
inParams: any;
|
|
18
|
+
out: any;
|
|
19
|
+
outParams: any;
|
|
20
|
+
transition: any;
|
|
21
|
+
wrap: Snippet;
|
|
9
22
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
export default class Dot extends SvelteComponent<DotProps, DotEvents, DotSlots> {
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
23
|
+
declare const Dot: import("svelte").Component<DotProps, {}, "">;
|
|
24
|
+
type Dot = ReturnType<typeof Dot>;
|
|
25
|
+
export default Dot;
|
package/dist/marks/DotX.svelte
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Dot from './Dot.svelte';
|
|
3
|
+
import { recordizeX } from '../index.js';
|
|
4
|
+
import type { BaseMarkProps, DataRow } from '../types.js';
|
|
5
|
+
import type { ChannelAccessor } from '../types.js';
|
|
6
|
+
|
|
7
|
+
type DotXProps = BaseMarkProps & {
|
|
8
|
+
data: DataRow[];
|
|
9
|
+
x?: ChannelAccessor;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
let { data = [{}], ...options }: DotXProps = $props();
|
|
13
|
+
|
|
14
|
+
const args = $derived(recordizeX({ data, ...options, y: 1 }, { withIndex: false }));
|
|
3
15
|
</script>
|
|
4
16
|
|
|
5
|
-
<Dot {
|
|
17
|
+
<Dot {...args} />
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
events: {
|
|
8
|
-
[evt: string]: CustomEvent<any>;
|
|
9
|
-
};
|
|
10
|
-
slots: {};
|
|
1
|
+
import type { BaseMarkProps, DataRow } from '../types.js';
|
|
2
|
+
import type { ChannelAccessor } from '../types.js';
|
|
3
|
+
type DotXProps = BaseMarkProps & {
|
|
4
|
+
data: DataRow[];
|
|
5
|
+
x?: ChannelAccessor;
|
|
11
6
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export
|
|
15
|
-
export default class DotX extends SvelteComponent<DotXProps, DotXEvents, DotXSlots> {
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
7
|
+
declare const DotX: import("svelte").Component<DotXProps, {}, "">;
|
|
8
|
+
type DotX = ReturnType<typeof DotX>;
|
|
9
|
+
export default DotX;
|
package/dist/marks/DotY.svelte
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Dot from './Dot.svelte';
|
|
3
|
+
import { recordizeY } from '../index.js';
|
|
4
|
+
|
|
5
|
+
let { data = [{}], ...options } = $props();
|
|
6
|
+
|
|
7
|
+
const args = $derived(recordizeY({ data, ...options, x: 0 }, { withIndex: false }));
|
|
3
8
|
</script>
|
|
4
9
|
|
|
5
|
-
<Dot {
|
|
10
|
+
<Dot {...args} />
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
events: {
|
|
8
|
-
[evt: string]: CustomEvent<any>;
|
|
9
|
-
};
|
|
10
|
-
slots: {};
|
|
11
|
-
};
|
|
12
|
-
export type DotYProps = typeof __propDef.props;
|
|
13
|
-
export type DotYEvents = typeof __propDef.events;
|
|
14
|
-
export type DotYSlots = typeof __propDef.slots;
|
|
15
|
-
export default class DotY extends SvelteComponent<DotYProps, DotYEvents, DotYSlots> {
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
1
|
+
declare const DotY: import("svelte").Component<{
|
|
2
|
+
data?: any[];
|
|
3
|
+
} & Record<string, any>, {}, "">;
|
|
4
|
+
type DotY = ReturnType<typeof DotY>;
|
|
5
|
+
export default DotY;
|
package/dist/marks/Frame.svelte
CHANGED
|
@@ -1,37 +1,45 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Mark from '../Mark.svelte';
|
|
3
|
+
import { getContext } from 'svelte';
|
|
4
|
+
import type { PlotContext, BaseRectMarkProps } from '../types.js';
|
|
5
|
+
import type { BaseMarkProps } from '../types.js';
|
|
6
|
+
import { resolveProp, resolveScaledStyles } from '../helpers/resolve.js';
|
|
7
|
+
import { addEventHandlers } from './helpers/events.js';
|
|
8
|
+
|
|
9
|
+
type FrameMarkProps = BaseMarkProps &
|
|
10
|
+
BaseRectMarkProps & {
|
|
11
|
+
automatic?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
let { automatic, class: className = null, ...options }: FrameMarkProps = $props();
|
|
15
|
+
|
|
16
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
17
|
+
const plot = $derived(getPlotState());
|
|
18
|
+
|
|
19
|
+
const dx = $derived(resolveProp(options.dx, null, 0));
|
|
20
|
+
const dy = $derived(resolveProp(options.dy, null, 0));
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
insetLeft = options.inset || 0,
|
|
24
|
+
insetTop = options.inset || 0,
|
|
25
|
+
insetRight = options.inset || 0,
|
|
26
|
+
insetBottom = options.inset || 0
|
|
27
|
+
} = $derived(options);
|
|
10
28
|
</script>
|
|
11
29
|
|
|
12
|
-
<
|
|
30
|
+
<Mark type="frame" {automatic}>
|
|
13
31
|
<rect
|
|
14
|
-
class=
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
style="font-size: 40px;text-anchor:middle"
|
|
26
|
-
dominant-baseline="central"
|
|
27
|
-
opacity={0.1}
|
|
28
|
-
transform="translate({plot.margins.left + plot.plotWidth * 0.5}, {plot.margins.top +
|
|
29
|
-
plot.plotHeight * 0.5})">{plot.plotWidth} x {plot.plotHeight}</text
|
|
30
|
-
> -->
|
|
32
|
+
class={['frame', className]}
|
|
33
|
+
transform={dx || dy ? `translate(${dx},${dy})` : null}
|
|
34
|
+
style={resolveScaledStyles({}, options, {}, plot, 'stroke')}
|
|
35
|
+
x={plot.options.marginLeft + +insetLeft}
|
|
36
|
+
y={plot.options.marginTop + +insetTop}
|
|
37
|
+
rx={resolveProp(options.rx, null, null)}
|
|
38
|
+
ry={resolveProp(options.ry, null, null)}
|
|
39
|
+
width={plot.facetWidth - (insetLeft || 0) - (insetRight || 0)}
|
|
40
|
+
height={plot.facetHeight - (insetBottom || 0) - (insetTop || 0)}
|
|
41
|
+
use:addEventHandlers={{ getPlotState, options: options, datum: {} }} />
|
|
42
|
+
</Mark>
|
|
31
43
|
|
|
32
44
|
<style>
|
|
33
|
-
.frame {
|
|
34
|
-
stroke: none;
|
|
35
|
-
fill: none;
|
|
36
|
-
}
|
|
37
45
|
</style>
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
events: {
|
|
6
|
-
[evt: string]: CustomEvent<any>;
|
|
7
|
-
};
|
|
8
|
-
slots: {};
|
|
1
|
+
import type { BaseRectMarkProps } from '../types.js';
|
|
2
|
+
import type { BaseMarkProps } from '../types.js';
|
|
3
|
+
type FrameMarkProps = BaseMarkProps & BaseRectMarkProps & {
|
|
4
|
+
automatic?: boolean;
|
|
9
5
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
export type FrameSlots = typeof __propDef.slots;
|
|
14
|
-
export default class Frame extends SvelteComponent<FrameProps, FrameEvents, FrameSlots> {
|
|
15
|
-
}
|
|
6
|
+
declare const Frame: import("svelte").Component<FrameMarkProps, {}, "">;
|
|
7
|
+
type Frame = ReturnType<typeof Frame>;
|
|
8
|
+
export default Frame;
|