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,126 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { ChannelAccessor, DataRow } from '../types.js';
|
|
3
|
+
|
|
4
|
+
export type PointerMarkProps = {
|
|
5
|
+
data: DataRow[];
|
|
6
|
+
children: Snippet<[{ data: DataRow[] }]>;
|
|
7
|
+
x?: ChannelAccessor;
|
|
8
|
+
y?: ChannelAccessor;
|
|
9
|
+
z?: ChannelAccessor;
|
|
10
|
+
/**
|
|
11
|
+
* maximum cursor distance to select data points
|
|
12
|
+
*/
|
|
13
|
+
maxDistance: number;
|
|
14
|
+
/**
|
|
15
|
+
* called whenever the selection changes
|
|
16
|
+
* @param data
|
|
17
|
+
*/
|
|
18
|
+
onupdate: (data: DataRow[]) => void;
|
|
19
|
+
};
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { getContext, type Snippet } from 'svelte';
|
|
24
|
+
import type { PlotContext } from '../types.js';
|
|
25
|
+
import { groups as d3Groups } from 'd3-array';
|
|
26
|
+
|
|
27
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
28
|
+
const plot = $derived(getPlotState());
|
|
29
|
+
|
|
30
|
+
import { resolveChannel } from '../helpers/resolve.js';
|
|
31
|
+
import { quadtree } from 'd3-quadtree';
|
|
32
|
+
import { projectXY } from '../helpers/scales.js';
|
|
33
|
+
import isDataRecord from '../helpers/isDataRecord.js';
|
|
34
|
+
|
|
35
|
+
let {
|
|
36
|
+
data = [{}],
|
|
37
|
+
children,
|
|
38
|
+
x,
|
|
39
|
+
y,
|
|
40
|
+
z,
|
|
41
|
+
maxDistance = 15,
|
|
42
|
+
onupdate = null
|
|
43
|
+
}: PointerMarkProps = $props();
|
|
44
|
+
|
|
45
|
+
let selectedData = $state([]);
|
|
46
|
+
|
|
47
|
+
function onMouseMove(evt: MouseEvent) {
|
|
48
|
+
updateSelection(evt.layerX, evt.layerY);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function onTouchMove(evt: TouchEvent) {
|
|
52
|
+
if (evt.touches) {
|
|
53
|
+
const rect = (evt.target as HTMLElement).getBoundingClientRect();
|
|
54
|
+
const pageTop = window.scrollY || document.documentElement.scrollTop;
|
|
55
|
+
const ox = rect.left;
|
|
56
|
+
const oy = rect.top + pageTop;
|
|
57
|
+
|
|
58
|
+
const touch = evt.touches[0] || evt.changedTouches[0];
|
|
59
|
+
if (touch) {
|
|
60
|
+
const ex = touch.pageX - ox;
|
|
61
|
+
const ey = touch.pageY - oy;
|
|
62
|
+
updateSelection(ex, ey);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function onMouseLeave() {
|
|
68
|
+
selectedData = [];
|
|
69
|
+
if (onupdate) onupdate(selectedData);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function updateSelection(ex: number, ey: number) {
|
|
73
|
+
// find data row with minimum distance to
|
|
74
|
+
const points = trees.map((tree) =>
|
|
75
|
+
tree.find(x != null ? ex : 0, y != null ? ey : 0, maxDistance)
|
|
76
|
+
);
|
|
77
|
+
selectedData = points.filter((d) => d != null);
|
|
78
|
+
if (onupdate) onupdate(selectedData);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
$effect(() => {
|
|
82
|
+
plot.body?.addEventListener('mousemove', onMouseMove);
|
|
83
|
+
plot.body?.addEventListener('mouseleave', onMouseLeave);
|
|
84
|
+
plot.body?.addEventListener('touchmove', onTouchMove);
|
|
85
|
+
|
|
86
|
+
return () => {
|
|
87
|
+
plot.body?.removeEventListener('mousemove', onMouseMove);
|
|
88
|
+
plot.body?.removeEventListener('mouseleave', onMouseLeave);
|
|
89
|
+
plot.body?.removeEventListener('touchmove', onTouchMove);
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const groups = $derived(
|
|
94
|
+
z != null ? d3Groups(data, (d) => resolveChannel('z', d, { x, z })) : [[null, data]]
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const trees = $derived(
|
|
98
|
+
groups.map(([, items]) =>
|
|
99
|
+
quadtree()
|
|
100
|
+
.x(x != null ? (d) => d.__pointerX : () => 0)
|
|
101
|
+
.y(y != null ? (d) => d.__pointerY : () => 0)
|
|
102
|
+
.addAll(
|
|
103
|
+
items?.map((d) => {
|
|
104
|
+
const [px, py] = projectXY(
|
|
105
|
+
plot.scales,
|
|
106
|
+
resolveChannel('x', d, { x }),
|
|
107
|
+
resolveChannel('y', d, { y }),
|
|
108
|
+
true,
|
|
109
|
+
true
|
|
110
|
+
);
|
|
111
|
+
return {
|
|
112
|
+
...(isDataRecord(d) ? d : { ___orig___: d }),
|
|
113
|
+
__pointerX: px,
|
|
114
|
+
__pointerY: py
|
|
115
|
+
};
|
|
116
|
+
}) ?? []
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
{#if children}
|
|
123
|
+
<g class="pointer">
|
|
124
|
+
{@render children({ data: selectedData })}
|
|
125
|
+
</g>
|
|
126
|
+
{/if}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ChannelAccessor, DataRow } from '../types.js';
|
|
2
|
+
export type PointerMarkProps = {
|
|
3
|
+
data: DataRow[];
|
|
4
|
+
children: Snippet<[{
|
|
5
|
+
data: DataRow[];
|
|
6
|
+
}]>;
|
|
7
|
+
x?: ChannelAccessor;
|
|
8
|
+
y?: ChannelAccessor;
|
|
9
|
+
z?: ChannelAccessor;
|
|
10
|
+
/**
|
|
11
|
+
* maximum cursor distance to select data points
|
|
12
|
+
*/
|
|
13
|
+
maxDistance: number;
|
|
14
|
+
/**
|
|
15
|
+
* called whenever the selection changes
|
|
16
|
+
* @param data
|
|
17
|
+
*/
|
|
18
|
+
onupdate: (data: DataRow[]) => void;
|
|
19
|
+
};
|
|
20
|
+
import { type Snippet } from 'svelte';
|
|
21
|
+
declare const Pointer: import("svelte").Component<PointerMarkProps, {}, "">;
|
|
22
|
+
type Pointer = ReturnType<typeof Pointer>;
|
|
23
|
+
export default Pointer;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
For arbitrary rectangles, requires quantitative x and y scales
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import Mark from '../Mark.svelte';
|
|
7
|
+
import { getContext } from 'svelte';
|
|
8
|
+
import { recordizeY, intervalX, intervalY } from '../index.js';
|
|
9
|
+
import {
|
|
10
|
+
resolveChannel,
|
|
11
|
+
resolveProp,
|
|
12
|
+
resolveScaledStyles,
|
|
13
|
+
resolveStyles
|
|
14
|
+
} from '../helpers/resolve.js';
|
|
15
|
+
import { getUsedScales, projectX, projectY } from '../helpers/scales.js';
|
|
16
|
+
import { coalesce, testFilter, maybeNumber } from '../helpers/index.js';
|
|
17
|
+
import type {
|
|
18
|
+
PlotContext,
|
|
19
|
+
DataRecord,
|
|
20
|
+
BaseMarkProps,
|
|
21
|
+
BaseRectMarkProps,
|
|
22
|
+
ChannelAccessor
|
|
23
|
+
} from '../types.js';
|
|
24
|
+
import { isValid } from '../helpers/isValid.js';
|
|
25
|
+
import { addEventHandlers } from './helpers/events.js';
|
|
26
|
+
import GroupMultiple from './helpers/GroupMultiple.svelte';
|
|
27
|
+
|
|
28
|
+
type RectMarkProps = BaseMarkProps & {
|
|
29
|
+
data: DataRecord[];
|
|
30
|
+
x?: ChannelAccessor;
|
|
31
|
+
x1?: ChannelAccessor;
|
|
32
|
+
x2?: ChannelAccessor;
|
|
33
|
+
y?: ChannelAccessor;
|
|
34
|
+
y1?: ChannelAccessor;
|
|
35
|
+
y2?: ChannelAccessor;
|
|
36
|
+
interval?: number | string;
|
|
37
|
+
} & BaseRectMarkProps;
|
|
38
|
+
|
|
39
|
+
let { data = [{}], class: className = null, ...options }: RectMarkProps = $props();
|
|
40
|
+
|
|
41
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
42
|
+
let plot = $derived(getPlotState());
|
|
43
|
+
|
|
44
|
+
const args = $derived(
|
|
45
|
+
intervalY(intervalX({ data, ...options }, { plot }), { plot }) as RectMarkProps
|
|
46
|
+
);
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<Mark
|
|
50
|
+
type="rect"
|
|
51
|
+
required={[]}
|
|
52
|
+
channels={['x1', 'x2', 'y1', 'y2', 'fill', 'stroke', 'opacity', 'fillOpacity', 'strokeOpacity']}
|
|
53
|
+
{...args}>
|
|
54
|
+
{#snippet children({ mark, usedScales, scaledData })}
|
|
55
|
+
<g class="rect">
|
|
56
|
+
{#each scaledData as d}
|
|
57
|
+
{#if d.valid}
|
|
58
|
+
{@const x1 = d.x1 == null ? plot.options.marginLeft : d.x1}
|
|
59
|
+
{@const x2 = d.x2 == null ? plot.options.marginLeft + plot.facetWidth : d.x2}
|
|
60
|
+
{@const y1 = d.y1 == null ? plot.options.marginTop : d.y1}
|
|
61
|
+
{@const y2 = d.y2 == null ? plot.options.marginTop + plot.facetHeight : d.y2}
|
|
62
|
+
|
|
63
|
+
{@const miny = Math.min(y1, y2)}
|
|
64
|
+
{@const maxy = Math.max(y1, y2)}
|
|
65
|
+
{@const minx = Math.min(x1, x2)}
|
|
66
|
+
{@const maxx = Math.max(x1, x2)}
|
|
67
|
+
{@const inset = resolveProp(args.inset, d.datum, 0)}
|
|
68
|
+
{@const insetLeft = resolveProp(args.insetLeft, d.datum)}
|
|
69
|
+
{@const insetRight = resolveProp(args.insetRight, d.datum)}
|
|
70
|
+
{@const insetTop = resolveProp(args.insetTop, d.datum)}
|
|
71
|
+
{@const insetBottom = resolveProp(args.insetBottom, d.datum)}
|
|
72
|
+
{@const insetL = maybeNumber(coalesce(insetLeft, inset, 0))}
|
|
73
|
+
{@const insetT = maybeNumber(coalesce(insetTop, inset, 0))}
|
|
74
|
+
{@const insetR = maybeNumber(coalesce(insetRight, inset, 0))}
|
|
75
|
+
{@const insetB = maybeNumber(coalesce(insetBottom, inset, 0))}
|
|
76
|
+
|
|
77
|
+
{@const [style, styleClass] = resolveStyles(plot, d, args, 'fill', usedScales)}
|
|
78
|
+
<rect
|
|
79
|
+
class={[styleClass]}
|
|
80
|
+
{style}
|
|
81
|
+
x={minx + insetL}
|
|
82
|
+
y={miny + insetT}
|
|
83
|
+
width={maxx - minx - insetL - insetR}
|
|
84
|
+
height={maxy - miny - insetT - insetB}
|
|
85
|
+
rx={resolveProp(args.rx, d.datum, null)}
|
|
86
|
+
ry={resolveProp(args.ry, d.datum, null)}
|
|
87
|
+
use:addEventHandlers={{
|
|
88
|
+
getPlotState,
|
|
89
|
+
options: args,
|
|
90
|
+
datum: d.datum
|
|
91
|
+
}} />
|
|
92
|
+
{/if}
|
|
93
|
+
{/each}
|
|
94
|
+
</g>
|
|
95
|
+
{/snippet}
|
|
96
|
+
</Mark>
|
|
97
|
+
|
|
98
|
+
<style>
|
|
99
|
+
rect {
|
|
100
|
+
stroke: none;
|
|
101
|
+
/* fill: none; */
|
|
102
|
+
}
|
|
103
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DataRecord, BaseMarkProps, BaseRectMarkProps, ChannelAccessor } from '../types.js';
|
|
2
|
+
type RectMarkProps = BaseMarkProps & {
|
|
3
|
+
data: DataRecord[];
|
|
4
|
+
x?: ChannelAccessor;
|
|
5
|
+
x1?: ChannelAccessor;
|
|
6
|
+
x2?: ChannelAccessor;
|
|
7
|
+
y?: ChannelAccessor;
|
|
8
|
+
y1?: ChannelAccessor;
|
|
9
|
+
y2?: ChannelAccessor;
|
|
10
|
+
interval?: number | string;
|
|
11
|
+
} & BaseRectMarkProps;
|
|
12
|
+
/** For arbitrary rectangles, requires quantitative x and y scales */
|
|
13
|
+
declare const Rect: import("svelte").Component<RectMarkProps, {}, "">;
|
|
14
|
+
type Rect = ReturnType<typeof Rect>;
|
|
15
|
+
export default Rect;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Rect from './Rect.svelte';
|
|
3
|
+
import { intervalY, stackX, recordizeX } from '../index.js';
|
|
4
|
+
import type {
|
|
5
|
+
DataRecord,
|
|
6
|
+
BaseMarkProps,
|
|
7
|
+
ChannelAccessor,
|
|
8
|
+
BaseRectMarkProps,
|
|
9
|
+
PlotContext
|
|
10
|
+
} from '../types.js';
|
|
11
|
+
import type { StackOptions } from '../transforms/stack.js';
|
|
12
|
+
import { getContext } from 'svelte';
|
|
13
|
+
|
|
14
|
+
type RectXMarkProps = BaseMarkProps & {
|
|
15
|
+
data: DataRecord[];
|
|
16
|
+
x?: ChannelAccessor;
|
|
17
|
+
x1?: ChannelAccessor;
|
|
18
|
+
x2?: ChannelAccessor;
|
|
19
|
+
y1?: ChannelAccessor;
|
|
20
|
+
y2?: ChannelAccessor;
|
|
21
|
+
stack?: StackOptions;
|
|
22
|
+
interval?: number | string;
|
|
23
|
+
} & BaseRectMarkProps;
|
|
24
|
+
|
|
25
|
+
let { data = [{}], stack, ...options }: RectXMarkProps = $props();
|
|
26
|
+
|
|
27
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
28
|
+
let plot = $derived(getPlotState());
|
|
29
|
+
|
|
30
|
+
const args = $derived(stackX(intervalY(recordizeX({ data, ...options }), { plot }), stack));
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<Rect {...args}></Rect>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DataRecord, BaseMarkProps, ChannelAccessor, BaseRectMarkProps } from '../types.js';
|
|
2
|
+
import type { StackOptions } from '../transforms/stack.js';
|
|
3
|
+
type RectXMarkProps = BaseMarkProps & {
|
|
4
|
+
data: DataRecord[];
|
|
5
|
+
x?: ChannelAccessor;
|
|
6
|
+
x1?: ChannelAccessor;
|
|
7
|
+
x2?: ChannelAccessor;
|
|
8
|
+
y1?: ChannelAccessor;
|
|
9
|
+
y2?: ChannelAccessor;
|
|
10
|
+
stack?: StackOptions;
|
|
11
|
+
interval?: number | string;
|
|
12
|
+
} & BaseRectMarkProps;
|
|
13
|
+
declare const RectX: import("svelte").Component<RectXMarkProps, {}, "">;
|
|
14
|
+
type RectX = ReturnType<typeof RectX>;
|
|
15
|
+
export default RectX;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Rect from './Rect.svelte';
|
|
3
|
+
import { intervalX, stackY, recordizeY } from '../index.js';
|
|
4
|
+
import type { StackOptions } from '../transforms/stack.js';
|
|
5
|
+
import type {
|
|
6
|
+
DataRecord,
|
|
7
|
+
BaseMarkProps,
|
|
8
|
+
ChannelAccessor,
|
|
9
|
+
BaseRectMarkProps,
|
|
10
|
+
PlotContext
|
|
11
|
+
} from '../types.js';
|
|
12
|
+
import { getContext } from 'svelte';
|
|
13
|
+
|
|
14
|
+
type RectYMarkProps = BaseMarkProps & {
|
|
15
|
+
data: DataRecord[];
|
|
16
|
+
y?: ChannelAccessor;
|
|
17
|
+
y1?: ChannelAccessor;
|
|
18
|
+
y2?: ChannelAccessor;
|
|
19
|
+
x1?: ChannelAccessor;
|
|
20
|
+
x2?: ChannelAccessor;
|
|
21
|
+
stack?: StackOptions;
|
|
22
|
+
interval?: number | string;
|
|
23
|
+
} & BaseRectMarkProps;
|
|
24
|
+
|
|
25
|
+
let { data = [{}], stack, ...options }: RectYMarkProps = $props();
|
|
26
|
+
|
|
27
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
28
|
+
const plot = $derived(getPlotState());
|
|
29
|
+
|
|
30
|
+
const args = $derived(stackY(intervalX(recordizeY({ data, ...options }), { plot }), stack));
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<Rect {...args}></Rect>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StackOptions } from '../transforms/stack.js';
|
|
2
|
+
import type { DataRecord, BaseMarkProps, ChannelAccessor, BaseRectMarkProps } from '../types.js';
|
|
3
|
+
type RectYMarkProps = BaseMarkProps & {
|
|
4
|
+
data: DataRecord[];
|
|
5
|
+
y?: ChannelAccessor;
|
|
6
|
+
y1?: ChannelAccessor;
|
|
7
|
+
y2?: ChannelAccessor;
|
|
8
|
+
x1?: ChannelAccessor;
|
|
9
|
+
x2?: ChannelAccessor;
|
|
10
|
+
stack?: StackOptions;
|
|
11
|
+
interval?: number | string;
|
|
12
|
+
} & BaseRectMarkProps;
|
|
13
|
+
declare const RectY: import("svelte").Component<RectYMarkProps, {}, "">;
|
|
14
|
+
type RectY = ReturnType<typeof RectY>;
|
|
15
|
+
export default RectY;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { resolveChannel } from '../helpers/resolve.js';
|
|
3
|
+
import type { ChannelName } from '../types.js';
|
|
4
|
+
import Mark from '../Mark.svelte';
|
|
5
|
+
import Regression, { type RegressionMarkProps } from './helpers/Regression.svelte';
|
|
6
|
+
import { groups as d3Groups } from 'd3-array';
|
|
7
|
+
|
|
8
|
+
let { data = [{}], ...options }: RegressionMarkProps = $props();
|
|
9
|
+
|
|
10
|
+
let groupBy: ChannelName | null =
|
|
11
|
+
options.stroke != null ? 'stroke' : options.z != null ? 'z' : null;
|
|
12
|
+
// separate groups
|
|
13
|
+
let groups = $derived(
|
|
14
|
+
groupBy !== null
|
|
15
|
+
? d3Groups(data, (d) => resolveChannel(groupBy as ChannelName, d, options)).map(
|
|
16
|
+
(g) => g[1]
|
|
17
|
+
)
|
|
18
|
+
: [data]
|
|
19
|
+
);
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<Mark type="regression">
|
|
23
|
+
{#each groups as group}
|
|
24
|
+
<Regression data={group} dependent="x" {...options} />
|
|
25
|
+
{/each}
|
|
26
|
+
</Mark>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { resolveChannel } from '../helpers/resolve.js';
|
|
3
|
+
import type { ChannelName } from '../types.js';
|
|
4
|
+
import Mark from '../Mark.svelte';
|
|
5
|
+
import Regression, { type RegressionMarkProps } from './helpers/Regression.svelte';
|
|
6
|
+
import { groups as d3Groups } from 'd3-array';
|
|
7
|
+
|
|
8
|
+
let { data = [{}], ...options }: RegressionMarkProps = $props();
|
|
9
|
+
|
|
10
|
+
let groupBy: ChannelName | null =
|
|
11
|
+
options.stroke != null ? 'stroke' : options.z != null ? 'z' : null;
|
|
12
|
+
// separate groups
|
|
13
|
+
let groups = $derived(
|
|
14
|
+
groupBy !== null
|
|
15
|
+
? d3Groups(data, (d) => resolveChannel(groupBy as ChannelName, d, options)).map(
|
|
16
|
+
(g) => g[1]
|
|
17
|
+
)
|
|
18
|
+
: [data]
|
|
19
|
+
);
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<Mark type="regression">
|
|
23
|
+
{#each groups as group}
|
|
24
|
+
<Regression data={group} dependent="y" {...options} />
|
|
25
|
+
{/each}
|
|
26
|
+
</Mark>
|
package/dist/marks/RuleX.svelte
CHANGED
|
@@ -1,30 +1,54 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Mark from '../Mark.svelte';
|
|
3
|
+
import GroupMultiple from './helpers/GroupMultiple.svelte';
|
|
4
|
+
import { getContext } from 'svelte';
|
|
5
|
+
import { recordizeX } from '../transforms/recordize.js';
|
|
6
|
+
import { resolveProp, resolveStyles } from '../helpers/resolve.js';
|
|
7
|
+
import type {
|
|
8
|
+
PlotContext,
|
|
9
|
+
DataRecord,
|
|
10
|
+
BaseMarkProps,
|
|
11
|
+
ConstantAccessor,
|
|
12
|
+
ChannelAccessor
|
|
13
|
+
} from '../types.js';
|
|
14
|
+
|
|
15
|
+
type RuleXMarkProps = BaseMarkProps & {
|
|
16
|
+
data: DataRecord[];
|
|
17
|
+
x?: ChannelAccessor;
|
|
18
|
+
y1?: ChannelAccessor;
|
|
19
|
+
y2?: ChannelAccessor;
|
|
20
|
+
inset?: ConstantAccessor<number>;
|
|
21
|
+
insetTop?: ConstantAccessor<number>;
|
|
22
|
+
insetBottom?: ConstantAccessor<number>;
|
|
23
|
+
dx?: ConstantAccessor<number>;
|
|
24
|
+
dy?: ConstantAccessor<number>;
|
|
25
|
+
};
|
|
10
26
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
y1={y1 != null ? plot.yScale(resolveChannel('y', datum, y1)) : plot.margins.top}
|
|
18
|
-
y2={y2 != null
|
|
19
|
-
? plot.yScale(resolveChannel('y', datum, y2))
|
|
20
|
-
: plot.plotHeight + plot.margins.top}
|
|
21
|
-
/>
|
|
22
|
-
{/each}
|
|
23
|
-
</g>
|
|
24
|
-
</BaseMark_RuleX>
|
|
27
|
+
let { data = [{}], class: className = null, ...options }: RuleXMarkProps = $props();
|
|
28
|
+
|
|
29
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
30
|
+
const plot = $derived(getPlotState());
|
|
31
|
+
const args = $derived(recordizeX({ data, ...options }, { withIndex: false }));
|
|
32
|
+
</script>
|
|
25
33
|
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
<Mark type="ruleX" channels={['x', 'y1', 'y2', 'stroke', 'opacity', 'strokeOpacity']} {...args}>
|
|
35
|
+
{#snippet children({ mark, scaledData, usedScales })}
|
|
36
|
+
<GroupMultiple class="rule-x {className || ''}" length={className ? 2 : scaledData.length}>
|
|
37
|
+
{#each scaledData as d}
|
|
38
|
+
{@const inset = resolveProp(args.inset, d.datum, 0)}
|
|
39
|
+
{@const insetTop = resolveProp(args.insetTop, d.datum, 0)}
|
|
40
|
+
{@const insetBottom = resolveProp(args.insetBottom, d.datum, 0)}
|
|
41
|
+
{@const dx = resolveProp(args.dx, d.datum, 0)}
|
|
42
|
+
{@const dy = resolveProp(args.dy, d.datum, 0)}
|
|
43
|
+
{@const [style, styleClass] = resolveStyles(plot, d, args, 'stroke', usedScales)}
|
|
44
|
+
<line
|
|
45
|
+
transform="translate({d.x + dx}, {dy})"
|
|
46
|
+
{style}
|
|
47
|
+
class={[styleClass]}
|
|
48
|
+
y1={(inset || insetTop) + (d.y1 != null ? d.y1 : plot.options.marginTop)}
|
|
49
|
+
y2={(d.y2 != null ? d.y2 : plot.facetHeight + plot.options.marginTop) -
|
|
50
|
+
(inset || insetBottom)} />
|
|
51
|
+
{/each}
|
|
52
|
+
</GroupMultiple>
|
|
53
|
+
{/snippet}
|
|
54
|
+
</Mark>
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import type { DataRecord, BaseMarkProps, ConstantAccessor, ChannelAccessor } from '../types.js';
|
|
2
|
+
type RuleXMarkProps = BaseMarkProps & {
|
|
3
|
+
data: DataRecord[];
|
|
4
|
+
x?: ChannelAccessor;
|
|
5
|
+
y1?: ChannelAccessor;
|
|
6
|
+
y2?: ChannelAccessor;
|
|
7
|
+
inset?: ConstantAccessor<number>;
|
|
8
|
+
insetTop?: ConstantAccessor<number>;
|
|
9
|
+
insetBottom?: ConstantAccessor<number>;
|
|
10
|
+
dx?: ConstantAccessor<number>;
|
|
11
|
+
dy?: ConstantAccessor<number>;
|
|
9
12
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
export default class RuleX extends SvelteComponent<RuleXProps, RuleXEvents, RuleXSlots> {
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
13
|
+
declare const RuleX: import("svelte").Component<RuleXMarkProps, {}, "">;
|
|
14
|
+
type RuleX = ReturnType<typeof RuleX>;
|
|
15
|
+
export default RuleX;
|
package/dist/marks/RuleY.svelte
CHANGED
|
@@ -1,30 +1,54 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Mark from '../Mark.svelte';
|
|
3
|
+
import GroupMultiple from './helpers/GroupMultiple.svelte';
|
|
4
|
+
import { getContext } from 'svelte';
|
|
5
|
+
import { recordizeY } from '../transforms/recordize.js';
|
|
6
|
+
import { resolveProp, resolveStyles } from '../helpers/resolve.js';
|
|
7
|
+
import type {
|
|
8
|
+
PlotContext,
|
|
9
|
+
DataRecord,
|
|
10
|
+
BaseMarkProps,
|
|
11
|
+
ConstantAccessor,
|
|
12
|
+
ChannelAccessor
|
|
13
|
+
} from '../types.js';
|
|
14
|
+
|
|
15
|
+
type RuleYMarkProps = BaseMarkProps & {
|
|
16
|
+
data: DataRecord[];
|
|
17
|
+
y?: ChannelAccessor;
|
|
18
|
+
x1?: ChannelAccessor;
|
|
19
|
+
x2?: ChannelAccessor;
|
|
20
|
+
inset?: ConstantAccessor<number>;
|
|
21
|
+
insetLeft?: ConstantAccessor<number>;
|
|
22
|
+
insetRight?: ConstantAccessor<number>;
|
|
23
|
+
dx?: ConstantAccessor<number>;
|
|
24
|
+
dy?: ConstantAccessor<number>;
|
|
25
|
+
};
|
|
10
26
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
x1={x1 != null ? plot.xScale(resolveChannel('x', datum, x1)) : plot.margins.left}
|
|
18
|
-
x2={x2 != null
|
|
19
|
-
? plot.xScale(resolveChannel('x', datum, x2))
|
|
20
|
-
: plot.plotWidth + plot.margins.left}
|
|
21
|
-
/>
|
|
22
|
-
{/each}
|
|
23
|
-
</g>
|
|
24
|
-
</BaseMark_RuleY>
|
|
27
|
+
let { data = [{}], class: className = null, ...options }: RuleYMarkProps = $props();
|
|
28
|
+
|
|
29
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
30
|
+
const plot = $derived(getPlotState());
|
|
31
|
+
const args = $derived(recordizeY({ data, ...options }, { withIndex: false }));
|
|
32
|
+
</script>
|
|
25
33
|
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
<Mark type="ruleY" channels={['y', 'x1', 'x2', 'stroke', 'opacity', 'strokeOpacity']} {...args}>
|
|
35
|
+
{#snippet children({ scaledData, usedScales })}
|
|
36
|
+
<GroupMultiple class="rule-y {className || ''}" length={className ? 2 : args.data.length}>
|
|
37
|
+
{#each scaledData as d}
|
|
38
|
+
{@const inset = resolveProp(args.inset, d.datum, 0)}
|
|
39
|
+
{@const insetLeft = resolveProp(args.insetLeft, d.datum, 0)}
|
|
40
|
+
{@const insetRight = resolveProp(args.insetRight, d.datum, 0)}
|
|
41
|
+
{@const dx = resolveProp(args.dx, d.datum, 0)}
|
|
42
|
+
{@const dy = resolveProp(args.dy, d.datum, 0)}
|
|
43
|
+
{@const [style, styleClass] = resolveStyles(plot, d, args, 'stroke', usedScales)}
|
|
44
|
+
<line
|
|
45
|
+
transform="translate({dx}, {d.y + dy})"
|
|
46
|
+
{style}
|
|
47
|
+
class={[styleClass]}
|
|
48
|
+
x1={(inset || insetLeft) + (d.x1 != null ? d.x1 : plot.options.marginLeft)}
|
|
49
|
+
x2={(d.x2 != null ? d.x2 : plot.facetWidth + plot.options.marginLeft) -
|
|
50
|
+
(inset || insetRight)} />
|
|
51
|
+
{/each}
|
|
52
|
+
</GroupMultiple>
|
|
53
|
+
{/snippet}
|
|
54
|
+
</Mark>
|