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