layerchart 0.17.1 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Arc.svelte +50 -9
- package/dist/components/Arc.svelte.d.ts +2 -2
- package/dist/components/Axis.svelte +47 -14
- package/dist/components/Axis.svelte.d.ts +3 -2
- package/dist/components/Chart.svelte.d.ts +1 -1
- package/dist/components/Frame.svelte +14 -0
- package/dist/components/Frame.svelte.d.ts +19 -0
- package/dist/components/Legend.svelte +14 -11
- package/dist/components/LinearGradient.svelte +1 -1
- package/dist/components/LinearGradient.svelte.d.ts +1 -1
- package/dist/components/Link.svelte +2 -0
- package/dist/components/Link.svelte.d.ts +2 -0
- package/dist/components/Rect.svelte +2 -0
- package/dist/components/RectClipPath.svelte +1 -0
- package/dist/components/Rule.svelte +48 -0
- package/dist/components/Rule.svelte.d.ts +18 -0
- package/dist/components/Tooltip.svelte +8 -7
- package/dist/components/Tooltip.svelte.d.ts +4 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +2 -1
- package/dist/docs/RangeField.svelte +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/utils/genData.d.ts +9 -0
- package/dist/utils/genData.js +17 -0
- package/dist/utils/graph.d.ts +5 -1
- package/dist/utils/graph.js +16 -10
- package/dist/utils/index.d.ts +5 -5
- package/dist/utils/index.js +5 -5
- package/package.json +8 -4
- package/dist/components/Baseline.svelte +0 -30
- package/dist/components/Baseline.svelte.d.ts +0 -18
|
@@ -46,6 +46,12 @@ export let innerRadius = undefined;
|
|
|
46
46
|
/**
|
|
47
47
|
* Define outerRadius. Defaults to yRange max / 2 (ie. chart height / 2)
|
|
48
48
|
*/
|
|
49
|
+
/**
|
|
50
|
+
* Define outerRadius. Defaults to yRange max (ie. chart height / 2)
|
|
51
|
+
* • value >= 1: discrete value
|
|
52
|
+
* • value < 1: percent of chart height / 2
|
|
53
|
+
* • value < 0: offset of chart height / 2
|
|
54
|
+
*/
|
|
49
55
|
export let outerRadius = undefined;
|
|
50
56
|
export let cornerRadius = 0;
|
|
51
57
|
export let padAngle = 0;
|
|
@@ -53,15 +59,50 @@ export let padAngle = 0;
|
|
|
53
59
|
export let track = false;
|
|
54
60
|
const { yRange } = getContext('LayerCake');
|
|
55
61
|
$: scale = scaleLinear().domain(domain).range(range);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
function getOuterRadius(outerRadius, chartRadius) {
|
|
63
|
+
if (outerRadius == null) {
|
|
64
|
+
return chartRadius;
|
|
65
|
+
}
|
|
66
|
+
else if (outerRadius > 1) {
|
|
67
|
+
// discrete value
|
|
68
|
+
return outerRadius;
|
|
69
|
+
}
|
|
70
|
+
else if (outerRadius > 0) {
|
|
71
|
+
// percent of `chartRadius`
|
|
72
|
+
return chartRadius * outerRadius;
|
|
73
|
+
}
|
|
74
|
+
else if (outerRadius < 0) {
|
|
75
|
+
// offset of `chartRadius`
|
|
76
|
+
return chartRadius + outerRadius;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// 0
|
|
80
|
+
return outerRadius;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
$: _outerRadius = getOuterRadius(outerRadius, max($yRange) / 2);
|
|
84
|
+
function getInnerRadius(innerRadius, outerRadius) {
|
|
85
|
+
if (innerRadius == null) {
|
|
86
|
+
return Math.min(...$yRange);
|
|
87
|
+
}
|
|
88
|
+
else if (innerRadius > 1) {
|
|
89
|
+
// discrete value
|
|
90
|
+
return innerRadius;
|
|
91
|
+
}
|
|
92
|
+
else if (innerRadius > 0) {
|
|
93
|
+
// percent of `outerRadius`
|
|
94
|
+
return outerRadius * innerRadius;
|
|
95
|
+
}
|
|
96
|
+
else if (innerRadius < 0) {
|
|
97
|
+
// offset of `outerRadius`
|
|
98
|
+
return outerRadius + innerRadius;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// 0
|
|
102
|
+
return innerRadius;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
$: _innerRadius = getInnerRadius(innerRadius, _outerRadius);
|
|
65
106
|
$: arc = d3arc()
|
|
66
107
|
.innerRadius(_innerRadius)
|
|
67
108
|
.outerRadius(_outerRadius)
|
|
@@ -11,8 +11,8 @@ declare const __propDef: {
|
|
|
11
11
|
range?: number[] | undefined;
|
|
12
12
|
startAngle?: number | undefined;
|
|
13
13
|
endAngle?: number | undefined;
|
|
14
|
-
innerRadius?: undefined;
|
|
15
|
-
outerRadius?: undefined;
|
|
14
|
+
innerRadius?: number | undefined;
|
|
15
|
+
outerRadius?: number | undefined;
|
|
16
16
|
cornerRadius?: number | undefined;
|
|
17
17
|
padAngle?: number | undefined;
|
|
18
18
|
track?: boolean | SVGAttributes<SVGPathElement> | undefined;
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
<script>import { getContext } from 'svelte';
|
|
2
|
-
import { format as formatValue } from 'svelte-ux';
|
|
3
|
-
import {
|
|
2
|
+
import { format as formatValue, cls } from 'svelte-ux';
|
|
3
|
+
import { extent } from 'd3-array';
|
|
4
4
|
import Text from './Text.svelte';
|
|
5
5
|
import { isScaleBand } from '../utils/scales';
|
|
6
6
|
const { xScale, yScale, xRange, yRange, width } = getContext('LayerCake');
|
|
7
|
+
/** Location of axis */
|
|
7
8
|
export let placement;
|
|
9
|
+
/** Draw a rule line. Use Rule component for greater rendering order control */
|
|
10
|
+
export let rule = false;
|
|
11
|
+
/** Draw a grid lines */
|
|
12
|
+
export let grid = false;
|
|
8
13
|
/** Control the number of ticks*/
|
|
9
14
|
export let ticks = placement === 'left' || placement === 'right' ? 4 : undefined;
|
|
10
|
-
export let gridlines = false;
|
|
11
15
|
export let tickSize = 4;
|
|
12
16
|
export let format = undefined;
|
|
13
17
|
export let labelProps = undefined;
|
|
14
18
|
$: orientation = ['top', 'bottom'].includes(placement) ? 'horizontal' : 'vertical';
|
|
15
19
|
$: scale = orientation === 'horizontal' ? $xScale : $yScale;
|
|
20
|
+
$: [xRangeMin, xRangeMax] = extent($xRange);
|
|
21
|
+
$: [yRangeMin, yRangeMax] = extent($yRange);
|
|
16
22
|
$: tickVals = Array.isArray(ticks)
|
|
17
23
|
? ticks
|
|
18
24
|
: isScaleBand(scale)
|
|
@@ -23,21 +29,21 @@ function getCoords(tick) {
|
|
|
23
29
|
case 'top':
|
|
24
30
|
return {
|
|
25
31
|
x: $xScale(tick) + (isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0),
|
|
26
|
-
y:
|
|
32
|
+
y: xRangeMin
|
|
27
33
|
};
|
|
28
34
|
case 'bottom':
|
|
29
35
|
return {
|
|
30
36
|
x: $xScale(tick) + (isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0),
|
|
31
|
-
y:
|
|
37
|
+
y: yRangeMax
|
|
32
38
|
};
|
|
33
39
|
case 'left':
|
|
34
40
|
return {
|
|
35
|
-
x:
|
|
41
|
+
x: xRangeMin,
|
|
36
42
|
y: $yScale(tick) + (isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0)
|
|
37
43
|
};
|
|
38
44
|
case 'right':
|
|
39
45
|
return {
|
|
40
|
-
x:
|
|
46
|
+
x: xRangeMax,
|
|
41
47
|
y: $yScale(tick) + (isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0)
|
|
42
48
|
};
|
|
43
49
|
}
|
|
@@ -75,18 +81,44 @@ function getDefaultLabelProps() {
|
|
|
75
81
|
</script>
|
|
76
82
|
|
|
77
83
|
<g class="Axis placement-{placement}">
|
|
84
|
+
{#if rule !== false}
|
|
85
|
+
{@const lineProps = typeof rule === 'object' ? rule : null}
|
|
86
|
+
{#if orientation === 'vertical'}
|
|
87
|
+
<line
|
|
88
|
+
x1={placement === 'right' ? xRangeMax : xRangeMin}
|
|
89
|
+
x2={placement === 'right' ? xRangeMax : xRangeMin}
|
|
90
|
+
y1={$yRange[0] || 0}
|
|
91
|
+
y2={$yRange[1] || 0}
|
|
92
|
+
{...lineProps}
|
|
93
|
+
class={cls('rule stroke-gray-400', lineProps?.class)}
|
|
94
|
+
/>
|
|
95
|
+
{/if}
|
|
96
|
+
|
|
97
|
+
{#if orientation === 'horizontal'}
|
|
98
|
+
<line
|
|
99
|
+
x1={$xRange[0] || 0}
|
|
100
|
+
x2={$xRange[1] || 0}
|
|
101
|
+
y1={placement === 'top' ? yRangeMin : yRangeMax}
|
|
102
|
+
y2={placement === 'top' ? yRangeMin : yRangeMax}
|
|
103
|
+
{...lineProps}
|
|
104
|
+
class={cls('rule stroke-gray-400', lineProps?.class)}
|
|
105
|
+
/>
|
|
106
|
+
{/if}
|
|
107
|
+
{/if}
|
|
108
|
+
|
|
78
109
|
{#each tickVals as tick, i}
|
|
79
110
|
{@const tickCoords = getCoords(tick)}
|
|
80
111
|
<g>
|
|
81
|
-
{#if
|
|
112
|
+
{#if grid !== false}
|
|
113
|
+
{@const lineProps = typeof grid === 'object' ? grid : null}
|
|
82
114
|
{#if orientation === 'horizontal'}
|
|
83
115
|
<line
|
|
84
116
|
x1={tickCoords.x}
|
|
85
|
-
y1={
|
|
117
|
+
y1={yRangeMin}
|
|
86
118
|
x2={tickCoords.x}
|
|
87
|
-
y2={
|
|
88
|
-
|
|
89
|
-
{
|
|
119
|
+
y2={yRangeMax}
|
|
120
|
+
{...lineProps}
|
|
121
|
+
class={cls('grid stroke-gray-200', lineProps?.class)}
|
|
90
122
|
/>
|
|
91
123
|
{:else if orientation === 'vertical'}
|
|
92
124
|
<line
|
|
@@ -94,12 +126,13 @@ function getDefaultLabelProps() {
|
|
|
94
126
|
y1={tickCoords.y}
|
|
95
127
|
x2={$width}
|
|
96
128
|
y2={tickCoords.y}
|
|
97
|
-
|
|
98
|
-
{
|
|
129
|
+
{...lineProps}
|
|
130
|
+
class={cls('grid stroke-gray-200', lineProps?.class)}
|
|
99
131
|
/>
|
|
100
132
|
{/if}
|
|
101
133
|
{/if}
|
|
102
134
|
|
|
135
|
+
<!-- Tick marks -->
|
|
103
136
|
{#if orientation === 'horizontal'}
|
|
104
137
|
<line
|
|
105
138
|
x1={tickCoords.x}
|
|
@@ -5,9 +5,10 @@ import { type FormatType } from 'svelte-ux';
|
|
|
5
5
|
import Text from './Text.svelte';
|
|
6
6
|
declare const __propDef: {
|
|
7
7
|
props: {
|
|
8
|
-
placement: 'top' | 'bottom' | 'left' | 'right';
|
|
8
|
+
/** Location of axis */ placement: 'top' | 'bottom' | 'left' | 'right';
|
|
9
|
+
/** Draw a rule line. Use Rule component for greater rendering order control */ rule?: boolean | SVGAttributes<SVGLineElement> | undefined;
|
|
10
|
+
/** Draw a grid lines */ grid?: boolean | SVGAttributes<SVGLineElement> | undefined;
|
|
9
11
|
/** Control the number of ticks*/ ticks?: number | Function | undefined;
|
|
10
|
-
gridlines?: boolean | SVGAttributes<SVGLineElement> | undefined;
|
|
11
12
|
tickSize?: number | undefined;
|
|
12
13
|
format?: FormatType;
|
|
13
14
|
labelProps?: ComponentProps<Text> | undefined;
|
|
@@ -16,7 +16,7 @@ declare const __propDef: {
|
|
|
16
16
|
yScale?: Function | undefined;
|
|
17
17
|
xBaseline?: number | null | undefined;
|
|
18
18
|
yBaseline?: number | null | undefined;
|
|
19
|
-
tooltip?: ComponentProps<TooltipContext> | undefined;
|
|
19
|
+
tooltip?: ComponentProps<TooltipContext> | boolean | undefined;
|
|
20
20
|
geo?: ComponentProps<GeoContext> | undefined;
|
|
21
21
|
};
|
|
22
22
|
events: {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script>import { getContext } from 'svelte';
|
|
2
|
+
const { width, height, padding } = getContext('LayerCake');
|
|
3
|
+
/** Include padding area */
|
|
4
|
+
export let full = false;
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<rect
|
|
8
|
+
x={full ? -$padding.left : 0}
|
|
9
|
+
y={full ? -$padding.top : 0}
|
|
10
|
+
width={$width + (full ? $padding.left + $padding.right : 0)}
|
|
11
|
+
height={$height + (full ? $padding.top + $padding.bottom : 0)}
|
|
12
|
+
on:click
|
|
13
|
+
{...$$restProps}
|
|
14
|
+
/>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
full?: boolean | undefined;
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
click: MouseEvent;
|
|
9
|
+
} & {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {};
|
|
13
|
+
};
|
|
14
|
+
export type FrameProps = typeof __propDef.props;
|
|
15
|
+
export type FrameEvents = typeof __propDef.events;
|
|
16
|
+
export type FrameSlots = typeof __propDef.slots;
|
|
17
|
+
export default class Frame extends SvelteComponentTyped<FrameProps, FrameEvents, FrameSlots> {
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -103,17 +103,20 @@ else {
|
|
|
103
103
|
<div
|
|
104
104
|
class={cls(
|
|
105
105
|
'inline-block',
|
|
106
|
-
|
|
107
|
-
'
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
106
|
+
placement && [
|
|
107
|
+
'absolute',
|
|
108
|
+
{
|
|
109
|
+
'top-left': 'top-0 left-0',
|
|
110
|
+
top: 'top-0 left-1/2 -translate-x-1/2',
|
|
111
|
+
'top-right': 'top-0 right-0',
|
|
112
|
+
left: 'top-1/2 left-0 -translate-y-1/2',
|
|
113
|
+
center: 'top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2',
|
|
114
|
+
right: 'top-1/2 right-0 -translate-y-1/2',
|
|
115
|
+
'bottom-left': 'bottom-0 left-0',
|
|
116
|
+
bottom: 'bottom-0 left-1/2 -translate-x-1/2',
|
|
117
|
+
'bottom-right': 'bottom-0 right-0'
|
|
118
|
+
}[placement]
|
|
119
|
+
],
|
|
117
120
|
classes.root
|
|
118
121
|
)}
|
|
119
122
|
{...$$restProps}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>export let id;
|
|
2
2
|
export let from;
|
|
3
|
-
export let via; // TODO: Currently --tw-gradient-via is not the color but the full stops
|
|
3
|
+
export let via = undefined; // TODO: Currently --tw-gradient-via is not the color but the full stops
|
|
4
4
|
export let to;
|
|
5
5
|
export let vertical = false;
|
|
6
6
|
export let x1 = '0%';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<script>import { getContext } from 'svelte';
|
|
2
|
+
import { cls } from 'svelte-ux';
|
|
3
|
+
import { extent } from 'd3-array';
|
|
4
|
+
import Line from './Line.svelte';
|
|
5
|
+
const { xScale, yScale, xRange, yRange } = getContext('LayerCake');
|
|
6
|
+
$: [xRangeMin, xRangeMax] = extent($xRange);
|
|
7
|
+
$: [yRangeMin, yRangeMax] = extent($yRange);
|
|
8
|
+
/**
|
|
9
|
+
* Create a vertical `x` line
|
|
10
|
+
* - If true or 'left', will draw at chart left (xRange[0])
|
|
11
|
+
* - If 'right', will draw at chart right (xRange[1])
|
|
12
|
+
* - Use `0` for baseline (yScale(0))
|
|
13
|
+
* - Use number | Date value for annotation (yScale(value))
|
|
14
|
+
*/
|
|
15
|
+
export let x = false;
|
|
16
|
+
/**
|
|
17
|
+
* Create a horizontal `y` line
|
|
18
|
+
* - If true or 'bottom', will draw at chart bottom (yRange[0])
|
|
19
|
+
* - If 'top', will draw at chart top (yRange[1])
|
|
20
|
+
* - Use `0` for baseline (xScale(0))
|
|
21
|
+
* - Use number | Date value for annotation (xScale(value))
|
|
22
|
+
*/
|
|
23
|
+
export let y = false;
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<g class="rule">
|
|
27
|
+
{#if x !== false}
|
|
28
|
+
<Line
|
|
29
|
+
x1={x === true || x === 'left' ? xRangeMin : x === 'right' ? xRangeMax : $xScale(x)}
|
|
30
|
+
x2={x === true || x === 'left' ? xRangeMin : x === 'right' ? xRangeMax : $xScale(x)}
|
|
31
|
+
y1={$yRange[0] || 0}
|
|
32
|
+
y2={$yRange[1] || 0}
|
|
33
|
+
{...$$restProps}
|
|
34
|
+
class={cls('stroke-gray-400', $$props.class)}
|
|
35
|
+
/>
|
|
36
|
+
{/if}
|
|
37
|
+
|
|
38
|
+
{#if y !== false}
|
|
39
|
+
<Line
|
|
40
|
+
x1={$xRange[0] || 0}
|
|
41
|
+
x2={$xRange[1] || 0}
|
|
42
|
+
y1={y === true || y === 'bottom' ? yRangeMax : y === 'top' ? yRangeMin : $yScale(y)}
|
|
43
|
+
y2={y === true || y === 'bottom' ? yRangeMax : y === 'top' ? yRangeMin : $yScale(y)}
|
|
44
|
+
{...$$restProps}
|
|
45
|
+
class={cls('stroke-gray-400', $$props.class)}
|
|
46
|
+
/>
|
|
47
|
+
{/if}
|
|
48
|
+
</g>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
x?: number | boolean | "left" | "right" | Date | undefined;
|
|
6
|
+
y?: number | boolean | "top" | "bottom" | Date | undefined;
|
|
7
|
+
};
|
|
8
|
+
events: {
|
|
9
|
+
[evt: string]: CustomEvent<any>;
|
|
10
|
+
};
|
|
11
|
+
slots: {};
|
|
12
|
+
};
|
|
13
|
+
export type RuleProps = typeof __propDef.props;
|
|
14
|
+
export type RuleEvents = typeof __propDef.events;
|
|
15
|
+
export type RuleSlots = typeof __propDef.slots;
|
|
16
|
+
export default class Rule extends SvelteComponentTyped<RuleProps, RuleEvents, RuleSlots> {
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { spring } from 'svelte/motion';
|
|
3
3
|
import { fade } from 'svelte/transition';
|
|
4
4
|
import { writable } from 'svelte/store';
|
|
5
|
+
import { cls } from 'svelte-ux';
|
|
5
6
|
import { tooltipContext } from './TooltipContext.svelte';
|
|
6
7
|
export let topOffset = 10;
|
|
7
8
|
export let leftOffset = 10;
|
|
@@ -15,8 +16,8 @@ let tooltipHeight = 0;
|
|
|
15
16
|
let top = animate ? spring($tooltip.top) : writable($tooltip.top);
|
|
16
17
|
$: if ($tooltip) {
|
|
17
18
|
if (contained === 'container' && $tooltip.top + topOffset + tooltipHeight > $containerHeight) {
|
|
18
|
-
//
|
|
19
|
-
$top = $tooltip.top - (topOffset + tooltipHeight);
|
|
19
|
+
// Change side. Do not allow tooltip to go above the top
|
|
20
|
+
$top = Math.max($tooltip.top - (topOffset + tooltipHeight), 0);
|
|
20
21
|
}
|
|
21
22
|
else {
|
|
22
23
|
$top = $tooltip.top + topOffset;
|
|
@@ -25,8 +26,8 @@ $: if ($tooltip) {
|
|
|
25
26
|
let left = animate ? spring($tooltip.left) : writable($tooltip.left);
|
|
26
27
|
$: if ($tooltip) {
|
|
27
28
|
if (contained === 'container' && $tooltip.left + leftOffset + tooltipWidth > $containerWidth) {
|
|
28
|
-
//
|
|
29
|
-
$left = $tooltip.left - (leftOffset + tooltipWidth);
|
|
29
|
+
// Change side
|
|
30
|
+
$left = Math.max($tooltip.left - (leftOffset + tooltipWidth), 0);
|
|
30
31
|
}
|
|
31
32
|
else {
|
|
32
33
|
$left = $tooltip.left + leftOffset;
|
|
@@ -36,7 +37,7 @@ $: if ($tooltip) {
|
|
|
36
37
|
|
|
37
38
|
{#if $tooltip.data}
|
|
38
39
|
<div
|
|
39
|
-
class=
|
|
40
|
+
class={cls('absolute pointer-events-none z-50', $$props.class)}
|
|
40
41
|
style:top="{$top}px"
|
|
41
42
|
style:left="{$left}px"
|
|
42
43
|
transition:fade={{ duration: 100 }}
|
|
@@ -44,11 +45,11 @@ $: if ($tooltip) {
|
|
|
44
45
|
bind:clientHeight={tooltipHeight}
|
|
45
46
|
>
|
|
46
47
|
<div
|
|
47
|
-
class="bg-gray-900/90 backdrop-filter backdrop-blur-[2px] text-white rounded elevation-1 px-2 py-1"
|
|
48
|
+
class="bg-gray-900/90 backdrop-filter backdrop-blur-[2px] text-white rounded elevation-1 px-2 py-1 h-full"
|
|
48
49
|
>
|
|
49
50
|
{#if header || $$slots.header}
|
|
50
51
|
<div class="text-center font-semibold whitespace-nowrap">
|
|
51
|
-
<slot name="header">
|
|
52
|
+
<slot name="header" data={$tooltip.data}>
|
|
52
53
|
{header($tooltip.data)}
|
|
53
54
|
</slot>
|
|
54
55
|
</div>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
|
+
[x: string]: any;
|
|
4
5
|
topOffset?: number | undefined;
|
|
5
6
|
leftOffset?: number | undefined;
|
|
6
7
|
contained?: false | "container" | undefined;
|
|
@@ -11,7 +12,9 @@ declare const __propDef: {
|
|
|
11
12
|
[evt: string]: CustomEvent<any>;
|
|
12
13
|
};
|
|
13
14
|
slots: {
|
|
14
|
-
header: {
|
|
15
|
+
header: {
|
|
16
|
+
data: any;
|
|
17
|
+
};
|
|
15
18
|
default: {
|
|
16
19
|
data: any;
|
|
17
20
|
};
|
|
@@ -3,7 +3,6 @@ export { default as Area } from './Area.svelte';
|
|
|
3
3
|
export { default as AreaStack } from './AreaStack.svelte';
|
|
4
4
|
export { default as Axis } from './Axis.svelte';
|
|
5
5
|
export { default as Bars } from './Bars.svelte';
|
|
6
|
-
export { default as Baseline } from './Baseline.svelte';
|
|
7
6
|
export { default as Blur } from './Blur.svelte';
|
|
8
7
|
export { default as Bounds } from './Bounds.svelte';
|
|
9
8
|
export { default as Chart } from './Chart.svelte';
|
|
@@ -14,6 +13,7 @@ export { default as ClipPath } from './ClipPath.svelte';
|
|
|
14
13
|
export { default as ClipPathUse } from './ClipPathUse.svelte';
|
|
15
14
|
export { default as ColorRamp } from './ColorRamp.svelte';
|
|
16
15
|
export { default as ConnectedPoints } from './ConnectedPoints.svelte';
|
|
16
|
+
export { default as Frame } from './Frame.svelte';
|
|
17
17
|
export { default as GeoContext } from './GeoContext.svelte';
|
|
18
18
|
export { default as GeoPath } from './GeoPath.svelte';
|
|
19
19
|
export { default as GeoPoint } from './GeoPoint.svelte';
|
|
@@ -35,6 +35,7 @@ export { default as Pie } from './Pie.svelte';
|
|
|
35
35
|
export { default as Points } from './Points.svelte';
|
|
36
36
|
export { default as Rect } from './Rect.svelte';
|
|
37
37
|
export { default as RectClipPath } from './RectClipPath.svelte';
|
|
38
|
+
export { default as Rule } from './Rule.svelte';
|
|
38
39
|
export { default as Sankey } from './Sankey.svelte';
|
|
39
40
|
export { default as Text } from './Text.svelte';
|
|
40
41
|
export { default as Threshold } from './Threshold.svelte';
|
package/dist/components/index.js
CHANGED
|
@@ -3,7 +3,6 @@ export { default as Area } from './Area.svelte';
|
|
|
3
3
|
export { default as AreaStack } from './AreaStack.svelte';
|
|
4
4
|
export { default as Axis } from './Axis.svelte';
|
|
5
5
|
export { default as Bars } from './Bars.svelte';
|
|
6
|
-
export { default as Baseline } from './Baseline.svelte';
|
|
7
6
|
export { default as Blur } from './Blur.svelte';
|
|
8
7
|
export { default as Bounds } from './Bounds.svelte';
|
|
9
8
|
export { default as Chart } from './Chart.svelte';
|
|
@@ -14,6 +13,7 @@ export { default as ClipPath } from './ClipPath.svelte';
|
|
|
14
13
|
export { default as ClipPathUse } from './ClipPathUse.svelte';
|
|
15
14
|
export { default as ColorRamp } from './ColorRamp.svelte';
|
|
16
15
|
export { default as ConnectedPoints } from './ConnectedPoints.svelte';
|
|
16
|
+
export { default as Frame } from './Frame.svelte';
|
|
17
17
|
export { default as GeoContext } from './GeoContext.svelte';
|
|
18
18
|
export { default as GeoPath } from './GeoPath.svelte';
|
|
19
19
|
export { default as GeoPoint } from './GeoPoint.svelte';
|
|
@@ -35,6 +35,7 @@ export { default as Pie } from './Pie.svelte';
|
|
|
35
35
|
export { default as Points } from './Points.svelte';
|
|
36
36
|
export { default as Rect } from './Rect.svelte';
|
|
37
37
|
export { default as RectClipPath } from './RectClipPath.svelte';
|
|
38
|
+
export { default as Rule } from './Rule.svelte';
|
|
38
39
|
export { default as Sankey } from './Sankey.svelte';
|
|
39
40
|
export { default as Text } from './Text.svelte';
|
|
40
41
|
export { default as Threshold } from './Threshold.svelte';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Svg, Html } from 'layercake';
|
|
2
|
-
export * from './components
|
|
3
|
-
export * from './utils
|
|
2
|
+
export * from './components';
|
|
3
|
+
export * from './utils';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Svg, Html } from 'layercake';
|
|
2
|
-
export * from './components
|
|
3
|
-
export * from './utils
|
|
2
|
+
export * from './components';
|
|
3
|
+
export * from './utils';
|
package/dist/utils/genData.d.ts
CHANGED
|
@@ -8,6 +8,15 @@ export declare function getRandomNumber(min: number, max: number): number;
|
|
|
8
8
|
* see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#getting_a_random_integer_between_two_values_inclusive
|
|
9
9
|
*/
|
|
10
10
|
export declare function getRandomInteger(min: number, max: number, includeMax?: boolean): number;
|
|
11
|
+
export declare function createSeries(options: {
|
|
12
|
+
count?: number;
|
|
13
|
+
min: number;
|
|
14
|
+
max: number;
|
|
15
|
+
keys?: Array<string>;
|
|
16
|
+
value?: 'number' | 'integer';
|
|
17
|
+
}): {
|
|
18
|
+
x: number;
|
|
19
|
+
}[];
|
|
11
20
|
export declare function createDateSeries(options: {
|
|
12
21
|
count?: number;
|
|
13
22
|
min: number;
|
package/dist/utils/genData.js
CHANGED
|
@@ -16,6 +16,23 @@ export function getRandomInteger(min, max, includeMax = true) {
|
|
|
16
16
|
max = Math.floor(max);
|
|
17
17
|
return Math.floor(Math.random() * (max - min + (includeMax ? 1 : 0)) + min);
|
|
18
18
|
}
|
|
19
|
+
export function createSeries(options) {
|
|
20
|
+
const count = options.count ?? 10;
|
|
21
|
+
const min = options.min;
|
|
22
|
+
const max = options.max;
|
|
23
|
+
const keys = options.keys ?? ['y'];
|
|
24
|
+
return Array.from({ length: count }).map((_, i) => {
|
|
25
|
+
return {
|
|
26
|
+
x: options.value === 'integer' ? getRandomInteger(min, max) : getRandomNumber(min, max),
|
|
27
|
+
...Object.fromEntries(keys.map((key) => {
|
|
28
|
+
return [
|
|
29
|
+
key,
|
|
30
|
+
options.value === 'integer' ? getRandomInteger(min, max) : getRandomNumber(min, max)
|
|
31
|
+
];
|
|
32
|
+
}))
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
19
36
|
export function createDateSeries(options) {
|
|
20
37
|
const now = startOfToday();
|
|
21
38
|
const count = options.count ?? 10;
|
package/dist/utils/graph.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SankeyGraph, SankeyNodeMinimal } from 'd3-sankey';
|
|
1
|
+
import type { SankeyExtraProperties, SankeyGraph, SankeyLink, SankeyNodeMinimal } from 'd3-sankey';
|
|
2
2
|
import type { hierarchy as d3Hierarchy } from 'd3-hierarchy';
|
|
3
3
|
/**
|
|
4
4
|
* Convert CSV rows in format: 'source,target,value' to SankeyGraph
|
|
@@ -22,3 +22,7 @@ export declare function graphFromNode(node: SankeyNodeMinimal<any, any>): {
|
|
|
22
22
|
nodes: SankeyNodeMinimal<any, any>[];
|
|
23
23
|
links: any[];
|
|
24
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Get distinct nodes from link.source and link.target
|
|
27
|
+
*/
|
|
28
|
+
export declare function nodesFromLinks<N extends SankeyExtraProperties, L extends SankeyExtraProperties>(links: Array<SankeyLink<N, L>>): any[];
|
package/dist/utils/graph.js
CHANGED
|
@@ -12,16 +12,7 @@ export function graphFromCsv(csv) {
|
|
|
12
12
|
// color: linkColor,
|
|
13
13
|
}
|
|
14
14
|
: null);
|
|
15
|
-
|
|
16
|
-
for (const link of links) {
|
|
17
|
-
if (!nodeByName.has(link.source)) {
|
|
18
|
-
nodeByName.set(link.source, { name: link.source });
|
|
19
|
-
}
|
|
20
|
-
if (!nodeByName.has(link.target)) {
|
|
21
|
-
nodeByName.set(link.target, { name: link.target });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return { nodes: Array.from(nodeByName.values()), links };
|
|
15
|
+
return { nodes: nodesFromLinks(links), links };
|
|
25
16
|
}
|
|
26
17
|
/**
|
|
27
18
|
* Convert d3-hierarchy to graph (nodes/links)
|
|
@@ -58,3 +49,18 @@ export function graphFromNode(node) {
|
|
|
58
49
|
});
|
|
59
50
|
return { nodes, links };
|
|
60
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Get distinct nodes from link.source and link.target
|
|
54
|
+
*/
|
|
55
|
+
export function nodesFromLinks(links) {
|
|
56
|
+
const nodesByName = new Map();
|
|
57
|
+
for (const link of links) {
|
|
58
|
+
if (!nodesByName.has(link.source)) {
|
|
59
|
+
nodesByName.set(link.source, { name: link.source });
|
|
60
|
+
}
|
|
61
|
+
if (!nodesByName.has(link.target)) {
|
|
62
|
+
nodesByName.set(link.target, { name: link.target });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return Array.from(nodesByName.values());
|
|
66
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
export * from './graph';
|
|
2
|
+
export * from './hierarchy';
|
|
3
|
+
export * from './math';
|
|
4
|
+
export * from './stack';
|
|
5
|
+
export * from './ticks';
|
package/dist/utils/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
export * from './graph';
|
|
2
|
+
export * from './hierarchy';
|
|
3
|
+
export * from './math';
|
|
4
|
+
export * from './stack';
|
|
5
|
+
export * from './ticks';
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Sean Lynch <techniq35@gmail.com>",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "techniq/layerchart",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.18.0",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "vite dev",
|
|
9
9
|
"build": "vite build",
|
|
@@ -13,13 +13,16 @@
|
|
|
13
13
|
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
14
14
|
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
|
|
15
15
|
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. .",
|
|
16
|
-
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
|
|
16
|
+
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. .",
|
|
17
|
+
"changeset": "changeset",
|
|
18
|
+
"version-package": "changeset version"
|
|
17
19
|
},
|
|
18
20
|
"devDependencies": {
|
|
19
21
|
"@rollup/plugin-dsv": "^3.0.2",
|
|
20
22
|
"@sveltejs/adapter-vercel": "^3.0.1",
|
|
21
23
|
"@sveltejs/kit": "^1.20.5",
|
|
22
24
|
"@sveltejs/package": "^2.1.0",
|
|
25
|
+
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
|
|
23
26
|
"@tailwindcss/typography": "^0.5.9",
|
|
24
27
|
"@types/d3-array": "^3.0.5",
|
|
25
28
|
"@types/d3-delaunay": "^6.0.1",
|
|
@@ -54,6 +57,7 @@
|
|
|
54
57
|
},
|
|
55
58
|
"type": "module",
|
|
56
59
|
"dependencies": {
|
|
60
|
+
"@changesets/cli": "^2.26.2",
|
|
57
61
|
"@mdi/js": "^7.2.96",
|
|
58
62
|
"@vercel/analytics": "^1.0.1",
|
|
59
63
|
"d3-array": "^3.2.4",
|
|
@@ -71,11 +75,11 @@
|
|
|
71
75
|
"d3-shape": "^3.2.0",
|
|
72
76
|
"d3-tile": "^1.0.0",
|
|
73
77
|
"date-fns": "^2.30.0",
|
|
74
|
-
"layercake": "^7.
|
|
78
|
+
"layercake": "^7.6.0",
|
|
75
79
|
"lodash-es": "^4.17.21",
|
|
76
80
|
"shapefile": "^0.6.6",
|
|
77
81
|
"svelte": "^3.59.1",
|
|
78
|
-
"svelte-ux": "^0.43.
|
|
82
|
+
"svelte-ux": "^0.43.3",
|
|
79
83
|
"topojson-client": "^3.1.0"
|
|
80
84
|
},
|
|
81
85
|
"main": "./dist/index.js",
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<script>import { min, max } from 'd3-array';
|
|
2
|
-
import { getContext } from 'svelte';
|
|
3
|
-
import { cls } from 'svelte-ux';
|
|
4
|
-
import { isScaleBand } from '../utils/scales';
|
|
5
|
-
const { xScale, yScale, xRange, yRange } = getContext('LayerCake');
|
|
6
|
-
export let x = false;
|
|
7
|
-
export let y = false;
|
|
8
|
-
</script>
|
|
9
|
-
|
|
10
|
-
<g class="baseline">
|
|
11
|
-
{#if x}
|
|
12
|
-
<line
|
|
13
|
-
x1={0}
|
|
14
|
-
x2={max($xRange) || 0}
|
|
15
|
-
y1={isScaleBand($yScale) ? max($yRange) : $yScale(0) || 0}
|
|
16
|
-
y2={isScaleBand($yScale) ? max($yRange) : $yScale(0) || 0}
|
|
17
|
-
class={cls('stroke-gray-400', $$props.class)}
|
|
18
|
-
/>
|
|
19
|
-
{/if}
|
|
20
|
-
|
|
21
|
-
{#if y}
|
|
22
|
-
<line
|
|
23
|
-
x1={isScaleBand($xScale) ? min($xRange) : $xScale(0) || 0}
|
|
24
|
-
x2={isScaleBand($xScale) ? min($xRange) : $xScale(0) || 0}
|
|
25
|
-
y1={min($yRange) || 0}
|
|
26
|
-
y2={max($yRange) || 0}
|
|
27
|
-
class={cls('stroke-gray-400', $$props.class)}
|
|
28
|
-
/>
|
|
29
|
-
{/if}
|
|
30
|
-
</g>
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
declare const __propDef: {
|
|
3
|
-
props: {
|
|
4
|
-
[x: string]: any;
|
|
5
|
-
x?: boolean | undefined;
|
|
6
|
-
y?: boolean | undefined;
|
|
7
|
-
};
|
|
8
|
-
events: {
|
|
9
|
-
[evt: string]: CustomEvent<any>;
|
|
10
|
-
};
|
|
11
|
-
slots: {};
|
|
12
|
-
};
|
|
13
|
-
export type BaselineProps = typeof __propDef.props;
|
|
14
|
-
export type BaselineEvents = typeof __propDef.events;
|
|
15
|
-
export type BaselineSlots = typeof __propDef.slots;
|
|
16
|
-
export default class Baseline extends SvelteComponentTyped<BaselineProps, BaselineEvents, BaselineSlots> {
|
|
17
|
-
}
|
|
18
|
-
export {};
|