layerchart 0.54.0 → 0.54.1
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/dist/components/Arc.svelte +170 -144
- package/dist/components/Area.svelte +96 -67
- package/dist/components/Area.svelte.d.ts +1 -0
- package/dist/components/Axis.svelte +205 -155
- package/dist/components/Bar.svelte +72 -45
- package/dist/components/Bars.svelte +45 -34
- package/dist/components/Blur.svelte +5 -3
- package/dist/components/Bounds.svelte +37 -21
- package/dist/components/Brush.svelte +181 -110
- package/dist/components/Calendar.svelte +51 -38
- package/dist/components/Chart.svelte +295 -74
- package/dist/components/Chart.svelte.d.ts +17 -17
- package/dist/components/ChartClipPath.svelte +8 -5
- package/dist/components/ChartContext.svelte +243 -93
- package/dist/components/ChartContext.svelte.d.ts +15 -23
- package/dist/components/Circle.svelte +25 -16
- package/dist/components/CircleClipPath.svelte +16 -10
- package/dist/components/ClipPath.svelte +11 -7
- package/dist/components/ColorRamp.svelte +12 -10
- package/dist/components/ForceSimulation.svelte +185 -116
- package/dist/components/Frame.svelte +10 -6
- package/dist/components/GeoCircle.svelte +15 -9
- package/dist/components/GeoContext.svelte +109 -62
- package/dist/components/GeoEdgeFade.svelte +20 -14
- package/dist/components/GeoPath.svelte +107 -69
- package/dist/components/GeoPoint.svelte +32 -18
- package/dist/components/GeoSpline.svelte +30 -22
- package/dist/components/GeoTile.svelte +40 -30
- package/dist/components/GeoVisible.svelte +10 -7
- package/dist/components/Graticule.svelte +14 -8
- package/dist/components/Grid.svelte +75 -48
- package/dist/components/Group.svelte +43 -31
- package/dist/components/Highlight.svelte +284 -243
- package/dist/components/HitCanvas.svelte +75 -42
- package/dist/components/Hull.svelte +40 -20
- package/dist/components/Labels.svelte +81 -70
- package/dist/components/Legend.svelte +105 -74
- package/dist/components/Legend.svelte.d.ts +1 -1
- package/dist/components/Line.svelte +29 -19
- package/dist/components/LinearGradient.svelte +21 -15
- package/dist/components/Link.svelte +44 -22
- package/dist/components/MonthPath.svelte +23 -16
- package/dist/components/MotionPath.svelte +34 -25
- package/dist/components/Pack.svelte +21 -14
- package/dist/components/Partition.svelte +35 -20
- package/dist/components/Pattern.svelte +8 -6
- package/dist/components/Pie.svelte +76 -57
- package/dist/components/Point.svelte +11 -7
- package/dist/components/Points.svelte +178 -143
- package/dist/components/RadialGradient.svelte +25 -18
- package/dist/components/Rect.svelte +33 -19
- package/dist/components/RectClipPath.svelte +16 -11
- package/dist/components/Rule.svelte +50 -42
- package/dist/components/Sankey.svelte +55 -30
- package/dist/components/Spline.svelte +118 -96
- package/dist/components/Text.svelte +137 -104
- package/dist/components/Threshold.svelte +18 -7
- package/dist/components/TileImage.svelte +56 -50
- package/dist/components/TransformContext.svelte +235 -135
- package/dist/components/TransformControls.svelte +57 -29
- package/dist/components/TransformControls.svelte.d.ts +1 -1
- package/dist/components/Tree.svelte +33 -23
- package/dist/components/Treemap.svelte +69 -41
- package/dist/components/Voronoi.svelte +55 -28
- package/dist/components/charts/AreaChart.svelte +128 -77
- package/dist/components/charts/AreaChart.svelte.d.ts +1 -1
- package/dist/components/charts/BarChart.svelte +169 -104
- package/dist/components/charts/BarChart.svelte.d.ts +1 -1
- package/dist/components/charts/LineChart.svelte +87 -43
- package/dist/components/charts/LineChart.svelte.d.ts +1 -1
- package/dist/components/charts/PieChart.svelte +102 -52
- package/dist/components/charts/PieChart.svelte.d.ts +1 -1
- package/dist/components/charts/ScatterChart.svelte +73 -38
- package/dist/components/charts/ScatterChart.svelte.d.ts +1 -1
- package/dist/components/layout/Canvas.svelte +63 -43
- package/dist/components/layout/Html.svelte +28 -18
- package/dist/components/layout/Svg.svelte +47 -32
- package/dist/components/tooltip/Tooltip.svelte +137 -91
- package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContext.svelte +315 -249
- package/dist/components/tooltip/TooltipHeader.svelte +9 -3
- package/dist/components/tooltip/TooltipItem.svelte +17 -9
- package/dist/components/tooltip/TooltipList.svelte +2 -1
- package/dist/components/tooltip/TooltipSeparator.svelte +3 -2
- package/dist/docs/Blockquote.svelte +4 -3
- package/dist/docs/Code.svelte +15 -8
- package/dist/docs/CurveMenuField.svelte +17 -12
- package/dist/docs/GeoDebug.svelte +13 -9
- package/dist/docs/Header1.svelte +2 -1
- package/dist/docs/Json.svelte +6 -4
- package/dist/docs/Layout.svelte +6 -6
- package/dist/docs/PathDataMenuField.svelte +52 -44
- package/dist/docs/Preview.svelte +39 -33
- package/dist/docs/TilesetField.svelte +80 -62
- package/dist/docs/TransformDebug.svelte +8 -5
- package/dist/docs/ViewSourceButton.svelte +13 -9
- package/dist/stores/motionStore.d.ts +1 -1
- package/dist/utils/scales.d.ts +3 -3
- package/package.json +29 -30
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export let
|
|
9
|
-
export let
|
|
10
|
-
|
|
11
|
-
export let
|
|
12
|
-
export let
|
|
13
|
-
|
|
14
|
-
let
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
let
|
|
18
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { tick } from 'svelte';
|
|
3
|
+
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
4
|
+
import { cls } from '@layerstack/tailwind';
|
|
5
|
+
|
|
6
|
+
import { motionStore } from '../stores/motionStore.js';
|
|
7
|
+
|
|
8
|
+
export let x1: number;
|
|
9
|
+
export let initialX1 = x1;
|
|
10
|
+
|
|
11
|
+
export let y1: number;
|
|
12
|
+
export let initialY1 = y1;
|
|
13
|
+
|
|
14
|
+
export let x2: number;
|
|
15
|
+
export let initialX2 = x2;
|
|
16
|
+
|
|
17
|
+
export let y2: number;
|
|
18
|
+
export let initialY2 = y2;
|
|
19
|
+
|
|
20
|
+
export let spring: boolean | Parameters<typeof springStore>[1] = undefined;
|
|
21
|
+
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
22
|
+
|
|
23
|
+
let tweened_x1 = motionStore(initialX1, { spring, tweened });
|
|
24
|
+
let tweened_y1 = motionStore(initialY1, { spring, tweened });
|
|
25
|
+
let tweened_x2 = motionStore(initialX2, { spring, tweened });
|
|
26
|
+
let tweened_y2 = motionStore(initialY2, { spring, tweened });
|
|
27
|
+
|
|
28
|
+
$: tick().then(() => {
|
|
19
29
|
tweened_x1.set(x1);
|
|
20
30
|
tweened_y1.set(y1);
|
|
21
31
|
tweened_x2.set(x2);
|
|
22
32
|
tweened_y2.set(y2);
|
|
23
|
-
});
|
|
33
|
+
});
|
|
24
34
|
</script>
|
|
25
35
|
|
|
26
36
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
export let
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { uniqueId } from '@layerstack/utils';
|
|
3
|
+
|
|
4
|
+
/** Unique id for linearGradient */
|
|
5
|
+
export let id: string = uniqueId('linearGradient-');
|
|
6
|
+
|
|
7
|
+
/** Array array of strings (colors), will equally distributed from 0-100%. If array of tuples, will use first value as the offset, and second as color */
|
|
8
|
+
export let stops: string[] | [string | number, string][] = [
|
|
6
9
|
'var(--tw-gradient-from)',
|
|
7
10
|
'var(--tw-gradient-to)',
|
|
8
|
-
];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export let
|
|
12
|
-
export let
|
|
13
|
-
export let
|
|
14
|
-
export let
|
|
15
|
-
export let
|
|
16
|
-
|
|
17
|
-
export let
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/** Apply color stops top-to-bottom (true) or left-to-right (false) */
|
|
14
|
+
export let vertical = false;
|
|
15
|
+
export let x1 = '0%';
|
|
16
|
+
export let y1 = '0%';
|
|
17
|
+
export let x2 = vertical ? '0%' : '100%';
|
|
18
|
+
export let y2 = vertical ? '100%' : '0%';
|
|
19
|
+
|
|
20
|
+
export let rotate: number | undefined = undefined;
|
|
21
|
+
|
|
22
|
+
/** Define the coordinate system for attributes (i.e. gradientUnits) */
|
|
23
|
+
export let units: 'objectBoundingBox' | 'userSpaceOnUse' = 'objectBoundingBox';
|
|
18
24
|
</script>
|
|
19
25
|
|
|
20
26
|
<defs>
|
|
@@ -1,29 +1,51 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
TODO:
|
|
4
|
+
- [ ] Show path progressively show / animated in on load. Also fix sliding in from left side (at last in from bottom)
|
|
5
|
+
- [ ] Support link types
|
|
6
|
+
- [ ] https://airbnb.io/visx/linktypes
|
|
7
|
+
- [ ] https://github.com/airbnb/visx/tree/master/packages/visx-shape/src/shapes/link
|
|
8
|
+
- [ ] https://observablehq.com/@nitaku/corner-connectors
|
|
9
|
+
- [ ] Straight
|
|
10
|
+
- [ ] Square
|
|
11
|
+
- [ ] Beveled
|
|
12
|
+
- [ ] Rounded
|
|
13
|
+
- [ ] Investigate: https://observablehq.com/@fil/sankey-link-paths
|
|
14
|
+
- [ ] Use for annotations - https://github.com/techniq/layerchart/issues/11
|
|
15
|
+
*/
|
|
16
|
+
import type { tweened as tweenedStore } from 'svelte/motion';
|
|
17
|
+
import { link as d3Link, curveBumpX, curveBumpY } from 'd3-shape';
|
|
18
|
+
import { interpolatePath } from 'd3-interpolate-path';
|
|
19
|
+
|
|
20
|
+
import { motionStore } from '../stores/motionStore.js';
|
|
21
|
+
|
|
22
|
+
// Override what is used from context
|
|
23
|
+
export let data: any = undefined; // TODO: Update Type
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Update source and target accessors to be compatible with d3-sankey. see: https://github.com/d3/d3-sankey#sankeyLinkHorizontal
|
|
27
|
+
*/
|
|
28
|
+
export let sankey = false;
|
|
29
|
+
export let source = sankey ? (d: any) => [d.source.x1, d.y0] : (d: any) => d.source;
|
|
30
|
+
export let target = sankey ? (d: any) => [d.target.x0, d.y1] : (d: any) => d.target;
|
|
31
|
+
|
|
32
|
+
/** Convenient property to swap x/y accessor logic */
|
|
33
|
+
export let orientation: 'vertical' | 'horizontal' = sankey ? 'horizontal' : 'vertical';
|
|
34
|
+
export let x = (d: any) => (sankey ? d[0] : orientation === 'horizontal' ? d.y : d.x);
|
|
35
|
+
export let y = (d: any) => (sankey ? d[1] : orientation === 'horizontal' ? d.x : d.y);
|
|
36
|
+
export let curve = orientation === 'horizontal' ? curveBumpX : curveBumpY;
|
|
37
|
+
|
|
38
|
+
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
39
|
+
// @ts-expect-error
|
|
40
|
+
$: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
|
|
41
|
+
$: tweened_d = motionStore('', { tweened: tweenedOptions });
|
|
42
|
+
|
|
43
|
+
$: {
|
|
22
44
|
orientation; // subscribe to orientation changes to update link
|
|
23
45
|
const link = d3Link(curve).source(source).target(target).x(x).y(y);
|
|
24
46
|
const d = link(data) ?? '';
|
|
25
47
|
tweened_d.set(d);
|
|
26
|
-
}
|
|
48
|
+
}
|
|
27
49
|
</script>
|
|
28
50
|
|
|
29
51
|
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
$:
|
|
16
|
-
$:
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { timeWeek, timeYear } from 'd3-time';
|
|
3
|
+
import { endOfMonth } from 'date-fns';
|
|
4
|
+
|
|
5
|
+
export let date: Date;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Size of cell. If `number`, sets width/height as same. If array, sets [width,height]. If undefined, is based on Chart width/height
|
|
9
|
+
*/
|
|
10
|
+
export let cellSize: number | [number, number];
|
|
11
|
+
|
|
12
|
+
$: [cellWidth, cellHeight] = Array.isArray(cellSize) ? cellSize : [cellSize, cellSize];
|
|
13
|
+
|
|
14
|
+
// start of month
|
|
15
|
+
$: startDayOfWeek = date.getDay();
|
|
16
|
+
$: startWeek = timeWeek.count(timeYear(date), date);
|
|
17
|
+
|
|
18
|
+
// end of month
|
|
19
|
+
$: monthEnd = endOfMonth(date);
|
|
20
|
+
$: endDayOfWeek = monthEnd.getDay();
|
|
21
|
+
$: endWeek = timeWeek.count(timeYear(monthEnd), monthEnd);
|
|
22
|
+
|
|
23
|
+
$: pathData = `
|
|
17
24
|
M${(startWeek + 1) * cellWidth},${startDayOfWeek * cellHeight}
|
|
18
25
|
H${startWeek * cellWidth} V${cellHeight * 7}
|
|
19
26
|
H${endWeek * cellWidth} V${(endDayOfWeek + 1) * cellHeight}
|
|
@@ -1,29 +1,38 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/** Id of
|
|
6
|
-
export let
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
let
|
|
24
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from 'svelte';
|
|
3
|
+
import { uniqueId } from '@layerstack/utils';
|
|
4
|
+
|
|
5
|
+
/** Id of path to move object along */
|
|
6
|
+
export let pathId: string = uniqueId('motionPathId-');
|
|
7
|
+
|
|
8
|
+
/** Id of object to move along path */
|
|
9
|
+
export let objectId: string = uniqueId('motionObjectId-');
|
|
10
|
+
|
|
11
|
+
/** Duration of the animation */
|
|
12
|
+
export let duration: string;
|
|
13
|
+
|
|
14
|
+
/** Number of times the animation will occur */
|
|
15
|
+
export let repeatCount: number | 'indefinite' | undefined = undefined;
|
|
16
|
+
|
|
17
|
+
/** Final state of the animation. Freeze (last frame) or remove (first frame)
|
|
18
|
+
* https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill#animate
|
|
19
|
+
* */
|
|
20
|
+
export let fill: 'freeze' | 'remove' = 'freeze';
|
|
21
|
+
|
|
22
|
+
/** Rotation applied to the element animated along a path, usually to make it pointing in the direction of the animation */
|
|
23
|
+
export let rotate: number | 'auto' | 'auto-reverse' | undefined = undefined;
|
|
24
|
+
|
|
25
|
+
// TODO: Investigate `calcMode:spline`, `keyTimes`, and `keySplines` to work with `svelte/easing`
|
|
26
|
+
// https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/calcMode
|
|
27
|
+
// https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/keyTimes
|
|
28
|
+
// https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/keySplines
|
|
29
|
+
// https://medium.com/javarevisited/animate-your-scalable-vector-graphics-svg-56f5800cd34b
|
|
30
|
+
|
|
31
|
+
// Restart animation anytime the component is remounted (otherwise it only ever plays once)
|
|
32
|
+
let animateEl: SVGAnimateMotionElement;
|
|
33
|
+
onMount(() => {
|
|
25
34
|
animateEl.beginElement();
|
|
26
|
-
});
|
|
35
|
+
});
|
|
27
36
|
</script>
|
|
28
37
|
|
|
29
38
|
<defs>
|
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { pack as d3Pack } from 'd3-hierarchy';
|
|
3
|
+
import { chartContext } from './ChartContext.svelte';
|
|
4
|
+
|
|
5
|
+
const { data, width, height } = chartContext();
|
|
6
|
+
|
|
7
|
+
export let size: [number, number] | undefined = undefined;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* see: https://github.com/d3/d3-hierarchy#pack_padding
|
|
11
|
+
*/
|
|
12
|
+
export let padding: number | undefined = undefined;
|
|
13
|
+
|
|
14
|
+
let pack: ReturnType<typeof d3Pack>;
|
|
15
|
+
$: {
|
|
11
16
|
pack = d3Pack().size(size ?? [$width, $height]);
|
|
17
|
+
|
|
12
18
|
if (padding) {
|
|
13
|
-
|
|
19
|
+
pack.padding(padding);
|
|
14
20
|
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// @ts-expect-error
|
|
24
|
+
$: packData = pack($data);
|
|
18
25
|
</script>
|
|
19
26
|
|
|
20
27
|
<slot nodes={packData.descendants()} />
|
|
@@ -1,27 +1,42 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export let
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
partition as d3Partition,
|
|
4
|
+
type HierarchyNode,
|
|
5
|
+
type HierarchyRectangularNode,
|
|
6
|
+
} from 'd3-hierarchy';
|
|
7
|
+
import { chartContext } from './ChartContext.svelte';
|
|
8
|
+
|
|
9
|
+
const { data, width, height } = chartContext();
|
|
10
|
+
|
|
11
|
+
export let orientation: 'vertical' | 'horizontal' = 'horizontal';
|
|
12
|
+
|
|
13
|
+
export let size: [number, number] | undefined = undefined;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* see: https://github.com/d3/d3-hierarchy#tree_nodeSize
|
|
17
|
+
*/
|
|
18
|
+
export let padding: number | undefined = undefined;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* see: https://github.com/d3/d3-hierarchy#tree_nodeSize
|
|
22
|
+
*/
|
|
23
|
+
export let round: boolean | undefined = undefined;
|
|
24
|
+
|
|
25
|
+
let partition: ReturnType<typeof d3Partition>;
|
|
26
|
+
$: {
|
|
27
|
+
partition = d3Partition().size(
|
|
28
|
+
size ?? (orientation === 'horizontal' ? [$height, $width] : [$width, $height])
|
|
29
|
+
);
|
|
30
|
+
|
|
17
31
|
if (padding) {
|
|
18
|
-
|
|
32
|
+
partition.padding(padding);
|
|
19
33
|
}
|
|
20
34
|
if (round) {
|
|
21
|
-
|
|
35
|
+
partition.round(round);
|
|
22
36
|
}
|
|
23
|
-
}
|
|
24
|
-
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
$: partitionData = partition($data as HierarchyNode<any>) as HierarchyRectangularNode<any>;
|
|
25
40
|
</script>
|
|
26
41
|
|
|
27
42
|
<slot nodes={partitionData.descendants()} />
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
<script
|
|
2
|
-
// https://
|
|
3
|
-
// https://
|
|
4
|
-
|
|
5
|
-
export let
|
|
6
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// https://developer.mozilla.org/en-US/docs/Web/SVG/Element/pattern
|
|
3
|
+
// https://airbnb.io/visx/patterns
|
|
4
|
+
// https://github.com/airbnb/visx/tree/master/packages/visx-pattern/src/patterns
|
|
5
|
+
export let id: string;
|
|
6
|
+
|
|
7
|
+
export let width: number;
|
|
8
|
+
export let height: number;
|
|
7
9
|
</script>
|
|
8
10
|
|
|
9
11
|
<defs>
|
|
@@ -1,65 +1,84 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
let
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
3
|
+
import { pie as d3pie } from 'd3-shape';
|
|
4
|
+
import { min, max } from 'd3-array';
|
|
5
|
+
|
|
6
|
+
import Arc from './Arc.svelte';
|
|
7
|
+
import { chartContext } from './ChartContext.svelte';
|
|
8
|
+
import { degreesToRadians } from '../utils/math.js';
|
|
9
|
+
import { motionStore } from '../stores/motionStore.js';
|
|
10
|
+
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
TODO:
|
|
14
|
+
- [ ] Offset (always, on hover)
|
|
15
|
+
- [ ] Labels
|
|
16
|
+
- [ ] Multiple nested circles (zScale, or take in data to override context data). See Path/Area/Threshold
|
|
17
|
+
- [ ] Hover events / change innerRadius / outerRadius, etc
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export let data: any[] | undefined = undefined; // TODO: Update Type
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Range [min,max] in degrees. See also startAngle/endAngle
|
|
24
|
+
*/
|
|
25
|
+
export let range = [0, 360]; // degrees
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Start angle in radians
|
|
29
|
+
*/
|
|
30
|
+
export let startAngle: number | undefined = undefined;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* End angle in radians
|
|
34
|
+
*/
|
|
35
|
+
export let endAngle: number | undefined = undefined;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Define innerRadius.
|
|
39
|
+
* value >= 1: discrete value
|
|
40
|
+
* value > 0: percent of `outerRadius`
|
|
41
|
+
* value < 0: offset of `outerRadius`
|
|
42
|
+
* default: yRange min
|
|
43
|
+
*/
|
|
44
|
+
export let innerRadius: number | undefined = undefined;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Define outerRadius. Defaults to yRange max/2 (ie. chart height / 2)
|
|
48
|
+
*/
|
|
49
|
+
export let outerRadius: number | undefined = undefined;
|
|
50
|
+
|
|
51
|
+
export let cornerRadius = 0;
|
|
52
|
+
export let padAngle = 0;
|
|
53
|
+
|
|
54
|
+
export let spring: boolean | Parameters<typeof springStore>[1] = undefined;
|
|
55
|
+
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Offset all arcs from center
|
|
59
|
+
*/
|
|
60
|
+
export let offset = 0;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Tooltip context to setup pointer events to show tooltip for related data
|
|
64
|
+
*/
|
|
65
|
+
export let tooltip: TooltipContextValue | undefined = undefined;
|
|
66
|
+
|
|
67
|
+
const { data: contextData, x, y, xRange, c, cScale, config, width, height } = chartContext();
|
|
68
|
+
|
|
69
|
+
// @ts-expect-error
|
|
70
|
+
$: resolved_endAngle = endAngle ?? degreesToRadians($config.xRange ? max($xRange) : max(range));
|
|
71
|
+
let tweened_endAngle = motionStore(0, { spring, tweened });
|
|
72
|
+
$: tweened_endAngle.set(resolved_endAngle);
|
|
73
|
+
|
|
74
|
+
$: pie = d3pie<any>()
|
|
57
75
|
// @ts-expect-error
|
|
58
76
|
.startAngle(startAngle ?? degreesToRadians($config.xRange ? min($xRange) : min(range)))
|
|
59
77
|
.endAngle($tweened_endAngle)
|
|
60
78
|
.padAngle(padAngle)
|
|
61
79
|
.value($x);
|
|
62
|
-
|
|
80
|
+
|
|
81
|
+
$: arcs = pie(data ?? (Array.isArray($contextData) ? $contextData : []));
|
|
63
82
|
</script>
|
|
64
83
|
|
|
65
84
|
<slot {arcs}>
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { chartContext } from './ChartContext.svelte';
|
|
3
|
+
|
|
4
|
+
const context = chartContext() as any;
|
|
5
|
+
const { xGet, yGet } = context;
|
|
6
|
+
|
|
7
|
+
/** Single data point to translate to x/y */
|
|
8
|
+
export let d;
|
|
9
|
+
|
|
10
|
+
$: x = $xGet(d);
|
|
11
|
+
$: y = $yGet(d);
|
|
8
12
|
</script>
|
|
9
13
|
|
|
10
14
|
<slot {x} {y} />
|