layerchart 2.0.0-next.1 → 2.0.0-next.11
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 +320 -179
- package/dist/components/Axis.svelte.d.ts +127 -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 +148 -77
- 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 +463 -197
- package/dist/components/Text.svelte.d.ts +136 -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 +153 -103
- package/dist/components/Voronoi.svelte.d.ts +42 -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 +444 -393
- package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
- package/dist/components/charts/BarChart.svelte +463 -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 +366 -315
- 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 +332 -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 +59 -0
- package/dist/components/index.d.ts +76 -4
- package/dist/components/index.js +76 -5
- package/dist/components/layout/Canvas.svelte +347 -171
- package/dist/components/layout/Canvas.svelte.d.ts +110 -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 +253 -78
- package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
- package/dist/components/tooltip/TooltipContext.svelte +426 -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 +3 -1
- package/dist/docs/Blockquote.svelte.d.ts +5 -16
- package/dist/docs/Code.svelte +20 -12
- package/dist/docs/Code.svelte.d.ts +12 -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 +4 -2
- package/dist/docs/Header1.svelte.d.ts +5 -18
- package/dist/docs/Json.svelte +11 -3
- package/dist/docs/Json.svelte.d.ts +9 -17
- package/dist/docs/Layout.svelte +10 -7
- package/dist/docs/Layout.svelte.d.ts +5 -15
- package/dist/docs/Link.svelte +7 -3
- package/dist/docs/Link.svelte.d.ts +5 -27
- 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 +20 -19
- package/dist/docs/TilesetField.svelte.d.ts +6 -19
- package/dist/docs/TransformDebug.svelte +5 -6
- package/dist/docs/TransformDebug.svelte.d.ts +18 -14
- package/dist/docs/ViewSourceButton.svelte +7 -4
- package/dist/docs/ViewSourceButton.svelte.d.ts +8 -18
- 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 +91 -0
- package/dist/utils/scales.svelte.js +201 -0
- 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 +9 -3
- package/dist/utils/ticks.js +122 -147
- package/dist/utils/ticks.test.d.ts +1 -0
- package/dist/utils/ticks.test.js +57 -0
- package/dist/utils/types.d.ts +81 -0
- package/package.json +28 -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/scales.js +0 -136
- /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
|
@@ -1,148 +1,255 @@
|
|
|
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
|
+
* Width or height of each tick in pxiels (responsive reduce)
|
|
48
|
+
*/
|
|
49
|
+
tickSpacing?: number;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether to render tick labels on multiple lines for additional context
|
|
53
|
+
*
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
tickMultiline?: boolean;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Length of the tick line
|
|
60
|
+
* @default 4
|
|
61
|
+
*/
|
|
62
|
+
tickLength?: number;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Whether to render tick marks.
|
|
66
|
+
*
|
|
67
|
+
* @default true
|
|
68
|
+
*/
|
|
69
|
+
tickMarks?: boolean;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Format tick labels
|
|
73
|
+
*/
|
|
74
|
+
format?: FormatType;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Props to apply to each tick label
|
|
78
|
+
*/
|
|
79
|
+
tickLabelProps?: Partial<ComponentProps<typeof Text>>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A snippet to render your own custom tick label.
|
|
83
|
+
*/
|
|
84
|
+
tickLabel?: Snippet<[{ props: ComponentProps<typeof Text>; index: number }]>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Transition function for entering elements
|
|
88
|
+
* @default defaults to fade if the motion prop is set to tweened
|
|
89
|
+
*/
|
|
90
|
+
transitionIn?: In;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Parameters for the transitionIn function
|
|
94
|
+
* @default { easing: cubicIn }
|
|
95
|
+
*/
|
|
96
|
+
transitionInParams?: TransitionParams<In>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Scale for the axis
|
|
100
|
+
*/
|
|
101
|
+
scale?: any;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Classes for styling various parts of the axis
|
|
105
|
+
* @default {}
|
|
106
|
+
*/
|
|
107
|
+
classes?: {
|
|
108
|
+
root?: string;
|
|
109
|
+
label?: string;
|
|
110
|
+
rule?: string;
|
|
111
|
+
tick?: string;
|
|
112
|
+
tickLabel?: string;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
motion?: MotionProp;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export type AxisProps<In extends Transition = Transition> = AxisPropsWithoutHTML<In> &
|
|
119
|
+
Without<GroupProps, AxisPropsWithoutHTML<In>>;
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<script lang="ts" generics="T extends Transition = Transition">
|
|
123
|
+
import { type ComponentProps, type Snippet } from 'svelte';
|
|
5
124
|
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
125
|
|
|
9
126
|
import { extent } from 'd3-array';
|
|
10
127
|
import { pointRadial } from 'd3-shape';
|
|
11
128
|
|
|
12
|
-
import {
|
|
129
|
+
import { type FormatType } from '@layerstack/utils';
|
|
13
130
|
import { cls } from '@layerstack/tailwind';
|
|
14
|
-
import type { TransitionParams } from 'svelte-ux'; // TODO: Replace with `@layerstack/svelte-types` or similar
|
|
15
131
|
|
|
16
|
-
import {
|
|
132
|
+
import Group, { type GroupProps } from './Group.svelte';
|
|
17
133
|
import Line from './Line.svelte';
|
|
18
134
|
import Rule from './Rule.svelte';
|
|
19
135
|
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
|
-
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 =
|
|
136
|
+
import { isScaleBand } from '../utils/scales.svelte.js';
|
|
137
|
+
|
|
138
|
+
import { getChartContext } from './Chart.svelte';
|
|
139
|
+
import { extractLayerProps, layerClass } from '../utils/attributes.js';
|
|
140
|
+
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
141
|
+
import { resolveTickFormat, resolveTickVals, type TicksConfig } from '../utils/ticks.js';
|
|
142
|
+
|
|
143
|
+
let {
|
|
144
|
+
placement,
|
|
145
|
+
label = '',
|
|
146
|
+
labelPlacement = 'middle',
|
|
147
|
+
labelProps,
|
|
148
|
+
rule = false,
|
|
149
|
+
grid = false,
|
|
150
|
+
ticks,
|
|
151
|
+
tickSpacing = ['top', 'bottom', 'angle'].includes(placement)
|
|
152
|
+
? 80
|
|
153
|
+
: ['left', 'right', 'radius'].includes(placement)
|
|
154
|
+
? 50
|
|
155
|
+
: undefined,
|
|
156
|
+
tickMultiline = false,
|
|
157
|
+
tickLength = 4,
|
|
158
|
+
tickMarks = true,
|
|
159
|
+
format,
|
|
160
|
+
tickLabelProps,
|
|
161
|
+
motion,
|
|
162
|
+
transitionIn,
|
|
163
|
+
transitionInParams,
|
|
164
|
+
scale: scaleProp,
|
|
165
|
+
classes = {},
|
|
166
|
+
class: className,
|
|
167
|
+
tickLabel,
|
|
168
|
+
...restProps
|
|
169
|
+
}: AxisProps<T> = $props();
|
|
170
|
+
|
|
171
|
+
const ctx = getChartContext();
|
|
172
|
+
|
|
173
|
+
const orientation = $derived(
|
|
71
174
|
placement === 'angle'
|
|
72
175
|
? 'angle'
|
|
73
176
|
: placement === 'radius'
|
|
74
177
|
? 'radius'
|
|
75
178
|
: ['top', 'bottom'].includes(placement)
|
|
76
179
|
? 'horizontal'
|
|
77
|
-
: 'vertical'
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
180
|
+
: 'vertical'
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
const scale = $derived(
|
|
184
|
+
scaleProp ?? (['horizontal', 'angle'].includes(orientation) ? ctx.xScale : ctx.yScale)
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const xRangeMinMax = $derived(extent<number>(ctx.xRange)) as [number, number];
|
|
188
|
+
const yRangeMinMax = $derived(extent<number>(ctx.yRange)) as [number, number];
|
|
189
|
+
|
|
190
|
+
const ctxSize = $derived(
|
|
191
|
+
orientation === 'vertical'
|
|
192
|
+
? ctx.height
|
|
193
|
+
: orientation === 'horizontal'
|
|
194
|
+
? ctx.width
|
|
195
|
+
: orientation === 'radius'
|
|
196
|
+
? ctx.height / 2
|
|
197
|
+
: orientation === 'angle'
|
|
198
|
+
? ctx.width
|
|
199
|
+
: null
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
const tickCount = $derived(
|
|
203
|
+
typeof ticks === 'number'
|
|
204
|
+
? ticks
|
|
205
|
+
: tickSpacing && ctxSize
|
|
206
|
+
? Math.round(ctxSize / tickSpacing)
|
|
207
|
+
: undefined
|
|
208
|
+
);
|
|
209
|
+
const tickVals = $derived(resolveTickVals(scale, ticks, tickCount));
|
|
210
|
+
const tickFormat = $derived(resolveTickFormat(scale, ticks, tickCount, format, tickMultiline));
|
|
104
211
|
|
|
105
212
|
function getCoords(tick: any) {
|
|
106
213
|
switch (placement) {
|
|
107
214
|
case 'top':
|
|
108
215
|
return {
|
|
109
|
-
x:
|
|
110
|
-
y:
|
|
216
|
+
x: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
217
|
+
y: yRangeMinMax[0],
|
|
111
218
|
};
|
|
112
219
|
|
|
113
220
|
case 'bottom':
|
|
114
221
|
return {
|
|
115
|
-
x:
|
|
116
|
-
y:
|
|
222
|
+
x: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
223
|
+
y: yRangeMinMax[1],
|
|
117
224
|
};
|
|
118
225
|
|
|
119
226
|
case 'left':
|
|
120
227
|
return {
|
|
121
|
-
x:
|
|
122
|
-
y:
|
|
228
|
+
x: xRangeMinMax[0],
|
|
229
|
+
y: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
123
230
|
};
|
|
124
231
|
|
|
125
232
|
case 'right':
|
|
126
233
|
return {
|
|
127
|
-
x:
|
|
128
|
-
y:
|
|
234
|
+
x: xRangeMinMax[1],
|
|
235
|
+
y: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
129
236
|
};
|
|
130
237
|
|
|
131
238
|
case 'angle':
|
|
132
239
|
return {
|
|
133
|
-
x:
|
|
134
|
-
y:
|
|
240
|
+
x: scale(tick),
|
|
241
|
+
y: yRangeMinMax[1],
|
|
135
242
|
};
|
|
136
243
|
|
|
137
244
|
case 'radius':
|
|
138
245
|
return {
|
|
139
|
-
x:
|
|
140
|
-
y:
|
|
246
|
+
x: xRangeMinMax[0],
|
|
247
|
+
y: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
|
|
141
248
|
};
|
|
142
249
|
}
|
|
143
250
|
}
|
|
144
251
|
|
|
145
|
-
function getDefaultTickLabelProps(tick: any): ComponentProps<Text> {
|
|
252
|
+
function getDefaultTickLabelProps(tick: any): ComponentProps<typeof Text> {
|
|
146
253
|
switch (placement) {
|
|
147
254
|
case 'top':
|
|
148
255
|
return {
|
|
@@ -175,7 +282,7 @@
|
|
|
175
282
|
};
|
|
176
283
|
|
|
177
284
|
case 'angle':
|
|
178
|
-
const xValue =
|
|
285
|
+
const xValue = scale(tick); // angle in radians
|
|
179
286
|
return {
|
|
180
287
|
textAnchor:
|
|
181
288
|
xValue === 0 ||
|
|
@@ -200,59 +307,90 @@
|
|
|
200
307
|
}
|
|
201
308
|
}
|
|
202
309
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
310
|
+
const resolvedLabelX = $derived.by(() => {
|
|
311
|
+
if (placement === 'left' || (orientation === 'horizontal' && labelPlacement === 'start')) {
|
|
312
|
+
return -ctx.padding.left;
|
|
313
|
+
} else if (
|
|
314
|
+
placement === 'right' ||
|
|
315
|
+
(orientation === 'horizontal' && labelPlacement === 'end')
|
|
316
|
+
) {
|
|
317
|
+
return ctx.width + ctx.padding.right;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return ctx.width / 2;
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
const resolvedLabelY = $derived.by(() => {
|
|
324
|
+
if (placement === 'top' || (orientation === 'vertical' && labelPlacement === 'start')) {
|
|
325
|
+
return -ctx.padding.top;
|
|
326
|
+
} else if (orientation === 'vertical' && labelPlacement === 'middle') {
|
|
327
|
+
return ctx.height / 2;
|
|
328
|
+
} else if (placement === 'bottom' || labelPlacement === 'end') {
|
|
329
|
+
return ctx.height + ctx.padding.bottom;
|
|
330
|
+
}
|
|
331
|
+
return '0';
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const resolvedLabelTextAnchor = $derived.by(() => {
|
|
335
|
+
if (labelPlacement === 'middle') {
|
|
336
|
+
return 'middle';
|
|
337
|
+
} else if (
|
|
338
|
+
placement === 'right' ||
|
|
339
|
+
(orientation === 'horizontal' && labelPlacement === 'end')
|
|
340
|
+
) {
|
|
341
|
+
return 'end';
|
|
342
|
+
}
|
|
343
|
+
return 'start';
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
const resolvedLabelVerticalAnchor = $derived.by(() => {
|
|
347
|
+
if (
|
|
226
348
|
placement === 'top' ||
|
|
227
349
|
(orientation === 'vertical' && labelPlacement === 'start') ||
|
|
228
350
|
(placement === 'left' && labelPlacement === 'middle')
|
|
229
|
-
|
|
230
|
-
|
|
351
|
+
) {
|
|
352
|
+
return 'start';
|
|
353
|
+
}
|
|
354
|
+
return 'end';
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const resolvedLabelProps = $derived({
|
|
358
|
+
value: typeof label === 'function' ? '' : undefined,
|
|
359
|
+
x: resolvedLabelX,
|
|
360
|
+
y: resolvedLabelY,
|
|
361
|
+
textAnchor: resolvedLabelTextAnchor,
|
|
362
|
+
verticalAnchor: resolvedLabelVerticalAnchor,
|
|
231
363
|
rotate: orientation === 'vertical' && labelPlacement === 'middle' ? -90 : 0,
|
|
232
364
|
capHeight: '.5rem', // text-[10px]
|
|
233
365
|
...labelProps,
|
|
234
366
|
class: cls(
|
|
235
|
-
'label
|
|
367
|
+
layerClass('axis-label'),
|
|
368
|
+
'text-[10px] stroke-surface-100 [stroke-width:2px] font-light',
|
|
236
369
|
classes.label,
|
|
237
370
|
labelProps?.class
|
|
238
371
|
),
|
|
239
|
-
} satisfies ComponentProps<Text>;
|
|
372
|
+
}) satisfies ComponentProps<typeof Text>;
|
|
240
373
|
</script>
|
|
241
374
|
|
|
242
|
-
<
|
|
375
|
+
<Group
|
|
376
|
+
{...restProps}
|
|
377
|
+
data-placement={placement}
|
|
378
|
+
class={cls(layerClass('axis'), `placement-${placement}`, classes.root, className)}
|
|
379
|
+
>
|
|
243
380
|
{#if rule !== false}
|
|
244
|
-
{@const ruleProps =
|
|
381
|
+
{@const ruleProps = extractLayerProps(rule, 'axis-rule')}
|
|
245
382
|
<Rule
|
|
246
383
|
x={placement === 'left' || placement === 'right' ? placement : placement === 'angle'}
|
|
247
384
|
y={placement === 'top' || placement === 'bottom' ? placement : placement === 'radius'}
|
|
248
|
-
{
|
|
249
|
-
{spring}
|
|
385
|
+
{motion}
|
|
250
386
|
{...ruleProps}
|
|
251
|
-
class={cls('
|
|
387
|
+
class={cls('stroke-surface-content/50', classes.rule, ruleProps?.class)}
|
|
252
388
|
/>
|
|
253
389
|
{/if}
|
|
254
390
|
|
|
255
|
-
{#if label}
|
|
391
|
+
{#if typeof label === 'function'}
|
|
392
|
+
{@render label({ props: resolvedLabelProps })}
|
|
393
|
+
{:else if label}
|
|
256
394
|
<Text {...resolvedLabelProps} />
|
|
257
395
|
{/if}
|
|
258
396
|
|
|
@@ -266,68 +404,71 @@
|
|
|
266
404
|
{@const resolvedTickLabelProps = {
|
|
267
405
|
x: orientation === 'angle' ? radialTickCoordsX : tickCoords.x,
|
|
268
406
|
y: orientation === 'angle' ? radialTickCoordsY : tickCoords.y,
|
|
269
|
-
value:
|
|
407
|
+
value: tickFormat(tick, index),
|
|
270
408
|
...getDefaultTickLabelProps(tick),
|
|
271
|
-
|
|
272
|
-
spring,
|
|
409
|
+
motion,
|
|
273
410
|
...tickLabelProps,
|
|
274
411
|
class: cls(
|
|
275
|
-
'
|
|
412
|
+
layerClass('axis-tick-label'),
|
|
413
|
+
'text-[10px] stroke-surface-100 [stroke-width:2px] font-light',
|
|
276
414
|
classes.tickLabel,
|
|
277
415
|
tickLabelProps?.class
|
|
278
416
|
),
|
|
279
417
|
}}
|
|
280
418
|
|
|
281
|
-
<
|
|
419
|
+
<Group {transitionIn} {transitionInParams} class={layerClass('axis-tick-group')}>
|
|
282
420
|
{#if grid !== false}
|
|
283
|
-
{@const ruleProps =
|
|
421
|
+
{@const ruleProps = extractLayerProps(grid, 'axis-grid')}
|
|
284
422
|
<Rule
|
|
285
423
|
x={orientation === 'horizontal' || orientation === 'angle' ? tick : false}
|
|
286
424
|
y={orientation === 'vertical' || orientation === 'radius' ? tick : false}
|
|
287
|
-
{
|
|
288
|
-
{spring}
|
|
425
|
+
{motion}
|
|
289
426
|
{...ruleProps}
|
|
290
|
-
class={cls('
|
|
427
|
+
class={cls('stroke-surface-content/10', classes.rule, ruleProps?.class)}
|
|
291
428
|
/>
|
|
292
429
|
{/if}
|
|
293
430
|
|
|
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
|
-
|
|
431
|
+
{#if tickMarks}
|
|
432
|
+
{@const tickClasses = cls(
|
|
433
|
+
layerClass('axis-tick'),
|
|
434
|
+
'stroke-surface-content/50',
|
|
435
|
+
classes.tick
|
|
436
|
+
)}
|
|
437
|
+
{#if orientation === 'horizontal'}
|
|
438
|
+
<Line
|
|
439
|
+
x1={tickCoords.x}
|
|
440
|
+
y1={tickCoords.y}
|
|
441
|
+
x2={tickCoords.x}
|
|
442
|
+
y2={tickCoords.y + (placement === 'top' ? -tickLength : tickLength)}
|
|
443
|
+
{motion}
|
|
444
|
+
class={tickClasses}
|
|
445
|
+
/>
|
|
446
|
+
{:else if orientation === 'vertical'}
|
|
447
|
+
<Line
|
|
448
|
+
x1={tickCoords.x}
|
|
449
|
+
y1={tickCoords.y}
|
|
450
|
+
x2={tickCoords.x + (placement === 'left' ? -tickLength : tickLength)}
|
|
451
|
+
y2={tickCoords.y}
|
|
452
|
+
{motion}
|
|
453
|
+
class={tickClasses}
|
|
454
|
+
/>
|
|
455
|
+
{:else if orientation === 'angle'}
|
|
456
|
+
<Line
|
|
457
|
+
x1={radialTickCoordsX}
|
|
458
|
+
y1={radialTickCoordsY}
|
|
459
|
+
x2={radialTickMarkCoordsX}
|
|
460
|
+
y2={radialTickMarkCoordsY}
|
|
461
|
+
{motion}
|
|
462
|
+
class={tickClasses}
|
|
463
|
+
/>
|
|
464
|
+
{/if}
|
|
325
465
|
{/if}
|
|
326
|
-
<!-- TODO: Add tick marks for radial (angle)? -->
|
|
327
466
|
|
|
328
|
-
|
|
467
|
+
{#if tickLabel}
|
|
468
|
+
{@render tickLabel({ props: resolvedTickLabelProps, index })}
|
|
469
|
+
{:else}
|
|
329
470
|
<Text {...resolvedTickLabelProps} />
|
|
330
|
-
|
|
331
|
-
</
|
|
471
|
+
{/if}
|
|
472
|
+
</Group>
|
|
332
473
|
{/each}
|
|
333
|
-
</
|
|
474
|
+
</Group>
|