layerchart 0.5.1 → 0.5.2
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/components/Arc.svelte +2 -2
- package/components/Area.svelte +2 -2
- package/components/Bounds.svelte +5 -5
- package/components/Bounds.svelte.d.ts +3 -0
- package/components/Circle.svelte +4 -4
- package/components/Group.svelte +3 -3
- package/components/Line.svelte +5 -5
- package/components/Link.svelte +2 -2
- package/components/Path.svelte +2 -2
- package/components/Pie.svelte +2 -2
- package/components/Rect.svelte +5 -5
- package/package.json +1 -1
- package/stores/motionStore.d.ts +5 -4
- package/stores/motionStore.js +1 -1
- package/utils/scales.d.ts +6 -5
- package/utils/scales.js +9 -8
package/components/Arc.svelte
CHANGED
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
import { getContext } from 'svelte';
|
|
16
16
|
import { arc as d3arc } from 'd3-shape';
|
|
17
17
|
import { scaleLinear } from 'd3-scale';
|
|
18
|
-
import {
|
|
18
|
+
import { motionStore } from '../stores/motionStore';
|
|
19
19
|
import { degreesToRadians } from '../utils/math';
|
|
20
20
|
export let spring = undefined;
|
|
21
21
|
export let tweened = undefined;
|
|
22
22
|
export let value = 0;
|
|
23
|
-
let tweened_value =
|
|
23
|
+
let tweened_value = motionStore(value, { spring, tweened });
|
|
24
24
|
$: tweened_value.set(value);
|
|
25
25
|
export let domain = [0, 100];
|
|
26
26
|
/**
|
package/components/Area.svelte
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>import { getContext } from 'svelte';
|
|
2
2
|
import { area as d3Area } from 'd3-shape';
|
|
3
3
|
import { interpolatePath } from 'd3-interpolate-path';
|
|
4
|
-
import {
|
|
4
|
+
import { motionStore } from '../stores/motionStore';
|
|
5
5
|
import Path from './Path.svelte';
|
|
6
6
|
const { data: contextData, xGet, yGet, yRange } = getContext('LayerCake');
|
|
7
7
|
// Properties to override what is used from context
|
|
@@ -18,7 +18,7 @@ export let color = 'var(--color-blue-500)';
|
|
|
18
18
|
export let opacity = 0.3;
|
|
19
19
|
export let line = false;
|
|
20
20
|
$: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
|
|
21
|
-
$: tweened_d =
|
|
21
|
+
$: tweened_d = motionStore('', { tweened: tweenedOptions });
|
|
22
22
|
$: {
|
|
23
23
|
const path = d3Area()
|
|
24
24
|
.x(x ?? $xGet)
|
package/components/Bounds.svelte
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<script>import { getContext } from 'svelte';
|
|
2
|
-
import { cubicOut } from 'svelte/easing';
|
|
3
2
|
import { scaleLinear } from 'd3-scale';
|
|
4
|
-
import {
|
|
3
|
+
import { motionScale } from '../utils/scales';
|
|
5
4
|
const { width, height } = getContext('LayerCake');
|
|
6
5
|
export let domain;
|
|
7
6
|
export let range;
|
|
8
|
-
|
|
7
|
+
export let spring = undefined;
|
|
8
|
+
export let tweened = undefined;
|
|
9
9
|
function getExtents(extents, axis, fallback) {
|
|
10
10
|
const resolvedExtents = typeof extents === 'function' ? extents({ width: $width, height: $height }) : extents;
|
|
11
11
|
return [
|
|
@@ -13,10 +13,10 @@ function getExtents(extents, axis, fallback) {
|
|
|
13
13
|
resolvedExtents?.[axis + '1'] ?? fallback // x1 or y1, fallback as $width or $height
|
|
14
14
|
];
|
|
15
15
|
}
|
|
16
|
-
const xScale =
|
|
16
|
+
const xScale = motionScale(scaleLinear, { spring, tweened });
|
|
17
17
|
$: xScale.domain(getExtents(domain, 'x', $width));
|
|
18
18
|
$: xScale.range(getExtents(range, 'x', $width));
|
|
19
|
-
const yScale =
|
|
19
|
+
const yScale = motionScale(scaleLinear, { spring, tweened });
|
|
20
20
|
$: yScale.domain(getExtents(domain, 'y', $height));
|
|
21
21
|
$: yScale.range(getExtents(range, 'y', $height));
|
|
22
22
|
</script>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import { motionScale } from '../utils/scales';
|
|
2
3
|
declare const __propDef: {
|
|
3
4
|
props: {
|
|
4
5
|
domain: {
|
|
@@ -29,6 +30,8 @@ declare const __propDef: {
|
|
|
29
30
|
x1: number;
|
|
30
31
|
y1: number;
|
|
31
32
|
});
|
|
33
|
+
spring?: boolean | Parameters<typeof motionScale>[1]['spring'];
|
|
34
|
+
tweened?: boolean | Parameters<typeof motionScale>[1]['tweened'];
|
|
32
35
|
};
|
|
33
36
|
events: {
|
|
34
37
|
[evt: string]: CustomEvent<any>;
|
package/components/Circle.svelte
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { motionStore } from '../stores/motionStore';
|
|
2
2
|
export let cx;
|
|
3
3
|
export let cy;
|
|
4
4
|
export let r;
|
|
5
5
|
export let spring = undefined;
|
|
6
6
|
export let tweened = undefined;
|
|
7
|
-
let tweened_cx =
|
|
8
|
-
let tweened_cy =
|
|
9
|
-
let tweened_r =
|
|
7
|
+
let tweened_cx = motionStore(cx, { spring, tweened });
|
|
8
|
+
let tweened_cy = motionStore(cy, { spring, tweened });
|
|
9
|
+
let tweened_r = motionStore(r, { spring, tweened });
|
|
10
10
|
$: tweened_cx.set(cx);
|
|
11
11
|
$: tweened_cy.set(cy);
|
|
12
12
|
$: tweened_r.set(r);
|
package/components/Group.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>import { getContext } from 'svelte';
|
|
2
|
-
import {
|
|
2
|
+
import { motionStore } from '../stores/motionStore';
|
|
3
3
|
const { width, height } = getContext('LayerCake');
|
|
4
4
|
/**
|
|
5
5
|
* Translate x
|
|
@@ -15,8 +15,8 @@ export let y = undefined;
|
|
|
15
15
|
export let center = false;
|
|
16
16
|
export let spring = undefined;
|
|
17
17
|
export let tweened = undefined;
|
|
18
|
-
let tweened_x =
|
|
19
|
-
let tweened_y =
|
|
18
|
+
let tweened_x = motionStore(x, { spring, tweened });
|
|
19
|
+
let tweened_y = motionStore(y, { spring, tweened });
|
|
20
20
|
$: tweened_x.set(x);
|
|
21
21
|
$: tweened_y.set(y);
|
|
22
22
|
let transform = undefined;
|
package/components/Line.svelte
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { motionStore } from '../stores/motionStore';
|
|
2
2
|
export let x1;
|
|
3
3
|
export let y1;
|
|
4
4
|
export let x2;
|
|
5
5
|
export let y2;
|
|
6
6
|
export let spring = undefined;
|
|
7
7
|
export let tweened = undefined;
|
|
8
|
-
let tweened_x1 =
|
|
9
|
-
let tweened_y1 =
|
|
10
|
-
let tweened_x2 =
|
|
11
|
-
let tweened_y2 =
|
|
8
|
+
let tweened_x1 = motionStore(x1, { spring, tweened });
|
|
9
|
+
let tweened_y1 = motionStore(y1, { spring, tweened });
|
|
10
|
+
let tweened_x2 = motionStore(x2, { spring, tweened });
|
|
11
|
+
let tweened_y2 = motionStore(y2, { spring, tweened });
|
|
12
12
|
$: tweened_x1.set(x1);
|
|
13
13
|
$: tweened_y1.set(y1);
|
|
14
14
|
$: tweened_x2.set(x2);
|
package/components/Link.svelte
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>import { link as d3Link, curveBumpX, curveBumpY } from 'd3-shape';
|
|
2
2
|
import { interpolatePath } from 'd3-interpolate-path';
|
|
3
|
-
import {
|
|
3
|
+
import { motionStore } from '../stores/motionStore';
|
|
4
4
|
// Properties to override what is used from context
|
|
5
5
|
export let data = undefined; // TODO: Update Type
|
|
6
6
|
export let orientation = 'horizontal';
|
|
@@ -17,7 +17,7 @@ export let tweened = undefined;
|
|
|
17
17
|
export let color = 'black';
|
|
18
18
|
export let width = undefined;
|
|
19
19
|
$: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
|
|
20
|
-
$: tweened_d =
|
|
20
|
+
$: tweened_d = motionStore('', { tweened: tweenedOptions });
|
|
21
21
|
$: {
|
|
22
22
|
orientation; // subscribe to orientation changes to link is update
|
|
23
23
|
const link = d3Link(curve).source(source).target(target).x(x).y(y);
|
package/components/Path.svelte
CHANGED
|
@@ -6,7 +6,7 @@ import { getContext } from 'svelte';
|
|
|
6
6
|
import { line as d3Line } from 'd3-shape';
|
|
7
7
|
// import { interpolateString } from 'd3-interpolate';
|
|
8
8
|
import { interpolatePath } from 'd3-interpolate-path';
|
|
9
|
-
import {
|
|
9
|
+
import { motionStore } from '../stores/motionStore';
|
|
10
10
|
const { data: contextData, xGet, yGet, zGet } = getContext('LayerCake');
|
|
11
11
|
// Properties to override what is used from context
|
|
12
12
|
export let data = undefined; // TODO: Update Type
|
|
@@ -19,7 +19,7 @@ export let defined = undefined;
|
|
|
19
19
|
export let color = 'black';
|
|
20
20
|
export let width = undefined;
|
|
21
21
|
$: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
|
|
22
|
-
$: tweened_d =
|
|
22
|
+
$: tweened_d = motionStore('', { tweened: tweenedOptions });
|
|
23
23
|
$: {
|
|
24
24
|
const path = d3Line()
|
|
25
25
|
.x(x ?? $xGet)
|
package/components/Pie.svelte
CHANGED
|
@@ -3,7 +3,7 @@ import { pie as d3pie } from 'd3-shape';
|
|
|
3
3
|
import Arc from './Arc.svelte';
|
|
4
4
|
import Group from './Group.svelte';
|
|
5
5
|
import { degreesToRadians } from '../utils/math';
|
|
6
|
-
import {
|
|
6
|
+
import { motionStore } from '../stores/motionStore';
|
|
7
7
|
/*
|
|
8
8
|
TODO:
|
|
9
9
|
- [ ] Offset (always, on hover)
|
|
@@ -48,7 +48,7 @@ export let tweened = undefined;
|
|
|
48
48
|
export let offset = 0;
|
|
49
49
|
const { data: contextData, x, y, xRange, rGet, config } = getContext('LayerCake');
|
|
50
50
|
$: resolved_endAngle = endAngle ?? degreesToRadians($config.xRange ? $xRange[1] : range[1]);
|
|
51
|
-
let tweened_endAngle =
|
|
51
|
+
let tweened_endAngle = motionStore(0, { spring, tweened });
|
|
52
52
|
$: tweened_endAngle.set(resolved_endAngle);
|
|
53
53
|
$: pie = d3pie()
|
|
54
54
|
.startAngle(startAngle ?? degreesToRadians($config.xRange ? $xRange[0] : range[0]))
|
package/components/Rect.svelte
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { motionStore } from '../stores/motionStore';
|
|
2
2
|
export let x = 0;
|
|
3
3
|
export let y = 0;
|
|
4
4
|
export let width;
|
|
5
5
|
export let height;
|
|
6
6
|
export let spring = undefined;
|
|
7
7
|
export let tweened = undefined;
|
|
8
|
-
let tweened_x =
|
|
9
|
-
let tweened_y =
|
|
10
|
-
let tweened_width =
|
|
11
|
-
let tweened_height =
|
|
8
|
+
let tweened_x = motionStore(x, { spring, tweened });
|
|
9
|
+
let tweened_y = motionStore(y, { spring, tweened });
|
|
10
|
+
let tweened_width = motionStore(width, { spring, tweened });
|
|
11
|
+
let tweened_height = motionStore(height, { spring, tweened });
|
|
12
12
|
$: tweened_x.set(x);
|
|
13
13
|
$: tweened_y.set(y);
|
|
14
14
|
$: tweened_width.set(width);
|
package/package.json
CHANGED
package/stores/motionStore.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { spring, tweened } from 'svelte/motion';
|
|
2
|
+
export declare type MotionOptions = {
|
|
3
|
+
spring?: boolean | Parameters<typeof spring>[1];
|
|
4
|
+
tweened?: boolean | Parameters<typeof tweened>[1];
|
|
5
|
+
};
|
|
2
6
|
/**
|
|
3
7
|
* Convenient wrapper to create a motion store (spring(), tweened()) based on properties, or fall back to basic writable() store
|
|
4
8
|
*/
|
|
5
|
-
export declare function
|
|
6
|
-
spring?: boolean | Parameters<typeof spring>[1];
|
|
7
|
-
tweened?: boolean | Parameters<typeof tweened>[1];
|
|
8
|
-
}): import("svelte/motion").Tweened<unknown> | import("svelte/motion").Spring<any> | import("svelte/store").Writable<any>;
|
|
9
|
+
export declare function motionStore(value: any, options: MotionOptions): import("svelte/motion").Tweened<unknown> | import("svelte/motion").Spring<any> | import("svelte/store").Writable<any>;
|
package/stores/motionStore.js
CHANGED
|
@@ -3,7 +3,7 @@ import { spring, tweened } from 'svelte/motion';
|
|
|
3
3
|
/**
|
|
4
4
|
* Convenient wrapper to create a motion store (spring(), tweened()) based on properties, or fall back to basic writable() store
|
|
5
5
|
*/
|
|
6
|
-
export function
|
|
6
|
+
export function motionStore(value, options) {
|
|
7
7
|
if (options.spring) {
|
|
8
8
|
return spring(value, options.spring === true ? undefined : options.spring);
|
|
9
9
|
}
|
package/utils/scales.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { tweened
|
|
1
|
+
import { tweened } from 'svelte/motion';
|
|
2
|
+
import { MotionOptions } from '../stores/motionStore';
|
|
2
3
|
/**
|
|
3
4
|
* Implemenation for missing `scaleBand().invert()`
|
|
4
5
|
*
|
|
@@ -18,10 +19,10 @@ export declare function tweenedScale(scale: any, tweenedOptions?: Parameters<typ
|
|
|
18
19
|
range: (values: any) => Promise<void>;
|
|
19
20
|
};
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
+
* Create a store wrapper around a d3-scale which interpolates the domain and/or range using `tweened()` or `spring()` stores. Fallbacks to `writable()` if not interpolating
|
|
22
23
|
*/
|
|
23
|
-
export declare function
|
|
24
|
+
export declare function motionScale(scale: any, options: MotionOptions): {
|
|
24
25
|
subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: (value?: any) => void) => import("svelte/store").Unsubscriber;
|
|
25
|
-
domain: (values: any) => Promise<void>;
|
|
26
|
-
range: (values: any) => Promise<void>;
|
|
26
|
+
domain: (values: any) => void | Promise<void>;
|
|
27
|
+
range: (values: any) => void | Promise<void>;
|
|
27
28
|
};
|
package/utils/scales.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { derived } from 'svelte/store';
|
|
2
|
-
import { tweened
|
|
2
|
+
import { tweened } from 'svelte/motion';
|
|
3
|
+
import { motionStore } from '../stores/motionStore';
|
|
3
4
|
/**
|
|
4
5
|
* Implemenation for missing `scaleBand().invert()`
|
|
5
6
|
*
|
|
@@ -44,12 +45,12 @@ export function tweenedScale(scale, tweenedOptions = {}) {
|
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
+
* Create a store wrapper around a d3-scale which interpolates the domain and/or range using `tweened()` or `spring()` stores. Fallbacks to `writable()` if not interpolating
|
|
48
49
|
*/
|
|
49
|
-
export function
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const tweenedScale = derived([
|
|
50
|
+
export function motionScale(scale, options) {
|
|
51
|
+
const domainStore = motionStore(undefined, options);
|
|
52
|
+
const rangeStore = motionStore(undefined, options);
|
|
53
|
+
const tweenedScale = derived([domainStore, rangeStore], ([domain, range]) => {
|
|
53
54
|
const scaleInstance = scale.domain ? scale : scale(); // support `scaleLinear` or `scaleLinear()` (which could have `.interpolate()` and others set)
|
|
54
55
|
if (domain) {
|
|
55
56
|
scaleInstance.domain(domain);
|
|
@@ -61,7 +62,7 @@ export function springScale(scale, springOptions = {}) {
|
|
|
61
62
|
});
|
|
62
63
|
return {
|
|
63
64
|
subscribe: tweenedScale.subscribe,
|
|
64
|
-
domain: (values) =>
|
|
65
|
-
range: (values) =>
|
|
65
|
+
domain: (values) => domainStore.set(values),
|
|
66
|
+
range: (values) => rangeStore.set(values)
|
|
66
67
|
};
|
|
67
68
|
}
|