layerchart 2.0.0-next.1 → 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 +21 -19
- package/dist/components/ChartContext.svelte +0 -295
- package/dist/components/ChartContext.svelte.d.ts +0 -139
- package/dist/components/TransformContext.svelte.d.ts +0 -158
- package/dist/stores/motionStore.d.ts +0 -30
- package/dist/stores/motionStore.js +0 -62
- package/dist/utils/graph.d.ts +0 -37
- package/dist/utils/rect.js +0 -107
- package/dist/utils/scales.d.ts +0 -66
- /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
|
@@ -1,213 +1,253 @@
|
|
|
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 } 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
|
-
|
|
110
|
+
import type { Insets } from '../../utils/rect.svelte.js';
|
|
111
|
+
import type { SeriesData, SimplifiedChartProps, SimplifiedChartPropsObject } from './types.js';
|
|
112
|
+
import 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 xScale = $derived(
|
|
175
|
+
xScaleProp ?? (isVertical ? scaleBand().padding(bandPadding) : scaleLinear())
|
|
176
|
+
);
|
|
177
|
+
const xBaseline = $derived(isVertical ? undefined : 0);
|
|
178
|
+
|
|
179
|
+
const yScale = $derived(
|
|
180
|
+
yScaleProp ?? (isVertical ? scaleLinear() : scaleBand().padding(bandPadding))
|
|
181
|
+
);
|
|
182
|
+
const yBaseline = $derived(isVertical ? 0 : undefined);
|
|
183
|
+
|
|
184
|
+
const x1Scale = $derived(
|
|
185
|
+
isGroupSeries && isVertical ? scaleBand().padding(groupPadding) : undefined
|
|
186
|
+
);
|
|
187
|
+
const x1Domain = $derived(
|
|
188
|
+
isGroupSeries && isVertical ? seriesState.visibleSeries.map((s) => s.key) : undefined
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const x1Range = $derived(
|
|
192
|
+
isGroupSeries && isVertical
|
|
193
|
+
? // TODO: can we do something better here where we don't need to cast this
|
|
194
|
+
// feels fragile!
|
|
195
|
+
({ xScale }: { xScale: AnyScale }) => [0, xScale.bandwidth!()]
|
|
196
|
+
: undefined
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const y1Scale = $derived(
|
|
200
|
+
isGroupSeries && !isVertical ? scaleBand().padding(groupPadding) : undefined
|
|
201
|
+
);
|
|
202
|
+
const y1Domain = $derived(
|
|
203
|
+
isGroupSeries && !isVertical ? seriesState.visibleSeries.map((s) => s.key) : undefined
|
|
204
|
+
);
|
|
205
|
+
const y1Range = $derived(
|
|
206
|
+
isGroupSeries && !isVertical
|
|
207
|
+
? // TODO: can we do something better here where we don't need to cast this
|
|
208
|
+
// feels fragile!
|
|
209
|
+
({ yScale }: { yScale: AnyScale }) => [0, yScale.bandwidth!()]
|
|
210
|
+
: undefined
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
function isStackData(d: TData): d is TData & { stackData: any[] } {
|
|
214
|
+
return d && typeof d === 'object' && 'stackData' in d;
|
|
52
215
|
}
|
|
53
216
|
|
|
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
|
-
$: groupSeries = seriesLayout === 'group';
|
|
82
|
-
|
|
83
|
-
export let axis: ComponentProps<Axis> | 'x' | 'y' | boolean = true;
|
|
84
|
-
export let rule: ComponentProps<Rule> | boolean = true;
|
|
85
|
-
export let grid: ComponentProps<Grid> | boolean = true;
|
|
86
|
-
export let labels: ComponentProps<Labels> | boolean = false;
|
|
87
|
-
export let legend: ComponentProps<Legend> | boolean = false;
|
|
88
|
-
|
|
89
|
-
/** Padding between primary x or y bands/bars, applied to scaleBand().padding() */
|
|
90
|
-
export let bandPadding = 0.4;
|
|
91
|
-
/** Padding between group/series items when using 'seriesLayout="group"', applied to scaleBand().padding() */
|
|
92
|
-
export let groupPadding = 0;
|
|
93
|
-
/** Padding between series items within bars when using 'seriesLayout="stack"' */
|
|
94
|
-
export let stackPadding = 0;
|
|
95
|
-
|
|
96
|
-
/** Expose tooltip context for external access */
|
|
97
|
-
export let tooltipContext: ComponentProps<Tooltip.Context>['tooltip'] = undefined;
|
|
98
|
-
|
|
99
|
-
/** Event dispatched with current tooltip data */
|
|
100
|
-
export let ontooltipclick: (e: MouseEvent, detail: { data: any }) => void = () => {};
|
|
101
|
-
|
|
102
|
-
// TODO: Need to find a way to have this play nice with `tooltip={{ mode: 'band' }}`
|
|
103
|
-
/** Event dispatched when individual Bar is clicked (useful with multiple series) */
|
|
104
|
-
export let onbarclick: (
|
|
105
|
-
e: MouseEvent,
|
|
106
|
-
detail: { data: any; series: (typeof series)[number] }
|
|
107
|
-
) => void = () => {};
|
|
108
|
-
|
|
109
|
-
$: xScale = $$props.xScale ?? (isVertical ? scaleBand().padding(bandPadding) : scaleLinear());
|
|
110
|
-
$: xBaseline = isVertical ? undefined : 0;
|
|
111
|
-
|
|
112
|
-
$: yScale = $$props.yScale ?? (isVertical ? scaleLinear() : scaleBand().padding(bandPadding));
|
|
113
|
-
$: yBaseline = isVertical ? 0 : undefined;
|
|
114
|
-
|
|
115
|
-
let x1Scale: ChartProps['x1Scale'];
|
|
116
|
-
let x1Domain: ChartProps['x1Domain'];
|
|
117
|
-
let x1Range: ChartProps['x1Range'];
|
|
118
|
-
|
|
119
|
-
let y1Scale: ChartProps['y1Scale'];
|
|
120
|
-
let y1Domain: ChartProps['y1Domain'];
|
|
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?.()];
|
|
217
|
+
const chartData: Array<TData & { stackData?: any }> = $derived.by(() => {
|
|
218
|
+
let _chartData = (
|
|
219
|
+
seriesState.allSeriesData.length ? seriesState.allSeriesData : chartDataArray(data)
|
|
220
|
+
) as Array<TData & { stackData?: any }>;
|
|
221
|
+
if (isStackSeries) {
|
|
222
|
+
const seriesKeys = seriesState.visibleSeries.map((s) => s.key);
|
|
223
|
+
|
|
224
|
+
const offset =
|
|
225
|
+
seriesLayout === 'stackExpand'
|
|
226
|
+
? stackOffsetExpand
|
|
227
|
+
: seriesLayout === 'stackDiverging'
|
|
228
|
+
? stackOffsetDiverging
|
|
229
|
+
: stackOffsetNone;
|
|
230
|
+
const stackData = stack()
|
|
231
|
+
.keys(seriesKeys)
|
|
232
|
+
.value((d, key) => {
|
|
233
|
+
const s = series.find((d) => d.key === key)!;
|
|
234
|
+
return accessor(s.value ?? s.key)(d as any);
|
|
235
|
+
})
|
|
236
|
+
.offset(offset)(chartDataArray(data)) as any[];
|
|
237
|
+
|
|
238
|
+
_chartData = _chartData.map((d, i) => {
|
|
239
|
+
return {
|
|
240
|
+
...d,
|
|
241
|
+
stackData: stackData.map((sd) => sd[i]),
|
|
242
|
+
};
|
|
243
|
+
});
|
|
132
244
|
}
|
|
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;
|
|
203
|
-
|
|
204
|
-
function setHighlightSeriesKey(seriesKey: typeof highlightSeriesKey) {
|
|
205
|
-
highlightSeriesKey = seriesKey;
|
|
206
|
-
}
|
|
245
|
+
return _chartData;
|
|
246
|
+
});
|
|
207
247
|
|
|
208
|
-
|
|
248
|
+
function getBarsProps(s: SeriesData<TData, typeof Bars>, i: number): ComponentProps<typeof Bars> {
|
|
209
249
|
const isFirst = i == 0;
|
|
210
|
-
const isLast = i == visibleSeries.length - 1;
|
|
250
|
+
const isLast = i == seriesState.visibleSeries.length - 1;
|
|
211
251
|
|
|
212
252
|
const isStackLayout = seriesLayout.startsWith('stack');
|
|
213
253
|
|
|
@@ -228,36 +268,40 @@
|
|
|
228
268
|
}
|
|
229
269
|
}
|
|
230
270
|
|
|
231
|
-
const valueAccessor =
|
|
271
|
+
const valueAccessor = isStackSeries
|
|
232
272
|
? (d: any) => d.stackData[i]
|
|
233
273
|
: (s.value ?? (s.data ? undefined : s.key));
|
|
234
|
-
|
|
274
|
+
|
|
275
|
+
return {
|
|
235
276
|
data: s.data,
|
|
236
277
|
x: !isVertical ? valueAccessor : undefined,
|
|
237
278
|
y: isVertical ? valueAccessor : undefined,
|
|
238
|
-
x1: isVertical &&
|
|
239
|
-
y1: !isVertical &&
|
|
240
|
-
rounded: isStackLayout && i !== visibleSeries.length - 1 ? 'none' : 'edge',
|
|
279
|
+
x1: isVertical && isGroupSeries ? (d) => s.value ?? s.key : undefined,
|
|
280
|
+
y1: !isVertical && isGroupSeries ? (d) => s.value ?? s.key : undefined,
|
|
281
|
+
rounded: isStackLayout && i !== seriesState.visibleSeries.length - 1 ? 'none' : 'edge',
|
|
241
282
|
radius: 4,
|
|
242
283
|
strokeWidth: 1,
|
|
243
284
|
insets: stackInsets,
|
|
244
285
|
fill: s.color,
|
|
245
|
-
|
|
286
|
+
onBarClick: (e, detail) => onBarClick(e, { ...detail, series: s }),
|
|
246
287
|
...props.bars,
|
|
247
288
|
...s.props,
|
|
248
289
|
class: cls(
|
|
249
290
|
'transition-opacity',
|
|
250
|
-
|
|
291
|
+
seriesState.highlightKey.current &&
|
|
292
|
+
seriesState.highlightKey.current !== s.key &&
|
|
293
|
+
'opacity-10',
|
|
251
294
|
props.bars?.class,
|
|
252
295
|
s.props?.class
|
|
253
296
|
),
|
|
254
297
|
};
|
|
298
|
+
}
|
|
255
299
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
300
|
+
function getLabelsProps(
|
|
301
|
+
s: SeriesData<TData, typeof Bars>,
|
|
302
|
+
i: number
|
|
303
|
+
): ComponentProps<typeof Labels<TData>> {
|
|
304
|
+
return {
|
|
261
305
|
// TODO: Improve placement when using `seriesLayout="group"`
|
|
262
306
|
// data: s.data,
|
|
263
307
|
// y: s.value ?? (s.data ? undefined : s.key),
|
|
@@ -265,23 +309,80 @@
|
|
|
265
309
|
...(typeof labels === 'object' ? labels : null),
|
|
266
310
|
class: cls(
|
|
267
311
|
'stroke-surface-200 transition-opacity',
|
|
268
|
-
|
|
312
|
+
seriesState.highlightKey.current &&
|
|
313
|
+
seriesState.highlightKey.current !== s.key &&
|
|
314
|
+
'opacity-10',
|
|
269
315
|
props.labels?.class,
|
|
270
316
|
typeof labels === 'object' && labels.class
|
|
271
317
|
),
|
|
272
318
|
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const brushProps = $derived({ ...(typeof brush === 'object' ? brush : null), ...props.brush });
|
|
322
|
+
|
|
323
|
+
function getLegendProps(): ComponentProps<typeof Legend> {
|
|
324
|
+
return createLegendProps({
|
|
325
|
+
seriesState,
|
|
326
|
+
props: {
|
|
327
|
+
...props.legend,
|
|
328
|
+
...(typeof legend === 'object' ? legend : null),
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
function getGridProps(): ComponentProps<typeof Grid> {
|
|
333
|
+
return {
|
|
334
|
+
x: !isVertical || radial,
|
|
335
|
+
y: isVertical || radial,
|
|
336
|
+
...(typeof grid === 'object' ? grid : null),
|
|
337
|
+
...props.grid,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
273
340
|
|
|
274
|
-
|
|
341
|
+
function getHighlightProps(): ComponentProps<typeof Highlight> {
|
|
342
|
+
return {
|
|
343
|
+
area: true,
|
|
344
|
+
...props.highlight,
|
|
345
|
+
};
|
|
275
346
|
}
|
|
276
347
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
348
|
+
function getAxisProps(axisDirection: 'x' | 'y'): ComponentProps<typeof Axis> {
|
|
349
|
+
if (axisDirection === 'y') {
|
|
350
|
+
return {
|
|
351
|
+
placement: radial ? 'radius' : 'left',
|
|
352
|
+
|
|
353
|
+
format: (value) => {
|
|
354
|
+
if (isVertical && seriesLayout === 'stackExpand') {
|
|
355
|
+
return format(value, 'percentRound');
|
|
356
|
+
} else {
|
|
357
|
+
return format(value, undefined, { variant: 'short' });
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
...(typeof axis === 'object' ? axis : null),
|
|
361
|
+
...props.yAxis,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
placement: radial ? 'angle' : 'bottom',
|
|
366
|
+
format: (value) => {
|
|
367
|
+
if (!isVertical && seriesLayout === 'stackExpand') {
|
|
368
|
+
return format(value, 'percentRound');
|
|
369
|
+
} else {
|
|
370
|
+
return format(value, undefined, { variant: 'short' });
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
...(typeof axis === 'object' ? axis : null),
|
|
374
|
+
...props.xAxis,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function getRuleProps(): ComponentProps<typeof Rule> {
|
|
379
|
+
return {
|
|
380
|
+
x: isVertical ? false : 0,
|
|
381
|
+
y: isVertical ? 0 : false,
|
|
382
|
+
...(typeof rule === 'object' ? rule : null),
|
|
383
|
+
...props.rule,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
285
386
|
|
|
286
387
|
if (profile) {
|
|
287
388
|
console.time('BarChart render');
|
|
@@ -289,230 +390,194 @@
|
|
|
289
390
|
console.timeEnd('BarChart render');
|
|
290
391
|
});
|
|
291
392
|
}
|
|
393
|
+
|
|
394
|
+
setTooltipMetaContext({
|
|
395
|
+
type: 'bar',
|
|
396
|
+
get orientation() {
|
|
397
|
+
return orientation;
|
|
398
|
+
},
|
|
399
|
+
get stackSeries() {
|
|
400
|
+
return isStackSeries;
|
|
401
|
+
},
|
|
402
|
+
get visibleSeries() {
|
|
403
|
+
return seriesState.visibleSeries;
|
|
404
|
+
},
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
function resolveAccessor(acc: Accessor<TData> | undefined) {
|
|
408
|
+
if (acc) return acc;
|
|
409
|
+
if (isStackSeries) {
|
|
410
|
+
return (d: TData) =>
|
|
411
|
+
isStackData(d) ? seriesState.visibleSeries.flatMap((s, i) => d.stackData[i]) : undefined;
|
|
412
|
+
}
|
|
413
|
+
return seriesState.visibleSeries.map((s) => s.value ?? s.key);
|
|
414
|
+
}
|
|
292
415
|
</script>
|
|
293
416
|
|
|
417
|
+
<!-- svelte-ignore ownership_invalid_binding -->
|
|
294
418
|
<Chart
|
|
419
|
+
bind:context
|
|
295
420
|
data={chartData}
|
|
296
|
-
x={
|
|
297
|
-
|
|
298
|
-
? (d) => visibleSeries.flatMap((s, i) => d.stackData[i])
|
|
299
|
-
: visibleSeries.map((s) => s.value ?? s.key))}
|
|
421
|
+
x={resolveAccessor(xProp)}
|
|
422
|
+
{xDomain}
|
|
300
423
|
{xScale}
|
|
301
424
|
{xBaseline}
|
|
302
425
|
xNice={orientation === 'horizontal'}
|
|
303
426
|
{x1Scale}
|
|
304
427
|
{x1Domain}
|
|
305
428
|
{x1Range}
|
|
306
|
-
y={
|
|
307
|
-
(stackSeries
|
|
308
|
-
? (d) => visibleSeries.flatMap((s, i) => d.stackData[i])
|
|
309
|
-
: visibleSeries.map((s) => s.value ?? s.key))}
|
|
429
|
+
y={resolveAccessor(yProp)}
|
|
310
430
|
{yScale}
|
|
311
431
|
{yBaseline}
|
|
312
432
|
yNice={orientation === 'vertical'}
|
|
313
433
|
{y1Scale}
|
|
314
434
|
{y1Domain}
|
|
315
435
|
{y1Range}
|
|
316
|
-
c={isVertical ?
|
|
436
|
+
c={isVertical ? yProp : xProp}
|
|
317
437
|
cRange={['var(--color-primary)']}
|
|
318
|
-
|
|
319
|
-
{
|
|
320
|
-
|
|
438
|
+
{radial}
|
|
439
|
+
padding={radial ? undefined : defaultChartPadding(axis, legend)}
|
|
440
|
+
{...restProps}
|
|
441
|
+
tooltip={tooltip === false
|
|
321
442
|
? false
|
|
322
443
|
: {
|
|
323
444
|
mode: 'band',
|
|
324
|
-
onclick:
|
|
445
|
+
onclick: onTooltipClick,
|
|
325
446
|
debug,
|
|
326
447
|
...props.tooltip?.context,
|
|
327
|
-
...$$props.tooltip,
|
|
328
448
|
}}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
449
|
+
brush={brush && (brush === true || brush.mode == undefined || brush.mode === 'integrated')
|
|
450
|
+
? {
|
|
451
|
+
axis: 'x',
|
|
452
|
+
resetOnEnd: true,
|
|
453
|
+
xDomain,
|
|
454
|
+
...brushProps,
|
|
455
|
+
onBrushEnd: (e) => {
|
|
456
|
+
// TOOD: This should set xRange instead of xDomain, and/or xDomain should be all values, not just bounds of brush range
|
|
457
|
+
xDomain = e.xDomain;
|
|
458
|
+
brushProps.onBrushEnd?.(e);
|
|
459
|
+
},
|
|
460
|
+
}
|
|
461
|
+
: false}
|
|
340
462
|
>
|
|
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
|
-
/>
|
|
463
|
+
{#snippet children({ context })}
|
|
464
|
+
{@const snippetProps = {
|
|
465
|
+
context,
|
|
466
|
+
series,
|
|
467
|
+
visibleSeries: seriesState.visibleSeries,
|
|
468
|
+
getBarsProps,
|
|
469
|
+
getLabelsProps,
|
|
470
|
+
getLegendProps,
|
|
471
|
+
getGridProps,
|
|
472
|
+
getHighlightProps,
|
|
473
|
+
getAxisProps,
|
|
474
|
+
getRuleProps,
|
|
475
|
+
highlightKey: seriesState.highlightKey.current,
|
|
476
|
+
setHighlightKey: seriesState.highlightKey.set,
|
|
477
|
+
}}
|
|
478
|
+
{#if childrenProp}
|
|
479
|
+
{@render childrenProp(snippetProps)}
|
|
480
|
+
{:else}
|
|
481
|
+
{@render belowContext?.(snippetProps)}
|
|
482
|
+
|
|
483
|
+
<Layer
|
|
484
|
+
type={renderContext}
|
|
485
|
+
{...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
|
|
486
|
+
center={radial}
|
|
487
|
+
{debug}
|
|
488
|
+
>
|
|
489
|
+
{#if typeof grid === 'function'}
|
|
490
|
+
{@render grid(snippetProps)}
|
|
491
|
+
{:else if grid}
|
|
492
|
+
<Grid {...getGridProps()} />
|
|
375
493
|
{/if}
|
|
376
|
-
</slot>
|
|
377
494
|
|
|
378
|
-
|
|
495
|
+
<ChartClipPath disabled={!brush}>
|
|
496
|
+
<ChartAnnotations
|
|
497
|
+
{annotations}
|
|
498
|
+
layer="below"
|
|
499
|
+
highlightKey={seriesState.highlightKey.current}
|
|
500
|
+
visibleSeries={seriesState.visibleSeries}
|
|
501
|
+
/>
|
|
379
502
|
|
|
380
|
-
|
|
381
|
-
{#each visibleSeries as s, i (s.key)}
|
|
382
|
-
<Bars {...getBarsProps(s, i)} />
|
|
383
|
-
{/each}
|
|
384
|
-
</slot>
|
|
503
|
+
{@render belowMarks?.(snippetProps)}
|
|
385
504
|
|
|
386
|
-
|
|
505
|
+
{#if typeof marks === 'function'}
|
|
506
|
+
{@render marks(snippetProps)}
|
|
507
|
+
{:else}
|
|
508
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
509
|
+
<Bars {...getBarsProps(s, i)} />
|
|
510
|
+
{/each}
|
|
511
|
+
{/if}
|
|
512
|
+
</ChartClipPath>
|
|
513
|
+
|
|
514
|
+
{@render aboveMarks?.(snippetProps)}
|
|
387
515
|
|
|
388
|
-
|
|
389
|
-
|
|
516
|
+
{#if typeof axis === 'function'}
|
|
517
|
+
{@render axis(snippetProps)}
|
|
518
|
+
{#if typeof rule === 'function'}
|
|
519
|
+
{@render rule(snippetProps)}
|
|
520
|
+
{:else if rule}
|
|
521
|
+
<Rule {...getRuleProps()} />
|
|
522
|
+
{/if}
|
|
523
|
+
{:else if axis}
|
|
390
524
|
{#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
|
-
/>
|
|
525
|
+
<Axis {...getAxisProps('y')} />
|
|
403
526
|
{/if}
|
|
404
527
|
|
|
405
528
|
{#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
|
-
/>
|
|
529
|
+
<Axis {...getAxisProps('x')} />
|
|
418
530
|
{/if}
|
|
419
531
|
|
|
420
|
-
{#if rule}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
{...typeof rule === 'object' ? rule : null}
|
|
425
|
-
{...props.rule}
|
|
426
|
-
/>
|
|
532
|
+
{#if typeof rule === 'function'}
|
|
533
|
+
{@render rule(snippetProps)}
|
|
534
|
+
{:else if rule}
|
|
535
|
+
<Rule {...getRuleProps()} />
|
|
427
536
|
{/if}
|
|
428
537
|
{/if}
|
|
429
|
-
</slot>
|
|
430
538
|
|
|
431
|
-
|
|
432
|
-
<
|
|
433
|
-
|
|
539
|
+
<!-- Use `full` to allow labels on edge to not be cropped (bleed into padding) -->
|
|
540
|
+
<ChartClipPath disabled={!brush} full>
|
|
541
|
+
{#if typeof highlight === 'function'}
|
|
542
|
+
{@render highlight(snippetProps)}
|
|
543
|
+
{:else if highlight}
|
|
544
|
+
<Highlight {...getHighlightProps()} />
|
|
545
|
+
{/if}
|
|
546
|
+
|
|
547
|
+
{#if typeof labels === 'function'}
|
|
548
|
+
{@render labels(snippetProps)}
|
|
549
|
+
{:else if labels}
|
|
550
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
551
|
+
<Labels {...getLabelsProps(s, i)} />
|
|
552
|
+
{/each}
|
|
553
|
+
{/if}
|
|
554
|
+
|
|
555
|
+
<ChartAnnotations
|
|
556
|
+
{annotations}
|
|
557
|
+
layer="above"
|
|
558
|
+
highlightKey={seriesState.highlightKey.current}
|
|
559
|
+
visibleSeries={seriesState.visibleSeries}
|
|
560
|
+
/>
|
|
561
|
+
</ChartClipPath>
|
|
562
|
+
</Layer>
|
|
563
|
+
|
|
564
|
+
{@render aboveContext?.(snippetProps)}
|
|
434
565
|
|
|
435
|
-
{#if
|
|
436
|
-
{
|
|
437
|
-
|
|
438
|
-
{
|
|
566
|
+
{#if typeof legend === 'function'}
|
|
567
|
+
{@render legend(snippetProps)}
|
|
568
|
+
{:else if legend}
|
|
569
|
+
<Legend {...getLegendProps()} />
|
|
439
570
|
{/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
|
-
}}
|
|
571
|
+
|
|
572
|
+
{#if typeof tooltip === 'function'}
|
|
573
|
+
{@render tooltip(snippetProps)}
|
|
574
|
+
{:else if tooltip}
|
|
575
|
+
<DefaultTooltip
|
|
576
|
+
tooltipProps={props.tooltip}
|
|
577
|
+
canHaveTotal={isStackSeries || isGroupSeries}
|
|
578
|
+
{seriesState}
|
|
469
579
|
/>
|
|
470
580
|
{/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>
|
|
581
|
+
{/if}
|
|
582
|
+
{/snippet}
|
|
518
583
|
</Chart>
|