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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { ComponentProps, Snippet } from 'svelte';
|
|
2
|
+
import Circle from './Circle.svelte';
|
|
3
|
+
import Line from './Line.svelte';
|
|
4
|
+
import Bar from './Bar.svelte';
|
|
5
|
+
import Rect from './Rect.svelte';
|
|
6
|
+
import { type Accessor } from '../utils/common.js';
|
|
7
|
+
export type HighlightPointData = {
|
|
8
|
+
x: any;
|
|
9
|
+
y: any;
|
|
10
|
+
};
|
|
11
|
+
export type HighlightPoint = {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
fill: string;
|
|
15
|
+
data: HighlightPointData;
|
|
16
|
+
};
|
|
17
|
+
export type HighlightPropsWithoutHTML = {
|
|
18
|
+
/**
|
|
19
|
+
* Highlight specific data (annotate), especte uses tooltip data
|
|
20
|
+
*/
|
|
21
|
+
data?: any;
|
|
22
|
+
/**
|
|
23
|
+
* Override `x` from context
|
|
24
|
+
*/
|
|
25
|
+
x?: Accessor;
|
|
26
|
+
/**
|
|
27
|
+
* Override `y` from context
|
|
28
|
+
*/
|
|
29
|
+
y?: Accessor;
|
|
30
|
+
axis?: 'x' | 'y' | 'both' | 'none';
|
|
31
|
+
/**
|
|
32
|
+
* Show points and pass props to Circles
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
points?: boolean | Partial<ComponentProps<typeof Circle>> | Snippet<[
|
|
36
|
+
{
|
|
37
|
+
points: {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
fill: string;
|
|
41
|
+
data: HighlightPointData;
|
|
42
|
+
}[];
|
|
43
|
+
}
|
|
44
|
+
]>;
|
|
45
|
+
/**
|
|
46
|
+
* Show lines and pass props to Lines
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
lines?: boolean | Partial<ComponentProps<typeof Line>> | Snippet<[
|
|
50
|
+
{
|
|
51
|
+
lines: {
|
|
52
|
+
x1: number;
|
|
53
|
+
y1: number;
|
|
54
|
+
x2: number;
|
|
55
|
+
y2: number;
|
|
56
|
+
}[];
|
|
57
|
+
}
|
|
58
|
+
]>;
|
|
59
|
+
/**
|
|
60
|
+
* Show area and pass props to Rect
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
area?: boolean | Partial<ComponentProps<typeof Rect>> | Snippet<[
|
|
64
|
+
{
|
|
65
|
+
area: {
|
|
66
|
+
x: number;
|
|
67
|
+
y: number;
|
|
68
|
+
width: number;
|
|
69
|
+
height: number;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
]>;
|
|
73
|
+
/**
|
|
74
|
+
* Show bar and pass props to Rect
|
|
75
|
+
*
|
|
76
|
+
* @default false
|
|
77
|
+
*/
|
|
78
|
+
bar?: boolean | Partial<ComponentProps<typeof Bar>> | Snippet;
|
|
79
|
+
/**
|
|
80
|
+
* Set to false to disable spring transitions
|
|
81
|
+
*
|
|
82
|
+
* @default true
|
|
83
|
+
*/
|
|
84
|
+
motion?: MotionProp;
|
|
85
|
+
onAreaClick?: (e: MouseEvent, detail: {
|
|
86
|
+
data: any;
|
|
87
|
+
}) => void;
|
|
88
|
+
onBarClick?: (e: MouseEvent, detail: {
|
|
89
|
+
data: any;
|
|
90
|
+
}) => void;
|
|
91
|
+
onPointClick?: (e: MouseEvent, detail: {
|
|
92
|
+
point: HighlightPoint;
|
|
93
|
+
data: any;
|
|
94
|
+
}) => void;
|
|
95
|
+
onPointEnter?: (e: MouseEvent, detail: {
|
|
96
|
+
point: HighlightPoint;
|
|
97
|
+
data: any;
|
|
98
|
+
}) => void;
|
|
99
|
+
onPointLeave?: (e: MouseEvent, detail: {
|
|
100
|
+
point: HighlightPoint;
|
|
101
|
+
data: any;
|
|
102
|
+
}) => void;
|
|
103
|
+
};
|
|
104
|
+
import type { MotionProp } from '../utils/motion.svelte.js';
|
|
105
|
+
declare const Highlight: import("svelte").Component<HighlightPropsWithoutHTML, {}, "">;
|
|
106
|
+
type Highlight = ReturnType<typeof Highlight>;
|
|
107
|
+
export default Highlight;
|
|
@@ -1,5 +1,58 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Without } from '../utils/types.js';
|
|
3
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
4
|
+
import type { ComponentProps } from 'svelte';
|
|
5
|
+
|
|
6
|
+
export type HullPropsWithoutHTML = {
|
|
7
|
+
/**
|
|
8
|
+
* Override data instead of using context
|
|
9
|
+
*/
|
|
10
|
+
data?: any;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The curve factory to use for the hull
|
|
14
|
+
* @default curveLinearClosed
|
|
15
|
+
*/
|
|
16
|
+
curve?: ComponentProps<typeof Spline>['curve'];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Classes to apply to the elements.
|
|
20
|
+
*/
|
|
21
|
+
classes?: {
|
|
22
|
+
root?: string;
|
|
23
|
+
path?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
onpointermove?: (
|
|
27
|
+
e: PointerEvent,
|
|
28
|
+
details: {
|
|
29
|
+
points: [number, number][];
|
|
30
|
+
polygon: Delaunay.Polygon;
|
|
31
|
+
}
|
|
32
|
+
) => void;
|
|
33
|
+
|
|
34
|
+
onclick?: (
|
|
35
|
+
e: MouseEvent,
|
|
36
|
+
details: {
|
|
37
|
+
points: [number, number][];
|
|
38
|
+
polygon: Delaunay.Polygon;
|
|
39
|
+
}
|
|
40
|
+
) => void;
|
|
41
|
+
|
|
42
|
+
onpointerleave?: (e: PointerEvent) => void;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A bindable reference to the wrapping `<g>` element.
|
|
46
|
+
*
|
|
47
|
+
* @bindable
|
|
48
|
+
*/
|
|
49
|
+
ref?: SVGGElement;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type HullProps = HullPropsWithoutHTML & Without<GroupProps, HullPropsWithoutHTML>;
|
|
53
|
+
</script>
|
|
54
|
+
|
|
1
55
|
<script lang="ts">
|
|
2
|
-
import { type ComponentProps } from 'svelte';
|
|
3
56
|
import { min } from 'd3-array';
|
|
4
57
|
import { Delaunay } from 'd3-delaunay';
|
|
5
58
|
// @ts-expect-error
|
|
@@ -7,59 +60,57 @@
|
|
|
7
60
|
import { curveLinearClosed } from 'd3-shape';
|
|
8
61
|
import { cls } from '@layerstack/tailwind';
|
|
9
62
|
|
|
10
|
-
import { chartContext } from './ChartContext.svelte';
|
|
11
63
|
import GeoPath from './GeoPath.svelte';
|
|
12
|
-
import {
|
|
64
|
+
import Group, { type GroupProps } from './Group.svelte';
|
|
13
65
|
import Spline from './Spline.svelte';
|
|
66
|
+
import { getChartContext } from './Chart.svelte';
|
|
67
|
+
import { getGeoContext } from './GeoContext.svelte';
|
|
68
|
+
import { layerClass } from '../utils/attributes.js';
|
|
69
|
+
|
|
70
|
+
let {
|
|
71
|
+
data,
|
|
72
|
+
curve = curveLinearClosed,
|
|
73
|
+
classes = {},
|
|
74
|
+
onpointermove,
|
|
75
|
+
onclick,
|
|
76
|
+
onpointerleave,
|
|
77
|
+
class: className,
|
|
78
|
+
ref: refProp = $bindable(),
|
|
79
|
+
...restProps
|
|
80
|
+
}: HullProps = $props();
|
|
81
|
+
|
|
82
|
+
let ref = $state<SVGGElement>();
|
|
14
83
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/** Override data instead of using context */
|
|
19
|
-
export let data: any = undefined;
|
|
20
|
-
|
|
21
|
-
export let curve: ComponentProps<Spline>['curve'] = curveLinearClosed;
|
|
22
|
-
|
|
23
|
-
export let classes: {
|
|
24
|
-
root?: string;
|
|
25
|
-
path?: string;
|
|
26
|
-
} = {};
|
|
27
|
-
|
|
28
|
-
export let onclick:
|
|
29
|
-
| ((e: MouseEvent, details: { points: [number, number][]; polygon: Delaunay.Polygon }) => void)
|
|
30
|
-
| undefined = undefined;
|
|
31
|
-
export let onpointermove:
|
|
32
|
-
| ((
|
|
33
|
-
e: PointerEvent,
|
|
34
|
-
details: {
|
|
35
|
-
points: [number, number][];
|
|
36
|
-
polygon: Delaunay.Polygon;
|
|
37
|
-
}
|
|
38
|
-
) => void)
|
|
39
|
-
| undefined = undefined;
|
|
40
|
-
export let onpointerleave: ((e: PointerEvent) => void) | undefined = undefined;
|
|
41
|
-
|
|
42
|
-
$: points = (data ?? $flatData).map((d: any) => {
|
|
43
|
-
const xValue = $xContext(d);
|
|
44
|
-
const yValue = $yContext(d);
|
|
45
|
-
|
|
46
|
-
const x = Array.isArray(xValue) ? min(xValue) : xValue;
|
|
47
|
-
const y = Array.isArray(yValue) ? min(yValue) : yValue;
|
|
48
|
-
|
|
49
|
-
const point = [x, y];
|
|
50
|
-
// @ts-expect-error
|
|
51
|
-
point.data = d;
|
|
52
|
-
return point;
|
|
84
|
+
$effect.pre(() => {
|
|
85
|
+
refProp = ref;
|
|
53
86
|
});
|
|
87
|
+
|
|
88
|
+
const ctx = getChartContext();
|
|
89
|
+
const geoCtx = getGeoContext();
|
|
90
|
+
|
|
91
|
+
const points = $derived(
|
|
92
|
+
(data ?? ctx.flatData).map((d: any) => {
|
|
93
|
+
const xValue = ctx.x(d);
|
|
94
|
+
const yValue = ctx.y(d);
|
|
95
|
+
|
|
96
|
+
const x = Array.isArray(xValue) ? min(xValue) : xValue;
|
|
97
|
+
const y = Array.isArray(yValue) ? min(yValue) : yValue;
|
|
98
|
+
|
|
99
|
+
const point = [x, y];
|
|
100
|
+
// @ts-expect-error
|
|
101
|
+
point.data = d;
|
|
102
|
+
return point;
|
|
103
|
+
})
|
|
104
|
+
);
|
|
54
105
|
</script>
|
|
55
106
|
|
|
56
|
-
<
|
|
57
|
-
{#if
|
|
107
|
+
<Group {...restProps} class={cls(layerClass('hull-g'), classes.root, className)} bind:ref>
|
|
108
|
+
{#if geoCtx.projection}
|
|
58
109
|
{@const polygon = geoVoronoi().hull(points)}
|
|
59
110
|
<GeoPath
|
|
60
111
|
geojson={polygon}
|
|
61
112
|
{curve}
|
|
62
|
-
class={cls('fill-transparent', classes.path)}
|
|
113
|
+
class={cls(layerClass('hull-path'), 'fill-transparent', classes.path)}
|
|
63
114
|
onclick={(e) => onclick?.(e, { points, polygon })}
|
|
64
115
|
onpointermove={(e) => onpointermove?.(e, { points, polygon })}
|
|
65
116
|
{onpointerleave}
|
|
@@ -72,10 +123,10 @@
|
|
|
72
123
|
x={(d) => d[0]}
|
|
73
124
|
y={(d) => d[1]}
|
|
74
125
|
{curve}
|
|
75
|
-
class={cls('fill-transparent', classes.path)}
|
|
126
|
+
class={cls(layerClass('hull-class'), 'fill-transparent', classes.path)}
|
|
76
127
|
onclick={(e) => onclick?.(e, { points, polygon })}
|
|
77
128
|
onpointermove={(e) => onpointermove?.(e, { points, polygon })}
|
|
78
129
|
{onpointerleave}
|
|
79
130
|
/>
|
|
80
131
|
{/if}
|
|
81
|
-
</
|
|
132
|
+
</Group>
|
|
@@ -1,32 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}) => void) | undefined | undefined;
|
|
20
|
-
onpointerleave?: ((e: PointerEvent) => void) | undefined | undefined;
|
|
21
|
-
};
|
|
22
|
-
events: {
|
|
23
|
-
[evt: string]: CustomEvent<any>;
|
|
1
|
+
import type { Without } from '../utils/types.js';
|
|
2
|
+
import type { ComponentProps } from 'svelte';
|
|
3
|
+
export type HullPropsWithoutHTML = {
|
|
4
|
+
/**
|
|
5
|
+
* Override data instead of using context
|
|
6
|
+
*/
|
|
7
|
+
data?: any;
|
|
8
|
+
/**
|
|
9
|
+
* The curve factory to use for the hull
|
|
10
|
+
* @default curveLinearClosed
|
|
11
|
+
*/
|
|
12
|
+
curve?: ComponentProps<typeof Spline>['curve'];
|
|
13
|
+
/**
|
|
14
|
+
* Classes to apply to the elements.
|
|
15
|
+
*/
|
|
16
|
+
classes?: {
|
|
17
|
+
root?: string;
|
|
18
|
+
path?: string;
|
|
24
19
|
};
|
|
25
|
-
|
|
20
|
+
onpointermove?: (e: PointerEvent, details: {
|
|
21
|
+
points: [number, number][];
|
|
22
|
+
polygon: Delaunay.Polygon;
|
|
23
|
+
}) => void;
|
|
24
|
+
onclick?: (e: MouseEvent, details: {
|
|
25
|
+
points: [number, number][];
|
|
26
|
+
polygon: Delaunay.Polygon;
|
|
27
|
+
}) => void;
|
|
28
|
+
onpointerleave?: (e: PointerEvent) => void;
|
|
29
|
+
/**
|
|
30
|
+
* A bindable reference to the wrapping `<g>` element.
|
|
31
|
+
*
|
|
32
|
+
* @bindable
|
|
33
|
+
*/
|
|
34
|
+
ref?: SVGGElement;
|
|
26
35
|
};
|
|
27
|
-
export type HullProps =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
36
|
+
export type HullProps = HullPropsWithoutHTML & Without<GroupProps, HullPropsWithoutHTML>;
|
|
37
|
+
import { Delaunay } from 'd3-delaunay';
|
|
38
|
+
import { type GroupProps } from './Group.svelte';
|
|
39
|
+
import Spline from './Spline.svelte';
|
|
40
|
+
declare const Hull: import("svelte").Component<HullProps, {}, "ref">;
|
|
41
|
+
type Hull = ReturnType<typeof Hull>;
|
|
42
|
+
export default Hull;
|
|
@@ -1,56 +1,129 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { type
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import Text, { type TextProps } from './Text.svelte';
|
|
3
|
+
import { type ComponentProps, type Snippet } from 'svelte';
|
|
3
4
|
import { format as formatValue, type FormatType } from '@layerstack/utils';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import Text from './Text.svelte';
|
|
7
|
-
import { isScaleBand } from '../utils/scales.js';
|
|
8
|
-
import { chartContext } from './ChartContext.svelte';
|
|
5
|
+
import type { Without } from '../utils/types.js';
|
|
9
6
|
import Points, { type Point } from './Points.svelte';
|
|
10
7
|
import { accessor, type Accessor } from '../utils/common.js';
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
export type LabelsPropsWithoutHTML<T = any> = {
|
|
10
|
+
/**
|
|
11
|
+
* Override data instead of using context
|
|
12
|
+
*/
|
|
13
|
+
data?: T;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Override display value accessor. By default, uses `y` unless yScale is band scale
|
|
17
|
+
*/
|
|
18
|
+
value?: Accessor<T>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The fill color of the label, which can either be a string or an accessor function
|
|
22
|
+
* that returns a valid `fill` color value.
|
|
23
|
+
*
|
|
24
|
+
* The accessor is useful for dynamic fill colors based on the data the label represents.
|
|
25
|
+
*/
|
|
26
|
+
fill?: string | Accessor<T>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Override `x` accessor from Chart context
|
|
30
|
+
*/
|
|
31
|
+
x?: Accessor<T>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Override `y` accessor from Chart context
|
|
35
|
+
*/
|
|
36
|
+
y?: Accessor<T>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The placement of the label relative to the point
|
|
40
|
+
* @default 'outside'
|
|
41
|
+
*/
|
|
42
|
+
placement?: 'inside' | 'outside' | 'center';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The offset of the label from the point
|
|
46
|
+
*
|
|
47
|
+
* @default placement === 'center' ? 0 : 4
|
|
48
|
+
*/
|
|
49
|
+
offset?: number;
|
|
13
50
|
|
|
14
|
-
|
|
15
|
-
|
|
51
|
+
/**
|
|
52
|
+
* The format of the label
|
|
53
|
+
*/
|
|
54
|
+
format?: FormatType;
|
|
16
55
|
|
|
17
|
-
|
|
18
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Define unique value for {#each} `(key)` expressions to improve transitions.
|
|
58
|
+
* `index` position used by default
|
|
59
|
+
*
|
|
60
|
+
* @default (d, index) => index
|
|
61
|
+
*/
|
|
62
|
+
key?: (d: T, index: number) => any;
|
|
19
63
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export
|
|
64
|
+
children?: Snippet<[{ data: Point; textProps: ComponentProps<typeof Text> }]>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type LabelsProps<T = any> = LabelsPropsWithoutHTML<T> &
|
|
68
|
+
Without<TextProps, LabelsPropsWithoutHTML<T>>;
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<script lang="ts" generics="TData = any">
|
|
72
|
+
import { cls } from '@layerstack/tailwind';
|
|
73
|
+
|
|
74
|
+
import { isScaleBand } from '../utils/scales.svelte.js';
|
|
75
|
+
import { getChartContext } from './Chart.svelte';
|
|
76
|
+
import Group from './Group.svelte';
|
|
77
|
+
import { extractLayerProps, layerClass } from '../utils/attributes.js';
|
|
24
78
|
|
|
25
|
-
|
|
26
|
-
export let offset = placement === 'center' ? 0 : 4;
|
|
27
|
-
export let format: FormatType | undefined = undefined;
|
|
79
|
+
const ctx = getChartContext();
|
|
28
80
|
|
|
29
|
-
|
|
30
|
-
|
|
81
|
+
let {
|
|
82
|
+
data,
|
|
83
|
+
value,
|
|
84
|
+
x,
|
|
85
|
+
y,
|
|
86
|
+
placement = 'outside',
|
|
87
|
+
offset = placement === 'center' ? 0 : 4,
|
|
88
|
+
format,
|
|
89
|
+
key = (_: any, i: number) => i,
|
|
90
|
+
children: childrenProp,
|
|
91
|
+
class: className,
|
|
92
|
+
fill,
|
|
93
|
+
...restProps
|
|
94
|
+
}: LabelsProps<TData> = $props();
|
|
31
95
|
|
|
32
|
-
|
|
96
|
+
function getTextProps(point: Point): ComponentProps<typeof Text> {
|
|
33
97
|
// Used for positioning
|
|
34
|
-
const pointValue = isScaleBand(
|
|
98
|
+
const pointValue = isScaleBand(ctx.yScale) ? point.xValue : point.yValue;
|
|
99
|
+
|
|
100
|
+
// extract the true fill value from `fill` which could be an
|
|
101
|
+
// accessor function or string/undefined
|
|
102
|
+
const fillValue = typeof fill === 'function' ? accessor(fill)(point.data) : fill;
|
|
35
103
|
|
|
36
104
|
const displayValue = value
|
|
37
105
|
? accessor(value)(point.data)
|
|
38
|
-
: isScaleBand(
|
|
106
|
+
: isScaleBand(ctx.yScale)
|
|
39
107
|
? point.xValue
|
|
40
108
|
: point.yValue;
|
|
41
109
|
|
|
42
110
|
const formattedValue = formatValue(
|
|
43
111
|
displayValue,
|
|
44
112
|
format ??
|
|
45
|
-
(value
|
|
113
|
+
(value
|
|
114
|
+
? undefined
|
|
115
|
+
: isScaleBand(ctx.yScale)
|
|
116
|
+
? ctx.xScale.tickFormat?.()
|
|
117
|
+
: ctx.yScale.tickFormat?.())
|
|
46
118
|
);
|
|
47
119
|
|
|
48
|
-
if (isScaleBand(
|
|
120
|
+
if (isScaleBand(ctx.yScale)) {
|
|
49
121
|
// Position label left/right on horizontal bars
|
|
50
122
|
if (pointValue < 0) {
|
|
51
123
|
// left
|
|
52
124
|
return {
|
|
53
125
|
value: formattedValue,
|
|
126
|
+
fill: fillValue,
|
|
54
127
|
x: point.x + (placement === 'outside' ? -offset : offset),
|
|
55
128
|
y: point.y,
|
|
56
129
|
textAnchor: placement === 'outside' ? 'end' : 'start',
|
|
@@ -61,6 +134,7 @@
|
|
|
61
134
|
// right
|
|
62
135
|
return {
|
|
63
136
|
value: formattedValue,
|
|
137
|
+
fill: fillValue,
|
|
64
138
|
x: point.x + (placement === 'outside' ? offset : -offset),
|
|
65
139
|
y: point.y,
|
|
66
140
|
textAnchor: placement === 'outside' ? 'start' : 'end',
|
|
@@ -74,6 +148,7 @@
|
|
|
74
148
|
// bottom
|
|
75
149
|
return {
|
|
76
150
|
value: formattedValue,
|
|
151
|
+
fill: fillValue,
|
|
77
152
|
x: point.x,
|
|
78
153
|
y: point.y + (placement === 'outside' ? offset : -offset),
|
|
79
154
|
capHeight: '.6rem',
|
|
@@ -85,6 +160,7 @@
|
|
|
85
160
|
// top
|
|
86
161
|
return {
|
|
87
162
|
value: formattedValue,
|
|
163
|
+
fill: fillValue,
|
|
88
164
|
x: point.x,
|
|
89
165
|
y: point.y + (placement === 'outside' ? -offset : offset),
|
|
90
166
|
capHeight: '.6rem',
|
|
@@ -94,27 +170,31 @@
|
|
|
94
170
|
};
|
|
95
171
|
}
|
|
96
172
|
}
|
|
97
|
-
}
|
|
173
|
+
}
|
|
98
174
|
</script>
|
|
99
175
|
|
|
100
|
-
<
|
|
101
|
-
<Points {data} {x} {y}
|
|
102
|
-
{#
|
|
103
|
-
{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
{
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
176
|
+
<Group class={layerClass('labels-g')}>
|
|
177
|
+
<Points {data} {x} {y}>
|
|
178
|
+
{#snippet children({ points })}
|
|
179
|
+
{#each points as point, i (key(point.data, i))}
|
|
180
|
+
{@const textProps = extractLayerProps(getTextProps(point), 'labels-text')}
|
|
181
|
+
{#if childrenProp}
|
|
182
|
+
{@render childrenProp({ data: point, textProps })}
|
|
183
|
+
{:else}
|
|
184
|
+
<Text
|
|
185
|
+
{...textProps}
|
|
186
|
+
{...restProps}
|
|
187
|
+
class={cls(
|
|
188
|
+
'text-xs',
|
|
189
|
+
placement === 'inside'
|
|
190
|
+
? 'fill-surface-300 stroke-surface-content'
|
|
191
|
+
: 'fill-surface-content stroke-surface-100',
|
|
192
|
+
textProps.class,
|
|
193
|
+
className
|
|
194
|
+
)}
|
|
195
|
+
/>
|
|
196
|
+
{/if}
|
|
197
|
+
{/each}
|
|
198
|
+
{/snippet}
|
|
119
199
|
</Points>
|
|
120
|
-
</
|
|
200
|
+
</Group>
|