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,27 +1,88 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
/**
|
|
3
|
+
* The additional snippet props passed to the various snippets belonging
|
|
4
|
+
* to the `AreaChart` component.
|
|
5
|
+
*/
|
|
6
|
+
export type AreaChartExtraSnippetProps<TData> = {
|
|
7
|
+
getAreaProps: (s: SeriesData<TData, typeof Area>, i: number) => ComponentProps<typeof Area>;
|
|
8
|
+
getLabelsProps: (
|
|
9
|
+
s: SeriesData<TData, typeof Area>,
|
|
10
|
+
i: number
|
|
11
|
+
) => ComponentProps<typeof Labels<TData>>;
|
|
12
|
+
getPointsProps: (s: SeriesData<TData, typeof Area>, i: number) => ComponentProps<typeof Points>;
|
|
13
|
+
getHighlightProps: (
|
|
14
|
+
s: SeriesData<TData, typeof Area>,
|
|
15
|
+
i: number
|
|
16
|
+
) => ComponentProps<typeof Highlight>;
|
|
17
|
+
getGridProps: () => ComponentProps<typeof Grid>;
|
|
18
|
+
getAxisProps: (axisDirection?: 'x' | 'y') => ComponentProps<typeof Axis>;
|
|
19
|
+
getRuleProps: () => ComponentProps<typeof Rule>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The accepted props via the `props` prop of the `AreaChart` component.
|
|
24
|
+
*/
|
|
25
|
+
export type AreaChartPropsObjProp = Pick<
|
|
26
|
+
SimplifiedChartPropsObject,
|
|
27
|
+
| 'area'
|
|
28
|
+
| 'brush'
|
|
29
|
+
| 'canvas'
|
|
30
|
+
| 'grid'
|
|
31
|
+
| 'highlight'
|
|
32
|
+
| 'labels'
|
|
33
|
+
| 'legend'
|
|
34
|
+
| 'line'
|
|
35
|
+
| 'points'
|
|
36
|
+
| 'rule'
|
|
37
|
+
| 'svg'
|
|
38
|
+
| 'tooltip'
|
|
39
|
+
| 'xAxis'
|
|
40
|
+
| 'yAxis'
|
|
41
|
+
>;
|
|
42
|
+
|
|
43
|
+
export type AreaChartProps<TData> = SimplifiedChartProps<
|
|
44
|
+
TData,
|
|
45
|
+
typeof Area,
|
|
46
|
+
AreaChartExtraSnippetProps<TData>
|
|
47
|
+
> & {
|
|
48
|
+
/**
|
|
49
|
+
* A callback function called when a point in the chart is clicked.
|
|
50
|
+
*
|
|
51
|
+
* @param e - the original event that triggered the `onPointClick`
|
|
52
|
+
* @param details - an object containing the highlighted point data and series data
|
|
53
|
+
*/
|
|
54
|
+
onPointClick?: (
|
|
55
|
+
e: MouseEvent,
|
|
56
|
+
details: { data: HighlightPointData; series: SeriesData<TData, typeof Area> }
|
|
57
|
+
) => void;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Additional props to be passed to the components rendered internally by the
|
|
61
|
+
* `AreaChart` component. This is useful for customizing the behavior of the individual
|
|
62
|
+
* components, without having to fully override them via a snippet.
|
|
63
|
+
*/
|
|
64
|
+
props?: AreaChartPropsObjProp;
|
|
65
|
+
};
|
|
66
|
+
</script>
|
|
67
|
+
|
|
1
68
|
<script lang="ts" generics="TData">
|
|
2
69
|
import { onMount, type ComponentProps } from 'svelte';
|
|
3
|
-
import { scaleLinear,
|
|
70
|
+
import { scaleLinear, scaleTime } from 'd3-scale';
|
|
4
71
|
import { stack, stackOffsetDiverging, stackOffsetExpand, stackOffsetNone } from 'd3-shape';
|
|
5
|
-
import { sum } from 'd3-array';
|
|
6
72
|
import { format } from '@layerstack/utils';
|
|
7
73
|
import { cls } from '@layerstack/tailwind';
|
|
8
|
-
import { selectionStore } from '@layerstack/svelte-stores';
|
|
9
74
|
|
|
10
75
|
import Area from '../Area.svelte';
|
|
11
76
|
import Axis from '../Axis.svelte';
|
|
12
|
-
import BrushContext from '../BrushContext.svelte';
|
|
13
|
-
import Canvas from '../layout/Canvas.svelte';
|
|
14
77
|
import Chart from '../Chart.svelte';
|
|
15
78
|
import ChartClipPath from '../ChartClipPath.svelte';
|
|
16
79
|
import Grid from '../Grid.svelte';
|
|
17
80
|
import Highlight, { type HighlightPointData } from '../Highlight.svelte';
|
|
18
81
|
import Labels from '../Labels.svelte';
|
|
82
|
+
import Layer from '../layout/Layer.svelte';
|
|
19
83
|
import Legend from '../Legend.svelte';
|
|
20
|
-
import Line from '../Line.svelte';
|
|
21
84
|
import Points from '../Points.svelte';
|
|
22
85
|
import Rule from '../Rule.svelte';
|
|
23
|
-
import Svg from '../layout/Svg.svelte';
|
|
24
|
-
import * as Tooltip from '../tooltip/index.js';
|
|
25
86
|
|
|
26
87
|
import {
|
|
27
88
|
accessor,
|
|
@@ -31,162 +92,151 @@
|
|
|
31
92
|
type Accessor,
|
|
32
93
|
} from '../../utils/common.js';
|
|
33
94
|
import { asAny } from '../../utils/types.js';
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
import Spline from '../Spline.svelte';
|
|
96
|
+
import type { SeriesData, SimplifiedChartProps, SimplifiedChartPropsObject } from './types.js';
|
|
97
|
+
import { createLegendProps, SeriesState } from './utils.svelte.js';
|
|
98
|
+
import { setTooltipMetaContext } from '../tooltip/tooltipMetaContext.js';
|
|
99
|
+
import DefaultTooltip from './DefaultTooltip.svelte';
|
|
100
|
+
import ChartAnnotations from './ChartAnnotations.svelte';
|
|
101
|
+
|
|
102
|
+
let {
|
|
103
|
+
data = [],
|
|
104
|
+
x,
|
|
105
|
+
y,
|
|
106
|
+
xDomain,
|
|
107
|
+
radial = false,
|
|
108
|
+
series: seriesProp,
|
|
109
|
+
seriesLayout = 'overlap',
|
|
110
|
+
axis = true,
|
|
111
|
+
brush = false,
|
|
112
|
+
grid = true,
|
|
113
|
+
labels = false,
|
|
114
|
+
legend = false,
|
|
115
|
+
points = false,
|
|
116
|
+
tooltip = true,
|
|
117
|
+
highlight = true,
|
|
118
|
+
annotations = [],
|
|
119
|
+
rule = true,
|
|
120
|
+
onTooltipClick = () => {},
|
|
121
|
+
onPointClick,
|
|
122
|
+
props = {},
|
|
123
|
+
renderContext = 'svg',
|
|
124
|
+
profile = false,
|
|
125
|
+
debug = false,
|
|
126
|
+
xScale: xScaleProp,
|
|
127
|
+
children: childrenProp,
|
|
128
|
+
aboveContext,
|
|
129
|
+
belowContext,
|
|
130
|
+
belowMarks,
|
|
131
|
+
aboveMarks,
|
|
132
|
+
marks,
|
|
133
|
+
context = $bindable(),
|
|
134
|
+
...restProps
|
|
135
|
+
}: AreaChartProps<TData> = $props();
|
|
136
|
+
|
|
137
|
+
const series = $derived(
|
|
138
|
+
seriesProp === undefined
|
|
139
|
+
? [{ key: 'default', value: y, color: 'var(--color-primary)' }]
|
|
140
|
+
: seriesProp
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const seriesState = new SeriesState(() => series);
|
|
144
|
+
|
|
145
|
+
const stackSeries = $derived(seriesLayout.startsWith('stack'));
|
|
146
|
+
|
|
147
|
+
const chartData = $derived.by(() => {
|
|
148
|
+
let _chartData = (
|
|
149
|
+
seriesState.allSeriesData.length ? seriesState.allSeriesData : chartDataArray(data)
|
|
150
|
+
) as Array<TData>;
|
|
151
|
+
if (stackSeries) {
|
|
152
|
+
const seriesKeys = seriesState.visibleSeries.map((s) => s.key);
|
|
153
|
+
const offset =
|
|
154
|
+
seriesLayout === 'stackExpand'
|
|
155
|
+
? stackOffsetExpand
|
|
156
|
+
: seriesLayout === 'stackDiverging'
|
|
157
|
+
? stackOffsetDiverging
|
|
158
|
+
: stackOffsetNone;
|
|
159
|
+
|
|
160
|
+
const stackData = stack()
|
|
161
|
+
.keys(seriesKeys)
|
|
162
|
+
.value((d, key) => {
|
|
163
|
+
const s = series.find((d) => d.key === key)!;
|
|
164
|
+
const value = accessor(s.value ?? y ?? s.key)(d as any);
|
|
165
|
+
return value;
|
|
166
|
+
})
|
|
167
|
+
.offset(offset)(_chartData as any[]);
|
|
168
|
+
|
|
169
|
+
// If series has data, add `stackData` to each data point
|
|
170
|
+
for (let [seriesIndex, s] of series.entries()) {
|
|
171
|
+
if (s.data) {
|
|
172
|
+
s.data = s.data.map((d, i) => {
|
|
173
|
+
return {
|
|
174
|
+
...d,
|
|
175
|
+
stackData: stackData[seriesIndex][i],
|
|
176
|
+
};
|
|
177
|
+
});
|
|
99
178
|
}
|
|
100
|
-
|
|
101
|
-
| undefined = undefined;
|
|
102
|
-
|
|
103
|
-
export let props: {
|
|
104
|
-
area?: Partial<ComponentProps<Area>>;
|
|
105
|
-
brush?: Partial<ComponentProps<BrushContext>>;
|
|
106
|
-
canvas?: Partial<ComponentProps<Canvas>>;
|
|
107
|
-
grid?: Partial<ComponentProps<Grid>>;
|
|
108
|
-
highlight?: Partial<ComponentProps<Highlight>>;
|
|
109
|
-
labels?: Partial<ComponentProps<Labels>>;
|
|
110
|
-
legend?: Partial<ComponentProps<Legend>>;
|
|
111
|
-
line?: Partial<ComponentProps<Line>>;
|
|
112
|
-
points?: Partial<ComponentProps<Points>>;
|
|
113
|
-
rule?: Partial<ComponentProps<Rule>>;
|
|
114
|
-
svg?: Partial<ComponentProps<Svg>>;
|
|
115
|
-
tooltip?: {
|
|
116
|
-
context?: Partial<ComponentProps<Tooltip.Context>>;
|
|
117
|
-
root?: Partial<ComponentProps<Tooltip.Root>>;
|
|
118
|
-
header?: Partial<ComponentProps<Tooltip.Header>>;
|
|
119
|
-
list?: Partial<ComponentProps<Tooltip.List>>;
|
|
120
|
-
item?: Partial<ComponentProps<Tooltip.Item>>;
|
|
121
|
-
separator?: Partial<ComponentProps<Tooltip.Separator>>;
|
|
122
|
-
};
|
|
123
|
-
xAxis?: Partial<ComponentProps<Axis>>;
|
|
124
|
-
yAxis?: Partial<ComponentProps<Axis>>;
|
|
125
|
-
} = {};
|
|
126
|
-
|
|
127
|
-
export let renderContext: 'svg' | 'canvas' = 'svg';
|
|
128
|
-
|
|
129
|
-
/** Log initial render performance using `console.time` */
|
|
130
|
-
export let profile = false;
|
|
131
|
-
|
|
132
|
-
/** Enable debug mode */
|
|
133
|
-
export let debug = false;
|
|
134
|
-
|
|
135
|
-
$: allSeriesData = visibleSeries
|
|
136
|
-
.flatMap((s) => s.data?.map((d) => ({ seriesKey: s.key, ...d })))
|
|
137
|
-
.filter((d) => d) as Array<TData & { stackData?: any }>;
|
|
179
|
+
}
|
|
138
180
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
181
|
+
// Add `stackData` to each data point
|
|
182
|
+
_chartData = _chartData.map((d, i) => {
|
|
183
|
+
return {
|
|
184
|
+
...d,
|
|
185
|
+
stackData: stackData.map((sd) => sd[i]),
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
}
|
|
142
189
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const offset =
|
|
146
|
-
seriesLayout === 'stackExpand'
|
|
147
|
-
? stackOffsetExpand
|
|
148
|
-
: seriesLayout === 'stackDiverging'
|
|
149
|
-
? stackOffsetDiverging
|
|
150
|
-
: stackOffsetNone;
|
|
151
|
-
|
|
152
|
-
const stackData = stack()
|
|
153
|
-
.keys(seriesKeys)
|
|
154
|
-
.value((d, key) => {
|
|
155
|
-
const s = series.find((d) => d.key === key)!;
|
|
156
|
-
return accessor(s.value ?? s.key)(d as any);
|
|
157
|
-
})
|
|
158
|
-
.offset(offset)(chartDataArray(data)) as any[];
|
|
159
|
-
|
|
160
|
-
chartData = chartData.map((d, i) => {
|
|
161
|
-
return {
|
|
162
|
-
...d,
|
|
163
|
-
stackData: stackData.map((sd) => sd[i]),
|
|
164
|
-
};
|
|
165
|
-
});
|
|
166
|
-
}
|
|
190
|
+
return _chartData;
|
|
191
|
+
});
|
|
167
192
|
|
|
168
193
|
// Default xScale based on first data's `x` value
|
|
169
|
-
|
|
170
|
-
|
|
194
|
+
const xScale = $derived(
|
|
195
|
+
xScaleProp ?? (accessor(x)(chartData[0]) instanceof Date ? scaleTime() : scaleLinear())
|
|
196
|
+
);
|
|
171
197
|
|
|
172
|
-
|
|
198
|
+
function isStackData(d: TData): d is TData & { stackData: any[] } {
|
|
199
|
+
return d && typeof d === 'object' && 'stackData' in d;
|
|
200
|
+
}
|
|
173
201
|
|
|
174
|
-
|
|
175
|
-
|
|
202
|
+
/**
|
|
203
|
+
* If series has data, return the stackData from series (enriched when setting up `chartData`)
|
|
204
|
+
*/
|
|
205
|
+
function getStackData(
|
|
206
|
+
s: SeriesData<TData, typeof Area>,
|
|
207
|
+
d: TData & { stackData: any[] },
|
|
208
|
+
i: number
|
|
209
|
+
) {
|
|
210
|
+
if (s.data) {
|
|
211
|
+
return d.stackData;
|
|
212
|
+
}
|
|
213
|
+
// TODO: Sometimes this returns `undefined` when toggling series visibility when legend overlaps chart container. Return empty array to be more defensive
|
|
214
|
+
return d.stackData[i] ?? [];
|
|
176
215
|
}
|
|
177
216
|
|
|
178
|
-
|
|
179
|
-
const lineProps = {
|
|
217
|
+
function getAreaProps(s: SeriesData<TData, typeof Area>, i: number): ComponentProps<typeof Area> {
|
|
218
|
+
const lineProps: ComponentProps<typeof Spline> = {
|
|
180
219
|
...props.line,
|
|
181
220
|
...(typeof props.area?.line === 'object' ? props.area.line : null),
|
|
182
221
|
...(typeof s.props?.line === 'object' ? s.props.line : null),
|
|
183
222
|
};
|
|
184
223
|
|
|
185
|
-
const
|
|
224
|
+
const highlightClass =
|
|
225
|
+
seriesState.visibleSeries.length > 1 &&
|
|
226
|
+
seriesState.highlightKey.current &&
|
|
227
|
+
seriesState.highlightKey.current !== s.key
|
|
228
|
+
? 'opacity-10'
|
|
229
|
+
: '';
|
|
230
|
+
|
|
231
|
+
return {
|
|
186
232
|
data: s.data,
|
|
187
|
-
y0: stackSeries
|
|
233
|
+
y0: stackSeries
|
|
234
|
+
? (d) => getStackData(s, d, i)[0]
|
|
235
|
+
: Array.isArray(s.value)
|
|
236
|
+
? s.value[0]
|
|
237
|
+
: undefined,
|
|
188
238
|
y1: stackSeries
|
|
189
|
-
? (d) => d
|
|
239
|
+
? (d) => getStackData(s, d, i)[1]
|
|
190
240
|
: Array.isArray(s.value)
|
|
191
241
|
? s.value[1]
|
|
192
242
|
: (s.value ?? (s.data ? undefined : s.key)),
|
|
@@ -197,35 +247,26 @@
|
|
|
197
247
|
class: cls(
|
|
198
248
|
'transition-opacity',
|
|
199
249
|
// Checking `visibleSeries.length > 1` fixes re-animated tweened areas on hover
|
|
200
|
-
|
|
201
|
-
highlightSeriesKey &&
|
|
202
|
-
highlightSeriesKey !== s.key &&
|
|
203
|
-
'opacity-10',
|
|
250
|
+
highlightClass,
|
|
204
251
|
props.area?.class,
|
|
205
252
|
s.props?.class
|
|
206
253
|
),
|
|
207
254
|
line: {
|
|
208
255
|
stroke: s.color,
|
|
209
256
|
...lineProps,
|
|
210
|
-
class: cls(
|
|
211
|
-
'transition-opacity',
|
|
212
|
-
visibleSeries.length > 1 &&
|
|
213
|
-
highlightSeriesKey &&
|
|
214
|
-
highlightSeriesKey !== s.key &&
|
|
215
|
-
'opacity-10',
|
|
216
|
-
lineProps.class
|
|
217
|
-
),
|
|
257
|
+
class: cls('transition-opacity', highlightClass, lineProps.class),
|
|
218
258
|
},
|
|
219
259
|
};
|
|
260
|
+
}
|
|
220
261
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
262
|
+
function getPointsProps(
|
|
263
|
+
s: SeriesData<TData, typeof Area>,
|
|
264
|
+
i: number
|
|
265
|
+
): ComponentProps<typeof Points> {
|
|
266
|
+
return {
|
|
226
267
|
data: s.data,
|
|
227
268
|
y: stackSeries
|
|
228
|
-
? (d) => d
|
|
269
|
+
? (d) => getStackData(s, d, i)[1]
|
|
229
270
|
: Array.isArray(s.value)
|
|
230
271
|
? s.value[1]
|
|
231
272
|
: (s.value ?? (s.data ? undefined : s.key)),
|
|
@@ -234,20 +275,23 @@
|
|
|
234
275
|
...(typeof points === 'object' ? points : null),
|
|
235
276
|
class: cls(
|
|
236
277
|
'stroke-surface-200 transition-opacity',
|
|
237
|
-
|
|
278
|
+
seriesState.highlightKey.current &&
|
|
279
|
+
seriesState.highlightKey.current !== s.key &&
|
|
280
|
+
'opacity-10',
|
|
238
281
|
props.points?.class,
|
|
239
282
|
typeof points === 'object' && points.class
|
|
240
283
|
),
|
|
241
284
|
};
|
|
242
|
-
|
|
243
|
-
return pointsProps;
|
|
244
285
|
}
|
|
245
286
|
|
|
246
|
-
function getLabelsProps(
|
|
247
|
-
|
|
287
|
+
function getLabelsProps(
|
|
288
|
+
s: SeriesData<TData, typeof Area>,
|
|
289
|
+
i: number
|
|
290
|
+
): ComponentProps<typeof Labels<TData>> {
|
|
291
|
+
return {
|
|
248
292
|
data: s.data,
|
|
249
293
|
y: stackSeries
|
|
250
|
-
? (d) => d
|
|
294
|
+
? (d) => (isStackData(d) ? getStackData(s, d, i)[1] : undefined)
|
|
251
295
|
: Array.isArray(s.value)
|
|
252
296
|
? s.value[1]
|
|
253
297
|
: (s.value ?? (s.data ? undefined : s.key)),
|
|
@@ -255,25 +299,74 @@
|
|
|
255
299
|
...(typeof labels === 'object' ? labels : null),
|
|
256
300
|
class: cls(
|
|
257
301
|
'stroke-surface-200 transition-opacity',
|
|
258
|
-
|
|
302
|
+
seriesState.highlightKey.current &&
|
|
303
|
+
seriesState.highlightKey.current !== s.key &&
|
|
304
|
+
'opacity-10',
|
|
259
305
|
props.labels?.class,
|
|
260
306
|
typeof labels === 'object' && labels.class
|
|
261
307
|
),
|
|
262
308
|
};
|
|
309
|
+
}
|
|
263
310
|
|
|
264
|
-
|
|
311
|
+
const brushProps = $derived({ ...(typeof brush === 'object' ? brush : null), ...props.brush });
|
|
312
|
+
|
|
313
|
+
function getHighlightProps(
|
|
314
|
+
s: SeriesData<TData, typeof Area>,
|
|
315
|
+
i: number
|
|
316
|
+
): ComponentProps<typeof Highlight> {
|
|
317
|
+
if (!context) return {};
|
|
318
|
+
const seriesTooltipData =
|
|
319
|
+
s.data && context.tooltip.data
|
|
320
|
+
? findRelatedData(s.data, context.tooltip.data, context.x)
|
|
321
|
+
: null;
|
|
322
|
+
const highlightPointsProps =
|
|
323
|
+
typeof props.highlight?.points === 'object' ? props.highlight.points : null;
|
|
324
|
+
|
|
325
|
+
return {
|
|
326
|
+
data: seriesTooltipData,
|
|
327
|
+
y: stackSeries ? (d) => getStackData(s, d, i)[1] : (s.value ?? (s.data ? undefined : s.key)),
|
|
328
|
+
lines: i == 0,
|
|
329
|
+
onPointClick: onPointClick
|
|
330
|
+
? (e, detail) => onPointClick(e, { ...detail, series: s })
|
|
331
|
+
: undefined,
|
|
332
|
+
onPointEnter: () => (seriesState.highlightKey.current = s.key),
|
|
333
|
+
onPointLeave: () => (seriesState.highlightKey.current = null),
|
|
334
|
+
...props.highlight,
|
|
335
|
+
points:
|
|
336
|
+
props.highlight?.points == false
|
|
337
|
+
? false
|
|
338
|
+
: {
|
|
339
|
+
...highlightPointsProps,
|
|
340
|
+
fill: s.color,
|
|
341
|
+
class: cls(
|
|
342
|
+
'transition-opacity',
|
|
343
|
+
seriesState.highlightKey.current &&
|
|
344
|
+
seriesState.highlightKey.current !== s.key &&
|
|
345
|
+
'opacity-10',
|
|
346
|
+
highlightPointsProps?.class
|
|
347
|
+
),
|
|
348
|
+
},
|
|
349
|
+
};
|
|
265
350
|
}
|
|
266
351
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
352
|
+
function getLegendProps(): ComponentProps<typeof Legend> {
|
|
353
|
+
return createLegendProps({
|
|
354
|
+
seriesState,
|
|
355
|
+
props: {
|
|
356
|
+
...props.legend,
|
|
357
|
+
...(typeof legend === 'object' ? legend : null),
|
|
358
|
+
},
|
|
359
|
+
});
|
|
360
|
+
}
|
|
275
361
|
|
|
276
|
-
|
|
362
|
+
function getGridProps(): ComponentProps<typeof Grid> {
|
|
363
|
+
return {
|
|
364
|
+
x: radial,
|
|
365
|
+
y: true,
|
|
366
|
+
...(typeof grid === 'object' ? grid : null),
|
|
367
|
+
...props.grid,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
277
370
|
|
|
278
371
|
if (profile) {
|
|
279
372
|
console.time('AreaChart render');
|
|
@@ -281,254 +374,212 @@
|
|
|
281
374
|
console.timeEnd('AreaChart render');
|
|
282
375
|
});
|
|
283
376
|
}
|
|
377
|
+
|
|
378
|
+
setTooltipMetaContext({
|
|
379
|
+
type: 'area',
|
|
380
|
+
get stackSeries() {
|
|
381
|
+
return stackSeries;
|
|
382
|
+
},
|
|
383
|
+
get visibleSeries() {
|
|
384
|
+
return seriesState.visibleSeries;
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
function resolveAccessor(acc: Accessor<TData> | undefined) {
|
|
389
|
+
if (stackSeries) {
|
|
390
|
+
return (d: TData) =>
|
|
391
|
+
isStackData(d) ? seriesState.visibleSeries.flatMap((s, i) => d.stackData[i]) : undefined;
|
|
392
|
+
}
|
|
393
|
+
if (acc) return acc;
|
|
394
|
+
return seriesState.visibleSeries.map((s) => s.value ?? s.key);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function getAxisProps(axisDirection?: 'x' | 'y'): ComponentProps<typeof Axis> {
|
|
398
|
+
if (axisDirection === 'y') {
|
|
399
|
+
return {
|
|
400
|
+
placement: radial ? 'radius' : 'left',
|
|
401
|
+
format:
|
|
402
|
+
seriesLayout === 'stackExpand' ? (value) => format(value, 'percentRound') : undefined,
|
|
403
|
+
...(typeof axis === 'object' ? axis : null),
|
|
404
|
+
...props.yAxis,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return {
|
|
409
|
+
placement: radial ? 'angle' : 'bottom',
|
|
410
|
+
...(typeof axis === 'object' ? axis : null),
|
|
411
|
+
...props.xAxis,
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function getRuleProps(): ComponentProps<typeof Rule> {
|
|
416
|
+
return {
|
|
417
|
+
x: 0,
|
|
418
|
+
y: 0,
|
|
419
|
+
...(typeof rule === 'object' ? rule : null),
|
|
420
|
+
...props.rule,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
284
423
|
</script>
|
|
285
424
|
|
|
425
|
+
<!-- svelte-ignore ownership_invalid_binding -->
|
|
286
426
|
<Chart
|
|
427
|
+
bind:context
|
|
287
428
|
data={chartData}
|
|
288
429
|
{x}
|
|
289
430
|
{xDomain}
|
|
290
431
|
{xScale}
|
|
291
|
-
y={y
|
|
292
|
-
(stackSeries
|
|
293
|
-
? (d) => visibleSeries.flatMap((s, i) => d.stackData[i])
|
|
294
|
-
: visibleSeries.map((s) => s.value ?? s.key))}
|
|
432
|
+
y={resolveAccessor(y)}
|
|
295
433
|
yBaseline={0}
|
|
296
434
|
yNice
|
|
297
435
|
{radial}
|
|
298
436
|
padding={radial ? undefined : defaultChartPadding(axis, legend)}
|
|
299
|
-
{
|
|
300
|
-
tooltip={
|
|
437
|
+
{...restProps}
|
|
438
|
+
tooltip={tooltip === false
|
|
301
439
|
? false
|
|
302
440
|
: {
|
|
303
441
|
mode: 'bisect-x',
|
|
304
|
-
onclick:
|
|
442
|
+
onclick: onTooltipClick,
|
|
305
443
|
debug,
|
|
306
444
|
...props.tooltip?.context,
|
|
307
|
-
...$$props.tooltip,
|
|
308
445
|
}}
|
|
309
|
-
bind:tooltipContext
|
|
310
446
|
brush={brush && (brush === true || brush.mode == undefined || brush.mode === 'integrated')
|
|
311
447
|
? {
|
|
312
448
|
axis: 'x',
|
|
313
449
|
resetOnEnd: true,
|
|
314
450
|
xDomain,
|
|
315
451
|
...brushProps,
|
|
316
|
-
|
|
452
|
+
onBrushEnd: (e) => {
|
|
317
453
|
xDomain = e.xDomain;
|
|
318
|
-
brushProps.
|
|
454
|
+
brushProps.onBrushEnd?.(e);
|
|
319
455
|
},
|
|
320
456
|
}
|
|
321
457
|
: false}
|
|
322
|
-
let:x
|
|
323
|
-
let:xScale
|
|
324
|
-
let:y
|
|
325
|
-
let:yScale
|
|
326
|
-
let:c
|
|
327
|
-
let:cScale
|
|
328
|
-
let:width
|
|
329
|
-
let:height
|
|
330
|
-
let:padding
|
|
331
|
-
let:tooltip
|
|
332
458
|
>
|
|
333
|
-
{
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
<Grid x={radial} y {...typeof grid === 'object' ? grid : null} {...props.grid} />
|
|
459
|
+
{#snippet children({ context })}
|
|
460
|
+
{@const snippetProps = {
|
|
461
|
+
context,
|
|
462
|
+
series,
|
|
463
|
+
visibleSeries: seriesState.visibleSeries,
|
|
464
|
+
getAreaProps,
|
|
465
|
+
getLabelsProps,
|
|
466
|
+
getPointsProps,
|
|
467
|
+
getHighlightProps,
|
|
468
|
+
getLegendProps,
|
|
469
|
+
getGridProps,
|
|
470
|
+
getAxisProps,
|
|
471
|
+
getRuleProps,
|
|
472
|
+
highlightKey: seriesState.highlightKey.current,
|
|
473
|
+
setHighlightKey: seriesState.highlightKey.set,
|
|
474
|
+
}}
|
|
475
|
+
|
|
476
|
+
{#if childrenProp}
|
|
477
|
+
{@render childrenProp(snippetProps)}
|
|
478
|
+
{:else}
|
|
479
|
+
{@render belowContext?.(snippetProps)}
|
|
480
|
+
<Layer
|
|
481
|
+
type={renderContext}
|
|
482
|
+
{...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
|
|
483
|
+
center={radial}
|
|
484
|
+
{debug}
|
|
485
|
+
>
|
|
486
|
+
{#if typeof grid === 'function'}
|
|
487
|
+
{@render grid(snippetProps)}
|
|
488
|
+
{:else if grid}
|
|
489
|
+
<Grid {...getGridProps()} />
|
|
365
490
|
{/if}
|
|
366
|
-
</slot>
|
|
367
|
-
|
|
368
|
-
<ChartClipPath disabled={!brush}>
|
|
369
|
-
<slot name="belowMarks" {...slotProps} />
|
|
370
|
-
|
|
371
|
-
<slot name="marks" {...slotProps}>
|
|
372
|
-
{#each visibleSeries as s, i (s.key)}
|
|
373
|
-
<Area {...getAreaProps(s, i)} />
|
|
374
|
-
{/each}
|
|
375
|
-
</slot>
|
|
376
|
-
</ChartClipPath>
|
|
377
|
-
|
|
378
|
-
<slot name="aboveMarks" {...slotProps} />
|
|
379
491
|
|
|
380
|
-
|
|
381
|
-
|
|
492
|
+
<ChartClipPath disabled={!brush}>
|
|
493
|
+
<ChartAnnotations
|
|
494
|
+
{annotations}
|
|
495
|
+
layer="below"
|
|
496
|
+
highlightKey={seriesState.highlightKey.current}
|
|
497
|
+
visibleSeries={seriesState.visibleSeries}
|
|
498
|
+
/>
|
|
499
|
+
|
|
500
|
+
{@render belowMarks?.(snippetProps)}
|
|
501
|
+
|
|
502
|
+
{#if marks}
|
|
503
|
+
{@render marks(snippetProps)}
|
|
504
|
+
{:else}
|
|
505
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
506
|
+
<Area {...getAreaProps(s, i)} />
|
|
507
|
+
{/each}
|
|
508
|
+
{/if}
|
|
509
|
+
</ChartClipPath>
|
|
510
|
+
|
|
511
|
+
{@render aboveMarks?.(snippetProps)}
|
|
512
|
+
{#if typeof axis === 'function'}
|
|
513
|
+
{@render axis(snippetProps)}
|
|
514
|
+
{#if typeof rule === 'function'}
|
|
515
|
+
{@render rule(snippetProps)}
|
|
516
|
+
{:else if rule}
|
|
517
|
+
<Rule {...getRuleProps()} />
|
|
518
|
+
{/if}
|
|
519
|
+
{:else if axis}
|
|
382
520
|
{#if axis !== 'x'}
|
|
383
|
-
<Axis
|
|
384
|
-
placement={radial ? 'radius' : 'left'}
|
|
385
|
-
format={(value) => {
|
|
386
|
-
if (seriesLayout === 'stackExpand') {
|
|
387
|
-
return format(value, 'percentRound');
|
|
388
|
-
} else {
|
|
389
|
-
return format(value, undefined, { variant: 'short' });
|
|
390
|
-
}
|
|
391
|
-
}}
|
|
392
|
-
{...typeof axis === 'object' ? axis : null}
|
|
393
|
-
{...props.yAxis}
|
|
394
|
-
/>
|
|
521
|
+
<Axis {...getAxisProps('y')} />
|
|
395
522
|
{/if}
|
|
396
523
|
|
|
397
524
|
{#if axis !== 'y'}
|
|
398
|
-
<Axis
|
|
399
|
-
placement={radial ? 'angle' : 'bottom'}
|
|
400
|
-
format={(value) => format(value, undefined, { variant: 'short' })}
|
|
401
|
-
{...typeof axis === 'object' ? axis : null}
|
|
402
|
-
{...props.xAxis}
|
|
403
|
-
/>
|
|
525
|
+
<Axis {...getAxisProps('x')} />
|
|
404
526
|
{/if}
|
|
405
527
|
|
|
406
|
-
{#if rule}
|
|
407
|
-
|
|
528
|
+
{#if typeof rule === 'function'}
|
|
529
|
+
{@render rule(snippetProps)}
|
|
530
|
+
{:else if rule}
|
|
531
|
+
<Rule {...getRuleProps()} />
|
|
408
532
|
{/if}
|
|
409
533
|
{/if}
|
|
410
|
-
</slot>
|
|
411
|
-
|
|
412
|
-
<!-- Use `full` to allow labels on edge to not be cropped (bleed into padding) -->
|
|
413
|
-
<ChartClipPath disabled={!brush} full>
|
|
414
|
-
{#if points}
|
|
415
|
-
{#each visibleSeries as s, i (s.key)}
|
|
416
|
-
<Points {...getPointsProps(s, i)} />
|
|
417
|
-
{/each}
|
|
418
|
-
{/if}
|
|
419
534
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
highlightSeriesKey && highlightSeriesKey !== s.key && 'opacity-10',
|
|
445
|
-
highlightPointsProps?.class
|
|
446
|
-
),
|
|
447
|
-
}}
|
|
448
|
-
/>
|
|
449
|
-
{/each}
|
|
450
|
-
</slot>
|
|
451
|
-
|
|
452
|
-
{#if labels}
|
|
453
|
-
{#each visibleSeries as s, i (s.key)}
|
|
454
|
-
<Labels {...getLabelsProps(s, i)} />
|
|
455
|
-
{/each}
|
|
456
|
-
{/if}
|
|
457
|
-
</ChartClipPath>
|
|
458
|
-
</svelte:component>
|
|
459
|
-
|
|
460
|
-
<slot name="aboveContext" {...slotProps} />
|
|
461
|
-
|
|
462
|
-
<slot name="legend" {...slotProps}>
|
|
463
|
-
{#if legend}
|
|
464
|
-
<Legend
|
|
465
|
-
scale={isDefaultSeries
|
|
466
|
-
? undefined
|
|
467
|
-
: scaleOrdinal(
|
|
468
|
-
series.map((s) => s.key),
|
|
469
|
-
series.map((s) => s.color)
|
|
470
|
-
)}
|
|
471
|
-
tickFormat={(key) => series.find((s) => s.key === key)?.label ?? key}
|
|
472
|
-
placement="bottom"
|
|
473
|
-
variant="swatches"
|
|
474
|
-
onclick={(e, item) => $selectedSeries.toggleSelected(item.value)}
|
|
475
|
-
onpointerenter={(e, item) => (highlightSeriesKey = item.value)}
|
|
476
|
-
onpointerleave={(e) => (highlightSeriesKey = null)}
|
|
477
|
-
{...props.legend}
|
|
478
|
-
{...typeof legend === 'object' ? legend : null}
|
|
479
|
-
classes={{
|
|
480
|
-
item: (item) =>
|
|
481
|
-
visibleSeries.length && !visibleSeries.some((s) => s.key === item.value)
|
|
482
|
-
? 'opacity-50'
|
|
483
|
-
: '',
|
|
484
|
-
...props.legend?.classes,
|
|
485
|
-
...(typeof legend === 'object' ? legend.classes : null),
|
|
486
|
-
}}
|
|
487
|
-
/>
|
|
488
|
-
{/if}
|
|
489
|
-
</slot>
|
|
490
|
-
|
|
491
|
-
<slot name="tooltip" {...slotProps}>
|
|
492
|
-
<Tooltip.Root {...props.tooltip?.root} let:data>
|
|
493
|
-
<Tooltip.Header value={x(data)} {format} {...props.tooltip?.header} />
|
|
494
|
-
|
|
495
|
-
<Tooltip.List {...props.tooltip?.list}>
|
|
496
|
-
<!-- Reverse series order so tooltip items match stacks -->
|
|
497
|
-
{@const seriesItems = stackSeries ? [...visibleSeries].reverse() : visibleSeries}
|
|
498
|
-
{#each seriesItems as s}
|
|
499
|
-
{@const seriesTooltipData = s.data ? findRelatedData(s.data, data, x) : data}
|
|
500
|
-
{@const valueAccessor = accessor(s.value ?? (s.data ? asAny(y) : s.key))}
|
|
501
|
-
|
|
502
|
-
<Tooltip.Item
|
|
503
|
-
label={s.label ?? (s.key !== 'default' ? s.key : 'value')}
|
|
504
|
-
value={seriesTooltipData ? valueAccessor(seriesTooltipData) : null}
|
|
505
|
-
color={s.color}
|
|
506
|
-
{format}
|
|
507
|
-
valueAlign="right"
|
|
508
|
-
onpointerenter={() => (highlightSeriesKey = s.key)}
|
|
509
|
-
onpointerleave={() => (highlightSeriesKey = null)}
|
|
510
|
-
{...props.tooltip?.item}
|
|
511
|
-
/>
|
|
512
|
-
{/each}
|
|
513
|
-
|
|
514
|
-
{#if stackSeries && visibleSeries.length > 1}
|
|
515
|
-
<Tooltip.Separator {...props.tooltip?.separator} />
|
|
516
|
-
|
|
517
|
-
<Tooltip.Item
|
|
518
|
-
label="total"
|
|
519
|
-
value={sum(visibleSeries, (s) => {
|
|
520
|
-
const seriesTooltipData = s.data ? s.data.find((d) => x(d) === x(data)) : data;
|
|
521
|
-
const valueAccessor = accessor(s.value ?? (s.data ? asAny(y) : s.key));
|
|
522
|
-
|
|
523
|
-
return valueAccessor(seriesTooltipData);
|
|
524
|
-
})}
|
|
525
|
-
format="integer"
|
|
526
|
-
valueAlign="right"
|
|
527
|
-
{...props.tooltip?.root}
|
|
528
|
-
/>
|
|
535
|
+
<!-- Use `full` to allow labels on edge to not be cropped (bleed into padding) -->
|
|
536
|
+
<ChartClipPath disabled={!brush} full>
|
|
537
|
+
{#if typeof points === 'function'}
|
|
538
|
+
{@render points(snippetProps)}
|
|
539
|
+
{:else if points}
|
|
540
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
541
|
+
<Points {...getPointsProps(s, i)} />
|
|
542
|
+
{/each}
|
|
543
|
+
{/if}
|
|
544
|
+
|
|
545
|
+
{#if typeof highlight === 'function'}
|
|
546
|
+
{@render highlight(snippetProps)}
|
|
547
|
+
{:else if highlight}
|
|
548
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
549
|
+
<Highlight {...getHighlightProps(s, i)} />
|
|
550
|
+
{/each}
|
|
551
|
+
{/if}
|
|
552
|
+
|
|
553
|
+
{#if typeof labels === 'function'}
|
|
554
|
+
{@render labels(snippetProps)}
|
|
555
|
+
{:else if labels}
|
|
556
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
557
|
+
<Labels {...getLabelsProps(s, i)} />
|
|
558
|
+
{/each}
|
|
529
559
|
{/if}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
560
|
+
|
|
561
|
+
<ChartAnnotations
|
|
562
|
+
{annotations}
|
|
563
|
+
layer="above"
|
|
564
|
+
highlightKey={seriesState.highlightKey.current}
|
|
565
|
+
visibleSeries={seriesState.visibleSeries}
|
|
566
|
+
/>
|
|
567
|
+
</ChartClipPath>
|
|
568
|
+
</Layer>
|
|
569
|
+
|
|
570
|
+
{@render aboveContext?.(snippetProps)}
|
|
571
|
+
|
|
572
|
+
{#if typeof legend === 'function'}
|
|
573
|
+
{@render legend(snippetProps)}
|
|
574
|
+
{:else if legend}
|
|
575
|
+
<Legend {...getLegendProps()} />
|
|
576
|
+
{/if}
|
|
577
|
+
|
|
578
|
+
{#if typeof tooltip === 'function'}
|
|
579
|
+
{@render tooltip(snippetProps)}
|
|
580
|
+
{:else if tooltip}
|
|
581
|
+
<DefaultTooltip tooltipProps={props.tooltip} {seriesState} canHaveTotal={stackSeries} />
|
|
582
|
+
{/if}
|
|
583
|
+
{/if}
|
|
584
|
+
{/snippet}
|
|
534
585
|
</Chart>
|