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,148 +1,225 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Transition, TransitionParams, Without } from '../utils/types.js';
|
|
3
|
+
|
|
4
|
+
export type AxisPropsWithoutHTML<In extends Transition = Transition> = {
|
|
5
|
+
/**
|
|
6
|
+
* Location of axis
|
|
7
|
+
*/
|
|
8
|
+
placement: 'top' | 'bottom' | 'left' | 'right' | 'angle' | 'radius';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The label for the axis.
|
|
12
|
+
*
|
|
13
|
+
* Can either be a string or a snippet to render custom content.
|
|
14
|
+
* The snippet receives spreadable props to apply to the label.
|
|
15
|
+
*/
|
|
16
|
+
label?: string | Snippet<[{ props: ComponentProps<typeof Text> }]>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Location of axis label
|
|
20
|
+
* @default 'middle'
|
|
21
|
+
*/
|
|
22
|
+
labelPlacement?: 'start' | 'middle' | 'end';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Props applied to label Text
|
|
26
|
+
*/
|
|
27
|
+
labelProps?: Partial<ComponentProps<typeof Text>>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Draw a rule line. Use Rule component for greater rendering order control
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
rule?: boolean | Partial<ComponentProps<typeof Rule>>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Draw grid lines
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
grid?: boolean | Pick<SVGAttributes<SVGElement>, 'class' | 'style'>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Control the number of ticks
|
|
43
|
+
*/
|
|
44
|
+
ticks?: TicksConfig;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Length of the tick line
|
|
48
|
+
* @default 4
|
|
49
|
+
*/
|
|
50
|
+
tickLength?: number;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Whether to render tick marks.
|
|
54
|
+
*
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
tickMarks?: boolean;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Format tick labels
|
|
61
|
+
*/
|
|
62
|
+
format?: FormatType;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Props to apply to each tick label
|
|
66
|
+
*/
|
|
67
|
+
tickLabelProps?: Partial<ComponentProps<typeof Text>>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A snippet to render your own custom tick label.
|
|
71
|
+
*/
|
|
72
|
+
tickLabel?: Snippet<[{ props: ComponentProps<typeof Text>; index: number }]>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Transition function for entering elements
|
|
76
|
+
* @default defaults to fade if the motion prop is set to tweened
|
|
77
|
+
*/
|
|
78
|
+
transitionIn?: In;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Parameters for the transitionIn function
|
|
82
|
+
* @default { easing: cubicIn }
|
|
83
|
+
*/
|
|
84
|
+
transitionInParams?: TransitionParams<In>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Scale for the axis
|
|
88
|
+
*/
|
|
89
|
+
scale?: any;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Classes for styling various parts of the axis
|
|
93
|
+
* @default {}
|
|
94
|
+
*/
|
|
95
|
+
classes?: {
|
|
96
|
+
root?: string;
|
|
97
|
+
label?: string;
|
|
98
|
+
rule?: string;
|
|
99
|
+
tick?: string;
|
|
100
|
+
tickLabel?: string;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
motion?: MotionProp;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type AxisProps<In extends Transition = Transition> = AxisPropsWithoutHTML<In> &
|
|
107
|
+
Without<SVGAttributes<SVGGElement>, AxisPropsWithoutHTML<In>>;
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
<script lang="ts" generics="T extends Transition = Transition">
|
|
111
|
+
import { type ComponentProps, type Snippet } from 'svelte';
|
|
3
112
|
import { fade } from 'svelte/transition';
|
|
4
113
|
import { cubicIn } from 'svelte/easing';
|
|
5
114
|
import type { SVGAttributes } from 'svelte/elements';
|
|
6
|
-
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
7
|
-
import type { TimeInterval } from 'd3-time';
|
|
8
115
|
|
|
9
116
|
import { extent } from 'd3-array';
|
|
10
117
|
import { pointRadial } from 'd3-shape';
|
|
11
118
|
|
|
12
|
-
import { format as formatValue,
|
|
119
|
+
import { format as formatValue, type FormatType } from '@layerstack/utils';
|
|
13
120
|
import { cls } from '@layerstack/tailwind';
|
|
14
|
-
import type { TransitionParams } from 'svelte-ux'; // TODO: Replace with `@layerstack/svelte-types` or similar
|
|
15
121
|
|
|
16
|
-
import { chartContext } from './ChartContext.svelte';
|
|
17
122
|
import Line from './Line.svelte';
|
|
18
123
|
import Rule from './Rule.svelte';
|
|
19
124
|
import Text from './Text.svelte';
|
|
20
|
-
import { isScaleBand
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
export let spring: boolean | Parameters<typeof springStore>[1] = undefined;
|
|
61
|
-
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
62
|
-
|
|
63
|
-
export let transitionIn = tweened
|
|
64
|
-
? fade
|
|
65
|
-
: () => {
|
|
66
|
-
return {};
|
|
67
|
-
};
|
|
68
|
-
export let transitionInParams: TransitionParams = { easing: cubicIn };
|
|
69
|
-
|
|
70
|
-
$: orientation =
|
|
125
|
+
import { isScaleBand } from '../utils/scales.svelte.js';
|
|
126
|
+
|
|
127
|
+
import { getChartContext } from './Chart.svelte';
|
|
128
|
+
import { extractLayerProps, layerClass } from '../utils/attributes.js';
|
|
129
|
+
import { extractTweenConfig, type MotionProp } from '../utils/motion.svelte.js';
|
|
130
|
+
import { resolveTickVals, type TicksConfig } from '../utils/ticks.js';
|
|
131
|
+
|
|
132
|
+
let {
|
|
133
|
+
placement,
|
|
134
|
+
label = '',
|
|
135
|
+
labelPlacement = 'middle',
|
|
136
|
+
labelProps,
|
|
137
|
+
rule = false,
|
|
138
|
+
grid = false,
|
|
139
|
+
ticks,
|
|
140
|
+
tickLength = 4,
|
|
141
|
+
tickMarks = true,
|
|
142
|
+
format,
|
|
143
|
+
tickLabelProps,
|
|
144
|
+
motion,
|
|
145
|
+
transitionIn: transitionInProp,
|
|
146
|
+
transitionInParams: transitionInParamsProp,
|
|
147
|
+
scale: scaleProp,
|
|
148
|
+
classes = {},
|
|
149
|
+
class: className,
|
|
150
|
+
tickLabel,
|
|
151
|
+
...restProps
|
|
152
|
+
}: AxisProps<T> = $props();
|
|
153
|
+
|
|
154
|
+
const transitionIn = $derived(
|
|
155
|
+
transitionInProp ? transitionInProp : extractTweenConfig(motion)?.options ? fade : () => {}
|
|
156
|
+
) as T;
|
|
157
|
+
const transitionInParams = $derived(
|
|
158
|
+
transitionInParamsProp ? transitionInParamsProp : { easing: cubicIn }
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const ctx = getChartContext();
|
|
162
|
+
|
|
163
|
+
const orientation = $derived(
|
|
71
164
|
placement === 'angle'
|
|
72
165
|
? 'angle'
|
|
73
166
|
: placement === 'radius'
|
|
74
167
|
? 'radius'
|
|
75
168
|
: ['top', 'bottom'].includes(placement)
|
|
76
169
|
? 'horizontal'
|
|
77
|
-
: 'vertical'
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
} = {};
|
|
89
|
-
|
|
90
|
-
$: [xRangeMin, xRangeMax] = extent<number>($xRange) as [number, number];
|
|
91
|
-
$: [yRangeMin, yRangeMax] = extent<number>($yRange) as [number, number];
|
|
92
|
-
|
|
93
|
-
$: tickVals = Array.isArray(ticks)
|
|
94
|
-
? ticks
|
|
95
|
-
: typeof ticks === 'function'
|
|
96
|
-
? ticks(_scale)
|
|
97
|
-
: isLiteralObject(ticks)
|
|
98
|
-
? _scale.ticks(ticks.interval) // d3-time interval such as `timeDay.every(1)`
|
|
99
|
-
: isScaleBand(_scale)
|
|
100
|
-
? ticks
|
|
101
|
-
? _scale.domain().filter((v: any, i: number) => i % ticks === 0)
|
|
102
|
-
: _scale.domain()
|
|
103
|
-
: _scale.ticks(ticks ?? (placement === 'left' || placement === 'right' ? 4 : undefined));
|
|
170
|
+
: 'vertical'
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const scale = $derived(
|
|
174
|
+
scaleProp ?? (['horizontal', 'angle'].includes(orientation) ? ctx.xScale : ctx.yScale)
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const xRangeMinMax = $derived(extent<number>(ctx.xRange)) as [number, number];
|
|
178
|
+
const yRangeMinMax = $derived(extent<number>(ctx.yRange)) as [number, number];
|
|
179
|
+
|
|
180
|
+
const tickVals = $derived(resolveTickVals(scale, ticks, placement));
|
|
104
181
|
|
|
105
182
|
function getCoords(tick: any) {
|
|
106
183
|
switch (placement) {
|
|
107
184
|
case 'top':
|
|
108
185
|
return {
|
|
109
|
-
x:
|
|
110
|
-
y:
|
|
186
|
+
x: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
187
|
+
y: yRangeMinMax[0],
|
|
111
188
|
};
|
|
112
189
|
|
|
113
190
|
case 'bottom':
|
|
114
191
|
return {
|
|
115
|
-
x:
|
|
116
|
-
y:
|
|
192
|
+
x: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
193
|
+
y: yRangeMinMax[1],
|
|
117
194
|
};
|
|
118
195
|
|
|
119
196
|
case 'left':
|
|
120
197
|
return {
|
|
121
|
-
x:
|
|
122
|
-
y:
|
|
198
|
+
x: xRangeMinMax[0],
|
|
199
|
+
y: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
123
200
|
};
|
|
124
201
|
|
|
125
202
|
case 'right':
|
|
126
203
|
return {
|
|
127
|
-
x:
|
|
128
|
-
y:
|
|
204
|
+
x: xRangeMinMax[1],
|
|
205
|
+
y: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
129
206
|
};
|
|
130
207
|
|
|
131
208
|
case 'angle':
|
|
132
209
|
return {
|
|
133
|
-
x:
|
|
134
|
-
y:
|
|
210
|
+
x: scale(tick),
|
|
211
|
+
y: yRangeMinMax[1],
|
|
135
212
|
};
|
|
136
213
|
|
|
137
214
|
case 'radius':
|
|
138
215
|
return {
|
|
139
|
-
x:
|
|
140
|
-
y:
|
|
216
|
+
x: xRangeMinMax[0],
|
|
217
|
+
y: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
141
218
|
};
|
|
142
219
|
}
|
|
143
220
|
}
|
|
144
221
|
|
|
145
|
-
function getDefaultTickLabelProps(tick: any): ComponentProps<Text> {
|
|
222
|
+
function getDefaultTickLabelProps(tick: any): ComponentProps<typeof Text> {
|
|
146
223
|
switch (placement) {
|
|
147
224
|
case 'top':
|
|
148
225
|
return {
|
|
@@ -175,7 +252,7 @@
|
|
|
175
252
|
};
|
|
176
253
|
|
|
177
254
|
case 'angle':
|
|
178
|
-
const xValue =
|
|
255
|
+
const xValue = scale(tick); // angle in radians
|
|
179
256
|
return {
|
|
180
257
|
textAnchor:
|
|
181
258
|
xValue === 0 ||
|
|
@@ -200,59 +277,90 @@
|
|
|
200
277
|
}
|
|
201
278
|
}
|
|
202
279
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
280
|
+
const resolvedLabelX = $derived.by(() => {
|
|
281
|
+
if (placement === 'left' || (orientation === 'horizontal' && labelPlacement === 'start')) {
|
|
282
|
+
return -ctx.padding.left;
|
|
283
|
+
} else if (
|
|
284
|
+
placement === 'right' ||
|
|
285
|
+
(orientation === 'horizontal' && labelPlacement === 'end')
|
|
286
|
+
) {
|
|
287
|
+
return ctx.width + ctx.padding.right;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return ctx.width / 2;
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
const resolvedLabelY = $derived.by(() => {
|
|
294
|
+
if (placement === 'top' || (orientation === 'vertical' && labelPlacement === 'start')) {
|
|
295
|
+
return -ctx.padding.top;
|
|
296
|
+
} else if (orientation === 'vertical' && labelPlacement === 'middle') {
|
|
297
|
+
return ctx.height / 2;
|
|
298
|
+
} else if (placement === 'bottom' || labelPlacement === 'end') {
|
|
299
|
+
return ctx.height + ctx.padding.bottom;
|
|
300
|
+
}
|
|
301
|
+
return '0';
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
const resolvedLabelTextAnchor = $derived.by(() => {
|
|
305
|
+
if (labelPlacement === 'middle') {
|
|
306
|
+
return 'middle';
|
|
307
|
+
} else if (
|
|
308
|
+
placement === 'right' ||
|
|
309
|
+
(orientation === 'horizontal' && labelPlacement === 'end')
|
|
310
|
+
) {
|
|
311
|
+
return 'end';
|
|
312
|
+
}
|
|
313
|
+
return 'start';
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const resolvedLabelVerticalAnchor = $derived.by(() => {
|
|
317
|
+
if (
|
|
226
318
|
placement === 'top' ||
|
|
227
319
|
(orientation === 'vertical' && labelPlacement === 'start') ||
|
|
228
320
|
(placement === 'left' && labelPlacement === 'middle')
|
|
229
|
-
|
|
230
|
-
|
|
321
|
+
) {
|
|
322
|
+
return 'start';
|
|
323
|
+
}
|
|
324
|
+
return 'end';
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
const resolvedLabelProps = $derived({
|
|
328
|
+
value: typeof label === 'function' ? '' : undefined,
|
|
329
|
+
x: resolvedLabelX,
|
|
330
|
+
y: resolvedLabelY,
|
|
331
|
+
textAnchor: resolvedLabelTextAnchor,
|
|
332
|
+
verticalAnchor: resolvedLabelVerticalAnchor,
|
|
231
333
|
rotate: orientation === 'vertical' && labelPlacement === 'middle' ? -90 : 0,
|
|
232
334
|
capHeight: '.5rem', // text-[10px]
|
|
233
335
|
...labelProps,
|
|
234
336
|
class: cls(
|
|
235
|
-
'label
|
|
337
|
+
layerClass('axis-label'),
|
|
338
|
+
'text-[10px] stroke-surface-100 [stroke-width:2px] font-light',
|
|
236
339
|
classes.label,
|
|
237
340
|
labelProps?.class
|
|
238
341
|
),
|
|
239
|
-
} satisfies ComponentProps<Text>;
|
|
342
|
+
}) satisfies ComponentProps<typeof Text>;
|
|
240
343
|
</script>
|
|
241
344
|
|
|
242
|
-
<g
|
|
345
|
+
<g
|
|
346
|
+
{...restProps}
|
|
347
|
+
data-placement={placement}
|
|
348
|
+
class={cls(layerClass('axis'), `placement-${placement}`, classes.root, className)}
|
|
349
|
+
>
|
|
243
350
|
{#if rule !== false}
|
|
244
|
-
{@const ruleProps =
|
|
351
|
+
{@const ruleProps = extractLayerProps(rule, 'axis-rule')}
|
|
245
352
|
<Rule
|
|
246
353
|
x={placement === 'left' || placement === 'right' ? placement : placement === 'angle'}
|
|
247
354
|
y={placement === 'top' || placement === 'bottom' ? placement : placement === 'radius'}
|
|
248
|
-
{
|
|
249
|
-
{spring}
|
|
355
|
+
{motion}
|
|
250
356
|
{...ruleProps}
|
|
251
|
-
class={cls('
|
|
357
|
+
class={cls('stroke-surface-content/50', classes.rule, ruleProps?.class)}
|
|
252
358
|
/>
|
|
253
359
|
{/if}
|
|
254
360
|
|
|
255
|
-
{#if label}
|
|
361
|
+
{#if typeof label === 'function'}
|
|
362
|
+
{@render label({ props: resolvedLabelProps })}
|
|
363
|
+
{:else if label}
|
|
256
364
|
<Text {...resolvedLabelProps} />
|
|
257
365
|
{/if}
|
|
258
366
|
|
|
@@ -266,68 +374,73 @@
|
|
|
266
374
|
{@const resolvedTickLabelProps = {
|
|
267
375
|
x: orientation === 'angle' ? radialTickCoordsX : tickCoords.x,
|
|
268
376
|
y: orientation === 'angle' ? radialTickCoordsY : tickCoords.y,
|
|
269
|
-
value: formatValue(tick, format ??
|
|
377
|
+
value: formatValue(tick, format ?? scale.tickFormat?.() ?? ((v) => v)),
|
|
270
378
|
...getDefaultTickLabelProps(tick),
|
|
271
|
-
|
|
272
|
-
spring,
|
|
379
|
+
motion,
|
|
273
380
|
...tickLabelProps,
|
|
274
381
|
class: cls(
|
|
275
|
-
'
|
|
382
|
+
layerClass('axis-tick-label'),
|
|
383
|
+
'text-[10px] stroke-surface-100 [stroke-width:2px] font-light',
|
|
276
384
|
classes.tickLabel,
|
|
277
385
|
tickLabelProps?.class
|
|
278
386
|
),
|
|
279
387
|
}}
|
|
280
388
|
|
|
281
|
-
<g in:transitionIn={transitionInParams}>
|
|
389
|
+
<g in:transitionIn={transitionInParams} class={layerClass('axis-tick-group')}>
|
|
282
390
|
{#if grid !== false}
|
|
283
|
-
{@const ruleProps =
|
|
391
|
+
{@const ruleProps = extractLayerProps(grid, 'axis-grid')}
|
|
284
392
|
<Rule
|
|
285
393
|
x={orientation === 'horizontal' || orientation === 'angle' ? tick : false}
|
|
286
394
|
y={orientation === 'vertical' || orientation === 'radius' ? tick : false}
|
|
287
|
-
{
|
|
288
|
-
{spring}
|
|
395
|
+
{motion}
|
|
289
396
|
{...ruleProps}
|
|
290
|
-
class={cls('
|
|
397
|
+
class={cls('stroke-surface-content/10', classes.rule, ruleProps?.class)}
|
|
291
398
|
/>
|
|
292
399
|
{/if}
|
|
293
400
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
401
|
+
{#if tickMarks}
|
|
402
|
+
{@const tickClasses = cls(
|
|
403
|
+
layerClass('axis-tick'),
|
|
404
|
+
'stroke-surface-content/50',
|
|
405
|
+
classes.tick
|
|
406
|
+
)}
|
|
407
|
+
<!-- Tick marks -->
|
|
408
|
+
{#if orientation === 'horizontal'}
|
|
409
|
+
<Line
|
|
410
|
+
x1={tickCoords.x}
|
|
411
|
+
y1={tickCoords.y}
|
|
412
|
+
x2={tickCoords.x}
|
|
413
|
+
y2={tickCoords.y + (placement === 'top' ? -tickLength : tickLength)}
|
|
414
|
+
{motion}
|
|
415
|
+
class={tickClasses}
|
|
416
|
+
/>
|
|
417
|
+
{:else if orientation === 'vertical'}
|
|
418
|
+
<Line
|
|
419
|
+
x1={tickCoords.x}
|
|
420
|
+
y1={tickCoords.y}
|
|
421
|
+
x2={tickCoords.x + (placement === 'left' ? -tickLength : tickLength)}
|
|
422
|
+
y2={tickCoords.y}
|
|
423
|
+
{motion}
|
|
424
|
+
class={tickClasses}
|
|
425
|
+
/>
|
|
426
|
+
{:else if orientation === 'angle'}
|
|
427
|
+
<Line
|
|
428
|
+
x1={radialTickCoordsX}
|
|
429
|
+
y1={radialTickCoordsY}
|
|
430
|
+
x2={radialTickMarkCoordsX}
|
|
431
|
+
y2={radialTickMarkCoordsY}
|
|
432
|
+
{motion}
|
|
433
|
+
class={tickClasses}
|
|
434
|
+
/>
|
|
435
|
+
{/if}
|
|
325
436
|
{/if}
|
|
326
437
|
<!-- TODO: Add tick marks for radial (angle)? -->
|
|
327
438
|
|
|
328
|
-
|
|
439
|
+
{#if tickLabel}
|
|
440
|
+
{@render tickLabel({ props: resolvedTickLabelProps, index })}
|
|
441
|
+
{:else}
|
|
329
442
|
<Text {...resolvedTickLabelProps} />
|
|
330
|
-
|
|
443
|
+
{/if}
|
|
331
444
|
</g>
|
|
332
445
|
{/each}
|
|
333
446
|
</g>
|