layerchart 0.54.0 → 0.55.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 +170 -144
- package/dist/components/Area.svelte +96 -67
- package/dist/components/Area.svelte.d.ts +1 -0
- package/dist/components/Axis.svelte +205 -155
- package/dist/components/Bar.svelte +72 -45
- package/dist/components/Bars.svelte +45 -34
- package/dist/components/Blur.svelte +5 -3
- package/dist/components/Bounds.svelte +37 -21
- package/dist/components/Brush.svelte +269 -112
- package/dist/components/Brush.svelte.d.ts +7 -0
- package/dist/components/Calendar.svelte +51 -38
- package/dist/components/Chart.svelte +295 -74
- package/dist/components/Chart.svelte.d.ts +17 -17
- package/dist/components/ChartClipPath.svelte +8 -5
- package/dist/components/ChartContext.svelte +243 -93
- package/dist/components/ChartContext.svelte.d.ts +15 -23
- package/dist/components/Circle.svelte +25 -16
- package/dist/components/CircleClipPath.svelte +16 -10
- package/dist/components/ClipPath.svelte +11 -7
- package/dist/components/ColorRamp.svelte +12 -10
- package/dist/components/ForceSimulation.svelte +185 -116
- package/dist/components/Frame.svelte +10 -6
- package/dist/components/GeoCircle.svelte +15 -9
- package/dist/components/GeoContext.svelte +109 -62
- package/dist/components/GeoEdgeFade.svelte +20 -14
- package/dist/components/GeoPath.svelte +107 -69
- package/dist/components/GeoPoint.svelte +32 -18
- package/dist/components/GeoSpline.svelte +30 -22
- package/dist/components/GeoTile.svelte +40 -30
- package/dist/components/GeoVisible.svelte +10 -7
- package/dist/components/Graticule.svelte +14 -8
- package/dist/components/Grid.svelte +75 -48
- package/dist/components/Group.svelte +43 -31
- package/dist/components/Highlight.svelte +284 -243
- package/dist/components/HitCanvas.svelte +75 -42
- package/dist/components/Hull.svelte +40 -20
- package/dist/components/Labels.svelte +81 -70
- package/dist/components/Legend.svelte +105 -74
- package/dist/components/Legend.svelte.d.ts +1 -1
- package/dist/components/Line.svelte +65 -19
- package/dist/components/Line.svelte.d.ts +13 -1
- package/dist/components/LinearGradient.svelte +21 -15
- package/dist/components/Link.svelte +94 -22
- package/dist/components/Link.svelte.d.ts +17 -1
- package/dist/components/Marker.svelte +81 -0
- package/dist/components/Marker.svelte.d.ts +28 -0
- package/dist/components/MonthPath.svelte +23 -16
- package/dist/components/MotionPath.svelte +34 -25
- package/dist/components/Pack.svelte +21 -14
- package/dist/components/Partition.svelte +35 -20
- package/dist/components/Pattern.svelte +8 -6
- package/dist/components/Pie.svelte +76 -57
- package/dist/components/Point.svelte +11 -7
- package/dist/components/Points.svelte +178 -143
- package/dist/components/RadialGradient.svelte +25 -18
- package/dist/components/Rect.svelte +33 -19
- package/dist/components/RectClipPath.svelte +16 -11
- package/dist/components/Rule.svelte +50 -42
- package/dist/components/Sankey.svelte +55 -30
- package/dist/components/Spline.svelte +167 -96
- package/dist/components/Spline.svelte.d.ts +15 -0
- package/dist/components/Text.svelte +137 -104
- package/dist/components/Threshold.svelte +18 -7
- package/dist/components/TileImage.svelte +56 -50
- package/dist/components/TransformContext.svelte +235 -135
- package/dist/components/TransformControls.svelte +57 -29
- package/dist/components/TransformControls.svelte.d.ts +1 -1
- package/dist/components/Tree.svelte +33 -23
- package/dist/components/Treemap.svelte +69 -41
- package/dist/components/Voronoi.svelte +55 -28
- package/dist/components/charts/AreaChart.svelte +138 -87
- package/dist/components/charts/AreaChart.svelte.d.ts +4 -4
- package/dist/components/charts/BarChart.svelte +179 -114
- package/dist/components/charts/BarChart.svelte.d.ts +4 -4
- package/dist/components/charts/LineChart.svelte +97 -53
- package/dist/components/charts/LineChart.svelte.d.ts +4 -4
- package/dist/components/charts/PieChart.svelte +104 -54
- package/dist/components/charts/PieChart.svelte.d.ts +3 -3
- package/dist/components/charts/ScatterChart.svelte +83 -48
- package/dist/components/charts/ScatterChart.svelte.d.ts +4 -4
- package/dist/components/layout/Canvas.svelte +63 -43
- package/dist/components/layout/Html.svelte +28 -18
- package/dist/components/layout/Svg.svelte +47 -32
- package/dist/components/tooltip/Tooltip.svelte +137 -91
- package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContext.svelte +315 -249
- package/dist/components/tooltip/TooltipHeader.svelte +9 -3
- package/dist/components/tooltip/TooltipItem.svelte +17 -9
- package/dist/components/tooltip/TooltipList.svelte +2 -1
- package/dist/components/tooltip/TooltipSeparator.svelte +3 -2
- package/dist/docs/Blockquote.svelte +4 -3
- package/dist/docs/Code.svelte +15 -8
- package/dist/docs/CurveMenuField.svelte +17 -12
- package/dist/docs/GeoDebug.svelte +13 -9
- package/dist/docs/Header1.svelte +2 -1
- package/dist/docs/Json.svelte +6 -4
- package/dist/docs/Layout.svelte +6 -6
- package/dist/docs/PathDataMenuField.svelte +52 -44
- package/dist/docs/Preview.svelte +39 -33
- package/dist/docs/TilesetField.svelte +80 -62
- package/dist/docs/TransformDebug.svelte +8 -5
- package/dist/docs/ViewSourceButton.svelte +13 -9
- package/dist/stores/motionStore.d.ts +1 -1
- package/dist/utils/scales.d.ts +3 -3
- package/package.json +29 -30
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
$:
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { scaleLinear } from 'd3-scale';
|
|
3
|
+
import { geoDistance } from 'd3-geo';
|
|
4
|
+
|
|
5
|
+
import { geoContext } from './GeoContext.svelte';
|
|
6
|
+
|
|
7
|
+
export let link: { source: [number, number]; target: [number, number] };
|
|
8
|
+
|
|
9
|
+
const geo = geoContext();
|
|
10
|
+
|
|
11
|
+
const fade = scaleLinear().domain([-0.1, 0]).range([0, 0.1]);
|
|
12
|
+
const clamper = scaleLinear().domain([0, 1]).range([0, 1]).clamp(true);
|
|
13
|
+
|
|
14
|
+
$: center = $geo.invert?.($geo.translate()) ?? ([0, 0] as [number, number]);
|
|
15
|
+
$: source = link.source;
|
|
16
|
+
$: target = link.target;
|
|
17
|
+
$: startDistance = 1.57 - geoDistance(source, center);
|
|
18
|
+
$: endDistance = 1.57 - geoDistance(target, center);
|
|
19
|
+
$: distance = startDistance < endDistance ? startDistance : endDistance;
|
|
20
|
+
$: opacity = clamper(fade(distance));
|
|
15
21
|
</script>
|
|
16
22
|
|
|
17
23
|
<g {opacity}>
|
|
@@ -1,80 +1,118 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { createEventDispatcher, getContext } from 'svelte';
|
|
3
|
+
import type { Readable } from 'svelte/store';
|
|
4
|
+
import {
|
|
5
|
+
geoTransform as d3geoTransform,
|
|
6
|
+
type GeoIdentityTransform,
|
|
7
|
+
type GeoPermissibleObjects,
|
|
8
|
+
type GeoProjection,
|
|
9
|
+
type GeoTransformPrototype,
|
|
10
|
+
} from 'd3-geo';
|
|
11
|
+
import { cls } from '@layerstack/tailwind';
|
|
12
|
+
|
|
13
|
+
import { chartContext } from './ChartContext.svelte';
|
|
14
|
+
import { geoContext } from './GeoContext.svelte';
|
|
15
|
+
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
16
|
+
import { curveLinearClosed, type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
|
|
17
|
+
import { geoCurvePath } from '../utils/geo.js';
|
|
18
|
+
|
|
19
|
+
export let geojson: GeoPermissibleObjects | null | undefined = undefined;
|
|
20
|
+
|
|
21
|
+
/** Render to canvas */
|
|
22
|
+
export let render:
|
|
23
|
+
| ((
|
|
24
|
+
ctx: CanvasRenderingContext2D,
|
|
25
|
+
options: { geoPath: ReturnType<typeof geoCurvePath> }
|
|
26
|
+
) => any)
|
|
27
|
+
| undefined = undefined;
|
|
28
|
+
|
|
29
|
+
export let fill: string | undefined = undefined;
|
|
30
|
+
export let stroke: string | undefined = undefined;
|
|
31
|
+
export let strokeWidth: number | string | undefined = undefined;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Tooltip context to setup mouse events to show tooltip for related data
|
|
35
|
+
*/
|
|
36
|
+
export let tooltip: TooltipContextValue | undefined = undefined;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Curve of path drawn. Imported via d3-shape.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* import { curveCatmullRom } from 'd3-shape';
|
|
43
|
+
* <GeoPath curve={curveCatmullRom} />
|
|
44
|
+
*
|
|
45
|
+
* @type {CurveFactory | CurveFactoryLineOnly | undefined}
|
|
46
|
+
*/
|
|
47
|
+
export let curve: CurveFactory | CurveFactoryLineOnly = curveLinearClosed;
|
|
48
|
+
|
|
49
|
+
let className: string | undefined = undefined;
|
|
50
|
+
export { className as class };
|
|
51
|
+
|
|
52
|
+
const dispatch = createEventDispatcher<{
|
|
53
|
+
click: { geoPath: ReturnType<typeof geoCurvePath>; event: MouseEvent };
|
|
54
|
+
}>();
|
|
55
|
+
|
|
56
|
+
const { containerWidth, containerHeight, padding } = chartContext();
|
|
57
|
+
const canvas = getContext<{ ctx: Readable<CanvasRenderingContext2D> }>('canvas');
|
|
58
|
+
const geo = geoContext();
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Apply geo transform to projection. Useful to draw straight lines with `geoMercator` projection.
|
|
62
|
+
* See: https://d3js.org/d3-geo/projection#geoTransform and https://stackoverflow.com/a/56409480/191902
|
|
63
|
+
**/
|
|
64
|
+
export let geoTransform:
|
|
65
|
+
| ((projection: GeoProjection | GeoIdentityTransform) => GeoTransformPrototype)
|
|
66
|
+
| undefined = undefined;
|
|
67
|
+
|
|
68
|
+
$: _projection = geoTransform ? d3geoTransform(geoTransform($geo)) : $geo;
|
|
69
|
+
|
|
70
|
+
$: geoPath = geoCurvePath(_projection, curve);
|
|
71
|
+
|
|
72
|
+
const DEFAULT_FILL = 'rgb(0, 0, 0)';
|
|
73
|
+
|
|
74
|
+
$: renderContext = canvas ? 'canvas' : 'svg';
|
|
75
|
+
|
|
76
|
+
$: ctx = canvas?.ctx;
|
|
77
|
+
$: if (renderContext === 'canvas' && $ctx) {
|
|
78
|
+
let computedStyles: Partial<CSSStyleDeclaration> = {};
|
|
79
|
+
|
|
46
80
|
// Transfer classes defined on <GeoPath> to <canvas> to enable window.getComputedStyle() retrieval (Tailwind classes, etc)
|
|
47
81
|
if (className) {
|
|
48
|
-
|
|
49
|
-
|
|
82
|
+
$ctx.canvas.classList.add(...className.split(' '));
|
|
83
|
+
computedStyles = window.getComputedStyle($ctx.canvas);
|
|
50
84
|
}
|
|
85
|
+
|
|
51
86
|
// console.count('render');
|
|
87
|
+
|
|
52
88
|
// Clear with negative offset due to Canvas `context.translate(...)`
|
|
53
89
|
$ctx.clearRect(-$padding.left, -$padding.top, $containerWidth, $containerHeight);
|
|
90
|
+
|
|
54
91
|
if (render) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
92
|
+
geoPath = geoCurvePath(_projection, curve, $ctx);
|
|
93
|
+
render($ctx, { geoPath });
|
|
94
|
+
} else {
|
|
95
|
+
$ctx.beginPath();
|
|
96
|
+
// Set the context here since setting it in `$: geoPath` is a circular reference
|
|
97
|
+
geoPath = geoCurvePath(_projection, curve, $ctx);
|
|
98
|
+
if (geojson) {
|
|
99
|
+
geoPath(geojson);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
$ctx.fillStyle =
|
|
103
|
+
fill ??
|
|
104
|
+
(computedStyles.fill !== DEFAULT_FILL ? computedStyles.fill : undefined) ??
|
|
105
|
+
'transparent';
|
|
106
|
+
$ctx.fill();
|
|
107
|
+
|
|
108
|
+
$ctx.lineWidth = Number(strokeWidth ?? 0);
|
|
109
|
+
$ctx.strokeStyle =
|
|
110
|
+
(stroke ?? computedStyles.stroke === 'none')
|
|
111
|
+
? 'transparent'
|
|
112
|
+
: (computedStyles.stroke ?? '');
|
|
113
|
+
$ctx.stroke();
|
|
76
114
|
}
|
|
77
|
-
}
|
|
115
|
+
}
|
|
78
116
|
</script>
|
|
79
117
|
|
|
80
118
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
@@ -1,26 +1,40 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
export let
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import type { Readable } from 'svelte/store';
|
|
4
|
+
|
|
5
|
+
import { geoContext } from './GeoContext.svelte';
|
|
6
|
+
import Circle from './Circle.svelte';
|
|
7
|
+
import Group from './Group.svelte';
|
|
8
|
+
|
|
9
|
+
/** Latitude */
|
|
10
|
+
export let lat: number;
|
|
11
|
+
/** Longitude */
|
|
12
|
+
export let long: number;
|
|
13
|
+
|
|
14
|
+
/** Render to canvas */
|
|
15
|
+
export let render: (
|
|
16
|
+
ctx: CanvasRenderingContext2D,
|
|
17
|
+
coords: { x: number; y: number }
|
|
18
|
+
) => any = () => {};
|
|
19
|
+
|
|
20
|
+
const canvas = getContext<{ ctx: Readable<CanvasRenderingContext2D> }>('canvas');
|
|
21
|
+
const geo = geoContext();
|
|
22
|
+
|
|
23
|
+
$: [x, y] = $geo([long, lat]) ?? [0, 0];
|
|
24
|
+
|
|
25
|
+
$: renderContext = canvas ? 'canvas' : 'svg';
|
|
26
|
+
|
|
27
|
+
$: ctx = canvas?.ctx;
|
|
28
|
+
$: if (renderContext === 'canvas' && $ctx) {
|
|
17
29
|
// $ctx.clearRect(0, 0, $width, $height);
|
|
30
|
+
|
|
18
31
|
// Transfer classes defined on <GeoPoint> to <canvas> to enable window.getComputedStyle() retrieval (Tailwind classes, etc)
|
|
19
32
|
if ($$props.class) {
|
|
20
|
-
|
|
33
|
+
$ctx.canvas.classList.add(...$$props.class.split(' '));
|
|
21
34
|
}
|
|
35
|
+
|
|
22
36
|
render($ctx, { x, y });
|
|
23
|
-
}
|
|
37
|
+
}
|
|
24
38
|
</script>
|
|
25
39
|
|
|
26
40
|
{#if renderContext === 'svg'}
|
|
@@ -1,28 +1,36 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { curveNatural, type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
|
|
3
|
+
import { geoOrthographic, geoInterpolate } from 'd3-geo';
|
|
4
|
+
|
|
5
|
+
import { geoContext } from './GeoContext.svelte';
|
|
6
|
+
import Spline from './Spline.svelte';
|
|
7
|
+
|
|
8
|
+
export let link: { source: [number, number]; target: [number, number] };
|
|
9
|
+
|
|
10
|
+
/** Amount of loft to apply to the midle of the curve */
|
|
11
|
+
export let loft = 1.0;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Curve of spline drawn. Imported via d3-shape.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* import { curveNatural } from 'd3-shape';
|
|
18
|
+
* <GeoSpline curve={curveNatrual} />
|
|
19
|
+
*
|
|
20
|
+
* @type {CurveFactory | CurveFactoryLineOnly | undefined}
|
|
21
|
+
*/
|
|
22
|
+
export let curve: CurveFactory | CurveFactoryLineOnly | undefined = curveNatural;
|
|
23
|
+
|
|
24
|
+
const geo = geoContext();
|
|
25
|
+
|
|
26
|
+
$: loftedProjection = geoOrthographic()
|
|
20
27
|
.translate($geo.translate())
|
|
21
28
|
.rotate($geo.rotate())
|
|
22
29
|
.scale($geo.scale() * loft);
|
|
23
|
-
|
|
24
|
-
$:
|
|
25
|
-
$:
|
|
30
|
+
|
|
31
|
+
$: source = $geo(link.source);
|
|
32
|
+
$: target = $geo(link.target);
|
|
33
|
+
$: middle = loftedProjection(geoInterpolate(link.source, link.target)(0.5));
|
|
26
34
|
</script>
|
|
27
35
|
|
|
28
36
|
<Spline data={[source, middle, target]} x={(d) => d[0]} y={(d) => d[1]} {curve} {...$$restProps} />
|
|
@@ -1,41 +1,51 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import type { Readable } from 'svelte/store';
|
|
4
|
+
// @ts-expect-error
|
|
5
|
+
import { tile as d3Tile } from 'd3-tile';
|
|
6
|
+
|
|
7
|
+
import { chartContext } from './ChartContext.svelte';
|
|
8
|
+
import { geoContext } from './GeoContext.svelte';
|
|
9
|
+
import Group from './Group.svelte';
|
|
10
|
+
import TileImage from './TileImage.svelte';
|
|
11
|
+
|
|
12
|
+
export let url: (x: number, y: number, z: number) => string;
|
|
13
|
+
export let zoomDelta = 0;
|
|
14
|
+
export let tileSize = 256;
|
|
15
|
+
export let disableCache = false;
|
|
16
|
+
export let debug = false;
|
|
17
|
+
|
|
18
|
+
const { containerWidth, containerHeight, padding } = chartContext();
|
|
19
|
+
const canvas = getContext<{ ctx: Readable<CanvasRenderingContext2D> }>('canvas');
|
|
20
|
+
const geo = geoContext();
|
|
21
|
+
|
|
22
|
+
$: center = $geo([0, 0]) ?? [0, 0];
|
|
23
|
+
|
|
24
|
+
$: tile = d3Tile()
|
|
18
25
|
.size([$containerWidth, $containerHeight])
|
|
19
26
|
.translate([center[0] + $padding.left, center[1] + $padding.top])
|
|
20
27
|
.scale($geo.scale() * 2 * Math.PI)
|
|
21
28
|
.tileSize(tileSize)
|
|
22
29
|
.zoomDelta(zoomDelta);
|
|
23
|
-
|
|
24
|
-
$: (
|
|
30
|
+
|
|
31
|
+
$: tiles = tile();
|
|
32
|
+
$: ({
|
|
25
33
|
translate: [tx, ty],
|
|
26
34
|
scale,
|
|
27
|
-
} = tiles);
|
|
28
|
-
|
|
29
|
-
$:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
image
|
|
35
|
+
} = tiles);
|
|
36
|
+
|
|
37
|
+
$: renderContext = canvas ? 'canvas' : 'svg';
|
|
38
|
+
|
|
39
|
+
$: ctx = canvas?.ctx;
|
|
40
|
+
$: if (renderContext === 'canvas' && $ctx && url) {
|
|
41
|
+
tiles.forEach(([x, y, z]: number[]) => {
|
|
42
|
+
const image = new Image();
|
|
43
|
+
image.onload = () => {
|
|
44
|
+
$ctx.drawImage(image, (x + tx) * scale, (y + ty) * scale, scale, scale);
|
|
45
|
+
};
|
|
46
|
+
image.src = url(x, y, z);
|
|
37
47
|
});
|
|
38
|
-
}
|
|
48
|
+
}
|
|
39
49
|
</script>
|
|
40
50
|
|
|
41
51
|
{#if renderContext === 'svg' && url}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
export let
|
|
7
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { geoContext } from './GeoContext.svelte';
|
|
3
|
+
import { isVisible } from '../utils/geo.js';
|
|
4
|
+
|
|
5
|
+
/** Latitude */
|
|
6
|
+
export let lat: number;
|
|
7
|
+
/** Longitude */
|
|
8
|
+
export let long: number;
|
|
9
|
+
|
|
10
|
+
const geo = geoContext();
|
|
8
11
|
</script>
|
|
9
12
|
|
|
10
13
|
{#if isVisible($geo)([long, lat])}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { geoGraticule } from 'd3-geo';
|
|
3
|
+
import type { ComponentProps } from 'svelte';
|
|
4
|
+
|
|
5
|
+
import GeoPath from './GeoPath.svelte';
|
|
6
|
+
|
|
7
|
+
// TODO: Support full api (stepMinor/Major, extent[Minor/Major], etc
|
|
8
|
+
export let lines: Partial<ComponentProps<GeoPath>> | boolean | undefined = undefined;
|
|
9
|
+
export let outline: Partial<ComponentProps<GeoPath>> | boolean | undefined = undefined;
|
|
10
|
+
export let step: [number, number] = [10, 10];
|
|
11
|
+
|
|
12
|
+
$: graticule = geoGraticule();
|
|
13
|
+
|
|
14
|
+
$: graticule.step(step);
|
|
9
15
|
</script>
|
|
10
16
|
|
|
11
17
|
<g class="graticule">
|
|
@@ -1,56 +1,83 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export let
|
|
25
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
3
|
+
import { fade } from 'svelte/transition';
|
|
4
|
+
import { cubicIn } from 'svelte/easing';
|
|
5
|
+
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
6
|
+
|
|
7
|
+
import { curveLinearClosed } from 'd3-shape';
|
|
8
|
+
|
|
9
|
+
import { cls } from '@layerstack/tailwind';
|
|
10
|
+
import type { TransitionParams } from 'svelte-ux'; // TODO: Replace with `@layerstack/svelte-types` or similar
|
|
11
|
+
|
|
12
|
+
import { chartContext } from './ChartContext.svelte';
|
|
13
|
+
import { isScaleBand, type AnyScale } from '../utils/scales.js';
|
|
14
|
+
|
|
15
|
+
import Rule from './Rule.svelte';
|
|
16
|
+
import Spline from './Spline.svelte';
|
|
17
|
+
import Circle from './Circle.svelte';
|
|
18
|
+
|
|
19
|
+
type TicksConfig = number | any[] | ((scale: AnyScale) => any) | null | undefined;
|
|
20
|
+
|
|
21
|
+
const { xScale, yScale, radial } = chartContext();
|
|
22
|
+
|
|
23
|
+
/** Draw a x-axis lines */
|
|
24
|
+
export let x: boolean | Pick<SVGAttributes<SVGElement>, 'class' | 'style'> = false;
|
|
25
|
+
|
|
26
|
+
/** Draw a y-axis lines */
|
|
27
|
+
export let y: boolean | Pick<SVGAttributes<SVGElement>, 'class' | 'style'> = false;
|
|
28
|
+
|
|
29
|
+
/** Control the number of x-axis ticks */
|
|
30
|
+
export let xTicks: TicksConfig = undefined;
|
|
31
|
+
|
|
32
|
+
/** Control the number of y-axis ticks */
|
|
33
|
+
export let yTicks: TicksConfig = !isScaleBand($yScale) ? 4 : undefined;
|
|
34
|
+
|
|
35
|
+
/** Line alignment when band scale is used (x or y axis) */
|
|
36
|
+
export let bandAlign: 'center' | 'between' = 'center';
|
|
37
|
+
|
|
38
|
+
/** Render `y` lines with circles or linear splines */
|
|
39
|
+
export let radialY: 'circle' | 'linear' = 'circle';
|
|
40
|
+
|
|
41
|
+
export let spring: boolean | Parameters<typeof springStore>[1] = undefined;
|
|
42
|
+
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
43
|
+
|
|
44
|
+
export let transitionIn = tweened
|
|
26
45
|
? fade
|
|
27
46
|
: () => {
|
|
28
47
|
return {};
|
|
29
|
-
|
|
30
|
-
export let transitionInParams = { easing: cubicIn };
|
|
31
|
-
|
|
32
|
-
|
|
48
|
+
};
|
|
49
|
+
export let transitionInParams: TransitionParams = { easing: cubicIn };
|
|
50
|
+
|
|
51
|
+
export let classes: {
|
|
52
|
+
root?: string;
|
|
53
|
+
line?: string;
|
|
54
|
+
} = {};
|
|
55
|
+
|
|
56
|
+
function getTickVals(scale: AnyScale, ticks: TicksConfig): any[] {
|
|
33
57
|
return Array.isArray(ticks)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
$:
|
|
45
|
-
$:
|
|
58
|
+
? ticks
|
|
59
|
+
: typeof ticks === 'function'
|
|
60
|
+
? ticks(scale)
|
|
61
|
+
: isScaleBand(scale)
|
|
62
|
+
? ticks
|
|
63
|
+
? scale.domain().filter((v: any, i: number) => i % ticks === 0)
|
|
64
|
+
: scale.domain()
|
|
65
|
+
: scale.ticks?.(ticks);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
$: xTickVals = getTickVals($xScale, xTicks);
|
|
69
|
+
$: yTickVals = getTickVals($yScale, yTicks);
|
|
70
|
+
|
|
71
|
+
$: xBandOffset = isScaleBand($xScale)
|
|
46
72
|
? bandAlign === 'between'
|
|
47
|
-
|
|
48
|
-
|
|
73
|
+
? -($xScale.padding() * $xScale.step()) / 2 // before
|
|
74
|
+
: $xScale.step() / 2 - ($xScale.padding() * $xScale.step()) / 2 // center
|
|
49
75
|
: 0;
|
|
50
|
-
|
|
76
|
+
|
|
77
|
+
$: yBandOffset = isScaleBand($yScale)
|
|
51
78
|
? bandAlign === 'between'
|
|
52
|
-
|
|
53
|
-
|
|
79
|
+
? -($yScale.padding() * $yScale.step()) / 2 // before
|
|
80
|
+
: $yScale.step() / 2 - ($yScale.padding() * $yScale.step()) / 2 // center
|
|
54
81
|
: 0;
|
|
55
82
|
</script>
|
|
56
83
|
|
|
@@ -58,7 +85,7 @@ $: yBandOffset = isScaleBand($yScale)
|
|
|
58
85
|
{#if x}
|
|
59
86
|
{@const splineProps = typeof x === 'object' ? x : null}
|
|
60
87
|
<g in:transitionIn={transitionInParams}>
|
|
61
|
-
{#each xTickVals as x}
|
|
88
|
+
{#each xTickVals as x (x)}
|
|
62
89
|
{#if $radial}
|
|
63
90
|
<Spline
|
|
64
91
|
data={yTickVals.map((y) => ({ x, y }))}
|
|
@@ -100,7 +127,7 @@ $: yBandOffset = isScaleBand($yScale)
|
|
|
100
127
|
{#if y}
|
|
101
128
|
{@const splineProps = typeof y === 'object' ? y : null}
|
|
102
129
|
<g in:transitionIn={transitionInParams}>
|
|
103
|
-
{#each yTickVals as y}
|
|
130
|
+
{#each yTickVals as y (y)}
|
|
104
131
|
{#if $radial}
|
|
105
132
|
{#if radialY === 'circle'}
|
|
106
133
|
<Circle
|