layerchart 2.0.0-next.44 → 2.0.0-next.46
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 +1 -1
- package/dist/components/AnnotationLine.svelte +1 -1
- package/dist/components/AnnotationPoint.svelte +1 -1
- package/dist/components/AnnotationRange.svelte +16 -15
- package/dist/components/Arc.svelte +10 -10
- package/dist/components/Arc.svelte.d.ts +4 -4
- package/dist/components/Arc.svelte.test.d.ts +1 -0
- package/dist/components/Arc.svelte.test.js +868 -0
- package/dist/components/Area.svelte +9 -7
- package/dist/components/Axis.svelte +2 -1
- package/dist/components/Axis.svelte.d.ts +1 -0
- package/dist/components/Bar.svelte +3 -3
- package/dist/components/Bars.svelte +1 -1
- package/dist/components/Blur.svelte +3 -3
- package/dist/components/Bounds.svelte +1 -1
- package/dist/components/BrushContext.svelte +1 -1
- package/dist/components/Calendar.svelte +2 -2
- package/dist/components/Calendar.svelte.d.ts +1 -1
- package/dist/components/Chart.svelte +63 -137
- package/dist/components/Chart.svelte.d.ts +23 -88
- package/dist/components/ChartClipPath.svelte +1 -1
- package/dist/components/Circle.svelte +17 -8
- package/dist/components/Circle.svelte.d.ts +3 -0
- package/dist/components/ClipPath.svelte +4 -4
- package/dist/components/Connector.svelte +4 -4
- package/dist/components/Connector.svelte.d.ts +3 -3
- package/dist/components/Ellipse.svelte +7 -7
- package/dist/components/Frame.svelte +1 -1
- package/dist/components/GeoContext.svelte +4 -20
- package/dist/components/GeoContext.svelte.d.ts +2 -6
- package/dist/components/GeoEdgeFade.svelte +1 -1
- package/dist/components/GeoPath.svelte +42 -107
- package/dist/components/GeoPath.svelte.d.ts +5 -4
- package/dist/components/GeoPoint.svelte +5 -5
- package/dist/components/GeoSpline.svelte +2 -14
- package/dist/components/GeoSpline.svelte.d.ts +1 -1
- package/dist/components/GeoTile.svelte +7 -6
- package/dist/components/GeoVisible.svelte +1 -1
- package/dist/components/Graticule.svelte +4 -7
- package/dist/components/Graticule.svelte.d.ts +2 -1
- package/dist/components/Grid.svelte +1 -1
- package/dist/components/Group.svelte +8 -8
- package/dist/components/Highlight.svelte +18 -16
- package/dist/components/Hull.svelte +2 -2
- package/dist/components/Labels.svelte +1 -1
- package/dist/components/Legend.svelte +1 -1
- package/dist/components/Line.svelte +9 -7
- package/dist/components/LinearGradient.svelte +8 -7
- package/dist/components/MonthPath.svelte +5 -11
- package/dist/components/MonthPath.svelte.d.ts +2 -2
- package/dist/components/Pack.svelte +4 -6
- package/dist/components/Pack.svelte.d.ts +2 -4
- package/dist/components/Partition.svelte +4 -3
- package/dist/components/Partition.svelte.d.ts +2 -1
- package/dist/components/Path.svelte +344 -0
- package/dist/components/Path.svelte.d.ts +72 -0
- package/dist/components/Pattern.svelte +6 -6
- package/dist/components/Pie.svelte +2 -2
- package/dist/components/Pie.svelte.d.ts +1 -1
- package/dist/components/Point.svelte +1 -1
- package/dist/components/Points.svelte +1 -1
- package/dist/components/Polygon.svelte +8 -6
- package/dist/components/RadialGradient.svelte +7 -7
- package/dist/components/Rect.svelte +32 -10
- package/dist/components/Rect.svelte.d.ts +4 -1
- package/dist/components/Rule.svelte +1 -1
- package/dist/components/Sankey.svelte +1 -1
- package/dist/components/Spline.svelte +13 -337
- package/dist/components/Spline.svelte.d.ts +10 -73
- package/dist/components/Text.svelte +9 -7
- package/dist/components/Threshold.svelte +3 -3
- package/dist/components/TransformContext.svelte +10 -143
- package/dist/components/TransformControls.svelte +2 -2
- package/dist/components/TransformControls.svelte.d.ts +1 -1
- package/dist/components/Tree.svelte +4 -3
- package/dist/components/Tree.svelte.d.ts +2 -1
- package/dist/components/Treemap.svelte +4 -3
- package/dist/components/Treemap.svelte.d.ts +2 -1
- package/dist/components/Voronoi.svelte +5 -5
- package/dist/components/charts/ArcChart.svelte +14 -6
- package/dist/components/charts/ArcChart.svelte.d.ts +1 -1
- package/dist/components/charts/AreaChart.svelte +12 -6
- package/dist/components/charts/BarChart.svelte +12 -6
- package/dist/components/charts/DefaultTooltip.svelte +1 -1
- package/dist/components/charts/LineChart.svelte +12 -6
- package/dist/components/charts/PieChart.svelte +14 -6
- package/dist/components/charts/PieChart.svelte.d.ts +1 -1
- package/dist/components/charts/ScatterChart.svelte +11 -9
- package/dist/components/charts/types.d.ts +7 -6
- package/dist/components/index.d.ts +14 -12
- package/dist/components/index.js +14 -12
- package/dist/components/{layout → layers}/Canvas.svelte +13 -60
- package/dist/components/{layout → layers}/Canvas.svelte.d.ts +2 -32
- package/dist/components/{layout → layers}/Html.svelte +18 -3
- package/dist/components/{layout → layers}/Html.svelte.d.ts +7 -0
- package/dist/components/layers/Layer.svelte +85 -0
- package/dist/components/{layout → layers}/Layer.svelte.d.ts +7 -3
- package/dist/components/{layout → layers}/Svg.svelte +18 -3
- package/dist/components/{layout → layers}/Svg.svelte.d.ts +7 -0
- package/dist/components/{layout → layers}/WebGL.svelte +1 -1
- package/dist/components/{layout → layers}/WebGL.svelte.d.ts +3 -3
- package/dist/components/tests/TestHarness.svelte +76 -0
- package/dist/components/tests/TestHarness.svelte.d.ts +19 -0
- package/dist/components/tooltip/Tooltip.svelte +3 -3
- package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContext.svelte +13 -45
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +2 -14
- package/dist/components/tooltip/tooltipMetaContext.d.ts +2 -2
- package/dist/components/tooltip/tooltipMetaContext.js +2 -2
- package/dist/contexts/canvas.d.ts +33 -0
- package/dist/contexts/canvas.js +14 -0
- package/dist/contexts/chart.d.ts +84 -0
- package/dist/contexts/chart.js +10 -0
- package/dist/contexts/geo.d.ts +6 -0
- package/dist/contexts/geo.js +12 -0
- package/dist/contexts/index.d.ts +6 -0
- package/dist/contexts/index.js +6 -0
- package/dist/contexts/layer.d.ts +3 -0
- package/dist/contexts/layer.js +8 -0
- package/dist/contexts/settings.d.ts +4 -0
- package/dist/contexts/settings.js +10 -0
- package/dist/contexts/tooltip.d.ts +15 -0
- package/dist/contexts/tooltip.js +8 -0
- package/dist/contexts/transform.d.ts +95 -0
- package/dist/contexts/transform.js +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/states/settings.svelte.d.ts +12 -0
- package/dist/states/settings.svelte.js +10 -0
- package/dist/states/transform.svelte.d.ts +9 -0
- package/dist/states/transform.svelte.js +31 -0
- package/dist/utils/arcText.svelte.d.ts +1 -1
- package/dist/utils/canvas.d.ts +7 -3
- package/dist/utils/canvas.js +78 -11
- package/dist/utils/common.d.ts +8 -1
- package/dist/utils/common.js +9 -10
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/motion.svelte.js +0 -1
- package/dist/utils/rect.svelte.d.ts +1 -1
- package/dist/utils/rect.svelte.js +17 -9
- package/dist/utils/scales.svelte.js +2 -2
- package/dist/utils/string.d.ts +3 -1
- package/package.json +32 -54
- package/README.md +0 -41
- package/dist/components/layout/Layer.svelte +0 -41
- package/dist/docs/Blockquote.svelte +0 -17
- package/dist/docs/Blockquote.svelte.d.ts +0 -5
- package/dist/docs/Code.svelte +0 -80
- package/dist/docs/Code.svelte.d.ts +0 -14
- package/dist/docs/ConnectorSweepMenuField.svelte +0 -17
- package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +0 -7
- package/dist/docs/ConnectorTypeMenuField.svelte +0 -17
- package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +0 -7
- package/dist/docs/CurveMenuField.svelte +0 -44
- package/dist/docs/CurveMenuField.svelte.d.ts +0 -9
- package/dist/docs/GeoDebug.svelte +0 -60
- package/dist/docs/GeoDebug.svelte.d.ts +0 -4
- package/dist/docs/Header1.svelte +0 -16
- package/dist/docs/Header1.svelte.d.ts +0 -5
- package/dist/docs/Json.svelte +0 -36
- package/dist/docs/Json.svelte.d.ts +0 -10
- package/dist/docs/Layout.svelte +0 -21
- package/dist/docs/Layout.svelte.d.ts +0 -8
- package/dist/docs/Link.svelte +0 -9
- package/dist/docs/Link.svelte.d.ts +0 -5
- package/dist/docs/PathDataMenuField.svelte +0 -78
- package/dist/docs/PathDataMenuField.svelte.d.ts +0 -9
- package/dist/docs/Preview.svelte +0 -104
- package/dist/docs/Preview.svelte.d.ts +0 -13
- package/dist/docs/TilesetField.svelte +0 -136
- package/dist/docs/TilesetField.svelte.d.ts +0 -6
- package/dist/docs/TransformDebug.svelte +0 -22
- package/dist/docs/TransformDebug.svelte.d.ts +0 -20
- package/dist/docs/ViewSourceButton.svelte +0 -53
- package/dist/docs/ViewSourceButton.svelte.d.ts +0 -11
- package/dist/utils/graph/dagre.d.ts +0 -34
- /package/dist/{utils → contexts}/legendPayload.d.ts +0 -0
- /package/dist/{utils → contexts}/legendPayload.js +0 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { MarkerOptions } from './MarkerWrapper.svelte';
|
|
4
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
5
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
createControlledMotion,
|
|
9
|
+
createMotion,
|
|
10
|
+
extractTweenConfig,
|
|
11
|
+
type MotionProp,
|
|
12
|
+
type ResolvedMotion,
|
|
13
|
+
} from '../utils/motion.svelte.js';
|
|
14
|
+
|
|
15
|
+
export type PathPropsWithoutHTML = {
|
|
16
|
+
/**
|
|
17
|
+
* Pass `<path d={...} />` explicitly instead of calculating
|
|
18
|
+
* from data / context
|
|
19
|
+
*/
|
|
20
|
+
pathData?: string | undefined | null;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Whether to animate the drawing of the path over time.
|
|
24
|
+
* Pass either `true` or an object with transition options to
|
|
25
|
+
* enable the transition.
|
|
26
|
+
*
|
|
27
|
+
* Works best with `tweened` disabled.
|
|
28
|
+
*/
|
|
29
|
+
draw?: boolean | Parameters<typeof _drawTransition>[1];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Marker to attach to both start and end points of the line
|
|
33
|
+
*/
|
|
34
|
+
marker?: MarkerOptions;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Marker to attach to the middle point of the line
|
|
38
|
+
*/
|
|
39
|
+
markerMid?: MarkerOptions;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Marker to attach to the start point of the line
|
|
43
|
+
*/
|
|
44
|
+
markerStart?: MarkerOptions;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Marker to attach to the end point of the line
|
|
48
|
+
*/
|
|
49
|
+
markerEnd?: MarkerOptions;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Add additional content at the start of the line.
|
|
53
|
+
*
|
|
54
|
+
* Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
|
|
55
|
+
*/
|
|
56
|
+
startContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Add additional content at the end of the line.
|
|
60
|
+
*
|
|
61
|
+
* Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
|
|
62
|
+
*/
|
|
63
|
+
endContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A reference to the `<path>` element.
|
|
67
|
+
*
|
|
68
|
+
* @bindable
|
|
69
|
+
*/
|
|
70
|
+
pathRef?: SVGPathElement;
|
|
71
|
+
|
|
72
|
+
motion?: MotionProp;
|
|
73
|
+
} & CommonStyleProps;
|
|
74
|
+
|
|
75
|
+
export type PathProps = PathPropsWithoutHTML &
|
|
76
|
+
Without<SVGAttributes<SVGPathElement>, PathPropsWithoutHTML>;
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<script lang="ts">
|
|
80
|
+
import { tick } from 'svelte';
|
|
81
|
+
import { draw as _drawTransition } from 'svelte/transition';
|
|
82
|
+
import { cubicInOut } from 'svelte/easing';
|
|
83
|
+
import { merge } from '@layerstack/utils';
|
|
84
|
+
|
|
85
|
+
import { interpolatePath } from 'd3-interpolate-path';
|
|
86
|
+
import { cls } from '@layerstack/tailwind';
|
|
87
|
+
|
|
88
|
+
import Group from './Group.svelte';
|
|
89
|
+
import { flattenPathData } from '../utils/path.js';
|
|
90
|
+
import { registerCanvasComponent } from './layers/Canvas.svelte';
|
|
91
|
+
import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
92
|
+
import { getLayerContext } from '../contexts/layer.js';
|
|
93
|
+
import MarkerWrapper from './MarkerWrapper.svelte';
|
|
94
|
+
import { getChartContext } from '../contexts/chart.js';
|
|
95
|
+
import { createKey } from '../utils/key.svelte.js';
|
|
96
|
+
import { createId } from '../utils/createId.js';
|
|
97
|
+
|
|
98
|
+
const ctx = getChartContext();
|
|
99
|
+
|
|
100
|
+
const uid = $props.id();
|
|
101
|
+
|
|
102
|
+
let {
|
|
103
|
+
pathData,
|
|
104
|
+
x,
|
|
105
|
+
y,
|
|
106
|
+
motion,
|
|
107
|
+
draw,
|
|
108
|
+
fill,
|
|
109
|
+
stroke,
|
|
110
|
+
strokeWidth,
|
|
111
|
+
fillOpacity,
|
|
112
|
+
class: className,
|
|
113
|
+
marker,
|
|
114
|
+
markerStart: markerStartProp,
|
|
115
|
+
markerMid: markerMidProp,
|
|
116
|
+
markerEnd: markerEndProp,
|
|
117
|
+
startContent,
|
|
118
|
+
endContent,
|
|
119
|
+
opacity,
|
|
120
|
+
pathRef: pathRefProp = $bindable(),
|
|
121
|
+
...restProps
|
|
122
|
+
}: PathProps = $props();
|
|
123
|
+
|
|
124
|
+
let pathRef = $state<SVGPathElement>();
|
|
125
|
+
|
|
126
|
+
$effect.pre(() => {
|
|
127
|
+
pathRefProp = pathRef;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const markerStart = $derived(markerStartProp ?? marker);
|
|
131
|
+
const markerMid = $derived(markerMidProp ?? marker);
|
|
132
|
+
const markerEnd = $derived(markerEndProp ?? marker);
|
|
133
|
+
|
|
134
|
+
const markerStartId = $derived(markerStart ? createId('marker-start', uid) : '');
|
|
135
|
+
const markerMidId = $derived(markerMid ? createId('marker-mid', uid) : '');
|
|
136
|
+
const markerEndId = $derived(markerEnd ? createId('marker-end', uid) : '');
|
|
137
|
+
|
|
138
|
+
const extractedTween = extractTweenConfig(motion);
|
|
139
|
+
|
|
140
|
+
const tweenedOptions: ResolvedMotion | undefined = extractedTween
|
|
141
|
+
? {
|
|
142
|
+
type: extractedTween.type,
|
|
143
|
+
options: { interpolate: interpolatePath, ...extractedTween.options },
|
|
144
|
+
}
|
|
145
|
+
: undefined;
|
|
146
|
+
|
|
147
|
+
/** Provide initial `0` horizontal baseline and initially hide/untrack scale changes so not reactive (only set on initial mount) */
|
|
148
|
+
function defaultPathData() {
|
|
149
|
+
if (!tweenedOptions) {
|
|
150
|
+
// If not tweened, return empty string (faster initial render)
|
|
151
|
+
return '';
|
|
152
|
+
} else if (pathData) {
|
|
153
|
+
// Flatten all `y` coordinates of pre-defined `pathData`
|
|
154
|
+
return flattenPathData(pathData, Math.min(ctx.yScale(0) ?? ctx.yRange[0], ctx.yRange[0]));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const d = $derived.by(() => {
|
|
159
|
+
return pathData;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const tweenedState = createMotion(defaultPathData(), () => d, tweenedOptions);
|
|
163
|
+
|
|
164
|
+
const drawTransition = $derived(draw ? _drawTransition : () => ({}));
|
|
165
|
+
|
|
166
|
+
let key = $state(Symbol());
|
|
167
|
+
|
|
168
|
+
const layerCtx = getLayerContext();
|
|
169
|
+
|
|
170
|
+
function render(
|
|
171
|
+
ctx: CanvasRenderingContext2D,
|
|
172
|
+
styleOverrides: ComputedStylesOptions | undefined
|
|
173
|
+
) {
|
|
174
|
+
renderPathData(
|
|
175
|
+
ctx,
|
|
176
|
+
tweenedState.current,
|
|
177
|
+
styleOverrides
|
|
178
|
+
? merge({ styles: { strokeWidth } }, styleOverrides)
|
|
179
|
+
: {
|
|
180
|
+
styles: { fill, fillOpacity, stroke, strokeWidth, opacity },
|
|
181
|
+
classes: cls('lc-path', className),
|
|
182
|
+
style: restProps.style as string | undefined,
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// TODO: Use objectId to work around Svelte 4 reactivity issue (even when memoizing gradients)
|
|
188
|
+
const fillKey = createKey(() => fill);
|
|
189
|
+
const strokeKey = createKey(() => stroke);
|
|
190
|
+
|
|
191
|
+
if (layerCtx === 'canvas') {
|
|
192
|
+
registerCanvasComponent({
|
|
193
|
+
name: 'Path',
|
|
194
|
+
render,
|
|
195
|
+
events: {
|
|
196
|
+
click: restProps.onclick,
|
|
197
|
+
pointerenter: restProps.onpointerenter,
|
|
198
|
+
pointermove: restProps.onpointermove,
|
|
199
|
+
pointerleave: restProps.onpointerleave,
|
|
200
|
+
pointerdown: restProps.onpointerdown,
|
|
201
|
+
pointerover: restProps.onpointerover,
|
|
202
|
+
pointerout: restProps.onpointerout,
|
|
203
|
+
touchmove: restProps.ontouchmove,
|
|
204
|
+
},
|
|
205
|
+
deps: () => [
|
|
206
|
+
fillKey.current,
|
|
207
|
+
fillOpacity,
|
|
208
|
+
strokeKey.current,
|
|
209
|
+
strokeWidth,
|
|
210
|
+
opacity,
|
|
211
|
+
className,
|
|
212
|
+
tweenedState.current,
|
|
213
|
+
restProps.style,
|
|
214
|
+
],
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
let startPoint = $state<DOMPoint | undefined>();
|
|
219
|
+
|
|
220
|
+
const endPointDuration = $derived.by(() => {
|
|
221
|
+
if (
|
|
222
|
+
typeof draw === 'object' &&
|
|
223
|
+
draw.duration !== undefined &&
|
|
224
|
+
typeof draw.duration !== 'function'
|
|
225
|
+
) {
|
|
226
|
+
return draw.duration;
|
|
227
|
+
}
|
|
228
|
+
return 800;
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const endPoint = createControlledMotion<DOMPoint | undefined>(
|
|
232
|
+
undefined,
|
|
233
|
+
draw
|
|
234
|
+
? {
|
|
235
|
+
type: 'tween',
|
|
236
|
+
duration: () => endPointDuration,
|
|
237
|
+
easing: typeof draw === 'object' && draw.easing ? draw.easing : cubicInOut,
|
|
238
|
+
interpolate() {
|
|
239
|
+
return (t: number) => {
|
|
240
|
+
const totalLength = pathRef?.getTotalLength() ?? 0;
|
|
241
|
+
const point = pathRef?.getPointAtLength(totalLength * t);
|
|
242
|
+
return point;
|
|
243
|
+
};
|
|
244
|
+
},
|
|
245
|
+
}
|
|
246
|
+
: { type: 'none' }
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
$effect(() => {
|
|
250
|
+
if (!startContent && !endContent) return;
|
|
251
|
+
d;
|
|
252
|
+
if (!pathRef) return;
|
|
253
|
+
|
|
254
|
+
// Wait for DOM to update before querying path geometry
|
|
255
|
+
tick().then(() => {
|
|
256
|
+
if (!pathRef) return;
|
|
257
|
+
const totalLength = pathRef.getTotalLength();
|
|
258
|
+
if (!totalLength) return;
|
|
259
|
+
|
|
260
|
+
startPoint = pathRef.getPointAtLength(0);
|
|
261
|
+
endPoint.target = pathRef.getPointAtLength(totalLength);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
$effect(() => {
|
|
266
|
+
if (!draw) return;
|
|
267
|
+
// Anytime the path data changes, redraw
|
|
268
|
+
[pathData /*, data, ctx.data*/];
|
|
269
|
+
key = Symbol();
|
|
270
|
+
});
|
|
271
|
+
</script>
|
|
272
|
+
|
|
273
|
+
{#if layerCtx === 'svg'}
|
|
274
|
+
{#key key}
|
|
275
|
+
<path
|
|
276
|
+
d={tweenedState.current}
|
|
277
|
+
{...restProps}
|
|
278
|
+
class={cls('lc-path', className)}
|
|
279
|
+
{fill}
|
|
280
|
+
fill-opacity={fillOpacity}
|
|
281
|
+
{stroke}
|
|
282
|
+
stroke-width={strokeWidth}
|
|
283
|
+
{opacity}
|
|
284
|
+
marker-start={markerStartId ? `url(#${markerStartId})` : undefined}
|
|
285
|
+
marker-mid={markerMidId ? `url(#${markerMidId})` : undefined}
|
|
286
|
+
marker-end={markerEndId ? `url(#${markerEndId})` : undefined}
|
|
287
|
+
in:drawTransition|global={typeof draw === 'object' ? draw : undefined}
|
|
288
|
+
bind:this={pathRef}
|
|
289
|
+
/>
|
|
290
|
+
<MarkerWrapper id={markerStartId} marker={markerStart} />
|
|
291
|
+
<MarkerWrapper id={markerMidId} marker={markerMid} />
|
|
292
|
+
<MarkerWrapper id={markerEndId} marker={markerEnd} />
|
|
293
|
+
|
|
294
|
+
{#if startContent && startPoint}
|
|
295
|
+
<Group x={startPoint.x} y={startPoint.y} class="lc-path-g-start">
|
|
296
|
+
{@render startContent({
|
|
297
|
+
point: startPoint,
|
|
298
|
+
value: {
|
|
299
|
+
x: ctx.xScale?.invert?.(startPoint.x),
|
|
300
|
+
y: ctx.yScale?.invert?.(startPoint.y),
|
|
301
|
+
},
|
|
302
|
+
})}
|
|
303
|
+
</Group>
|
|
304
|
+
{/if}
|
|
305
|
+
|
|
306
|
+
{#if endContent && endPoint.current}
|
|
307
|
+
<Group x={endPoint.current.x} y={endPoint.current.y} class="lc-path-g-end">
|
|
308
|
+
{@render endContent({
|
|
309
|
+
point: endPoint.current,
|
|
310
|
+
value: {
|
|
311
|
+
x: ctx.xScale?.invert?.(endPoint.current.x),
|
|
312
|
+
y: ctx.yScale?.invert?.(endPoint.current.y),
|
|
313
|
+
},
|
|
314
|
+
})}
|
|
315
|
+
</Group>
|
|
316
|
+
{/if}
|
|
317
|
+
{/key}
|
|
318
|
+
{/if}
|
|
319
|
+
|
|
320
|
+
<style>
|
|
321
|
+
@layer base {
|
|
322
|
+
:global(:where(.lc-path)) {
|
|
323
|
+
/* Use transparent to enable pointer events */
|
|
324
|
+
--fill-color: transparent;
|
|
325
|
+
--stroke-color: var(--color-surface-content, currentColor);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/* Svg | Canvas layers */
|
|
329
|
+
:global(:where(.lc-layout-svg .lc-path, svg.lc-path):not([fill])) {
|
|
330
|
+
fill: var(--fill-color);
|
|
331
|
+
}
|
|
332
|
+
:global(:where(.lc-layout-svg .lc-path, svg.lc-path):not([stroke])) {
|
|
333
|
+
stroke: var(--stroke-color);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/* Html layers */
|
|
337
|
+
:global(:where(.lc-layout-html .lc-path):not([background-color])) {
|
|
338
|
+
background-color: var(--fill-color);
|
|
339
|
+
}
|
|
340
|
+
:global(:where(.lc-layout-html .lc-path):not([border-color])) {
|
|
341
|
+
border-color: var(--stroke-color);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
</style>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { MarkerOptions } from './MarkerWrapper.svelte';
|
|
3
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
4
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
5
|
+
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
6
|
+
export type PathPropsWithoutHTML = {
|
|
7
|
+
/**
|
|
8
|
+
* Pass `<path d={...} />` explicitly instead of calculating
|
|
9
|
+
* from data / context
|
|
10
|
+
*/
|
|
11
|
+
pathData?: string | undefined | null;
|
|
12
|
+
/**
|
|
13
|
+
* Whether to animate the drawing of the path over time.
|
|
14
|
+
* Pass either `true` or an object with transition options to
|
|
15
|
+
* enable the transition.
|
|
16
|
+
*
|
|
17
|
+
* Works best with `tweened` disabled.
|
|
18
|
+
*/
|
|
19
|
+
draw?: boolean | Parameters<typeof _drawTransition>[1];
|
|
20
|
+
/**
|
|
21
|
+
* Marker to attach to both start and end points of the line
|
|
22
|
+
*/
|
|
23
|
+
marker?: MarkerOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Marker to attach to the middle point of the line
|
|
26
|
+
*/
|
|
27
|
+
markerMid?: MarkerOptions;
|
|
28
|
+
/**
|
|
29
|
+
* Marker to attach to the start point of the line
|
|
30
|
+
*/
|
|
31
|
+
markerStart?: MarkerOptions;
|
|
32
|
+
/**
|
|
33
|
+
* Marker to attach to the end point of the line
|
|
34
|
+
*/
|
|
35
|
+
markerEnd?: MarkerOptions;
|
|
36
|
+
/**
|
|
37
|
+
* Add additional content at the start of the line.
|
|
38
|
+
*
|
|
39
|
+
* Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
|
|
40
|
+
*/
|
|
41
|
+
startContent?: Snippet<[{
|
|
42
|
+
point: DOMPoint;
|
|
43
|
+
value: {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
};
|
|
47
|
+
}]>;
|
|
48
|
+
/**
|
|
49
|
+
* Add additional content at the end of the line.
|
|
50
|
+
*
|
|
51
|
+
* Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
|
|
52
|
+
*/
|
|
53
|
+
endContent?: Snippet<[{
|
|
54
|
+
point: DOMPoint;
|
|
55
|
+
value: {
|
|
56
|
+
x: number;
|
|
57
|
+
y: number;
|
|
58
|
+
};
|
|
59
|
+
}]>;
|
|
60
|
+
/**
|
|
61
|
+
* A reference to the `<path>` element.
|
|
62
|
+
*
|
|
63
|
+
* @bindable
|
|
64
|
+
*/
|
|
65
|
+
pathRef?: SVGPathElement;
|
|
66
|
+
motion?: MotionProp;
|
|
67
|
+
} & CommonStyleProps;
|
|
68
|
+
export type PathProps = PathPropsWithoutHTML & Without<SVGAttributes<SVGPathElement>, PathPropsWithoutHTML>;
|
|
69
|
+
import { draw as _drawTransition } from 'svelte/transition';
|
|
70
|
+
declare const Path: import("svelte").Component<PathProps, {}, "pathRef">;
|
|
71
|
+
type Path = ReturnType<typeof Path>;
|
|
72
|
+
export default Path;
|
|
@@ -125,8 +125,8 @@
|
|
|
125
125
|
</script>
|
|
126
126
|
|
|
127
127
|
<script lang="ts">
|
|
128
|
-
import {
|
|
129
|
-
import { registerCanvasComponent } from './
|
|
128
|
+
import { getLayerContext } from '../contexts/layer.js';
|
|
129
|
+
import { registerCanvasComponent } from './layers/Canvas.svelte';
|
|
130
130
|
import { createPattern } from '../utils/canvas.js';
|
|
131
131
|
|
|
132
132
|
const uid = $props.id();
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
...restProps
|
|
145
145
|
}: PatternProps = $props();
|
|
146
146
|
|
|
147
|
-
const
|
|
147
|
+
const layerCtx = getLayerContext();
|
|
148
148
|
|
|
149
149
|
let canvasPattern = $state<CanvasPattern | null>(null);
|
|
150
150
|
|
|
@@ -247,7 +247,7 @@
|
|
|
247
247
|
canvasPattern = pattern;
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
if (
|
|
250
|
+
if (layerCtx === 'canvas') {
|
|
251
251
|
registerCanvasComponent({
|
|
252
252
|
name: 'Pattern',
|
|
253
253
|
render,
|
|
@@ -256,9 +256,9 @@
|
|
|
256
256
|
}
|
|
257
257
|
</script>
|
|
258
258
|
|
|
259
|
-
{#if
|
|
259
|
+
{#if layerCtx === 'canvas'}
|
|
260
260
|
{@render children?.({ id, pattern: asAny(canvasPattern) })}
|
|
261
|
-
{:else if
|
|
261
|
+
{:else if layerCtx === 'svg'}
|
|
262
262
|
<defs>
|
|
263
263
|
<pattern
|
|
264
264
|
{id}
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
import Arc from './Arc.svelte';
|
|
79
79
|
import { degreesToRadians } from '../utils/math.js';
|
|
80
80
|
import { createMotion, type MotionProp } from '../utils/motion.svelte.js';
|
|
81
|
-
import type { TooltipContextValue } from '
|
|
82
|
-
import { getChartContext } from '
|
|
81
|
+
import type { TooltipContextValue } from '../contexts/tooltip.js';
|
|
82
|
+
import { getChartContext } from '../contexts/chart.js';
|
|
83
83
|
import type { Snippet } from 'svelte';
|
|
84
84
|
|
|
85
85
|
/*
|
|
@@ -59,7 +59,7 @@ export type PiePropsWithoutHTML = {
|
|
|
59
59
|
motion?: MotionProp;
|
|
60
60
|
};
|
|
61
61
|
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
62
|
-
import type { TooltipContextValue } from '
|
|
62
|
+
import type { TooltipContextValue } from '../contexts/tooltip.js';
|
|
63
63
|
import type { Snippet } from 'svelte';
|
|
64
64
|
declare const Pie: import("svelte").Component<PiePropsWithoutHTML, {}, "">;
|
|
65
65
|
type Pie = ReturnType<typeof Pie>;
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
import Circle, { type CircleProps } from './Circle.svelte';
|
|
51
51
|
import { isScaleBand, type AnyScale } from '../utils/scales.svelte.js';
|
|
52
52
|
import { accessor, type Accessor } from '../utils/common.js';
|
|
53
|
-
import { getChartContext } from '
|
|
53
|
+
import { getChartContext } from '../contexts/chart.js';
|
|
54
54
|
import { extractLayerProps } from '../utils/attributes.js';
|
|
55
55
|
|
|
56
56
|
const ctx = getChartContext();
|
|
@@ -131,17 +131,17 @@
|
|
|
131
131
|
<script lang="ts">
|
|
132
132
|
import type { SVGAttributes } from 'svelte/elements';
|
|
133
133
|
import { cls } from '@layerstack/tailwind';
|
|
134
|
-
import { merge } from '
|
|
134
|
+
import { merge } from '@layerstack/utils';
|
|
135
135
|
import { interpolatePath } from 'd3-interpolate-path';
|
|
136
136
|
|
|
137
|
-
import {
|
|
137
|
+
import { getLayerContext } from '../contexts/layer.js';
|
|
138
138
|
import {
|
|
139
139
|
createMotion,
|
|
140
140
|
extractTweenConfig,
|
|
141
141
|
type MotionProp,
|
|
142
142
|
type ResolvedMotion,
|
|
143
143
|
} from '../utils/motion.svelte.js';
|
|
144
|
-
import { registerCanvasComponent } from './
|
|
144
|
+
import { registerCanvasComponent } from './layers/Canvas.svelte';
|
|
145
145
|
import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
146
146
|
import { createKey } from '../utils/key.svelte.js';
|
|
147
147
|
import { polygon } from '../utils/shape.js';
|
|
@@ -220,7 +220,7 @@
|
|
|
220
220
|
|
|
221
221
|
const tweenedState = createMotion(null, () => d, tweenedOptions);
|
|
222
222
|
|
|
223
|
-
const
|
|
223
|
+
const layerCtx = getLayerContext();
|
|
224
224
|
|
|
225
225
|
function render(
|
|
226
226
|
ctx: CanvasRenderingContext2D,
|
|
@@ -234,6 +234,7 @@
|
|
|
234
234
|
: {
|
|
235
235
|
styles: { fill, fillOpacity, stroke, strokeWidth, opacity },
|
|
236
236
|
classes: cls('lc-polygon', className),
|
|
237
|
+
style: restProps.style as string | undefined,
|
|
237
238
|
}
|
|
238
239
|
);
|
|
239
240
|
}
|
|
@@ -242,7 +243,7 @@
|
|
|
242
243
|
const fillKey = createKey(() => fill);
|
|
243
244
|
const strokeKey = createKey(() => stroke);
|
|
244
245
|
|
|
245
|
-
if (
|
|
246
|
+
if (layerCtx === 'canvas') {
|
|
246
247
|
registerCanvasComponent({
|
|
247
248
|
name: 'Polygon',
|
|
248
249
|
render,
|
|
@@ -264,12 +265,13 @@
|
|
|
264
265
|
opacity,
|
|
265
266
|
className,
|
|
266
267
|
tweenedState.current,
|
|
268
|
+
restProps.style,
|
|
267
269
|
],
|
|
268
270
|
});
|
|
269
271
|
}
|
|
270
272
|
</script>
|
|
271
273
|
|
|
272
|
-
{#if
|
|
274
|
+
{#if layerCtx === 'svg'}
|
|
273
275
|
<path
|
|
274
276
|
d={tweenedState.current}
|
|
275
277
|
{fill}
|
|
@@ -83,11 +83,11 @@
|
|
|
83
83
|
</script>
|
|
84
84
|
|
|
85
85
|
<script lang="ts">
|
|
86
|
-
import {
|
|
87
|
-
import { registerCanvasComponent } from './
|
|
86
|
+
import { getLayerContext } from '../contexts/layer.js';
|
|
87
|
+
import { registerCanvasComponent } from './layers/Canvas.svelte';
|
|
88
88
|
import { getComputedStyles } from '../utils/canvas.js';
|
|
89
89
|
import { parsePercent } from '../utils/math.js';
|
|
90
|
-
import { getChartContext } from '
|
|
90
|
+
import { getChartContext } from '../contexts/chart.js';
|
|
91
91
|
import { createId } from '../utils/createId.js';
|
|
92
92
|
import { extractLayerProps } from '../utils/attributes.js';
|
|
93
93
|
import { cls } from '@layerstack/tailwind';
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
|
|
115
115
|
const ctx = getChartContext();
|
|
116
116
|
|
|
117
|
-
const
|
|
117
|
+
const layerCtx = getLayerContext();
|
|
118
118
|
|
|
119
119
|
let canvasGradient = $state<CanvasGradient>();
|
|
120
120
|
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
canvasGradient = gradient;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
if (
|
|
147
|
+
if (layerCtx === 'canvas') {
|
|
148
148
|
registerCanvasComponent({
|
|
149
149
|
name: 'Gradient',
|
|
150
150
|
render,
|
|
@@ -153,9 +153,9 @@
|
|
|
153
153
|
}
|
|
154
154
|
</script>
|
|
155
155
|
|
|
156
|
-
{#if
|
|
156
|
+
{#if layerCtx === 'canvas'}
|
|
157
157
|
{@render children?.({ id, gradient: canvasGradient as any })}
|
|
158
|
-
{:else if
|
|
158
|
+
{:else if layerCtx === 'svg'}
|
|
159
159
|
<defs>
|
|
160
160
|
<radialGradient
|
|
161
161
|
{id}
|