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