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,159 +1,177 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export type LineChartExtraSnippetProps<TData> = {
|
|
3
|
+
getSplineProps: (
|
|
4
|
+
s: SeriesData<TData, typeof Spline>,
|
|
5
|
+
i: number
|
|
6
|
+
) => ComponentProps<typeof Spline>;
|
|
7
|
+
getLabelsProps: (
|
|
8
|
+
s: SeriesData<TData, typeof Spline>,
|
|
9
|
+
i: number
|
|
10
|
+
) => ComponentProps<typeof Labels<TData>>;
|
|
11
|
+
getPointsProps: (
|
|
12
|
+
s: SeriesData<TData, typeof Spline>,
|
|
13
|
+
i: number
|
|
14
|
+
) => ComponentProps<typeof Points>;
|
|
15
|
+
getHighlightProps: (
|
|
16
|
+
s: SeriesData<TData, typeof Spline>,
|
|
17
|
+
i: number
|
|
18
|
+
) => ComponentProps<typeof Highlight>;
|
|
19
|
+
getGridProps: () => ComponentProps<typeof Grid>;
|
|
20
|
+
getAxisProps: (axisDirection?: 'x' | 'y') => ComponentProps<typeof Axis>;
|
|
21
|
+
getRuleProps: () => ComponentProps<typeof Rule>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type LineChartPropsObjProp = Pick<
|
|
25
|
+
SimplifiedChartPropsObject,
|
|
26
|
+
| 'brush'
|
|
27
|
+
| 'canvas'
|
|
28
|
+
| 'grid'
|
|
29
|
+
| 'highlight'
|
|
30
|
+
| 'labels'
|
|
31
|
+
| 'legend'
|
|
32
|
+
| 'points'
|
|
33
|
+
| 'rule'
|
|
34
|
+
| 'spline'
|
|
35
|
+
| 'svg'
|
|
36
|
+
| 'tooltip'
|
|
37
|
+
| 'xAxis'
|
|
38
|
+
| 'yAxis'
|
|
39
|
+
>;
|
|
40
|
+
|
|
41
|
+
export type LineChartProps<TData> = SimplifiedChartProps<
|
|
42
|
+
TData,
|
|
43
|
+
typeof Spline,
|
|
44
|
+
LineChartExtraSnippetProps<TData>
|
|
45
|
+
> & {
|
|
46
|
+
/**
|
|
47
|
+
* The event to be dispatched when the point is clicked.
|
|
48
|
+
*/
|
|
49
|
+
onPointClick?: (
|
|
50
|
+
e: MouseEvent,
|
|
51
|
+
details: { data: HighlightPointData; series: SeriesData<TData, typeof Spline> }
|
|
52
|
+
) => void;
|
|
53
|
+
|
|
54
|
+
props?: LineChartPropsObjProp;
|
|
55
|
+
|
|
56
|
+
spline?: SimplifiedChartSnippet<
|
|
57
|
+
TData,
|
|
58
|
+
typeof Spline,
|
|
59
|
+
LineChartExtraSnippetProps<TData> & {
|
|
60
|
+
props: ComponentProps<typeof Spline>;
|
|
61
|
+
/**
|
|
62
|
+
* The index of the series currently being iterated over.
|
|
63
|
+
*/
|
|
64
|
+
seriesIndex: number;
|
|
65
|
+
}
|
|
66
|
+
>;
|
|
67
|
+
};
|
|
68
|
+
</script>
|
|
69
|
+
|
|
1
70
|
<script lang="ts" generics="TData">
|
|
2
71
|
import { onMount, type ComponentProps } from 'svelte';
|
|
3
|
-
import { scaleLinear,
|
|
72
|
+
import { scaleLinear, scaleTime } from 'd3-scale';
|
|
4
73
|
import { format } from '@layerstack/utils';
|
|
5
74
|
import { cls } from '@layerstack/tailwind';
|
|
6
|
-
import { selectionStore } from '@layerstack/svelte-stores';
|
|
7
75
|
|
|
8
76
|
import Axis from '../Axis.svelte';
|
|
9
|
-
import BrushContext from '../BrushContext.svelte';
|
|
10
|
-
import Canvas from '../layout/Canvas.svelte';
|
|
11
77
|
import Chart from '../Chart.svelte';
|
|
12
78
|
import ChartClipPath from '../ChartClipPath.svelte';
|
|
13
79
|
import Grid from '../Grid.svelte';
|
|
14
80
|
import Highlight, { type HighlightPointData } from '../Highlight.svelte';
|
|
15
81
|
import Labels from '../Labels.svelte';
|
|
82
|
+
import Layer from '../layout/Layer.svelte';
|
|
16
83
|
import Legend from '../Legend.svelte';
|
|
17
84
|
import Points from '../Points.svelte';
|
|
18
85
|
import Rule from '../Rule.svelte';
|
|
19
86
|
import Spline from '../Spline.svelte';
|
|
20
|
-
import Svg from '../layout/Svg.svelte';
|
|
21
|
-
import * as Tooltip from '../tooltip/index.js';
|
|
22
87
|
|
|
23
88
|
import {
|
|
24
89
|
accessor,
|
|
25
90
|
chartDataArray,
|
|
26
91
|
defaultChartPadding,
|
|
27
92
|
findRelatedData,
|
|
28
|
-
type Accessor,
|
|
29
93
|
} from '../../utils/common.js';
|
|
30
94
|
import { asAny } from '../../utils/types.js';
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
) => void)
|
|
93
|
-
| undefined = undefined;
|
|
94
|
-
|
|
95
|
-
export let props: {
|
|
96
|
-
brush?: Partial<ComponentProps<BrushContext>>;
|
|
97
|
-
canvas?: Partial<ComponentProps<Canvas>>;
|
|
98
|
-
grid?: Partial<ComponentProps<Grid>>;
|
|
99
|
-
highlight?: Partial<ComponentProps<Highlight>>;
|
|
100
|
-
labels?: Partial<ComponentProps<Labels>>;
|
|
101
|
-
legend?: Partial<ComponentProps<Legend>>;
|
|
102
|
-
points?: Partial<ComponentProps<Points>>;
|
|
103
|
-
rule?: Partial<ComponentProps<Rule>>;
|
|
104
|
-
spline?: Partial<ComponentProps<Spline>>;
|
|
105
|
-
svg?: Partial<ComponentProps<Svg>>;
|
|
106
|
-
tooltip?: {
|
|
107
|
-
context?: Partial<ComponentProps<Tooltip.Context>>;
|
|
108
|
-
root?: Partial<ComponentProps<Tooltip.Root>>;
|
|
109
|
-
header?: Partial<ComponentProps<Tooltip.Header>>;
|
|
110
|
-
list?: Partial<ComponentProps<Tooltip.List>>;
|
|
111
|
-
item?: Partial<ComponentProps<Tooltip.Item>>;
|
|
112
|
-
separator?: Partial<ComponentProps<Tooltip.Separator>>;
|
|
113
|
-
};
|
|
114
|
-
xAxis?: Partial<ComponentProps<Axis>>;
|
|
115
|
-
yAxis?: Partial<ComponentProps<Axis>>;
|
|
116
|
-
} = {};
|
|
117
|
-
|
|
118
|
-
export let renderContext: 'svg' | 'canvas' = 'svg';
|
|
119
|
-
|
|
120
|
-
/** Log initial render performance using `console.time` */
|
|
121
|
-
export let profile = false;
|
|
122
|
-
|
|
123
|
-
/** Enable debug mode */
|
|
124
|
-
export let debug = false;
|
|
125
|
-
|
|
126
|
-
$: allSeriesData = series
|
|
127
|
-
.flatMap((s) => s.data?.map((d) => ({ seriesKey: s.key, ...d })))
|
|
128
|
-
.filter((d) => d) as Array<TData & { stackData?: any }>;
|
|
129
|
-
|
|
130
|
-
$: chartData = (allSeriesData.length ? allSeriesData : chartDataArray(data)) as Array<
|
|
131
|
-
TData & { stackData?: any }
|
|
132
|
-
>;
|
|
95
|
+
import type {
|
|
96
|
+
SeriesData,
|
|
97
|
+
SimplifiedChartProps,
|
|
98
|
+
SimplifiedChartPropsObject,
|
|
99
|
+
SimplifiedChartSnippet,
|
|
100
|
+
} from './types.js';
|
|
101
|
+
import { createLegendProps, SeriesState } from './utils.svelte.js';
|
|
102
|
+
import { setTooltipMetaContext } from '../tooltip/tooltipMetaContext.js';
|
|
103
|
+
import { layerClass } from '../../utils/attributes.js';
|
|
104
|
+
import DefaultTooltip from './DefaultTooltip.svelte';
|
|
105
|
+
import ChartAnnotations from './ChartAnnotations.svelte';
|
|
106
|
+
|
|
107
|
+
let {
|
|
108
|
+
data = [],
|
|
109
|
+
x: xProp,
|
|
110
|
+
y: yProp,
|
|
111
|
+
xDomain,
|
|
112
|
+
radial = false,
|
|
113
|
+
series: seriesProp,
|
|
114
|
+
seriesLayout = 'overlap',
|
|
115
|
+
axis = true,
|
|
116
|
+
brush = false,
|
|
117
|
+
grid = true,
|
|
118
|
+
labels = false,
|
|
119
|
+
legend = false,
|
|
120
|
+
points = false,
|
|
121
|
+
rule = true,
|
|
122
|
+
onTooltipClick = () => {},
|
|
123
|
+
onPointClick,
|
|
124
|
+
props = {},
|
|
125
|
+
renderContext = 'svg',
|
|
126
|
+
profile = false,
|
|
127
|
+
debug = false,
|
|
128
|
+
xScale: xScaleProp,
|
|
129
|
+
tooltip = true,
|
|
130
|
+
children: childrenProp,
|
|
131
|
+
aboveContext,
|
|
132
|
+
belowContext,
|
|
133
|
+
belowMarks,
|
|
134
|
+
aboveMarks,
|
|
135
|
+
marks,
|
|
136
|
+
spline,
|
|
137
|
+
highlight = true,
|
|
138
|
+
annotations = [],
|
|
139
|
+
context = $bindable(),
|
|
140
|
+
...restProps
|
|
141
|
+
}: LineChartProps<TData> = $props();
|
|
142
|
+
|
|
143
|
+
const series = $derived(
|
|
144
|
+
seriesProp === undefined
|
|
145
|
+
? [{ key: 'default', value: yProp, color: 'var(--color-primary)' }]
|
|
146
|
+
: seriesProp
|
|
147
|
+
);
|
|
148
|
+
const seriesState = new SeriesState(() => series);
|
|
149
|
+
|
|
150
|
+
const chartData = $derived(
|
|
151
|
+
(seriesState.allSeriesData.length
|
|
152
|
+
? seriesState.allSeriesData
|
|
153
|
+
: chartDataArray(data)) as Array<TData>
|
|
154
|
+
);
|
|
133
155
|
|
|
134
156
|
// Default xScale based on first data's `x` value
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
let highlightSeriesKey: (typeof series)[number]['key'] | null = null;
|
|
139
|
-
|
|
140
|
-
function setHighlightSeriesKey(seriesKey: typeof highlightSeriesKey) {
|
|
141
|
-
highlightSeriesKey = seriesKey;
|
|
142
|
-
}
|
|
157
|
+
const xScale = $derived(
|
|
158
|
+
xScaleProp ?? (accessor(xProp)(chartData[0]) instanceof Date ? scaleTime() : scaleLinear())
|
|
159
|
+
);
|
|
143
160
|
|
|
144
|
-
|
|
145
|
-
const splineProps: ComponentProps<Spline> = {
|
|
161
|
+
function getSplineProps(s: SeriesData<TData, typeof Spline>, i: number) {
|
|
162
|
+
const splineProps: ComponentProps<typeof Spline> = {
|
|
146
163
|
data: s.data,
|
|
147
164
|
y: s.value ?? (s.data ? undefined : s.key),
|
|
148
165
|
stroke: s.color,
|
|
149
166
|
...props.spline,
|
|
150
167
|
...s.props,
|
|
151
168
|
class: cls(
|
|
169
|
+
layerClass('line-chart-line'),
|
|
152
170
|
'transition-opacity',
|
|
153
171
|
// Checking `visibleSeries.length > 1` fixes re-animated tweened areas on hover
|
|
154
|
-
visibleSeries.length > 1 &&
|
|
155
|
-
|
|
156
|
-
|
|
172
|
+
seriesState.visibleSeries.length > 1 &&
|
|
173
|
+
seriesState.highlightKey.current &&
|
|
174
|
+
seriesState.highlightKey.current !== s.key &&
|
|
157
175
|
'opacity-10',
|
|
158
176
|
props.spline?.class,
|
|
159
177
|
s.props?.class
|
|
@@ -161,10 +179,10 @@
|
|
|
161
179
|
};
|
|
162
180
|
|
|
163
181
|
return splineProps;
|
|
164
|
-
}
|
|
182
|
+
}
|
|
165
183
|
|
|
166
|
-
function getPointsProps(s:
|
|
167
|
-
const pointsProps: ComponentProps<Points> = {
|
|
184
|
+
function getPointsProps(s: SeriesData<TData, typeof Spline>, i: number) {
|
|
185
|
+
const pointsProps: ComponentProps<typeof Points> = {
|
|
168
186
|
data: s.data,
|
|
169
187
|
y: s.value ?? (s.data ? undefined : s.key),
|
|
170
188
|
fill: s.color,
|
|
@@ -172,7 +190,9 @@
|
|
|
172
190
|
...(typeof points === 'object' ? points : null),
|
|
173
191
|
class: cls(
|
|
174
192
|
'stroke-surface-200 transition-opacity',
|
|
175
|
-
|
|
193
|
+
seriesState.highlightKey.current &&
|
|
194
|
+
seriesState.highlightKey.current !== s.key &&
|
|
195
|
+
'opacity-10',
|
|
176
196
|
props.points?.class,
|
|
177
197
|
typeof points === 'object' && points.class
|
|
178
198
|
),
|
|
@@ -181,15 +201,17 @@
|
|
|
181
201
|
return pointsProps;
|
|
182
202
|
}
|
|
183
203
|
|
|
184
|
-
function getLabelsProps(s:
|
|
185
|
-
const labelsProps: ComponentProps<Labels
|
|
204
|
+
function getLabelsProps(s: SeriesData<TData, typeof Spline>, i: number) {
|
|
205
|
+
const labelsProps: ComponentProps<typeof Labels<TData>> = {
|
|
186
206
|
data: s.data,
|
|
187
207
|
y: s.value ?? (s.data ? undefined : s.key),
|
|
188
208
|
...props.labels,
|
|
189
209
|
...(typeof labels === 'object' ? labels : null),
|
|
190
210
|
class: cls(
|
|
191
211
|
'stroke-surface-200 transition-opacity',
|
|
192
|
-
|
|
212
|
+
seriesState.highlightKey.current &&
|
|
213
|
+
seriesState.highlightKey.current !== s.key &&
|
|
214
|
+
'opacity-10',
|
|
193
215
|
props.labels?.class,
|
|
194
216
|
typeof labels === 'object' && labels.class
|
|
195
217
|
),
|
|
@@ -198,16 +220,93 @@
|
|
|
198
220
|
return labelsProps;
|
|
199
221
|
}
|
|
200
222
|
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
223
|
+
const highlightPointsProps = $derived(
|
|
224
|
+
typeof props.highlight?.points === 'object' ? props.highlight.points : null
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
function getHighlightProps(
|
|
228
|
+
s: SeriesData<TData, typeof Spline>,
|
|
229
|
+
i: number
|
|
230
|
+
): ComponentProps<typeof Highlight> {
|
|
231
|
+
if (!context || !context.tooltip.data) return {};
|
|
232
|
+
const seriesTooltipData =
|
|
233
|
+
s.data && context.tooltip.data
|
|
234
|
+
? findRelatedData(s.data, context.tooltip.data, context.x)
|
|
235
|
+
: null;
|
|
236
|
+
|
|
237
|
+
return {
|
|
238
|
+
data: seriesTooltipData,
|
|
239
|
+
y: s.value ?? (s.data ? undefined : s.key),
|
|
240
|
+
lines: i === 0,
|
|
241
|
+
onPointClick: onPointClick
|
|
242
|
+
? (e, detail) => onPointClick(e, { ...detail, series: s })
|
|
243
|
+
: undefined,
|
|
244
|
+
onPointEnter: () => (seriesState.highlightKey.current = s.key),
|
|
245
|
+
onPointLeave: () => (seriesState.highlightKey.current = null),
|
|
246
|
+
...props.highlight,
|
|
247
|
+
points:
|
|
248
|
+
props.highlight?.points == false
|
|
249
|
+
? false
|
|
250
|
+
: {
|
|
251
|
+
...highlightPointsProps,
|
|
252
|
+
fill: s.color,
|
|
253
|
+
class: cls(
|
|
254
|
+
'transition-opacity',
|
|
255
|
+
seriesState.highlightKey.current &&
|
|
256
|
+
seriesState.highlightKey.current !== s.key &&
|
|
257
|
+
'opacity-10',
|
|
258
|
+
highlightPointsProps?.class
|
|
259
|
+
),
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function getLegendProps(): ComponentProps<typeof Legend> {
|
|
265
|
+
return createLegendProps({
|
|
266
|
+
seriesState,
|
|
267
|
+
props: {
|
|
268
|
+
...props.legend,
|
|
269
|
+
...(typeof legend === 'object' ? legend : null),
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function getGridProps(): ComponentProps<typeof Grid> {
|
|
275
|
+
return {
|
|
276
|
+
x: radial,
|
|
277
|
+
y: true,
|
|
278
|
+
...(typeof grid === 'object' ? grid : null),
|
|
279
|
+
...props.grid,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function getAxisProps(axisDirection?: 'x' | 'y'): ComponentProps<typeof Axis> {
|
|
284
|
+
if (axisDirection === 'y') {
|
|
285
|
+
return {
|
|
286
|
+
placement: radial ? 'radius' : 'left',
|
|
287
|
+
format: (value) => format(value, undefined, { variant: 'short' }),
|
|
288
|
+
...(typeof axis === 'object' ? axis : null),
|
|
289
|
+
...props.yAxis,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
placement: radial ? 'angle' : 'bottom',
|
|
294
|
+
format: (value) => format(value, undefined, { variant: 'short' }),
|
|
295
|
+
...(typeof axis === 'object' ? axis : null),
|
|
296
|
+
...props.xAxis,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function getRuleProps(): ComponentProps<typeof Rule> {
|
|
301
|
+
return {
|
|
302
|
+
x: 0,
|
|
303
|
+
y: 0,
|
|
304
|
+
...(typeof rule === 'object' ? rule : null),
|
|
305
|
+
...props.rule,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
209
308
|
|
|
210
|
-
|
|
309
|
+
const brushProps = $derived({ ...(typeof brush === 'object' ? brush : null), ...props.brush });
|
|
211
310
|
|
|
212
311
|
if (profile) {
|
|
213
312
|
console.time('LineChart render');
|
|
@@ -215,223 +314,179 @@
|
|
|
215
314
|
console.timeEnd('LineChart render');
|
|
216
315
|
});
|
|
217
316
|
}
|
|
317
|
+
|
|
318
|
+
setTooltipMetaContext({
|
|
319
|
+
type: 'line',
|
|
320
|
+
get visibleSeries() {
|
|
321
|
+
return seriesState.visibleSeries;
|
|
322
|
+
},
|
|
323
|
+
});
|
|
218
324
|
</script>
|
|
219
325
|
|
|
326
|
+
<!-- svelte-ignore ownership_invalid_binding -->
|
|
220
327
|
<Chart
|
|
328
|
+
bind:context
|
|
221
329
|
data={chartData}
|
|
222
|
-
{
|
|
330
|
+
x={xProp}
|
|
223
331
|
{xDomain}
|
|
224
332
|
{xScale}
|
|
225
|
-
y={
|
|
333
|
+
y={yProp ?? series.map((s) => s.value ?? s.key)}
|
|
226
334
|
yBaseline={0}
|
|
227
335
|
yNice
|
|
228
336
|
{radial}
|
|
229
337
|
padding={radial ? undefined : defaultChartPadding(axis, legend)}
|
|
230
|
-
{
|
|
231
|
-
tooltip={
|
|
338
|
+
{...restProps}
|
|
339
|
+
tooltip={tooltip === false
|
|
232
340
|
? false
|
|
233
341
|
: {
|
|
234
342
|
mode: 'bisect-x',
|
|
235
|
-
onclick:
|
|
343
|
+
onclick: onTooltipClick,
|
|
236
344
|
debug,
|
|
237
345
|
...props.tooltip?.context,
|
|
238
|
-
...$$props.tooltip,
|
|
239
346
|
}}
|
|
240
|
-
bind:tooltipContext
|
|
241
347
|
brush={brush && (brush === true || brush.mode == undefined || brush.mode === 'integrated')
|
|
242
348
|
? {
|
|
243
349
|
axis: 'x',
|
|
244
350
|
resetOnEnd: true,
|
|
245
351
|
xDomain,
|
|
246
352
|
...brushProps,
|
|
247
|
-
|
|
353
|
+
onBrushEnd: (e) => {
|
|
248
354
|
xDomain = e.xDomain;
|
|
249
|
-
brushProps.
|
|
355
|
+
brushProps.onBrushEnd?.(e);
|
|
250
356
|
},
|
|
251
357
|
}
|
|
252
358
|
: false}
|
|
253
|
-
let:x
|
|
254
|
-
let:xScale
|
|
255
|
-
let:y
|
|
256
|
-
let:yScale
|
|
257
|
-
let:c
|
|
258
|
-
let:cScale
|
|
259
|
-
let:width
|
|
260
|
-
let:height
|
|
261
|
-
let:padding
|
|
262
|
-
let:tooltip
|
|
263
359
|
>
|
|
264
|
-
{
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
360
|
+
{#snippet children({ context })}
|
|
361
|
+
{@const snippetProps = {
|
|
362
|
+
context,
|
|
363
|
+
series,
|
|
364
|
+
visibleSeries: seriesState.visibleSeries,
|
|
365
|
+
getLabelsProps,
|
|
366
|
+
getPointsProps,
|
|
367
|
+
getSplineProps,
|
|
368
|
+
getHighlightProps,
|
|
369
|
+
getLegendProps,
|
|
370
|
+
getGridProps,
|
|
371
|
+
getAxisProps,
|
|
372
|
+
getRuleProps,
|
|
373
|
+
highlightKey: seriesState.highlightKey.current,
|
|
374
|
+
setHighlightKey: seriesState.highlightKey.set,
|
|
375
|
+
}}
|
|
376
|
+
{#if childrenProp}
|
|
377
|
+
{@render childrenProp(snippetProps)}
|
|
378
|
+
{:else}
|
|
379
|
+
{@render belowContext?.(snippetProps)}
|
|
380
|
+
<!-- TODO: Always use `Svg` until `Pattern` supports `Canvas` (issue #307) -->
|
|
381
|
+
|
|
382
|
+
<Layer
|
|
383
|
+
type={renderContext}
|
|
384
|
+
{...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
|
|
385
|
+
center={radial}
|
|
386
|
+
{debug}
|
|
387
|
+
>
|
|
388
|
+
{#if typeof grid === 'function'}
|
|
389
|
+
{@render grid(snippetProps)}
|
|
390
|
+
{:else if grid}
|
|
391
|
+
<Grid {...getGridProps()} />
|
|
295
392
|
{/if}
|
|
296
|
-
</slot>
|
|
297
393
|
|
|
298
|
-
|
|
299
|
-
|
|
394
|
+
<ChartClipPath disabled={!brush}>
|
|
395
|
+
<ChartAnnotations
|
|
396
|
+
{annotations}
|
|
397
|
+
layer="below"
|
|
398
|
+
highlightKey={seriesState.highlightKey.current}
|
|
399
|
+
visibleSeries={seriesState.visibleSeries}
|
|
400
|
+
/>
|
|
401
|
+
|
|
402
|
+
{@render belowMarks?.(snippetProps)}
|
|
403
|
+
{#if marks}
|
|
404
|
+
{@render marks(snippetProps)}
|
|
405
|
+
{:else}
|
|
406
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
407
|
+
{#if typeof spline === 'function'}
|
|
408
|
+
{@render spline({ ...snippetProps, props: getSplineProps(s, i), seriesIndex: i })}
|
|
409
|
+
{:else}
|
|
410
|
+
<Spline {...getSplineProps(s, i)} />
|
|
411
|
+
{/if}
|
|
412
|
+
{/each}
|
|
413
|
+
{/if}
|
|
300
414
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
<Spline {...getSplineProps(s, i)} />
|
|
304
|
-
{/each}
|
|
305
|
-
</slot>
|
|
415
|
+
{@render aboveMarks?.(snippetProps)}
|
|
416
|
+
</ChartClipPath>
|
|
306
417
|
|
|
307
|
-
|
|
308
|
-
|
|
418
|
+
{#if typeof axis === 'function'}
|
|
419
|
+
{@render axis(snippetProps)}
|
|
309
420
|
|
|
310
|
-
|
|
311
|
-
|
|
421
|
+
{#if typeof rule === 'function'}
|
|
422
|
+
{@render rule(snippetProps)}
|
|
423
|
+
{:else if rule}
|
|
424
|
+
<Rule {...getRuleProps()} />
|
|
425
|
+
{/if}
|
|
426
|
+
{:else if axis}
|
|
312
427
|
{#if axis !== 'x'}
|
|
313
|
-
<Axis
|
|
314
|
-
placement={radial ? 'radius' : 'left'}
|
|
315
|
-
format={(value) => format(value, undefined, { variant: 'short' })}
|
|
316
|
-
{...typeof axis === 'object' ? axis : null}
|
|
317
|
-
{...props.yAxis}
|
|
318
|
-
/>
|
|
428
|
+
<Axis {...getAxisProps('y')} />
|
|
319
429
|
{/if}
|
|
320
430
|
|
|
321
431
|
{#if axis !== 'y'}
|
|
322
|
-
<Axis
|
|
323
|
-
placement={radial ? 'angle' : 'bottom'}
|
|
324
|
-
format={(value) => format(value, undefined, { variant: 'short' })}
|
|
325
|
-
{...typeof axis === 'object' ? axis : null}
|
|
326
|
-
{...props.xAxis}
|
|
327
|
-
/>
|
|
432
|
+
<Axis {...getAxisProps('x')} />
|
|
328
433
|
{/if}
|
|
329
434
|
|
|
330
|
-
{#if rule}
|
|
331
|
-
|
|
435
|
+
{#if typeof rule === 'function'}
|
|
436
|
+
{@render rule(snippetProps)}
|
|
437
|
+
{:else if rule}
|
|
438
|
+
<Rule {...getRuleProps()} />
|
|
332
439
|
{/if}
|
|
333
440
|
{/if}
|
|
334
|
-
</slot>
|
|
335
|
-
|
|
336
|
-
<!-- Use `full` to allow labels on edge to not be cropped (bleed into padding) -->
|
|
337
|
-
<ChartClipPath disabled={!brush} full>
|
|
338
|
-
{#if points}
|
|
339
|
-
{#each visibleSeries as s, i (s.key)}
|
|
340
|
-
<Points {...getPointsProps(s, i)} />
|
|
341
|
-
{/each}
|
|
342
|
-
{/if}
|
|
343
441
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
442
|
+
<!-- Use `full` to allow labels on edge to not be cropped (bleed into padding) -->
|
|
443
|
+
<ChartClipPath disabled={!brush} full>
|
|
444
|
+
{#if typeof points === 'function'}
|
|
445
|
+
{@render points(snippetProps)}
|
|
446
|
+
{:else if points}
|
|
447
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
448
|
+
<Points {...getPointsProps(s, i)} />
|
|
449
|
+
{/each}
|
|
450
|
+
{/if}
|
|
451
|
+
|
|
452
|
+
{#if typeof labels === 'function'}
|
|
453
|
+
{@render labels(snippetProps)}
|
|
454
|
+
{:else if labels}
|
|
455
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
456
|
+
<Labels {...getLabelsProps(s, i)} />
|
|
457
|
+
{/each}
|
|
458
|
+
{/if}
|
|
459
|
+
|
|
460
|
+
{#if typeof highlight === 'function'}
|
|
461
|
+
{@render highlight(snippetProps)}
|
|
462
|
+
{:else if highlight}
|
|
463
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
464
|
+
<Highlight {...getHighlightProps(s, i)} />
|
|
465
|
+
{/each}
|
|
466
|
+
{/if}
|
|
467
|
+
|
|
468
|
+
<ChartAnnotations
|
|
469
|
+
{annotations}
|
|
470
|
+
layer="above"
|
|
471
|
+
highlightKey={seriesState.highlightKey.current}
|
|
472
|
+
visibleSeries={seriesState.visibleSeries}
|
|
473
|
+
/>
|
|
474
|
+
</ChartClipPath>
|
|
475
|
+
</Layer>
|
|
476
|
+
|
|
477
|
+
{@render aboveContext?.(snippetProps)}
|
|
478
|
+
|
|
479
|
+
{#if typeof legend === 'function'}
|
|
480
|
+
{@render legend(snippetProps)}
|
|
481
|
+
{:else if legend}
|
|
482
|
+
<Legend {...getLegendProps()} />
|
|
483
|
+
{/if}
|
|
349
484
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
{@const highlightPointsProps =
|
|
355
|
-
typeof props.highlight?.points === 'object' ? props.highlight.points : null}
|
|
356
|
-
|
|
357
|
-
<Highlight
|
|
358
|
-
data={seriesTooltipData}
|
|
359
|
-
y={s.value ?? (s.data ? undefined : s.key)}
|
|
360
|
-
lines={i === 0}
|
|
361
|
-
onpointclick={onpointclick
|
|
362
|
-
? (e, detail) => onpointclick(e, { ...detail, series: s })
|
|
363
|
-
: undefined}
|
|
364
|
-
onpointenter={() => (highlightSeriesKey = s.key)}
|
|
365
|
-
onpointleave={() => (highlightSeriesKey = null)}
|
|
366
|
-
{...props.highlight}
|
|
367
|
-
points={props.highlight?.points == false
|
|
368
|
-
? false
|
|
369
|
-
: {
|
|
370
|
-
...highlightPointsProps,
|
|
371
|
-
fill: s.color,
|
|
372
|
-
class: cls(
|
|
373
|
-
'transition-opacity',
|
|
374
|
-
highlightSeriesKey && highlightSeriesKey !== s.key && 'opacity-10',
|
|
375
|
-
highlightPointsProps?.class
|
|
376
|
-
),
|
|
377
|
-
}}
|
|
378
|
-
/>
|
|
379
|
-
{/each}
|
|
380
|
-
</slot>
|
|
381
|
-
</ChartClipPath>
|
|
382
|
-
</svelte:component>
|
|
383
|
-
|
|
384
|
-
<slot name="aboveContext" {...slotProps} />
|
|
385
|
-
|
|
386
|
-
<slot name="legend" {...slotProps}>
|
|
387
|
-
{#if legend}
|
|
388
|
-
<Legend
|
|
389
|
-
scale={isDefaultSeries
|
|
390
|
-
? undefined
|
|
391
|
-
: scaleOrdinal(
|
|
392
|
-
series.map((s) => s.key),
|
|
393
|
-
series.map((s) => s.color)
|
|
394
|
-
)}
|
|
395
|
-
tickFormat={(key) => series.find((s) => s.key === key)?.label ?? key}
|
|
396
|
-
placement="bottom"
|
|
397
|
-
variant="swatches"
|
|
398
|
-
onclick={(e, item) => $selectedSeries.toggleSelected(item.value)}
|
|
399
|
-
onpointerenter={(e, item) => (highlightSeriesKey = item.value)}
|
|
400
|
-
onpointerleave={(e) => (highlightSeriesKey = null)}
|
|
401
|
-
{...props.legend}
|
|
402
|
-
{...typeof legend === 'object' ? legend : null}
|
|
403
|
-
classes={{
|
|
404
|
-
item: (item) =>
|
|
405
|
-
visibleSeries.length && !visibleSeries.some((s) => s.key === item.value)
|
|
406
|
-
? 'opacity-50'
|
|
407
|
-
: '',
|
|
408
|
-
...props.legend?.classes,
|
|
409
|
-
...(typeof legend === 'object' ? legend.classes : null),
|
|
410
|
-
}}
|
|
411
|
-
/>
|
|
485
|
+
{#if typeof tooltip === 'function'}
|
|
486
|
+
{@render tooltip(snippetProps)}
|
|
487
|
+
{:else if tooltip}
|
|
488
|
+
<DefaultTooltip tooltipProps={props.tooltip} {seriesState} canHaveTotal />
|
|
412
489
|
{/if}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
<slot name="tooltip" {...slotProps}>
|
|
416
|
-
<Tooltip.Root {...props.tooltip?.root} let:data>
|
|
417
|
-
<Tooltip.Header value={x(data)} {format} {...props.tooltip?.header} />
|
|
418
|
-
<Tooltip.List {...props.tooltip?.list}>
|
|
419
|
-
{#each visibleSeries as s}
|
|
420
|
-
{@const seriesTooltipData = s.data ? findRelatedData(s.data, data, x) : data}
|
|
421
|
-
{@const valueAccessor = accessor(s.value ?? (s.data ? asAny(y) : s.key))}
|
|
422
|
-
|
|
423
|
-
<Tooltip.Item
|
|
424
|
-
label={s.label ?? (s.key !== 'default' ? s.key : 'value')}
|
|
425
|
-
value={seriesTooltipData ? valueAccessor(seriesTooltipData) : null}
|
|
426
|
-
color={s.color}
|
|
427
|
-
{format}
|
|
428
|
-
onpointerenter={() => (highlightSeriesKey = s.key)}
|
|
429
|
-
onpointerleave={() => (highlightSeriesKey = null)}
|
|
430
|
-
{...props.tooltip?.item}
|
|
431
|
-
/>
|
|
432
|
-
{/each}
|
|
433
|
-
</Tooltip.List>
|
|
434
|
-
</Tooltip.Root>
|
|
435
|
-
</slot>
|
|
436
|
-
</slot>
|
|
490
|
+
{/if}
|
|
491
|
+
{/snippet}
|
|
437
492
|
</Chart>
|