layerchart 2.0.0-next.1 → 2.0.0-next.3
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 +283 -180
- package/dist/components/Axis.svelte.d.ts +117 -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 +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 +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 +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 +108 -76
- 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,79 +1,223 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import type { Without } from '../../utils/types.js';
|
|
4
|
+
import type { TooltipPayload } from './tooltipMetaContext.js';
|
|
5
|
+
import type { Placement } from '../types.js';
|
|
6
|
+
|
|
7
|
+
export type Align = 'start' | 'center' | 'end';
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
export type TooltipPropsWithoutHTML<T = any> = {
|
|
10
|
+
/**
|
|
11
|
+
* `x` position of tooltip. By default uses the pointer/mouse, can also snap to data or an
|
|
12
|
+
* explicit fixed position.
|
|
13
|
+
*
|
|
14
|
+
* @default 'pointer'
|
|
15
|
+
*/
|
|
16
|
+
x?: 'pointer' | 'data' | number;
|
|
17
|
+
/**
|
|
18
|
+
* `y` position of tooltip. By default uses the pointer/mouse, can also snap to data or an
|
|
19
|
+
* explicit fixed position.
|
|
20
|
+
*
|
|
21
|
+
* @default 'pointer'
|
|
22
|
+
*/
|
|
23
|
+
y?: 'pointer' | 'data' | number;
|
|
9
24
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Offset added to `x` position
|
|
27
|
+
*
|
|
28
|
+
* @default x === 'pointer' ? 10 : 0
|
|
29
|
+
*/
|
|
30
|
+
xOffset?: number;
|
|
14
31
|
|
|
15
|
-
|
|
16
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Offset added to `y` position
|
|
34
|
+
*
|
|
35
|
+
* @default y === 'pointer' ? 10 : 0
|
|
36
|
+
*/
|
|
37
|
+
yOffset?: number;
|
|
17
38
|
|
|
18
|
-
|
|
19
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Align based on edge of tooltip
|
|
41
|
+
*
|
|
42
|
+
* @default 'top-left'
|
|
43
|
+
*/
|
|
44
|
+
anchor?: Placement;
|
|
20
45
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
| 'center'
|
|
28
|
-
| 'right'
|
|
29
|
-
| 'bottom-left'
|
|
30
|
-
| 'bottom'
|
|
31
|
-
| 'bottom-right';
|
|
32
|
-
export let anchor: Placement = 'top-left';
|
|
46
|
+
/**
|
|
47
|
+
* The default motion state of the tooltip.
|
|
48
|
+
*
|
|
49
|
+
* @default "spring"
|
|
50
|
+
*/
|
|
51
|
+
motion?: MotionProp;
|
|
33
52
|
|
|
34
|
-
|
|
35
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Allow pointer events. Disabled by default to reduce accidental selection, but useful to
|
|
55
|
+
* enable to allow interactive tooltips (using `locked`)
|
|
56
|
+
*
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
pointerEvents?: boolean;
|
|
36
60
|
|
|
37
|
-
|
|
38
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Include padding area (ex. axis)
|
|
63
|
+
*
|
|
64
|
+
* @default 'container'
|
|
65
|
+
*/
|
|
66
|
+
contained?: 'container' | 'window' | false;
|
|
39
67
|
|
|
40
|
-
|
|
41
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Tooltip variant
|
|
70
|
+
*
|
|
71
|
+
* @default 'default'
|
|
72
|
+
*/
|
|
73
|
+
variant?: 'default' | 'invert' | 'none';
|
|
42
74
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Classes to apply to the various elements of the tooltip.
|
|
77
|
+
*
|
|
78
|
+
* @default {}
|
|
79
|
+
*/
|
|
80
|
+
classes?: {
|
|
81
|
+
/**
|
|
82
|
+
* Classes to apply to the root tooltip element
|
|
83
|
+
*/
|
|
84
|
+
root?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Classes to apply to the tooltip container element
|
|
87
|
+
*/
|
|
88
|
+
container?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Classes to apply to the tooltip content element
|
|
91
|
+
*/
|
|
92
|
+
content?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Classes to apply to the tooltip header element
|
|
95
|
+
*/
|
|
96
|
+
header?: string;
|
|
97
|
+
};
|
|
49
98
|
|
|
50
|
-
|
|
51
|
-
|
|
99
|
+
children?: Snippet<
|
|
100
|
+
[
|
|
101
|
+
{
|
|
102
|
+
/**
|
|
103
|
+
* The chart data that triggered the tooltip.
|
|
104
|
+
*/
|
|
105
|
+
data: T;
|
|
52
106
|
|
|
53
|
-
|
|
54
|
-
|
|
107
|
+
/**
|
|
108
|
+
* An array of tooltip payloads, each containing data for a specific series,
|
|
109
|
+
* along with their own `payload` property that contains the same data as `data`.
|
|
110
|
+
*
|
|
111
|
+
* This is useful when working with the simplified charts, such as `AreaChart`, `BarChart`,
|
|
112
|
+
* `PieChart`, etc., where series construction is handled internally.
|
|
113
|
+
*/
|
|
114
|
+
payload: TooltipPayload[];
|
|
115
|
+
},
|
|
116
|
+
]
|
|
117
|
+
>;
|
|
55
118
|
|
|
56
|
-
|
|
57
|
-
|
|
119
|
+
/**
|
|
120
|
+
* A reference to the tooltip's outermost `<div>` tag.
|
|
121
|
+
*
|
|
122
|
+
* @bindable
|
|
123
|
+
*/
|
|
124
|
+
rootRef?: HTMLElement;
|
|
58
125
|
|
|
59
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Props to pass to the underlying elements rendered
|
|
128
|
+
* by the Tooltip component
|
|
129
|
+
*/
|
|
130
|
+
props?: {
|
|
131
|
+
/**
|
|
132
|
+
* Props to pass to the root tooltip element
|
|
133
|
+
*/
|
|
134
|
+
root?: HTMLAttributes<HTMLElement>;
|
|
135
|
+
/**
|
|
136
|
+
* Props to pass to the tooltip container element
|
|
137
|
+
*/
|
|
138
|
+
container?: HTMLAttributes<HTMLElement>;
|
|
139
|
+
/**
|
|
140
|
+
* Props to pass to the tooltip content element
|
|
141
|
+
*/
|
|
142
|
+
content?: HTMLAttributes<HTMLElement>;
|
|
143
|
+
};
|
|
60
144
|
|
|
61
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Optionally pass the chart's context to the tooltip to get
|
|
147
|
+
* type inference for the data.
|
|
148
|
+
*/
|
|
149
|
+
context?: ChartContextValue<T, any, any>;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export type TooltipProps<T = any> = TooltipPropsWithoutHTML<T> &
|
|
153
|
+
Without<HTMLAttributes<HTMLElement>, TooltipPropsWithoutHTML<T>>;
|
|
154
|
+
</script>
|
|
155
|
+
|
|
156
|
+
<script lang="ts" generics="T = any">
|
|
157
|
+
import { fade } from 'svelte/transition';
|
|
158
|
+
import { cls } from '@layerstack/tailwind';
|
|
159
|
+
|
|
160
|
+
import { isScaleBand } from '../../utils/scales.svelte.js';
|
|
161
|
+
import { getChartContext, type ChartContextValue } from '../Chart.svelte';
|
|
162
|
+
import { getTooltipContext } from './TooltipContext.svelte';
|
|
163
|
+
import { createMotion, type MotionProp } from '../../utils/motion.svelte.js';
|
|
164
|
+
import { untrack, type Snippet } from 'svelte';
|
|
165
|
+
import { layerClass } from '../../utils/attributes.js';
|
|
166
|
+
|
|
167
|
+
let {
|
|
168
|
+
anchor = 'top-left',
|
|
169
|
+
classes = {},
|
|
170
|
+
contained = 'container',
|
|
171
|
+
motion = 'spring',
|
|
172
|
+
pointerEvents = false,
|
|
173
|
+
variant = 'default',
|
|
174
|
+
x = 'pointer',
|
|
175
|
+
xOffset = x === 'pointer' ? 10 : 0,
|
|
176
|
+
y = 'pointer',
|
|
177
|
+
yOffset = y === 'pointer' ? 10 : 0,
|
|
178
|
+
children,
|
|
179
|
+
rootRef: rootRefProp = $bindable(),
|
|
180
|
+
props = {
|
|
181
|
+
root: {},
|
|
182
|
+
container: {},
|
|
183
|
+
content: {},
|
|
184
|
+
},
|
|
185
|
+
class: className,
|
|
186
|
+
}: TooltipProps<T> = $props();
|
|
187
|
+
|
|
188
|
+
let rootRef = $state<HTMLElement>();
|
|
189
|
+
$effect.pre(() => {
|
|
190
|
+
rootRefProp = rootRef;
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const ctx = getChartContext();
|
|
194
|
+
const tooltipCtx = getTooltipContext();
|
|
195
|
+
|
|
196
|
+
let tooltipWidth = $state(0);
|
|
197
|
+
let tooltipHeight = $state(0);
|
|
198
|
+
|
|
199
|
+
function alignValue(value: number, align: Align, additionalOffset: number, tooltipSize: number) {
|
|
62
200
|
const alignOffset = align === 'center' ? tooltipSize / 2 : align === 'end' ? tooltipSize : 0;
|
|
63
|
-
return value + (align === 'end' ? -
|
|
201
|
+
return value + (align === 'end' ? -additionalOffset : additionalOffset) - alignOffset;
|
|
64
202
|
}
|
|
65
203
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
204
|
+
const positions = $derived.by(() => {
|
|
205
|
+
if (!tooltipCtx.data) {
|
|
206
|
+
// if no data, fallback?
|
|
207
|
+
const tooltipX = untrack(() => tooltipCtx.x);
|
|
208
|
+
const tooltipY = untrack(() => tooltipCtx.y);
|
|
209
|
+
return { x: tooltipX, y: tooltipY };
|
|
210
|
+
}
|
|
211
|
+
const xBandOffset = isScaleBand(ctx.xScale)
|
|
212
|
+
? ctx.xScale.step() / 2 - (ctx.xScale.padding() * ctx.xScale.step()) / 2
|
|
69
213
|
: 0;
|
|
70
214
|
|
|
71
215
|
const xValue: number =
|
|
72
216
|
typeof x === 'number'
|
|
73
217
|
? x
|
|
74
218
|
: x === 'data'
|
|
75
|
-
?
|
|
76
|
-
:
|
|
219
|
+
? ctx.xGet(tooltipCtx.data) + ctx.padding.left + xBandOffset
|
|
220
|
+
: tooltipCtx.x;
|
|
77
221
|
|
|
78
222
|
let xAlign: Align = 'start';
|
|
79
223
|
switch (anchor) {
|
|
@@ -96,15 +240,15 @@
|
|
|
96
240
|
break;
|
|
97
241
|
}
|
|
98
242
|
|
|
99
|
-
const yBandOffset = isScaleBand(
|
|
100
|
-
?
|
|
243
|
+
const yBandOffset = isScaleBand(ctx.yScale)
|
|
244
|
+
? ctx.yScale.step() / 2 - (ctx.yScale.padding() * ctx.yScale.step()) / 2
|
|
101
245
|
: 0;
|
|
102
246
|
const yValue: number =
|
|
103
247
|
typeof y === 'number'
|
|
104
248
|
? y
|
|
105
249
|
: y === 'data'
|
|
106
|
-
?
|
|
107
|
-
:
|
|
250
|
+
? ctx.yGet(tooltipCtx.data) + ctx.padding.top + yBandOffset
|
|
251
|
+
: tooltipCtx.y;
|
|
108
252
|
|
|
109
253
|
let yAlign: Align = 'start';
|
|
110
254
|
switch (anchor) {
|
|
@@ -138,23 +282,23 @@
|
|
|
138
282
|
rect.right = rect.left + tooltipWidth;
|
|
139
283
|
|
|
140
284
|
if (contained === 'container') {
|
|
141
|
-
// Only attempt
|
|
285
|
+
// Only attempt repositioning if not fixed (ie. `pointer`/`data`)
|
|
142
286
|
if (typeof x !== 'number') {
|
|
143
287
|
// Check if outside of container and swap align side accordingly
|
|
144
|
-
if ((xAlign === 'start' || xAlign === 'center') && rect.right >
|
|
288
|
+
if ((xAlign === 'start' || xAlign === 'center') && rect.right > ctx.containerWidth) {
|
|
145
289
|
rect.left = alignValue(xValue, 'end', xOffset, tooltipWidth);
|
|
146
290
|
}
|
|
147
|
-
if ((xAlign === 'end' || xAlign === 'center') && rect.left <
|
|
291
|
+
if ((xAlign === 'end' || xAlign === 'center') && rect.left < ctx.padding.left) {
|
|
148
292
|
rect.left = alignValue(xValue, 'start', xOffset, tooltipWidth);
|
|
149
293
|
}
|
|
150
294
|
}
|
|
151
295
|
rect.right = rect.left + tooltipWidth;
|
|
152
296
|
|
|
153
297
|
if (typeof y !== 'number') {
|
|
154
|
-
if ((yAlign === 'start' || yAlign === 'center') && rect.bottom >
|
|
298
|
+
if ((yAlign === 'start' || yAlign === 'center') && rect.bottom > ctx.containerHeight) {
|
|
155
299
|
rect.top = alignValue(yValue, 'end', yOffset, tooltipHeight);
|
|
156
300
|
}
|
|
157
|
-
if ((yAlign === 'end' || yAlign === 'center') && rect.top <
|
|
301
|
+
if ((yAlign === 'end' || yAlign === 'center') && rect.top < ctx.padding.top) {
|
|
158
302
|
rect.top = alignValue(yValue, 'start', yOffset, tooltipHeight);
|
|
159
303
|
}
|
|
160
304
|
}
|
|
@@ -162,10 +306,10 @@
|
|
|
162
306
|
} else if (contained === 'window') {
|
|
163
307
|
// Check if outside of window / viewport and swap align side accordingly
|
|
164
308
|
// Root <div> won't be available on initial mount
|
|
165
|
-
if (
|
|
166
|
-
const parentViewportRect =
|
|
309
|
+
if (rootRef?.parentElement) {
|
|
310
|
+
const parentViewportRect = rootRef.parentElement.getBoundingClientRect();
|
|
167
311
|
|
|
168
|
-
// Only attempt
|
|
312
|
+
// Only attempt repositioning if not fixed (ie. `pointer`/`data`)
|
|
169
313
|
if (typeof x !== 'number') {
|
|
170
314
|
if (
|
|
171
315
|
(xAlign === 'start' || xAlign === 'center') &&
|
|
@@ -196,26 +340,49 @@
|
|
|
196
340
|
rect.bottom = rect.top + tooltipHeight;
|
|
197
341
|
}
|
|
198
342
|
}
|
|
343
|
+
return {
|
|
344
|
+
x: rect.left,
|
|
345
|
+
y: rect.top,
|
|
346
|
+
};
|
|
347
|
+
});
|
|
199
348
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
349
|
+
const motionX = createMotion(tooltipCtx.x, () => positions.x, motion);
|
|
350
|
+
const motionY = createMotion(tooltipCtx.y, () => positions.y, motion);
|
|
203
351
|
|
|
204
|
-
|
|
352
|
+
$effect(() => {
|
|
353
|
+
if (!tooltipCtx.data) {
|
|
354
|
+
tooltipCtx.isHoveringTooltipContent = false;
|
|
355
|
+
}
|
|
356
|
+
});
|
|
205
357
|
</script>
|
|
206
358
|
|
|
207
|
-
{#if
|
|
359
|
+
{#if tooltipCtx.data}
|
|
208
360
|
<div
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
361
|
+
{...props.root}
|
|
362
|
+
class={cls(
|
|
363
|
+
layerClass('tooltip-root'),
|
|
364
|
+
'absolute z-50 select-none',
|
|
365
|
+
!pointerEvents && 'pointer-events-none',
|
|
366
|
+
classes.root,
|
|
367
|
+
props.root?.class
|
|
368
|
+
)}
|
|
369
|
+
style:top="{motionY.current}px"
|
|
370
|
+
style:left="{motionX.current}px"
|
|
212
371
|
transition:fade={{ duration: 100 }}
|
|
213
372
|
bind:clientWidth={tooltipWidth}
|
|
214
373
|
bind:clientHeight={tooltipHeight}
|
|
215
|
-
bind:this={
|
|
374
|
+
bind:this={rootRef}
|
|
375
|
+
onpointerenter={() => {
|
|
376
|
+
tooltipCtx.isHoveringTooltipContent = true;
|
|
377
|
+
}}
|
|
378
|
+
onpointerleave={() => {
|
|
379
|
+
tooltipCtx.isHoveringTooltipContent = false;
|
|
380
|
+
}}
|
|
216
381
|
>
|
|
217
382
|
<div
|
|
383
|
+
{...props.container}
|
|
218
384
|
class={cls(
|
|
385
|
+
layerClass('tooltip-container'),
|
|
219
386
|
variant !== 'none' && ['text-sm py-1 px-2 h-full rounded-sm elevation-1'],
|
|
220
387
|
{
|
|
221
388
|
default: [
|
|
@@ -229,12 +396,13 @@
|
|
|
229
396
|
none: '',
|
|
230
397
|
}[variant],
|
|
231
398
|
classes.container,
|
|
232
|
-
|
|
399
|
+
props.container?.class,
|
|
400
|
+
className
|
|
233
401
|
)}
|
|
234
402
|
>
|
|
235
|
-
{#if
|
|
236
|
-
<div class={cls(classes.content)}>
|
|
237
|
-
|
|
403
|
+
{#if children}
|
|
404
|
+
<div {...props.content} class={cls(layerClass('tooltip-content'), classes.content)}>
|
|
405
|
+
{@render children({ data: tooltipCtx.data, payload: tooltipCtx.payload })}
|
|
238
406
|
</div>
|
|
239
407
|
{/if}
|
|
240
408
|
</div>
|
|
@@ -1,35 +1,153 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
import type { Without } from '../../utils/types.js';
|
|
3
|
+
import type { TooltipPayload } from './tooltipMetaContext.js';
|
|
4
|
+
import type { Placement } from '../types.js';
|
|
5
|
+
export type Align = 'start' | 'center' | 'end';
|
|
6
|
+
export type TooltipPropsWithoutHTML<T = any> = {
|
|
7
|
+
/**
|
|
8
|
+
* `x` position of tooltip. By default uses the pointer/mouse, can also snap to data or an
|
|
9
|
+
* explicit fixed position.
|
|
10
|
+
*
|
|
11
|
+
* @default 'pointer'
|
|
12
|
+
*/
|
|
13
|
+
x?: 'pointer' | 'data' | number;
|
|
14
|
+
/**
|
|
15
|
+
* `y` position of tooltip. By default uses the pointer/mouse, can also snap to data or an
|
|
16
|
+
* explicit fixed position.
|
|
17
|
+
*
|
|
18
|
+
* @default 'pointer'
|
|
19
|
+
*/
|
|
20
|
+
y?: 'pointer' | 'data' | number;
|
|
21
|
+
/**
|
|
22
|
+
* Offset added to `x` position
|
|
23
|
+
*
|
|
24
|
+
* @default x === 'pointer' ? 10 : 0
|
|
25
|
+
*/
|
|
26
|
+
xOffset?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Offset added to `y` position
|
|
29
|
+
*
|
|
30
|
+
* @default y === 'pointer' ? 10 : 0
|
|
31
|
+
*/
|
|
32
|
+
yOffset?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Align based on edge of tooltip
|
|
35
|
+
*
|
|
36
|
+
* @default 'top-left'
|
|
37
|
+
*/
|
|
38
|
+
anchor?: Placement;
|
|
39
|
+
/**
|
|
40
|
+
* The default motion state of the tooltip.
|
|
41
|
+
*
|
|
42
|
+
* @default "spring"
|
|
43
|
+
*/
|
|
44
|
+
motion?: MotionProp;
|
|
45
|
+
/**
|
|
46
|
+
* Allow pointer events. Disabled by default to reduce accidental selection, but useful to
|
|
47
|
+
* enable to allow interactive tooltips (using `locked`)
|
|
48
|
+
*
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
pointerEvents?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Include padding area (ex. axis)
|
|
54
|
+
*
|
|
55
|
+
* @default 'container'
|
|
56
|
+
*/
|
|
57
|
+
contained?: 'container' | 'window' | false;
|
|
58
|
+
/**
|
|
59
|
+
* Tooltip variant
|
|
60
|
+
*
|
|
61
|
+
* @default 'default'
|
|
62
|
+
*/
|
|
63
|
+
variant?: 'default' | 'invert' | 'none';
|
|
64
|
+
/**
|
|
65
|
+
* Classes to apply to the various elements of the tooltip.
|
|
66
|
+
*
|
|
67
|
+
* @default {}
|
|
68
|
+
*/
|
|
69
|
+
classes?: {
|
|
70
|
+
/**
|
|
71
|
+
* Classes to apply to the root tooltip element
|
|
72
|
+
*/
|
|
73
|
+
root?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Classes to apply to the tooltip container element
|
|
76
|
+
*/
|
|
77
|
+
container?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Classes to apply to the tooltip content element
|
|
80
|
+
*/
|
|
81
|
+
content?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Classes to apply to the tooltip header element
|
|
84
|
+
*/
|
|
85
|
+
header?: string;
|
|
20
86
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
data:
|
|
27
|
-
|
|
87
|
+
children?: Snippet<[
|
|
88
|
+
{
|
|
89
|
+
/**
|
|
90
|
+
* The chart data that triggered the tooltip.
|
|
91
|
+
*/
|
|
92
|
+
data: T;
|
|
93
|
+
/**
|
|
94
|
+
* An array of tooltip payloads, each containing data for a specific series,
|
|
95
|
+
* along with their own `payload` property that contains the same data as `data`.
|
|
96
|
+
*
|
|
97
|
+
* This is useful when working with the simplified charts, such as `AreaChart`, `BarChart`,
|
|
98
|
+
* `PieChart`, etc., where series construction is handled internally.
|
|
99
|
+
*/
|
|
100
|
+
payload: TooltipPayload[];
|
|
101
|
+
}
|
|
102
|
+
]>;
|
|
103
|
+
/**
|
|
104
|
+
* A reference to the tooltip's outermost `<div>` tag.
|
|
105
|
+
*
|
|
106
|
+
* @bindable
|
|
107
|
+
*/
|
|
108
|
+
rootRef?: HTMLElement;
|
|
109
|
+
/**
|
|
110
|
+
* Props to pass to the underlying elements rendered
|
|
111
|
+
* by the Tooltip component
|
|
112
|
+
*/
|
|
113
|
+
props?: {
|
|
114
|
+
/**
|
|
115
|
+
* Props to pass to the root tooltip element
|
|
116
|
+
*/
|
|
117
|
+
root?: HTMLAttributes<HTMLElement>;
|
|
118
|
+
/**
|
|
119
|
+
* Props to pass to the tooltip container element
|
|
120
|
+
*/
|
|
121
|
+
container?: HTMLAttributes<HTMLElement>;
|
|
122
|
+
/**
|
|
123
|
+
* Props to pass to the tooltip content element
|
|
124
|
+
*/
|
|
125
|
+
content?: HTMLAttributes<HTMLElement>;
|
|
28
126
|
};
|
|
127
|
+
/**
|
|
128
|
+
* Optionally pass the chart's context to the tooltip to get
|
|
129
|
+
* type inference for the data.
|
|
130
|
+
*/
|
|
131
|
+
context?: ChartContextValue<T, any, any>;
|
|
29
132
|
};
|
|
30
|
-
export type TooltipProps =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
133
|
+
export type TooltipProps<T = any> = TooltipPropsWithoutHTML<T> & Without<HTMLAttributes<HTMLElement>, TooltipPropsWithoutHTML<T>>;
|
|
134
|
+
import { type ChartContextValue } from '../Chart.svelte';
|
|
135
|
+
import { type MotionProp } from '../../utils/motion.svelte.js';
|
|
136
|
+
import { type Snippet } from 'svelte';
|
|
137
|
+
declare class __sveltets_Render<T = any> {
|
|
138
|
+
props(): TooltipProps<T>;
|
|
139
|
+
events(): {};
|
|
140
|
+
slots(): {};
|
|
141
|
+
bindings(): "rootRef";
|
|
142
|
+
exports(): {};
|
|
143
|
+
}
|
|
144
|
+
interface $$IsomorphicComponent {
|
|
145
|
+
new <T = any>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
146
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
147
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
148
|
+
<T = any>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
149
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
34
150
|
}
|
|
35
|
-
|
|
151
|
+
declare const Tooltip: $$IsomorphicComponent;
|
|
152
|
+
type Tooltip<T = any> = InstanceType<typeof Tooltip<T>>;
|
|
153
|
+
export default Tooltip;
|