layerchart 0.0.4 → 0.0.5
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/README.md +2 -37
- package/components/Arc.svelte +77 -0
- package/components/Arc.svelte.d.ts +34 -0
- package/components/Area.svelte +19 -10
- package/components/Area.svelte.d.ts +4 -1
- package/components/AxisX.svelte +1 -1
- package/components/AxisY.svelte +1 -4
- package/components/{Bar.svelte → Bars.svelte} +23 -14
- package/components/{Bar.svelte.d.ts → Bars.svelte.d.ts} +7 -4
- package/components/ConnectedPoints.svelte +68 -0
- package/components/ConnectedPoints.svelte.d.ts +18 -0
- package/components/Group.svelte +26 -0
- package/components/Group.svelte.d.ts +21 -0
- package/components/{HighlightBar.svelte → HighlightRect.svelte} +0 -0
- package/components/HighlightRect.svelte.d.ts +18 -0
- package/components/{Label.svelte → Labels.svelte} +0 -0
- package/components/{Label.svelte.d.ts → Labels.svelte.d.ts} +4 -4
- package/components/LinearGradient.svelte +27 -0
- package/components/LinearGradient.svelte.d.ts +27 -0
- package/components/Path.svelte +19 -15
- package/components/Path.svelte.d.ts +4 -2
- package/components/Points.svelte +58 -0
- package/components/Points.svelte.d.ts +19 -0
- package/components/Threshold.svelte +25 -22
- package/components/index.d.ts +3 -3
- package/components/index.js +3 -3
- package/docs/Preview.svelte +7 -3
- package/docs/Preview.svelte.d.ts +2 -0
- package/package.json +17 -10
- package/stores/motionStore.d.ts +2 -2
- package/utils/genData.d.ts +13 -0
- package/utils/genData.js +24 -0
- package/utils/math.d.ts +4 -0
- package/utils/math.js +6 -0
- package/utils/path.d.ts +5 -0
- package/utils/path.js +14 -0
- package/utils/pivot.js +1 -1
- package/utils/stack.d.ts +14 -0
- package/utils/stack.js +69 -0
- package/components/ClevelandDotPlot.svelte +0 -44
- package/components/ClevelandDotPlot.svelte.d.ts +0 -21
- package/components/HighlightBar.svelte.d.ts +0 -18
- package/components/Scatter.svelte +0 -25
- package/components/Scatter.svelte.d.ts +0 -33
package/README.md
CHANGED
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# layerchart
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Creating a project
|
|
6
|
-
|
|
7
|
-
If you're seeing this, you've probably already done this step. Congrats!
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
# create a new project in the current directory
|
|
11
|
-
npm init svelte@next
|
|
12
|
-
|
|
13
|
-
# create a new project in my-app
|
|
14
|
-
npm init svelte@next my-app
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
> Note: the `@next` is temporary
|
|
18
|
-
|
|
19
|
-
## Developing
|
|
20
|
-
|
|
21
|
-
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm run dev
|
|
25
|
-
|
|
26
|
-
# or start the server and open the app in a new browser tab
|
|
27
|
-
npm run dev -- --open
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Building
|
|
31
|
-
|
|
32
|
-
Before creating a production version of your app, install an [adapter](https://kit.svelte.dev/docs#adapters) for your target environment. Then:
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
npm run build
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
> You can preview the built app with `npm run preview`, regardless of whether you installed an adapter. This should _not_ be used to serve your app in production.
|
|
3
|
+
WIP
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script >/*
|
|
2
|
+
TODO:
|
|
3
|
+
- [ ] Chart usage
|
|
4
|
+
- [x] Track on/off and pass props
|
|
5
|
+
- [x] Text configuration / slot?
|
|
6
|
+
- [ ] Pie usage (second dimension?)
|
|
7
|
+
- [x] style / class (gradient, etc)
|
|
8
|
+
- [ ] Allow spring/tweened to be reactive (but ignore value)
|
|
9
|
+
*/
|
|
10
|
+
// https://caniuse.com/#feat=css-conic-gradients
|
|
11
|
+
// https://css-tricks.com/snippets/css/css-conic-gradient/
|
|
12
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/conic-gradient
|
|
13
|
+
import { arc as d3arc } from 'd3-shape';
|
|
14
|
+
import { scaleLinear } from 'd3-scale';
|
|
15
|
+
import { getMotionStore } from '../stores/motionStore';
|
|
16
|
+
import { degreesToRadians } from '../utils/math';
|
|
17
|
+
export let spring = undefined;
|
|
18
|
+
export let tweened = undefined;
|
|
19
|
+
export let value = 0;
|
|
20
|
+
let tweened_value = getMotionStore(value, { spring, tweened });
|
|
21
|
+
$: tweened_value.set(value);
|
|
22
|
+
export let domain = [0, 100];
|
|
23
|
+
export let range = [0, 360]; // degrees
|
|
24
|
+
export let innerRadius = 50;
|
|
25
|
+
export let outerRadius = 60;
|
|
26
|
+
export let cornerRadius = 10;
|
|
27
|
+
export let padAngle = 0;
|
|
28
|
+
export let padRadius = 0;
|
|
29
|
+
export let track = false;
|
|
30
|
+
$: scale = scaleLinear().domain(domain).range(range);
|
|
31
|
+
$: startAngle = degreesToRadians(range[0]);
|
|
32
|
+
$: endAngle = degreesToRadians(range[1]);
|
|
33
|
+
$: valueAngle = degreesToRadians(scale($tweened_value));
|
|
34
|
+
$: arc = d3arc()
|
|
35
|
+
.innerRadius(innerRadius)
|
|
36
|
+
.outerRadius(outerRadius)
|
|
37
|
+
.startAngle(startAngle)
|
|
38
|
+
.endAngle(valueAngle)
|
|
39
|
+
.cornerRadius(cornerRadius)
|
|
40
|
+
.padAngle(padAngle);
|
|
41
|
+
// .padRadius(padRadius);
|
|
42
|
+
$: trackArc = d3arc()
|
|
43
|
+
.innerRadius(innerRadius)
|
|
44
|
+
.outerRadius(outerRadius)
|
|
45
|
+
.startAngle(startAngle)
|
|
46
|
+
.endAngle(endAngle)
|
|
47
|
+
.cornerRadius(cornerRadius)
|
|
48
|
+
.padAngle(padAngle);
|
|
49
|
+
// .padRadius(padRadius);
|
|
50
|
+
$: trackArcCentroid = trackArc.centroid();
|
|
51
|
+
// $: console.log(trackArcCentroid)
|
|
52
|
+
let trackArcEl;
|
|
53
|
+
$: boundingBox = trackArc && trackArcEl ? trackArcEl.getBBox() : {};
|
|
54
|
+
// $: console.log(boundingBox)
|
|
55
|
+
$: labelArcCenterOffset = {
|
|
56
|
+
x: outerRadius - boundingBox.width / 2,
|
|
57
|
+
// x: 0,
|
|
58
|
+
y: (outerRadius - boundingBox.height / 2) * -1
|
|
59
|
+
};
|
|
60
|
+
// $: console.log(labelArcCenterOffset)
|
|
61
|
+
$: labelArcBottomOffset = {
|
|
62
|
+
// x: outerRadius - boundingBox.width / 2,
|
|
63
|
+
x: outerRadius - boundingBox.width / 2,
|
|
64
|
+
// x: 0,
|
|
65
|
+
// y: (outerRadius - boundingBox.height) * -1
|
|
66
|
+
y: (outerRadius - boundingBox.height) * -1
|
|
67
|
+
};
|
|
68
|
+
// $: console.log(labelArcBottomOffset)
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
{#if track}
|
|
72
|
+
<path d={trackArc()} class="track" bind:this={trackArcEl} {...track} />
|
|
73
|
+
{/if}
|
|
74
|
+
|
|
75
|
+
<path d={arc()} {...$$restProps} />
|
|
76
|
+
|
|
77
|
+
<slot value={$tweened_value} centroid={trackArcCentroid} {boundingBox} />
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
spring?: boolean | Parameters<typeof springStore>[1];
|
|
7
|
+
tweened?: boolean | Parameters<typeof tweenedStore>[1];
|
|
8
|
+
value?: number;
|
|
9
|
+
domain?: number[];
|
|
10
|
+
range?: number[];
|
|
11
|
+
innerRadius?: number;
|
|
12
|
+
outerRadius?: number;
|
|
13
|
+
cornerRadius?: number;
|
|
14
|
+
padAngle?: number;
|
|
15
|
+
padRadius?: number;
|
|
16
|
+
track?: boolean | svelte.JSX.SVGProps<SVGPathElement>;
|
|
17
|
+
};
|
|
18
|
+
events: {
|
|
19
|
+
[evt: string]: CustomEvent<any>;
|
|
20
|
+
};
|
|
21
|
+
slots: {
|
|
22
|
+
default: {
|
|
23
|
+
value: any;
|
|
24
|
+
centroid: [number, number];
|
|
25
|
+
boundingBox: any;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export declare type ArcProps = typeof __propDef.props;
|
|
30
|
+
export declare type ArcEvents = typeof __propDef.events;
|
|
31
|
+
export declare type ArcSlots = typeof __propDef.slots;
|
|
32
|
+
export default class Arc extends SvelteComponentTyped<ArcProps, ArcEvents, ArcSlots> {
|
|
33
|
+
}
|
|
34
|
+
export {};
|
package/components/Area.svelte
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script >import { getContext } from 'svelte';
|
|
2
2
|
import { area as d3Area } from 'd3-shape';
|
|
3
|
+
import { interpolatePath } from 'd3-interpolate-path';
|
|
4
|
+
import { getMotionStore } from '../stores/motionStore';
|
|
3
5
|
import Path from './Path.svelte';
|
|
4
6
|
const { data: contextData, xGet, yGet, yRange } = getContext('LayerCake');
|
|
5
7
|
// Properties to override what is used from context
|
|
@@ -9,28 +11,35 @@ export let y0 = undefined; // TODO: Update Type
|
|
|
9
11
|
export let y1 = undefined; // TODO: Update Type
|
|
10
12
|
export let pathData = undefined;
|
|
11
13
|
export let clipPath = undefined;
|
|
14
|
+
export let tweened = undefined;
|
|
12
15
|
export let curve = undefined;
|
|
13
16
|
export let defined = undefined;
|
|
14
17
|
export let color = 'var(--color-blue-500)';
|
|
15
18
|
export let opacity = 0.3;
|
|
16
19
|
export let line = false;
|
|
17
|
-
$:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
$: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
|
|
21
|
+
$: tweened_d = getMotionStore('', { tweened: tweenedOptions });
|
|
22
|
+
$: {
|
|
23
|
+
const path = d3Area()
|
|
24
|
+
.x(x ?? $xGet)
|
|
25
|
+
.y0(y0 ?? $yRange[0])
|
|
26
|
+
.y1(y1 ?? $yGet);
|
|
27
|
+
if (curve)
|
|
28
|
+
path.curve(curve);
|
|
29
|
+
if (defined)
|
|
30
|
+
path.defined(defined);
|
|
31
|
+
const d = pathData ?? path(data ?? $contextData);
|
|
32
|
+
tweened_d.set(d);
|
|
33
|
+
}
|
|
25
34
|
</script>
|
|
26
35
|
|
|
27
36
|
{#if line}
|
|
28
|
-
<Path {curve} {defined} {color} {...line} />
|
|
37
|
+
<Path {curve} {defined} {color} {tweened} {...line} />
|
|
29
38
|
{/if}
|
|
30
39
|
|
|
31
40
|
<path
|
|
32
41
|
class="path-area"
|
|
33
|
-
d={
|
|
42
|
+
d={$tweened_d}
|
|
34
43
|
clip-path={clipPath}
|
|
35
44
|
fill={color}
|
|
36
45
|
fill-opacity={opacity}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { tweened as tweenedStore } from 'svelte/motion';
|
|
3
|
+
import { Area } from 'd3-shape';
|
|
2
4
|
import type { CurveFactory } from 'd3-shape';
|
|
3
5
|
declare const __propDef: {
|
|
4
6
|
props: {
|
|
@@ -9,8 +11,9 @@ declare const __propDef: {
|
|
|
9
11
|
y1?: any;
|
|
10
12
|
pathData?: string;
|
|
11
13
|
clipPath?: string;
|
|
14
|
+
tweened?: boolean | Parameters<typeof tweenedStore>[1];
|
|
12
15
|
curve?: CurveFactory;
|
|
13
|
-
defined?:
|
|
16
|
+
defined?: Parameters<Area<any>['defined']>[0];
|
|
14
17
|
color?: string;
|
|
15
18
|
opacity?: number;
|
|
16
19
|
line?: boolean | any;
|
package/components/AxisX.svelte
CHANGED
|
@@ -22,7 +22,7 @@ $: tickVals = Array.isArray(ticks)
|
|
|
22
22
|
{#each tickVals as tick, i}
|
|
23
23
|
<g class="tick tick-{tick}" transform="translate({$xScale(tick)},{$yRange[0]})">
|
|
24
24
|
{#if gridlines !== false}
|
|
25
|
-
<line y1={$height * -1} y2="0" x1="0" x2="0" />
|
|
25
|
+
<line y1={$height * -1} y2="0" x1="0" x2="0" {...gridlines} />
|
|
26
26
|
{/if}
|
|
27
27
|
<Text
|
|
28
28
|
x={xTick || isBand ? $xScale.bandwidth() / 2 : 0}
|
package/components/AxisY.svelte
CHANGED
|
@@ -30,6 +30,7 @@ $: tickVals = Array.isArray(ticks)
|
|
|
30
30
|
x2={$width + $padding.left}
|
|
31
31
|
y1={yTick + (isBand ? $yScale.bandwidth() / 2 : 0)}
|
|
32
32
|
y2={yTick + (isBand ? $yScale.bandwidth() / 2 : 0)}
|
|
33
|
+
{...gridlines}
|
|
33
34
|
/>
|
|
34
35
|
{/if}
|
|
35
36
|
<!-- <circle
|
|
@@ -62,8 +63,4 @@ $: tickVals = Array.isArray(ticks)
|
|
|
62
63
|
stroke: #e0e0e0;
|
|
63
64
|
/* stroke-dasharray: 2; */
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
.tick.tick-0 line {
|
|
67
|
-
stroke-dasharray: 0;
|
|
68
|
-
}
|
|
69
66
|
</style>
|
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
<script >import { getContext } from 'svelte';
|
|
2
2
|
import { scaleBand } from 'd3-scale';
|
|
3
3
|
import { max, min } from 'd3-array';
|
|
4
|
-
import Rect from './Rect.svelte';
|
|
5
4
|
import { unique } from 'svelte-ux/utils/array';
|
|
6
|
-
|
|
5
|
+
import Rect from './Rect.svelte';
|
|
6
|
+
const { data, flatData, xGet, yRange, xScale, yScale, x: xContext, y: yContext, rGet, config } = getContext('LayerCake');
|
|
7
|
+
/**
|
|
8
|
+
* Override `x` from context. Useful for multiple Bar instances
|
|
9
|
+
*/
|
|
10
|
+
export let x = $xContext;
|
|
11
|
+
// Convert x to function
|
|
12
|
+
$: _x = x ? (typeof x === 'string' ? (d) => d[x] : x) : $xContext;
|
|
13
|
+
/**
|
|
14
|
+
* Override `y` from context. Useful for multiple Bar instances
|
|
15
|
+
*/
|
|
16
|
+
export let y = $yContext;
|
|
17
|
+
$: _y = y ? (typeof y === 'string' ? (d) => d[y] : y) : $yContext;
|
|
7
18
|
/*
|
|
8
|
-
TODO:
|
|
9
|
-
|
|
10
|
-
- https://layercake.graphics/example/Column
|
|
11
|
-
- https://layercake.graphics/example/BarStacked
|
|
12
|
-
- https://layercake.graphics/example/ColumnStacked
|
|
19
|
+
TODO:
|
|
20
|
+
- [ ] Support vertical/horizontal layout (Bar/Column)
|
|
13
21
|
*/
|
|
14
22
|
export let color = 'var(--color-blue-500)';
|
|
15
23
|
export let opacity = 1;
|
|
16
24
|
export let stroke = 'black';
|
|
17
25
|
export let strokeWidth = 0;
|
|
18
26
|
export let radius = 0;
|
|
19
|
-
export let getKey = (item) =>
|
|
27
|
+
export let getKey = (item) => _x(item);
|
|
20
28
|
export let getProps = undefined;
|
|
29
|
+
export let widthOffset = 0;
|
|
21
30
|
// See: https://svelte.dev/repl/7000c5ce05b84cd98ccbfb2768b4be3d?version=3.38.3
|
|
22
31
|
export let groupBy = undefined;
|
|
23
32
|
// export let delay = 300;
|
|
@@ -26,17 +35,17 @@ $: groupKeys = unique($flatData.map((d) => d[groupBy]));
|
|
|
26
35
|
$: x1Scale = scaleBand().domain(groupKeys).range([0, $xScale.bandwidth()]).paddingInner(0.2);
|
|
27
36
|
$: getDimensions = (item) => {
|
|
28
37
|
// console.log({ item, y: $y(item) });
|
|
29
|
-
const x = $xGet(item) + (groupBy ? x1Scale(item[groupBy]) : 0);
|
|
38
|
+
const x = $xGet(item) + (groupBy ? x1Scale(item[groupBy]) : 0) - widthOffset / 2;
|
|
30
39
|
// TODO: Do we need to support the non-bandwidth scale?
|
|
31
40
|
// const width = $xScale.bandwidth
|
|
32
41
|
// ? $xScale.bandwidth()
|
|
33
42
|
// : Math.max(0, $xGet(d)[1] - $xGet(d)[0]);
|
|
34
|
-
const width = groupBy ? x1Scale.bandwidth() : $xScale.bandwidth();
|
|
35
|
-
const yValue =
|
|
43
|
+
const width = (groupBy ? x1Scale.bandwidth() : $xScale.bandwidth()) + widthOffset;
|
|
44
|
+
const yValue = _y(item);
|
|
36
45
|
let yTop = 0;
|
|
37
46
|
let yBottom = 0;
|
|
38
47
|
if (Array.isArray(yValue)) {
|
|
39
|
-
// Array contains both top and bottom values;
|
|
48
|
+
// Array contains both top and bottom values (stack, etc);
|
|
40
49
|
yTop = max(yValue);
|
|
41
50
|
yBottom = min(yValue);
|
|
42
51
|
}
|
|
@@ -64,7 +73,7 @@ $: getDimensions = (item) => {
|
|
|
64
73
|
};
|
|
65
74
|
function getColor(item, index) {
|
|
66
75
|
if (typeof color === 'function') {
|
|
67
|
-
return color({ value:
|
|
76
|
+
return color({ value: _y(item), item, index });
|
|
68
77
|
}
|
|
69
78
|
else if ($config.r) {
|
|
70
79
|
return $rGet(item);
|
|
@@ -86,7 +95,7 @@ function getColor(item, index) {
|
|
|
86
95
|
stroke-width={strokeWidth}
|
|
87
96
|
rx={radius}
|
|
88
97
|
{...getDimensions(item)}
|
|
89
|
-
{...getProps?.({ value:
|
|
98
|
+
{...getProps?.({ value: _y(item), item, index })}
|
|
90
99
|
{...$$restProps}
|
|
91
100
|
/>
|
|
92
101
|
{/each}
|
|
@@ -2,6 +2,8 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
+
x?: any;
|
|
6
|
+
y?: any;
|
|
5
7
|
color?: string | ((obj: {
|
|
6
8
|
value: any;
|
|
7
9
|
item: any;
|
|
@@ -17,6 +19,7 @@ declare const __propDef: {
|
|
|
17
19
|
item: any;
|
|
18
20
|
index: number;
|
|
19
21
|
}) => any;
|
|
22
|
+
widthOffset?: number;
|
|
20
23
|
groupBy?: string;
|
|
21
24
|
};
|
|
22
25
|
events: {
|
|
@@ -24,9 +27,9 @@ declare const __propDef: {
|
|
|
24
27
|
};
|
|
25
28
|
slots: {};
|
|
26
29
|
};
|
|
27
|
-
export declare type
|
|
28
|
-
export declare type
|
|
29
|
-
export declare type
|
|
30
|
-
export default class
|
|
30
|
+
export declare type BarsProps = typeof __propDef.props;
|
|
31
|
+
export declare type BarsEvents = typeof __propDef.events;
|
|
32
|
+
export declare type BarsSlots = typeof __propDef.slots;
|
|
33
|
+
export default class Bars extends SvelteComponentTyped<BarsProps, BarsEvents, BarsSlots> {
|
|
31
34
|
}
|
|
32
35
|
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script >/*
|
|
2
|
+
TODO:
|
|
3
|
+
- [ ] Consider becoming LinkLine using d3-path buider https://github.com/d3/d3-path
|
|
4
|
+
- https://github.com/airbnb/visx/blob/master/packages/visx-shape/src/shapes/link/line/LinkHorizontalLine.tsx
|
|
5
|
+
*/
|
|
6
|
+
import { getContext } from 'svelte';
|
|
7
|
+
import { extent } from 'd3-array';
|
|
8
|
+
import Line from './Line.svelte';
|
|
9
|
+
const context = getContext('LayerCake');
|
|
10
|
+
const { data, xGet, yGet, config } = context;
|
|
11
|
+
export let offsetX = 0;
|
|
12
|
+
export let offsetY = 0;
|
|
13
|
+
function getOffset(value, offset) {
|
|
14
|
+
if (typeof offset === 'function') {
|
|
15
|
+
return offset(value, context);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return offset;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
$: points = $data.flatMap((d) => {
|
|
22
|
+
if (Array.isArray($config.x)) {
|
|
23
|
+
/*
|
|
24
|
+
x={["prop1" ,"prop2"]}
|
|
25
|
+
y="prop3"
|
|
26
|
+
*/
|
|
27
|
+
const [xMin, xMax] = extent($xGet(d));
|
|
28
|
+
return {
|
|
29
|
+
x1: xMin + getOffset(xMin, offsetX),
|
|
30
|
+
y1: $yGet(d) + getOffset($yGet(d), offsetY),
|
|
31
|
+
x2: xMax + getOffset(xMax, offsetX),
|
|
32
|
+
y2: $yGet(d) + getOffset($yGet(d), offsetY)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
else if (Array.isArray($config.y)) {
|
|
36
|
+
/*
|
|
37
|
+
x="prop1"
|
|
38
|
+
y={["prop2" ,"prop3"]}
|
|
39
|
+
*/
|
|
40
|
+
const [yMin, yMax] = extent($yGet(d));
|
|
41
|
+
return {
|
|
42
|
+
x1: $xGet(d) + getOffset($xGet(d), offsetX),
|
|
43
|
+
y1: yMin + getOffset(yMin, offsetY),
|
|
44
|
+
x2: $xGet(d) + getOffset($xGet(d), offsetX),
|
|
45
|
+
y2: yMax + getOffset(yMax, offsetY)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
/*
|
|
50
|
+
x="prop1"
|
|
51
|
+
y="prop2"
|
|
52
|
+
*/
|
|
53
|
+
// Not really supported (nothing to connect...)
|
|
54
|
+
return {
|
|
55
|
+
x1: $xGet(d) + getOffset($xGet(d), offsetX),
|
|
56
|
+
y1: $yGet(d) + getOffset($yGet(d), offsetY),
|
|
57
|
+
x2: $xGet(d) + getOffset($xGet(d), offsetX),
|
|
58
|
+
y2: $yGet(d) + getOffset($yGet(d), offsetY)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<g class="connected-points">
|
|
65
|
+
{#each points as p}
|
|
66
|
+
<Line x1={p.x1} y1={p.y1} x2={p.x2} y2={p.y2} {...$$restProps} />
|
|
67
|
+
{/each}
|
|
68
|
+
</g>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
offsetX?: number | ((value: number, context: any) => number);
|
|
6
|
+
offsetY?: number | ((value: number, context: any) => number);
|
|
7
|
+
};
|
|
8
|
+
events: {
|
|
9
|
+
[evt: string]: CustomEvent<any>;
|
|
10
|
+
};
|
|
11
|
+
slots: {};
|
|
12
|
+
};
|
|
13
|
+
export declare type ConnectedPointsProps = typeof __propDef.props;
|
|
14
|
+
export declare type ConnectedPointsEvents = typeof __propDef.events;
|
|
15
|
+
export declare type ConnectedPointsSlots = typeof __propDef.slots;
|
|
16
|
+
export default class ConnectedPoints extends SvelteComponentTyped<ConnectedPointsProps, ConnectedPointsEvents, ConnectedPointsSlots> {
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script >import { getContext } from 'svelte';
|
|
2
|
+
/**
|
|
3
|
+
* Translate x
|
|
4
|
+
*/
|
|
5
|
+
export let x;
|
|
6
|
+
/**
|
|
7
|
+
* Translate x
|
|
8
|
+
*/
|
|
9
|
+
export let y;
|
|
10
|
+
/**
|
|
11
|
+
* Center within chart
|
|
12
|
+
*/
|
|
13
|
+
export let center;
|
|
14
|
+
const { width, height } = getContext('LayerCake');
|
|
15
|
+
let transform = undefined;
|
|
16
|
+
$: if (x != null || y != null) {
|
|
17
|
+
transform = `translate(${x ?? 0}, ${y ?? 0})`;
|
|
18
|
+
}
|
|
19
|
+
$: if (center) {
|
|
20
|
+
transform = `translate(${$width / 2}, ${$height / 2})`;
|
|
21
|
+
}
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<g {transform} {...$$restProps}>
|
|
25
|
+
<slot />
|
|
26
|
+
</g>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
center: boolean;
|
|
8
|
+
};
|
|
9
|
+
events: {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {
|
|
13
|
+
default: {};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare type GroupProps = typeof __propDef.props;
|
|
17
|
+
export declare type GroupEvents = typeof __propDef.events;
|
|
18
|
+
export declare type GroupSlots = typeof __propDef.slots;
|
|
19
|
+
export default class Group extends SvelteComponentTyped<GroupProps, GroupEvents, GroupSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
data: any;
|
|
5
|
+
};
|
|
6
|
+
events: {
|
|
7
|
+
click: MouseEvent;
|
|
8
|
+
} & {
|
|
9
|
+
[evt: string]: CustomEvent<any>;
|
|
10
|
+
};
|
|
11
|
+
slots: {};
|
|
12
|
+
};
|
|
13
|
+
export declare type HighlightRectProps = typeof __propDef.props;
|
|
14
|
+
export declare type HighlightRectEvents = typeof __propDef.events;
|
|
15
|
+
export declare type HighlightRectSlots = typeof __propDef.slots;
|
|
16
|
+
export default class HighlightRect extends SvelteComponentTyped<HighlightRectProps, HighlightRectEvents, HighlightRectSlots> {
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
File without changes
|
|
@@ -14,9 +14,9 @@ declare const __propDef: {
|
|
|
14
14
|
};
|
|
15
15
|
slots: {};
|
|
16
16
|
};
|
|
17
|
-
export declare type
|
|
18
|
-
export declare type
|
|
19
|
-
export declare type
|
|
20
|
-
export default class
|
|
17
|
+
export declare type LabelsProps = typeof __propDef.props;
|
|
18
|
+
export declare type LabelsEvents = typeof __propDef.events;
|
|
19
|
+
export declare type LabelsSlots = typeof __propDef.slots;
|
|
20
|
+
export default class Labels extends SvelteComponentTyped<LabelsProps, LabelsEvents, LabelsSlots> {
|
|
21
21
|
}
|
|
22
22
|
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script >export let id;
|
|
2
|
+
export let from;
|
|
3
|
+
export let to;
|
|
4
|
+
export let vertical = false;
|
|
5
|
+
export let x1 = '0%';
|
|
6
|
+
export let y1 = '0%';
|
|
7
|
+
export let x2 = vertical ? '0%' : '100%';
|
|
8
|
+
export let y2 = vertical ? '100%' : '0%';
|
|
9
|
+
export let rotate = undefined;
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<defs>
|
|
13
|
+
<linearGradient
|
|
14
|
+
{id}
|
|
15
|
+
{x1}
|
|
16
|
+
{y1}
|
|
17
|
+
{x2}
|
|
18
|
+
{y2}
|
|
19
|
+
gradientTransform={rotate ? `rotate(${rotate})` : ''}
|
|
20
|
+
{...$$restProps}
|
|
21
|
+
>
|
|
22
|
+
<slot>
|
|
23
|
+
<stop offset="0%" stop-color={from} />
|
|
24
|
+
<stop offset="100%" stop-color={to} />
|
|
25
|
+
</slot>
|
|
26
|
+
</linearGradient>
|
|
27
|
+
</defs>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
id: string;
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
vertical?: boolean;
|
|
9
|
+
x1?: string;
|
|
10
|
+
y1?: string;
|
|
11
|
+
x2?: string;
|
|
12
|
+
y2?: string;
|
|
13
|
+
rotate?: number;
|
|
14
|
+
};
|
|
15
|
+
events: {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
};
|
|
18
|
+
slots: {
|
|
19
|
+
default: {};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare type LinearGradientProps = typeof __propDef.props;
|
|
23
|
+
export declare type LinearGradientEvents = typeof __propDef.events;
|
|
24
|
+
export declare type LinearGradientSlots = typeof __propDef.slots;
|
|
25
|
+
export default class LinearGradient extends SvelteComponentTyped<LinearGradientProps, LinearGradientEvents, LinearGradientSlots> {
|
|
26
|
+
}
|
|
27
|
+
export {};
|
package/components/Path.svelte
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
<script >import { getContext } from 'svelte';
|
|
2
2
|
import { line as d3Line } from 'd3-shape';
|
|
3
|
+
// import { interpolateString } from 'd3-interpolate';
|
|
4
|
+
import { interpolatePath } from 'd3-interpolate-path';
|
|
5
|
+
import { getMotionStore } from '../stores/motionStore';
|
|
3
6
|
const { data: contextData, xGet, yGet, zGet } = getContext('LayerCake');
|
|
4
7
|
// Properties to override what is used from context
|
|
5
8
|
export let data = undefined; // TODO: Update Type
|
|
6
9
|
export let x = undefined; // TODO: Update Type
|
|
7
10
|
export let y = undefined; // TODO: Update Type
|
|
8
11
|
export let pathData = undefined;
|
|
12
|
+
export let tweened = undefined;
|
|
9
13
|
export let curve = undefined;
|
|
10
14
|
export let defined = undefined;
|
|
11
|
-
export let color = '
|
|
15
|
+
export let color = 'black';
|
|
12
16
|
export let width = undefined;
|
|
13
|
-
$:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
$: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
|
|
18
|
+
$: tweened_d = getMotionStore('', { tweened: tweenedOptions });
|
|
19
|
+
$: {
|
|
20
|
+
const path = d3Line()
|
|
21
|
+
.x(x ?? $xGet)
|
|
22
|
+
.y(y ?? $yGet);
|
|
23
|
+
if (curve)
|
|
24
|
+
path.curve(curve);
|
|
25
|
+
if (defined)
|
|
26
|
+
path.defined(defined);
|
|
27
|
+
const d = pathData ?? path(data ?? $contextData);
|
|
28
|
+
tweened_d.set(d);
|
|
29
|
+
}
|
|
20
30
|
</script>
|
|
21
31
|
|
|
22
|
-
<path
|
|
23
|
-
class="path-line"
|
|
24
|
-
d={pathData ?? path(data ?? $contextData)}
|
|
25
|
-
stroke={color}
|
|
26
|
-
stroke-width={width}
|
|
27
|
-
{...$$restProps}
|
|
28
|
-
/>
|
|
32
|
+
<path class="path-line" d={$tweened_d} stroke={color} stroke-width={width} {...$$restProps} />
|
|
29
33
|
|
|
30
34
|
<style >
|
|
31
35
|
.path-line {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type {
|
|
2
|
+
import type { tweened as tweenedStore } from 'svelte/motion';
|
|
3
|
+
import type { CurveFactory, CurveFactoryLineOnly, Line } from 'd3-shape';
|
|
3
4
|
declare const __propDef: {
|
|
4
5
|
props: {
|
|
5
6
|
[x: string]: any;
|
|
@@ -7,8 +8,9 @@ declare const __propDef: {
|
|
|
7
8
|
x?: any;
|
|
8
9
|
y?: any;
|
|
9
10
|
pathData?: string;
|
|
11
|
+
tweened?: boolean | Parameters<typeof tweenedStore>[1];
|
|
10
12
|
curve?: CurveFactory | CurveFactoryLineOnly;
|
|
11
|
-
defined?:
|
|
13
|
+
defined?: Parameters<Line<any>['defined']>[0];
|
|
12
14
|
color?: string;
|
|
13
15
|
width?: any;
|
|
14
16
|
};
|