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,148 +1,217 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
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<GroupProps, AxisPropsWithoutHTML<In>>;
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
<script lang="ts" generics="T extends Transition = Transition">
|
|
111
|
+
import { type ComponentProps, type Snippet } from 'svelte';
|
|
5
112
|
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
113
|
|
|
9
114
|
import { extent } from 'd3-array';
|
|
10
115
|
import { pointRadial } from 'd3-shape';
|
|
11
116
|
|
|
12
|
-
import { format as formatValue,
|
|
117
|
+
import { format as formatValue, type FormatType } from '@layerstack/utils';
|
|
13
118
|
import { cls } from '@layerstack/tailwind';
|
|
14
|
-
import type { TransitionParams } from 'svelte-ux'; // TODO: Replace with `@layerstack/svelte-types` or similar
|
|
15
119
|
|
|
16
|
-
import {
|
|
120
|
+
import Group, { type GroupProps } from './Group.svelte';
|
|
17
121
|
import Line from './Line.svelte';
|
|
18
122
|
import Rule from './Rule.svelte';
|
|
19
123
|
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
|
-
export let tickLength = 4;
|
|
53
|
-
|
|
54
|
-
/** Format tick labels */
|
|
55
|
-
export let format: FormatType | undefined = undefined;
|
|
56
|
-
|
|
57
|
-
/** Props to apply to each tick label */
|
|
58
|
-
export let tickLabelProps: Partial<ComponentProps<Text>> | undefined = undefined;
|
|
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 =
|
|
124
|
+
import { isScaleBand } from '../utils/scales.svelte.js';
|
|
125
|
+
|
|
126
|
+
import { getChartContext } from './Chart.svelte';
|
|
127
|
+
import { extractLayerProps, layerClass } from '../utils/attributes.js';
|
|
128
|
+
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
129
|
+
import { resolveTickVals, type TicksConfig } from '../utils/ticks.js';
|
|
130
|
+
|
|
131
|
+
let {
|
|
132
|
+
placement,
|
|
133
|
+
label = '',
|
|
134
|
+
labelPlacement = 'middle',
|
|
135
|
+
labelProps,
|
|
136
|
+
rule = false,
|
|
137
|
+
grid = false,
|
|
138
|
+
ticks,
|
|
139
|
+
tickLength = 4,
|
|
140
|
+
tickMarks = true,
|
|
141
|
+
format,
|
|
142
|
+
tickLabelProps,
|
|
143
|
+
motion,
|
|
144
|
+
transitionIn,
|
|
145
|
+
transitionInParams,
|
|
146
|
+
scale: scaleProp,
|
|
147
|
+
classes = {},
|
|
148
|
+
class: className,
|
|
149
|
+
tickLabel,
|
|
150
|
+
...restProps
|
|
151
|
+
}: AxisProps<T> = $props();
|
|
152
|
+
|
|
153
|
+
const ctx = getChartContext();
|
|
154
|
+
|
|
155
|
+
const orientation = $derived(
|
|
71
156
|
placement === 'angle'
|
|
72
157
|
? 'angle'
|
|
73
158
|
: placement === 'radius'
|
|
74
159
|
? 'radius'
|
|
75
160
|
: ['top', 'bottom'].includes(placement)
|
|
76
161
|
? '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));
|
|
162
|
+
: 'vertical'
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
const scale = $derived(
|
|
166
|
+
scaleProp ?? (['horizontal', 'angle'].includes(orientation) ? ctx.xScale : ctx.yScale)
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
const xRangeMinMax = $derived(extent<number>(ctx.xRange)) as [number, number];
|
|
170
|
+
const yRangeMinMax = $derived(extent<number>(ctx.yRange)) as [number, number];
|
|
171
|
+
|
|
172
|
+
const tickVals = $derived(resolveTickVals(scale, ticks, placement));
|
|
104
173
|
|
|
105
174
|
function getCoords(tick: any) {
|
|
106
175
|
switch (placement) {
|
|
107
176
|
case 'top':
|
|
108
177
|
return {
|
|
109
|
-
x:
|
|
110
|
-
y:
|
|
178
|
+
x: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
179
|
+
y: yRangeMinMax[0],
|
|
111
180
|
};
|
|
112
181
|
|
|
113
182
|
case 'bottom':
|
|
114
183
|
return {
|
|
115
|
-
x:
|
|
116
|
-
y:
|
|
184
|
+
x: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
185
|
+
y: yRangeMinMax[1],
|
|
117
186
|
};
|
|
118
187
|
|
|
119
188
|
case 'left':
|
|
120
189
|
return {
|
|
121
|
-
x:
|
|
122
|
-
y:
|
|
190
|
+
x: xRangeMinMax[0],
|
|
191
|
+
y: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
123
192
|
};
|
|
124
193
|
|
|
125
194
|
case 'right':
|
|
126
195
|
return {
|
|
127
|
-
x:
|
|
128
|
-
y:
|
|
196
|
+
x: xRangeMinMax[1],
|
|
197
|
+
y: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
129
198
|
};
|
|
130
199
|
|
|
131
200
|
case 'angle':
|
|
132
201
|
return {
|
|
133
|
-
x:
|
|
134
|
-
y:
|
|
202
|
+
x: scale(tick),
|
|
203
|
+
y: yRangeMinMax[1],
|
|
135
204
|
};
|
|
136
205
|
|
|
137
206
|
case 'radius':
|
|
138
207
|
return {
|
|
139
|
-
x:
|
|
140
|
-
y:
|
|
208
|
+
x: xRangeMinMax[0],
|
|
209
|
+
y: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
141
210
|
};
|
|
142
211
|
}
|
|
143
212
|
}
|
|
144
213
|
|
|
145
|
-
function getDefaultTickLabelProps(tick: any): ComponentProps<Text> {
|
|
214
|
+
function getDefaultTickLabelProps(tick: any): ComponentProps<typeof Text> {
|
|
146
215
|
switch (placement) {
|
|
147
216
|
case 'top':
|
|
148
217
|
return {
|
|
@@ -175,7 +244,7 @@
|
|
|
175
244
|
};
|
|
176
245
|
|
|
177
246
|
case 'angle':
|
|
178
|
-
const xValue =
|
|
247
|
+
const xValue = scale(tick); // angle in radians
|
|
179
248
|
return {
|
|
180
249
|
textAnchor:
|
|
181
250
|
xValue === 0 ||
|
|
@@ -200,63 +269,94 @@
|
|
|
200
269
|
}
|
|
201
270
|
}
|
|
202
271
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
272
|
+
const resolvedLabelX = $derived.by(() => {
|
|
273
|
+
if (placement === 'left' || (orientation === 'horizontal' && labelPlacement === 'start')) {
|
|
274
|
+
return -ctx.padding.left;
|
|
275
|
+
} else if (
|
|
276
|
+
placement === 'right' ||
|
|
277
|
+
(orientation === 'horizontal' && labelPlacement === 'end')
|
|
278
|
+
) {
|
|
279
|
+
return ctx.width + ctx.padding.right;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return ctx.width / 2;
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
const resolvedLabelY = $derived.by(() => {
|
|
286
|
+
if (placement === 'top' || (orientation === 'vertical' && labelPlacement === 'start')) {
|
|
287
|
+
return -ctx.padding.top;
|
|
288
|
+
} else if (orientation === 'vertical' && labelPlacement === 'middle') {
|
|
289
|
+
return ctx.height / 2;
|
|
290
|
+
} else if (placement === 'bottom' || labelPlacement === 'end') {
|
|
291
|
+
return ctx.height + ctx.padding.bottom;
|
|
292
|
+
}
|
|
293
|
+
return '0';
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const resolvedLabelTextAnchor = $derived.by(() => {
|
|
297
|
+
if (labelPlacement === 'middle') {
|
|
298
|
+
return 'middle';
|
|
299
|
+
} else if (
|
|
300
|
+
placement === 'right' ||
|
|
301
|
+
(orientation === 'horizontal' && labelPlacement === 'end')
|
|
302
|
+
) {
|
|
303
|
+
return 'end';
|
|
304
|
+
}
|
|
305
|
+
return 'start';
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
const resolvedLabelVerticalAnchor = $derived.by(() => {
|
|
309
|
+
if (
|
|
226
310
|
placement === 'top' ||
|
|
227
311
|
(orientation === 'vertical' && labelPlacement === 'start') ||
|
|
228
312
|
(placement === 'left' && labelPlacement === 'middle')
|
|
229
|
-
|
|
230
|
-
|
|
313
|
+
) {
|
|
314
|
+
return 'start';
|
|
315
|
+
}
|
|
316
|
+
return 'end';
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
const resolvedLabelProps = $derived({
|
|
320
|
+
value: typeof label === 'function' ? '' : undefined,
|
|
321
|
+
x: resolvedLabelX,
|
|
322
|
+
y: resolvedLabelY,
|
|
323
|
+
textAnchor: resolvedLabelTextAnchor,
|
|
324
|
+
verticalAnchor: resolvedLabelVerticalAnchor,
|
|
231
325
|
rotate: orientation === 'vertical' && labelPlacement === 'middle' ? -90 : 0,
|
|
232
326
|
capHeight: '.5rem', // text-[10px]
|
|
233
327
|
...labelProps,
|
|
234
328
|
class: cls(
|
|
235
|
-
'label
|
|
329
|
+
layerClass('axis-label'),
|
|
330
|
+
'text-[10px] stroke-surface-100 [stroke-width:2px] font-light',
|
|
236
331
|
classes.label,
|
|
237
332
|
labelProps?.class
|
|
238
333
|
),
|
|
239
|
-
} satisfies ComponentProps<Text>;
|
|
334
|
+
}) satisfies ComponentProps<typeof Text>;
|
|
240
335
|
</script>
|
|
241
336
|
|
|
242
|
-
<
|
|
337
|
+
<Group
|
|
338
|
+
{...restProps}
|
|
339
|
+
data-placement={placement}
|
|
340
|
+
class={cls(layerClass('axis'), `placement-${placement}`, classes.root, className)}
|
|
341
|
+
>
|
|
243
342
|
{#if rule !== false}
|
|
244
|
-
{@const ruleProps =
|
|
343
|
+
{@const ruleProps = extractLayerProps(rule, 'axis-rule')}
|
|
245
344
|
<Rule
|
|
246
345
|
x={placement === 'left' || placement === 'right' ? placement : placement === 'angle'}
|
|
247
346
|
y={placement === 'top' || placement === 'bottom' ? placement : placement === 'radius'}
|
|
248
|
-
{
|
|
249
|
-
{spring}
|
|
347
|
+
{motion}
|
|
250
348
|
{...ruleProps}
|
|
251
|
-
class={cls('
|
|
349
|
+
class={cls('stroke-surface-content/50', classes.rule, ruleProps?.class)}
|
|
252
350
|
/>
|
|
253
351
|
{/if}
|
|
254
352
|
|
|
255
|
-
{#if label}
|
|
353
|
+
{#if typeof label === 'function'}
|
|
354
|
+
{@render label({ props: resolvedLabelProps })}
|
|
355
|
+
{:else if label}
|
|
256
356
|
<Text {...resolvedLabelProps} />
|
|
257
357
|
{/if}
|
|
258
358
|
|
|
259
|
-
{#each tickVals as tick, index (tick)}
|
|
359
|
+
{#each tickVals as tick, index (tick.toString())}
|
|
260
360
|
{@const tickCoords = getCoords(tick)}
|
|
261
361
|
{@const [radialTickCoordsX, radialTickCoordsY] = pointRadial(tickCoords.x, tickCoords.y)}
|
|
262
362
|
{@const [radialTickMarkCoordsX, radialTickMarkCoordsY] = pointRadial(
|
|
@@ -266,68 +366,71 @@
|
|
|
266
366
|
{@const resolvedTickLabelProps = {
|
|
267
367
|
x: orientation === 'angle' ? radialTickCoordsX : tickCoords.x,
|
|
268
368
|
y: orientation === 'angle' ? radialTickCoordsY : tickCoords.y,
|
|
269
|
-
value: formatValue(tick, format ??
|
|
369
|
+
value: formatValue(tick, format ?? scale.tickFormat?.() ?? ((v) => v)),
|
|
270
370
|
...getDefaultTickLabelProps(tick),
|
|
271
|
-
|
|
272
|
-
spring,
|
|
371
|
+
motion,
|
|
273
372
|
...tickLabelProps,
|
|
274
373
|
class: cls(
|
|
275
|
-
'
|
|
374
|
+
layerClass('axis-tick-label'),
|
|
375
|
+
'text-[10px] stroke-surface-100 [stroke-width:2px] font-light',
|
|
276
376
|
classes.tickLabel,
|
|
277
377
|
tickLabelProps?.class
|
|
278
378
|
),
|
|
279
379
|
}}
|
|
280
380
|
|
|
281
|
-
<
|
|
381
|
+
<Group {transitionIn} {transitionInParams} class={layerClass('axis-tick-group')}>
|
|
282
382
|
{#if grid !== false}
|
|
283
|
-
{@const ruleProps =
|
|
383
|
+
{@const ruleProps = extractLayerProps(grid, 'axis-grid')}
|
|
284
384
|
<Rule
|
|
285
385
|
x={orientation === 'horizontal' || orientation === 'angle' ? tick : false}
|
|
286
386
|
y={orientation === 'vertical' || orientation === 'radius' ? tick : false}
|
|
287
|
-
{
|
|
288
|
-
{spring}
|
|
387
|
+
{motion}
|
|
289
388
|
{...ruleProps}
|
|
290
|
-
class={cls('
|
|
389
|
+
class={cls('stroke-surface-content/10', classes.rule, ruleProps?.class)}
|
|
291
390
|
/>
|
|
292
391
|
{/if}
|
|
293
392
|
|
|
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
|
-
|
|
393
|
+
{#if tickMarks}
|
|
394
|
+
{@const tickClasses = cls(
|
|
395
|
+
layerClass('axis-tick'),
|
|
396
|
+
'stroke-surface-content/50',
|
|
397
|
+
classes.tick
|
|
398
|
+
)}
|
|
399
|
+
{#if orientation === 'horizontal'}
|
|
400
|
+
<Line
|
|
401
|
+
x1={tickCoords.x}
|
|
402
|
+
y1={tickCoords.y}
|
|
403
|
+
x2={tickCoords.x}
|
|
404
|
+
y2={tickCoords.y + (placement === 'top' ? -tickLength : tickLength)}
|
|
405
|
+
{motion}
|
|
406
|
+
class={tickClasses}
|
|
407
|
+
/>
|
|
408
|
+
{:else if orientation === 'vertical'}
|
|
409
|
+
<Line
|
|
410
|
+
x1={tickCoords.x}
|
|
411
|
+
y1={tickCoords.y}
|
|
412
|
+
x2={tickCoords.x + (placement === 'left' ? -tickLength : tickLength)}
|
|
413
|
+
y2={tickCoords.y}
|
|
414
|
+
{motion}
|
|
415
|
+
class={tickClasses}
|
|
416
|
+
/>
|
|
417
|
+
{:else if orientation === 'angle'}
|
|
418
|
+
<Line
|
|
419
|
+
x1={radialTickCoordsX}
|
|
420
|
+
y1={radialTickCoordsY}
|
|
421
|
+
x2={radialTickMarkCoordsX}
|
|
422
|
+
y2={radialTickMarkCoordsY}
|
|
423
|
+
{motion}
|
|
424
|
+
class={tickClasses}
|
|
425
|
+
/>
|
|
426
|
+
{/if}
|
|
325
427
|
{/if}
|
|
326
|
-
<!-- TODO: Add tick marks for radial (angle)? -->
|
|
327
428
|
|
|
328
|
-
|
|
429
|
+
{#if tickLabel}
|
|
430
|
+
{@render tickLabel({ props: resolvedTickLabelProps, index })}
|
|
431
|
+
{:else}
|
|
329
432
|
<Text {...resolvedTickLabelProps} />
|
|
330
|
-
|
|
331
|
-
</
|
|
433
|
+
{/if}
|
|
434
|
+
</Group>
|
|
332
435
|
{/each}
|
|
333
|
-
</
|
|
436
|
+
</Group>
|