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
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Spring, Tween } from 'svelte/motion';
|
|
2
|
+
/**
|
|
3
|
+
* Spring motion configuration options
|
|
4
|
+
*/
|
|
5
|
+
export type SpringOptions<T = any> = ConstructorParameters<typeof Spring<T>>[1];
|
|
6
|
+
export type SpringSetOptions = Parameters<(typeof Spring)['prototype']['set']>[1];
|
|
7
|
+
/**
|
|
8
|
+
* Tween motion configuration options
|
|
9
|
+
*/
|
|
10
|
+
export type TweenOptions<T = any> = ConstructorParameters<typeof Tween<T>>[1];
|
|
11
|
+
export type TweenSetOptions = Parameters<(typeof Tween)['prototype']['set']>[1];
|
|
12
|
+
/**
|
|
13
|
+
* MotionNone is a non-animating state container that provides a compatible
|
|
14
|
+
* interface with Spring and Tween, but updates values immediately without animation.
|
|
15
|
+
* This gives us consistent state management whether animations are enabled or not.
|
|
16
|
+
*/
|
|
17
|
+
export type NoneOptions<T = any> = ConstructorParameters<typeof MotionNone<T>>[1];
|
|
18
|
+
export type NoneSetOptions = Parameters<(typeof MotionNone)['prototype']['set']>[1];
|
|
19
|
+
/**
|
|
20
|
+
* Configuration object for Spring animations with additional type discriminator
|
|
21
|
+
*/
|
|
22
|
+
export type MotionSpringOption = ({
|
|
23
|
+
type: 'spring';
|
|
24
|
+
} & SpringOptions) | 'spring';
|
|
25
|
+
/**
|
|
26
|
+
* Configuration object for Tween animations with additional type discriminator
|
|
27
|
+
*/
|
|
28
|
+
export type MotionTweenOption = ({
|
|
29
|
+
type: 'tween';
|
|
30
|
+
} & TweenOptions) | 'tween';
|
|
31
|
+
/**
|
|
32
|
+
* Configuration object for non-animating state with additional type discriminator
|
|
33
|
+
*/
|
|
34
|
+
export type MotionNoneOption = {
|
|
35
|
+
type: 'none';
|
|
36
|
+
} | 'none';
|
|
37
|
+
/**
|
|
38
|
+
* Union type of all possible motion configuration options
|
|
39
|
+
*/
|
|
40
|
+
export type MotionOptions = MotionSpringOption | MotionTweenOption | MotionNoneOption;
|
|
41
|
+
type IsDefault<K> = K extends string ? (string extends K ? true : false) : never;
|
|
42
|
+
/**
|
|
43
|
+
* Motion config that can be either a direct motion config or
|
|
44
|
+
* a map of property names to motion configs
|
|
45
|
+
*/
|
|
46
|
+
export type MotionProp<K extends string = string> = IsDefault<K> extends true ? MotionOptions : MotionOptions | {
|
|
47
|
+
[prop in K]?: MotionOptions;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Extended Spring class that adds a type discriminator to help with
|
|
51
|
+
* type narrowing in our motion system
|
|
52
|
+
*/
|
|
53
|
+
declare class MotionSpring<T = any> extends Spring<T> {
|
|
54
|
+
type: "spring";
|
|
55
|
+
constructor(value: T, options?: SpringOptions<T>);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Extended Tween class that adds a type discriminator to help with
|
|
59
|
+
* type narrowing in our motion system
|
|
60
|
+
*/
|
|
61
|
+
declare class MotionTween<T = any> extends Tween<T> {
|
|
62
|
+
type: "tween";
|
|
63
|
+
constructor(value: T, options?: TweenOptions<T>);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* MotionNone is a state container that provides the same interface as
|
|
67
|
+
* Spring and Tween but without any animation logic. Values update immediately.
|
|
68
|
+
*
|
|
69
|
+
* This allows components to use a consistent API regardless of whether
|
|
70
|
+
* animations are enabled or not.
|
|
71
|
+
*/
|
|
72
|
+
declare class MotionNone<T = any> {
|
|
73
|
+
#private;
|
|
74
|
+
type: "none";
|
|
75
|
+
constructor(value: T, _options?: any);
|
|
76
|
+
/**
|
|
77
|
+
* Updates the value immediately and returns a resolved promise
|
|
78
|
+
* to maintain API compatibility with animated motion classes
|
|
79
|
+
*/
|
|
80
|
+
set(value: T, _options?: any): Promise<void>;
|
|
81
|
+
get current(): T;
|
|
82
|
+
get target(): T;
|
|
83
|
+
set target(v: T);
|
|
84
|
+
}
|
|
85
|
+
export type ResolvedTween = {
|
|
86
|
+
type: 'tween';
|
|
87
|
+
options: TweenOptions;
|
|
88
|
+
};
|
|
89
|
+
export type ResolvedSpring = {
|
|
90
|
+
type: 'spring';
|
|
91
|
+
options: SpringOptions;
|
|
92
|
+
};
|
|
93
|
+
export type ResolvedNone = {
|
|
94
|
+
type: 'none';
|
|
95
|
+
options: {};
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Union type of all possible resolved motion configurations
|
|
99
|
+
*/
|
|
100
|
+
export type ResolvedMotion = ResolvedSpring | ResolvedTween | ResolvedNone;
|
|
101
|
+
/**
|
|
102
|
+
* Internal options for motion state configuration
|
|
103
|
+
*/
|
|
104
|
+
type InternalMotionOptions = {
|
|
105
|
+
/**
|
|
106
|
+
* When true, the motion state will only update when explicitly set
|
|
107
|
+
* rather than automatically tracking changes to the source value
|
|
108
|
+
*/
|
|
109
|
+
controlled?: boolean;
|
|
110
|
+
};
|
|
111
|
+
export declare function createMotion<T = any>(initialValue: T, getValue: () => T, motionProp: MotionOptions | undefined, options?: InternalMotionOptions): MotionSpring<T> | MotionTween<any> | MotionNone<T>;
|
|
112
|
+
/**
|
|
113
|
+
* Creates a controlled motion state that only updates when explicitly set
|
|
114
|
+
* rather than automatically tracking changes to the source value
|
|
115
|
+
*/
|
|
116
|
+
export declare function createControlledMotion<T = any>(initialValue: T, motionProp: MotionOptions | undefined): MotionTween<any> | MotionSpring<T> | MotionNone<T>;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a state tracker for animation completion
|
|
119
|
+
* This helps track whether any motion transitions are currently in progress
|
|
120
|
+
*
|
|
121
|
+
* @returns an object with methods to handle animation promises and check current status
|
|
122
|
+
*/
|
|
123
|
+
export declare function createMotionTracker(): {
|
|
124
|
+
handle: (promise: Promise<void> | void) => void;
|
|
125
|
+
readonly current: boolean;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Extracts tween configuration from a motion prop
|
|
129
|
+
* @returns Resolved tween configuration or undefined if not a tween
|
|
130
|
+
*/
|
|
131
|
+
export declare function extractTweenConfig<T extends string = never>(prop?: MotionProp<T> | undefined): ResolvedTween | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Parses and normalizes a motion configuration into a standard format
|
|
134
|
+
*
|
|
135
|
+
* @param config - The motion configuration to parse
|
|
136
|
+
* @param propertyKey - Optional property key when config is a map of properties
|
|
137
|
+
* @returns A standardized motion configuration object
|
|
138
|
+
*/
|
|
139
|
+
export declare function parseMotionProp<T extends string = never>(config: MotionProp<T> | undefined | ResolvedMotion, accessor?: string): ResolvedMotion;
|
|
140
|
+
export {};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { Spring, Tween } from 'svelte/motion';
|
|
2
|
+
import { afterTick } from './afterTick.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extended Spring class that adds a type discriminator to help with
|
|
5
|
+
* type narrowing in our motion system
|
|
6
|
+
*/
|
|
7
|
+
class MotionSpring extends Spring {
|
|
8
|
+
type = 'spring';
|
|
9
|
+
constructor(value, options) {
|
|
10
|
+
super(value, options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Extended Tween class that adds a type discriminator to help with
|
|
15
|
+
* type narrowing in our motion system
|
|
16
|
+
*/
|
|
17
|
+
class MotionTween extends Tween {
|
|
18
|
+
type = 'tween';
|
|
19
|
+
constructor(value, options) {
|
|
20
|
+
super(value, options);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* MotionNone is a state container that provides the same interface as
|
|
25
|
+
* Spring and Tween but without any animation logic. Values update immediately.
|
|
26
|
+
*
|
|
27
|
+
* This allows components to use a consistent API regardless of whether
|
|
28
|
+
* animations are enabled or not.
|
|
29
|
+
*/
|
|
30
|
+
class MotionNone {
|
|
31
|
+
type = 'none';
|
|
32
|
+
#current = $state(null);
|
|
33
|
+
#target = $state(null);
|
|
34
|
+
constructor(value, _options = {}) {
|
|
35
|
+
this.#current = value;
|
|
36
|
+
this.#target = value;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Updates the value immediately and returns a resolved promise
|
|
40
|
+
* to maintain API compatibility with animated motion classes
|
|
41
|
+
*/
|
|
42
|
+
set(value, _options = {}) {
|
|
43
|
+
this.#current = value;
|
|
44
|
+
this.#target = value;
|
|
45
|
+
return Promise.resolve();
|
|
46
|
+
}
|
|
47
|
+
get current() {
|
|
48
|
+
return this.#current;
|
|
49
|
+
}
|
|
50
|
+
get target() {
|
|
51
|
+
return this.#target;
|
|
52
|
+
}
|
|
53
|
+
set target(v) {
|
|
54
|
+
this.set(v);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Sets up automatic tracking between a source value and a motion state.
|
|
59
|
+
* When the `controlled` option is `true`, the motion state will not update
|
|
60
|
+
* automatically and will only update when explicitly set.
|
|
61
|
+
*/
|
|
62
|
+
function setupTracking(motion, getValue, options) {
|
|
63
|
+
if (options.controlled)
|
|
64
|
+
return;
|
|
65
|
+
$effect(() => {
|
|
66
|
+
motion.set(getValue());
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export function createMotion(initialValue, getValue, motionProp, options = {}) {
|
|
70
|
+
const motion = parseMotionProp(motionProp);
|
|
71
|
+
const motionState = motion.type === 'spring'
|
|
72
|
+
? new MotionSpring(initialValue, motion.options)
|
|
73
|
+
: motion.type === 'tween'
|
|
74
|
+
? new MotionTween(initialValue, motion.options)
|
|
75
|
+
: new MotionNone(initialValue);
|
|
76
|
+
setupTracking(motionState, getValue, options);
|
|
77
|
+
return motionState;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates a controlled motion state that only updates when explicitly set
|
|
81
|
+
* rather than automatically tracking changes to the source value
|
|
82
|
+
*/
|
|
83
|
+
export function createControlledMotion(initialValue, motionProp) {
|
|
84
|
+
return createMotion(initialValue, () => initialValue, motionProp, { controlled: true });
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates a state tracker for animation completion
|
|
88
|
+
* This helps track whether any motion transitions are currently in progress
|
|
89
|
+
*
|
|
90
|
+
* @returns an object with methods to handle animation promises and check current status
|
|
91
|
+
*/
|
|
92
|
+
export function createMotionTracker() {
|
|
93
|
+
let latestIndex = 0;
|
|
94
|
+
let current = $state(false);
|
|
95
|
+
function handle(promise) {
|
|
96
|
+
latestIndex += 1;
|
|
97
|
+
if (!promise) {
|
|
98
|
+
current = false;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
let currIndex = latestIndex;
|
|
102
|
+
current = true;
|
|
103
|
+
promise
|
|
104
|
+
.then(() => {
|
|
105
|
+
if (currIndex === latestIndex) {
|
|
106
|
+
current = false;
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
.catch(() => { });
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
handle,
|
|
113
|
+
get current() {
|
|
114
|
+
return current;
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Extracts tween configuration from a motion prop
|
|
120
|
+
* @returns Resolved tween configuration or undefined if not a tween
|
|
121
|
+
*/
|
|
122
|
+
export function extractTweenConfig(prop) {
|
|
123
|
+
const resolved = parseMotionProp(prop);
|
|
124
|
+
if (resolved.type === 'tween')
|
|
125
|
+
return resolved;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Parses and normalizes a motion configuration into a standard format
|
|
129
|
+
*
|
|
130
|
+
* @param config - The motion configuration to parse
|
|
131
|
+
* @param propertyKey - Optional property key when config is a map of properties
|
|
132
|
+
* @returns A standardized motion configuration object
|
|
133
|
+
*/
|
|
134
|
+
export function parseMotionProp(config, accessor) {
|
|
135
|
+
if (typeof config === 'object' && 'type' in config && 'options' in config) {
|
|
136
|
+
if (typeof config.options === 'object')
|
|
137
|
+
return config;
|
|
138
|
+
return { type: config.type, options: {} };
|
|
139
|
+
}
|
|
140
|
+
// Default to no animation if no configuration provided
|
|
141
|
+
if (config === undefined)
|
|
142
|
+
return { type: 'none', options: {} };
|
|
143
|
+
// Case 1: string shorthand ('spring', 'tween', 'none')
|
|
144
|
+
if (typeof config === 'string') {
|
|
145
|
+
if (config === 'spring') {
|
|
146
|
+
return { type: 'spring', options: {} };
|
|
147
|
+
}
|
|
148
|
+
else if (config === 'tween') {
|
|
149
|
+
return { type: 'tween', options: {} };
|
|
150
|
+
}
|
|
151
|
+
return { type: 'none', options: {} };
|
|
152
|
+
}
|
|
153
|
+
// Case 2: Object with explicit type property
|
|
154
|
+
if (typeof config === 'object' && 'type' in config) {
|
|
155
|
+
if (config.type === 'spring') {
|
|
156
|
+
const { type, ...options } = config;
|
|
157
|
+
return { type: 'spring', options };
|
|
158
|
+
}
|
|
159
|
+
else if (config.type === 'tween') {
|
|
160
|
+
const { type, ...options } = config;
|
|
161
|
+
return { type: 'tween', options };
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
return { type: 'none', options: {} };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// Case 3: Property map object, lookup by property key
|
|
168
|
+
// We've already established config is an object at this point
|
|
169
|
+
if (accessor) {
|
|
170
|
+
const propConfig = config[accessor];
|
|
171
|
+
if (propConfig !== undefined) {
|
|
172
|
+
return parseMotionProp(propConfig);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// Fallback to no animation
|
|
176
|
+
return {
|
|
177
|
+
type: 'none',
|
|
178
|
+
options: {},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { parseMotionProp, extractTweenConfig } from './motion.svelte.js';
|
|
3
|
+
describe('parseMotionProp', () => {
|
|
4
|
+
it('should return "none" type when config is undefined', () => {
|
|
5
|
+
const result = parseMotionProp(undefined);
|
|
6
|
+
expect(result).toEqual({ type: 'none', options: {} });
|
|
7
|
+
});
|
|
8
|
+
it('should return an already resolved motion object that may have been parsed earlier in the chain', () => {
|
|
9
|
+
const resolvedMotion = {
|
|
10
|
+
type: 'spring',
|
|
11
|
+
options: {
|
|
12
|
+
stiffness: 0.5,
|
|
13
|
+
damping: 0.8,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const result = parseMotionProp(resolvedMotion);
|
|
17
|
+
expect(result).toEqual(resolvedMotion);
|
|
18
|
+
});
|
|
19
|
+
describe('string input handling', () => {
|
|
20
|
+
it('should handle "spring" string shorthand', () => {
|
|
21
|
+
const result = parseMotionProp('spring');
|
|
22
|
+
expect(result).toEqual({ type: 'spring', options: {} });
|
|
23
|
+
});
|
|
24
|
+
it('should handle "tween" string shorthand', () => {
|
|
25
|
+
const result = parseMotionProp('tween');
|
|
26
|
+
expect(result).toEqual({ type: 'tween', options: {} });
|
|
27
|
+
});
|
|
28
|
+
it('should handle "none" string shorthand', () => {
|
|
29
|
+
const result = parseMotionProp('none');
|
|
30
|
+
expect(result).toEqual({ type: 'none', options: {} });
|
|
31
|
+
});
|
|
32
|
+
it('should default to "none" for invalid string values', () => {
|
|
33
|
+
const result = parseMotionProp('invalid');
|
|
34
|
+
expect(result).toEqual({ type: 'none', options: {} });
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('object with type property', () => {
|
|
38
|
+
it('should handle spring object with options', () => {
|
|
39
|
+
const springConfig = {
|
|
40
|
+
type: 'spring',
|
|
41
|
+
stiffness: 0.5,
|
|
42
|
+
damping: 0.8,
|
|
43
|
+
};
|
|
44
|
+
const result = parseMotionProp(springConfig);
|
|
45
|
+
expect(result).toEqual({
|
|
46
|
+
type: 'spring',
|
|
47
|
+
options: { stiffness: 0.5, damping: 0.8 },
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
it('should handle tween object with options', () => {
|
|
51
|
+
const tweenConfig = {
|
|
52
|
+
type: 'tween',
|
|
53
|
+
duration: 300,
|
|
54
|
+
easing: (t) => t,
|
|
55
|
+
};
|
|
56
|
+
const result = parseMotionProp(tweenConfig);
|
|
57
|
+
expect(result).toEqual({
|
|
58
|
+
type: 'tween',
|
|
59
|
+
options: { duration: 300, easing: expect.any(Function) },
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
it('should handle none object', () => {
|
|
63
|
+
const noneConfig = {
|
|
64
|
+
type: 'none',
|
|
65
|
+
};
|
|
66
|
+
const result = parseMotionProp(noneConfig);
|
|
67
|
+
expect(result).toEqual({ type: 'none', options: {} });
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('property map object with accessor', () => {
|
|
71
|
+
it('should extract a specific property motion config', () => {
|
|
72
|
+
const propMap = {
|
|
73
|
+
x: 'spring',
|
|
74
|
+
y: { type: 'tween', duration: 300 },
|
|
75
|
+
scale: { type: 'spring', stiffness: 0.2 },
|
|
76
|
+
};
|
|
77
|
+
const resultX = parseMotionProp(propMap, 'x');
|
|
78
|
+
expect(resultX).toEqual({ type: 'spring', options: {} });
|
|
79
|
+
const resultY = parseMotionProp(propMap, 'y');
|
|
80
|
+
expect(resultY).toEqual({ type: 'tween', options: { duration: 300 } });
|
|
81
|
+
const resultScale = parseMotionProp(propMap, 'scale');
|
|
82
|
+
expect(resultScale).toEqual({ type: 'spring', options: { stiffness: 0.2 } });
|
|
83
|
+
});
|
|
84
|
+
it('should return "none" type for non-existent accessor', () => {
|
|
85
|
+
const propMap = {
|
|
86
|
+
x: 'spring',
|
|
87
|
+
y: 'tween',
|
|
88
|
+
};
|
|
89
|
+
const result = parseMotionProp(propMap, 'z');
|
|
90
|
+
expect(result).toEqual({ type: 'none', options: {} });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('edge cases', () => {
|
|
94
|
+
it('should handle empty object as "none"', () => {
|
|
95
|
+
const result = parseMotionProp({});
|
|
96
|
+
expect(result).toEqual({ type: 'none', options: {} });
|
|
97
|
+
});
|
|
98
|
+
it('should handle object without type property', () => {
|
|
99
|
+
const invalidObject = {
|
|
100
|
+
stiffness: 0.5,
|
|
101
|
+
damping: 0.8,
|
|
102
|
+
};
|
|
103
|
+
const result = parseMotionProp(invalidObject);
|
|
104
|
+
expect(result).toEqual({ type: 'none', options: {} });
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
// Test case 6: Type Generic
|
|
108
|
+
describe('type generic parameter', () => {
|
|
109
|
+
it('should work with explicit generic type parameter', () => {
|
|
110
|
+
const propMap = {
|
|
111
|
+
x: 'spring',
|
|
112
|
+
y: 'tween',
|
|
113
|
+
scale: { type: 'spring', stiffness: 0.3 },
|
|
114
|
+
};
|
|
115
|
+
const result = parseMotionProp(propMap, 'x');
|
|
116
|
+
expect(result).toEqual({ type: 'spring', options: {} });
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
describe('extractTweenConfig', () => {
|
|
121
|
+
// Test case 1: Undefined input
|
|
122
|
+
it('should return undefined when config is undefined', () => {
|
|
123
|
+
const result = extractTweenConfig(undefined);
|
|
124
|
+
expect(result).toBeUndefined();
|
|
125
|
+
});
|
|
126
|
+
// Test case 2: String inputs
|
|
127
|
+
describe('string input handling', () => {
|
|
128
|
+
it('should extract tween config from "tween" string shorthand', () => {
|
|
129
|
+
const result = extractTweenConfig('tween');
|
|
130
|
+
expect(result).toEqual({ type: 'tween', options: {} });
|
|
131
|
+
});
|
|
132
|
+
it('should return undefined for "spring" string shorthand', () => {
|
|
133
|
+
const result = extractTweenConfig('spring');
|
|
134
|
+
expect(result).toBeUndefined();
|
|
135
|
+
});
|
|
136
|
+
it('should return undefined for "none" string shorthand', () => {
|
|
137
|
+
const result = extractTweenConfig('none');
|
|
138
|
+
expect(result).toBeUndefined();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
// Test case 3: Object with type property
|
|
142
|
+
describe('object with type property', () => {
|
|
143
|
+
it('should extract tween object with options', () => {
|
|
144
|
+
const tweenConfig = {
|
|
145
|
+
type: 'tween',
|
|
146
|
+
duration: 300,
|
|
147
|
+
easing: (t) => t,
|
|
148
|
+
};
|
|
149
|
+
const result = extractTweenConfig(tweenConfig);
|
|
150
|
+
expect(result).toEqual({
|
|
151
|
+
type: 'tween',
|
|
152
|
+
options: { duration: 300, easing: expect.any(Function) },
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
it('should return undefined for spring object', () => {
|
|
156
|
+
const springConfig = {
|
|
157
|
+
type: 'spring',
|
|
158
|
+
stiffness: 0.5,
|
|
159
|
+
damping: 0.8,
|
|
160
|
+
};
|
|
161
|
+
const result = extractTweenConfig(springConfig);
|
|
162
|
+
expect(result).toBeUndefined();
|
|
163
|
+
});
|
|
164
|
+
it('should return undefined for none object', () => {
|
|
165
|
+
const noneConfig = {
|
|
166
|
+
type: 'none',
|
|
167
|
+
};
|
|
168
|
+
const result = extractTweenConfig(noneConfig);
|
|
169
|
+
expect(result).toBeUndefined();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
// Test case 4: Property map object (without accessor)
|
|
173
|
+
describe('property map object without accessor', () => {
|
|
174
|
+
it('should return undefined for property map objects without accessor', () => {
|
|
175
|
+
const propMap = {
|
|
176
|
+
x: 'tween',
|
|
177
|
+
y: { type: 'tween', duration: 300 },
|
|
178
|
+
scale: { type: 'spring', stiffness: 0.2 },
|
|
179
|
+
};
|
|
180
|
+
const result = extractTweenConfig(propMap);
|
|
181
|
+
expect(result).toBeUndefined();
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
// Test case 6: Edge cases
|
|
185
|
+
describe('edge cases', () => {
|
|
186
|
+
it('should handle empty object', () => {
|
|
187
|
+
const result = extractTweenConfig({});
|
|
188
|
+
expect(result).toBeUndefined();
|
|
189
|
+
});
|
|
190
|
+
it('should handle object without type property', () => {
|
|
191
|
+
const invalidObject = {
|
|
192
|
+
duration: 300,
|
|
193
|
+
easing: (t) => t,
|
|
194
|
+
};
|
|
195
|
+
const result = extractTweenConfig(invalidObject);
|
|
196
|
+
expect(result).toBeUndefined();
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
describe('with generic type parameter', () => {
|
|
200
|
+
it('should work with explicit generic type parameter', () => {
|
|
201
|
+
const propMap = {
|
|
202
|
+
x: 'tween',
|
|
203
|
+
y: { type: 'tween', duration: 400 },
|
|
204
|
+
scale: 'spring',
|
|
205
|
+
};
|
|
206
|
+
// The extractTweenConfig function doesn't directly support accessors,
|
|
207
|
+
// so for this case we manually extract the property first
|
|
208
|
+
const xConfig = propMap.x;
|
|
209
|
+
const result = extractTweenConfig(xConfig);
|
|
210
|
+
expect(result).toEqual({ type: 'tween', options: {} });
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChartContextValue } from '../components/Chart.svelte';
|
|
2
2
|
import { type Accessor } from './common.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* A set of inset distances, applied to a rectangle to shrink or expand
|
|
5
|
+
* the area represented by that rectangle.
|
|
6
|
+
*/
|
|
4
7
|
export type Insets = {
|
|
5
8
|
/** Applies an inset all sides of a rectangle: `left`, `right`, `bottom`, and `top` */
|
|
6
9
|
all?: number;
|
|
@@ -28,12 +31,12 @@ type DimensionGetterOptions = {
|
|
|
28
31
|
y1?: Accessor;
|
|
29
32
|
insets?: Insets;
|
|
30
33
|
};
|
|
31
|
-
export declare function createDimensionGetter<TData>(
|
|
34
|
+
export declare function createDimensionGetter<TData>(ctx: ChartContextValue<TData>, getOptions?: () => DimensionGetterOptions): (item: TData) => {
|
|
32
35
|
x: any;
|
|
33
36
|
y: any;
|
|
34
37
|
width: number;
|
|
35
38
|
height: number;
|
|
36
|
-
}
|
|
39
|
+
};
|
|
37
40
|
/**
|
|
38
41
|
* If value is an array, returns first item, else returns original value
|
|
39
42
|
* Useful when x/y getters for band scale are an array (such as for histograms)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { accessor } from './common.js';
|
|
2
|
+
import { isScaleBand } from './scales.svelte.js';
|
|
3
|
+
import { max, min } from 'd3-array';
|
|
4
|
+
function resolveInsets(insets) {
|
|
5
|
+
const all = insets?.all ?? 0;
|
|
6
|
+
const x = insets?.x ?? all;
|
|
7
|
+
const y = insets?.y ?? all;
|
|
8
|
+
const left = insets?.left ?? x;
|
|
9
|
+
const right = insets?.right ?? x;
|
|
10
|
+
const top = insets?.top ?? y;
|
|
11
|
+
const bottom = insets?.bottom ?? y;
|
|
12
|
+
return { left, right, bottom, top };
|
|
13
|
+
}
|
|
14
|
+
export function createDimensionGetter(ctx, getOptions) {
|
|
15
|
+
const options = $derived(getOptions?.());
|
|
16
|
+
return (item) => {
|
|
17
|
+
const insets = resolveInsets(options?.insets);
|
|
18
|
+
// Use `xscale.domain()` instead of `$xDomain` to include `nice()` being applied
|
|
19
|
+
const xDomainMinMax = ctx.xScale.domain();
|
|
20
|
+
const yDomainMinMax = ctx.yScale.domain();
|
|
21
|
+
const _x = accessor(options?.x ?? ctx.x);
|
|
22
|
+
const _y = accessor(options?.y ?? ctx.y);
|
|
23
|
+
const _x1 = accessor(options?.x1 ?? ctx.x1);
|
|
24
|
+
const _y1 = accessor(options?.y1 ?? ctx.y1);
|
|
25
|
+
if (isScaleBand(ctx.yScale)) {
|
|
26
|
+
// Horizontal band
|
|
27
|
+
const y = firstValue(ctx.yScale(_y(item)) ?? 0) +
|
|
28
|
+
(ctx.y1Scale ? ctx.y1Scale(_y1(item)) : 0) +
|
|
29
|
+
insets.top;
|
|
30
|
+
const height = Math.max(0, ctx.yScale.bandwidth
|
|
31
|
+
? (ctx.y1Scale ? (ctx.y1Scale.bandwidth?.() ?? 0) : ctx.yScale.bandwidth()) -
|
|
32
|
+
insets.bottom -
|
|
33
|
+
insets.top
|
|
34
|
+
: 0);
|
|
35
|
+
const xValue = _x(item);
|
|
36
|
+
let left = 0;
|
|
37
|
+
let right = 0;
|
|
38
|
+
if (Array.isArray(xValue)) {
|
|
39
|
+
// Array contains both top and bottom values (stack, etc);
|
|
40
|
+
left = min(xValue);
|
|
41
|
+
right = max(xValue);
|
|
42
|
+
}
|
|
43
|
+
else if (xValue == null) {
|
|
44
|
+
// null/undefined value
|
|
45
|
+
left = 0;
|
|
46
|
+
right = 0;
|
|
47
|
+
}
|
|
48
|
+
else if (xValue > 0) {
|
|
49
|
+
// Positive value
|
|
50
|
+
left = max([0, xDomainMinMax[0]]);
|
|
51
|
+
right = xValue;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// Negative value
|
|
55
|
+
left = xValue;
|
|
56
|
+
right = min([0, xDomainMinMax[1]]);
|
|
57
|
+
}
|
|
58
|
+
const x = ctx.xScale(left) + insets.left;
|
|
59
|
+
const width = Math.max(0, ctx.xScale(right) - ctx.xScale(left) - insets.left - insets.right);
|
|
60
|
+
return { x, y, width, height };
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// Vertical band or linear
|
|
64
|
+
const x = firstValue(ctx.xScale(_x(item))) + (ctx.x1Scale ? ctx.x1Scale(_x1(item)) : 0) + insets.left;
|
|
65
|
+
const width = Math.max(0, ctx.xScale.bandwidth
|
|
66
|
+
? (ctx.x1Scale ? (ctx.x1Scale.bandwidth?.() ?? 0) : ctx.xScale.bandwidth()) -
|
|
67
|
+
insets.left -
|
|
68
|
+
insets.right
|
|
69
|
+
: 0);
|
|
70
|
+
const yValue = _y(item);
|
|
71
|
+
let top = 0;
|
|
72
|
+
let bottom = 0;
|
|
73
|
+
if (Array.isArray(yValue)) {
|
|
74
|
+
// Array contains both top and bottom values (stack, etc);
|
|
75
|
+
top = max(yValue);
|
|
76
|
+
bottom = min(yValue);
|
|
77
|
+
}
|
|
78
|
+
else if (yValue == null) {
|
|
79
|
+
// null/undefined value
|
|
80
|
+
top = 0;
|
|
81
|
+
bottom = 0;
|
|
82
|
+
}
|
|
83
|
+
else if (yValue > 0) {
|
|
84
|
+
// Positive value
|
|
85
|
+
top = yValue;
|
|
86
|
+
bottom = max([0, yDomainMinMax[0]]);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// Negative value
|
|
90
|
+
top = min([0, yDomainMinMax[1]]);
|
|
91
|
+
bottom = yValue;
|
|
92
|
+
}
|
|
93
|
+
const y = ctx.yScale(top) + insets.top;
|
|
94
|
+
const height = ctx.yScale(bottom) - ctx.yScale(top) - insets.bottom - insets.top;
|
|
95
|
+
return { x, y, width, height };
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* If value is an array, returns first item, else returns original value
|
|
101
|
+
* Useful when x/y getters for band scale are an array (such as for histograms)
|
|
102
|
+
*/
|
|
103
|
+
export function firstValue(value) {
|
|
104
|
+
return Array.isArray(value) ? value[0] : value;
|
|
105
|
+
}
|