svelteplot 0.8.1 → 0.9.0-pr-311.0
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/README.md +4 -3
- package/dist/Mark.svelte +1 -1
- package/dist/Mark.svelte.d.ts +6 -4
- package/dist/constants.d.ts +3 -1
- package/dist/constants.js +11 -2
- package/dist/core/Plot.svelte +4 -4
- package/dist/helpers/autoScales.d.ts +1 -1
- package/dist/helpers/callWithProps.d.ts +1 -3
- package/dist/helpers/callWithProps.js +5 -3
- package/dist/helpers/colors.d.ts +9 -12
- package/dist/helpers/facets.d.ts +1 -1
- package/dist/helpers/getBaseStyles.d.ts +2 -4
- package/dist/helpers/index.d.ts +3 -3
- package/dist/helpers/projection.js +7 -2
- package/dist/helpers/reduce.d.ts +1 -1
- package/dist/helpers/scales.d.ts +7 -7
- package/dist/helpers/symbols.d.ts +2 -2
- package/dist/helpers/time.d.ts +3 -3
- package/dist/helpers/typeChecks.d.ts +8 -8
- package/dist/hooks/usePlot.svelte.d.ts +51 -0
- package/dist/hooks/usePlot.svelte.js +90 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/marks/Area.svelte +3 -5
- package/dist/marks/Area.svelte.d.ts +6 -4
- package/dist/marks/AreaX.svelte.d.ts +7 -5
- package/dist/marks/Arrow.svelte +3 -5
- package/dist/marks/Arrow.svelte.d.ts +6 -4
- package/dist/marks/AxisX.svelte +2 -3
- package/dist/marks/AxisX.svelte.d.ts +7 -5
- package/dist/marks/AxisY.svelte +3 -4
- package/dist/marks/AxisY.svelte.d.ts +7 -5
- package/dist/marks/BarX.svelte +2 -4
- package/dist/marks/BarX.svelte.d.ts +6 -4
- package/dist/marks/BarY.svelte +2 -4
- package/dist/marks/BarY.svelte.d.ts +6 -4
- package/dist/marks/BollingerX.svelte.d.ts +2 -76
- package/dist/marks/BollingerY.svelte.d.ts +2 -76
- package/dist/marks/BoxX.svelte +4 -138
- package/dist/marks/BoxY.svelte +20 -137
- package/dist/marks/BoxY.svelte.d.ts +6 -64
- package/dist/marks/Brush.svelte +3 -3
- package/dist/marks/Brush.svelte.d.ts +1 -63
- package/dist/marks/Cell.svelte +2 -4
- package/dist/marks/Cell.svelte.d.ts +6 -4
- package/dist/marks/ColorLegend.svelte +2 -4
- package/dist/marks/CustomMark.svelte.d.ts +2 -84
- package/dist/marks/CustomMarkHTML.svelte +5 -10
- package/dist/marks/DifferenceY.svelte +3 -5
- package/dist/marks/DifferenceY.svelte.d.ts +1 -63
- package/dist/marks/Dot.svelte +4 -5
- package/dist/marks/Dot.svelte.d.ts +6 -4
- package/dist/marks/DotX.svelte.d.ts +7 -5
- package/dist/marks/DotY.svelte.d.ts +7 -5
- package/dist/marks/Frame.svelte +3 -9
- package/dist/marks/Frame.svelte.d.ts +7 -5
- package/dist/marks/Geo.svelte +5 -5
- package/dist/marks/Geo.svelte.d.ts +7 -4
- package/dist/marks/GridX.svelte +3 -10
- package/dist/marks/GridX.svelte.d.ts +6 -4
- package/dist/marks/GridY.svelte +3 -4
- package/dist/marks/GridY.svelte.d.ts +6 -4
- package/dist/marks/HTMLTooltip.svelte +5 -5
- package/dist/marks/Image.svelte.d.ts +2 -75
- package/dist/marks/Line.svelte +7 -6
- package/dist/marks/Line.svelte.d.ts +6 -4
- package/dist/marks/LineX.svelte.d.ts +8 -6
- package/dist/marks/LineY.svelte.d.ts +8 -6
- package/dist/marks/Link.svelte +2 -4
- package/dist/marks/Link.svelte.d.ts +6 -4
- package/dist/marks/Pointer.svelte +4 -4
- package/dist/marks/Rect.svelte +2 -4
- package/dist/marks/Rect.svelte.d.ts +6 -4
- package/dist/marks/RectX.svelte +4 -4
- package/dist/marks/RectY.svelte +4 -4
- package/dist/marks/RuleX.svelte +2 -4
- package/dist/marks/RuleX.svelte.d.ts +6 -4
- package/dist/marks/RuleY.svelte +2 -4
- package/dist/marks/RuleY.svelte.d.ts +6 -4
- package/dist/marks/Spike.svelte.d.ts +7 -5
- package/dist/marks/SymbolLegend.svelte +2 -4
- package/dist/marks/SymbolLegend.svelte.d.ts +17 -2
- package/dist/marks/Text.svelte.d.ts +6 -4
- package/dist/marks/TickX.svelte +2 -3
- package/dist/marks/TickX.svelte.d.ts +6 -4
- package/dist/marks/TickY.svelte +2 -3
- package/dist/marks/TickY.svelte.d.ts +6 -4
- package/dist/marks/Trail.svelte +161 -0
- package/dist/marks/Trail.svelte.d.ts +44 -0
- package/dist/marks/Vector.svelte +3 -4
- package/dist/marks/Vector.svelte.d.ts +6 -4
- package/dist/marks/WaffleX.svelte +3 -4
- package/dist/marks/WaffleX.svelte.d.ts +2 -85
- package/dist/marks/WaffleY.svelte +2 -4
- package/dist/marks/WaffleY.svelte.d.ts +2 -83
- package/dist/marks/helpers/AreaCanvas.svelte +2 -4
- package/dist/marks/helpers/Box.svelte +271 -0
- package/dist/marks/helpers/Box.svelte.d.ts +55 -0
- package/dist/marks/helpers/CanvasLayer.svelte +2 -4
- package/dist/marks/helpers/DotCanvas.svelte +3 -5
- package/dist/marks/helpers/GeoCanvas.svelte +2 -4
- package/dist/marks/helpers/LineCanvas.svelte +2 -4
- package/dist/marks/helpers/LinearGradientX.svelte +3 -4
- package/dist/marks/helpers/LinearGradientY.svelte +3 -4
- package/dist/marks/helpers/MarkerPath.svelte +4 -5
- package/dist/marks/helpers/MarkerPath.svelte.d.ts +2 -102
- package/dist/marks/helpers/MultilineText.svelte +4 -4
- package/dist/marks/helpers/RectPath.svelte +5 -6
- package/dist/marks/helpers/Regression.svelte +4 -8
- package/dist/marks/helpers/TrailCanvas.svelte +138 -0
- package/dist/marks/helpers/TrailCanvas.svelte.d.ts +40 -0
- package/dist/marks/helpers/events.d.ts +2 -2
- package/dist/marks/helpers/events.js +4 -4
- package/dist/marks/helpers/trail.d.ts +23 -0
- package/dist/marks/helpers/trail.js +372 -0
- package/dist/marks/index.d.ts +1 -0
- package/dist/marks/index.js +1 -0
- package/dist/transforms/bollinger.d.ts +1 -69
- package/dist/transforms/centroid.d.ts +1 -4
- package/dist/transforms/group.d.ts +4 -12
- package/dist/transforms/interval.d.ts +2 -128
- package/dist/transforms/normalize.d.ts +23 -0
- package/dist/transforms/recordize.d.ts +4 -7
- package/dist/transforms/select.d.ts +7 -448
- package/dist/transforms/sort.d.ts +5 -253
- package/dist/transforms/stack.d.ts +3 -23
- package/dist/transforms/window.d.ts +2 -134
- package/dist/types/mark.d.ts +2 -1
- package/dist/types/plot.d.ts +6 -1
- package/dist/ui/Spiral.svelte +4 -0
- package/package.json +25 -23
|
@@ -2,17 +2,16 @@
|
|
|
2
2
|
import type {
|
|
3
3
|
Mark,
|
|
4
4
|
BaseMarkProps,
|
|
5
|
-
PlotContext,
|
|
6
5
|
ScaledDataRecord,
|
|
7
6
|
UsedScales
|
|
8
7
|
} from '../../types/index.js';
|
|
9
8
|
import { resolveProp, resolveScaledStyleProps } from '../../helpers/resolve.js';
|
|
10
|
-
import { getContext } from 'svelte';
|
|
11
9
|
import { type Line } from 'd3-shape';
|
|
12
10
|
import CanvasLayer from './CanvasLayer.svelte';
|
|
13
11
|
import type { Attachment } from 'svelte/attachments';
|
|
14
12
|
import { devicePixelRatio } from 'svelte/reactivity/window';
|
|
15
13
|
import { resolveColor } from './canvas.js';
|
|
14
|
+
import { usePlot } from '../../hooks/usePlot.svelte.js';
|
|
16
15
|
|
|
17
16
|
let {
|
|
18
17
|
mark,
|
|
@@ -27,8 +26,7 @@
|
|
|
27
26
|
groupByKey?: unknown;
|
|
28
27
|
} = $props();
|
|
29
28
|
|
|
30
|
-
const
|
|
31
|
-
const plot = $derived(getPlotState());
|
|
29
|
+
const plot = usePlot();
|
|
32
30
|
|
|
33
31
|
function maybeOpacity(value: unknown) {
|
|
34
32
|
return value == null ? 1 : +value;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import type { RawValue } from '../../index.js';
|
|
3
|
+
import { usePlot } from '../../hooks/usePlot.svelte.js';
|
|
4
4
|
|
|
5
5
|
let {
|
|
6
6
|
id,
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
stops: { x: RawValue; color: string }[];
|
|
11
11
|
} = $props();
|
|
12
12
|
|
|
13
|
-
const
|
|
14
|
-
const plot = $derived(getPlotState());
|
|
13
|
+
const plot = usePlot();
|
|
15
14
|
|
|
16
15
|
const projectedStops = $derived(
|
|
17
16
|
stops
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import type { RawValue } from '../../index.js';
|
|
3
|
+
import { usePlot } from '../../hooks/usePlot.svelte.js';
|
|
4
4
|
|
|
5
5
|
let {
|
|
6
6
|
id,
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
stops: { y: RawValue; color: string }[];
|
|
11
11
|
} = $props();
|
|
12
12
|
|
|
13
|
-
const
|
|
14
|
-
const plot = $derived(getPlotState());
|
|
13
|
+
const plot = usePlot();
|
|
15
14
|
|
|
16
15
|
const projectedStops = $derived(
|
|
17
16
|
stops
|
|
@@ -11,11 +11,10 @@
|
|
|
11
11
|
ConstantAccessor,
|
|
12
12
|
DataRecord,
|
|
13
13
|
Mark,
|
|
14
|
-
PlotContext,
|
|
15
14
|
PlotScales
|
|
16
15
|
} from '../../types/index.js';
|
|
17
16
|
import { addEventHandlers } from './events.js';
|
|
18
|
-
import {
|
|
17
|
+
import { usePlot } from '../../hooks/usePlot.svelte.js';
|
|
19
18
|
|
|
20
19
|
type MarkerPathProps = BaseMarkProps<Datum> & {
|
|
21
20
|
/**
|
|
@@ -78,7 +77,7 @@
|
|
|
78
77
|
|
|
79
78
|
const id = randomId();
|
|
80
79
|
|
|
81
|
-
const
|
|
80
|
+
const plot = usePlot();
|
|
82
81
|
|
|
83
82
|
const points = $derived(text && d != null ? d.split(/[LMC]/).slice(1) : []);
|
|
84
83
|
const hasPath = $derived(points.length > 0);
|
|
@@ -96,7 +95,7 @@
|
|
|
96
95
|
class={className}
|
|
97
96
|
stroke-width={strokeWidth_}
|
|
98
97
|
{@attach addEventHandlers({
|
|
99
|
-
|
|
98
|
+
plot,
|
|
100
99
|
options: mark.options,
|
|
101
100
|
datum: datum
|
|
102
101
|
})}>
|
|
@@ -127,7 +126,7 @@
|
|
|
127
126
|
{d}
|
|
128
127
|
{style}
|
|
129
128
|
{@attach addEventHandlers({
|
|
130
|
-
|
|
129
|
+
plot,
|
|
131
130
|
options: mark.options,
|
|
132
131
|
datum: datum
|
|
133
132
|
})} />
|
|
@@ -1,106 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { BaseMarkProps, ConstantAccessor, DataRecord, Mark, PlotScales } from '../../types/index.js';
|
|
1
|
+
import type { DataRecord } from '../../types/index.js';
|
|
3
2
|
declare function $$render<Datum extends DataRecord>(): {
|
|
4
|
-
props:
|
|
5
|
-
filter: ConstantAccessor<boolean, Datum>;
|
|
6
|
-
facet: "auto" | "include" | "exclude";
|
|
7
|
-
fx: import("../../types/index.js").ChannelAccessor<Datum>;
|
|
8
|
-
fy: import("../../types/index.js").ChannelAccessor<Datum>;
|
|
9
|
-
dx: ConstantAccessor<number, Datum>;
|
|
10
|
-
dy: ConstantAccessor<number, Datum>;
|
|
11
|
-
dodgeX: import("../../transforms/dodge").DodgeXOptions;
|
|
12
|
-
dodgeY: import("../../transforms/dodge").DodgeYOptions;
|
|
13
|
-
fill: import("../../types/index.js").ChannelAccessor<Datum>;
|
|
14
|
-
fillOpacity: ConstantAccessor<number, Datum>;
|
|
15
|
-
sort: ((a: import("../../types/index.js").RawValue, b: import("../../types/index.js").RawValue) => number) | {
|
|
16
|
-
channel: string;
|
|
17
|
-
order?: "ascending" | "descending";
|
|
18
|
-
} | ConstantAccessor<import("../../types/index.js").RawValue, Datum>;
|
|
19
|
-
stroke: import("../../types/index.js").ChannelAccessor<Datum>;
|
|
20
|
-
strokeWidth: ConstantAccessor<number, Datum>;
|
|
21
|
-
strokeOpacity: ConstantAccessor<number, Datum>;
|
|
22
|
-
strokeLinejoin: ConstantAccessor<import("csstype").Property.StrokeLinejoin, Datum>;
|
|
23
|
-
strokeLinecap: ConstantAccessor<import("csstype").Property.StrokeLinecap, Datum>;
|
|
24
|
-
strokeMiterlimit: ConstantAccessor<number, Datum>;
|
|
25
|
-
opacity: import("../../types/index.js").ChannelAccessor<Datum>;
|
|
26
|
-
strokeDasharray: ConstantAccessor<string, Datum>;
|
|
27
|
-
strokeDashoffset: ConstantAccessor<number, Datum>;
|
|
28
|
-
mixBlendMode: ConstantAccessor<import("csstype").Property.MixBlendMode, Datum>;
|
|
29
|
-
clipPath: string;
|
|
30
|
-
imageFilter: ConstantAccessor<string, Datum>;
|
|
31
|
-
shapeRendering: ConstantAccessor<import("csstype").Property.ShapeRendering, Datum>;
|
|
32
|
-
paintOrder: ConstantAccessor<string, Datum>;
|
|
33
|
-
onclick: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
34
|
-
ondblclick: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
35
|
-
onmouseup: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
36
|
-
onmousedown: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
37
|
-
onmouseenter: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
38
|
-
onmousemove: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
39
|
-
onmouseleave: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
40
|
-
onmouseout: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
41
|
-
onmouseover: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
42
|
-
onpointercancel: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
43
|
-
onpointerdown: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
44
|
-
onpointerup: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
45
|
-
onpointerenter: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
46
|
-
onpointerleave: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
47
|
-
onpointermove: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
48
|
-
onpointerover: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
49
|
-
onpointerout: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
50
|
-
ondrag: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
51
|
-
ondrop: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
52
|
-
ondragstart: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
53
|
-
ondragenter: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
54
|
-
ondragleave: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
55
|
-
ondragover: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
56
|
-
ondragend: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
57
|
-
ontouchstart: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
58
|
-
ontouchmove: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
59
|
-
ontouchend: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
60
|
-
ontouchcancel: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
61
|
-
oncontextmenu: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
62
|
-
onwheel: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
63
|
-
class: string;
|
|
64
|
-
style: string;
|
|
65
|
-
cursor: ConstantAccessor<import("csstype").Property.Cursor, Datum>;
|
|
66
|
-
}> & {
|
|
67
|
-
/**
|
|
68
|
-
* the datum associated with this path, usually the first
|
|
69
|
-
* element of the data array group
|
|
70
|
-
*/
|
|
71
|
-
datum: Datum;
|
|
72
|
-
/**
|
|
73
|
-
* the marker shape to use at the start of the path, defaults to
|
|
74
|
-
* circle
|
|
75
|
-
*/
|
|
76
|
-
markerStart?: boolean | MarkerShape;
|
|
77
|
-
/**
|
|
78
|
-
* the marker shape to use at the middle of the path, defaults to circle
|
|
79
|
-
*/
|
|
80
|
-
markerMid?: boolean | MarkerShape;
|
|
81
|
-
/**
|
|
82
|
-
* the marker shape to use at the end of the path, defaults to circle
|
|
83
|
-
*/
|
|
84
|
-
markerEnd?: boolean | MarkerShape;
|
|
85
|
-
/**
|
|
86
|
-
* shorthand for setting all markers
|
|
87
|
-
*/
|
|
88
|
-
marker?: boolean | MarkerShape;
|
|
89
|
-
/**
|
|
90
|
-
* path string
|
|
91
|
-
*/
|
|
92
|
-
d: string;
|
|
93
|
-
style: string;
|
|
94
|
-
startOffset: string;
|
|
95
|
-
textStyle: string;
|
|
96
|
-
textStyleClass?: string | null;
|
|
97
|
-
text: string;
|
|
98
|
-
transform: string;
|
|
99
|
-
color: string;
|
|
100
|
-
strokeWidth: ConstantAccessor<number>;
|
|
101
|
-
mark: Mark<BaseMarkProps<Datum>>;
|
|
102
|
-
scales: PlotScales;
|
|
103
|
-
};
|
|
3
|
+
props: any;
|
|
104
4
|
exports: {};
|
|
105
5
|
bindings: "";
|
|
106
6
|
slots: {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { resolveProp, resolveStyles } from '../../helpers/resolve';
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
3
|
+
import { type ComponentProps } from 'svelte';
|
|
4
|
+
import type { ScaledDataRecord, UsedScales } from '../../index.js';
|
|
5
5
|
import type Text from '../Text.svelte';
|
|
6
6
|
import { CSS_VAR } from '../../constants';
|
|
7
7
|
import { maybeFromPixel, maybeFromRem } from '../../helpers/getBaseStyles';
|
|
8
|
+
import { usePlot } from '../../hooks/usePlot.svelte.js';
|
|
8
9
|
|
|
9
10
|
const LINE_ANCHOR = {
|
|
10
11
|
bottom: 'auto',
|
|
@@ -12,8 +13,7 @@
|
|
|
12
13
|
top: 'hanging'
|
|
13
14
|
} as const;
|
|
14
15
|
|
|
15
|
-
const
|
|
16
|
-
const plot = $derived(getPlotState());
|
|
16
|
+
const plot = usePlot();
|
|
17
17
|
|
|
18
18
|
let {
|
|
19
19
|
textLines,
|
|
@@ -29,11 +29,11 @@ Helper component for rendering rectangular marks in SVG
|
|
|
29
29
|
import { resolveProp, resolveStyles } from '../../helpers/resolve';
|
|
30
30
|
import { roundedRect } from '../../helpers/roundedRect';
|
|
31
31
|
import { addEventHandlers } from './events.js';
|
|
32
|
-
import { getContext } from 'svelte';
|
|
33
32
|
import Anchor from './Anchor.svelte';
|
|
34
33
|
import type { BaseMarkProps, BaseRectMarkProps, BorderRadius } from '../../types/mark.js';
|
|
35
34
|
import type { DataRecord, ScaledDataRecord } from '../../types/data.js';
|
|
36
|
-
import type {
|
|
35
|
+
import type { UsedScales } from '../../types/index.js';
|
|
36
|
+
import { usePlot } from '../../hooks/usePlot.svelte.js';
|
|
37
37
|
|
|
38
38
|
let {
|
|
39
39
|
datum,
|
|
@@ -49,8 +49,7 @@ Helper component for rendering rectangular marks in SVG
|
|
|
49
49
|
fallbackStyle
|
|
50
50
|
}: RectPathProps = $props();
|
|
51
51
|
|
|
52
|
-
const
|
|
53
|
-
const plot = $derived(getPlotState());
|
|
52
|
+
const plot = usePlot();
|
|
54
53
|
|
|
55
54
|
const inset = $derived(+(resolveProp(options.inset, datum?.datum, 0) as number));
|
|
56
55
|
const insetLeft = $derived(
|
|
@@ -119,7 +118,7 @@ Helper component for rendering rectangular marks in SVG
|
|
|
119
118
|
class={[styleClass, className]}
|
|
120
119
|
{style}
|
|
121
120
|
{@attach addEventHandlers({
|
|
122
|
-
|
|
121
|
+
plot,
|
|
123
122
|
options,
|
|
124
123
|
datum: datum?.datum
|
|
125
124
|
})} />
|
|
@@ -131,7 +130,7 @@ Helper component for rendering rectangular marks in SVG
|
|
|
131
130
|
class={[styleClass, className]}
|
|
132
131
|
{style}
|
|
133
132
|
{@attach addEventHandlers({
|
|
134
|
-
|
|
133
|
+
plot,
|
|
135
134
|
options,
|
|
136
135
|
datum: datum?.datum
|
|
137
136
|
})} />
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
|
-
import type {
|
|
3
|
-
BaseMarkProps,
|
|
4
|
-
ChannelAccessor,
|
|
5
|
-
FacetContext,
|
|
6
|
-
PlotContext
|
|
7
|
-
} from '../../types/index.js';
|
|
2
|
+
import type { BaseMarkProps, ChannelAccessor, FacetContext } from '../../types/index.js';
|
|
8
3
|
|
|
9
4
|
type RegressionType = 'linear' | 'quad' | 'poly' | 'exp' | 'log' | 'pow' | 'loess';
|
|
10
5
|
|
|
@@ -65,8 +60,9 @@
|
|
|
65
60
|
throw new Error('unknown regression ' + name);
|
|
66
61
|
}
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
import { usePlot } from '../../hooks/usePlot.svelte.js';
|
|
64
|
+
|
|
65
|
+
const plot = usePlot();
|
|
70
66
|
|
|
71
67
|
let {
|
|
72
68
|
data,
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<script lang="ts" generics="Datum extends DataRecord">
|
|
2
|
+
import type {
|
|
3
|
+
Mark,
|
|
4
|
+
BaseMarkProps,
|
|
5
|
+
ScaledDataRecord,
|
|
6
|
+
UsedScales,
|
|
7
|
+
CurveName,
|
|
8
|
+
ConstantAccessor
|
|
9
|
+
} from '../../types/index.js';
|
|
10
|
+
import CanvasLayer from './CanvasLayer.svelte';
|
|
11
|
+
import type { Attachment } from 'svelte/attachments';
|
|
12
|
+
import { devicePixelRatio } from 'svelte/reactivity/window';
|
|
13
|
+
import { resolveColor } from './canvas.js';
|
|
14
|
+
import type { CurveFactory } from 'd3-shape';
|
|
15
|
+
import { trailPath, type TrailSample } from './trail';
|
|
16
|
+
import { resolveProp, resolveScaledStyleProps } from '../../helpers/resolve';
|
|
17
|
+
import { usePlot } from '../../hooks/usePlot.svelte.js';
|
|
18
|
+
|
|
19
|
+
interface TrailCanvasProps<Datum> {
|
|
20
|
+
curve?: CurveName | CurveFactory;
|
|
21
|
+
tension?: number;
|
|
22
|
+
cap?: 'butt' | 'round';
|
|
23
|
+
resolution?: number | 'auto';
|
|
24
|
+
data: ScaledDataRecord<Datum>[][];
|
|
25
|
+
usedScales: UsedScales;
|
|
26
|
+
options: {
|
|
27
|
+
fill?: ConstantAccessor<string, Datum>;
|
|
28
|
+
defined?: ConstantAccessor<boolean, Datum>;
|
|
29
|
+
opacity?: ConstantAccessor<number, Datum>;
|
|
30
|
+
'fill-opacity'?: ConstantAccessor<number, Datum>;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let {
|
|
35
|
+
curve,
|
|
36
|
+
cap,
|
|
37
|
+
tension,
|
|
38
|
+
resolution,
|
|
39
|
+
usedScales,
|
|
40
|
+
data: groupedTrailData,
|
|
41
|
+
options
|
|
42
|
+
}: TrailCanvasProps<Datum> = $props();
|
|
43
|
+
|
|
44
|
+
function maybeOpacity(value: unknown) {
|
|
45
|
+
return value == null ? 1 : +value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const plot = usePlot();
|
|
49
|
+
|
|
50
|
+
const render = ((canvas: HTMLCanvasElement) => {
|
|
51
|
+
const context = canvas.getContext('2d');
|
|
52
|
+
|
|
53
|
+
$effect(() => {
|
|
54
|
+
if (context) {
|
|
55
|
+
context.resetTransform();
|
|
56
|
+
context.scale(devicePixelRatio.current ?? 1, devicePixelRatio.current ?? 1);
|
|
57
|
+
|
|
58
|
+
for (const trailData of groupedTrailData) {
|
|
59
|
+
if (trailData.length < 2) continue;
|
|
60
|
+
|
|
61
|
+
// Get the first point to determine line styles
|
|
62
|
+
const firstPoint = trailData[0];
|
|
63
|
+
if (!firstPoint || !firstPoint.valid) continue;
|
|
64
|
+
|
|
65
|
+
const samples = trailData.map((d) => ({
|
|
66
|
+
x: Number(d.x),
|
|
67
|
+
y: Number(d.y),
|
|
68
|
+
r: Number(d.r ?? 0)
|
|
69
|
+
})) satisfies TrailSample[];
|
|
70
|
+
|
|
71
|
+
const defined = trailData.map(
|
|
72
|
+
(d) =>
|
|
73
|
+
d.valid &&
|
|
74
|
+
d.r >= 0 &&
|
|
75
|
+
(resolveProp(options.defined, d.datum, true) ?? true)
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
let { fill, ...restStyles } = resolveScaledStyleProps(
|
|
79
|
+
firstPoint.datum,
|
|
80
|
+
options,
|
|
81
|
+
usedScales,
|
|
82
|
+
plot,
|
|
83
|
+
'fill'
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const opacity = maybeOpacity(restStyles['opacity']);
|
|
87
|
+
const fillOpacity = maybeOpacity(restStyles['fill-opacity']);
|
|
88
|
+
|
|
89
|
+
fill = resolveColor(fill, canvas);
|
|
90
|
+
|
|
91
|
+
context.fillStyle = fill ? fill : 'currentColor';
|
|
92
|
+
context.beginPath();
|
|
93
|
+
|
|
94
|
+
trailPath(samples, defined, context, {
|
|
95
|
+
curve,
|
|
96
|
+
cap,
|
|
97
|
+
tension,
|
|
98
|
+
...(typeof resolution === 'number' ? { samplesPerSegment: resolution } : {})
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
context.globalAlpha = opacity * fillOpacity;
|
|
102
|
+
context.fill();
|
|
103
|
+
|
|
104
|
+
// {#each groupedTrailData as trailData, i (i)}
|
|
105
|
+
// {@const samples = trailData.map((d) => ({
|
|
106
|
+
// x: Number(d.x),
|
|
107
|
+
// y: Number(d.y),
|
|
108
|
+
// r: Number(d.r ?? 0)
|
|
109
|
+
// })) satisfies TrailSample[]}
|
|
110
|
+
// {@const defined = trailData.map(
|
|
111
|
+
// (d) =>
|
|
112
|
+
// d.valid &&
|
|
113
|
+
// d.r >= 0 &&
|
|
114
|
+
// (resolveProp(options.defined, d.datum, true) ?? true)
|
|
115
|
+
// )}
|
|
116
|
+
// {@const pathString = trailPath(samples, defined, d3Path(), {
|
|
117
|
+
// curve,
|
|
118
|
+
// cap,
|
|
119
|
+
// tension,
|
|
120
|
+
// ...(typeof resolution === 'number'
|
|
121
|
+
// ? { samplesPerSegment: resolution }
|
|
122
|
+
// : {})
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return () => {
|
|
127
|
+
context?.clearRect(
|
|
128
|
+
0,
|
|
129
|
+
0,
|
|
130
|
+
plot.width * (devicePixelRatio.current ?? 1),
|
|
131
|
+
plot.height * (devicePixelRatio.current ?? 1)
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
}) as Attachment;
|
|
136
|
+
</script>
|
|
137
|
+
|
|
138
|
+
<CanvasLayer {@attach render} />
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ScaledDataRecord, UsedScales, CurveName, ConstantAccessor } from '../../types/index.js';
|
|
2
|
+
import type { CurveFactory } from 'd3-shape';
|
|
3
|
+
interface TrailCanvasProps<Datum> {
|
|
4
|
+
curve?: CurveName | CurveFactory;
|
|
5
|
+
tension?: number;
|
|
6
|
+
cap?: 'butt' | 'round';
|
|
7
|
+
resolution?: number | 'auto';
|
|
8
|
+
data: ScaledDataRecord<Datum>[][];
|
|
9
|
+
usedScales: UsedScales;
|
|
10
|
+
options: {
|
|
11
|
+
fill?: ConstantAccessor<string, Datum>;
|
|
12
|
+
defined?: ConstantAccessor<boolean, Datum>;
|
|
13
|
+
opacity?: ConstantAccessor<number, Datum>;
|
|
14
|
+
'fill-opacity'?: ConstantAccessor<number, Datum>;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
declare function $$render<Datum extends DataRecord>(): {
|
|
18
|
+
props: TrailCanvasProps<Datum>;
|
|
19
|
+
exports: {};
|
|
20
|
+
bindings: "";
|
|
21
|
+
slots: {};
|
|
22
|
+
events: {};
|
|
23
|
+
};
|
|
24
|
+
declare class __sveltets_Render<Datum extends DataRecord> {
|
|
25
|
+
props(): ReturnType<typeof $$render<Datum>>['props'];
|
|
26
|
+
events(): ReturnType<typeof $$render<Datum>>['events'];
|
|
27
|
+
slots(): ReturnType<typeof $$render<Datum>>['slots'];
|
|
28
|
+
bindings(): "";
|
|
29
|
+
exports(): {};
|
|
30
|
+
}
|
|
31
|
+
interface $$IsomorphicComponent {
|
|
32
|
+
new <Datum extends DataRecord>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Datum>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Datum>['props']>, ReturnType<__sveltets_Render<Datum>['events']>, ReturnType<__sveltets_Render<Datum>['slots']>> & {
|
|
33
|
+
$$bindings?: ReturnType<__sveltets_Render<Datum>['bindings']>;
|
|
34
|
+
} & ReturnType<__sveltets_Render<Datum>['exports']>;
|
|
35
|
+
<Datum extends DataRecord>(internal: unknown, props: ReturnType<__sveltets_Render<Datum>['props']> & {}): ReturnType<__sveltets_Render<Datum>['exports']>;
|
|
36
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
37
|
+
}
|
|
38
|
+
declare const TrailCanvas: $$IsomorphicComponent;
|
|
39
|
+
type TrailCanvas<Datum extends DataRecord> = InstanceType<typeof TrailCanvas<Datum>>;
|
|
40
|
+
export default TrailCanvas;
|
|
@@ -13,8 +13,8 @@ declare global {
|
|
|
13
13
|
* of the plot frame, regardless of which element triggered the event
|
|
14
14
|
*/
|
|
15
15
|
export declare function clientToLayerCoordinates(event: MouseEvent, plotBody: HTMLElement | null | undefined): [number, number];
|
|
16
|
-
export declare function addEventHandlers<T extends DataRow>({ options, datum,
|
|
16
|
+
export declare function addEventHandlers<T extends DataRow>({ options, datum, plot }: {
|
|
17
17
|
options: BaseMarkProps<T>;
|
|
18
18
|
datum: DataRecord;
|
|
19
|
-
|
|
19
|
+
plot: PlotState;
|
|
20
20
|
}): Attachment;
|
|
@@ -19,7 +19,7 @@ export function clientToLayerCoordinates(event, plotBody) {
|
|
|
19
19
|
// Calculate the coordinates relative to the plot body
|
|
20
20
|
return [event.clientX - plotBodyRect.left, event.clientY - plotBodyRect.top];
|
|
21
21
|
}
|
|
22
|
-
export function addEventHandlers({ options, datum,
|
|
22
|
+
export function addEventHandlers({ options, datum, plot }) {
|
|
23
23
|
const events = pick(options, [
|
|
24
24
|
'onclick',
|
|
25
25
|
'oncontextmenu',
|
|
@@ -57,7 +57,7 @@ export function addEventHandlers({ options, datum, getPlotState }) {
|
|
|
57
57
|
for (const [eventName, eventHandler] of Object.entries(events)) {
|
|
58
58
|
if (eventHandler) {
|
|
59
59
|
const wrappedHandler = (origEvent) => {
|
|
60
|
-
const { scales, body, options } =
|
|
60
|
+
const { scales, body, options: plotOptions } = plot;
|
|
61
61
|
if (origEvent instanceof MouseEvent || origEvent instanceof PointerEvent) {
|
|
62
62
|
let facetEl = origEvent.target;
|
|
63
63
|
while (facetEl &&
|
|
@@ -69,8 +69,8 @@ export function addEventHandlers({ options, datum, getPlotState }) {
|
|
|
69
69
|
facetEl = facetEl.parentElement;
|
|
70
70
|
}
|
|
71
71
|
const facetRect = (facetEl?.firstElementChild ?? body).getBoundingClientRect();
|
|
72
|
-
const relativeX = origEvent.clientX - facetRect.left + (
|
|
73
|
-
const relativeY = origEvent.clientY - facetRect.top + (
|
|
72
|
+
const relativeX = origEvent.clientX - facetRect.left + (plotOptions.marginLeft ?? 0);
|
|
73
|
+
const relativeY = origEvent.clientY - facetRect.top + (plotOptions.marginTop ?? 0);
|
|
74
74
|
if (scales.projection) {
|
|
75
75
|
const [x, y] = scales.projection.invert([relativeX, relativeY]);
|
|
76
76
|
origEvent.dataX = x;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Path } from 'd3-path';
|
|
2
|
+
import type { CurveName } from '../../types/index.js';
|
|
3
|
+
import type { CurveFactory } from 'd3-shape';
|
|
4
|
+
export type TrailContext = CanvasRenderingContext2D | Path;
|
|
5
|
+
export type TrailCurve = CurveName | CurveFactory;
|
|
6
|
+
export type TrailCap = 'round' | 'butt';
|
|
7
|
+
export type TrailOptions = {
|
|
8
|
+
curve?: TrailCurve;
|
|
9
|
+
samplesPerSegment?: number;
|
|
10
|
+
cap?: TrailCap;
|
|
11
|
+
tension?: number;
|
|
12
|
+
};
|
|
13
|
+
export type TrailSample = {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
r: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Draw a stroked capsule trail along successive points with varying widths.
|
|
20
|
+
* Adapted from Vega's trail mark implementation.
|
|
21
|
+
*/
|
|
22
|
+
export declare function trailPath(samples: TrailSample[], defined: boolean[], context: TrailContext, options?: TrailOptions): string | void;
|
|
23
|
+
export default trailPath;
|