layerchart 2.0.0-next.1 → 2.0.0-next.3
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/actions/movable.d.ts +28 -0
- package/dist/actions/movable.js +91 -0
- package/dist/components/AnnotationLine.svelte +143 -0
- package/dist/components/AnnotationLine.svelte.d.ts +30 -0
- package/dist/components/AnnotationPoint.svelte +119 -0
- package/dist/components/AnnotationPoint.svelte.d.ts +34 -0
- package/dist/components/AnnotationRange.svelte +147 -0
- package/dist/components/AnnotationRange.svelte.d.ts +40 -0
- package/dist/components/Arc.svelte +344 -151
- package/dist/components/Arc.svelte.d.ts +138 -0
- package/dist/components/Area.svelte +165 -149
- package/dist/components/Area.svelte.d.ts +45 -0
- package/dist/components/Axis.svelte +283 -180
- package/dist/components/Axis.svelte.d.ts +117 -0
- package/dist/components/Bar.svelte +166 -107
- package/dist/components/Bar.svelte.d.ts +51 -0
- package/dist/components/Bars.svelte +56 -67
- package/dist/components/Bars.svelte.d.ts +27 -0
- package/dist/components/Blur.svelte +42 -12
- package/dist/components/Blur.svelte.d.ts +23 -21
- package/dist/components/Bounds.svelte +49 -19
- package/dist/components/Bounds.svelte.d.ts +24 -50
- package/dist/components/BrushContext.svelte +296 -168
- package/dist/components/BrushContext.svelte.d.ts +97 -65
- package/dist/components/Calendar.svelte +116 -59
- package/dist/components/Calendar.svelte.d.ts +50 -31
- package/dist/components/Chart.svelte +1289 -398
- package/dist/components/Chart.svelte.d.ts +535 -410
- package/dist/components/ChartClipPath.svelte +37 -15
- package/dist/components/ChartClipPath.svelte.d.ts +21 -19
- package/dist/components/Circle.svelte +124 -85
- package/dist/components/Circle.svelte.d.ts +52 -0
- package/dist/components/CircleClipPath.svelte +76 -16
- package/dist/components/CircleClipPath.svelte.d.ts +46 -0
- package/dist/components/ClipPath.svelte +71 -21
- package/dist/components/ClipPath.svelte.d.ts +40 -27
- package/dist/components/ColorRamp.svelte +75 -9
- package/dist/components/ColorRamp.svelte.d.ts +37 -19
- package/dist/components/ComputedStyles.svelte +17 -5
- package/dist/components/ComputedStyles.svelte.d.ts +11 -19
- package/dist/components/Connector.svelte +149 -0
- package/dist/components/Connector.svelte.d.ts +51 -0
- package/dist/components/Dagre.svelte +211 -122
- package/dist/components/Dagre.svelte.d.ts +119 -56
- package/dist/components/ForceSimulation.svelte +215 -90
- package/dist/components/ForceSimulation.svelte.d.ts +82 -35
- package/dist/components/Frame.svelte +33 -13
- package/dist/components/Frame.svelte.d.ts +13 -17
- package/dist/components/GeoCircle.svelte +29 -16
- package/dist/components/GeoCircle.svelte.d.ts +22 -24
- package/dist/components/GeoContext.svelte +113 -72
- package/dist/components/GeoContext.svelte.d.ts +49 -41
- package/dist/components/GeoEdgeFade.svelte +49 -13
- package/dist/components/GeoEdgeFade.svelte.d.ts +17 -19
- package/dist/components/GeoPath.svelte +157 -127
- package/dist/components/GeoPath.svelte.d.ts +48 -36
- package/dist/components/GeoPoint.svelte +52 -20
- package/dist/components/GeoPoint.svelte.d.ts +25 -22
- package/dist/components/GeoSpline.svelte +75 -26
- package/dist/components/GeoSpline.svelte.d.ts +29 -20
- package/dist/components/GeoTile.svelte +100 -49
- package/dist/components/GeoTile.svelte.d.ts +38 -23
- package/dist/components/GeoVisible.svelte +17 -9
- package/dist/components/GeoVisible.svelte.d.ts +10 -18
- package/dist/components/Graticule.svelte +30 -14
- package/dist/components/Graticule.svelte.d.ts +11 -52
- package/dist/components/Grid.svelte +230 -117
- package/dist/components/Grid.svelte.d.ts +71 -0
- package/dist/components/Group.svelte +173 -106
- package/dist/components/Group.svelte.d.ts +81 -0
- package/dist/components/Highlight.svelte +410 -308
- package/dist/components/Highlight.svelte.d.ts +107 -0
- package/dist/components/Hull.svelte +97 -46
- package/dist/components/Hull.svelte.d.ts +40 -30
- package/dist/components/Labels.svelte +127 -47
- package/dist/components/Labels.svelte.d.ts +70 -27
- package/dist/components/Legend.svelte +374 -190
- package/dist/components/Legend.svelte.d.ts +95 -44
- package/dist/components/Line.svelte +163 -125
- package/dist/components/Line.svelte.d.ts +75 -0
- package/dist/components/LinearGradient.svelte +153 -78
- package/dist/components/LinearGradient.svelte.d.ts +66 -31
- package/dist/components/Link.svelte +160 -104
- package/dist/components/Link.svelte.d.ts +54 -0
- package/dist/components/Marker.svelte +100 -39
- package/dist/components/Marker.svelte.d.ts +59 -27
- package/dist/components/MarkerWrapper.svelte +35 -0
- package/dist/components/MarkerWrapper.svelte.d.ts +18 -0
- package/dist/components/MonthPath.svelte +65 -20
- package/dist/components/MonthPath.svelte.d.ts +23 -17
- package/dist/components/MotionPath.svelte +80 -24
- package/dist/components/MotionPath.svelte.d.ts +46 -27
- package/dist/components/Pack.svelte +53 -17
- package/dist/components/Pack.svelte.d.ts +42 -21
- package/dist/components/Partition.svelte +64 -22
- package/dist/components/Partition.svelte.d.ts +49 -26
- package/dist/components/Pattern.svelte +297 -11
- package/dist/components/Pattern.svelte.d.ts +103 -19
- package/dist/components/Pie.svelte +122 -76
- package/dist/components/Pie.svelte.d.ts +65 -51
- package/dist/components/Point.svelte +20 -9
- package/dist/components/Point.svelte.d.ts +16 -20
- package/dist/components/Points.svelte +148 -137
- package/dist/components/Points.svelte.d.ts +45 -34
- package/dist/components/RadialGradient.svelte +143 -70
- package/dist/components/RadialGradient.svelte.d.ts +69 -31
- package/dist/components/Rect.svelte +121 -102
- package/dist/components/Rect.svelte.d.ts +36 -0
- package/dist/components/RectClipPath.svelte +82 -18
- package/dist/components/RectClipPath.svelte.d.ts +55 -0
- package/dist/components/Rule.svelte +107 -63
- package/dist/components/Rule.svelte.d.ts +40 -19
- package/dist/components/Sankey.svelte +132 -55
- package/dist/components/Sankey.svelte.d.ts +61 -31
- package/dist/components/Spline.svelte +281 -218
- package/dist/components/Spline.svelte.d.ts +95 -0
- package/dist/components/Text.svelte +437 -176
- package/dist/components/Text.svelte.d.ts +130 -0
- package/dist/components/Threshold.svelte +48 -16
- package/dist/components/Threshold.svelte.d.ts +29 -31
- package/dist/components/TileImage.svelte +103 -30
- package/dist/components/TileImage.svelte.d.ts +48 -23
- package/dist/components/TransformContext.svelte +365 -171
- package/dist/components/TransformControls.svelte +50 -26
- package/dist/components/TransformControls.svelte.d.ts +27 -19
- package/dist/components/Tree.svelte +74 -33
- package/dist/components/Tree.svelte.d.ts +42 -30
- package/dist/components/Treemap.svelte +119 -42
- package/dist/components/Treemap.svelte.d.ts +75 -27
- package/dist/components/Voronoi.svelte +108 -76
- package/dist/components/Voronoi.svelte.d.ts +40 -41
- package/dist/components/charts/ArcChart.svelte +464 -0
- package/dist/components/charts/ArcChart.svelte.d.ts +90 -0
- package/dist/components/charts/AreaChart.svelte +450 -393
- package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
- package/dist/components/charts/BarChart.svelte +454 -389
- package/dist/components/charts/BarChart.svelte.d.ts +76 -0
- package/dist/components/charts/ChartAnnotations.svelte +37 -0
- package/dist/components/charts/ChartAnnotations.svelte.d.ts +10 -0
- package/dist/components/charts/DefaultTooltip.svelte +60 -0
- package/dist/components/charts/DefaultTooltip.svelte.d.ts +10 -0
- package/dist/components/charts/LineChart.svelte +369 -314
- package/dist/components/charts/LineChart.svelte.d.ts +53 -0
- package/dist/components/charts/PieChart.svelte +458 -316
- package/dist/components/charts/PieChart.svelte.d.ts +137 -353
- package/dist/components/charts/ScatterChart.svelte +334 -296
- package/dist/components/charts/ScatterChart.svelte.d.ts +39 -0
- package/dist/components/charts/index.d.ts +8 -0
- package/dist/components/charts/index.js +7 -0
- package/dist/components/charts/types.d.ts +253 -0
- package/dist/components/charts/utils.svelte.d.ts +30 -0
- package/dist/components/charts/utils.svelte.js +55 -0
- package/dist/components/index.d.ts +76 -4
- package/dist/components/index.js +76 -5
- package/dist/components/layout/Canvas.svelte +321 -155
- package/dist/components/layout/Canvas.svelte.d.ts +104 -55
- package/dist/components/layout/Html.svelte +82 -42
- package/dist/components/layout/Html.svelte.d.ts +39 -28
- package/dist/components/layout/Layer.svelte +39 -0
- package/dist/components/layout/Layer.svelte.d.ts +17 -0
- package/dist/components/layout/Svg.svelte +122 -70
- package/dist/components/layout/Svg.svelte.d.ts +53 -34
- package/dist/components/layout/WebGL.svelte +135 -0
- package/dist/components/layout/WebGL.svelte.d.ts +50 -0
- package/dist/components/tooltip/Tooltip.svelte +246 -78
- package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
- package/dist/components/tooltip/TooltipContext.svelte +409 -271
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +86 -55
- package/dist/components/tooltip/TooltipHeader.svelte +100 -11
- package/dist/components/tooltip/TooltipHeader.svelte.d.ts +43 -23
- package/dist/components/tooltip/TooltipItem.svelte +167 -27
- package/dist/components/tooltip/TooltipItem.svelte.d.ts +63 -31
- package/dist/components/tooltip/TooltipList.svelte +22 -3
- package/dist/components/tooltip/TooltipList.svelte.d.ts +6 -17
- package/dist/components/tooltip/TooltipSeparator.svelte +27 -1
- package/dist/components/tooltip/TooltipSeparator.svelte.d.ts +6 -15
- package/dist/components/tooltip/index.d.ts +6 -0
- package/dist/components/tooltip/index.js +6 -0
- package/dist/components/tooltip/tooltipMetaContext.d.ts +79 -0
- package/dist/components/tooltip/tooltipMetaContext.js +139 -0
- package/dist/components/types.d.ts +1 -0
- package/dist/components/types.js +1 -0
- package/dist/docs/Blockquote.svelte.d.ts +18 -14
- package/dist/docs/Code.svelte.d.ts +26 -22
- package/dist/docs/ConnectorSweepMenuField.svelte +17 -0
- package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +7 -0
- package/dist/docs/ConnectorTypeMenuField.svelte +17 -0
- package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +7 -0
- package/dist/docs/CurveMenuField.svelte +14 -3
- package/dist/docs/CurveMenuField.svelte.d.ts +9 -18
- package/dist/docs/GeoDebug.svelte +47 -42
- package/dist/docs/GeoDebug.svelte.d.ts +4 -16
- package/dist/docs/Header1.svelte.d.ts +27 -16
- package/dist/docs/Json.svelte.d.ts +20 -16
- package/dist/docs/Layout.svelte.d.ts +18 -13
- package/dist/docs/Link.svelte.d.ts +33 -21
- package/dist/docs/PathDataMenuField.svelte +14 -10
- package/dist/docs/PathDataMenuField.svelte.d.ts +8 -18
- package/dist/docs/Preview.svelte +20 -7
- package/dist/docs/Preview.svelte.d.ts +12 -22
- package/dist/docs/TilesetField.svelte.d.ts +21 -17
- package/dist/docs/TransformDebug.svelte +5 -6
- package/dist/docs/TransformDebug.svelte.d.ts +18 -14
- package/dist/docs/ViewSourceButton.svelte.d.ts +21 -17
- package/dist/types/d3-shape-extentions.d.ts +7 -0
- package/dist/utils/afterTick.d.ts +5 -0
- package/dist/utils/afterTick.js +8 -0
- package/dist/utils/arcText.svelte.d.ts +57 -0
- package/dist/utils/arcText.svelte.js +262 -0
- package/dist/utils/array.d.ts +9 -1
- package/dist/utils/array.js +13 -0
- package/dist/utils/attributes.d.ts +29 -0
- package/dist/utils/attributes.js +40 -0
- package/dist/utils/canvas.js +47 -10
- package/dist/utils/chart.d.ts +78 -0
- package/dist/utils/chart.js +512 -0
- package/dist/utils/color.d.ts +1 -0
- package/dist/utils/color.js +8 -0
- package/dist/utils/common.d.ts +3 -5
- package/dist/utils/common.js +3 -2
- package/dist/utils/connectorUtils.d.ts +21 -0
- package/dist/utils/connectorUtils.js +111 -0
- package/dist/utils/createId.d.ts +7 -0
- package/dist/utils/createId.js +9 -0
- package/dist/utils/debug.d.ts +1 -0
- package/dist/utils/debug.js +84 -0
- package/dist/utils/filterObject.d.ts +9 -0
- package/dist/utils/filterObject.js +12 -0
- package/dist/utils/graph/dagre.d.ts +34 -0
- package/dist/utils/graph/dagre.js +78 -0
- package/dist/utils/graph/dagre.test.d.ts +1 -0
- package/dist/utils/{graph.test.js → graph/dagre.test.js} +19 -33
- package/dist/utils/graph/sankey.d.ts +28 -0
- package/dist/utils/{graph.js → graph/sankey.js} +13 -41
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/key.svelte.d.ts +3 -0
- package/dist/utils/key.svelte.js +11 -0
- package/dist/utils/legendPayload.d.ts +7 -0
- package/dist/utils/legendPayload.js +8 -0
- package/dist/utils/motion.svelte.d.ts +140 -0
- package/dist/utils/motion.svelte.js +180 -0
- package/dist/utils/motion.test.d.ts +1 -0
- package/dist/utils/motion.test.js +213 -0
- package/dist/utils/{rect.d.ts → rect.svelte.d.ts} +7 -4
- package/dist/utils/rect.svelte.js +105 -0
- package/dist/utils/scales.svelte.d.ts +90 -0
- package/dist/utils/{scales.js → scales.svelte.js} +100 -39
- package/dist/utils/stack.d.ts +2 -3
- package/dist/utils/stack.js +1 -1
- package/dist/utils/string.js +87 -0
- package/dist/utils/ticks.d.ts +8 -2
- package/dist/utils/ticks.js +28 -0
- package/dist/utils/ticks.test.d.ts +1 -0
- package/dist/utils/ticks.test.js +67 -0
- package/dist/utils/types.d.ts +81 -0
- package/package.json +21 -19
- package/dist/components/ChartContext.svelte +0 -295
- package/dist/components/ChartContext.svelte.d.ts +0 -139
- package/dist/components/TransformContext.svelte.d.ts +0 -158
- package/dist/stores/motionStore.d.ts +0 -30
- package/dist/stores/motionStore.js +0 -62
- package/dist/utils/graph.d.ts +0 -37
- package/dist/utils/rect.js +0 -107
- package/dist/utils/scales.d.ts +0 -66
- /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
|
@@ -1,46 +1,97 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { Placement } from './types.js';
|
|
3
|
+
import type { Without } from '../utils/types.js';
|
|
4
|
+
export type LegendItem = {
|
|
5
|
+
value: any;
|
|
6
|
+
color: string;
|
|
7
|
+
};
|
|
8
|
+
export type LegendPropsWithoutHTML = {
|
|
9
|
+
scale?: AnyScale;
|
|
10
|
+
/**
|
|
11
|
+
* The title of the legend.
|
|
12
|
+
*
|
|
13
|
+
* @default ''
|
|
14
|
+
*/
|
|
15
|
+
title?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The width of the legend.
|
|
18
|
+
*
|
|
19
|
+
* @default 320
|
|
20
|
+
*/
|
|
21
|
+
width?: number;
|
|
22
|
+
/**
|
|
23
|
+
* The height of the legend.
|
|
24
|
+
*
|
|
25
|
+
* @default 10
|
|
26
|
+
*/
|
|
27
|
+
height?: number;
|
|
28
|
+
/**
|
|
29
|
+
* The number of ticks to show on the scale.
|
|
30
|
+
* @default width / 64
|
|
31
|
+
*/
|
|
32
|
+
ticks?: number;
|
|
33
|
+
tickFormat?: FormatType;
|
|
34
|
+
tickValues?: any[];
|
|
35
|
+
/**
|
|
36
|
+
* The font size of the tick labels.
|
|
37
|
+
*
|
|
38
|
+
* @default 10
|
|
39
|
+
*/
|
|
40
|
+
tickFontSize?: number;
|
|
41
|
+
/**
|
|
42
|
+
* The length of the tick marks.
|
|
43
|
+
*
|
|
44
|
+
* @default 4
|
|
45
|
+
*/
|
|
46
|
+
tickLength?: number;
|
|
47
|
+
/**
|
|
48
|
+
* The placement of the legend.
|
|
49
|
+
*/
|
|
50
|
+
placement?: Placement;
|
|
51
|
+
/**
|
|
52
|
+
* The orientation of the legend.
|
|
53
|
+
*
|
|
54
|
+
* @default 'horizontal'
|
|
55
|
+
*/
|
|
56
|
+
orientation?: 'horizontal' | 'vertical';
|
|
57
|
+
onclick?: (e: MouseEvent, detail: LegendItem) => any;
|
|
58
|
+
onpointerenter?: (e: MouseEvent, detail: LegendItem) => any;
|
|
59
|
+
onpointerleave?: (e: MouseEvent, detail: LegendItem) => any;
|
|
60
|
+
/**
|
|
61
|
+
* Determine display ramp (individual color swatches or continuous ramp)
|
|
62
|
+
*
|
|
63
|
+
* @default 'ramp'
|
|
64
|
+
*/
|
|
65
|
+
variant?: 'ramp' | 'swatches';
|
|
66
|
+
/**
|
|
67
|
+
* Classes to apply to the elements.
|
|
68
|
+
*
|
|
69
|
+
* @default {}
|
|
70
|
+
*/
|
|
71
|
+
classes?: {
|
|
72
|
+
root?: string;
|
|
73
|
+
title?: string;
|
|
74
|
+
label?: string;
|
|
75
|
+
tick?: string;
|
|
76
|
+
swatches?: string;
|
|
77
|
+
swatch?: string;
|
|
78
|
+
item?: (item: LegendItem) => string;
|
|
39
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* A bindable reference to the wrapping `<div>` element.
|
|
82
|
+
*
|
|
83
|
+
* @bindable
|
|
84
|
+
*/
|
|
85
|
+
ref?: HTMLElement;
|
|
86
|
+
children?: Snippet<[{
|
|
87
|
+
values: any[];
|
|
88
|
+
scale: AnyScale | null;
|
|
89
|
+
}]>;
|
|
40
90
|
};
|
|
41
|
-
export type LegendProps =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
91
|
+
export type LegendProps = LegendPropsWithoutHTML & Without<HTMLAttributes<HTMLElement>, LegendPropsWithoutHTML>;
|
|
92
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
93
|
+
import { type FormatType } from '@layerstack/utils';
|
|
94
|
+
import type { AnyScale } from '../utils/scales.svelte.js';
|
|
95
|
+
declare const Legend: import("svelte").Component<LegendProps, {}, "ref">;
|
|
96
|
+
type Legend = ReturnType<typeof Legend>;
|
|
97
|
+
export default Legend;
|
|
@@ -1,79 +1,146 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
3
|
+
import { createMotion, type MotionProp } from '../utils/motion.svelte.js';
|
|
4
|
+
import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
5
|
+
import MarkerWrapper, { type MarkerOptions } from './MarkerWrapper.svelte';
|
|
6
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
7
|
+
|
|
8
|
+
export type LinePropsWithoutHTML = {
|
|
9
|
+
/**
|
|
10
|
+
* The x-coordinate of the line's starting point
|
|
11
|
+
*
|
|
12
|
+
* @required
|
|
13
|
+
*/
|
|
14
|
+
x1: number;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The initial x-coordinate of the line's starting point (defaults to x1 if not provided)
|
|
18
|
+
*
|
|
19
|
+
* @default x1
|
|
20
|
+
*/
|
|
21
|
+
initialX1?: number;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The y-coordinate of the line's starting point
|
|
25
|
+
*
|
|
26
|
+
* @required
|
|
27
|
+
*/
|
|
28
|
+
y1: number;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The initial y-coordinate of the line's starting point (defaults to y1 if not provided)
|
|
32
|
+
*
|
|
33
|
+
* @default y1
|
|
34
|
+
*/
|
|
35
|
+
initialY1?: number;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The x-coordinate of the line's ending point
|
|
39
|
+
*
|
|
40
|
+
* @required
|
|
41
|
+
*/
|
|
42
|
+
x2: number;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The initial x-coordinate of the line's ending point (defaults to x2 if not provided)
|
|
46
|
+
*
|
|
47
|
+
* @default x2
|
|
48
|
+
*/
|
|
49
|
+
initialX2?: number;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The y-coordinate of the line's ending point
|
|
53
|
+
*
|
|
54
|
+
* @default y2
|
|
55
|
+
*/
|
|
56
|
+
y2: number;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The initial y-coordinate of the line's ending point (defaults to y2 if not provided)
|
|
60
|
+
*
|
|
61
|
+
* @default y2
|
|
62
|
+
*/
|
|
63
|
+
initialY2?: number;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Marker to attach to both start and end points of the line
|
|
67
|
+
*/
|
|
68
|
+
marker?: MarkerOptions;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Marker to attach to the start point of the line
|
|
72
|
+
*/
|
|
73
|
+
markerStart?: MarkerOptions;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Marker to attach to the mid point of the line
|
|
77
|
+
*/
|
|
78
|
+
markerMid?: MarkerOptions;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Marker to attach to the end point of the line
|
|
82
|
+
*/
|
|
83
|
+
markerEnd?: MarkerOptions;
|
|
84
|
+
|
|
85
|
+
motion?: MotionProp;
|
|
86
|
+
} & CommonStyleProps;
|
|
87
|
+
|
|
88
|
+
export type LineProps = LinePropsWithoutHTML &
|
|
89
|
+
Without<SVGAttributes<SVGPathElement>, LinePropsWithoutHTML>;
|
|
90
|
+
</script>
|
|
91
|
+
|
|
1
92
|
<script lang="ts">
|
|
2
|
-
import { onDestroy, tick, type ComponentProps } from 'svelte';
|
|
3
|
-
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
4
93
|
import { cls } from '@layerstack/tailwind';
|
|
5
|
-
import { uniqueId } from '@layerstack/utils';
|
|
6
|
-
import { objectId } from '@layerstack/utils/object';
|
|
7
94
|
import { merge } from 'lodash-es';
|
|
8
95
|
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import Marker from './Marker.svelte';
|
|
12
|
-
import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
13
|
-
import { getCanvasContext } from './layout/Canvas.svelte';
|
|
96
|
+
import { registerCanvasComponent } from './layout/Canvas.svelte';
|
|
14
97
|
import { getRenderContext } from './Chart.svelte';
|
|
15
98
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
56
|
-
|
|
57
|
-
let tweened_x1 = motionStore(initialX1, { spring, tweened });
|
|
58
|
-
let tweened_y1 = motionStore(initialY1, { spring, tweened });
|
|
59
|
-
let tweened_x2 = motionStore(initialX2, { spring, tweened });
|
|
60
|
-
let tweened_y2 = motionStore(initialY2, { spring, tweened });
|
|
61
|
-
|
|
62
|
-
$: tick().then(() => {
|
|
63
|
-
tweened_x1.set(x1);
|
|
64
|
-
tweened_y1.set(y1);
|
|
65
|
-
tweened_x2.set(x2);
|
|
66
|
-
tweened_y2.set(y2);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const renderContext = getRenderContext();
|
|
70
|
-
const canvasContext = getCanvasContext();
|
|
99
|
+
import { createKey } from '../utils/key.svelte.js';
|
|
100
|
+
import { createId } from '../utils/createId.js';
|
|
101
|
+
import { layerClass } from '../utils/attributes.js';
|
|
102
|
+
|
|
103
|
+
const uid = $props.id();
|
|
104
|
+
|
|
105
|
+
let {
|
|
106
|
+
x1,
|
|
107
|
+
initialX1 = x1,
|
|
108
|
+
y1,
|
|
109
|
+
initialY1 = y1,
|
|
110
|
+
x2,
|
|
111
|
+
initialX2 = x2,
|
|
112
|
+
y2,
|
|
113
|
+
initialY2 = y2,
|
|
114
|
+
class: className,
|
|
115
|
+
strokeWidth,
|
|
116
|
+
opacity,
|
|
117
|
+
fill,
|
|
118
|
+
stroke,
|
|
119
|
+
marker,
|
|
120
|
+
markerEnd,
|
|
121
|
+
markerStart,
|
|
122
|
+
markerMid,
|
|
123
|
+
motion,
|
|
124
|
+
fillOpacity,
|
|
125
|
+
...restProps
|
|
126
|
+
}: LineProps = $props();
|
|
127
|
+
|
|
128
|
+
const markerStartId = $derived(markerStart || marker ? createId('marker-start', uid) : '');
|
|
129
|
+
const markerMidId = $derived(markerMid || marker ? createId('marker-mid', uid) : '');
|
|
130
|
+
const markerEndId = $derived(markerEnd || marker ? createId('marker-end', uid) : '');
|
|
131
|
+
|
|
132
|
+
const motionX1 = createMotion(initialX1, () => x1, motion);
|
|
133
|
+
const motionY1 = createMotion(initialY1, () => y1, motion);
|
|
134
|
+
const motionX2 = createMotion(initialX2, () => x2, motion);
|
|
135
|
+
const motionY2 = createMotion(initialY2, () => y2, motion);
|
|
136
|
+
|
|
137
|
+
const renderCtx = getRenderContext();
|
|
71
138
|
|
|
72
139
|
function render(
|
|
73
140
|
ctx: CanvasRenderingContext2D,
|
|
74
141
|
styleOverrides: ComputedStylesOptions | undefined
|
|
75
142
|
) {
|
|
76
|
-
const pathData = `M ${
|
|
143
|
+
const pathData = `M ${motionX1.current},${motionY1.current} L ${motionX2.current},${motionY2.current}`;
|
|
77
144
|
renderPathData(
|
|
78
145
|
ctx,
|
|
79
146
|
pathData,
|
|
@@ -86,81 +153,52 @@
|
|
|
86
153
|
);
|
|
87
154
|
}
|
|
88
155
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
$: strokeKey = stroke && typeof stroke === 'object' ? objectId(stroke) : stroke;
|
|
92
|
-
|
|
93
|
-
$: if (renderContext === 'canvas') {
|
|
94
|
-
// Redraw when props change
|
|
95
|
-
$tweened_x1 &&
|
|
96
|
-
$tweened_y1 &&
|
|
97
|
-
$tweened_x2 &&
|
|
98
|
-
$tweened_y2 &&
|
|
99
|
-
fillKey &&
|
|
100
|
-
strokeKey &&
|
|
101
|
-
strokeWidth &&
|
|
102
|
-
opacity &&
|
|
103
|
-
className;
|
|
104
|
-
canvasContext.invalidate();
|
|
105
|
-
}
|
|
156
|
+
const fillKey = createKey(() => fill);
|
|
157
|
+
const strokeKey = createKey(() => stroke);
|
|
106
158
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
canvasUnregister = canvasContext.register({
|
|
159
|
+
if (renderCtx === 'canvas') {
|
|
160
|
+
registerCanvasComponent({
|
|
110
161
|
name: 'Line',
|
|
111
162
|
render,
|
|
112
163
|
events: {
|
|
113
|
-
click: onclick,
|
|
114
|
-
pointerenter: onpointerenter,
|
|
115
|
-
pointermove: onpointermove,
|
|
116
|
-
pointerleave: onpointerleave,
|
|
164
|
+
click: restProps.onclick,
|
|
165
|
+
pointerenter: restProps.onpointerenter,
|
|
166
|
+
pointermove: restProps.onpointermove,
|
|
167
|
+
pointerleave: restProps.onpointerleave,
|
|
117
168
|
},
|
|
169
|
+
deps: () => [
|
|
170
|
+
motionX1.current,
|
|
171
|
+
motionY1.current,
|
|
172
|
+
motionX2.current,
|
|
173
|
+
motionY2.current,
|
|
174
|
+
fillKey.current,
|
|
175
|
+
strokeKey.current,
|
|
176
|
+
strokeWidth,
|
|
177
|
+
opacity,
|
|
178
|
+
className,
|
|
179
|
+
],
|
|
118
180
|
});
|
|
119
181
|
}
|
|
120
|
-
|
|
121
|
-
onDestroy(() => {
|
|
122
|
-
if (renderContext === 'canvas') {
|
|
123
|
-
canvasUnregister();
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
182
|
</script>
|
|
127
183
|
|
|
128
|
-
{#if
|
|
129
|
-
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
184
|
+
{#if renderCtx === 'svg'}
|
|
130
185
|
<line
|
|
131
|
-
x1={
|
|
132
|
-
y1={
|
|
133
|
-
x2={
|
|
134
|
-
y2={
|
|
186
|
+
x1={motionX1.current}
|
|
187
|
+
y1={motionY1.current}
|
|
188
|
+
x2={motionX2.current}
|
|
189
|
+
y2={motionY2.current}
|
|
135
190
|
{fill}
|
|
136
191
|
{stroke}
|
|
192
|
+
fill-opacity={fillOpacity}
|
|
137
193
|
stroke-width={strokeWidth}
|
|
138
194
|
{opacity}
|
|
139
195
|
marker-start={markerStartId ? `url(#${markerStartId})` : undefined}
|
|
196
|
+
marker-mid={markerMidId ? `url(#${markerMidId})` : undefined}
|
|
140
197
|
marker-end={markerEndId ? `url(#${markerEndId})` : undefined}
|
|
141
|
-
class={cls(stroke === undefined && 'stroke-surface-content', className)}
|
|
142
|
-
{
|
|
143
|
-
on:click={onclick}
|
|
144
|
-
on:pointerenter={onpointerenter}
|
|
145
|
-
on:pointermove={onpointermove}
|
|
146
|
-
on:pointerleave={onpointerleave}
|
|
198
|
+
class={cls(layerClass('line'), stroke === undefined && 'stroke-surface-content', className)}
|
|
199
|
+
{...restProps}
|
|
147
200
|
/>
|
|
148
|
-
|
|
149
|
-
<
|
|
150
|
-
|
|
151
|
-
<Marker
|
|
152
|
-
id={markerStartId}
|
|
153
|
-
type={typeof markerStart === 'string' ? markerStart : undefined}
|
|
154
|
-
{...typeof markerStart === 'object' ? markerStart : null}
|
|
155
|
-
/>
|
|
156
|
-
{/if}
|
|
157
|
-
</slot>
|
|
158
|
-
|
|
159
|
-
<slot name="markerEnd" id={markerEndId}>
|
|
160
|
-
<Marker
|
|
161
|
-
id={markerEndId}
|
|
162
|
-
type={typeof markerEnd === 'string' ? markerEnd : undefined}
|
|
163
|
-
{...typeof markerEnd === 'object' ? markerEnd : null}
|
|
164
|
-
/>
|
|
165
|
-
</slot>
|
|
201
|
+
<MarkerWrapper id={markerStartId} marker={markerStart ?? marker} />
|
|
202
|
+
<MarkerWrapper id={markerMidId} marker={markerMid ?? marker} />
|
|
203
|
+
<MarkerWrapper id={markerEndId} marker={markerEnd ?? marker} />
|
|
166
204
|
{/if}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
2
|
+
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
3
|
+
import { type MarkerOptions } from './MarkerWrapper.svelte';
|
|
4
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
5
|
+
export type LinePropsWithoutHTML = {
|
|
6
|
+
/**
|
|
7
|
+
* The x-coordinate of the line's starting point
|
|
8
|
+
*
|
|
9
|
+
* @required
|
|
10
|
+
*/
|
|
11
|
+
x1: number;
|
|
12
|
+
/**
|
|
13
|
+
* The initial x-coordinate of the line's starting point (defaults to x1 if not provided)
|
|
14
|
+
*
|
|
15
|
+
* @default x1
|
|
16
|
+
*/
|
|
17
|
+
initialX1?: number;
|
|
18
|
+
/**
|
|
19
|
+
* The y-coordinate of the line's starting point
|
|
20
|
+
*
|
|
21
|
+
* @required
|
|
22
|
+
*/
|
|
23
|
+
y1: number;
|
|
24
|
+
/**
|
|
25
|
+
* The initial y-coordinate of the line's starting point (defaults to y1 if not provided)
|
|
26
|
+
*
|
|
27
|
+
* @default y1
|
|
28
|
+
*/
|
|
29
|
+
initialY1?: number;
|
|
30
|
+
/**
|
|
31
|
+
* The x-coordinate of the line's ending point
|
|
32
|
+
*
|
|
33
|
+
* @required
|
|
34
|
+
*/
|
|
35
|
+
x2: number;
|
|
36
|
+
/**
|
|
37
|
+
* The initial x-coordinate of the line's ending point (defaults to x2 if not provided)
|
|
38
|
+
*
|
|
39
|
+
* @default x2
|
|
40
|
+
*/
|
|
41
|
+
initialX2?: number;
|
|
42
|
+
/**
|
|
43
|
+
* The y-coordinate of the line's ending point
|
|
44
|
+
*
|
|
45
|
+
* @default y2
|
|
46
|
+
*/
|
|
47
|
+
y2: number;
|
|
48
|
+
/**
|
|
49
|
+
* The initial y-coordinate of the line's ending point (defaults to y2 if not provided)
|
|
50
|
+
*
|
|
51
|
+
* @default y2
|
|
52
|
+
*/
|
|
53
|
+
initialY2?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Marker to attach to both start and end points of the line
|
|
56
|
+
*/
|
|
57
|
+
marker?: MarkerOptions;
|
|
58
|
+
/**
|
|
59
|
+
* Marker to attach to the start point of the line
|
|
60
|
+
*/
|
|
61
|
+
markerStart?: MarkerOptions;
|
|
62
|
+
/**
|
|
63
|
+
* Marker to attach to the mid point of the line
|
|
64
|
+
*/
|
|
65
|
+
markerMid?: MarkerOptions;
|
|
66
|
+
/**
|
|
67
|
+
* Marker to attach to the end point of the line
|
|
68
|
+
*/
|
|
69
|
+
markerEnd?: MarkerOptions;
|
|
70
|
+
motion?: MotionProp;
|
|
71
|
+
} & CommonStyleProps;
|
|
72
|
+
export type LineProps = LinePropsWithoutHTML & Without<SVGAttributes<SVGPathElement>, LinePropsWithoutHTML>;
|
|
73
|
+
declare const Line: import("svelte").Component<LineProps, {}, "">;
|
|
74
|
+
type Line = ReturnType<typeof Line>;
|
|
75
|
+
export default Line;
|