Skip to content

Commit

Permalink
fix(Spline): Refine default path data to handle 0 out of visible ra…
Browse files Browse the repository at this point in the history
…nge and improve custom curve tweening
  • Loading branch information
techniq committed Nov 6, 2024
1 parent dc6d02c commit 0b06ee0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-mayflies-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'layerchart': patch
---

fix(Spline): Refine default path data to handle `0` out of visible range and improve custom curve tweening
26 changes: 22 additions & 4 deletions packages/layerchart/src/lib/components/Spline.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@
import { accessor, type Accessor } from '../utils/common.js';
import { isScaleBand } from '../utils/scales.js';
const { data: contextData, xScale, yScale, x: contextX, y: contextY, radial } = chartContext();
const {
data: contextData,
xScale,
yScale,
x: contextX,
y: contextY,
yRange,
radial,
} = chartContext();
/** Override data instead of using context */
export let data: any = undefined;
Expand Down Expand Up @@ -92,9 +100,19 @@
/** Provide initial `0` horizontal baseline and initially hide/untrack scale changes so not reactive (only set on initial mount) */
function defaultPathData() {
const [xRangeMin, xRangeMax] = $xScale.range();
const yRangeZero = $yScale(0);
return `M${xRangeMin},${yRangeZero} L${xRangeMax},${yRangeZero}`;
const path = $radial
? lineRadial()
.angle((d) => $xScale(xAccessor(d)))
.radius((d) => Math.min($yScale(0), $yRange[0]))
: d3Line()
.x((d) => $xScale(xAccessor(d)) + xOffset)
.y((d) => Math.min($yScale(0), $yRange[0]));
path.defined(defined ?? ((d) => xAccessor(d) != null && yAccessor(d) != null));
if (curve) path.curve(curve);
return path(data ?? $contextData);
}
let d: string | null = '';
Expand Down

0 comments on commit 0b06ee0

Please sign in to comment.