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
|
@@ -13,11 +13,11 @@ $: tweened_r.set(r);
|
|
|
13
13
|
</script>
|
|
14
14
|
|
|
15
15
|
<circle
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
cx={$tweened_cx}
|
|
17
|
+
cy={$tweened_cy}
|
|
18
|
+
r={$tweened_r}
|
|
19
|
+
{...$$restProps}
|
|
20
|
+
on:click
|
|
21
|
+
on:mousemove
|
|
22
|
+
on:mouseleave
|
|
23
23
|
/>
|
|
@@ -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 Circle from './Circle.svelte';
|
|
4
4
|
/** Unique id for clipPath */
|
|
@@ -11,11 +11,11 @@ export let tweened = undefined;
|
|
|
11
11
|
</script>
|
|
12
12
|
|
|
13
13
|
<ClipPath {id}>
|
|
14
|
-
|
|
14
|
+
<Circle {cx} {cy} {r} {spring} {tweened} />
|
|
15
15
|
</ClipPath>
|
|
16
16
|
|
|
17
17
|
{#if $$slots.default}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
<g style="clip-path: url(#{id})" on:click on:mousemove on:mouseleave>
|
|
19
|
+
<slot {id} />
|
|
20
|
+
</g>
|
|
21
21
|
{/if}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
<script>import { uniqueId } from 'svelte-ux
|
|
1
|
+
<script>import { uniqueId } from 'svelte-ux';
|
|
2
2
|
/** Unique id for clipPath */
|
|
3
3
|
export let id = uniqueId('clipPath-');
|
|
4
4
|
</script>
|
|
5
5
|
|
|
6
6
|
<defs>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
<clipPath {id} {...$$restProps}>
|
|
8
|
+
<slot {id} />
|
|
9
|
+
</clipPath>
|
|
10
10
|
</defs>
|
|
@@ -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
|
/** Id of path or shape */
|
|
4
4
|
export let refId;
|
|
@@ -7,11 +7,11 @@ export let clipPathId = uniqueId('clipPath-');
|
|
|
7
7
|
</script>
|
|
8
8
|
|
|
9
9
|
<ClipPath id={clipPathId}>
|
|
10
|
-
|
|
10
|
+
<use href="#{refId}" />
|
|
11
11
|
</ClipPath>
|
|
12
12
|
|
|
13
13
|
{#if $$slots.default}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
<g style="clip-path: url(#{clipPathId})" on:click on:mousemove on:mouseleave on:keydown>
|
|
15
|
+
<slot {refId} {clipPathId} />
|
|
16
|
+
</g>
|
|
17
17
|
{/if}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script>/*
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
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
6
|
import { getContext } from 'svelte';
|
|
7
7
|
import { extent } from 'd3-array';
|
|
8
8
|
import Line from './Line.svelte';
|
|
@@ -28,9 +28,9 @@ function getOffset(value, offset, scale) {
|
|
|
28
28
|
$: points = $data.flatMap((d) => {
|
|
29
29
|
if (Array.isArray($config.x)) {
|
|
30
30
|
/*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
x={["prop1" ,"prop2"]}
|
|
32
|
+
y="prop3"
|
|
33
|
+
*/
|
|
34
34
|
const [xMin, xMax] = extent($xGet(d));
|
|
35
35
|
return {
|
|
36
36
|
x1: xMin + getOffset(xMin, offsetX, $xScale),
|
|
@@ -41,9 +41,9 @@ $: points = $data.flatMap((d) => {
|
|
|
41
41
|
}
|
|
42
42
|
else if (Array.isArray($config.y)) {
|
|
43
43
|
/*
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
x="prop1"
|
|
45
|
+
y={["prop2" ,"prop3"]}
|
|
46
|
+
*/
|
|
47
47
|
const [yMin, yMax] = extent($yGet(d));
|
|
48
48
|
return {
|
|
49
49
|
x1: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
|
|
@@ -54,9 +54,9 @@ $: points = $data.flatMap((d) => {
|
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
56
|
/*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
x="prop1"
|
|
58
|
+
y="prop2"
|
|
59
|
+
*/
|
|
60
60
|
// Not really supported (nothing to connect...)
|
|
61
61
|
return {
|
|
62
62
|
x1: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
|
|
@@ -69,7 +69,7 @@ $: points = $data.flatMap((d) => {
|
|
|
69
69
|
</script>
|
|
70
70
|
|
|
71
71
|
<g class="connected-points">
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
{#each points as p}
|
|
73
|
+
<Line x1={p.x1} y1={p.y1} x2={p.x2} y2={p.y2} {...$$restProps} />
|
|
74
|
+
{/each}
|
|
75
75
|
</g>
|
|
@@ -42,15 +42,15 @@ $: if (renderContext === 'canvas' && $ctx) {
|
|
|
42
42
|
</script>
|
|
43
43
|
|
|
44
44
|
{#if renderContext === 'svg'}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
<slot {geoPath}>
|
|
46
|
+
<path
|
|
47
|
+
d={geoPath(geojson)}
|
|
48
|
+
fill={fill || (fillScale && $rGet(fillScale)) || 'transparent'}
|
|
49
|
+
stroke={stroke || 'black'}
|
|
50
|
+
on:mousemove={(e) => tooltip?.show(e, geojson)}
|
|
51
|
+
on:mouseleave={(e) => tooltip?.hide()}
|
|
52
|
+
on:click={(event) => dispatch('click', { geoPath, event })}
|
|
53
|
+
{...$$restProps}
|
|
54
|
+
/>
|
|
55
|
+
</slot>
|
|
56
56
|
{/if}
|
|
@@ -39,9 +39,9 @@ $: if (renderContext === 'canvas' && $ctx && url) {
|
|
|
39
39
|
</script>
|
|
40
40
|
|
|
41
41
|
{#if renderContext === 'svg' && url}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
<slot {tiles}>
|
|
43
|
+
{#each tiles as [x, y, z] (url(x, y, z))}
|
|
44
|
+
<TileImage {url} {x} {y} {z} {tx} {ty} {k} {disableCache} {debug} />
|
|
45
|
+
{/each}
|
|
46
|
+
</slot>
|
|
47
47
|
{/if}
|
|
@@ -9,18 +9,18 @@ $: graticule.step(step);
|
|
|
9
9
|
</script>
|
|
10
10
|
|
|
11
11
|
<g class="graticule">
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
<!-- TODO: Any reason to still render the single `MultiLineString` path if using `lines` and/or `outline` -->
|
|
13
|
+
{#if !lines && !outline}
|
|
14
|
+
<GeoPath geojson={graticule()} {...$$restProps} />
|
|
15
|
+
{/if}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
{#if lines}
|
|
18
|
+
{#each graticule.lines() as line}
|
|
19
|
+
<GeoPath geojson={line} {...lines} />
|
|
20
|
+
{/each}
|
|
21
|
+
{/if}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
{#if outline}
|
|
24
|
+
<GeoPath geojson={graticule.outline()} {...outline} />
|
|
25
|
+
{/if}
|
|
26
26
|
</g>
|
|
@@ -115,30 +115,30 @@ $: if ($tooltip.data) {
|
|
|
115
115
|
</script>
|
|
116
116
|
|
|
117
117
|
{#if $tooltip.data}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
118
|
+
{#each lines as line}
|
|
119
|
+
<Line
|
|
120
|
+
spring
|
|
121
|
+
x1={line.x1}
|
|
122
|
+
y1={line.y1}
|
|
123
|
+
x2={line.x2}
|
|
124
|
+
y2={line.y2}
|
|
125
|
+
stroke="rgba(0,0,0,.5)"
|
|
126
|
+
stroke-width={2}
|
|
127
|
+
style="pointerEvents: none"
|
|
128
|
+
stroke-dasharray="2,2"
|
|
129
|
+
/>
|
|
130
|
+
{/each}
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
132
|
+
{#each points as point}
|
|
133
|
+
<Circle
|
|
134
|
+
spring
|
|
135
|
+
cx={point.x}
|
|
136
|
+
cy={point.y}
|
|
137
|
+
r={7}
|
|
138
|
+
fill="rgba(255,255,255,.9)"
|
|
139
|
+
stroke={point.color}
|
|
140
|
+
stroke-width={2}
|
|
141
|
+
/>
|
|
142
|
+
<Circle spring cx={point.x} cy={point.y} r={3} fill={point.color} />
|
|
143
|
+
{/each}
|
|
144
144
|
{/if}
|
|
@@ -4,79 +4,39 @@
|
|
|
4
4
|
* - [ ] Support multiple values (threshold, stacks, etc)
|
|
5
5
|
*/
|
|
6
6
|
import { getContext } from 'svelte';
|
|
7
|
-
import { scaleBand } from 'd3-scale';
|
|
8
|
-
import { max, min } from 'd3-array';
|
|
9
7
|
import Text from './Text.svelte';
|
|
8
|
+
import { format as formatValue } from 'svelte-ux';
|
|
10
9
|
import { formatNumberAsStyle } from 'svelte-ux/utils/number';
|
|
10
|
+
import { greatestAbs } from 'svelte-ux/utils/array';
|
|
11
11
|
import { isScaleBand } from '../utils/scales';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export let orientation = 'auto';
|
|
12
|
+
import { createDimensionGetter } from '../utils/rect';
|
|
13
|
+
const { flatData, yScale, x, y, custom } = getContext('LayerCake');
|
|
14
|
+
// export let orientation: 'outside' | 'inside' | 'auto' = 'auto';
|
|
16
15
|
export let significantDigits = 3;
|
|
17
16
|
export let format = undefined;
|
|
18
17
|
export let formatStyle = null;
|
|
19
|
-
export let overlap = false;
|
|
18
|
+
// export let overlap = false;
|
|
20
19
|
$: yBaseline = $custom?.yBaseline ?? 0;
|
|
21
20
|
export let groupBy = undefined;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
width = groupBy ? x1Scale.bandwidth() : $xScale.bandwidth();
|
|
33
|
-
x += (groupBy ? x1Scale(item[groupBy]) : 0) + width / 2;
|
|
34
|
-
}
|
|
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 = min($yRange); // or `0`?
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
// Negative value
|
|
55
|
-
yTop = min($yRange); // or `0`?
|
|
56
|
-
yBottom = yValue;
|
|
57
|
-
}
|
|
58
|
-
if (yBottom < 0) {
|
|
59
|
-
// Show label below
|
|
60
|
-
return {
|
|
61
|
-
x,
|
|
62
|
-
y: $yScale(yBottom),
|
|
63
|
-
dy: '0.5em',
|
|
64
|
-
width
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
// Show label above
|
|
69
|
-
return {
|
|
70
|
-
x,
|
|
71
|
-
y: $yScale(yTop),
|
|
72
|
-
dy: '-0.6em',
|
|
73
|
-
width
|
|
74
|
-
};
|
|
21
|
+
export let groupPaddingInner = 0.2;
|
|
22
|
+
export let groupPaddingOuter = 0;
|
|
23
|
+
$: getDimensions = createDimensionGetter(getContext('LayerCake'), {
|
|
24
|
+
// x,
|
|
25
|
+
// y,
|
|
26
|
+
groupBy,
|
|
27
|
+
// padding,
|
|
28
|
+
groupPadding: {
|
|
29
|
+
inner: groupPaddingInner,
|
|
30
|
+
outer: groupPaddingOuter
|
|
75
31
|
}
|
|
32
|
+
});
|
|
33
|
+
$: getValue = (item) => (isScaleBand($yScale) ? $x(item) : $y(item));
|
|
34
|
+
$: getLabelValue = (item) => {
|
|
35
|
+
const value = getValue(item);
|
|
36
|
+
return (Array.isArray(value) ? greatestAbs(value) : value) + yBaseline;
|
|
76
37
|
};
|
|
77
|
-
$:
|
|
78
|
-
const
|
|
79
|
-
const labelValue = (Array.isArray(value) ? greatestAbs(value) : value) + yBaseline;
|
|
38
|
+
$: getFormattedValue = (item) => {
|
|
39
|
+
const labelValue = getLabelValue(item);
|
|
80
40
|
let formattedValue = labelValue;
|
|
81
41
|
if (labelValue != null) {
|
|
82
42
|
if (format) {
|
|
@@ -90,17 +50,66 @@ $: getValue = (item) => {
|
|
|
90
50
|
}
|
|
91
51
|
return formattedValue ?? '';
|
|
92
52
|
};
|
|
53
|
+
$: getTextProps = (item) => {
|
|
54
|
+
const labelValue = getLabelValue(item);
|
|
55
|
+
const dimensions = $getDimensions(item);
|
|
56
|
+
if (isScaleBand($yScale)) {
|
|
57
|
+
// Position label left/right on horizontal bars
|
|
58
|
+
if (labelValue < 0) {
|
|
59
|
+
// left
|
|
60
|
+
return {
|
|
61
|
+
x: dimensions?.x - 4,
|
|
62
|
+
y: dimensions?.y + (dimensions?.height ?? 0) / 2,
|
|
63
|
+
textAnchor: 'end',
|
|
64
|
+
verticalAnchor: 'middle',
|
|
65
|
+
capHeight: '.6rem'
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// right
|
|
70
|
+
return {
|
|
71
|
+
x: dimensions?.x + dimensions?.width + 4,
|
|
72
|
+
y: dimensions?.y + (dimensions?.height ?? 0) / 2,
|
|
73
|
+
textAnchor: 'start',
|
|
74
|
+
verticalAnchor: 'middle',
|
|
75
|
+
capHeight: '.6rem'
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// Position label top/bottom on vertical bars
|
|
81
|
+
if (labelValue < 0) {
|
|
82
|
+
// bottom
|
|
83
|
+
return {
|
|
84
|
+
x: dimensions?.x + (dimensions?.width ?? 0) / 2,
|
|
85
|
+
y: dimensions?.y + dimensions?.height,
|
|
86
|
+
dy: '0.5em',
|
|
87
|
+
textAnchor: 'middle',
|
|
88
|
+
verticalAnchor: 'middle'
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// top
|
|
93
|
+
return {
|
|
94
|
+
x: dimensions?.x + (dimensions?.width ?? 0) / 2,
|
|
95
|
+
y: dimensions?.y,
|
|
96
|
+
dy: '-0.6em',
|
|
97
|
+
textAnchor: 'middle',
|
|
98
|
+
verticalAnchor: 'middle'
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
93
103
|
</script>
|
|
94
104
|
|
|
95
|
-
<g class="
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
{/each}
|
|
105
|
+
<g class="Labels">
|
|
106
|
+
{#each $flatData as item, index}
|
|
107
|
+
<!-- TODO: Add labels for each item when array/stack? Use `getValue(item)` instead and iterate -->
|
|
108
|
+
<Text
|
|
109
|
+
value={getFormattedValue(item)}
|
|
110
|
+
class="text-xs stroke-white [stroke-width:2px]"
|
|
111
|
+
{...getTextProps(item)}
|
|
112
|
+
{...$$restProps}
|
|
113
|
+
/>
|
|
114
|
+
{/each}
|
|
106
115
|
</g>
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import { type FormatType } from 'svelte-ux';
|
|
2
3
|
declare const __propDef: {
|
|
3
4
|
props: {
|
|
4
5
|
[x: string]: any;
|
|
5
|
-
orientation?: "auto" | "outside" | "inside" | undefined;
|
|
6
6
|
significantDigits?: number | undefined;
|
|
7
|
-
format?:
|
|
7
|
+
format?: FormatType;
|
|
8
8
|
formatStyle?: any;
|
|
9
|
-
overlap?: boolean | undefined;
|
|
10
9
|
groupBy?: string | undefined;
|
|
10
|
+
groupPaddingInner?: number | undefined;
|
|
11
|
+
groupPaddingOuter?: number | undefined;
|
|
11
12
|
};
|
|
12
13
|
events: {
|
|
13
14
|
[evt: string]: CustomEvent<any>;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { scaleBand, scaleLinear } from 'd3-scale';
|
|
3
3
|
import { quantize, interpolate, interpolateRound } from 'd3-interpolate';
|
|
4
4
|
import { quantile, range } from 'd3-array';
|
|
5
|
-
import { format } from 'svelte-ux
|
|
5
|
+
import { format } from 'svelte-ux';
|
|
6
6
|
import ColorRamp from './ColorRamp.svelte';
|
|
7
|
-
import { cls } from 'svelte-ux
|
|
7
|
+
import { cls } from 'svelte-ux';
|
|
8
8
|
const { rScale } = getContext('LayerCake') ?? {};
|
|
9
9
|
export let scale = undefined;
|
|
10
10
|
export let title = '';
|
|
@@ -101,64 +101,64 @@ else {
|
|
|
101
101
|
</script>
|
|
102
102
|
|
|
103
103
|
<div
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
104
|
+
class={cls(
|
|
105
|
+
'inline-block',
|
|
106
|
+
{
|
|
107
|
+
'top-left': 'absolute top-0 left-0',
|
|
108
|
+
top: 'absolute top-0 left-1/2 -translate-x-1/2',
|
|
109
|
+
'top-right': 'absolute top-0 right-0',
|
|
110
|
+
left: 'absolute top-1/2 left-0 -translate-y-1/2',
|
|
111
|
+
center: 'absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2',
|
|
112
|
+
right: 'absolute top-1/2 right-0 -translate-y-1/2',
|
|
113
|
+
'bottom-left': 'absolute bottom-0 left-0',
|
|
114
|
+
bottom: 'absolute bottom-0 left-1/2 -translate-x-1/2',
|
|
115
|
+
'bottom-right': 'absolute bottom-0 right-0'
|
|
116
|
+
}[placement],
|
|
117
|
+
classes.root
|
|
118
|
+
)}
|
|
119
|
+
{...$$restProps}
|
|
120
120
|
>
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
121
|
+
<div class={cls('text-[10px] font-semibold', classes.title)}>{title}</div>
|
|
122
|
+
<slot values={tickValues} {scale}>
|
|
123
|
+
<svg
|
|
124
|
+
{width}
|
|
125
|
+
height={height + tickSize + tickFontSize}
|
|
126
|
+
viewBox="0 0 {width} {height + tickSize + tickFontSize}"
|
|
127
|
+
class="overflow-visible"
|
|
128
|
+
>
|
|
129
|
+
<g>
|
|
130
|
+
{#if interpolator}
|
|
131
|
+
<ColorRamp {width} {height} {interpolator} />
|
|
132
|
+
{:else if swatches}
|
|
133
|
+
{#each swatches as swatch, i}
|
|
134
|
+
<rect {...swatch} />
|
|
135
|
+
{/each}
|
|
136
|
+
{/if}
|
|
137
|
+
</g>
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
139
|
+
<g>
|
|
140
|
+
{#each tickValues ?? xScale?.ticks?.(ticks) ?? [] as tick, i}
|
|
141
|
+
<text
|
|
142
|
+
text-anchor="middle"
|
|
143
|
+
x={xScale(tick) + tickLabelOffset}
|
|
144
|
+
y={height + tickSize + tickFontSize}
|
|
145
|
+
style:font-size={tickFontSize}
|
|
146
|
+
class={classes.label}
|
|
147
|
+
>
|
|
148
|
+
{tickFormat ? format(tick, tickFormat) : tick}
|
|
149
|
+
</text>
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
151
|
+
{#if tickLine}
|
|
152
|
+
<line
|
|
153
|
+
x1={xScale(tick)}
|
|
154
|
+
y1={0}
|
|
155
|
+
x2={xScale(tick)}
|
|
156
|
+
y2={height + tickSize}
|
|
157
|
+
class={cls('stroke-black', classes.tick)}
|
|
158
|
+
/>
|
|
159
|
+
{/if}
|
|
160
|
+
{/each}
|
|
161
|
+
</g>
|
|
162
|
+
</svg>
|
|
163
|
+
</slot>
|
|
164
164
|
</div>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import { type FormatType } from 'svelte-ux';
|
|
2
3
|
declare const __propDef: {
|
|
3
4
|
props: {
|
|
4
5
|
[x: string]: any;
|
|
@@ -7,11 +8,11 @@ declare const __propDef: {
|
|
|
7
8
|
width?: number | undefined;
|
|
8
9
|
height?: number | undefined;
|
|
9
10
|
ticks?: number | undefined;
|
|
10
|
-
tickFormat?:
|
|
11
|
+
tickFormat?: FormatType;
|
|
11
12
|
tickValues?: any[] | undefined;
|
|
12
13
|
tickFontSize?: number | undefined;
|
|
13
14
|
tickSize?: number | undefined;
|
|
14
|
-
placement?: ("
|
|
15
|
+
placement?: ("top" | "bottom" | "left" | "right" | "center" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
|
|
15
16
|
classes?: {
|
|
16
17
|
root?: string | undefined;
|
|
17
18
|
title?: string | undefined;
|