layerchart 2.0.0-next.0 → 2.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/movable.d.ts +28 -0
- package/dist/actions/movable.js +91 -0
- package/dist/components/AnnotationLine.svelte +155 -0
- package/dist/components/AnnotationLine.svelte.d.ts +28 -0
- package/dist/components/AnnotationPoint.svelte +121 -0
- package/dist/components/AnnotationPoint.svelte.d.ts +32 -0
- package/dist/components/AnnotationRange.svelte +147 -0
- package/dist/components/AnnotationRange.svelte.d.ts +40 -0
- package/dist/components/Arc.svelte +344 -151
- package/dist/components/Arc.svelte.d.ts +138 -0
- package/dist/components/Area.svelte +165 -149
- package/dist/components/Area.svelte.d.ts +45 -0
- package/dist/components/Axis.svelte +287 -174
- package/dist/components/Axis.svelte.d.ts +116 -0
- package/dist/components/Bar.svelte +163 -107
- package/dist/components/Bar.svelte.d.ts +48 -0
- package/dist/components/Bars.svelte +54 -68
- package/dist/components/Bars.svelte.d.ts +27 -0
- package/dist/components/Blur.svelte +31 -7
- package/dist/components/Blur.svelte.d.ts +23 -21
- package/dist/components/Bounds.svelte +49 -19
- package/dist/components/Bounds.svelte.d.ts +24 -50
- package/dist/components/BrushContext.svelte +296 -168
- package/dist/components/BrushContext.svelte.d.ts +97 -65
- package/dist/components/Calendar.svelte +116 -59
- package/dist/components/Calendar.svelte.d.ts +50 -31
- package/dist/components/Chart.svelte +1289 -398
- package/dist/components/Chart.svelte.d.ts +535 -410
- package/dist/components/ChartClipPath.svelte +37 -15
- package/dist/components/ChartClipPath.svelte.d.ts +21 -19
- package/dist/components/Circle.svelte +124 -85
- package/dist/components/Circle.svelte.d.ts +52 -0
- package/dist/components/CircleClipPath.svelte +76 -16
- package/dist/components/CircleClipPath.svelte.d.ts +46 -0
- package/dist/components/ClipPath.svelte +60 -15
- package/dist/components/ClipPath.svelte.d.ts +40 -27
- package/dist/components/ColorRamp.svelte +75 -9
- package/dist/components/ColorRamp.svelte.d.ts +37 -19
- package/dist/components/ComputedStyles.svelte +17 -5
- package/dist/components/ComputedStyles.svelte.d.ts +11 -19
- package/dist/components/Connector.svelte +149 -0
- package/dist/components/Connector.svelte.d.ts +51 -0
- package/dist/components/Dagre.svelte +211 -122
- package/dist/components/Dagre.svelte.d.ts +119 -56
- package/dist/components/ForceSimulation.svelte +215 -90
- package/dist/components/ForceSimulation.svelte.d.ts +82 -35
- package/dist/components/Frame.svelte +33 -13
- package/dist/components/Frame.svelte.d.ts +13 -17
- package/dist/components/GeoCircle.svelte +29 -16
- package/dist/components/GeoCircle.svelte.d.ts +22 -24
- package/dist/components/GeoContext.svelte +113 -72
- package/dist/components/GeoContext.svelte.d.ts +49 -41
- package/dist/components/GeoEdgeFade.svelte +47 -12
- package/dist/components/GeoEdgeFade.svelte.d.ts +17 -19
- package/dist/components/GeoPath.svelte +157 -127
- package/dist/components/GeoPath.svelte.d.ts +48 -36
- package/dist/components/GeoPoint.svelte +52 -20
- package/dist/components/GeoPoint.svelte.d.ts +25 -22
- package/dist/components/GeoSpline.svelte +75 -26
- package/dist/components/GeoSpline.svelte.d.ts +29 -20
- package/dist/components/GeoTile.svelte +100 -49
- package/dist/components/GeoTile.svelte.d.ts +38 -23
- package/dist/components/GeoVisible.svelte +17 -9
- package/dist/components/GeoVisible.svelte.d.ts +10 -18
- package/dist/components/Graticule.svelte +28 -13
- package/dist/components/Graticule.svelte.d.ts +11 -52
- package/dist/components/Grid.svelte +226 -114
- package/dist/components/Grid.svelte.d.ts +70 -0
- package/dist/components/Group.svelte +132 -105
- package/dist/components/Group.svelte.d.ts +53 -0
- package/dist/components/Highlight.svelte +409 -307
- package/dist/components/Highlight.svelte.d.ts +107 -0
- package/dist/components/Hull.svelte +96 -45
- package/dist/components/Hull.svelte.d.ts +40 -30
- package/dist/components/Labels.svelte +125 -46
- package/dist/components/Labels.svelte.d.ts +70 -27
- package/dist/components/Legend.svelte +374 -190
- package/dist/components/Legend.svelte.d.ts +95 -44
- package/dist/components/Line.svelte +163 -125
- package/dist/components/Line.svelte.d.ts +75 -0
- package/dist/components/LinearGradient.svelte +153 -78
- package/dist/components/LinearGradient.svelte.d.ts +66 -31
- package/dist/components/Link.svelte +160 -104
- package/dist/components/Link.svelte.d.ts +54 -0
- package/dist/components/Marker.svelte +100 -39
- package/dist/components/Marker.svelte.d.ts +59 -27
- package/dist/components/MarkerWrapper.svelte +35 -0
- package/dist/components/MarkerWrapper.svelte.d.ts +18 -0
- package/dist/components/MonthPath.svelte +65 -20
- package/dist/components/MonthPath.svelte.d.ts +23 -17
- package/dist/components/MotionPath.svelte +80 -24
- package/dist/components/MotionPath.svelte.d.ts +46 -27
- package/dist/components/Pack.svelte +53 -17
- package/dist/components/Pack.svelte.d.ts +42 -21
- package/dist/components/Partition.svelte +64 -22
- package/dist/components/Partition.svelte.d.ts +49 -26
- package/dist/components/Pattern.svelte +297 -11
- package/dist/components/Pattern.svelte.d.ts +103 -19
- package/dist/components/Pie.svelte +122 -76
- package/dist/components/Pie.svelte.d.ts +65 -51
- package/dist/components/Point.svelte +20 -9
- package/dist/components/Point.svelte.d.ts +16 -20
- package/dist/components/Points.svelte +148 -137
- package/dist/components/Points.svelte.d.ts +45 -34
- package/dist/components/RadialGradient.svelte +143 -70
- package/dist/components/RadialGradient.svelte.d.ts +69 -31
- package/dist/components/Rect.svelte +121 -102
- package/dist/components/Rect.svelte.d.ts +36 -0
- package/dist/components/RectClipPath.svelte +82 -18
- package/dist/components/RectClipPath.svelte.d.ts +55 -0
- package/dist/components/Rule.svelte +105 -62
- package/dist/components/Rule.svelte.d.ts +40 -19
- package/dist/components/Sankey.svelte +132 -55
- package/dist/components/Sankey.svelte.d.ts +61 -31
- package/dist/components/Spline.svelte +281 -218
- package/dist/components/Spline.svelte.d.ts +95 -0
- package/dist/components/Text.svelte +437 -176
- package/dist/components/Text.svelte.d.ts +130 -0
- package/dist/components/Threshold.svelte +48 -16
- package/dist/components/Threshold.svelte.d.ts +29 -31
- package/dist/components/TileImage.svelte +103 -30
- package/dist/components/TileImage.svelte.d.ts +48 -23
- package/dist/components/TransformContext.svelte +365 -171
- package/dist/components/TransformControls.svelte +50 -26
- package/dist/components/TransformControls.svelte.d.ts +27 -19
- package/dist/components/Tree.svelte +74 -33
- package/dist/components/Tree.svelte.d.ts +42 -30
- package/dist/components/Treemap.svelte +119 -42
- package/dist/components/Treemap.svelte.d.ts +75 -27
- package/dist/components/Voronoi.svelte +106 -75
- package/dist/components/Voronoi.svelte.d.ts +40 -41
- package/dist/components/charts/ArcChart.svelte +464 -0
- package/dist/components/charts/ArcChart.svelte.d.ts +90 -0
- package/dist/components/charts/AreaChart.svelte +450 -393
- package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
- package/dist/components/charts/BarChart.svelte +454 -389
- package/dist/components/charts/BarChart.svelte.d.ts +76 -0
- package/dist/components/charts/ChartAnnotations.svelte +37 -0
- package/dist/components/charts/ChartAnnotations.svelte.d.ts +10 -0
- package/dist/components/charts/DefaultTooltip.svelte +60 -0
- package/dist/components/charts/DefaultTooltip.svelte.d.ts +10 -0
- package/dist/components/charts/LineChart.svelte +369 -314
- package/dist/components/charts/LineChart.svelte.d.ts +53 -0
- package/dist/components/charts/PieChart.svelte +458 -316
- package/dist/components/charts/PieChart.svelte.d.ts +137 -353
- package/dist/components/charts/ScatterChart.svelte +334 -296
- package/dist/components/charts/ScatterChart.svelte.d.ts +39 -0
- package/dist/components/charts/index.d.ts +8 -0
- package/dist/components/charts/index.js +7 -0
- package/dist/components/charts/types.d.ts +253 -0
- package/dist/components/charts/utils.svelte.d.ts +30 -0
- package/dist/components/charts/utils.svelte.js +55 -0
- package/dist/components/index.d.ts +76 -4
- package/dist/components/index.js +76 -5
- package/dist/components/layout/Canvas.svelte +321 -155
- package/dist/components/layout/Canvas.svelte.d.ts +104 -55
- package/dist/components/layout/Html.svelte +82 -42
- package/dist/components/layout/Html.svelte.d.ts +39 -28
- package/dist/components/layout/Layer.svelte +39 -0
- package/dist/components/layout/Layer.svelte.d.ts +17 -0
- package/dist/components/layout/Svg.svelte +122 -70
- package/dist/components/layout/Svg.svelte.d.ts +53 -34
- package/dist/components/layout/WebGL.svelte +135 -0
- package/dist/components/layout/WebGL.svelte.d.ts +50 -0
- package/dist/components/tooltip/Tooltip.svelte +246 -78
- package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
- package/dist/components/tooltip/TooltipContext.svelte +409 -271
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +86 -55
- package/dist/components/tooltip/TooltipHeader.svelte +100 -11
- package/dist/components/tooltip/TooltipHeader.svelte.d.ts +43 -23
- package/dist/components/tooltip/TooltipItem.svelte +167 -27
- package/dist/components/tooltip/TooltipItem.svelte.d.ts +63 -31
- package/dist/components/tooltip/TooltipList.svelte +22 -3
- package/dist/components/tooltip/TooltipList.svelte.d.ts +6 -17
- package/dist/components/tooltip/TooltipSeparator.svelte +27 -1
- package/dist/components/tooltip/TooltipSeparator.svelte.d.ts +6 -15
- package/dist/components/tooltip/index.d.ts +6 -0
- package/dist/components/tooltip/index.js +6 -0
- package/dist/components/tooltip/tooltipMetaContext.d.ts +79 -0
- package/dist/components/tooltip/tooltipMetaContext.js +139 -0
- package/dist/components/types.d.ts +1 -0
- package/dist/components/types.js +1 -0
- package/dist/docs/Blockquote.svelte.d.ts +18 -14
- package/dist/docs/Code.svelte.d.ts +26 -22
- package/dist/docs/ConnectorSweepMenuField.svelte +17 -0
- package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +7 -0
- package/dist/docs/ConnectorTypeMenuField.svelte +17 -0
- package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +7 -0
- package/dist/docs/CurveMenuField.svelte +14 -3
- package/dist/docs/CurveMenuField.svelte.d.ts +9 -18
- package/dist/docs/GeoDebug.svelte +47 -42
- package/dist/docs/GeoDebug.svelte.d.ts +4 -16
- package/dist/docs/Header1.svelte.d.ts +27 -16
- package/dist/docs/Json.svelte.d.ts +20 -16
- package/dist/docs/Layout.svelte.d.ts +18 -13
- package/dist/docs/Link.svelte.d.ts +33 -21
- package/dist/docs/PathDataMenuField.svelte +14 -10
- package/dist/docs/PathDataMenuField.svelte.d.ts +8 -18
- package/dist/docs/Preview.svelte +20 -7
- package/dist/docs/Preview.svelte.d.ts +12 -22
- package/dist/docs/TilesetField.svelte.d.ts +21 -17
- package/dist/docs/TransformDebug.svelte +5 -6
- package/dist/docs/TransformDebug.svelte.d.ts +18 -14
- package/dist/docs/ViewSourceButton.svelte.d.ts +21 -17
- package/dist/types/d3-shape-extentions.d.ts +7 -0
- package/dist/utils/afterTick.d.ts +5 -0
- package/dist/utils/afterTick.js +8 -0
- package/dist/utils/arcText.svelte.d.ts +57 -0
- package/dist/utils/arcText.svelte.js +262 -0
- package/dist/utils/array.d.ts +9 -1
- package/dist/utils/array.js +13 -0
- package/dist/utils/attributes.d.ts +29 -0
- package/dist/utils/attributes.js +40 -0
- package/dist/utils/canvas.js +47 -10
- package/dist/utils/chart.d.ts +78 -0
- package/dist/utils/chart.js +512 -0
- package/dist/utils/color.d.ts +1 -0
- package/dist/utils/color.js +8 -0
- package/dist/utils/common.d.ts +3 -5
- package/dist/utils/common.js +3 -2
- package/dist/utils/connectorUtils.d.ts +21 -0
- package/dist/utils/connectorUtils.js +111 -0
- package/dist/utils/createId.d.ts +7 -0
- package/dist/utils/createId.js +9 -0
- package/dist/utils/debug.d.ts +1 -0
- package/dist/utils/debug.js +84 -0
- package/dist/utils/filterObject.d.ts +9 -0
- package/dist/utils/filterObject.js +12 -0
- package/dist/utils/graph/dagre.d.ts +34 -0
- package/dist/utils/graph/dagre.js +78 -0
- package/dist/utils/graph/dagre.test.d.ts +1 -0
- package/dist/utils/{graph.test.js → graph/dagre.test.js} +19 -33
- package/dist/utils/graph/sankey.d.ts +28 -0
- package/dist/utils/{graph.js → graph/sankey.js} +13 -41
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/key.svelte.d.ts +3 -0
- package/dist/utils/key.svelte.js +11 -0
- package/dist/utils/legendPayload.d.ts +7 -0
- package/dist/utils/legendPayload.js +8 -0
- package/dist/utils/motion.svelte.d.ts +140 -0
- package/dist/utils/motion.svelte.js +180 -0
- package/dist/utils/motion.test.d.ts +1 -0
- package/dist/utils/motion.test.js +213 -0
- package/dist/utils/{rect.d.ts → rect.svelte.d.ts} +7 -4
- package/dist/utils/rect.svelte.js +105 -0
- package/dist/utils/scales.svelte.d.ts +90 -0
- package/dist/utils/{scales.js → scales.svelte.js} +100 -39
- package/dist/utils/stack.d.ts +2 -3
- package/dist/utils/stack.js +1 -1
- package/dist/utils/string.js +87 -0
- package/dist/utils/ticks.d.ts +8 -2
- package/dist/utils/ticks.js +28 -0
- package/dist/utils/ticks.test.d.ts +1 -0
- package/dist/utils/ticks.test.js +67 -0
- package/dist/utils/types.d.ts +81 -0
- package/package.json +25 -24
- package/dist/components/ChartContext.svelte +0 -295
- package/dist/components/ChartContext.svelte.d.ts +0 -139
- package/dist/components/TransformContext.svelte.d.ts +0 -158
- package/dist/stores/motionStore.d.ts +0 -30
- package/dist/stores/motionStore.js +0 -62
- package/dist/utils/graph.d.ts +0 -37
- package/dist/utils/rect.js +0 -107
- package/dist/utils/scales.d.ts +0 -66
- /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
|
@@ -1,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,218 @@
|
|
|
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: (value) => {
|
|
402
|
+
if (seriesLayout === 'stackExpand') {
|
|
403
|
+
return format(value, 'percentRound');
|
|
404
|
+
} else {
|
|
405
|
+
return format(value, undefined, { variant: 'short' });
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
...(typeof axis === 'object' ? axis : null),
|
|
409
|
+
...props.yAxis,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return {
|
|
414
|
+
placement: radial ? 'angle' : 'bottom',
|
|
415
|
+
format: (value) => format(value, undefined, { variant: 'short' }),
|
|
416
|
+
...(typeof axis === 'object' ? axis : null),
|
|
417
|
+
...props.xAxis,
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function getRuleProps(): ComponentProps<typeof Rule> {
|
|
422
|
+
return {
|
|
423
|
+
x: 0,
|
|
424
|
+
y: 0,
|
|
425
|
+
...(typeof rule === 'object' ? rule : null),
|
|
426
|
+
...props.rule,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
284
429
|
</script>
|
|
285
430
|
|
|
431
|
+
<!-- svelte-ignore ownership_invalid_binding -->
|
|
286
432
|
<Chart
|
|
433
|
+
bind:context
|
|
287
434
|
data={chartData}
|
|
288
435
|
{x}
|
|
289
436
|
{xDomain}
|
|
290
437
|
{xScale}
|
|
291
|
-
y={y
|
|
292
|
-
(stackSeries
|
|
293
|
-
? (d) => visibleSeries.flatMap((s, i) => d.stackData[i])
|
|
294
|
-
: visibleSeries.map((s) => s.value ?? s.key))}
|
|
438
|
+
y={resolveAccessor(y)}
|
|
295
439
|
yBaseline={0}
|
|
296
440
|
yNice
|
|
297
441
|
{radial}
|
|
298
442
|
padding={radial ? undefined : defaultChartPadding(axis, legend)}
|
|
299
|
-
{
|
|
300
|
-
tooltip={
|
|
443
|
+
{...restProps}
|
|
444
|
+
tooltip={tooltip === false
|
|
301
445
|
? false
|
|
302
446
|
: {
|
|
303
447
|
mode: 'bisect-x',
|
|
304
|
-
onclick:
|
|
448
|
+
onclick: onTooltipClick,
|
|
305
449
|
debug,
|
|
306
450
|
...props.tooltip?.context,
|
|
307
|
-
...$$props.tooltip,
|
|
308
451
|
}}
|
|
309
|
-
bind:tooltipContext
|
|
310
452
|
brush={brush && (brush === true || brush.mode == undefined || brush.mode === 'integrated')
|
|
311
453
|
? {
|
|
312
454
|
axis: 'x',
|
|
313
455
|
resetOnEnd: true,
|
|
314
456
|
xDomain,
|
|
315
457
|
...brushProps,
|
|
316
|
-
|
|
458
|
+
onBrushEnd: (e) => {
|
|
317
459
|
xDomain = e.xDomain;
|
|
318
|
-
brushProps.
|
|
460
|
+
brushProps.onBrushEnd?.(e);
|
|
319
461
|
},
|
|
320
462
|
}
|
|
321
463
|
: 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
464
|
>
|
|
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} />
|
|
465
|
+
{#snippet children({ context })}
|
|
466
|
+
{@const snippetProps = {
|
|
467
|
+
context,
|
|
468
|
+
series,
|
|
469
|
+
visibleSeries: seriesState.visibleSeries,
|
|
470
|
+
getAreaProps,
|
|
471
|
+
getLabelsProps,
|
|
472
|
+
getPointsProps,
|
|
473
|
+
getHighlightProps,
|
|
474
|
+
getLegendProps,
|
|
475
|
+
getGridProps,
|
|
476
|
+
getAxisProps,
|
|
477
|
+
getRuleProps,
|
|
478
|
+
highlightKey: seriesState.highlightKey.current,
|
|
479
|
+
setHighlightKey: seriesState.highlightKey.set,
|
|
480
|
+
}}
|
|
481
|
+
|
|
482
|
+
{#if childrenProp}
|
|
483
|
+
{@render childrenProp(snippetProps)}
|
|
484
|
+
{:else}
|
|
485
|
+
{@render belowContext?.(snippetProps)}
|
|
486
|
+
<Layer
|
|
487
|
+
type={renderContext}
|
|
488
|
+
{...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
|
|
489
|
+
center={radial}
|
|
490
|
+
{debug}
|
|
491
|
+
>
|
|
492
|
+
{#if typeof grid === 'function'}
|
|
493
|
+
{@render grid(snippetProps)}
|
|
494
|
+
{:else if grid}
|
|
495
|
+
<Grid {...getGridProps()} />
|
|
365
496
|
{/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
497
|
|
|
380
|
-
|
|
381
|
-
|
|
498
|
+
<ChartClipPath disabled={!brush}>
|
|
499
|
+
<ChartAnnotations
|
|
500
|
+
{annotations}
|
|
501
|
+
layer="below"
|
|
502
|
+
highlightKey={seriesState.highlightKey.current}
|
|
503
|
+
visibleSeries={seriesState.visibleSeries}
|
|
504
|
+
/>
|
|
505
|
+
|
|
506
|
+
{@render belowMarks?.(snippetProps)}
|
|
507
|
+
|
|
508
|
+
{#if marks}
|
|
509
|
+
{@render marks(snippetProps)}
|
|
510
|
+
{:else}
|
|
511
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
512
|
+
<Area {...getAreaProps(s, i)} />
|
|
513
|
+
{/each}
|
|
514
|
+
{/if}
|
|
515
|
+
</ChartClipPath>
|
|
516
|
+
|
|
517
|
+
{@render aboveMarks?.(snippetProps)}
|
|
518
|
+
{#if typeof axis === 'function'}
|
|
519
|
+
{@render axis(snippetProps)}
|
|
520
|
+
{#if typeof rule === 'function'}
|
|
521
|
+
{@render rule(snippetProps)}
|
|
522
|
+
{:else if rule}
|
|
523
|
+
<Rule {...getRuleProps()} />
|
|
524
|
+
{/if}
|
|
525
|
+
{:else if axis}
|
|
382
526
|
{#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
|
-
/>
|
|
527
|
+
<Axis {...getAxisProps('y')} />
|
|
395
528
|
{/if}
|
|
396
529
|
|
|
397
530
|
{#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
|
-
/>
|
|
531
|
+
<Axis {...getAxisProps('x')} />
|
|
404
532
|
{/if}
|
|
405
533
|
|
|
406
|
-
{#if rule}
|
|
407
|
-
|
|
534
|
+
{#if typeof rule === 'function'}
|
|
535
|
+
{@render rule(snippetProps)}
|
|
536
|
+
{:else if rule}
|
|
537
|
+
<Rule {...getRuleProps()} />
|
|
408
538
|
{/if}
|
|
409
539
|
{/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
540
|
|
|
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
|
-
/>
|
|
541
|
+
<!-- Use `full` to allow labels on edge to not be cropped (bleed into padding) -->
|
|
542
|
+
<ChartClipPath disabled={!brush} full>
|
|
543
|
+
{#if typeof points === 'function'}
|
|
544
|
+
{@render points(snippetProps)}
|
|
545
|
+
{:else if points}
|
|
546
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
547
|
+
<Points {...getPointsProps(s, i)} />
|
|
548
|
+
{/each}
|
|
549
|
+
{/if}
|
|
550
|
+
|
|
551
|
+
{#if typeof highlight === 'function'}
|
|
552
|
+
{@render highlight(snippetProps)}
|
|
553
|
+
{:else if highlight}
|
|
554
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
555
|
+
<Highlight {...getHighlightProps(s, i)} />
|
|
556
|
+
{/each}
|
|
557
|
+
{/if}
|
|
558
|
+
|
|
559
|
+
{#if typeof labels === 'function'}
|
|
560
|
+
{@render labels(snippetProps)}
|
|
561
|
+
{:else if labels}
|
|
562
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
563
|
+
<Labels {...getLabelsProps(s, i)} />
|
|
564
|
+
{/each}
|
|
529
565
|
{/if}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
566
|
+
|
|
567
|
+
<ChartAnnotations
|
|
568
|
+
{annotations}
|
|
569
|
+
layer="above"
|
|
570
|
+
highlightKey={seriesState.highlightKey.current}
|
|
571
|
+
visibleSeries={seriesState.visibleSeries}
|
|
572
|
+
/>
|
|
573
|
+
</ChartClipPath>
|
|
574
|
+
</Layer>
|
|
575
|
+
|
|
576
|
+
{@render aboveContext?.(snippetProps)}
|
|
577
|
+
|
|
578
|
+
{#if typeof legend === 'function'}
|
|
579
|
+
{@render legend(snippetProps)}
|
|
580
|
+
{:else if legend}
|
|
581
|
+
<Legend {...getLegendProps()} />
|
|
582
|
+
{/if}
|
|
583
|
+
|
|
584
|
+
{#if typeof tooltip === 'function'}
|
|
585
|
+
{@render tooltip(snippetProps)}
|
|
586
|
+
{:else if tooltip}
|
|
587
|
+
<DefaultTooltip tooltipProps={props.tooltip} {seriesState} canHaveTotal={stackSeries} />
|
|
588
|
+
{/if}
|
|
589
|
+
{/if}
|
|
590
|
+
{/snippet}
|
|
534
591
|
</Chart>
|