Skip to content

Commit 435d3bd

Browse files
committed
fix(Spline): Make motion prop reactive so toggling between tween/none updates without remount
1 parent adcd155 commit 435d3bd

2 files changed

Lines changed: 17 additions & 20 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'layerchart': patch
3+
---
4+
5+
fix(Spline): Make motion prop reactive so toggling between tween/none updates without remount

packages/layerchart/src/lib/components/Spline.svelte

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@
9090
import { getGeoContext } from '$lib/contexts/geo.js';
9191
import { resolveColorProp, resolveStyleProp } from '$lib/utils/dataProp.js';
9292
import Path, { type PathProps } from './Path.svelte';
93-
import {
94-
createMotion,
95-
extractTweenConfig,
96-
type ResolvedMotion,
97-
} from '$lib/utils/motion.svelte.js';
93+
import { createMotion, extractTweenConfig } from '$lib/utils/motion.svelte.js';
9894
9995
const ctx = getChartContext();
10096
const geo = getGeoContext();
@@ -231,24 +227,13 @@
231227
}));
232228
});
233229
234-
const extractedTween = extractTweenConfig(motion);
235-
236-
const tweenOptions: ResolvedMotion | undefined = extractedTween
237-
? {
238-
type: extractedTween.type,
239-
options: {
240-
interpolate: interpolatePath,
241-
...extractedTween.options,
242-
},
243-
}
244-
: undefined;
245-
246230
/**
247231
* Provide initial `0` horizontal baseline so the line animates up from y=0 on mount.
248232
* Computes a proper flattened path using d3-line with all y-values at baseline.
249233
*/
250234
function defaultPathData() {
251-
if (!tweenOptions) return '';
235+
// Skip baseline computation when motion is not initially enabled (faster initial render)
236+
if (!extractTweenConfig(motion)) return '';
252237
253238
if (ctx.config.x) {
254239
const resolvedData = data ?? series?.data ?? ctx.data;
@@ -271,7 +256,14 @@
271256
return '';
272257
}
273258
274-
const tweenState = createMotion(defaultPathData(), () => d, tweenOptions);
259+
// Always create tween motion so it's ready when motion is toggled on
260+
const tweenState = createMotion(defaultPathData(), () => d, {
261+
type: 'tween',
262+
interpolate: interpolatePath,
263+
});
264+
265+
/** Reactively check whether motion is enabled */
266+
const isTweened = $derived(extractTweenConfig(motion) != null);
275267
276268
const seriesOpacity = $derived(
277269
series?.key == null ||
@@ -298,7 +290,7 @@
298290
{/each}
299291
{:else}
300292
<Path
301-
pathData={tweenOptions ? tweenState.current : d}
293+
pathData={isTweened ? tweenState.current : d}
302294
stroke={(typeof stroke === 'string' ? stroke : undefined) ?? series?.color}
303295
fill={typeof fill === 'string' ? fill : undefined}
304296
{...series?.props}

0 commit comments

Comments
 (0)