layerchart 0.0.1 → 0.0.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/Area.svelte +38 -0
- package/components/Area.svelte.d.ts +28 -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 +69 -0
- package/components/AxisY.svelte.d.ts +23 -0
- package/components/Bar.svelte +93 -0
- package/components/Bar.svelte.d.ts +32 -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/ClevelandDotPlot.svelte +44 -0
- package/components/ClevelandDotPlot.svelte.d.ts +21 -0
- package/components/HighlightBar.svelte +27 -0
- package/components/HighlightBar.svelte.d.ts +18 -0
- package/components/HighlightLine.svelte +52 -0
- package/components/HighlightLine.svelte.d.ts +17 -0
- package/components/Label.svelte +96 -0
- package/components/Label.svelte.d.ts +22 -0
- package/components/Line.svelte +18 -0
- package/components/Line.svelte.d.ts +23 -0
- package/components/Path.svelte +36 -0
- package/components/Path.svelte.d.ts +25 -0
- package/components/Rect.svelte +25 -0
- package/components/Rect.svelte.d.ts +25 -0
- package/components/Scatter.svelte +25 -0
- package/components/Scatter.svelte.d.ts +33 -0
- package/components/Text.svelte +129 -0
- package/components/Text.svelte.d.ts +28 -0
- package/components/Threshold.svelte +83 -0
- package/components/Threshold.svelte.d.ts +35 -0
- package/components/Tooltip.svelte +120 -0
- package/components/Tooltip.svelte.d.ts +33 -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 +19 -0
- package/docs/Preview.svelte.d.ts +19 -0
- package/package.json +73 -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 +19 -0
- package/utils/genData.js +35 -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/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,38 @@
|
|
|
1
|
+
<script >import { getContext } from 'svelte';
|
|
2
|
+
import { area as d3Area } from 'd3-shape';
|
|
3
|
+
import Path from './Path.svelte';
|
|
4
|
+
const { data: contextData, xGet, yGet, yRange } = getContext('LayerCake');
|
|
5
|
+
// Properties to override what is used from context
|
|
6
|
+
export let data = undefined; // TODO: Update Type
|
|
7
|
+
export let x = undefined; // TODO: Update Type
|
|
8
|
+
export let y0 = undefined; // TODO: Update Type
|
|
9
|
+
export let y1 = undefined; // TODO: Update Type
|
|
10
|
+
export let pathData = undefined;
|
|
11
|
+
export let clipPath = undefined;
|
|
12
|
+
export let curve = undefined;
|
|
13
|
+
export let defined = undefined;
|
|
14
|
+
export let color = 'var(--color-blue-500)';
|
|
15
|
+
export let opacity = 0.3;
|
|
16
|
+
export let line = false;
|
|
17
|
+
$: path = d3Area()
|
|
18
|
+
.x(x ?? $xGet)
|
|
19
|
+
.y0(y0 ?? $yRange[0])
|
|
20
|
+
.y1(y1 ?? $yGet);
|
|
21
|
+
$: if (curve)
|
|
22
|
+
path.curve(curve);
|
|
23
|
+
$: if (defined)
|
|
24
|
+
path.defined(defined);
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
{#if line}
|
|
28
|
+
<Path {curve} {defined} {color} {...line} />
|
|
29
|
+
{/if}
|
|
30
|
+
|
|
31
|
+
<path
|
|
32
|
+
class="path-area"
|
|
33
|
+
d={pathData ?? path(data ?? $contextData)}
|
|
34
|
+
clip-path={clipPath}
|
|
35
|
+
fill={color}
|
|
36
|
+
fill-opacity={opacity}
|
|
37
|
+
{...$$restProps}
|
|
38
|
+
/>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { CurveFactory } from 'd3-shape';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
data?: any;
|
|
7
|
+
x?: any;
|
|
8
|
+
y0?: any;
|
|
9
|
+
y1?: any;
|
|
10
|
+
pathData?: string;
|
|
11
|
+
clipPath?: string;
|
|
12
|
+
curve?: CurveFactory;
|
|
13
|
+
defined?: (d: [number, number], index: number, data: [number, number][]) => boolean;
|
|
14
|
+
color?: string;
|
|
15
|
+
opacity?: number;
|
|
16
|
+
line?: boolean | any;
|
|
17
|
+
};
|
|
18
|
+
events: {
|
|
19
|
+
[evt: string]: CustomEvent<any>;
|
|
20
|
+
};
|
|
21
|
+
slots: {};
|
|
22
|
+
};
|
|
23
|
+
export declare type AreaProps = typeof __propDef.props;
|
|
24
|
+
export declare type AreaEvents = typeof __propDef.events;
|
|
25
|
+
export declare type AreaSlots = typeof __propDef.slots;
|
|
26
|
+
export default class Area extends SvelteComponentTyped<AreaProps, AreaEvents, AreaSlots> {
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script >import { getContext } from 'svelte';
|
|
2
|
+
import Area from './Area.svelte';
|
|
3
|
+
import Path from './Path.svelte';
|
|
4
|
+
const { data, yScale, zGet } = getContext('LayerCake');
|
|
5
|
+
export let curve = undefined;
|
|
6
|
+
export let defined = undefined;
|
|
7
|
+
export let opacity = 0.3;
|
|
8
|
+
export let line = false;
|
|
9
|
+
// Render in reverse order so bottom stacks are rendered last (and stack above the upper stacks). Fixes when upper stack has 0 value
|
|
10
|
+
$: lineData = [...$data].reverse();
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
{#if line}
|
|
14
|
+
<g class="line-group">
|
|
15
|
+
{#each lineData as seriesData}
|
|
16
|
+
<Path
|
|
17
|
+
data={seriesData}
|
|
18
|
+
y={(d) => $yScale(d[1])}
|
|
19
|
+
color={$zGet(seriesData)}
|
|
20
|
+
{curve}
|
|
21
|
+
{defined}
|
|
22
|
+
{...line}
|
|
23
|
+
/>
|
|
24
|
+
{/each}
|
|
25
|
+
</g>
|
|
26
|
+
{/if}
|
|
27
|
+
|
|
28
|
+
<g class="area-group">
|
|
29
|
+
{#each $data as seriesData}
|
|
30
|
+
<Area
|
|
31
|
+
data={seriesData}
|
|
32
|
+
y0={(d) => $yScale(d[0])}
|
|
33
|
+
y1={(d) => $yScale(d[1])}
|
|
34
|
+
color={$zGet(seriesData)}
|
|
35
|
+
{curve}
|
|
36
|
+
{defined}
|
|
37
|
+
{opacity}
|
|
38
|
+
/>
|
|
39
|
+
{/each}
|
|
40
|
+
</g>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { CurveFactory } from 'd3-shape';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
curve?: CurveFactory;
|
|
6
|
+
defined?: (d: any, index: number, data: any[]) => boolean;
|
|
7
|
+
opacity?: number;
|
|
8
|
+
line?: boolean | any;
|
|
9
|
+
};
|
|
10
|
+
events: {
|
|
11
|
+
[evt: string]: CustomEvent<any>;
|
|
12
|
+
};
|
|
13
|
+
slots: {};
|
|
14
|
+
};
|
|
15
|
+
export declare type AreaStackProps = typeof __propDef.props;
|
|
16
|
+
export declare type AreaStackEvents = typeof __propDef.events;
|
|
17
|
+
export declare type AreaStackSlots = typeof __propDef.slots;
|
|
18
|
+
export default class AreaStack extends SvelteComponentTyped<AreaStackProps, AreaStackEvents, AreaStackSlots> {
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script >import { getContext } from 'svelte';
|
|
2
|
+
import { format } from 'svelte-ux/utils/format';
|
|
3
|
+
import Text from './Text.svelte';
|
|
4
|
+
import { isScaleBand } from '../utils/scales';
|
|
5
|
+
const { height, xScale, yRange } = getContext('LayerCake');
|
|
6
|
+
export let gridlines = false;
|
|
7
|
+
export let formatTick = undefined;
|
|
8
|
+
export let ticks = undefined;
|
|
9
|
+
export let xTick = undefined;
|
|
10
|
+
export let yTick = 8;
|
|
11
|
+
export let dxTick = 0;
|
|
12
|
+
export let dyTick = 0;
|
|
13
|
+
$: isBand = isScaleBand($xScale);
|
|
14
|
+
$: tickVals = Array.isArray(ticks)
|
|
15
|
+
? ticks
|
|
16
|
+
: isBand
|
|
17
|
+
? $xScale.domain()
|
|
18
|
+
: $xScale.ticks(typeof ticks === 'function' ? ticks($xScale) : ticks);
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<g class="axis x-axis">
|
|
22
|
+
{#each tickVals as tick, i}
|
|
23
|
+
<g class="tick tick-{tick}" transform="translate({$xScale(tick)},{$yRange[0]})">
|
|
24
|
+
{#if gridlines !== false}
|
|
25
|
+
<line y1={$height * -1} y2="0" x1="0" x2="0" />
|
|
26
|
+
{/if}
|
|
27
|
+
<Text
|
|
28
|
+
x={xTick || isBand ? $xScale.bandwidth() / 2 : 0}
|
|
29
|
+
y={yTick}
|
|
30
|
+
dx={dxTick}
|
|
31
|
+
dy={dyTick}
|
|
32
|
+
rotate={315}
|
|
33
|
+
textAnchor="end"
|
|
34
|
+
verticalAnchor="middle"
|
|
35
|
+
style="font-size: 10px;"
|
|
36
|
+
value={format(tick, formatTick ?? $xScale.tickFormat?.())}
|
|
37
|
+
/>
|
|
38
|
+
</g>
|
|
39
|
+
{/each}
|
|
40
|
+
</g>
|
|
41
|
+
|
|
42
|
+
<style >
|
|
43
|
+
.tick {
|
|
44
|
+
font-size: 0.725em;
|
|
45
|
+
font-weight: 200;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
line,
|
|
49
|
+
.tick line {
|
|
50
|
+
stroke: #e0e0e0;
|
|
51
|
+
}
|
|
52
|
+
</style>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { FormatType } from 'svelte-ux/utils/format';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
gridlines?: boolean;
|
|
6
|
+
formatTick?: FormatType;
|
|
7
|
+
ticks?: any;
|
|
8
|
+
xTick?: any;
|
|
9
|
+
yTick?: number;
|
|
10
|
+
dxTick?: number;
|
|
11
|
+
dyTick?: number;
|
|
12
|
+
};
|
|
13
|
+
events: {
|
|
14
|
+
[evt: string]: CustomEvent<any>;
|
|
15
|
+
};
|
|
16
|
+
slots: {};
|
|
17
|
+
};
|
|
18
|
+
export declare type AxisXProps = typeof __propDef.props;
|
|
19
|
+
export declare type AxisXEvents = typeof __propDef.events;
|
|
20
|
+
export declare type AxisXSlots = typeof __propDef.slots;
|
|
21
|
+
export default class AxisX extends SvelteComponentTyped<AxisXProps, AxisXEvents, AxisXSlots> {
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script >import { getContext } from 'svelte';
|
|
2
|
+
import { format } from 'svelte-ux/utils/format';
|
|
3
|
+
import Text from './Text.svelte';
|
|
4
|
+
import { isScaleBand } from '../utils/scales';
|
|
5
|
+
const { padding, xRange, yScale, width } = getContext('LayerCake');
|
|
6
|
+
export let gridlines = false;
|
|
7
|
+
export let ticks = 4;
|
|
8
|
+
export let formatTick = undefined;
|
|
9
|
+
export let xTick = 0;
|
|
10
|
+
export let yTick = 0;
|
|
11
|
+
export let dxTick = 0;
|
|
12
|
+
export let dyTick = -3; // TODO: Maualliy tweak based on font-size until <Text /> handles custom styles
|
|
13
|
+
$: isBand = isScaleBand($yScale);
|
|
14
|
+
$: tickVals = Array.isArray(ticks)
|
|
15
|
+
? ticks
|
|
16
|
+
: isBand
|
|
17
|
+
? $yScale.domain()
|
|
18
|
+
: $yScale.ticks(typeof ticks === 'function' ? ticks($yScale) : ticks);
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<g class="axis y-axis" transform="translate({-$padding.left}, 0)">
|
|
22
|
+
{#each tickVals as tick, i}
|
|
23
|
+
<g
|
|
24
|
+
class="tick tick-{tick}"
|
|
25
|
+
transform="translate({$xRange[0] + (isBand ? $padding.left : 0)}, {$yScale(tick)})"
|
|
26
|
+
>
|
|
27
|
+
{#if gridlines !== false}
|
|
28
|
+
<line
|
|
29
|
+
x1={$padding.left}
|
|
30
|
+
x2={$width + $padding.left}
|
|
31
|
+
y1={yTick + (isBand ? $yScale.bandwidth() / 2 : 0)}
|
|
32
|
+
y2={yTick + (isBand ? $yScale.bandwidth() / 2 : 0)}
|
|
33
|
+
/>
|
|
34
|
+
{/if}
|
|
35
|
+
<!-- <circle
|
|
36
|
+
cx={$padding.left - 4}
|
|
37
|
+
cy={yTick + (isBand ? $yScale.bandwidth() / 2 : 0)}
|
|
38
|
+
r="2"
|
|
39
|
+
fill="red"
|
|
40
|
+
/> -->
|
|
41
|
+
<Text
|
|
42
|
+
x={$padding.left - 4}
|
|
43
|
+
y={yTick + (isBand ? $yScale.bandwidth() / 2 : 0)}
|
|
44
|
+
dx={dxTick}
|
|
45
|
+
dy={dyTick}
|
|
46
|
+
textAnchor="end"
|
|
47
|
+
verticalAnchor="middle"
|
|
48
|
+
style="font-size: 10px;"
|
|
49
|
+
value={format(tick, formatTick ?? $yScale.tickFormat?.())}
|
|
50
|
+
/>
|
|
51
|
+
</g>
|
|
52
|
+
{/each}
|
|
53
|
+
</g>
|
|
54
|
+
|
|
55
|
+
<style >
|
|
56
|
+
.tick {
|
|
57
|
+
font-size: 0.725em;
|
|
58
|
+
font-weight: 200;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.tick line {
|
|
62
|
+
stroke: #e0e0e0;
|
|
63
|
+
/* stroke-dasharray: 2; */
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.tick.tick-0 line {
|
|
67
|
+
stroke-dasharray: 0;
|
|
68
|
+
}
|
|
69
|
+
</style>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { FormatType } from 'svelte-ux/utils/format';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
gridlines?: boolean;
|
|
6
|
+
ticks?: number | Function;
|
|
7
|
+
formatTick?: FormatType;
|
|
8
|
+
xTick?: number;
|
|
9
|
+
yTick?: number;
|
|
10
|
+
dxTick?: number;
|
|
11
|
+
dyTick?: number;
|
|
12
|
+
};
|
|
13
|
+
events: {
|
|
14
|
+
[evt: string]: CustomEvent<any>;
|
|
15
|
+
};
|
|
16
|
+
slots: {};
|
|
17
|
+
};
|
|
18
|
+
export declare type AxisYProps = typeof __propDef.props;
|
|
19
|
+
export declare type AxisYEvents = typeof __propDef.events;
|
|
20
|
+
export declare type AxisYSlots = typeof __propDef.slots;
|
|
21
|
+
export default class AxisY extends SvelteComponentTyped<AxisYProps, AxisYEvents, AxisYSlots> {
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
<script >import { getContext } from 'svelte';
|
|
2
|
+
import { scaleBand } from 'd3-scale';
|
|
3
|
+
import { max, min } from 'd3-array';
|
|
4
|
+
import Rect from './Rect.svelte';
|
|
5
|
+
import { unique } from 'svelte-ux/utils/array';
|
|
6
|
+
const { data, flatData, xGet, yRange, xScale, yScale, x, y, rGet, config } = getContext('LayerCake');
|
|
7
|
+
/*
|
|
8
|
+
TODO: Support vertical/horizontal layout
|
|
9
|
+
- https://layercake.graphics/example/Bar
|
|
10
|
+
- https://layercake.graphics/example/Column
|
|
11
|
+
- https://layercake.graphics/example/BarStacked
|
|
12
|
+
- https://layercake.graphics/example/ColumnStacked
|
|
13
|
+
*/
|
|
14
|
+
export let color = 'var(--color-blue-500)';
|
|
15
|
+
export let opacity = 1;
|
|
16
|
+
export let stroke = 'black';
|
|
17
|
+
export let strokeWidth = 0;
|
|
18
|
+
export let radius = 0;
|
|
19
|
+
export let getKey = (item) => $x(item);
|
|
20
|
+
export let getProps = undefined;
|
|
21
|
+
// See: https://svelte.dev/repl/7000c5ce05b84cd98ccbfb2768b4be3d?version=3.38.3
|
|
22
|
+
export let groupBy = undefined;
|
|
23
|
+
// export let delay = 300;
|
|
24
|
+
// $: console.log({ $data, $flatData, groupBy, stackBy })
|
|
25
|
+
$: groupKeys = unique($flatData.map((d) => d[groupBy]));
|
|
26
|
+
$: x1Scale = scaleBand().domain(groupKeys).range([0, $xScale.bandwidth()]).paddingInner(0.2);
|
|
27
|
+
$: getDimensions = (item) => {
|
|
28
|
+
// console.log({ item, y: $y(item) });
|
|
29
|
+
const x = $xGet(item) + (groupBy ? x1Scale(item[groupBy]) : 0);
|
|
30
|
+
// TODO: Do we need to support the non-bandwidth scale?
|
|
31
|
+
// const width = $xScale.bandwidth
|
|
32
|
+
// ? $xScale.bandwidth()
|
|
33
|
+
// : Math.max(0, $xGet(d)[1] - $xGet(d)[0]);
|
|
34
|
+
const width = groupBy ? x1Scale.bandwidth() : $xScale.bandwidth();
|
|
35
|
+
const yValue = $y(item);
|
|
36
|
+
let yTop = 0;
|
|
37
|
+
let yBottom = 0;
|
|
38
|
+
if (Array.isArray(yValue)) {
|
|
39
|
+
// Array contains both top and bottom values;
|
|
40
|
+
yTop = max(yValue);
|
|
41
|
+
yBottom = min(yValue);
|
|
42
|
+
}
|
|
43
|
+
else if (yValue == null) {
|
|
44
|
+
// null/undefined value
|
|
45
|
+
yTop = 0;
|
|
46
|
+
yBottom = 0;
|
|
47
|
+
}
|
|
48
|
+
else if (yValue > 0) {
|
|
49
|
+
// Positive value
|
|
50
|
+
yTop = yValue;
|
|
51
|
+
yBottom = $yRange[1]; // or `0`?
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// Negative value
|
|
55
|
+
yTop = $yRange[1]; // or `0`?
|
|
56
|
+
yBottom = yValue;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
x,
|
|
60
|
+
y: $yScale(yTop),
|
|
61
|
+
width,
|
|
62
|
+
height: $yScale(yBottom) - $yScale(yTop)
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
function getColor(item, index) {
|
|
66
|
+
if (typeof color === 'function') {
|
|
67
|
+
return color({ value: $y(item), item, index });
|
|
68
|
+
}
|
|
69
|
+
else if ($config.r) {
|
|
70
|
+
return $rGet(item);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return color;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<g class="column-group">
|
|
79
|
+
{#each $data as item, index (getKey(item, index))}
|
|
80
|
+
<Rect
|
|
81
|
+
class="group-rect"
|
|
82
|
+
data-id={index}
|
|
83
|
+
fill={getColor(item, index)}
|
|
84
|
+
fill-opacity={opacity}
|
|
85
|
+
{stroke}
|
|
86
|
+
stroke-width={strokeWidth}
|
|
87
|
+
rx={radius}
|
|
88
|
+
{...getDimensions(item)}
|
|
89
|
+
{...getProps?.({ value: $y(item), item, index })}
|
|
90
|
+
{...$$restProps}
|
|
91
|
+
/>
|
|
92
|
+
{/each}
|
|
93
|
+
</g>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
color?: string | ((obj: {
|
|
6
|
+
value: any;
|
|
7
|
+
item: any;
|
|
8
|
+
index: number;
|
|
9
|
+
}) => string);
|
|
10
|
+
opacity?: number;
|
|
11
|
+
stroke?: string;
|
|
12
|
+
strokeWidth?: number;
|
|
13
|
+
radius?: number;
|
|
14
|
+
getKey?: (item: any, index: number) => any;
|
|
15
|
+
getProps?: (obj: {
|
|
16
|
+
value: any;
|
|
17
|
+
item: any;
|
|
18
|
+
index: number;
|
|
19
|
+
}) => any;
|
|
20
|
+
groupBy?: string;
|
|
21
|
+
};
|
|
22
|
+
events: {
|
|
23
|
+
[evt: string]: CustomEvent<any>;
|
|
24
|
+
};
|
|
25
|
+
slots: {};
|
|
26
|
+
};
|
|
27
|
+
export declare type BarProps = typeof __propDef.props;
|
|
28
|
+
export declare type BarEvents = typeof __propDef.events;
|
|
29
|
+
export declare type BarSlots = typeof __propDef.slots;
|
|
30
|
+
export default class Bar extends SvelteComponentTyped<BarProps, BarEvents, BarSlots> {
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script >import { getContext } from 'svelte';
|
|
2
|
+
const { xRange, yScale, yRange } = getContext('LayerCake');
|
|
3
|
+
export let x = false;
|
|
4
|
+
export let y = false;
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<g class="baseline">
|
|
8
|
+
{#if x}
|
|
9
|
+
<line x1={0} x2={$xRange[1] || 0} y1={$yScale(0) || 0} y2={$yScale(0) || 0} class="baseline" />
|
|
10
|
+
{/if}
|
|
11
|
+
|
|
12
|
+
{#if y}
|
|
13
|
+
<line x1={0} x2={0} y1={$yRange[0] || 0} y2={$yRange[1] || 0} class="baseline" />
|
|
14
|
+
{/if}
|
|
15
|
+
</g>
|
|
16
|
+
|
|
17
|
+
<style >
|
|
18
|
+
.baseline {
|
|
19
|
+
stroke: #777;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
x?: boolean;
|
|
5
|
+
y?: boolean;
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {};
|
|
11
|
+
};
|
|
12
|
+
export declare type BaselineProps = typeof __propDef.props;
|
|
13
|
+
export declare type BaselineEvents = typeof __propDef.events;
|
|
14
|
+
export declare type BaselineSlots = typeof __propDef.slots;
|
|
15
|
+
export default class Baseline extends SvelteComponentTyped<BaselineProps, BaselineEvents, BaselineSlots> {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<script context="module" >import { LayerCake, Svg, Html } from 'layercake';
|
|
2
|
+
export { Svg, Html };
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<script >import { max, min } from 'd3-array';
|
|
6
|
+
import { get } from 'lodash-es';
|
|
7
|
+
/**
|
|
8
|
+
* Resolve a value from data based on the accessor type
|
|
9
|
+
*/
|
|
10
|
+
function getValue(accessor, d) {
|
|
11
|
+
console.log({ accessor });
|
|
12
|
+
if (Array.isArray(accessor)) {
|
|
13
|
+
return accessor.map((a) => getValue(a, d));
|
|
14
|
+
}
|
|
15
|
+
else if (typeof accessor === 'function') {
|
|
16
|
+
return accessor(d) || 0;
|
|
17
|
+
}
|
|
18
|
+
else if (typeof accessor === 'string') {
|
|
19
|
+
return get(d, accessor);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
throw new Error('Unexpected accessor: ' + accessor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export let data = [];
|
|
26
|
+
export let x;
|
|
27
|
+
export let y;
|
|
28
|
+
/**
|
|
29
|
+
* xBaseline guaranteed to be visible in xDomain
|
|
30
|
+
*/
|
|
31
|
+
export let xBaseline = null;
|
|
32
|
+
let xDomain = undefined;
|
|
33
|
+
$: if (xBaseline != null) {
|
|
34
|
+
const xValues = data.flatMap((d) => getValue(x, d));
|
|
35
|
+
xDomain = [min([xBaseline, ...xValues]), max([xBaseline, ...xValues])];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* yBaseline guaranteed to be visible in yDomain
|
|
39
|
+
*/
|
|
40
|
+
export let yBaseline = null;
|
|
41
|
+
let yDomain = undefined;
|
|
42
|
+
$: if (yBaseline != null) {
|
|
43
|
+
const yValues = data.flatMap((d) => getValue(y, d));
|
|
44
|
+
yDomain = [min([yBaseline, ...yValues]), max([yBaseline, ...yValues])];
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<LayerCake {data} {y} {yDomain} {x} {xDomain} {...$$restProps}>
|
|
49
|
+
<slot />
|
|
50
|
+
</LayerCake>
|
|
@@ -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,44 @@
|
|
|
1
|
+
<script >import { getContext } from 'svelte';
|
|
2
|
+
const { data, xGet, yGet, y, yScale, rGet, config } = getContext('LayerCake');
|
|
3
|
+
export let color = 'var(--color-blue-500)';
|
|
4
|
+
export let radius = 5;
|
|
5
|
+
$: midHeight = $yScale.bandwidth() / 2;
|
|
6
|
+
function getColor(item, index) {
|
|
7
|
+
if (typeof color == 'function') {
|
|
8
|
+
return color({ value: $y(item), item, index });
|
|
9
|
+
}
|
|
10
|
+
else if ($config.r) {
|
|
11
|
+
return $rGet(item);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return color;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<g class="dot-plot">
|
|
20
|
+
{#each $data as row}
|
|
21
|
+
<g class="dot-row">
|
|
22
|
+
<line
|
|
23
|
+
x1={Math.min(...$xGet(row))}
|
|
24
|
+
y1={$yGet(row) + midHeight}
|
|
25
|
+
x2={Math.max(...$xGet(row))}
|
|
26
|
+
y2={$yGet(row) + midHeight}
|
|
27
|
+
/>
|
|
28
|
+
{#each $xGet(row) as circleX, i}
|
|
29
|
+
<circle cx={circleX} cy={$yGet(row) + midHeight} r={radius} fill={getColor(row, i)} />
|
|
30
|
+
{/each}
|
|
31
|
+
</g>
|
|
32
|
+
{/each}
|
|
33
|
+
</g>
|
|
34
|
+
|
|
35
|
+
<style >
|
|
36
|
+
line {
|
|
37
|
+
stroke-width: 1px;
|
|
38
|
+
stroke: #000;
|
|
39
|
+
}
|
|
40
|
+
circle {
|
|
41
|
+
stroke: #000;
|
|
42
|
+
stroke-width: 1px;
|
|
43
|
+
}
|
|
44
|
+
</style>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
color?: string | ((obj: {
|
|
5
|
+
value: any;
|
|
6
|
+
item: any;
|
|
7
|
+
index: number;
|
|
8
|
+
}) => string);
|
|
9
|
+
radius?: number;
|
|
10
|
+
};
|
|
11
|
+
events: {
|
|
12
|
+
[evt: string]: CustomEvent<any>;
|
|
13
|
+
};
|
|
14
|
+
slots: {};
|
|
15
|
+
};
|
|
16
|
+
export declare type ClevelandDotPlotProps = typeof __propDef.props;
|
|
17
|
+
export declare type ClevelandDotPlotEvents = typeof __propDef.events;
|
|
18
|
+
export declare type ClevelandDotPlotSlots = typeof __propDef.slots;
|
|
19
|
+
export default class ClevelandDotPlot extends SvelteComponentTyped<ClevelandDotPlotProps, ClevelandDotPlotEvents, ClevelandDotPlotSlots> {
|
|
20
|
+
}
|
|
21
|
+
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}
|