layerchart 2.0.0-next.0 → 2.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/movable.d.ts +28 -0
- package/dist/actions/movable.js +91 -0
- package/dist/components/AnnotationLine.svelte +155 -0
- package/dist/components/AnnotationLine.svelte.d.ts +28 -0
- package/dist/components/AnnotationPoint.svelte +121 -0
- package/dist/components/AnnotationPoint.svelte.d.ts +32 -0
- package/dist/components/AnnotationRange.svelte +147 -0
- package/dist/components/AnnotationRange.svelte.d.ts +40 -0
- package/dist/components/Arc.svelte +344 -151
- package/dist/components/Arc.svelte.d.ts +138 -0
- package/dist/components/Area.svelte +165 -149
- package/dist/components/Area.svelte.d.ts +45 -0
- package/dist/components/Axis.svelte +287 -174
- package/dist/components/Axis.svelte.d.ts +116 -0
- package/dist/components/Bar.svelte +163 -107
- package/dist/components/Bar.svelte.d.ts +48 -0
- package/dist/components/Bars.svelte +54 -68
- package/dist/components/Bars.svelte.d.ts +27 -0
- package/dist/components/Blur.svelte +31 -7
- package/dist/components/Blur.svelte.d.ts +23 -21
- package/dist/components/Bounds.svelte +49 -19
- package/dist/components/Bounds.svelte.d.ts +24 -50
- package/dist/components/BrushContext.svelte +296 -168
- package/dist/components/BrushContext.svelte.d.ts +97 -65
- package/dist/components/Calendar.svelte +116 -59
- package/dist/components/Calendar.svelte.d.ts +50 -31
- package/dist/components/Chart.svelte +1289 -398
- package/dist/components/Chart.svelte.d.ts +535 -410
- package/dist/components/ChartClipPath.svelte +37 -15
- package/dist/components/ChartClipPath.svelte.d.ts +21 -19
- package/dist/components/Circle.svelte +124 -85
- package/dist/components/Circle.svelte.d.ts +52 -0
- package/dist/components/CircleClipPath.svelte +76 -16
- package/dist/components/CircleClipPath.svelte.d.ts +46 -0
- package/dist/components/ClipPath.svelte +60 -15
- package/dist/components/ClipPath.svelte.d.ts +40 -27
- package/dist/components/ColorRamp.svelte +75 -9
- package/dist/components/ColorRamp.svelte.d.ts +37 -19
- package/dist/components/ComputedStyles.svelte +17 -5
- package/dist/components/ComputedStyles.svelte.d.ts +11 -19
- package/dist/components/Connector.svelte +149 -0
- package/dist/components/Connector.svelte.d.ts +51 -0
- package/dist/components/Dagre.svelte +211 -122
- package/dist/components/Dagre.svelte.d.ts +119 -56
- package/dist/components/ForceSimulation.svelte +215 -90
- package/dist/components/ForceSimulation.svelte.d.ts +82 -35
- package/dist/components/Frame.svelte +33 -13
- package/dist/components/Frame.svelte.d.ts +13 -17
- package/dist/components/GeoCircle.svelte +29 -16
- package/dist/components/GeoCircle.svelte.d.ts +22 -24
- package/dist/components/GeoContext.svelte +113 -72
- package/dist/components/GeoContext.svelte.d.ts +49 -41
- package/dist/components/GeoEdgeFade.svelte +47 -12
- package/dist/components/GeoEdgeFade.svelte.d.ts +17 -19
- package/dist/components/GeoPath.svelte +157 -127
- package/dist/components/GeoPath.svelte.d.ts +48 -36
- package/dist/components/GeoPoint.svelte +52 -20
- package/dist/components/GeoPoint.svelte.d.ts +25 -22
- package/dist/components/GeoSpline.svelte +75 -26
- package/dist/components/GeoSpline.svelte.d.ts +29 -20
- package/dist/components/GeoTile.svelte +100 -49
- package/dist/components/GeoTile.svelte.d.ts +38 -23
- package/dist/components/GeoVisible.svelte +17 -9
- package/dist/components/GeoVisible.svelte.d.ts +10 -18
- package/dist/components/Graticule.svelte +28 -13
- package/dist/components/Graticule.svelte.d.ts +11 -52
- package/dist/components/Grid.svelte +226 -114
- package/dist/components/Grid.svelte.d.ts +70 -0
- package/dist/components/Group.svelte +132 -105
- package/dist/components/Group.svelte.d.ts +53 -0
- package/dist/components/Highlight.svelte +409 -307
- package/dist/components/Highlight.svelte.d.ts +107 -0
- package/dist/components/Hull.svelte +96 -45
- package/dist/components/Hull.svelte.d.ts +40 -30
- package/dist/components/Labels.svelte +125 -46
- package/dist/components/Labels.svelte.d.ts +70 -27
- package/dist/components/Legend.svelte +374 -190
- package/dist/components/Legend.svelte.d.ts +95 -44
- package/dist/components/Line.svelte +163 -125
- package/dist/components/Line.svelte.d.ts +75 -0
- package/dist/components/LinearGradient.svelte +153 -78
- package/dist/components/LinearGradient.svelte.d.ts +66 -31
- package/dist/components/Link.svelte +160 -104
- package/dist/components/Link.svelte.d.ts +54 -0
- package/dist/components/Marker.svelte +100 -39
- package/dist/components/Marker.svelte.d.ts +59 -27
- package/dist/components/MarkerWrapper.svelte +35 -0
- package/dist/components/MarkerWrapper.svelte.d.ts +18 -0
- package/dist/components/MonthPath.svelte +65 -20
- package/dist/components/MonthPath.svelte.d.ts +23 -17
- package/dist/components/MotionPath.svelte +80 -24
- package/dist/components/MotionPath.svelte.d.ts +46 -27
- package/dist/components/Pack.svelte +53 -17
- package/dist/components/Pack.svelte.d.ts +42 -21
- package/dist/components/Partition.svelte +64 -22
- package/dist/components/Partition.svelte.d.ts +49 -26
- package/dist/components/Pattern.svelte +297 -11
- package/dist/components/Pattern.svelte.d.ts +103 -19
- package/dist/components/Pie.svelte +122 -76
- package/dist/components/Pie.svelte.d.ts +65 -51
- package/dist/components/Point.svelte +20 -9
- package/dist/components/Point.svelte.d.ts +16 -20
- package/dist/components/Points.svelte +148 -137
- package/dist/components/Points.svelte.d.ts +45 -34
- package/dist/components/RadialGradient.svelte +143 -70
- package/dist/components/RadialGradient.svelte.d.ts +69 -31
- package/dist/components/Rect.svelte +121 -102
- package/dist/components/Rect.svelte.d.ts +36 -0
- package/dist/components/RectClipPath.svelte +82 -18
- package/dist/components/RectClipPath.svelte.d.ts +55 -0
- package/dist/components/Rule.svelte +105 -62
- package/dist/components/Rule.svelte.d.ts +40 -19
- package/dist/components/Sankey.svelte +132 -55
- package/dist/components/Sankey.svelte.d.ts +61 -31
- package/dist/components/Spline.svelte +281 -218
- package/dist/components/Spline.svelte.d.ts +95 -0
- package/dist/components/Text.svelte +437 -176
- package/dist/components/Text.svelte.d.ts +130 -0
- package/dist/components/Threshold.svelte +48 -16
- package/dist/components/Threshold.svelte.d.ts +29 -31
- package/dist/components/TileImage.svelte +103 -30
- package/dist/components/TileImage.svelte.d.ts +48 -23
- package/dist/components/TransformContext.svelte +365 -171
- package/dist/components/TransformControls.svelte +50 -26
- package/dist/components/TransformControls.svelte.d.ts +27 -19
- package/dist/components/Tree.svelte +74 -33
- package/dist/components/Tree.svelte.d.ts +42 -30
- package/dist/components/Treemap.svelte +119 -42
- package/dist/components/Treemap.svelte.d.ts +75 -27
- package/dist/components/Voronoi.svelte +106 -75
- package/dist/components/Voronoi.svelte.d.ts +40 -41
- package/dist/components/charts/ArcChart.svelte +464 -0
- package/dist/components/charts/ArcChart.svelte.d.ts +90 -0
- package/dist/components/charts/AreaChart.svelte +450 -393
- package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
- package/dist/components/charts/BarChart.svelte +454 -389
- package/dist/components/charts/BarChart.svelte.d.ts +76 -0
- package/dist/components/charts/ChartAnnotations.svelte +37 -0
- package/dist/components/charts/ChartAnnotations.svelte.d.ts +10 -0
- package/dist/components/charts/DefaultTooltip.svelte +60 -0
- package/dist/components/charts/DefaultTooltip.svelte.d.ts +10 -0
- package/dist/components/charts/LineChart.svelte +369 -314
- package/dist/components/charts/LineChart.svelte.d.ts +53 -0
- package/dist/components/charts/PieChart.svelte +458 -316
- package/dist/components/charts/PieChart.svelte.d.ts +137 -353
- package/dist/components/charts/ScatterChart.svelte +334 -296
- package/dist/components/charts/ScatterChart.svelte.d.ts +39 -0
- package/dist/components/charts/index.d.ts +8 -0
- package/dist/components/charts/index.js +7 -0
- package/dist/components/charts/types.d.ts +253 -0
- package/dist/components/charts/utils.svelte.d.ts +30 -0
- package/dist/components/charts/utils.svelte.js +55 -0
- package/dist/components/index.d.ts +76 -4
- package/dist/components/index.js +76 -5
- package/dist/components/layout/Canvas.svelte +321 -155
- package/dist/components/layout/Canvas.svelte.d.ts +104 -55
- package/dist/components/layout/Html.svelte +82 -42
- package/dist/components/layout/Html.svelte.d.ts +39 -28
- package/dist/components/layout/Layer.svelte +39 -0
- package/dist/components/layout/Layer.svelte.d.ts +17 -0
- package/dist/components/layout/Svg.svelte +122 -70
- package/dist/components/layout/Svg.svelte.d.ts +53 -34
- package/dist/components/layout/WebGL.svelte +135 -0
- package/dist/components/layout/WebGL.svelte.d.ts +50 -0
- package/dist/components/tooltip/Tooltip.svelte +246 -78
- package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
- package/dist/components/tooltip/TooltipContext.svelte +409 -271
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +86 -55
- package/dist/components/tooltip/TooltipHeader.svelte +100 -11
- package/dist/components/tooltip/TooltipHeader.svelte.d.ts +43 -23
- package/dist/components/tooltip/TooltipItem.svelte +167 -27
- package/dist/components/tooltip/TooltipItem.svelte.d.ts +63 -31
- package/dist/components/tooltip/TooltipList.svelte +22 -3
- package/dist/components/tooltip/TooltipList.svelte.d.ts +6 -17
- package/dist/components/tooltip/TooltipSeparator.svelte +27 -1
- package/dist/components/tooltip/TooltipSeparator.svelte.d.ts +6 -15
- package/dist/components/tooltip/index.d.ts +6 -0
- package/dist/components/tooltip/index.js +6 -0
- package/dist/components/tooltip/tooltipMetaContext.d.ts +79 -0
- package/dist/components/tooltip/tooltipMetaContext.js +139 -0
- package/dist/components/types.d.ts +1 -0
- package/dist/components/types.js +1 -0
- package/dist/docs/Blockquote.svelte.d.ts +18 -14
- package/dist/docs/Code.svelte.d.ts +26 -22
- package/dist/docs/ConnectorSweepMenuField.svelte +17 -0
- package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +7 -0
- package/dist/docs/ConnectorTypeMenuField.svelte +17 -0
- package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +7 -0
- package/dist/docs/CurveMenuField.svelte +14 -3
- package/dist/docs/CurveMenuField.svelte.d.ts +9 -18
- package/dist/docs/GeoDebug.svelte +47 -42
- package/dist/docs/GeoDebug.svelte.d.ts +4 -16
- package/dist/docs/Header1.svelte.d.ts +27 -16
- package/dist/docs/Json.svelte.d.ts +20 -16
- package/dist/docs/Layout.svelte.d.ts +18 -13
- package/dist/docs/Link.svelte.d.ts +33 -21
- package/dist/docs/PathDataMenuField.svelte +14 -10
- package/dist/docs/PathDataMenuField.svelte.d.ts +8 -18
- package/dist/docs/Preview.svelte +20 -7
- package/dist/docs/Preview.svelte.d.ts +12 -22
- package/dist/docs/TilesetField.svelte.d.ts +21 -17
- package/dist/docs/TransformDebug.svelte +5 -6
- package/dist/docs/TransformDebug.svelte.d.ts +18 -14
- package/dist/docs/ViewSourceButton.svelte.d.ts +21 -17
- package/dist/types/d3-shape-extentions.d.ts +7 -0
- package/dist/utils/afterTick.d.ts +5 -0
- package/dist/utils/afterTick.js +8 -0
- package/dist/utils/arcText.svelte.d.ts +57 -0
- package/dist/utils/arcText.svelte.js +262 -0
- package/dist/utils/array.d.ts +9 -1
- package/dist/utils/array.js +13 -0
- package/dist/utils/attributes.d.ts +29 -0
- package/dist/utils/attributes.js +40 -0
- package/dist/utils/canvas.js +47 -10
- package/dist/utils/chart.d.ts +78 -0
- package/dist/utils/chart.js +512 -0
- package/dist/utils/color.d.ts +1 -0
- package/dist/utils/color.js +8 -0
- package/dist/utils/common.d.ts +3 -5
- package/dist/utils/common.js +3 -2
- package/dist/utils/connectorUtils.d.ts +21 -0
- package/dist/utils/connectorUtils.js +111 -0
- package/dist/utils/createId.d.ts +7 -0
- package/dist/utils/createId.js +9 -0
- package/dist/utils/debug.d.ts +1 -0
- package/dist/utils/debug.js +84 -0
- package/dist/utils/filterObject.d.ts +9 -0
- package/dist/utils/filterObject.js +12 -0
- package/dist/utils/graph/dagre.d.ts +34 -0
- package/dist/utils/graph/dagre.js +78 -0
- package/dist/utils/graph/dagre.test.d.ts +1 -0
- package/dist/utils/{graph.test.js → graph/dagre.test.js} +19 -33
- package/dist/utils/graph/sankey.d.ts +28 -0
- package/dist/utils/{graph.js → graph/sankey.js} +13 -41
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/key.svelte.d.ts +3 -0
- package/dist/utils/key.svelte.js +11 -0
- package/dist/utils/legendPayload.d.ts +7 -0
- package/dist/utils/legendPayload.js +8 -0
- package/dist/utils/motion.svelte.d.ts +140 -0
- package/dist/utils/motion.svelte.js +180 -0
- package/dist/utils/motion.test.d.ts +1 -0
- package/dist/utils/motion.test.js +213 -0
- package/dist/utils/{rect.d.ts → rect.svelte.d.ts} +7 -4
- package/dist/utils/rect.svelte.js +105 -0
- package/dist/utils/scales.svelte.d.ts +90 -0
- package/dist/utils/{scales.js → scales.svelte.js} +100 -39
- package/dist/utils/stack.d.ts +2 -3
- package/dist/utils/stack.js +1 -1
- package/dist/utils/string.js +87 -0
- package/dist/utils/ticks.d.ts +8 -2
- package/dist/utils/ticks.js +28 -0
- package/dist/utils/ticks.test.d.ts +1 -0
- package/dist/utils/ticks.test.js +67 -0
- package/dist/utils/types.d.ts +81 -0
- package/package.json +25 -24
- package/dist/components/ChartContext.svelte +0 -295
- package/dist/components/ChartContext.svelte.d.ts +0 -139
- package/dist/components/TransformContext.svelte.d.ts +0 -158
- package/dist/stores/motionStore.d.ts +0 -30
- package/dist/stores/motionStore.js +0 -62
- package/dist/utils/graph.d.ts +0 -37
- package/dist/utils/rect.js +0 -107
- package/dist/utils/scales.d.ts +0 -66
- /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
|
@@ -1,173 +1,233 @@
|
|
|
1
|
-
<script lang="ts"
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { SeriesData, SimplifiedChartProps, SimplifiedChartPropsObject } from './types.js';
|
|
3
|
+
import type { AnyScale } from '../../utils/scales.svelte.js';
|
|
2
4
|
import { onMount, type ComponentProps } from 'svelte';
|
|
3
|
-
|
|
5
|
+
|
|
6
|
+
export type ScatterChartExtraSnippetProps<TData> = {
|
|
7
|
+
getLabelsProps: (
|
|
8
|
+
s: SeriesData<TData, typeof Points>,
|
|
9
|
+
i: number
|
|
10
|
+
) => ComponentProps<typeof Labels<TData>>;
|
|
11
|
+
getPointsProps: (
|
|
12
|
+
s: SeriesData<TData, typeof Points>,
|
|
13
|
+
i: number
|
|
14
|
+
) => ComponentProps<typeof Points>;
|
|
15
|
+
getHighlightProps: () => ComponentProps<typeof Highlight>;
|
|
16
|
+
getAxisProps: (axisDirection: 'x' | 'y') => ComponentProps<typeof Axis>;
|
|
17
|
+
getRuleProps: () => ComponentProps<typeof Rule>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ScatterChartPropsObjProp = Pick<
|
|
21
|
+
SimplifiedChartPropsObject,
|
|
22
|
+
| 'brush'
|
|
23
|
+
| 'canvas'
|
|
24
|
+
| 'grid'
|
|
25
|
+
| 'highlight'
|
|
26
|
+
| 'labels'
|
|
27
|
+
| 'legend'
|
|
28
|
+
| 'points'
|
|
29
|
+
| 'rule'
|
|
30
|
+
| 'svg'
|
|
31
|
+
| 'tooltip'
|
|
32
|
+
| 'xAxis'
|
|
33
|
+
| 'yAxis'
|
|
34
|
+
>;
|
|
35
|
+
|
|
36
|
+
export type ScatterChartProps<TData> = Omit<
|
|
37
|
+
SimplifiedChartProps<TData, typeof Points, ScatterChartExtraSnippetProps<TData>>,
|
|
38
|
+
'radial'
|
|
39
|
+
> & {
|
|
40
|
+
props?: ScatterChartPropsObjProp;
|
|
41
|
+
yDomain?: ComponentProps<typeof BrushContext>['yDomain'];
|
|
42
|
+
yScale?: AnyScale;
|
|
43
|
+
};
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<script lang="ts" generics="TData">
|
|
47
|
+
import { scaleLinear, scaleTime } from 'd3-scale';
|
|
4
48
|
import { format } from '@layerstack/utils';
|
|
5
49
|
import { cls } from '@layerstack/tailwind';
|
|
6
|
-
import { selectionStore } from '@layerstack/svelte-stores';
|
|
7
50
|
|
|
8
51
|
import Axis from '../Axis.svelte';
|
|
9
52
|
import BrushContext from '../BrushContext.svelte';
|
|
10
|
-
import Canvas from '../layout/Canvas.svelte';
|
|
11
53
|
import Chart from '../Chart.svelte';
|
|
54
|
+
import ChartAnnotations from './ChartAnnotations.svelte';
|
|
12
55
|
import ChartClipPath from '../ChartClipPath.svelte';
|
|
13
56
|
import Grid from '../Grid.svelte';
|
|
14
57
|
import Highlight from '../Highlight.svelte';
|
|
15
58
|
import Labels from '../Labels.svelte';
|
|
59
|
+
import Layer from '../layout/Layer.svelte';
|
|
16
60
|
import Legend from '../Legend.svelte';
|
|
17
61
|
import Points from '../Points.svelte';
|
|
18
62
|
import Rule from '../Rule.svelte';
|
|
19
|
-
import Svg from '../layout/Svg.svelte';
|
|
20
63
|
import * as Tooltip from '../tooltip/index.js';
|
|
21
64
|
|
|
22
|
-
import {
|
|
23
|
-
accessor,
|
|
24
|
-
chartDataArray,
|
|
25
|
-
defaultChartPadding,
|
|
26
|
-
type Accessor,
|
|
27
|
-
} from '../../utils/common.js';
|
|
65
|
+
import { accessor, chartDataArray, defaultChartPadding } from '../../utils/common.js';
|
|
28
66
|
import { asAny } from '../../utils/types.js';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/** Event dispatched with current tooltip data */
|
|
72
|
-
export let ontooltipclick: (e: MouseEvent, detail: { data: any }) => void = () => {};
|
|
73
|
-
|
|
74
|
-
export let props: {
|
|
75
|
-
brush?: Partial<ComponentProps<BrushContext>>;
|
|
76
|
-
canvas?: Partial<ComponentProps<Canvas>>;
|
|
77
|
-
debug?: typeof debug;
|
|
78
|
-
grid?: Partial<ComponentProps<Grid>>;
|
|
79
|
-
highlight?: Partial<ComponentProps<Highlight>>;
|
|
80
|
-
labels?: Partial<ComponentProps<Labels>>;
|
|
81
|
-
legend?: Partial<ComponentProps<Legend>>;
|
|
82
|
-
points?: Partial<ComponentProps<Points>>;
|
|
83
|
-
profile?: typeof profile;
|
|
84
|
-
rule?: Partial<ComponentProps<Rule>>;
|
|
85
|
-
svg?: Partial<ComponentProps<Svg>>;
|
|
86
|
-
tooltip?: {
|
|
87
|
-
context?: Partial<ComponentProps<Tooltip.Context>>;
|
|
88
|
-
root?: Partial<ComponentProps<Tooltip.Root>>;
|
|
89
|
-
header?: Partial<ComponentProps<Tooltip.Header>>;
|
|
90
|
-
list?: Partial<ComponentProps<Tooltip.List>>;
|
|
91
|
-
item?: Partial<ComponentProps<Tooltip.Item>>;
|
|
92
|
-
separator?: Partial<ComponentProps<Tooltip.Separator>>;
|
|
93
|
-
};
|
|
94
|
-
xAxis?: Partial<ComponentProps<Axis>>;
|
|
95
|
-
yAxis?: Partial<ComponentProps<Axis>>;
|
|
96
|
-
} = {};
|
|
97
|
-
|
|
98
|
-
export let renderContext: 'svg' | 'canvas' = 'svg';
|
|
99
|
-
|
|
100
|
-
/** Log initial render performance using `console.time` */
|
|
101
|
-
export let profile = false;
|
|
102
|
-
|
|
103
|
-
/** Enable debug mode */
|
|
104
|
-
export let debug = false;
|
|
67
|
+
import { createLegendProps, SeriesState } from './utils.svelte.js';
|
|
68
|
+
|
|
69
|
+
let {
|
|
70
|
+
data = [],
|
|
71
|
+
x: xProp,
|
|
72
|
+
y: yProp,
|
|
73
|
+
xDomain,
|
|
74
|
+
yDomain,
|
|
75
|
+
series: seriesProp,
|
|
76
|
+
seriesLayout = 'overlap',
|
|
77
|
+
axis = true,
|
|
78
|
+
brush = false,
|
|
79
|
+
grid = true,
|
|
80
|
+
labels = false,
|
|
81
|
+
legend = false,
|
|
82
|
+
points = false,
|
|
83
|
+
rule = true,
|
|
84
|
+
tooltip = true,
|
|
85
|
+
context = $bindable(),
|
|
86
|
+
onTooltipClick = () => {},
|
|
87
|
+
props = {},
|
|
88
|
+
renderContext = 'svg',
|
|
89
|
+
profile = false,
|
|
90
|
+
debug = false,
|
|
91
|
+
xScale: xScaleProp,
|
|
92
|
+
yScale: yScaleProp,
|
|
93
|
+
children: childrenProp,
|
|
94
|
+
aboveContext,
|
|
95
|
+
belowContext,
|
|
96
|
+
belowMarks,
|
|
97
|
+
aboveMarks,
|
|
98
|
+
marks,
|
|
99
|
+
highlight = true,
|
|
100
|
+
annotations = [],
|
|
101
|
+
...restProps
|
|
102
|
+
}: ScatterChartProps<TData> = $props();
|
|
103
|
+
|
|
104
|
+
const series: SeriesData<TData, typeof Points>[] = $derived(
|
|
105
|
+
seriesProp === undefined ? [{ key: 'default', data: chartDataArray(data) }] : seriesProp
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const seriesState = new SeriesState(() => series);
|
|
105
109
|
|
|
106
110
|
// Default xScale based on first data's `x` value
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
const xScale = $derived(
|
|
112
|
+
xScaleProp ??
|
|
113
|
+
(accessor(xProp)(chartDataArray(data)[0]) instanceof Date ? scaleTime() : scaleLinear())
|
|
114
|
+
);
|
|
110
115
|
|
|
111
116
|
// Default yScale based on first data's `y` value
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
117
|
+
const yScale = $derived(
|
|
118
|
+
yScaleProp ??
|
|
119
|
+
(accessor(yProp)(chartDataArray(data)[0]) instanceof Date ? scaleTime() : scaleLinear())
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const chartData = $derived(
|
|
123
|
+
seriesState.visibleSeries
|
|
124
|
+
.flatMap((s) => s.data?.map((d) => ({ seriesKey: s.key, ...d })))
|
|
125
|
+
.filter((d) => d) as Array<TData>
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
function getPointsProps(
|
|
129
|
+
s: SeriesData<TData, typeof Points>,
|
|
130
|
+
i: number
|
|
131
|
+
): ComponentProps<typeof Points> {
|
|
132
|
+
return {
|
|
128
133
|
data: s.data,
|
|
129
|
-
stroke: s.color,
|
|
130
134
|
fill: s.color,
|
|
131
|
-
fillOpacity: 0.3,
|
|
132
135
|
...props.points,
|
|
133
136
|
...s.props,
|
|
134
137
|
class: cls(
|
|
135
138
|
'transition-opacity',
|
|
136
|
-
|
|
139
|
+
seriesState.highlightKey.current &&
|
|
140
|
+
seriesState.highlightKey.current !== s.key &&
|
|
141
|
+
'opacity-10',
|
|
137
142
|
props.points?.class,
|
|
138
143
|
s.props?.class
|
|
139
144
|
),
|
|
140
145
|
};
|
|
146
|
+
}
|
|
141
147
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
148
|
+
function getLabelsProps(
|
|
149
|
+
s: SeriesData<TData, typeof Points>,
|
|
150
|
+
i: number
|
|
151
|
+
): ComponentProps<typeof Labels<TData>> {
|
|
152
|
+
return {
|
|
147
153
|
data: s.data,
|
|
148
154
|
...props.labels,
|
|
149
155
|
...(typeof labels === 'object' ? labels : null),
|
|
150
156
|
class: cls(
|
|
151
157
|
'stroke-surface-200 transition-opacity',
|
|
152
|
-
|
|
158
|
+
seriesState.highlightKey.current &&
|
|
159
|
+
seriesState.highlightKey.current !== s.key &&
|
|
160
|
+
'opacity-10',
|
|
153
161
|
props.labels?.class,
|
|
154
162
|
typeof labels === 'object' && labels.class
|
|
155
163
|
),
|
|
156
164
|
};
|
|
165
|
+
}
|
|
157
166
|
|
|
158
|
-
|
|
167
|
+
function getLegendProps(): ComponentProps<typeof Legend> {
|
|
168
|
+
return createLegendProps({
|
|
169
|
+
seriesState,
|
|
170
|
+
props: {
|
|
171
|
+
...props.legend,
|
|
172
|
+
...(typeof legend === 'object' ? legend : null),
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function getGridProps(): ComponentProps<typeof Grid> {
|
|
178
|
+
return {
|
|
179
|
+
x: true,
|
|
180
|
+
y: true,
|
|
181
|
+
...(typeof grid === 'object' ? grid : null),
|
|
182
|
+
...props.grid,
|
|
183
|
+
};
|
|
159
184
|
}
|
|
160
185
|
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
$selectedSeries.selected.length === 0 || $selectedSeries.isSelected(s.key)
|
|
166
|
-
// || highlightSeriesKey == s.key
|
|
167
|
-
);
|
|
186
|
+
const activeSeries = $derived.by(() => {
|
|
187
|
+
if (!context?.tooltip?.data) return null;
|
|
188
|
+
// @ts-expect-error - shh
|
|
189
|
+
return series.find((s) => s.key === context?.tooltip.data?.seriesKey) ?? series[0];
|
|
168
190
|
});
|
|
169
191
|
|
|
170
|
-
|
|
192
|
+
function getHighlightProps(): ComponentProps<typeof Highlight> {
|
|
193
|
+
return {
|
|
194
|
+
lines: true,
|
|
195
|
+
axis: 'both',
|
|
196
|
+
...props.highlight,
|
|
197
|
+
points: {
|
|
198
|
+
...(activeSeries?.color && { fill: activeSeries.color }),
|
|
199
|
+
...(typeof props.highlight?.points === 'object' ? props.highlight.points : null),
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function getAxisProps(axisDirection: 'x' | 'y'): ComponentProps<typeof Axis> {
|
|
205
|
+
if (axisDirection === 'y') {
|
|
206
|
+
return {
|
|
207
|
+
placement: 'left',
|
|
208
|
+
format: (value) => format(value, undefined, { variant: 'short' }),
|
|
209
|
+
...(typeof axis === 'object' ? axis : null),
|
|
210
|
+
...props.yAxis,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
placement: 'bottom',
|
|
215
|
+
format: (value) => format(value, undefined, { variant: 'short' }),
|
|
216
|
+
...(typeof axis === 'object' ? axis : null),
|
|
217
|
+
...props.xAxis,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function getRuleProps(): ComponentProps<typeof Rule> {
|
|
222
|
+
return {
|
|
223
|
+
x: 0,
|
|
224
|
+
y: 0,
|
|
225
|
+
...(typeof rule === 'object' ? rule : null),
|
|
226
|
+
...props.rule,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const brushProps = $derived({ ...(typeof brush === 'object' ? brush : null), ...props.brush });
|
|
171
231
|
|
|
172
232
|
if (profile) {
|
|
173
233
|
console.time('ScatterChart render');
|
|
@@ -177,27 +237,29 @@
|
|
|
177
237
|
}
|
|
178
238
|
</script>
|
|
179
239
|
|
|
240
|
+
<!-- svelte-ignore ownership_invalid_binding -->
|
|
180
241
|
<Chart
|
|
242
|
+
bind:context
|
|
181
243
|
data={chartData}
|
|
182
|
-
{
|
|
244
|
+
x={xProp}
|
|
183
245
|
{xDomain}
|
|
184
246
|
{xScale}
|
|
185
|
-
{
|
|
247
|
+
y={yProp}
|
|
186
248
|
{yDomain}
|
|
187
249
|
{yScale}
|
|
188
250
|
yNice
|
|
251
|
+
c={yProp}
|
|
252
|
+
cRange={['var(--color-primary)']}
|
|
189
253
|
padding={defaultChartPadding(axis, legend)}
|
|
190
|
-
{
|
|
191
|
-
tooltip={
|
|
254
|
+
{...restProps}
|
|
255
|
+
tooltip={tooltip === false
|
|
192
256
|
? false
|
|
193
257
|
: {
|
|
194
258
|
mode: 'voronoi',
|
|
195
|
-
onclick:
|
|
259
|
+
onclick: onTooltipClick,
|
|
196
260
|
debug,
|
|
197
261
|
...props.tooltip?.context,
|
|
198
|
-
...$$props.tooltip,
|
|
199
262
|
}}
|
|
200
|
-
bind:tooltipContext
|
|
201
263
|
brush={brush && (brush === true || brush.mode == undefined || brush.mode === 'integrated')
|
|
202
264
|
? {
|
|
203
265
|
axis: 'both',
|
|
@@ -205,191 +267,167 @@
|
|
|
205
267
|
xDomain,
|
|
206
268
|
yDomain,
|
|
207
269
|
...brushProps,
|
|
208
|
-
|
|
270
|
+
onBrushEnd: (e) => {
|
|
209
271
|
xDomain = e.xDomain;
|
|
210
272
|
yDomain = e.yDomain;
|
|
211
|
-
brushProps.
|
|
273
|
+
brushProps.onBrushEnd?.(e);
|
|
212
274
|
},
|
|
213
275
|
}
|
|
214
276
|
: false}
|
|
215
|
-
let:x
|
|
216
|
-
let:xScale
|
|
217
|
-
let:y
|
|
218
|
-
let:yScale
|
|
219
|
-
let:c
|
|
220
|
-
let:cScale
|
|
221
|
-
let:r
|
|
222
|
-
let:width
|
|
223
|
-
let:height
|
|
224
|
-
let:padding
|
|
225
|
-
let:tooltip
|
|
226
|
-
let:config
|
|
227
277
|
>
|
|
228
|
-
{
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
{debug}
|
|
257
|
-
>
|
|
258
|
-
<slot name="grid" {...slotProps}>
|
|
259
|
-
{#if grid}
|
|
260
|
-
<Grid x y {...typeof grid === 'object' ? grid : null} {...props.grid} />
|
|
278
|
+
{#snippet children({ context })}
|
|
279
|
+
{@const snippetProps = {
|
|
280
|
+
context,
|
|
281
|
+
series,
|
|
282
|
+
visibleSeries: seriesState.visibleSeries,
|
|
283
|
+
getLabelsProps,
|
|
284
|
+
getPointsProps,
|
|
285
|
+
getLegendProps,
|
|
286
|
+
getHighlightProps,
|
|
287
|
+
getAxisProps,
|
|
288
|
+
getRuleProps,
|
|
289
|
+
highlightKey: seriesState.highlightKey.current,
|
|
290
|
+
setHighlightKey: seriesState.highlightKey.set,
|
|
291
|
+
}}
|
|
292
|
+
|
|
293
|
+
{#if childrenProp}
|
|
294
|
+
{@render childrenProp(snippetProps)}
|
|
295
|
+
{:else}
|
|
296
|
+
{@render belowContext?.(snippetProps)}
|
|
297
|
+
<Layer
|
|
298
|
+
type={renderContext}
|
|
299
|
+
{...asAny(renderContext === 'canvas' ? props.canvas : props.svg)}
|
|
300
|
+
{debug}
|
|
301
|
+
>
|
|
302
|
+
{#if typeof grid === 'function'}
|
|
303
|
+
{@render grid(snippetProps)}
|
|
304
|
+
{:else if grid}
|
|
305
|
+
<Grid {...getGridProps()} />
|
|
261
306
|
{/if}
|
|
262
|
-
</slot>
|
|
263
307
|
|
|
264
|
-
|
|
265
|
-
|
|
308
|
+
<ChartClipPath disabled={!brush}>
|
|
309
|
+
<ChartAnnotations
|
|
310
|
+
{annotations}
|
|
311
|
+
layer="below"
|
|
312
|
+
highlightKey={seriesState.highlightKey.current}
|
|
313
|
+
visibleSeries={seriesState.visibleSeries}
|
|
314
|
+
/>
|
|
266
315
|
|
|
267
|
-
|
|
268
|
-
{#each visibleSeries as s, i (s.key)}
|
|
269
|
-
<Points {...getPointsProps(s, i)} />
|
|
270
|
-
{/each}
|
|
271
|
-
</slot>
|
|
316
|
+
{@render belowMarks?.(snippetProps)}
|
|
272
317
|
|
|
273
|
-
|
|
274
|
-
|
|
318
|
+
{#if typeof marks === 'function'}
|
|
319
|
+
{@render marks(snippetProps)}
|
|
320
|
+
{:else}
|
|
321
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
322
|
+
<Points {...getPointsProps(s, i)} />
|
|
323
|
+
{/each}
|
|
324
|
+
{/if}
|
|
275
325
|
|
|
276
|
-
|
|
277
|
-
|
|
326
|
+
{@render aboveMarks?.(snippetProps)}
|
|
327
|
+
</ChartClipPath>
|
|
328
|
+
|
|
329
|
+
{#if typeof axis === 'function'}
|
|
330
|
+
{@render axis(snippetProps)}
|
|
331
|
+
{#if typeof rule === 'function'}
|
|
332
|
+
{@render rule(snippetProps)}
|
|
333
|
+
{:else if rule}
|
|
334
|
+
<Rule {...getRuleProps()} />
|
|
335
|
+
{/if}
|
|
336
|
+
{:else if axis}
|
|
278
337
|
{#if axis !== 'x'}
|
|
279
|
-
<Axis
|
|
280
|
-
placement="left"
|
|
281
|
-
format={(value) => format(value, undefined, { variant: 'short' })}
|
|
282
|
-
{...typeof axis === 'object' ? axis : null}
|
|
283
|
-
{...props.yAxis}
|
|
284
|
-
/>
|
|
338
|
+
<Axis {...getAxisProps('y')} />
|
|
285
339
|
{/if}
|
|
286
340
|
|
|
287
341
|
{#if axis !== 'y'}
|
|
288
|
-
<Axis
|
|
289
|
-
placement="bottom"
|
|
290
|
-
format={(value) => format(value, undefined, { variant: 'short' })}
|
|
291
|
-
{...typeof axis === 'object' ? axis : null}
|
|
292
|
-
{...props.xAxis}
|
|
293
|
-
/>
|
|
342
|
+
<Axis {...getAxisProps('x')} />
|
|
294
343
|
{/if}
|
|
295
344
|
|
|
296
|
-
{#if rule}
|
|
297
|
-
|
|
345
|
+
{#if typeof rule === 'function'}
|
|
346
|
+
{@render rule(snippetProps)}
|
|
347
|
+
{:else if rule}
|
|
348
|
+
<Rule {...getRuleProps()} />
|
|
298
349
|
{/if}
|
|
299
350
|
{/if}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
351
|
+
|
|
352
|
+
<!-- Use `full` to allow labels on edge to not be cropped (bleed into padding) -->
|
|
353
|
+
<ChartClipPath disabled={!brush} full>
|
|
354
|
+
{#if typeof highlight === 'function'}
|
|
355
|
+
{@render highlight(snippetProps)}
|
|
356
|
+
{:else if highlight}
|
|
357
|
+
<Highlight {...getHighlightProps()} />
|
|
358
|
+
{/if}
|
|
359
|
+
|
|
360
|
+
{#if typeof labels === 'function'}
|
|
361
|
+
{@render labels(snippetProps)}
|
|
362
|
+
{:else if labels}
|
|
363
|
+
{#each seriesState.visibleSeries as s, i (s.key)}
|
|
364
|
+
<Labels {...getLabelsProps(s, i)} />
|
|
365
|
+
{/each}
|
|
366
|
+
{/if}
|
|
367
|
+
|
|
368
|
+
<ChartAnnotations
|
|
369
|
+
{annotations}
|
|
370
|
+
layer="above"
|
|
371
|
+
highlightKey={seriesState.highlightKey.current}
|
|
372
|
+
visibleSeries={seriesState.visibleSeries}
|
|
313
373
|
/>
|
|
314
|
-
</
|
|
374
|
+
</ChartClipPath>
|
|
375
|
+
</Layer>
|
|
315
376
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
</svelte:component>
|
|
323
|
-
|
|
324
|
-
<slot name="aboveContext" {...slotProps} />
|
|
325
|
-
|
|
326
|
-
<slot name="legend" {...slotProps}>
|
|
327
|
-
{#if legend}
|
|
328
|
-
<Legend
|
|
329
|
-
scale={isDefaultSeries
|
|
330
|
-
? undefined
|
|
331
|
-
: scaleOrdinal(
|
|
332
|
-
series.map((s) => s.key),
|
|
333
|
-
series.map((s) => s.color)
|
|
334
|
-
)}
|
|
335
|
-
tickFormat={(key) => series.find((s) => s.key === key)?.label ?? key}
|
|
336
|
-
placement="bottom"
|
|
337
|
-
variant="swatches"
|
|
338
|
-
onclick={(e, item) => $selectedSeries.toggleSelected(item.value)}
|
|
339
|
-
onpointerenter={(e, item) => (highlightSeriesKey = item.value)}
|
|
340
|
-
onpointerleave={(e) => (highlightSeriesKey = null)}
|
|
341
|
-
{...props.legend}
|
|
342
|
-
{...typeof legend === 'object' ? legend : null}
|
|
343
|
-
classes={{
|
|
344
|
-
item: (item) =>
|
|
345
|
-
visibleSeries.length && !visibleSeries.some((s) => s.key === item.value)
|
|
346
|
-
? 'opacity-50'
|
|
347
|
-
: '',
|
|
348
|
-
...props.legend?.classes,
|
|
349
|
-
...(typeof legend === 'object' ? legend.classes : null),
|
|
350
|
-
}}
|
|
351
|
-
/>
|
|
377
|
+
{@render aboveContext?.(snippetProps)}
|
|
378
|
+
|
|
379
|
+
{#if typeof legend === 'function'}
|
|
380
|
+
{@render legend(snippetProps)}
|
|
381
|
+
{:else if legend}
|
|
382
|
+
<Legend {...getLegendProps()} />
|
|
352
383
|
{/if}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
{
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
{
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
384
|
+
|
|
385
|
+
{#if typeof tooltip === 'function'}
|
|
386
|
+
{@render tooltip(snippetProps)}
|
|
387
|
+
{:else if tooltip}
|
|
388
|
+
<Tooltip.Root {context} {...props.tooltip?.root}>
|
|
389
|
+
{#snippet children({ data })}
|
|
390
|
+
{#if activeSeries?.key !== 'default'}
|
|
391
|
+
<Tooltip.Header
|
|
392
|
+
value={activeSeries?.label ?? activeSeries?.key}
|
|
393
|
+
color={activeSeries?.color}
|
|
394
|
+
{...props.tooltip?.header}
|
|
395
|
+
/>
|
|
396
|
+
{/if}
|
|
397
|
+
<Tooltip.List {...props.tooltip?.list}>
|
|
398
|
+
<Tooltip.Item
|
|
399
|
+
label={typeof context.config.x === 'string' ? context.config.x : 'x'}
|
|
400
|
+
value={context.x(data)}
|
|
401
|
+
{format}
|
|
402
|
+
onpointerenter={() =>
|
|
403
|
+
(seriesState.highlightKey.current = activeSeries?.key ?? null)}
|
|
404
|
+
onpointerleave={() => (seriesState.highlightKey.current = null)}
|
|
405
|
+
{...props.tooltip?.item}
|
|
406
|
+
/>
|
|
407
|
+
<Tooltip.Item
|
|
408
|
+
label={typeof context.config.y === 'string' ? context.config.y : 'y'}
|
|
409
|
+
value={context.y(data)}
|
|
410
|
+
{format}
|
|
411
|
+
onpointerenter={() =>
|
|
412
|
+
(seriesState.highlightKey.current = activeSeries?.key ?? null)}
|
|
413
|
+
onpointerleave={() => (seriesState.highlightKey.current = null)}
|
|
414
|
+
{...props.tooltip?.item}
|
|
415
|
+
/>
|
|
416
|
+
{#if context.config.r}
|
|
417
|
+
<Tooltip.Item
|
|
418
|
+
label={typeof context.config.r === 'string' ? context.config.r : 'r'}
|
|
419
|
+
value={context.r(data)}
|
|
420
|
+
{format}
|
|
421
|
+
onpointerenter={() =>
|
|
422
|
+
(seriesState.highlightKey.current = activeSeries?.key ?? null)}
|
|
423
|
+
onpointerleave={() => (seriesState.highlightKey.current = null)}
|
|
424
|
+
{...props.tooltip?.item}
|
|
425
|
+
/>
|
|
426
|
+
{/if}
|
|
427
|
+
</Tooltip.List>
|
|
428
|
+
{/snippet}
|
|
429
|
+
</Tooltip.Root>
|
|
430
|
+
{/if}
|
|
431
|
+
{/if}
|
|
432
|
+
{/snippet}
|
|
395
433
|
</Chart>
|