Skip to content

Commit 0a0392f

Browse files
committed
[Point] Add radial support
1 parent c6ff343 commit 0a0392f

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

.changeset/modern-pets-jam.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"layerchart": patch
2+
'layerchart': patch
33
---
44

5-
[Area/Spline/Axis] Support radial / polar coordinate system (along with cartesian)
5+
Support radial / polar coordinate system (along with cartesian) for Axis, Spline, Area, and Point

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import Circle from './Circle.svelte';
77
import Link from './Link.svelte';
88
import { isScaleBand } from '../utils/scales';
9+
import { pointRadial } from 'd3-shape';
910
1011
const context = getContext('LayerCake') as any;
1112
const { data, xGet, y, yGet, xScale, yScale, rGet, config } = context;
@@ -16,6 +17,9 @@
1617
export let offsetX: Offset = undefined;
1718
export let offsetY: Offset = undefined;
1819
20+
/** Use radial instead of cartesian line generator, mapping `x` to `angle` and `y` to `radius`. Radial points are positioned relative to the origin, use transform (ex. `<Group center>`) to change the origin */
21+
export let radial = false;
22+
1923
/** Enable showing links between related points (array x/y accessors) */
2024
export let links: boolean | Partial<ComponentProps<Link>> = false;
2125
@@ -24,7 +28,7 @@
2428
return offset(value, context);
2529
} else if (offset != null) {
2630
return offset;
27-
} else if (isScaleBand(scale)) {
31+
} else if (isScaleBand(scale) && !radial) {
2832
return scale.bandwidth() / 2;
2933
} else {
3034
return 0;
@@ -127,9 +131,10 @@
127131

128132
<g class="point-group">
129133
{#each points as point}
134+
{@const radialPoint = pointRadial(point.x, point.y)}
130135
<Circle
131-
cx={point.x}
132-
cy={point.y}
136+
cx={radial ? radialPoint[0] : point.x}
137+
cy={radial ? radialPoint[1] : point.y}
133138
{r}
134139
fill={$config.r ? $rGet(point.data) : null}
135140
{...$$restProps}

0 commit comments

Comments
 (0)