layerchart 2.0.0-next.0 → 2.0.0-next.2
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 +155 -0
- package/dist/components/AnnotationLine.svelte.d.ts +28 -0
- package/dist/components/AnnotationPoint.svelte +121 -0
- package/dist/components/AnnotationPoint.svelte.d.ts +32 -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 +287 -174
- package/dist/components/Axis.svelte.d.ts +116 -0
- package/dist/components/Bar.svelte +163 -107
- package/dist/components/Bar.svelte.d.ts +48 -0
- package/dist/components/Bars.svelte +54 -68
- package/dist/components/Bars.svelte.d.ts +27 -0
- package/dist/components/Blur.svelte +31 -7
- 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 +60 -15
- 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 +47 -12
- 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 +28 -13
- package/dist/components/Graticule.svelte.d.ts +11 -52
- package/dist/components/Grid.svelte +226 -114
- package/dist/components/Grid.svelte.d.ts +70 -0
- package/dist/components/Group.svelte +132 -105
- package/dist/components/Group.svelte.d.ts +53 -0
- package/dist/components/Highlight.svelte +409 -307
- package/dist/components/Highlight.svelte.d.ts +107 -0
- package/dist/components/Hull.svelte +96 -45
- package/dist/components/Hull.svelte.d.ts +40 -30
- package/dist/components/Labels.svelte +125 -46
- 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 +105 -62
- 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 +106 -75
- 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 +25 -24
- 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,443 +1,545 @@
|
|
|
1
|
-
<script lang="ts"
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { ComponentProps, Snippet } from 'svelte';
|
|
3
|
+
import Circle from './Circle.svelte';
|
|
4
|
+
import Line from './Line.svelte';
|
|
5
|
+
import Bar from './Bar.svelte';
|
|
6
|
+
import Rect from './Rect.svelte';
|
|
7
|
+
import { accessor, type Accessor } from '../utils/common.js';
|
|
8
|
+
|
|
2
9
|
export type HighlightPointData = { x: any; y: any };
|
|
10
|
+
export type HighlightPoint = { x: number; y: number; fill: string; data: HighlightPointData };
|
|
11
|
+
|
|
12
|
+
export type HighlightPropsWithoutHTML = {
|
|
13
|
+
/**
|
|
14
|
+
* Highlight specific data (annotate), especte uses tooltip data
|
|
15
|
+
*/
|
|
16
|
+
data?: any;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Override `x` from context
|
|
20
|
+
*/
|
|
21
|
+
x?: Accessor;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Override `y` from context
|
|
25
|
+
*/
|
|
26
|
+
y?: Accessor;
|
|
27
|
+
|
|
28
|
+
axis?: 'x' | 'y' | 'both' | 'none';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Show points and pass props to Circles
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
points?:
|
|
35
|
+
| boolean
|
|
36
|
+
| Partial<ComponentProps<typeof Circle>>
|
|
37
|
+
| Snippet<
|
|
38
|
+
[
|
|
39
|
+
{
|
|
40
|
+
points: {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
fill: string;
|
|
44
|
+
data: HighlightPointData;
|
|
45
|
+
}[];
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Show lines and pass props to Lines
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
54
|
+
lines?:
|
|
55
|
+
| boolean
|
|
56
|
+
| Partial<ComponentProps<typeof Line>>
|
|
57
|
+
| Snippet<
|
|
58
|
+
[
|
|
59
|
+
{
|
|
60
|
+
lines: {
|
|
61
|
+
x1: number;
|
|
62
|
+
y1: number;
|
|
63
|
+
x2: number;
|
|
64
|
+
y2: number;
|
|
65
|
+
}[];
|
|
66
|
+
},
|
|
67
|
+
]
|
|
68
|
+
>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Show area and pass props to Rect
|
|
72
|
+
* @default false
|
|
73
|
+
*/
|
|
74
|
+
area?:
|
|
75
|
+
| boolean
|
|
76
|
+
| Partial<ComponentProps<typeof Rect>>
|
|
77
|
+
| Snippet<
|
|
78
|
+
[
|
|
79
|
+
{
|
|
80
|
+
area: {
|
|
81
|
+
x: number;
|
|
82
|
+
y: number;
|
|
83
|
+
width: number;
|
|
84
|
+
height: number;
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Show bar and pass props to Rect
|
|
92
|
+
*
|
|
93
|
+
* @default false
|
|
94
|
+
*/
|
|
95
|
+
bar?: boolean | Partial<ComponentProps<typeof Bar>> | Snippet;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Set to false to disable spring transitions
|
|
99
|
+
*
|
|
100
|
+
* @default true
|
|
101
|
+
*/
|
|
102
|
+
motion?: MotionProp;
|
|
103
|
+
|
|
104
|
+
onAreaClick?: (e: MouseEvent, detail: { data: any }) => void;
|
|
105
|
+
onBarClick?: (e: MouseEvent, detail: { data: any }) => void;
|
|
106
|
+
|
|
107
|
+
onPointClick?: (e: MouseEvent, detail: { point: HighlightPoint; data: any }) => void;
|
|
108
|
+
onPointEnter?: (e: MouseEvent, detail: { point: HighlightPoint; data: any }) => void;
|
|
109
|
+
onPointLeave?: (e: MouseEvent, detail: { point: HighlightPoint; data: any }) => void;
|
|
110
|
+
};
|
|
3
111
|
</script>
|
|
4
112
|
|
|
5
113
|
<script lang="ts">
|
|
6
|
-
import { type ComponentProps } from 'svelte';
|
|
7
114
|
import { max, min } from 'd3-array';
|
|
8
115
|
import { pointRadial, type Series, type SeriesPoint } from 'd3-shape';
|
|
9
116
|
import { notNull } from '@layerstack/utils';
|
|
10
117
|
import { cls } from '@layerstack/tailwind';
|
|
11
118
|
|
|
12
|
-
import {
|
|
13
|
-
import Circle from './Circle.svelte';
|
|
14
|
-
import Line from './Line.svelte';
|
|
15
|
-
import Bar from './Bar.svelte';
|
|
16
|
-
import Rect from './Rect.svelte';
|
|
17
|
-
import { tooltipContext } from './tooltip/TooltipContext.svelte';
|
|
18
|
-
|
|
19
|
-
import { isScaleBand } from '../utils/scales.js';
|
|
20
|
-
import { accessor, type Accessor } from '../utils/common.js';
|
|
119
|
+
import { isScaleBand } from '../utils/scales.svelte.js';
|
|
21
120
|
import { asAny } from '../utils/types.js';
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
/** Set to false to disable spring transitions */
|
|
68
|
-
export let motion = true;
|
|
69
|
-
|
|
70
|
-
export let onareaclick: ((e: MouseEvent, detail: { data: any }) => void) | undefined = undefined;
|
|
71
|
-
export let onbarclick: ((e: MouseEvent, detail: { data: any }) => void) | undefined = undefined;
|
|
72
|
-
|
|
73
|
-
export let onpointclick:
|
|
74
|
-
| ((e: MouseEvent, detail: { point: (typeof _points)[number]; data: any }) => void)
|
|
75
|
-
| undefined = undefined;
|
|
76
|
-
export let onpointenter:
|
|
77
|
-
| ((e: MouseEvent, detail: { point: (typeof _points)[number]; data: any }) => void)
|
|
78
|
-
| undefined = undefined;
|
|
79
|
-
export let onpointleave:
|
|
80
|
-
| ((e: MouseEvent, detail: { point: (typeof _points)[number]; data: any }) => void)
|
|
81
|
-
| undefined = undefined;
|
|
82
|
-
|
|
83
|
-
const _x = accessor(x);
|
|
84
|
-
const _y = accessor(y);
|
|
85
|
-
|
|
86
|
-
let _points: { x: number; y: number; fill: string; data: HighlightPointData }[] = [];
|
|
87
|
-
let _lines: { x1: number; y1: number; x2: number; y2: number }[] = [];
|
|
88
|
-
let _area = {
|
|
89
|
-
x: 0,
|
|
90
|
-
y: 0,
|
|
91
|
-
width: 0,
|
|
92
|
-
height: 0,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
$: highlightData = data ?? $tooltip.data;
|
|
96
|
-
|
|
97
|
-
$: if (highlightData) {
|
|
98
|
-
const xValue = _x(highlightData);
|
|
99
|
-
const xCoord = Array.isArray(xValue) ? xValue.map((v) => $xScale(v)) : $xScale(xValue);
|
|
100
|
-
const xOffset = isScaleBand($xScale) && !$radial ? $xScale.bandwidth() / 2 : 0;
|
|
101
|
-
|
|
102
|
-
const yValue = _y(highlightData);
|
|
103
|
-
const yCoord = Array.isArray(yValue) ? yValue.map((v) => $yScale(v)) : $yScale(yValue);
|
|
104
|
-
const yOffset = isScaleBand($yScale) && !$radial ? $yScale.bandwidth() / 2 : 0;
|
|
105
|
-
|
|
106
|
-
// Reset lines
|
|
107
|
-
_lines = [];
|
|
108
|
-
|
|
109
|
-
const defaultAxis = isScaleBand($yScale) ? 'y' : 'x';
|
|
110
|
-
if (axis == null) {
|
|
111
|
-
axis = defaultAxis;
|
|
112
|
-
}
|
|
113
|
-
|
|
121
|
+
import { getChartContext } from './Chart.svelte';
|
|
122
|
+
import { getTooltipContext } from './tooltip/TooltipContext.svelte';
|
|
123
|
+
import { extractLayerProps } from '../utils/attributes.js';
|
|
124
|
+
import type { MotionProp } from '../utils/motion.svelte.js';
|
|
125
|
+
import Arc from './Arc.svelte';
|
|
126
|
+
|
|
127
|
+
const ctx = getChartContext();
|
|
128
|
+
const tooltipCtx = getTooltipContext();
|
|
129
|
+
|
|
130
|
+
let {
|
|
131
|
+
data,
|
|
132
|
+
x: xProp = ctx.x,
|
|
133
|
+
y: yProp = ctx.y,
|
|
134
|
+
axis: axisProp,
|
|
135
|
+
points = false,
|
|
136
|
+
lines: linesProp = false,
|
|
137
|
+
area = false,
|
|
138
|
+
bar = false,
|
|
139
|
+
motion = 'spring',
|
|
140
|
+
onAreaClick,
|
|
141
|
+
onBarClick,
|
|
142
|
+
onPointClick,
|
|
143
|
+
onPointEnter,
|
|
144
|
+
onPointLeave,
|
|
145
|
+
}: HighlightPropsWithoutHTML = $props();
|
|
146
|
+
|
|
147
|
+
const x = $derived(accessor(xProp));
|
|
148
|
+
const y = $derived(accessor(yProp));
|
|
149
|
+
|
|
150
|
+
const highlightData = $derived(data ?? tooltipCtx.data);
|
|
151
|
+
const xValue = $derived(x(highlightData));
|
|
152
|
+
const xCoord = $derived(
|
|
153
|
+
Array.isArray(xValue) ? xValue.map((v) => ctx.xScale(v)) : ctx.xScale(xValue)
|
|
154
|
+
);
|
|
155
|
+
const xOffset = $derived(isScaleBand(ctx.xScale) && !ctx.radial ? ctx.xScale.bandwidth() / 2 : 0);
|
|
156
|
+
const yValue = $derived(y(highlightData));
|
|
157
|
+
const yCoord = $derived(
|
|
158
|
+
Array.isArray(yValue) ? yValue.map((v) => ctx.yScale(v)) : ctx.yScale(yValue)
|
|
159
|
+
);
|
|
160
|
+
const yOffset = $derived(isScaleBand(ctx.yScale) && !ctx.radial ? ctx.yScale.bandwidth() / 2 : 0);
|
|
161
|
+
const axis = $derived(axisProp == null ? (isScaleBand(ctx.yScale) ? 'y' : 'x') : axisProp);
|
|
162
|
+
|
|
163
|
+
const _lines: { x1: number; y1: number; x2: number; y2: number }[] = $derived.by(() => {
|
|
164
|
+
let tmpLines: { x1: number; y1: number; x2: number; y2: number }[] = [];
|
|
165
|
+
if (!highlightData) return tmpLines;
|
|
114
166
|
if (axis === 'x' || axis === 'both') {
|
|
115
|
-
// x lines
|
|
116
167
|
if (Array.isArray(xCoord)) {
|
|
117
168
|
// `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
|
|
118
|
-
|
|
119
|
-
...
|
|
169
|
+
tmpLines = [
|
|
170
|
+
...tmpLines,
|
|
120
171
|
...xCoord.filter(notNull).map((xItem, i) => ({
|
|
121
172
|
x1: xItem + xOffset,
|
|
122
|
-
y1: min(
|
|
173
|
+
y1: min(ctx.yRange) as unknown as number,
|
|
123
174
|
x2: xItem + xOffset,
|
|
124
|
-
y2: max(
|
|
175
|
+
y2: max(ctx.yRange) as unknown as number,
|
|
125
176
|
})),
|
|
126
177
|
];
|
|
127
178
|
} else if (xCoord) {
|
|
128
|
-
|
|
129
|
-
...
|
|
179
|
+
tmpLines = [
|
|
180
|
+
...tmpLines,
|
|
130
181
|
{
|
|
131
182
|
x1: xCoord + xOffset,
|
|
132
|
-
y1: min(
|
|
183
|
+
y1: min(ctx.yRange) as unknown as number,
|
|
133
184
|
x2: xCoord + xOffset,
|
|
134
|
-
y2: max(
|
|
185
|
+
y2: max(ctx.yRange) as unknown as number,
|
|
135
186
|
},
|
|
136
187
|
];
|
|
137
188
|
}
|
|
138
|
-
|
|
139
|
-
// x area
|
|
140
|
-
if (Array.isArray(xCoord)) {
|
|
141
|
-
// `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
|
|
142
|
-
_area.width = max(xCoord) - min(xCoord); // Use first/last values for width
|
|
143
|
-
} else if (isScaleBand($xScale)) {
|
|
144
|
-
_area.width = $xScale.step();
|
|
145
|
-
} else {
|
|
146
|
-
// Find width to next data point
|
|
147
|
-
const index = $flatData.findIndex((d) => Number(_x(d)) === Number(_x(highlightData)));
|
|
148
|
-
const isLastPoint = index + 1 === $flatData.length;
|
|
149
|
-
const nextDataPoint = isLastPoint ? max($xDomain) : _x($flatData[index + 1]);
|
|
150
|
-
_area.width = ($xScale(nextDataPoint) ?? 0) - (xCoord ?? 0);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// If array, use left-most value for top left of rect
|
|
154
|
-
_area.x =
|
|
155
|
-
(Array.isArray(xCoord) ? min(xCoord) : xCoord) -
|
|
156
|
-
(isScaleBand($xScale) ? ($xScale.padding() * $xScale.step()) / 2 : 0);
|
|
157
|
-
|
|
158
|
-
if (axis === 'x') {
|
|
159
|
-
_area.height = max($yRange) as unknown as number;
|
|
160
|
-
}
|
|
161
189
|
}
|
|
162
190
|
|
|
163
191
|
if (axis === 'y' || axis === 'both') {
|
|
164
192
|
// y lines
|
|
165
193
|
if (Array.isArray(yCoord)) {
|
|
166
194
|
// `y` accessor with multiple properties (ex. `y={['start', 'end']})`)
|
|
167
|
-
|
|
168
|
-
...
|
|
195
|
+
tmpLines = [
|
|
196
|
+
...tmpLines,
|
|
169
197
|
...yCoord.filter(notNull).map((yItem, i) => ({
|
|
170
|
-
x1: min(
|
|
198
|
+
x1: min(ctx.xRange) as unknown as number,
|
|
171
199
|
y1: yItem + yOffset,
|
|
172
|
-
x2: max(
|
|
200
|
+
x2: max(ctx.xRange) as unknown as number,
|
|
173
201
|
y2: yItem + yOffset,
|
|
174
202
|
})),
|
|
175
203
|
];
|
|
176
204
|
} else if (yCoord) {
|
|
177
|
-
|
|
178
|
-
...
|
|
205
|
+
tmpLines = [
|
|
206
|
+
...tmpLines,
|
|
179
207
|
{
|
|
180
|
-
x1: min(
|
|
208
|
+
x1: min(ctx.xRange) as unknown as number,
|
|
181
209
|
y1: yCoord + yOffset,
|
|
182
|
-
x2: max(
|
|
210
|
+
x2: max(ctx.xRange) as unknown as number,
|
|
183
211
|
y2: yCoord + yOffset,
|
|
184
212
|
},
|
|
185
213
|
];
|
|
186
214
|
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (ctx.radial) {
|
|
218
|
+
tmpLines = tmpLines.map((l) => {
|
|
219
|
+
const [x1, y1] = pointRadial(l.x1, l.y1);
|
|
220
|
+
const [x2, y2] = pointRadial(l.x2, l.y2);
|
|
221
|
+
return {
|
|
222
|
+
...l,
|
|
223
|
+
x1,
|
|
224
|
+
y1,
|
|
225
|
+
x2,
|
|
226
|
+
y2,
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return tmpLines;
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const _area: {
|
|
235
|
+
x: number;
|
|
236
|
+
y: number;
|
|
237
|
+
width: number;
|
|
238
|
+
height: number;
|
|
239
|
+
} = $derived.by(() => {
|
|
240
|
+
const tmpArea: {
|
|
241
|
+
x: number;
|
|
242
|
+
y: number;
|
|
243
|
+
width: number;
|
|
244
|
+
height: number;
|
|
245
|
+
} = {
|
|
246
|
+
x: 0,
|
|
247
|
+
y: 0,
|
|
248
|
+
width: 0,
|
|
249
|
+
height: 0,
|
|
250
|
+
};
|
|
251
|
+
if (!highlightData) return tmpArea;
|
|
252
|
+
if (axis === 'x' || axis === 'both') {
|
|
253
|
+
// x area
|
|
254
|
+
if (Array.isArray(xCoord)) {
|
|
255
|
+
// `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
|
|
256
|
+
tmpArea.width = max(xCoord) - min(xCoord); // Use first/last values for width
|
|
257
|
+
} else if (isScaleBand(ctx.xScale)) {
|
|
258
|
+
tmpArea.width = ctx.xScale.step();
|
|
259
|
+
} else {
|
|
260
|
+
// Find width to next data point
|
|
261
|
+
const index = ctx.flatData.findIndex((d) => Number(x(d)) === Number(x(highlightData)));
|
|
262
|
+
const isLastPoint = index + 1 === ctx.flatData.length;
|
|
263
|
+
const nextDataPoint = isLastPoint ? max(ctx.xDomain) : x(ctx.flatData[index + 1]);
|
|
264
|
+
tmpArea.width = (ctx.xScale(nextDataPoint) ?? 0) - (xCoord ?? 0);
|
|
265
|
+
}
|
|
187
266
|
|
|
267
|
+
// If array, use left-most value for top left of rect
|
|
268
|
+
tmpArea.x =
|
|
269
|
+
(Array.isArray(xCoord) ? min(xCoord) : xCoord) -
|
|
270
|
+
(isScaleBand(ctx.xScale) ? (ctx.xScale.padding() * ctx.xScale.step()) / 2 : 0);
|
|
271
|
+
|
|
272
|
+
if (axis === 'x') {
|
|
273
|
+
tmpArea.y = min(ctx.yRange) as unknown as number;
|
|
274
|
+
tmpArea.height = (max(ctx.yRange) - min(ctx.yRange)) as unknown as number;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (axis === 'y' || axis === 'both') {
|
|
188
279
|
// y area
|
|
189
280
|
if (Array.isArray(yCoord)) {
|
|
190
281
|
// `y` accessor with multiple properties (ex. `y={['start', 'end']})`)
|
|
191
|
-
|
|
192
|
-
} else if (isScaleBand(
|
|
193
|
-
|
|
282
|
+
tmpArea.height = max(yCoord) - min(yCoord); // Use first/last values for width
|
|
283
|
+
} else if (isScaleBand(ctx.yScale)) {
|
|
284
|
+
tmpArea.height = ctx.yScale.step();
|
|
194
285
|
} else {
|
|
195
286
|
// Find width to next data point
|
|
196
|
-
const index =
|
|
197
|
-
const isLastPoint = index + 1 ===
|
|
198
|
-
const nextDataPoint = isLastPoint ? max(
|
|
199
|
-
|
|
287
|
+
const index = ctx.flatData.findIndex((d) => Number(x(d)) === Number(x(highlightData)));
|
|
288
|
+
const isLastPoint = index + 1 === ctx.flatData.length;
|
|
289
|
+
const nextDataPoint = isLastPoint ? max(ctx.yDomain) : x(ctx.flatData[index + 1]);
|
|
290
|
+
tmpArea.height = (ctx.yScale(nextDataPoint) ?? 0) - (yCoord ?? 0);
|
|
200
291
|
}
|
|
201
292
|
|
|
202
293
|
// If array, use left-most value for top left of rect
|
|
203
|
-
|
|
294
|
+
tmpArea.y =
|
|
204
295
|
(Array.isArray(yCoord) ? min(yCoord) : yCoord) -
|
|
205
|
-
(isScaleBand(
|
|
296
|
+
(isScaleBand(ctx.yScale) ? (ctx.yScale.padding() * ctx.yScale.step()) / 2 : 0);
|
|
206
297
|
|
|
207
298
|
if (axis === 'y') {
|
|
208
|
-
|
|
299
|
+
tmpArea.width = max(ctx.xRange) as unknown as number;
|
|
209
300
|
}
|
|
210
301
|
}
|
|
302
|
+
return tmpArea;
|
|
303
|
+
});
|
|
211
304
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (Array.isArray(
|
|
217
|
-
//
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
305
|
+
const _points: { x: number; y: number; fill: string; data: HighlightPointData }[] = $derived.by(
|
|
306
|
+
() => {
|
|
307
|
+
let tmpPoints: { x: number; y: number; fill: string; data: HighlightPointData }[] = [];
|
|
308
|
+
if (!highlightData) return tmpPoints;
|
|
309
|
+
if (Array.isArray(xCoord)) {
|
|
310
|
+
// `x` accessor with multiple properties (ex. `x={['start', 'end']}` or `x={[0, 1]}`)
|
|
311
|
+
|
|
312
|
+
if (Array.isArray(highlightData)) {
|
|
313
|
+
// Stack series (ex. `y={[['apples', 'bananas', 'oranges']]})`)
|
|
314
|
+
// `highlightData` is a single stack layer/point, which is an 2 element array with an extra `data` property `[number, number, data: any]`.
|
|
315
|
+
const highlightSeriesPoint = highlightData as SeriesPoint<any>;
|
|
316
|
+
|
|
317
|
+
// Ignore non-array data such as hierarchy and graph (make Typescript happy)
|
|
318
|
+
if (Array.isArray(ctx.data)) {
|
|
319
|
+
// For each series, find the related data point
|
|
320
|
+
const seriesPointsData = (ctx.data as any[])
|
|
321
|
+
.map((series: Series<any, any>) => {
|
|
322
|
+
return {
|
|
323
|
+
series,
|
|
324
|
+
point: series.find((d) => y(d) === y(highlightSeriesPoint))!,
|
|
325
|
+
};
|
|
326
|
+
})
|
|
327
|
+
.filter((d) => d.point); // remove if no point found (ex. Histogram);
|
|
328
|
+
|
|
329
|
+
tmpPoints = seriesPointsData.map((seriesPoint, i) => {
|
|
226
330
|
return {
|
|
227
|
-
|
|
228
|
-
|
|
331
|
+
x: ctx.xScale(seriesPoint.point[1]) + xOffset,
|
|
332
|
+
y: yCoord + yOffset,
|
|
333
|
+
fill: ctx.config.c ? ctx.cGet(seriesPoint.series) : null,
|
|
334
|
+
data: {
|
|
335
|
+
x: seriesPoint.point[1],
|
|
336
|
+
y: yValue,
|
|
337
|
+
},
|
|
229
338
|
};
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
} else {
|
|
342
|
+
// Multi series / etc (ex. `y={['apples', 'bananas', 'oranges']}`)
|
|
343
|
+
tmpPoints = xCoord.filter(notNull).map((xItem, i) => {
|
|
344
|
+
// @ts-expect-error - TODO: fix type
|
|
345
|
+
const _key = ctx.config.x?.[i];
|
|
234
346
|
return {
|
|
235
|
-
x:
|
|
347
|
+
x: xItem + xOffset,
|
|
236
348
|
y: yCoord + yOffset,
|
|
237
|
-
|
|
349
|
+
// TODO: is there a better way to expose the series key/value?
|
|
350
|
+
fill: ctx.config.c ? ctx.cGet({ ...highlightData, $key: _key }) : null,
|
|
238
351
|
data: {
|
|
239
|
-
x:
|
|
352
|
+
x: xValue, // TODO: use highlightData[$key]?
|
|
240
353
|
y: yValue,
|
|
241
354
|
},
|
|
242
355
|
};
|
|
243
356
|
});
|
|
244
357
|
}
|
|
245
|
-
} else {
|
|
246
|
-
//
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
358
|
+
} else if (Array.isArray(yCoord)) {
|
|
359
|
+
// `y` accessor with multiple properties (ex. `y={['apples', 'bananas', 'oranges']}` or `y={[0, 1]})
|
|
360
|
+
|
|
361
|
+
if (Array.isArray(highlightData)) {
|
|
362
|
+
// Stack series (ex. `y={[['apples', 'bananas', 'oranges']]})`)
|
|
363
|
+
// `highlightData` is a single stack layer/point, which is an 2 element array with an extra `data` property `[number, number, data: any]`.
|
|
364
|
+
const highlightSeriesPoint = highlightData as SeriesPoint<any>;
|
|
365
|
+
|
|
366
|
+
// Ignore non-array data such as hierarchy and graph (make Typescript happy)
|
|
367
|
+
if (Array.isArray(ctx.data)) {
|
|
368
|
+
// For each series, find the related data point
|
|
369
|
+
const seriesPointsData = (ctx.data as any[])
|
|
370
|
+
.map((series: Series<any, any>) => {
|
|
371
|
+
return {
|
|
372
|
+
series,
|
|
373
|
+
point: series.find((d) => x(d) === x(highlightSeriesPoint))!,
|
|
374
|
+
};
|
|
375
|
+
})
|
|
376
|
+
.filter((d) => d.point); // remove if no point found (ex. Histogram)
|
|
377
|
+
|
|
378
|
+
tmpPoints = seriesPointsData.map((seriesPoint, i) => ({
|
|
379
|
+
x: xCoord + xOffset,
|
|
380
|
+
y: ctx.yScale(seriesPoint.point[1]) + yOffset,
|
|
381
|
+
fill: ctx.config.c ? ctx.cGet(seriesPoint.series) : null,
|
|
382
|
+
data: {
|
|
383
|
+
x: xValue,
|
|
384
|
+
y: seriesPoint.point[1],
|
|
385
|
+
},
|
|
386
|
+
}));
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
// Multi series / etc (ex. `y={['apples', 'bananas', 'oranges']}`)
|
|
390
|
+
tmpPoints = yCoord.filter(notNull).map((yItem, i) => {
|
|
391
|
+
// @ts-expect-error - TODO: fix type
|
|
392
|
+
const _key = ctx.config.y[i];
|
|
393
|
+
return {
|
|
394
|
+
x: xCoord + xOffset,
|
|
395
|
+
y: yItem + yOffset,
|
|
396
|
+
// TODO: is there a better way to expose the series key/value?
|
|
397
|
+
fill: ctx.config.c ? ctx.cGet({ ...highlightData, $key: _key }) : null,
|
|
398
|
+
data: {
|
|
399
|
+
x: xValue,
|
|
400
|
+
y: yValue, // TODO: use highlightData[$key] ?
|
|
401
|
+
},
|
|
402
|
+
};
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
} else if (xCoord != null && yCoord != null) {
|
|
406
|
+
tmpPoints = [
|
|
407
|
+
{
|
|
408
|
+
x: xCoord + xOffset,
|
|
251
409
|
y: yCoord + yOffset,
|
|
252
|
-
|
|
253
|
-
fill: $config.c ? $cGet({ ...highlightData, $key }) : null,
|
|
410
|
+
fill: ctx.config.c ? ctx.cGet(highlightData) : null,
|
|
254
411
|
data: {
|
|
255
|
-
x: xValue,
|
|
412
|
+
x: xValue,
|
|
256
413
|
y: yValue,
|
|
257
414
|
},
|
|
258
|
-
}
|
|
259
|
-
|
|
415
|
+
},
|
|
416
|
+
];
|
|
417
|
+
} else {
|
|
418
|
+
tmpPoints = [];
|
|
260
419
|
}
|
|
261
|
-
} else if (Array.isArray(yCoord)) {
|
|
262
|
-
// `y` accessor with multiple properties (ex. `y={['apples', 'bananas', 'oranges']}` or `y={[0, 1]})
|
|
263
|
-
|
|
264
|
-
if (Array.isArray(highlightData)) {
|
|
265
|
-
// Stack series (ex. `y={[['apples', 'bananas', 'oranges']]})`)
|
|
266
|
-
// `highlightData` is a single stack layer/point, which is an 2 element array with an extra `data` property `[number, number, data: any]`.
|
|
267
|
-
const highlightSeriesPoint = highlightData as SeriesPoint<any>;
|
|
268
|
-
|
|
269
|
-
// Ignore non-array data such as hierarchy and graph (make Typescript happy)
|
|
270
|
-
if (Array.isArray($contextData)) {
|
|
271
|
-
// For each series, find the related data point
|
|
272
|
-
const seriesPointsData = $contextData
|
|
273
|
-
.map((series: Series<any, any>) => {
|
|
274
|
-
return {
|
|
275
|
-
series,
|
|
276
|
-
point: series.find((d) => _x(d) === _x(highlightSeriesPoint))!,
|
|
277
|
-
};
|
|
278
|
-
})
|
|
279
|
-
.filter((d) => d.point); // remove if no point found (ex. Histogram)
|
|
280
420
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
data: {
|
|
286
|
-
x: xValue,
|
|
287
|
-
y: seriesPoint.point[1],
|
|
288
|
-
},
|
|
289
|
-
}));
|
|
290
|
-
}
|
|
291
|
-
} else {
|
|
292
|
-
// Multi series / etc (ex. `y={['apples', 'bananas', 'oranges']}`)
|
|
293
|
-
_points = yCoord.filter(notNull).map((yItem, i) => {
|
|
294
|
-
const $key = $config.y[i];
|
|
421
|
+
if (ctx.radial) {
|
|
422
|
+
// Translate x/y to angle/radius
|
|
423
|
+
tmpPoints = tmpPoints.map((p) => {
|
|
424
|
+
const [x, y] = pointRadial(p.x, p.y);
|
|
295
425
|
return {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
fill: $config.c ? $cGet({ ...highlightData, $key }) : null,
|
|
300
|
-
data: {
|
|
301
|
-
x: xValue,
|
|
302
|
-
y: yValue, // TODO: use highlightData[$key] ?
|
|
303
|
-
},
|
|
426
|
+
...p,
|
|
427
|
+
x,
|
|
428
|
+
y,
|
|
304
429
|
};
|
|
305
430
|
});
|
|
306
431
|
}
|
|
307
|
-
|
|
308
|
-
_points = [
|
|
309
|
-
{
|
|
310
|
-
x: xCoord + xOffset,
|
|
311
|
-
y: yCoord + yOffset,
|
|
312
|
-
fill: $config.c ? $cGet(highlightData) : null,
|
|
313
|
-
data: {
|
|
314
|
-
x: xValue,
|
|
315
|
-
y: yValue,
|
|
316
|
-
},
|
|
317
|
-
},
|
|
318
|
-
];
|
|
319
|
-
} else {
|
|
320
|
-
_points = [];
|
|
432
|
+
return tmpPoints;
|
|
321
433
|
}
|
|
434
|
+
);
|
|
322
435
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
return {
|
|
328
|
-
...p,
|
|
329
|
-
x,
|
|
330
|
-
y,
|
|
331
|
-
};
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
_lines = _lines.map((l) => {
|
|
335
|
-
const [x1, y1] = pointRadial(l.x1, l.y1);
|
|
336
|
-
const [x2, y2] = pointRadial(l.x2, l.y2);
|
|
337
|
-
return {
|
|
338
|
-
...l,
|
|
339
|
-
x1,
|
|
340
|
-
y1,
|
|
341
|
-
x2,
|
|
342
|
-
y2,
|
|
343
|
-
};
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
// TODO: How to handle _areas
|
|
347
|
-
}
|
|
348
|
-
}
|
|
436
|
+
const areaProps = $derived(extractLayerProps(area, 'highlight-area'));
|
|
437
|
+
const barProps = $derived(extractLayerProps(bar, 'highlight-bar'));
|
|
438
|
+
const linesProps = $derived(extractLayerProps(linesProp, 'highlight-line'));
|
|
439
|
+
const pointsProps = $derived(extractLayerProps(points, 'highlight-point'));
|
|
349
440
|
</script>
|
|
350
441
|
|
|
351
442
|
{#if highlightData}
|
|
352
443
|
{#if area}
|
|
353
|
-
|
|
444
|
+
{#if typeof area === 'function'}
|
|
445
|
+
{@render area({ area: _area })}
|
|
446
|
+
{:else if ctx.radial}
|
|
447
|
+
<!-- TODO: What should we do about areaProps -->
|
|
448
|
+
<Arc
|
|
449
|
+
motion={motion === 'spring' ? 'spring' : undefined}
|
|
450
|
+
startAngle={_area.x}
|
|
451
|
+
endAngle={_area.x + _area.width}
|
|
452
|
+
innerRadius={_area.y}
|
|
453
|
+
outerRadius={_area.y + _area.height}
|
|
454
|
+
class={cls(!areaProps.fill && 'fill-surface-content/5', areaProps.class)}
|
|
455
|
+
onclick={onAreaClick && ((e) => onAreaClick(e, { data: highlightData }))}
|
|
456
|
+
/>
|
|
457
|
+
{:else}
|
|
354
458
|
<Rect
|
|
355
|
-
|
|
459
|
+
motion={motion === 'spring' ? 'spring' : undefined}
|
|
356
460
|
{..._area}
|
|
357
|
-
{...
|
|
358
|
-
class={cls(
|
|
359
|
-
|
|
360
|
-
!area.fill && 'fill-surface-content/5',
|
|
361
|
-
typeof area === 'object' ? area.class : null
|
|
362
|
-
)}
|
|
363
|
-
onclick={onareaclick && ((e) => onareaclick(e, { data: highlightData }))}
|
|
461
|
+
{...areaProps}
|
|
462
|
+
class={cls(!areaProps.fill && 'fill-surface-content/5', areaProps.class)}
|
|
463
|
+
onclick={onAreaClick && ((e) => onAreaClick(e, { data: highlightData }))}
|
|
364
464
|
/>
|
|
365
|
-
|
|
465
|
+
{/if}
|
|
366
466
|
{/if}
|
|
367
467
|
|
|
368
468
|
{#if bar}
|
|
369
|
-
|
|
469
|
+
{#if typeof bar === 'function'}
|
|
470
|
+
{@render bar()}
|
|
471
|
+
{:else}
|
|
370
472
|
<Bar
|
|
371
|
-
|
|
473
|
+
motion={motion === 'spring' ? 'spring' : undefined}
|
|
372
474
|
bar={highlightData}
|
|
373
|
-
{...
|
|
374
|
-
class={cls(
|
|
375
|
-
|
|
376
|
-
!bar.fill && 'fill-primary',
|
|
377
|
-
typeof bar === 'object' ? bar.class : null
|
|
378
|
-
)}
|
|
379
|
-
onclick={onbarclick && ((e) => onbarclick(e, { data: highlightData }))}
|
|
475
|
+
{...barProps}
|
|
476
|
+
class={cls(!barProps.fill && 'fill-primary', barProps.class)}
|
|
477
|
+
onclick={onBarClick && ((e) => onBarClick(e, { data: highlightData }))}
|
|
380
478
|
/>
|
|
381
|
-
|
|
479
|
+
{/if}
|
|
382
480
|
{/if}
|
|
383
481
|
|
|
384
|
-
{#if
|
|
385
|
-
|
|
482
|
+
{#if linesProp}
|
|
483
|
+
{#if typeof linesProp === 'function'}
|
|
484
|
+
{@render linesProp({ lines: _lines })}
|
|
485
|
+
{:else}
|
|
386
486
|
{#each _lines as line}
|
|
387
487
|
<Line
|
|
388
|
-
|
|
488
|
+
motion={motion === 'spring' ? 'spring' : undefined}
|
|
389
489
|
x1={line.x1}
|
|
390
490
|
y1={line.y1}
|
|
391
491
|
x2={line.x2}
|
|
392
492
|
y2={line.y2}
|
|
393
|
-
{...
|
|
493
|
+
{...linesProps}
|
|
394
494
|
class={cls(
|
|
395
495
|
'stroke-surface-content/20 stroke-2 [stroke-dasharray:2,2] pointer-events-none',
|
|
396
|
-
|
|
496
|
+
linesProps.class
|
|
397
497
|
)}
|
|
398
498
|
/>
|
|
399
499
|
{/each}
|
|
400
|
-
|
|
500
|
+
{/if}
|
|
401
501
|
{/if}
|
|
402
502
|
|
|
403
503
|
{#if points}
|
|
404
|
-
|
|
504
|
+
{#if typeof points === 'function'}
|
|
505
|
+
{@render points({ points: _points })}
|
|
506
|
+
{:else}
|
|
405
507
|
{#each _points as point}
|
|
406
508
|
<Circle
|
|
407
|
-
|
|
509
|
+
motion={motion === 'spring' ? 'spring' : undefined}
|
|
408
510
|
cx={point.x}
|
|
409
511
|
cy={point.y}
|
|
410
512
|
fill={point.fill}
|
|
411
513
|
r={4}
|
|
412
514
|
strokeWidth={6}
|
|
413
|
-
{...
|
|
515
|
+
{...pointsProps}
|
|
414
516
|
class={cls(
|
|
415
517
|
'stroke-white [paint-order:stroke] drop-shadow-sm',
|
|
416
518
|
!point.fill && (typeof points === 'boolean' || !points.fill) && 'fill-primary',
|
|
417
|
-
|
|
519
|
+
pointsProps.class
|
|
418
520
|
)}
|
|
419
|
-
onpointerdown={
|
|
521
|
+
onpointerdown={onPointClick &&
|
|
420
522
|
((e) => {
|
|
421
523
|
// Do not propagate `pointerdown` event to `BrushContext` if `onclick` is provided
|
|
422
524
|
e.stopPropagation();
|
|
423
525
|
})}
|
|
424
|
-
onclick={
|
|
425
|
-
onpointerenter={
|
|
526
|
+
onclick={onPointClick && ((e) => onPointClick(e, { point, data: highlightData }))}
|
|
527
|
+
onpointerenter={onPointEnter &&
|
|
426
528
|
((e) => {
|
|
427
|
-
if (
|
|
529
|
+
if (onPointClick) {
|
|
428
530
|
asAny(e.target).style.cursor = 'pointer';
|
|
429
531
|
}
|
|
430
|
-
|
|
532
|
+
onPointEnter(e, { point, data: highlightData });
|
|
431
533
|
})}
|
|
432
|
-
onpointerleave={
|
|
534
|
+
onpointerleave={onPointLeave &&
|
|
433
535
|
((e) => {
|
|
434
|
-
if (
|
|
536
|
+
if (onPointClick) {
|
|
435
537
|
asAny(e.target).style.cursor = 'default';
|
|
436
538
|
}
|
|
437
|
-
|
|
539
|
+
onPointLeave(e, { point, data: highlightData });
|
|
438
540
|
})}
|
|
439
541
|
/>
|
|
440
542
|
{/each}
|
|
441
|
-
|
|
543
|
+
{/if}
|
|
442
544
|
{/if}
|
|
443
545
|
{/if}
|