layerchart 2.0.0-next.44 → 2.0.0-next.46
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/LICENSE +1 -1
- package/dist/components/AnnotationLine.svelte +1 -1
- package/dist/components/AnnotationPoint.svelte +1 -1
- package/dist/components/AnnotationRange.svelte +16 -15
- package/dist/components/Arc.svelte +10 -10
- package/dist/components/Arc.svelte.d.ts +4 -4
- package/dist/components/Arc.svelte.test.d.ts +1 -0
- package/dist/components/Arc.svelte.test.js +868 -0
- package/dist/components/Area.svelte +9 -7
- package/dist/components/Axis.svelte +2 -1
- package/dist/components/Axis.svelte.d.ts +1 -0
- package/dist/components/Bar.svelte +3 -3
- package/dist/components/Bars.svelte +1 -1
- package/dist/components/Blur.svelte +3 -3
- package/dist/components/Bounds.svelte +1 -1
- package/dist/components/BrushContext.svelte +1 -1
- package/dist/components/Calendar.svelte +2 -2
- package/dist/components/Calendar.svelte.d.ts +1 -1
- package/dist/components/Chart.svelte +63 -137
- package/dist/components/Chart.svelte.d.ts +23 -88
- package/dist/components/ChartClipPath.svelte +1 -1
- package/dist/components/Circle.svelte +17 -8
- package/dist/components/Circle.svelte.d.ts +3 -0
- package/dist/components/ClipPath.svelte +4 -4
- package/dist/components/Connector.svelte +4 -4
- package/dist/components/Connector.svelte.d.ts +3 -3
- package/dist/components/Ellipse.svelte +7 -7
- package/dist/components/Frame.svelte +1 -1
- package/dist/components/GeoContext.svelte +4 -20
- package/dist/components/GeoContext.svelte.d.ts +2 -6
- package/dist/components/GeoEdgeFade.svelte +1 -1
- package/dist/components/GeoPath.svelte +42 -107
- package/dist/components/GeoPath.svelte.d.ts +5 -4
- package/dist/components/GeoPoint.svelte +5 -5
- package/dist/components/GeoSpline.svelte +2 -14
- package/dist/components/GeoSpline.svelte.d.ts +1 -1
- package/dist/components/GeoTile.svelte +7 -6
- package/dist/components/GeoVisible.svelte +1 -1
- package/dist/components/Graticule.svelte +4 -7
- package/dist/components/Graticule.svelte.d.ts +2 -1
- package/dist/components/Grid.svelte +1 -1
- package/dist/components/Group.svelte +8 -8
- package/dist/components/Highlight.svelte +18 -16
- package/dist/components/Hull.svelte +2 -2
- package/dist/components/Labels.svelte +1 -1
- package/dist/components/Legend.svelte +1 -1
- package/dist/components/Line.svelte +9 -7
- package/dist/components/LinearGradient.svelte +8 -7
- package/dist/components/MonthPath.svelte +5 -11
- package/dist/components/MonthPath.svelte.d.ts +2 -2
- package/dist/components/Pack.svelte +4 -6
- package/dist/components/Pack.svelte.d.ts +2 -4
- package/dist/components/Partition.svelte +4 -3
- package/dist/components/Partition.svelte.d.ts +2 -1
- package/dist/components/Path.svelte +344 -0
- package/dist/components/Path.svelte.d.ts +72 -0
- package/dist/components/Pattern.svelte +6 -6
- package/dist/components/Pie.svelte +2 -2
- package/dist/components/Pie.svelte.d.ts +1 -1
- package/dist/components/Point.svelte +1 -1
- package/dist/components/Points.svelte +1 -1
- package/dist/components/Polygon.svelte +8 -6
- package/dist/components/RadialGradient.svelte +7 -7
- package/dist/components/Rect.svelte +32 -10
- package/dist/components/Rect.svelte.d.ts +4 -1
- package/dist/components/Rule.svelte +1 -1
- package/dist/components/Sankey.svelte +1 -1
- package/dist/components/Spline.svelte +13 -337
- package/dist/components/Spline.svelte.d.ts +10 -73
- package/dist/components/Text.svelte +9 -7
- package/dist/components/Threshold.svelte +3 -3
- package/dist/components/TransformContext.svelte +10 -143
- package/dist/components/TransformControls.svelte +2 -2
- package/dist/components/TransformControls.svelte.d.ts +1 -1
- package/dist/components/Tree.svelte +4 -3
- package/dist/components/Tree.svelte.d.ts +2 -1
- package/dist/components/Treemap.svelte +4 -3
- package/dist/components/Treemap.svelte.d.ts +2 -1
- package/dist/components/Voronoi.svelte +5 -5
- package/dist/components/charts/ArcChart.svelte +14 -6
- package/dist/components/charts/ArcChart.svelte.d.ts +1 -1
- package/dist/components/charts/AreaChart.svelte +12 -6
- package/dist/components/charts/BarChart.svelte +12 -6
- package/dist/components/charts/DefaultTooltip.svelte +1 -1
- package/dist/components/charts/LineChart.svelte +12 -6
- package/dist/components/charts/PieChart.svelte +14 -6
- package/dist/components/charts/PieChart.svelte.d.ts +1 -1
- package/dist/components/charts/ScatterChart.svelte +11 -9
- package/dist/components/charts/types.d.ts +7 -6
- package/dist/components/index.d.ts +14 -12
- package/dist/components/index.js +14 -12
- package/dist/components/{layout → layers}/Canvas.svelte +13 -60
- package/dist/components/{layout → layers}/Canvas.svelte.d.ts +2 -32
- package/dist/components/{layout → layers}/Html.svelte +18 -3
- package/dist/components/{layout → layers}/Html.svelte.d.ts +7 -0
- package/dist/components/layers/Layer.svelte +85 -0
- package/dist/components/{layout → layers}/Layer.svelte.d.ts +7 -3
- package/dist/components/{layout → layers}/Svg.svelte +18 -3
- package/dist/components/{layout → layers}/Svg.svelte.d.ts +7 -0
- package/dist/components/{layout → layers}/WebGL.svelte +1 -1
- package/dist/components/{layout → layers}/WebGL.svelte.d.ts +3 -3
- package/dist/components/tests/TestHarness.svelte +76 -0
- package/dist/components/tests/TestHarness.svelte.d.ts +19 -0
- package/dist/components/tooltip/Tooltip.svelte +3 -3
- package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContext.svelte +13 -45
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +2 -14
- package/dist/components/tooltip/tooltipMetaContext.d.ts +2 -2
- package/dist/components/tooltip/tooltipMetaContext.js +2 -2
- package/dist/contexts/canvas.d.ts +33 -0
- package/dist/contexts/canvas.js +14 -0
- package/dist/contexts/chart.d.ts +84 -0
- package/dist/contexts/chart.js +10 -0
- package/dist/contexts/geo.d.ts +6 -0
- package/dist/contexts/geo.js +12 -0
- package/dist/contexts/index.d.ts +6 -0
- package/dist/contexts/index.js +6 -0
- package/dist/contexts/layer.d.ts +3 -0
- package/dist/contexts/layer.js +8 -0
- package/dist/contexts/settings.d.ts +4 -0
- package/dist/contexts/settings.js +10 -0
- package/dist/contexts/tooltip.d.ts +15 -0
- package/dist/contexts/tooltip.js +8 -0
- package/dist/contexts/transform.d.ts +95 -0
- package/dist/contexts/transform.js +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/states/settings.svelte.d.ts +12 -0
- package/dist/states/settings.svelte.js +10 -0
- package/dist/states/transform.svelte.d.ts +9 -0
- package/dist/states/transform.svelte.js +31 -0
- package/dist/utils/arcText.svelte.d.ts +1 -1
- package/dist/utils/canvas.d.ts +7 -3
- package/dist/utils/canvas.js +78 -11
- package/dist/utils/common.d.ts +8 -1
- package/dist/utils/common.js +9 -10
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/motion.svelte.js +0 -1
- package/dist/utils/rect.svelte.d.ts +1 -1
- package/dist/utils/rect.svelte.js +17 -9
- package/dist/utils/scales.svelte.js +2 -2
- package/dist/utils/string.d.ts +3 -1
- package/package.json +32 -54
- package/README.md +0 -41
- package/dist/components/layout/Layer.svelte +0 -41
- package/dist/docs/Blockquote.svelte +0 -17
- package/dist/docs/Blockquote.svelte.d.ts +0 -5
- package/dist/docs/Code.svelte +0 -80
- package/dist/docs/Code.svelte.d.ts +0 -14
- package/dist/docs/ConnectorSweepMenuField.svelte +0 -17
- package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +0 -7
- package/dist/docs/ConnectorTypeMenuField.svelte +0 -17
- package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +0 -7
- package/dist/docs/CurveMenuField.svelte +0 -44
- package/dist/docs/CurveMenuField.svelte.d.ts +0 -9
- package/dist/docs/GeoDebug.svelte +0 -60
- package/dist/docs/GeoDebug.svelte.d.ts +0 -4
- package/dist/docs/Header1.svelte +0 -16
- package/dist/docs/Header1.svelte.d.ts +0 -5
- package/dist/docs/Json.svelte +0 -36
- package/dist/docs/Json.svelte.d.ts +0 -10
- package/dist/docs/Layout.svelte +0 -21
- package/dist/docs/Layout.svelte.d.ts +0 -8
- package/dist/docs/Link.svelte +0 -9
- package/dist/docs/Link.svelte.d.ts +0 -5
- package/dist/docs/PathDataMenuField.svelte +0 -78
- package/dist/docs/PathDataMenuField.svelte.d.ts +0 -9
- package/dist/docs/Preview.svelte +0 -104
- package/dist/docs/Preview.svelte.d.ts +0 -13
- package/dist/docs/TilesetField.svelte +0 -136
- package/dist/docs/TilesetField.svelte.d.ts +0 -6
- package/dist/docs/TransformDebug.svelte +0 -22
- package/dist/docs/TransformDebug.svelte.d.ts +0 -20
- package/dist/docs/ViewSourceButton.svelte +0 -53
- package/dist/docs/ViewSourceButton.svelte.d.ts +0 -11
- package/dist/utils/graph/dagre.d.ts +0 -34
- /package/dist/{utils → contexts}/legendPayload.d.ts +0 -0
- /package/dist/{utils → contexts}/legendPayload.js +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
2
3
|
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
3
4
|
|
|
4
5
|
export type CirclePropsWithoutHTML = {
|
|
@@ -52,6 +53,9 @@
|
|
|
52
53
|
ref?: SVGCircleElement;
|
|
53
54
|
|
|
54
55
|
motion?: MotionProp;
|
|
56
|
+
|
|
57
|
+
/** Children content to render. Note: Only works for Html layers */
|
|
58
|
+
children?: Snippet;
|
|
55
59
|
} & CommonStyleProps;
|
|
56
60
|
|
|
57
61
|
export type CircleProps = CirclePropsWithoutHTML &
|
|
@@ -60,11 +64,11 @@
|
|
|
60
64
|
|
|
61
65
|
<script lang="ts">
|
|
62
66
|
import { cls } from '@layerstack/tailwind';
|
|
63
|
-
import { merge } from '
|
|
67
|
+
import { merge } from '@layerstack/utils';
|
|
64
68
|
|
|
65
|
-
import {
|
|
69
|
+
import { getLayerContext } from '../contexts/layer.js';
|
|
66
70
|
import { createMotion, type MotionProp } from '../utils/motion.svelte.js';
|
|
67
|
-
import { registerCanvasComponent } from './
|
|
71
|
+
import { registerCanvasComponent } from './layers/Canvas.svelte';
|
|
68
72
|
import { renderCircle, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
69
73
|
import type { SVGAttributes } from 'svelte/elements';
|
|
70
74
|
import { createKey } from '../utils/key.svelte.js';
|
|
@@ -84,6 +88,7 @@
|
|
|
84
88
|
opacity,
|
|
85
89
|
class: className,
|
|
86
90
|
ref: refProp = $bindable(),
|
|
91
|
+
children,
|
|
87
92
|
...restProps
|
|
88
93
|
}: CircleProps = $props();
|
|
89
94
|
|
|
@@ -97,7 +102,7 @@
|
|
|
97
102
|
const initialCy = initialCyProp ?? cy;
|
|
98
103
|
const initialR = initialRProp ?? r;
|
|
99
104
|
|
|
100
|
-
const
|
|
105
|
+
const layerCtx = getLayerContext();
|
|
101
106
|
|
|
102
107
|
const motionCx = createMotion(initialCx, () => cx, motion);
|
|
103
108
|
const motionCy = createMotion(initialCy, () => cy, motion);
|
|
@@ -115,6 +120,7 @@
|
|
|
115
120
|
: {
|
|
116
121
|
styles: { fill, fillOpacity, stroke, strokeWidth, opacity },
|
|
117
122
|
classes: cls('lc-circle', className),
|
|
123
|
+
style: restProps.style as string | undefined,
|
|
118
124
|
}
|
|
119
125
|
);
|
|
120
126
|
}
|
|
@@ -123,7 +129,7 @@
|
|
|
123
129
|
const fillKey = createKey(() => fill);
|
|
124
130
|
const strokeKey = createKey(() => stroke);
|
|
125
131
|
|
|
126
|
-
if (
|
|
132
|
+
if (layerCtx === 'canvas') {
|
|
127
133
|
registerCanvasComponent({
|
|
128
134
|
name: 'Circle',
|
|
129
135
|
render,
|
|
@@ -144,12 +150,13 @@
|
|
|
144
150
|
strokeWidth,
|
|
145
151
|
opacity,
|
|
146
152
|
className,
|
|
153
|
+
restProps.style,
|
|
147
154
|
],
|
|
148
155
|
});
|
|
149
156
|
}
|
|
150
157
|
</script>
|
|
151
158
|
|
|
152
|
-
{#if
|
|
159
|
+
{#if layerCtx === 'svg'}
|
|
153
160
|
<circle
|
|
154
161
|
bind:this={ref}
|
|
155
162
|
cx={motionCx.current}
|
|
@@ -163,7 +170,7 @@
|
|
|
163
170
|
class={cls('lc-circle', className)}
|
|
164
171
|
{...restProps}
|
|
165
172
|
/>
|
|
166
|
-
{:else if
|
|
173
|
+
{:else if layerCtx === 'html'}
|
|
167
174
|
<div
|
|
168
175
|
style:position="absolute"
|
|
169
176
|
style:left="{motionCx.current}px"
|
|
@@ -179,7 +186,9 @@
|
|
|
179
186
|
style:transform="translate(-50%, -50%)"
|
|
180
187
|
class={cls('lc-circle', className)}
|
|
181
188
|
{...restProps}
|
|
182
|
-
|
|
189
|
+
>
|
|
190
|
+
{@render children?.()}
|
|
191
|
+
</div>
|
|
183
192
|
{/if}
|
|
184
193
|
|
|
185
194
|
<style>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
1
2
|
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
2
3
|
export type CirclePropsWithoutHTML = {
|
|
3
4
|
/**
|
|
@@ -43,6 +44,8 @@ export type CirclePropsWithoutHTML = {
|
|
|
43
44
|
*/
|
|
44
45
|
ref?: SVGCircleElement;
|
|
45
46
|
motion?: MotionProp;
|
|
47
|
+
/** Children content to render. Note: Only works for Html layers */
|
|
48
|
+
children?: Snippet;
|
|
46
49
|
} & CommonStyleProps;
|
|
47
50
|
export type CircleProps = CirclePropsWithoutHTML & Without<SVGAttributes<Element>, CirclePropsWithoutHTML>;
|
|
48
51
|
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import type { Without } from '../utils/types.js';
|
|
4
4
|
import type { Snippet } from 'svelte';
|
|
5
5
|
import type { SVGAttributes } from 'svelte/elements';
|
|
6
|
-
import {
|
|
6
|
+
import { getLayerContext } from '../contexts/layer.js';
|
|
7
7
|
|
|
8
8
|
export type ClipPathPropsWithoutHTML = {
|
|
9
9
|
/**
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
|
|
57
57
|
const url = $derived(`url(#${id})`);
|
|
58
58
|
|
|
59
|
-
const
|
|
59
|
+
const layerCtx = getLayerContext();
|
|
60
60
|
</script>
|
|
61
61
|
|
|
62
|
-
{#if
|
|
62
|
+
{#if layerCtx === 'svg'}
|
|
63
63
|
<defs>
|
|
64
64
|
<clipPath {id} {...restProps}>
|
|
65
65
|
{@render clip?.({ id })}
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
{/if}
|
|
73
73
|
|
|
74
74
|
{#if children}
|
|
75
|
-
{#if disabled ||
|
|
75
|
+
{#if disabled || layerCtx !== 'svg'}
|
|
76
76
|
{@render children({ id, url, useId })}
|
|
77
77
|
{:else}
|
|
78
78
|
<g style:clip-path={url} class="lc-clip-path-g">
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
* @default `d3.curveLinear`
|
|
47
47
|
*/
|
|
48
48
|
curve?: CurveFactory;
|
|
49
|
-
} &
|
|
49
|
+
} & PathPropsWithoutHTML;
|
|
50
50
|
|
|
51
51
|
export type ConnectorProps = ConnectorPropsWithoutHTML &
|
|
52
|
-
Without<
|
|
52
|
+
Without<PathProps, ConnectorPropsWithoutHTML>;
|
|
53
53
|
</script>
|
|
54
54
|
|
|
55
55
|
<script lang="ts">
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
type ConnectorSweep,
|
|
62
62
|
type ConnectorType,
|
|
63
63
|
} from '../utils/connectorUtils.js';
|
|
64
|
-
import
|
|
64
|
+
import Path, { type PathProps, type PathPropsWithoutHTML } from './Path.svelte';
|
|
65
65
|
import type { Without } from '../utils/types.js';
|
|
66
66
|
import { createId } from '../utils/createId.js';
|
|
67
67
|
import { extractLayerProps } from '../utils/attributes.js';
|
|
@@ -135,7 +135,7 @@
|
|
|
135
135
|
);
|
|
136
136
|
</script>
|
|
137
137
|
|
|
138
|
-
<
|
|
138
|
+
<Path
|
|
139
139
|
pathData={motionPath.current}
|
|
140
140
|
bind:pathRef
|
|
141
141
|
marker-start={markerStartId ? `url(#${markerStartId})` : undefined}
|
|
@@ -40,11 +40,11 @@ export type ConnectorPropsWithoutHTML = {
|
|
|
40
40
|
* @default `d3.curveLinear`
|
|
41
41
|
*/
|
|
42
42
|
curve?: CurveFactory;
|
|
43
|
-
} &
|
|
44
|
-
export type ConnectorProps = ConnectorPropsWithoutHTML & Without<
|
|
43
|
+
} & PathPropsWithoutHTML;
|
|
44
|
+
export type ConnectorProps = ConnectorPropsWithoutHTML & Without<PathProps, ConnectorPropsWithoutHTML>;
|
|
45
45
|
import { type CurveFactory } from 'd3-shape';
|
|
46
46
|
import { type ConnectorCoords, type ConnectorSweep, type ConnectorType } from '../utils/connectorUtils.js';
|
|
47
|
-
import { type
|
|
47
|
+
import { type PathProps, type PathPropsWithoutHTML } from './Path.svelte';
|
|
48
48
|
import type { Without } from '../utils/types.js';
|
|
49
49
|
declare const Connector: import("svelte").Component<ConnectorProps, {}, "pathRef">;
|
|
50
50
|
type Connector = ReturnType<typeof Connector>;
|
|
@@ -74,11 +74,11 @@
|
|
|
74
74
|
|
|
75
75
|
<script lang="ts">
|
|
76
76
|
import { cls } from '@layerstack/tailwind';
|
|
77
|
-
import { merge } from '
|
|
77
|
+
import { merge } from '@layerstack/utils';
|
|
78
78
|
|
|
79
|
-
import {
|
|
79
|
+
import { getLayerContext } from '../contexts/layer.js';
|
|
80
80
|
import { createMotion, type MotionProp } from '../utils/motion.svelte.js';
|
|
81
|
-
import { registerCanvasComponent } from './
|
|
81
|
+
import { registerCanvasComponent } from './layers/Canvas.svelte';
|
|
82
82
|
import { renderEllipse, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
83
83
|
import type { SVGAttributes } from 'svelte/elements';
|
|
84
84
|
import { createKey } from '../utils/key.svelte.js';
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
const initialRx = initialRxProp ?? rx;
|
|
115
115
|
const initialRy = initialRyProp ?? ry;
|
|
116
116
|
|
|
117
|
-
const
|
|
117
|
+
const layerCtx = getLayerContext();
|
|
118
118
|
|
|
119
119
|
const motionCx = createMotion(initialCx, () => cx, motion);
|
|
120
120
|
const motionCy = createMotion(initialCy, () => cy, motion);
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
const fillKey = createKey(() => fill);
|
|
142
142
|
const strokeKey = createKey(() => stroke);
|
|
143
143
|
|
|
144
|
-
if (
|
|
144
|
+
if (layerCtx === 'canvas') {
|
|
145
145
|
registerCanvasComponent({
|
|
146
146
|
name: 'Ellipse',
|
|
147
147
|
render,
|
|
@@ -168,7 +168,7 @@
|
|
|
168
168
|
}
|
|
169
169
|
</script>
|
|
170
170
|
|
|
171
|
-
{#if
|
|
171
|
+
{#if layerCtx === 'svg'}
|
|
172
172
|
<ellipse
|
|
173
173
|
bind:this={ref}
|
|
174
174
|
cx={motionCx.current}
|
|
@@ -183,7 +183,7 @@
|
|
|
183
183
|
class={cls('lc-ellipse', className)}
|
|
184
184
|
{...restProps}
|
|
185
185
|
/>
|
|
186
|
-
{:else if
|
|
186
|
+
{:else if layerCtx === 'html'}
|
|
187
187
|
<div
|
|
188
188
|
style:position="absolute"
|
|
189
189
|
style:left="{motionCx.current}px"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
</script>
|
|
19
19
|
|
|
20
20
|
<script lang="ts">
|
|
21
|
-
import { getChartContext } from '
|
|
21
|
+
import { getChartContext } from '../contexts/chart.js';
|
|
22
22
|
import { extractLayerProps } from '../utils/attributes.js';
|
|
23
23
|
|
|
24
24
|
let { ref: refProp = $bindable(), full = false, ...restProps }: FrameProps = $props();
|
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
import { type GeoPermissibleObjects, type GeoProjection } from 'd3-geo';
|
|
3
|
-
import { getTransformContext } from './TransformContext.svelte';
|
|
4
|
-
import { Context } from 'runed';
|
|
5
|
-
import { getChartContext } from './Chart.svelte';
|
|
6
2
|
import type { Snippet } from 'svelte';
|
|
3
|
+
import { type GeoPermissibleObjects, type GeoProjection } from 'd3-geo';
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Access or set the current GeoContext.
|
|
14
|
-
*/
|
|
15
|
-
const _GeoContext = new Context<GeoContextValue>('GeoContext');
|
|
16
|
-
|
|
17
|
-
export function getGeoContext() {
|
|
18
|
-
return _GeoContext.getOr({ projection: undefined } as GeoContextValue);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function setGeoContext(geo: GeoContextValue) {
|
|
22
|
-
return _GeoContext.set(geo);
|
|
23
|
-
}
|
|
5
|
+
import { setGeoContext, type GeoContextValue } from '../contexts/geo.js';
|
|
6
|
+
import { getTransformContext } from '../contexts/transform.js';
|
|
7
|
+
import { getChartContext } from '../contexts/chart.js';
|
|
24
8
|
|
|
25
9
|
export type GeoContextProps = {
|
|
26
10
|
/**
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { type GeoPermissibleObjects, type GeoProjection } from 'd3-geo';
|
|
2
1
|
import type { Snippet } from 'svelte';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
export declare function getGeoContext(): GeoContextValue;
|
|
7
|
-
export declare function setGeoContext(geo: GeoContextValue): GeoContextValue;
|
|
2
|
+
import { type GeoPermissibleObjects, type GeoProjection } from 'd3-geo';
|
|
3
|
+
import { type GeoContextValue } from '../contexts/geo.js';
|
|
8
4
|
export type GeoContextProps = {
|
|
9
5
|
/**
|
|
10
6
|
* A d3 projection function. Pass this in as an uncalled function, e.g.
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
import { scaleLinear } from 'd3-scale';
|
|
23
23
|
import { geoDistance } from 'd3-geo';
|
|
24
24
|
|
|
25
|
-
import { getGeoContext } from '
|
|
25
|
+
import { getGeoContext } from '../contexts/geo.js';
|
|
26
26
|
import Group, { type GroupProps } from './Group.svelte';
|
|
27
27
|
import { extractLayerProps } from '../utils/attributes.js';
|
|
28
28
|
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
3
2
|
import type { Snippet } from 'svelte';
|
|
4
|
-
import type {
|
|
5
|
-
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
6
|
-
import { curveLinearClosed, type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
|
|
3
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
7
4
|
import {
|
|
8
5
|
geoPath as d3GeoPath,
|
|
9
6
|
geoTransform as d3geoTransform,
|
|
@@ -12,7 +9,11 @@
|
|
|
12
9
|
type GeoProjection,
|
|
13
10
|
type GeoTransformPrototype,
|
|
14
11
|
} from 'd3-geo';
|
|
15
|
-
import {
|
|
12
|
+
import { curveLinearClosed, type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
|
|
13
|
+
|
|
14
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
15
|
+
import type { TooltipContextValue } from '../contexts/tooltip.js';
|
|
16
|
+
import type { PathProps } from './Path.svelte';
|
|
16
17
|
|
|
17
18
|
export type GeoPathPropsWithoutHTML = {
|
|
18
19
|
/**
|
|
@@ -59,42 +60,45 @@
|
|
|
59
60
|
ref?: SVGPathElement;
|
|
60
61
|
|
|
61
62
|
children?: Snippet<[{ geoPath: ReturnType<typeof geoCurvePath> | undefined }]>;
|
|
62
|
-
} & CommonStyleProps
|
|
63
|
+
} & CommonStyleProps &
|
|
64
|
+
Pick<
|
|
65
|
+
PathProps,
|
|
66
|
+
| 'motion'
|
|
67
|
+
| 'draw'
|
|
68
|
+
| 'marker'
|
|
69
|
+
| 'markerStart'
|
|
70
|
+
| 'markerMid'
|
|
71
|
+
| 'markerEnd'
|
|
72
|
+
| 'startContent'
|
|
73
|
+
| 'endContent'
|
|
74
|
+
>;
|
|
63
75
|
|
|
64
76
|
export type GeoPathProps = GeoPathPropsWithoutHTML &
|
|
65
77
|
Without<SVGAttributes<SVGPathElement>, GeoPathPropsWithoutHTML>;
|
|
66
78
|
</script>
|
|
67
79
|
|
|
68
80
|
<script lang="ts">
|
|
69
|
-
import {
|
|
81
|
+
import { cls } from '@layerstack/tailwind';
|
|
70
82
|
|
|
71
|
-
import { getRenderContext } from './Chart.svelte';
|
|
72
|
-
import { registerCanvasComponent } from './layout/Canvas.svelte';
|
|
73
83
|
import { geoCurvePath } from '../utils/geo.js';
|
|
74
|
-
import { getGeoContext } from '
|
|
75
|
-
import
|
|
84
|
+
import { getGeoContext } from '../contexts/geo.js';
|
|
85
|
+
import Path from './Path.svelte';
|
|
76
86
|
|
|
77
87
|
let {
|
|
78
|
-
fill,
|
|
79
|
-
stroke,
|
|
80
|
-
strokeWidth,
|
|
81
|
-
opacity,
|
|
82
88
|
geoTransform,
|
|
83
89
|
geojson,
|
|
84
90
|
tooltipContext,
|
|
85
91
|
curve = curveLinearClosed,
|
|
86
92
|
onclick,
|
|
93
|
+
onpointerenter,
|
|
94
|
+
onpointermove,
|
|
95
|
+
onpointerleave,
|
|
87
96
|
class: className,
|
|
88
97
|
ref: refProp = $bindable(),
|
|
89
98
|
children,
|
|
90
99
|
...restProps
|
|
91
100
|
}: GeoPathProps = $props();
|
|
92
101
|
|
|
93
|
-
let ref = $state<SVGPathElement>();
|
|
94
|
-
$effect.pre(() => {
|
|
95
|
-
refProp = ref;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
102
|
const geo = getGeoContext();
|
|
99
103
|
|
|
100
104
|
const projection = $derived(
|
|
@@ -111,109 +115,40 @@
|
|
|
111
115
|
return geoCurvePath(projection, curve);
|
|
112
116
|
});
|
|
113
117
|
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
function render(
|
|
117
|
-
ctx: CanvasRenderingContext2D,
|
|
118
|
-
styleOverrides: ComputedStylesOptions | undefined
|
|
119
|
-
) {
|
|
120
|
-
if (!geojson) return;
|
|
121
|
-
const pathData = geoPath?.(geojson);
|
|
122
|
-
renderPathData(
|
|
123
|
-
ctx,
|
|
124
|
-
pathData,
|
|
125
|
-
styleOverrides
|
|
126
|
-
? merge({ styles: { strokeWidth } }, styleOverrides)
|
|
127
|
-
: {
|
|
128
|
-
styles: { fill, stroke, strokeWidth, opacity },
|
|
129
|
-
classes: className,
|
|
130
|
-
}
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// TODO: Use objectId to work around Svelte 4 reactivity issue (even when memoizing gradients)
|
|
135
|
-
const fillKey = createKey(() => fill);
|
|
136
|
-
const strokeKey = createKey(() => stroke);
|
|
118
|
+
const pathData = $derived(geojson ? geoPath?.(geojson) : '');
|
|
137
119
|
|
|
138
|
-
// Hide `geoPath`
|
|
120
|
+
// Hide `geoPath` reactivity from onclick handler
|
|
139
121
|
function _onClick(e: MouseEvent) {
|
|
140
122
|
onclick?.(e, geoPath);
|
|
141
123
|
}
|
|
142
124
|
|
|
143
|
-
|
|
144
|
-
|
|
125
|
+
function _onPointerEnter(e: PointerEvent & { currentTarget: EventTarget & SVGPathElement }) {
|
|
126
|
+
onpointerenter?.(e);
|
|
145
127
|
tooltipContext?.show(e, geojson);
|
|
146
|
-
}
|
|
128
|
+
}
|
|
147
129
|
|
|
148
|
-
|
|
149
|
-
|
|
130
|
+
function _onPointerMove(e: PointerEvent & { currentTarget: EventTarget & SVGPathElement }) {
|
|
131
|
+
onpointermove?.(e);
|
|
150
132
|
tooltipContext?.show(e, geojson);
|
|
151
|
-
}
|
|
133
|
+
}
|
|
152
134
|
|
|
153
|
-
|
|
154
|
-
|
|
135
|
+
function _onPointerLeave(e: PointerEvent & { currentTarget: EventTarget & SVGPathElement }) {
|
|
136
|
+
onpointerleave?.(e);
|
|
155
137
|
tooltipContext?.hide();
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
if (renderCtx === 'canvas') {
|
|
159
|
-
registerCanvasComponent({
|
|
160
|
-
name: 'GeoPath',
|
|
161
|
-
render,
|
|
162
|
-
events: {
|
|
163
|
-
// Only register events if they are defined (so they are not registered with hit canvas unnecessarily)
|
|
164
|
-
click: onclick ? _onClick : undefined,
|
|
165
|
-
pointerenter: restProps.onpointerenter || tooltipContext ? _onPointerEnter : undefined,
|
|
166
|
-
pointermove: restProps.onpointermove || tooltipContext ? _onPointerMove : undefined,
|
|
167
|
-
pointerleave: restProps.onpointerleave || tooltipContext ? _onPointerLeave : undefined,
|
|
168
|
-
pointerdown: restProps.onpointerdown,
|
|
169
|
-
touchmove: restProps.ontouchmove,
|
|
170
|
-
},
|
|
171
|
-
deps: () => [
|
|
172
|
-
projection,
|
|
173
|
-
geojson,
|
|
174
|
-
curve,
|
|
175
|
-
fillKey.current,
|
|
176
|
-
strokeKey.current,
|
|
177
|
-
strokeWidth,
|
|
178
|
-
opacity,
|
|
179
|
-
className,
|
|
180
|
-
],
|
|
181
|
-
});
|
|
182
138
|
}
|
|
183
139
|
</script>
|
|
184
140
|
|
|
185
141
|
{#if children}
|
|
186
142
|
{@render children({ geoPath })}
|
|
187
|
-
{:else
|
|
188
|
-
<
|
|
189
|
-
|
|
143
|
+
{:else}
|
|
144
|
+
<Path
|
|
145
|
+
{pathData}
|
|
190
146
|
{...restProps}
|
|
191
|
-
d={geojson ? geoPath?.(geojson) : ''}
|
|
192
|
-
{fill}
|
|
193
|
-
{stroke}
|
|
194
|
-
stroke-width={strokeWidth}
|
|
195
|
-
{opacity}
|
|
196
147
|
onclick={_onClick}
|
|
197
|
-
onpointerenter={_onPointerEnter}
|
|
198
|
-
onpointermove={_onPointerMove}
|
|
199
|
-
onpointerleave={_onPointerLeave}
|
|
200
|
-
class={
|
|
148
|
+
onpointerenter={tooltipContext || onpointerenter ? _onPointerEnter : undefined}
|
|
149
|
+
onpointermove={tooltipContext || onpointermove ? _onPointerMove : undefined}
|
|
150
|
+
onpointerleave={tooltipContext || onpointerleave ? _onPointerLeave : undefined}
|
|
151
|
+
class={cls('lc-geo-path', className)}
|
|
152
|
+
pathRef={refProp}
|
|
201
153
|
/>
|
|
202
154
|
{/if}
|
|
203
|
-
|
|
204
|
-
<style>
|
|
205
|
-
@layer base {
|
|
206
|
-
:global(:where(.lc-geo-path)) {
|
|
207
|
-
--fill-color: transparent;
|
|
208
|
-
--stroke-color: initial;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/* Svg | Canvas layers */
|
|
212
|
-
:global(:where(.lc-layout-svg .lc-geo-path, svg.lc-geo-path):not([fill])) {
|
|
213
|
-
fill: var(--fill-color);
|
|
214
|
-
}
|
|
215
|
-
:global(:where(.lc-layout-svg .lc-geo-path, svg.lc-geo-path):not([stroke])) {
|
|
216
|
-
stroke: var(--stroke-color);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
</style>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
2
1
|
import type { Snippet } from 'svelte';
|
|
3
2
|
import type { SVGAttributes } from 'svelte/elements';
|
|
4
|
-
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
5
|
-
import { type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
|
|
6
3
|
import { type GeoIdentityTransform, type GeoPermissibleObjects, type GeoProjection, type GeoTransformPrototype } from 'd3-geo';
|
|
4
|
+
import { type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
|
|
5
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
6
|
+
import type { TooltipContextValue } from '../contexts/tooltip.js';
|
|
7
|
+
import type { PathProps } from './Path.svelte';
|
|
7
8
|
export type GeoPathPropsWithoutHTML = {
|
|
8
9
|
/**
|
|
9
10
|
* GeoJSON data to render
|
|
@@ -43,7 +44,7 @@ export type GeoPathPropsWithoutHTML = {
|
|
|
43
44
|
children?: Snippet<[{
|
|
44
45
|
geoPath: ReturnType<typeof geoCurvePath> | undefined;
|
|
45
46
|
}]>;
|
|
46
|
-
} & CommonStyleProps
|
|
47
|
+
} & CommonStyleProps & Pick<PathProps, 'motion' | 'draw' | 'marker' | 'markerStart' | 'markerMid' | 'markerEnd' | 'startContent' | 'endContent'>;
|
|
47
48
|
export type GeoPathProps = GeoPathPropsWithoutHTML & Without<SVGAttributes<SVGPathElement>, GeoPathPropsWithoutHTML>;
|
|
48
49
|
import { geoCurvePath } from '../utils/geo.js';
|
|
49
50
|
declare const GeoPath: import("svelte").Component<GeoPathProps, {}, "ref">;
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
|
|
32
32
|
<script lang="ts">
|
|
33
33
|
import Group from './Group.svelte';
|
|
34
|
-
import {
|
|
35
|
-
import { getGeoContext } from '
|
|
34
|
+
import { getLayerContext } from '../contexts/layer.js';
|
|
35
|
+
import { getGeoContext } from '../contexts/geo.js';
|
|
36
36
|
import { extractLayerProps } from '../utils/attributes.js';
|
|
37
37
|
|
|
38
38
|
let { lat, long, ref: refProp = $bindable(), children, ...restProps }: GeoPointProps = $props();
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
const x = $derived(points[0]);
|
|
49
49
|
const y = $derived(points[1]);
|
|
50
50
|
|
|
51
|
-
const
|
|
51
|
+
const layerCtx = getLayerContext();
|
|
52
52
|
</script>
|
|
53
53
|
|
|
54
|
-
{#if
|
|
54
|
+
{#if layerCtx === 'svg'}
|
|
55
55
|
{#if children}
|
|
56
56
|
<Group {x} {y} {...extractLayerProps(restProps, 'lc-geo-point-group')}>
|
|
57
57
|
{@render children({ x, y })}
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
{/if}
|
|
62
62
|
{/if}
|
|
63
63
|
|
|
64
|
-
{#if
|
|
64
|
+
{#if layerCtx === 'canvas'}
|
|
65
65
|
{#if children}
|
|
66
66
|
<!-- TODO: Handle Canvas translation. Consolidate with svg use case above -->
|
|
67
67
|
<!-- <Group {x} {y} {...$$restProps}> -->
|
|
@@ -35,21 +35,10 @@
|
|
|
35
35
|
<script lang="ts">
|
|
36
36
|
import { geoOrthographic, geoInterpolate } from 'd3-geo';
|
|
37
37
|
|
|
38
|
-
import { getGeoContext } from '
|
|
38
|
+
import { getGeoContext } from '../contexts/geo.js';
|
|
39
39
|
import { extractLayerProps } from '../utils/attributes.js';
|
|
40
40
|
|
|
41
|
-
let {
|
|
42
|
-
link,
|
|
43
|
-
loft = 1.0,
|
|
44
|
-
curve = curveNatural,
|
|
45
|
-
pathRef: pathRefProp = $bindable(),
|
|
46
|
-
...restProps
|
|
47
|
-
}: GeoSplineProps = $props();
|
|
48
|
-
|
|
49
|
-
let pathRef = $state<SVGPathElement>();
|
|
50
|
-
$effect.pre(() => {
|
|
51
|
-
pathRefProp = pathRef;
|
|
52
|
-
});
|
|
41
|
+
let { link, loft = 1.0, curve = curveNatural, ...restProps }: GeoSplineProps = $props();
|
|
53
42
|
|
|
54
43
|
const geoCtx = getGeoContext();
|
|
55
44
|
|
|
@@ -76,7 +65,6 @@
|
|
|
76
65
|
</script>
|
|
77
66
|
|
|
78
67
|
<Spline
|
|
79
|
-
bind:pathRef
|
|
80
68
|
data={[source, middle, target]}
|
|
81
69
|
x={(d) => d[0]}
|
|
82
70
|
y={(d) => d[1]}
|
|
@@ -27,6 +27,6 @@ export type GeoSplinePropsWithoutHTML = {
|
|
|
27
27
|
curve?: CurveFactory | CurveFactoryLineOnly;
|
|
28
28
|
};
|
|
29
29
|
export type GeoSplineProps = GeoSplinePropsWithoutHTML & Without<SplineProps, GeoSplinePropsWithoutHTML>;
|
|
30
|
-
declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "
|
|
30
|
+
declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "">;
|
|
31
31
|
type GeoSpline = ReturnType<typeof GeoSpline>;
|
|
32
32
|
export default GeoSpline;
|
|
@@ -44,11 +44,12 @@
|
|
|
44
44
|
// @ts-expect-error
|
|
45
45
|
import { tile as d3Tile } from 'd3-tile';
|
|
46
46
|
|
|
47
|
-
import {
|
|
48
|
-
import {
|
|
47
|
+
import { getChartContext } from '../contexts/chart.js';
|
|
48
|
+
import { getLayerContext } from '../contexts/layer.js';
|
|
49
|
+
import { registerCanvasComponent } from './layers/Canvas.svelte';
|
|
49
50
|
import Group from './Group.svelte';
|
|
50
51
|
import TileImage from './TileImage.svelte';
|
|
51
|
-
import { getGeoContext } from '
|
|
52
|
+
import { getGeoContext } from '../contexts/geo.js';
|
|
52
53
|
import { extractLayerProps } from '../utils/attributes.js';
|
|
53
54
|
|
|
54
55
|
let {
|
|
@@ -63,7 +64,7 @@
|
|
|
63
64
|
|
|
64
65
|
const ctx = getChartContext();
|
|
65
66
|
const geoCtx = getGeoContext();
|
|
66
|
-
const
|
|
67
|
+
const layerCtx = getLayerContext();
|
|
67
68
|
|
|
68
69
|
const center = $derived(geoCtx.projection?.([0, 0]) ?? [0, 0]);
|
|
69
70
|
|
|
@@ -90,7 +91,7 @@
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
if (
|
|
94
|
+
if (layerCtx === 'canvas') {
|
|
94
95
|
registerCanvasComponent({
|
|
95
96
|
name: 'GeoTile',
|
|
96
97
|
render,
|
|
@@ -99,7 +100,7 @@
|
|
|
99
100
|
}
|
|
100
101
|
</script>
|
|
101
102
|
|
|
102
|
-
{#if
|
|
103
|
+
{#if layerCtx === 'svg' && url}
|
|
103
104
|
{#if children}
|
|
104
105
|
{@render children({ tiles })}
|
|
105
106
|
{:else}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
<script lang="ts">
|
|
14
14
|
import { isVisible } from '../utils/geo.js';
|
|
15
|
-
import { getGeoContext } from '
|
|
15
|
+
import { getGeoContext } from '../contexts/geo.js';
|
|
16
16
|
|
|
17
17
|
let { lat, long, children }: GeoVisibleProps = $props();
|
|
18
18
|
const geoCtx = getGeoContext();
|