layerchart 0.15.6 → 0.17.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/README.md +22 -1
- package/dist/components/Arc.svelte +10 -10
- package/dist/components/Arc.svelte.d.ts +2 -1
- package/dist/components/Area.svelte +10 -10
- package/dist/components/AreaStack.svelte +25 -25
- package/dist/components/Axis.svelte +131 -0
- package/dist/components/Axis.svelte.d.ts +25 -0
- package/dist/components/Bars.svelte +30 -71
- package/dist/components/Bars.svelte.d.ts +1 -1
- package/dist/components/Baseline.svelte +20 -20
- package/dist/components/Blur.svelte +7 -7
- package/dist/components/Chart.svelte +46 -40
- package/dist/components/Chart.svelte.d.ts +2 -0
- package/dist/components/ChartClipPath.svelte +7 -7
- package/dist/components/Circle.svelte +7 -7
- package/dist/components/CircleClipPath.svelte +5 -5
- package/dist/components/ClipPath.svelte +4 -4
- package/dist/components/ClipPathUse.svelte +5 -5
- package/dist/components/ConnectedPoints.svelte +16 -16
- package/dist/components/GeoPath.svelte +11 -11
- package/dist/components/GeoPoint.svelte +3 -3
- package/dist/components/GeoTile.svelte +5 -5
- package/dist/components/Graticule.svelte +12 -12
- package/dist/components/Group.svelte +1 -1
- package/dist/components/HighlightLine.svelte +25 -25
- package/dist/components/HighlightRect.svelte +1 -1
- package/dist/components/Labels.svelte +83 -74
- package/dist/components/Labels.svelte.d.ts +4 -3
- package/dist/components/Legend.svelte +59 -59
- package/dist/components/Legend.svelte.d.ts +3 -2
- package/dist/components/Line.svelte +8 -8
- package/dist/components/LinearGradient.svelte +22 -22
- package/dist/components/Link.svelte +10 -10
- package/dist/components/Link.svelte.d.ts +1 -1
- package/dist/components/Pack.svelte.d.ts +2 -2
- package/dist/components/Partition.svelte.d.ts +5 -5
- package/dist/components/Path.svelte +16 -16
- package/dist/components/Pattern.svelte +3 -3
- package/dist/components/Pie.svelte +21 -21
- package/dist/components/Pie.svelte.d.ts +18 -18
- package/dist/components/Points.svelte +14 -14
- package/dist/components/Rect.svelte +8 -8
- package/dist/components/RectClipPath.svelte +5 -5
- package/dist/components/Sankey.svelte.d.ts +2 -2
- package/dist/components/Text.svelte +32 -32
- package/dist/components/Threshold.svelte +25 -25
- package/dist/components/TileImage.svelte +21 -21
- package/dist/components/Tooltip.svelte +25 -25
- package/dist/components/TooltipContext.svelte +80 -78
- package/dist/components/TooltipContext.svelte.d.ts +1 -1
- package/dist/components/TooltipItem.svelte +11 -12
- package/dist/components/TooltipItem.svelte.d.ts +2 -1
- package/dist/components/Tree.svelte.d.ts +9 -9
- package/dist/components/Zoom.svelte +18 -18
- package/dist/components/Zoom.svelte.d.ts +1 -1
- package/dist/components/index.d.ts +1 -2
- package/dist/components/index.js +1 -2
- package/dist/docs/Blockquote.svelte +2 -2
- package/dist/docs/Blockquote.svelte.d.ts +6 -17
- package/dist/docs/Code.svelte +25 -27
- package/dist/docs/Code.svelte.d.ts +8 -17
- package/dist/docs/GeoDebug.svelte +26 -27
- package/dist/docs/Header1.svelte +2 -3
- package/dist/docs/Header1.svelte.d.ts +5 -14
- package/dist/docs/Layout.svelte +11 -11
- package/dist/docs/Layout.svelte.d.ts +9 -20
- package/dist/docs/Link.svelte +2 -2
- package/dist/docs/Link.svelte.d.ts +5 -14
- package/dist/docs/Preview.svelte +25 -25
- package/dist/docs/Preview.svelte.d.ts +1 -1
- package/dist/docs/RangeField.svelte +18 -18
- package/dist/docs/TilesetField.svelte +13 -13
- package/dist/docs/ViewSourceButton.svelte +42 -0
- package/dist/docs/ViewSourceButton.svelte.d.ts +19 -0
- package/dist/docs/ZoomControls.svelte +40 -41
- package/dist/docs/ZoomControls.svelte.d.ts +2 -2
- package/dist/utils/genData.d.ts +2 -2
- package/dist/utils/quadtree.d.ts +10 -2
- package/dist/utils/quadtree.js +1 -1
- package/dist/utils/rect.d.ts +19 -0
- package/dist/utils/rect.js +97 -0
- package/dist/utils/scales.d.ts +8 -0
- package/dist/utils/scales.js +17 -0
- package/package.json +90 -88
- package/dist/components/AxisX.svelte +0 -43
- package/dist/components/AxisX.svelte.d.ts +0 -37
- package/dist/components/AxisY.svelte +0 -55
- package/dist/components/AxisY.svelte.d.ts +0 -37
|
@@ -16,12 +16,12 @@ $: tweened_y2.set(y2);
|
|
|
16
16
|
</script>
|
|
17
17
|
|
|
18
18
|
<line
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
x1={$tweened_x1}
|
|
20
|
+
y1={$tweened_y1}
|
|
21
|
+
x2={$tweened_x2}
|
|
22
|
+
y2={$tweened_y2}
|
|
23
|
+
{...$$restProps}
|
|
24
|
+
on:click
|
|
25
|
+
on:mousemove
|
|
26
|
+
on:mouseleave
|
|
27
27
|
/>
|
|
@@ -11,28 +11,28 @@ export let rotate = undefined;
|
|
|
11
11
|
</script>
|
|
12
12
|
|
|
13
13
|
<defs>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
<linearGradient
|
|
15
|
+
{id}
|
|
16
|
+
{x1}
|
|
17
|
+
{y1}
|
|
18
|
+
{x2}
|
|
19
|
+
{y2}
|
|
20
|
+
gradientTransform={rotate ? `rotate(${rotate})` : ''}
|
|
21
|
+
{...$$restProps}
|
|
22
|
+
>
|
|
23
|
+
<slot>
|
|
24
|
+
{#if from}
|
|
25
|
+
<stop offset="0%" stop-color={from === true ? 'var(--tw-gradient-from)' : from} />
|
|
26
|
+
{/if}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
{#if via}
|
|
29
|
+
<!-- <stop offset="50%" stop-color={via === true ? 'var(--tw-gradient-via)' : via} /> -->
|
|
30
|
+
<stop offset="50%" stop-color={via} />
|
|
31
|
+
{/if}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
{#if to}
|
|
34
|
+
<stop offset="100%" stop-color={to === true ? 'var(--tw-gradient-to)' : to} />
|
|
35
|
+
{/if}
|
|
36
|
+
</slot>
|
|
37
|
+
</linearGradient>
|
|
38
38
|
</defs>
|
|
@@ -5,7 +5,7 @@ import { motionStore } from '../stores/motionStore';
|
|
|
5
5
|
export let data = undefined; // TODO: Update Type
|
|
6
6
|
export let orientation = 'horizontal';
|
|
7
7
|
/**
|
|
8
|
-
* Update source and target accessors to be
|
|
8
|
+
* Update source and target accessors to be compatible with d3-sankey. see: https://github.com/d3/d3-sankey#sankeyLinkHorizontal
|
|
9
9
|
*/
|
|
10
10
|
export let sankey = false;
|
|
11
11
|
export let source = sankey ? (d) => [d.source.x1, d.y0] : (d) => d.source;
|
|
@@ -28,13 +28,13 @@ $: {
|
|
|
28
28
|
|
|
29
29
|
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
|
30
30
|
<path
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
class="path-link"
|
|
32
|
+
d={$tweened_d}
|
|
33
|
+
stroke={color}
|
|
34
|
+
stroke-width={width}
|
|
35
|
+
fill="none"
|
|
36
|
+
on:click
|
|
37
|
+
on:mouseover
|
|
38
|
+
on:mouseout
|
|
39
|
+
{...$$restProps}
|
|
40
40
|
/>
|
|
@@ -4,7 +4,7 @@ declare const __propDef: {
|
|
|
4
4
|
props: {
|
|
5
5
|
[x: string]: any;
|
|
6
6
|
data?: any;
|
|
7
|
-
orientation?: "
|
|
7
|
+
orientation?: "horizontal" | "vertical" | undefined;
|
|
8
8
|
sankey?: boolean | undefined;
|
|
9
9
|
source?: ((d: any) => any) | undefined;
|
|
10
10
|
target?: ((d: any) => any) | undefined;
|
|
@@ -3,8 +3,8 @@ declare const __propDef: {
|
|
|
3
3
|
props: {
|
|
4
4
|
size?: [number, number] | undefined;
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
* see: https://github.com/d3/d3-hierarchy#pack_padding
|
|
7
|
+
*/ padding?: number | undefined;
|
|
8
8
|
};
|
|
9
9
|
events: {
|
|
10
10
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
|
-
orientation?: "
|
|
4
|
+
orientation?: "horizontal" | "vertical" | undefined;
|
|
5
5
|
size?: [number, number] | undefined;
|
|
6
6
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
* see: https://github.com/d3/d3-hierarchy#tree_nodeSize
|
|
8
|
+
*/ padding?: number | undefined;
|
|
9
9
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
* see: https://github.com/d3/d3-hierarchy#tree_nodeSize
|
|
11
|
+
*/ round?: boolean | undefined;
|
|
12
12
|
};
|
|
13
13
|
events: {
|
|
14
14
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>/*
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
2
|
+
TODO:
|
|
3
|
+
- [ ] Show path progressively show / animated in on load. Also fix sliding in from left side (at last in from bottom)
|
|
4
|
+
*/
|
|
5
5
|
import { getContext } from 'svelte';
|
|
6
6
|
import { line as d3Line } from 'd3-shape';
|
|
7
7
|
// import { interpolateString } from 'd3-interpolate';
|
|
@@ -34,20 +34,20 @@ $: {
|
|
|
34
34
|
</script>
|
|
35
35
|
|
|
36
36
|
<path
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
class="path-line"
|
|
38
|
+
d={$tweened_d}
|
|
39
|
+
stroke={color}
|
|
40
|
+
stroke-width={width}
|
|
41
|
+
{...$$restProps}
|
|
42
|
+
on:click
|
|
43
|
+
on:mousemove
|
|
44
|
+
on:mouseleave
|
|
45
45
|
/>
|
|
46
46
|
|
|
47
47
|
<style>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
.path-line {
|
|
49
|
+
fill: none;
|
|
50
|
+
stroke-linejoin: round;
|
|
51
|
+
stroke-linecap: round;
|
|
52
|
+
}
|
|
53
53
|
</style>
|
|
@@ -7,7 +7,7 @@ export let height;
|
|
|
7
7
|
</script>
|
|
8
8
|
|
|
9
9
|
<defs>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
<pattern {id} {width} {height} patternUnits="userSpaceOnUse" {...$$restProps}>
|
|
11
|
+
<slot />
|
|
12
|
+
</pattern>
|
|
13
13
|
</defs>
|
|
@@ -6,11 +6,11 @@ import Group from './Group.svelte';
|
|
|
6
6
|
import { degreesToRadians } from '../utils/math';
|
|
7
7
|
import { motionStore } from '../stores/motionStore';
|
|
8
8
|
/*
|
|
9
|
-
TODO:
|
|
10
|
-
- [ ] Offset (always, on hover)
|
|
11
|
-
- [ ] Labels
|
|
12
|
-
- [ ] Multiple nested circles (zScale, or take in data to override context data). See Path/Area/Threshold
|
|
13
|
-
- [ ] Hover events / change innerRadius / outerRadius, etc
|
|
9
|
+
TODO:
|
|
10
|
+
- [ ] Offset (always, on hover)
|
|
11
|
+
- [ ] Labels
|
|
12
|
+
- [ ] Multiple nested circles (zScale, or take in data to override context data). See Path/Area/Threshold
|
|
13
|
+
- [ ] Hover events / change innerRadius / outerRadius, etc
|
|
14
14
|
*/
|
|
15
15
|
export let data = undefined; // TODO: Update Type
|
|
16
16
|
/**
|
|
@@ -76,20 +76,20 @@ function getColor(item, index) {
|
|
|
76
76
|
</script>
|
|
77
77
|
|
|
78
78
|
<Group center>
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
79
|
+
<slot {arcs}>
|
|
80
|
+
{#each arcs as arc, index}
|
|
81
|
+
<Arc
|
|
82
|
+
startAngle={arc.startAngle}
|
|
83
|
+
endAngle={arc.endAngle}
|
|
84
|
+
padAngle={arc.padAngle}
|
|
85
|
+
{innerRadius}
|
|
86
|
+
{outerRadius}
|
|
87
|
+
{cornerRadius}
|
|
88
|
+
{offset}
|
|
89
|
+
fill={getColor(arc.data, index)}
|
|
90
|
+
on:mousemove={(e) => tooltip?.show(e, arc.data)}
|
|
91
|
+
on:mouseleave={(e) => tooltip?.hide()}
|
|
92
|
+
/>
|
|
93
|
+
{/each}
|
|
94
|
+
</slot>
|
|
95
95
|
</Group>
|
|
@@ -5,24 +5,24 @@ declare const __propDef: {
|
|
|
5
5
|
props: {
|
|
6
6
|
data?: any;
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
* Range [min,max] in degrees. See also startAngle/endAngle
|
|
9
|
+
*/ range?: number[] | undefined;
|
|
10
10
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
* Start angle in radians
|
|
12
|
+
*/ startAngle?: number | undefined;
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
* End angle in radians
|
|
15
|
+
*/ endAngle?: number | undefined;
|
|
16
16
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
* Define innerRadius.
|
|
18
|
+
* value >= 1: discrete value
|
|
19
|
+
* value > 0: percent of `outerRadius`
|
|
20
|
+
* value < 0: offset of `outerRadius`
|
|
21
|
+
* default: yRange min
|
|
22
|
+
*/ innerRadius?: undefined;
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
* Define outerRadius. Defaults to yRange max/2 (ie. chart height / 2)
|
|
25
|
+
*/ outerRadius?: undefined;
|
|
26
26
|
cornerRadius?: number | undefined;
|
|
27
27
|
padAngle?: number | undefined;
|
|
28
28
|
color?: string | ((obj: {
|
|
@@ -33,11 +33,11 @@ declare const __propDef: {
|
|
|
33
33
|
spring?: boolean | Parameters<typeof springStore>[1];
|
|
34
34
|
tweened?: boolean | Parameters<typeof tweenedStore>[1];
|
|
35
35
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
* Offset all arcs from center
|
|
37
|
+
*/ offset?: number | undefined;
|
|
38
38
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
* Tooltip context to setup mouse events to show tooltip for related data
|
|
40
|
+
*/ tooltip?: TooltipContextValue | undefined;
|
|
41
41
|
};
|
|
42
42
|
events: {
|
|
43
43
|
[evt: string]: CustomEvent<any>;
|
|
@@ -36,9 +36,9 @@ function getColor(item, index) {
|
|
|
36
36
|
$: points = $data.flatMap((d) => {
|
|
37
37
|
if (Array.isArray($config.x)) {
|
|
38
38
|
/*
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
x={["prop1" ,"prop2"]}
|
|
40
|
+
y="prop3"
|
|
41
|
+
*/
|
|
42
42
|
return $xGet(d).map((x) => {
|
|
43
43
|
return {
|
|
44
44
|
x: x + getOffset(x, offsetX, $xScale),
|
|
@@ -49,9 +49,9 @@ $: points = $data.flatMap((d) => {
|
|
|
49
49
|
}
|
|
50
50
|
else if (Array.isArray($config.y)) {
|
|
51
51
|
/*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
x="prop1"
|
|
53
|
+
y={["prop2" ,"prop3"]}
|
|
54
|
+
*/
|
|
55
55
|
return $yGet(d).map((y) => {
|
|
56
56
|
return {
|
|
57
57
|
x: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
|
|
@@ -62,9 +62,9 @@ $: points = $data.flatMap((d) => {
|
|
|
62
62
|
}
|
|
63
63
|
else {
|
|
64
64
|
/*
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
x="prop1"
|
|
66
|
+
y="prop2"
|
|
67
|
+
*/
|
|
68
68
|
return {
|
|
69
69
|
x: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
|
|
70
70
|
y: $yGet(d) + getOffset($yGet(d), offsetY, $yScale),
|
|
@@ -75,9 +75,9 @@ $: points = $data.flatMap((d) => {
|
|
|
75
75
|
</script>
|
|
76
76
|
|
|
77
77
|
<slot {points}>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
<g class="point-group">
|
|
79
|
+
{#each points as point, index}
|
|
80
|
+
<Circle cx={point.x} cy={point.y} {r} fill={getColor(point.data, index)} {...$$restProps} />
|
|
81
|
+
{/each}
|
|
82
|
+
</g>
|
|
83
83
|
</slot>
|
|
@@ -17,12 +17,12 @@ $: tweened_height.set(height);
|
|
|
17
17
|
|
|
18
18
|
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
|
19
19
|
<rect
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
x={$tweened_x}
|
|
21
|
+
y={$tweened_y}
|
|
22
|
+
width={$tweened_width}
|
|
23
|
+
height={$tweened_height}
|
|
24
|
+
{...$$restProps}
|
|
25
|
+
on:click
|
|
26
|
+
on:mouseover
|
|
27
|
+
on:mouseout
|
|
28
28
|
/>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<script>import { uniqueId } from 'svelte-ux
|
|
1
|
+
<script>import { uniqueId } from 'svelte-ux';
|
|
2
2
|
import ClipPath from './ClipPath.svelte';
|
|
3
3
|
import Rect from './Rect.svelte';
|
|
4
4
|
/** Unique id for clipPath */
|
|
@@ -12,11 +12,11 @@ export let tweened = undefined;
|
|
|
12
12
|
</script>
|
|
13
13
|
|
|
14
14
|
<ClipPath {id}>
|
|
15
|
-
|
|
15
|
+
<Rect {x} {y} {width} {height} {spring} {tweened} />
|
|
16
16
|
</ClipPath>
|
|
17
17
|
|
|
18
18
|
{#if $$slots.default}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
<g style="clip-path: url(#{id})" on:click on:mousemove on:mouseleave>
|
|
20
|
+
<slot {id} />
|
|
21
|
+
</g>
|
|
22
22
|
{/if}
|
|
@@ -5,8 +5,8 @@ declare const __propDef: {
|
|
|
5
5
|
nodes?: ((d: any) => any) | undefined;
|
|
6
6
|
nodeId?: ((d: any) => any) | undefined;
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
* see: https://github.com/d3/d3-sankey#alignments
|
|
9
|
+
*/ nodeAlign?: "left" | "right" | "center" | "justify" | ((node: SankeyNode<any, any>, n: number) => number) | undefined;
|
|
10
10
|
nodeWidth?: number | undefined;
|
|
11
11
|
nodePadding?: number | undefined;
|
|
12
12
|
nodeSort?: undefined;
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
<script>import { getStringWidth } from '../utils/string';
|
|
2
2
|
/*
|
|
3
|
-
TODO:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
TODO:
|
|
4
|
+
- [ ] Handle styled text (use <slot /> to measure?)
|
|
5
|
+
- [ ] Simplify by using `alignment-baseline` / `dominant-baseline`, rework multiline or drop support, etc
|
|
6
|
+
- https://svelte.dev/repl/f12d3003313a43ba8a0be53e5786f1c7?version=3.44.3
|
|
7
|
+
- https://observablehq.com/@neocartocnrs/cheat-sheet-on-texts-in-svg
|
|
8
8
|
|
|
9
|
-
Reference:
|
|
10
|
-
- https://bl.ocks.org/mbostock/7555321
|
|
11
|
-
- https://github.com/airbnb/visx/blob/master/packages/visx-text/src/Text.tsx
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
Reference:
|
|
10
|
+
- https://bl.ocks.org/mbostock/7555321
|
|
11
|
+
- https://github.com/airbnb/visx/blob/master/packages/visx-text/src/Text.tsx
|
|
12
|
+
- https://airbnb.io/visx/text
|
|
13
|
+
- https://github.com/airbnb/visx/blob/master/packages/visx-demo/src/pages/text.tsx
|
|
14
14
|
*/
|
|
15
15
|
/** text value */
|
|
16
16
|
export let value = 0;
|
|
17
|
-
/** Maximum width to occupy (approximate as words are not split)
|
|
17
|
+
/** Maximum width to occupy (approximate as words are not split) */
|
|
18
18
|
export let width = undefined;
|
|
19
|
-
/** x position of the text
|
|
19
|
+
/** x position of the text */
|
|
20
20
|
export let x = 0;
|
|
21
|
-
/** y position of the text
|
|
21
|
+
/** y position of the text */
|
|
22
22
|
export let y = 0;
|
|
23
|
-
/** dx offset of the text
|
|
23
|
+
/** dx offset of the text */
|
|
24
24
|
export let dx = 0;
|
|
25
|
-
/** dy offset of the text
|
|
25
|
+
/** dy offset of the text */
|
|
26
26
|
export let dy = 0;
|
|
27
|
-
/** Desired "line height" of the text, implemented as y offsets
|
|
27
|
+
/** Desired "line height" of the text, implemented as y offsets */
|
|
28
28
|
export let lineHeight = '1em';
|
|
29
|
-
/** Cap height of the text
|
|
29
|
+
/** Cap height of the text */
|
|
30
30
|
export let capHeight = '0.71em'; // Magic number from d3
|
|
31
|
-
/** Whether to scale the fontSize to accommodate the specified width
|
|
31
|
+
/** Whether to scale the fontSize to accommodate the specified width */
|
|
32
32
|
export let scaleToFit = false;
|
|
33
|
-
/** Horizontal text anchor
|
|
33
|
+
/** Horizontal text anchor */
|
|
34
34
|
export let textAnchor = 'start';
|
|
35
|
-
/** Vertical text anchor
|
|
35
|
+
/** Vertical text anchor */
|
|
36
36
|
export let verticalAnchor = 'end'; // default SVG behavior
|
|
37
|
-
/** Rotational angle of the text
|
|
37
|
+
/** Rotational angle of the text */
|
|
38
38
|
export let rotate = undefined;
|
|
39
39
|
let wordsByLines = [];
|
|
40
40
|
let wordsWithWidth = [];
|
|
@@ -119,16 +119,16 @@ function isValidXOrY(xOrY) {
|
|
|
119
119
|
}
|
|
120
120
|
</script>
|
|
121
121
|
|
|
122
|
-
<!-- overflow: visible
|
|
123
|
-
<!-- paint-order: stroke
|
|
122
|
+
<!-- `overflow: visible` allow contents to be shown outside element -->
|
|
123
|
+
<!-- `paint-order: stroke` supports stroke outlining text -->
|
|
124
124
|
<svg x={dx} y={dy} style="overflow: visible; paint-order: stroke;">
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
125
|
+
{#if isValidXOrY(x) && isValidXOrY(y)}
|
|
126
|
+
<text {x} {y} {transform} text-anchor={textAnchor} {...$$restProps}>
|
|
127
|
+
{#each wordsByLines as line, index}
|
|
128
|
+
<tspan {x} dy={index === 0 ? startDy : lineHeight}>
|
|
129
|
+
{line.words.join(' ')}
|
|
130
|
+
</tspan>
|
|
131
|
+
{/each}
|
|
132
|
+
</text>
|
|
133
|
+
{/if}
|
|
134
134
|
</svg>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>/*
|
|
2
|
-
See also:
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
See also:
|
|
3
|
+
- https://observablehq.com/@d3/difference-chart
|
|
4
|
+
- https://github.com/airbnb/visx/issues/245
|
|
5
5
|
*/
|
|
6
6
|
import { getContext } from 'svelte';
|
|
7
7
|
import { area as d3Area, line as d3Line } from 'd3-shape';
|
|
@@ -57,30 +57,30 @@ $: if (defined)
|
|
|
57
57
|
|
|
58
58
|
<!-- Recreate on curve change as otherwise is 1 state change behind for some reason -->
|
|
59
59
|
{#key curve}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
60
|
+
<g class="clip-paths">
|
|
61
|
+
<defs>
|
|
62
|
+
<clipPath id="threshold-clip-below-{id}">
|
|
63
|
+
<path d={clipPathBelow(data ?? $contextData)} />
|
|
64
|
+
</clipPath>
|
|
65
|
+
<clipPath id="threshold-clip-above-{id}">
|
|
66
|
+
<path d={clipPathAbove(data ?? $contextData)} />
|
|
67
|
+
</clipPath>
|
|
68
|
+
</defs>
|
|
69
|
+
</g>
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
<slot
|
|
72
|
+
name="pathAbove"
|
|
73
|
+
areaPathData={areaPath(data ?? $contextData)}
|
|
74
|
+
clipPath="url(#threshold-clip-below-{id})"
|
|
75
|
+
linePathData={linePathAbove(data ?? $contextData)}
|
|
76
|
+
/>
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
<slot
|
|
79
|
+
name="pathBelow"
|
|
80
|
+
areaPathData={areaPath(data ?? $contextData)}
|
|
81
|
+
clipPath="url(#threshold-clip-above-{id})"
|
|
82
|
+
linePathData={linePathBelow(data ?? $contextData)}
|
|
83
|
+
/>
|
|
84
84
|
{/key}
|
|
85
85
|
|
|
86
86
|
<!-- Fix `<Threshold> received an unexpected slot "default".` warning -->
|
|
@@ -57,28 +57,28 @@ $: if (!disableCache) {
|
|
|
57
57
|
|
|
58
58
|
<!-- To avoid aliasing artifacts (thin white lines) between tiles, two layers of tiles are drawn, with the lower layer’s tiles enlarged by one pixel -->
|
|
59
59
|
<image
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
xlink:href={href}
|
|
61
|
+
x={(x + tx) * k - 0.5}
|
|
62
|
+
y={(y + ty) * k - 0.5}
|
|
63
|
+
width={k + 1}
|
|
64
|
+
height={k + 1}
|
|
65
65
|
/>
|
|
66
66
|
<image xlink:href={href} x={(x + tx) * k} y={(y + ty) * k} width={k} height={k} />
|
|
67
67
|
{#if debug}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
68
|
+
<rect
|
|
69
|
+
x={(x + tx) * k}
|
|
70
|
+
y={(y + ty) * k}
|
|
71
|
+
width={k}
|
|
72
|
+
height={k}
|
|
73
|
+
class="stroke-red-500/50 fill-none"
|
|
74
|
+
/>
|
|
75
|
+
<Text
|
|
76
|
+
x={(x + tx) * k}
|
|
77
|
+
y={(y + ty) * k}
|
|
78
|
+
verticalAnchor="start"
|
|
79
|
+
dx={2}
|
|
80
|
+
dy={-2}
|
|
81
|
+
value="{x}-{y}-{z}"
|
|
82
|
+
class="text-[8px] fill-black/50"
|
|
83
|
+
/>
|
|
84
84
|
{/if}
|