layerchart 0.0.1 → 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 +47 -0
- package/components/Area.svelte.d.ts +31 -0
- package/components/AreaStack.svelte +40 -0
- package/components/AreaStack.svelte.d.ts +20 -0
- package/components/AxisX.svelte +52 -0
- package/components/AxisX.svelte.d.ts +23 -0
- package/components/AxisY.svelte +66 -0
- package/components/AxisY.svelte.d.ts +23 -0
- package/components/Bars.svelte +102 -0
- package/components/Bars.svelte.d.ts +35 -0
- package/components/Baseline.svelte +21 -0
- package/components/Baseline.svelte.d.ts +17 -0
- package/components/Chart.svelte +50 -0
- package/components/Chart.svelte.d.ts +24 -0
- package/components/Circle.svelte +15 -0
- package/components/Circle.svelte.d.ts +22 -0
- 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/HighlightLine.svelte +52 -0
- package/components/HighlightLine.svelte.d.ts +17 -0
- package/components/HighlightRect.svelte +27 -0
- package/components/HighlightRect.svelte.d.ts +18 -0
- package/components/Labels.svelte +96 -0
- package/components/Labels.svelte.d.ts +22 -0
- package/components/Line.svelte +18 -0
- package/components/Line.svelte.d.ts +23 -0
- package/components/LinearGradient.svelte +27 -0
- package/components/LinearGradient.svelte.d.ts +27 -0
- package/components/Path.svelte +40 -0
- package/components/Path.svelte.d.ts +27 -0
- package/components/Points.svelte +58 -0
- package/components/Points.svelte.d.ts +19 -0
- package/components/Rect.svelte +25 -0
- package/components/Rect.svelte.d.ts +25 -0
- package/components/Text.svelte +129 -0
- package/components/Text.svelte.d.ts +28 -0
- package/components/Threshold.svelte +86 -0
- package/components/Threshold.svelte.d.ts +35 -0
- package/components/Tooltip.svelte +120 -0
- package/components/Tooltip.svelte.d.ts +33 -0
- package/components/index.d.ts +19 -0
- package/components/index.js +19 -0
- package/docs/Blockquote.svelte +7 -0
- package/docs/Blockquote.svelte.d.ts +23 -0
- package/docs/Code.svelte +6 -0
- package/docs/Code.svelte.d.ts +23 -0
- package/docs/Layout.svelte +20 -0
- package/docs/Layout.svelte.d.ts +29 -0
- package/docs/Link.svelte +7 -0
- package/docs/Link.svelte.d.ts +27 -0
- package/docs/Preview.svelte +23 -0
- package/docs/Preview.svelte.d.ts +21 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/package.json +84 -26
- package/stores/motionStore.d.ts +8 -0
- package/stores/motionStore.js +16 -0
- package/utils/event.d.ts +4 -0
- package/utils/event.js +42 -0
- package/utils/genData.d.ts +32 -0
- package/utils/genData.js +59 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -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.d.ts +14 -0
- package/utils/pivot.js +36 -0
- package/utils/scales.d.ts +10 -0
- package/utils/scales.js +21 -0
- package/utils/stack.d.ts +14 -0
- package/utils/stack.js +69 -0
- package/utils/string.d.ts +4 -0
- package/utils/string.js +27 -0
- package/utils/ticks.d.ts +3 -0
- package/utils/ticks.js +157 -0
- package/.prettierrc +0 -6
- package/src/app.html +0 -12
- package/src/global.d.ts +0 -1
- package/src/routes/index.svelte +0 -2
- package/static/favicon.png +0 -0
- package/svelte.config.js +0 -15
- package/tsconfig.json +0 -31
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import { Svg, Html } from 'layercake';
|
|
3
|
+
export { Svg, Html };
|
|
4
|
+
declare const __propDef: {
|
|
5
|
+
props: {
|
|
6
|
+
[x: string]: any;
|
|
7
|
+
data?: any[];
|
|
8
|
+
x: (string | ((d: any) => number)) | (string | ((d: any) => number))[];
|
|
9
|
+
y: (string | ((d: any) => number)) | (string | ((d: any) => number))[];
|
|
10
|
+
xBaseline?: number | null;
|
|
11
|
+
yBaseline?: number | null;
|
|
12
|
+
};
|
|
13
|
+
events: {
|
|
14
|
+
[evt: string]: CustomEvent<any>;
|
|
15
|
+
};
|
|
16
|
+
slots: {
|
|
17
|
+
default: {};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export declare type ChartProps = typeof __propDef.props;
|
|
21
|
+
export declare type ChartEvents = typeof __propDef.events;
|
|
22
|
+
export declare type ChartSlots = typeof __propDef.slots;
|
|
23
|
+
export default class Chart extends SvelteComponentTyped<ChartProps, ChartEvents, ChartSlots> {
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script >import { getMotionStore } from '../stores/motionStore';
|
|
2
|
+
export let cx;
|
|
3
|
+
export let cy;
|
|
4
|
+
export let r;
|
|
5
|
+
export let spring = undefined;
|
|
6
|
+
export let tweened = undefined;
|
|
7
|
+
let tweened_cx = getMotionStore(cx, { spring, tweened });
|
|
8
|
+
let tweened_cy = getMotionStore(cy, { spring, tweened });
|
|
9
|
+
let tweened_r = getMotionStore(r, { spring, tweened });
|
|
10
|
+
$: tweened_cx.set(cx);
|
|
11
|
+
$: tweened_cy.set(cy);
|
|
12
|
+
$: tweened_r.set(r);
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<circle cx={$tweened_cx} cy={$tweened_cy} r={$tweened_r} {...$$restProps} />
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
cx: number;
|
|
7
|
+
cy: number;
|
|
8
|
+
r: number;
|
|
9
|
+
spring?: boolean | Parameters<typeof springStore>[1];
|
|
10
|
+
tweened?: boolean | Parameters<typeof tweenedStore>[1];
|
|
11
|
+
};
|
|
12
|
+
events: {
|
|
13
|
+
[evt: string]: CustomEvent<any>;
|
|
14
|
+
};
|
|
15
|
+
slots: {};
|
|
16
|
+
};
|
|
17
|
+
export declare type CircleProps = typeof __propDef.props;
|
|
18
|
+
export declare type CircleEvents = typeof __propDef.events;
|
|
19
|
+
export declare type CircleSlots = typeof __propDef.slots;
|
|
20
|
+
export default class Circle extends SvelteComponentTyped<CircleProps, CircleEvents, CircleSlots> {
|
|
21
|
+
}
|
|
22
|
+
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 {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script >import { getContext } from 'svelte';
|
|
2
|
+
import { get } from 'svelte/store';
|
|
3
|
+
import Circle from './Circle.svelte';
|
|
4
|
+
import Line from './Line.svelte';
|
|
5
|
+
export let data;
|
|
6
|
+
export let color = undefined;
|
|
7
|
+
const { xGet, yScale, yRange, yGet, zScale, padding } = getContext('LayerCake');
|
|
8
|
+
// TODO: Fix circle points being backwards for stack (see AreaStack)
|
|
9
|
+
$: x = $xGet(data);
|
|
10
|
+
function getColor(index) {
|
|
11
|
+
return color ?? get(zScale)(index) ?? 'var(--color-blue-500)';
|
|
12
|
+
}
|
|
13
|
+
$: points = Array.isArray(data)
|
|
14
|
+
? // Stack series
|
|
15
|
+
data.map((yValue, i) => ({
|
|
16
|
+
x,
|
|
17
|
+
y: $yScale(yValue),
|
|
18
|
+
color: getColor(i)
|
|
19
|
+
}))
|
|
20
|
+
: [
|
|
21
|
+
{
|
|
22
|
+
x,
|
|
23
|
+
y: $yGet(data) - $padding.top,
|
|
24
|
+
color: getColor(0)
|
|
25
|
+
}
|
|
26
|
+
];
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<Line
|
|
30
|
+
spring
|
|
31
|
+
x1={x}
|
|
32
|
+
y1={0}
|
|
33
|
+
x2={x}
|
|
34
|
+
y2={$yRange[0]}
|
|
35
|
+
stroke="rgba(0,0,0,.5)"
|
|
36
|
+
stroke-width={2}
|
|
37
|
+
style="pointerEvents: none"
|
|
38
|
+
stroke-dasharray="2,2"
|
|
39
|
+
/>
|
|
40
|
+
|
|
41
|
+
{#each points as point}
|
|
42
|
+
<Circle
|
|
43
|
+
spring
|
|
44
|
+
cx={point.x}
|
|
45
|
+
cy={point.y}
|
|
46
|
+
r={7}
|
|
47
|
+
fill="rgba(255,255,255,.9)"
|
|
48
|
+
stroke={point.color}
|
|
49
|
+
stroke-width={2}
|
|
50
|
+
/>
|
|
51
|
+
<Circle spring cx={point.x} cy={point.y} r={3} fill={point.color} />
|
|
52
|
+
{/each}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
data: any;
|
|
5
|
+
color?: any;
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {};
|
|
11
|
+
};
|
|
12
|
+
export declare type HighlightLineProps = typeof __propDef.props;
|
|
13
|
+
export declare type HighlightLineEvents = typeof __propDef.events;
|
|
14
|
+
export declare type HighlightLineSlots = typeof __propDef.slots;
|
|
15
|
+
export default class HighlightLine extends SvelteComponentTyped<HighlightLineProps, HighlightLineEvents, HighlightLineSlots> {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script >import { getContext } from 'svelte';
|
|
2
|
+
import { isScaleBand } from '../utils/scales';
|
|
3
|
+
import Rect from './Rect.svelte';
|
|
4
|
+
export let data;
|
|
5
|
+
const { flatData, xScale, x, xGet, yRange, padding } = getContext('LayerCake');
|
|
6
|
+
$: isBand = isScaleBand($xScale);
|
|
7
|
+
let width = 0;
|
|
8
|
+
$: if (isBand) {
|
|
9
|
+
width = $xScale.step();
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
// Find width to next data point
|
|
13
|
+
let index = $flatData.findIndex((d) => Number($x(d)) === Number($x(data)));
|
|
14
|
+
let nextDataPoint = $x($flatData[index + 1]);
|
|
15
|
+
width = ($xScale(nextDataPoint) ?? 0) - ($xGet(data) ?? 0);
|
|
16
|
+
}
|
|
17
|
+
$: dimensions = {
|
|
18
|
+
x: $xGet(data) - (isBand ? ($xScale.padding() * $xScale.step()) / 2 : 0),
|
|
19
|
+
y: -$padding.top,
|
|
20
|
+
width,
|
|
21
|
+
height: $yRange[0]
|
|
22
|
+
};
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
{#if Number.isFinite(dimensions.x)}
|
|
26
|
+
<Rect spring {...dimensions} fill="rgba(0,0,0,.1)" on:click />
|
|
27
|
+
{/if}
|
|
@@ -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 {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<script >/*
|
|
2
|
+
* TODO
|
|
3
|
+
* - [ ] Support step curves (center like scaleBand())
|
|
4
|
+
* - [ ] Support multiple values (threshold, stacks, etc)
|
|
5
|
+
*/
|
|
6
|
+
import { getContext } from 'svelte';
|
|
7
|
+
import { scaleBand } from 'd3-scale';
|
|
8
|
+
import { max, min } from 'd3-array';
|
|
9
|
+
import Text from './Text.svelte';
|
|
10
|
+
import { formatNumberAsStyle } from 'svelte-ux/utils/number';
|
|
11
|
+
import { isScaleBand } from '../utils/scales';
|
|
12
|
+
import { greatestAbs, unique } from 'svelte-ux/utils/array';
|
|
13
|
+
const { data, flatData, xGet, yRange, xScale, yScale, x, y, custom } = getContext('LayerCake');
|
|
14
|
+
export let orientation = 'auto';
|
|
15
|
+
export let significantDigits = 3;
|
|
16
|
+
export let formatStyle = null;
|
|
17
|
+
export let overlap = false;
|
|
18
|
+
$: yBaseline = $custom?.yBaseline ?? 0;
|
|
19
|
+
export let groupBy = undefined;
|
|
20
|
+
const x1Scale = scaleBand();
|
|
21
|
+
$: if (isScaleBand($xScale) && groupBy) {
|
|
22
|
+
const groupKeys = unique($flatData.map((d) => d[groupBy]));
|
|
23
|
+
x1Scale.domain(groupKeys).range([0, $xScale.bandwidth()]).paddingInner(0.2);
|
|
24
|
+
}
|
|
25
|
+
$: getDimensions = (item) => {
|
|
26
|
+
// console.log({ item, y: $y(item) });
|
|
27
|
+
let x = $xGet(item);
|
|
28
|
+
let width = 0;
|
|
29
|
+
if (isScaleBand($xScale)) {
|
|
30
|
+
width = groupBy ? x1Scale.bandwidth() : $xScale.bandwidth();
|
|
31
|
+
x += (groupBy ? x1Scale(item[groupBy]) : 0) + width / 2;
|
|
32
|
+
}
|
|
33
|
+
const yValue = $y(item);
|
|
34
|
+
let yTop = 0;
|
|
35
|
+
let yBottom = 0;
|
|
36
|
+
if (Array.isArray(yValue)) {
|
|
37
|
+
// Array contains both top and bottom values;
|
|
38
|
+
yTop = max(yValue);
|
|
39
|
+
yBottom = min(yValue);
|
|
40
|
+
}
|
|
41
|
+
else if (yValue == null) {
|
|
42
|
+
// null/undefined value
|
|
43
|
+
yTop = 0;
|
|
44
|
+
yBottom = 0;
|
|
45
|
+
}
|
|
46
|
+
else if (yValue > 0) {
|
|
47
|
+
// Positive value
|
|
48
|
+
yTop = yValue;
|
|
49
|
+
yBottom = $yRange[1]; // or `0`?
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// Negative value
|
|
53
|
+
yTop = $yRange[1]; // or `0`?
|
|
54
|
+
yBottom = yValue;
|
|
55
|
+
}
|
|
56
|
+
if (yBottom < 0) {
|
|
57
|
+
// Show label below
|
|
58
|
+
return {
|
|
59
|
+
x,
|
|
60
|
+
y: $yScale(yBottom),
|
|
61
|
+
dy: '0.5em',
|
|
62
|
+
width
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// Show label above
|
|
67
|
+
return {
|
|
68
|
+
x,
|
|
69
|
+
y: $yScale(yTop),
|
|
70
|
+
dy: '-0.6em',
|
|
71
|
+
width
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
$: getValue = (item) => {
|
|
76
|
+
const value = $y(item);
|
|
77
|
+
const labelValue = Array.isArray(value) ? greatestAbs(value) : value;
|
|
78
|
+
return labelValue != null
|
|
79
|
+
? formatNumberAsStyle(labelValue + yBaseline, formatStyle, 0, significantDigits) ?? ''
|
|
80
|
+
: '';
|
|
81
|
+
};
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<g class="label-group">
|
|
85
|
+
{#each $data as item, index}
|
|
86
|
+
<Text
|
|
87
|
+
class="group-rect"
|
|
88
|
+
textAnchor="middle"
|
|
89
|
+
verticalAnchor="middle"
|
|
90
|
+
value={getValue(item)}
|
|
91
|
+
style="font-size: 0.7em"
|
|
92
|
+
{...getDimensions(item)}
|
|
93
|
+
{...$$restProps}
|
|
94
|
+
/>
|
|
95
|
+
{/each}
|
|
96
|
+
</g>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import { FormatNumberStyle } from 'svelte-ux/utils/number';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
orientation?: 'outside' | 'inside' | 'auto';
|
|
7
|
+
significantDigits?: number;
|
|
8
|
+
formatStyle?: FormatNumberStyle;
|
|
9
|
+
overlap?: boolean;
|
|
10
|
+
groupBy?: string;
|
|
11
|
+
};
|
|
12
|
+
events: {
|
|
13
|
+
[evt: string]: CustomEvent<any>;
|
|
14
|
+
};
|
|
15
|
+
slots: {};
|
|
16
|
+
};
|
|
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
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<script >import { getMotionStore } from '../stores/motionStore';
|
|
2
|
+
export let x1;
|
|
3
|
+
export let y1;
|
|
4
|
+
export let x2;
|
|
5
|
+
export let y2;
|
|
6
|
+
export let spring = undefined;
|
|
7
|
+
export let tweened = undefined;
|
|
8
|
+
let tweened_x1 = getMotionStore(x1, { spring, tweened });
|
|
9
|
+
let tweened_y1 = getMotionStore(y1, { spring, tweened });
|
|
10
|
+
let tweened_x2 = getMotionStore(x2, { spring, tweened });
|
|
11
|
+
let tweened_y2 = getMotionStore(y2, { spring, tweened });
|
|
12
|
+
$: tweened_x1.set(x1);
|
|
13
|
+
$: tweened_y1.set(y1);
|
|
14
|
+
$: tweened_x2.set(x2);
|
|
15
|
+
$: tweened_y2.set(y2);
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<line x1={$tweened_x1} y1={$tweened_y1} x2={$tweened_x2} y2={$tweened_y2} {...$$restProps} />
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
x1: number;
|
|
7
|
+
y1: number;
|
|
8
|
+
x2: number;
|
|
9
|
+
y2: number;
|
|
10
|
+
spring?: boolean | Parameters<typeof springStore>[1];
|
|
11
|
+
tweened?: boolean | Parameters<typeof tweenedStore>[1];
|
|
12
|
+
};
|
|
13
|
+
events: {
|
|
14
|
+
[evt: string]: CustomEvent<any>;
|
|
15
|
+
};
|
|
16
|
+
slots: {};
|
|
17
|
+
};
|
|
18
|
+
export declare type LineProps = typeof __propDef.props;
|
|
19
|
+
export declare type LineEvents = typeof __propDef.events;
|
|
20
|
+
export declare type LineSlots = typeof __propDef.slots;
|
|
21
|
+
export default class Line extends SvelteComponentTyped<LineProps, LineEvents, LineSlots> {
|
|
22
|
+
}
|
|
23
|
+
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 {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script >import { getContext } from 'svelte';
|
|
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';
|
|
6
|
+
const { data: contextData, xGet, yGet, zGet } = getContext('LayerCake');
|
|
7
|
+
// Properties to override what is used from context
|
|
8
|
+
export let data = undefined; // TODO: Update Type
|
|
9
|
+
export let x = undefined; // TODO: Update Type
|
|
10
|
+
export let y = undefined; // TODO: Update Type
|
|
11
|
+
export let pathData = undefined;
|
|
12
|
+
export let tweened = undefined;
|
|
13
|
+
export let curve = undefined;
|
|
14
|
+
export let defined = undefined;
|
|
15
|
+
export let color = 'black';
|
|
16
|
+
export let width = undefined;
|
|
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
|
+
}
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<path class="path-line" d={$tweened_d} stroke={color} stroke-width={width} {...$$restProps} />
|
|
33
|
+
|
|
34
|
+
<style >
|
|
35
|
+
.path-line {
|
|
36
|
+
fill: none;
|
|
37
|
+
stroke-linejoin: round;
|
|
38
|
+
stroke-linecap: round;
|
|
39
|
+
}
|
|
40
|
+
</style>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { tweened as tweenedStore } from 'svelte/motion';
|
|
3
|
+
import type { CurveFactory, CurveFactoryLineOnly, Line } from 'd3-shape';
|
|
4
|
+
declare const __propDef: {
|
|
5
|
+
props: {
|
|
6
|
+
[x: string]: any;
|
|
7
|
+
data?: any;
|
|
8
|
+
x?: any;
|
|
9
|
+
y?: any;
|
|
10
|
+
pathData?: string;
|
|
11
|
+
tweened?: boolean | Parameters<typeof tweenedStore>[1];
|
|
12
|
+
curve?: CurveFactory | CurveFactoryLineOnly;
|
|
13
|
+
defined?: Parameters<Line<any>['defined']>[0];
|
|
14
|
+
color?: string;
|
|
15
|
+
width?: any;
|
|
16
|
+
};
|
|
17
|
+
events: {
|
|
18
|
+
[evt: string]: CustomEvent<any>;
|
|
19
|
+
};
|
|
20
|
+
slots: {};
|
|
21
|
+
};
|
|
22
|
+
export declare type PathProps = typeof __propDef.props;
|
|
23
|
+
export declare type PathEvents = typeof __propDef.events;
|
|
24
|
+
export declare type PathSlots = typeof __propDef.slots;
|
|
25
|
+
export default class Path extends SvelteComponentTyped<PathProps, PathEvents, PathSlots> {
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<script >import { getContext } from 'svelte';
|
|
2
|
+
import Circle from './Circle.svelte';
|
|
3
|
+
const context = getContext('LayerCake');
|
|
4
|
+
const { data, xGet, yGet, config } = context;
|
|
5
|
+
export let r = 5;
|
|
6
|
+
export let offsetX = 0;
|
|
7
|
+
export let offsetY = 0;
|
|
8
|
+
function getOffset(value, offset) {
|
|
9
|
+
if (typeof offset === 'function') {
|
|
10
|
+
return offset(value, context);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return offset;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
$: points = $data.flatMap((d) => {
|
|
17
|
+
if (Array.isArray($config.x)) {
|
|
18
|
+
/*
|
|
19
|
+
x={["prop1" ,"prop2"]}
|
|
20
|
+
y="prop3"
|
|
21
|
+
*/
|
|
22
|
+
return $xGet(d).map((x) => {
|
|
23
|
+
return {
|
|
24
|
+
x: x + getOffset(x, offsetX),
|
|
25
|
+
y: $yGet(d) + getOffset($yGet(d), offsetY)
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else if (Array.isArray($config.y)) {
|
|
30
|
+
/*
|
|
31
|
+
x="prop1"
|
|
32
|
+
y={["prop2" ,"prop3"]}
|
|
33
|
+
*/
|
|
34
|
+
return $yGet(d).map((y) => {
|
|
35
|
+
return {
|
|
36
|
+
x: $xGet(d) + getOffset($xGet(d), offsetX),
|
|
37
|
+
y: y + getOffset(y, offsetY)
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
/*
|
|
43
|
+
x="prop1"
|
|
44
|
+
y="prop2"
|
|
45
|
+
*/
|
|
46
|
+
return {
|
|
47
|
+
x: $xGet(d) + getOffset($xGet(d), offsetX),
|
|
48
|
+
y: $yGet(d) + getOffset($yGet(d), offsetY)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<g class="point-group">
|
|
55
|
+
{#each points as p}
|
|
56
|
+
<Circle cx={p.x} cy={p.y} {r} {...$$restProps} />
|
|
57
|
+
{/each}
|
|
58
|
+
</g>
|