layerchart 0.53.0 → 0.54.1
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/components/Arc.svelte +170 -144
- package/dist/components/Area.svelte +96 -67
- package/dist/components/Area.svelte.d.ts +1 -0
- package/dist/components/Axis.svelte +241 -234
- package/dist/components/Axis.svelte.d.ts +2 -1
- package/dist/components/Bar.svelte +72 -45
- package/dist/components/Bars.svelte +46 -34
- package/dist/components/Bars.svelte.d.ts +1 -0
- package/dist/components/Blur.svelte +5 -3
- package/dist/components/Bounds.svelte +37 -21
- package/dist/components/Brush.svelte +181 -110
- package/dist/components/Calendar.svelte +51 -38
- package/dist/components/Chart.svelte +296 -73
- package/dist/components/Chart.svelte.d.ts +42 -25
- package/dist/components/ChartClipPath.svelte +8 -5
- package/dist/components/ChartContext.svelte +243 -93
- package/dist/components/ChartContext.svelte.d.ts +15 -23
- package/dist/components/Circle.svelte +25 -16
- package/dist/components/CircleClipPath.svelte +16 -10
- package/dist/components/ClipPath.svelte +11 -7
- package/dist/components/ColorRamp.svelte +12 -10
- package/dist/components/ForceSimulation.svelte +185 -116
- package/dist/components/Frame.svelte +10 -6
- package/dist/components/GeoCircle.svelte +15 -9
- package/dist/components/GeoContext.svelte +109 -62
- package/dist/components/GeoEdgeFade.svelte +20 -14
- package/dist/components/GeoPath.svelte +107 -69
- package/dist/components/GeoPoint.svelte +32 -18
- package/dist/components/GeoSpline.svelte +30 -22
- package/dist/components/GeoTile.svelte +40 -30
- package/dist/components/GeoVisible.svelte +10 -7
- package/dist/components/Graticule.svelte +14 -8
- package/dist/components/Grid.svelte +178 -0
- package/dist/components/Grid.svelte.d.ts +35 -0
- package/dist/components/Group.svelte +43 -31
- package/dist/components/Highlight.svelte +284 -243
- package/dist/components/HitCanvas.svelte +75 -42
- package/dist/components/Hull.svelte +40 -20
- package/dist/components/Labels.svelte +84 -63
- package/dist/components/Labels.svelte.d.ts +2 -0
- package/dist/components/Legend.svelte +106 -75
- package/dist/components/Legend.svelte.d.ts +1 -1
- package/dist/components/Line.svelte +29 -19
- package/dist/components/LinearGradient.svelte +21 -15
- package/dist/components/Link.svelte +44 -22
- package/dist/components/MonthPath.svelte +23 -16
- package/dist/components/MotionPath.svelte +34 -25
- package/dist/components/Pack.svelte +21 -14
- package/dist/components/Partition.svelte +35 -20
- package/dist/components/Pattern.svelte +8 -6
- package/dist/components/Pie.svelte +76 -57
- package/dist/components/Point.svelte +11 -7
- package/dist/components/Points.svelte +178 -143
- package/dist/components/RadialGradient.svelte +25 -18
- package/dist/components/Rect.svelte +33 -19
- package/dist/components/RectClipPath.svelte +16 -11
- package/dist/components/Rule.svelte +66 -42
- package/dist/components/Rule.svelte.d.ts +2 -0
- package/dist/components/Sankey.svelte +55 -30
- package/dist/components/Spline.svelte +118 -96
- package/dist/components/Text.svelte +137 -104
- package/dist/components/Threshold.svelte +18 -7
- package/dist/components/TileImage.svelte +56 -50
- package/dist/components/TransformContext.svelte +238 -136
- package/dist/components/TransformControls.svelte +57 -29
- package/dist/components/TransformControls.svelte.d.ts +1 -1
- package/dist/components/Tree.svelte +33 -23
- package/dist/components/Treemap.svelte +69 -41
- package/dist/components/Voronoi.svelte +55 -28
- package/dist/components/charts/AreaChart.svelte +162 -87
- package/dist/components/charts/AreaChart.svelte.d.ts +41 -3
- package/dist/components/charts/BarChart.svelte +207 -108
- package/dist/components/charts/BarChart.svelte.d.ts +41 -3
- package/dist/components/charts/LineChart.svelte +119 -47
- package/dist/components/charts/LineChart.svelte.d.ts +41 -3
- package/dist/components/charts/PieChart.svelte +117 -53
- package/dist/components/charts/PieChart.svelte.d.ts +17 -2
- package/dist/components/charts/ScatterChart.svelte +92 -42
- package/dist/components/charts/ScatterChart.svelte.d.ts +39 -3
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/layout/Canvas.svelte +63 -43
- package/dist/components/layout/Html.svelte +28 -18
- package/dist/components/layout/Svg.svelte +47 -32
- package/dist/components/tooltip/Tooltip.svelte +143 -82
- package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContext.svelte +315 -248
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +7 -0
- package/dist/components/tooltip/TooltipHeader.svelte +9 -3
- package/dist/components/tooltip/TooltipItem.svelte +17 -9
- package/dist/components/tooltip/TooltipList.svelte +2 -1
- package/dist/components/tooltip/TooltipSeparator.svelte +3 -2
- package/dist/docs/Blockquote.svelte +4 -3
- package/dist/docs/Code.svelte +15 -8
- package/dist/docs/CurveMenuField.svelte +17 -12
- package/dist/docs/GeoDebug.svelte +13 -9
- package/dist/docs/Header1.svelte +2 -1
- package/dist/docs/Json.svelte +6 -4
- package/dist/docs/Layout.svelte +6 -6
- package/dist/docs/PathDataMenuField.svelte +52 -44
- package/dist/docs/Preview.svelte +48 -29
- package/dist/docs/TilesetField.svelte +80 -62
- package/dist/docs/TransformDebug.svelte +8 -5
- package/dist/docs/ViewSourceButton.svelte +13 -9
- package/dist/stores/motionStore.d.ts +1 -1
- package/dist/utils/scales.d.ts +4 -4
- package/package.json +29 -30
|
@@ -1,216 +1,243 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
export let
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/** Props
|
|
33
|
-
export let
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export let
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { type ComponentProps } from 'svelte';
|
|
3
|
+
import { fade } from 'svelte/transition';
|
|
4
|
+
import { cubicIn } from 'svelte/easing';
|
|
5
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
6
|
+
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
7
|
+
|
|
8
|
+
import { extent } from 'd3-array';
|
|
9
|
+
import { pointRadial } from 'd3-shape';
|
|
10
|
+
|
|
11
|
+
import { format as formatValue, type FormatType } from '@layerstack/utils';
|
|
12
|
+
import { cls } from '@layerstack/tailwind';
|
|
13
|
+
import type { TransitionParams } from 'svelte-ux'; // TODO: Replace with `@layerstack/svelte-types` or similar
|
|
14
|
+
|
|
15
|
+
import { chartContext } from './ChartContext.svelte';
|
|
16
|
+
import Line from './Line.svelte';
|
|
17
|
+
import Rule from './Rule.svelte';
|
|
18
|
+
import Text from './Text.svelte';
|
|
19
|
+
import { isScaleBand, type AnyScale } from '../utils/scales.js';
|
|
20
|
+
|
|
21
|
+
const { xScale, yScale, xRange, yRange, width, height, padding } = chartContext();
|
|
22
|
+
|
|
23
|
+
/** Location of axis */
|
|
24
|
+
export let placement: 'top' | 'bottom' | 'left' | 'right' | 'angle' | 'radius';
|
|
25
|
+
|
|
26
|
+
/** Axis label */
|
|
27
|
+
export let label = '';
|
|
28
|
+
|
|
29
|
+
/** Location of axis label */
|
|
30
|
+
export let labelPlacement: 'start' | 'middle' | 'end' = 'middle';
|
|
31
|
+
|
|
32
|
+
/** Props applied label Text */
|
|
33
|
+
export let labelProps: Partial<ComponentProps<Text>> | undefined = undefined;
|
|
34
|
+
|
|
35
|
+
/** Draw a rule line. Use Rule component for greater rendering order control */
|
|
36
|
+
export let rule: boolean | Partial<ComponentProps<Rule>> = false;
|
|
37
|
+
|
|
38
|
+
/** Draw a grid lines */
|
|
39
|
+
export let grid: boolean | Pick<SVGAttributes<SVGElement>, 'class' | 'style'> = false;
|
|
40
|
+
|
|
41
|
+
/** Control the number of ticks*/
|
|
42
|
+
export let ticks: number | any[] | ((scale: AnyScale) => any) | null | undefined = undefined;
|
|
43
|
+
|
|
44
|
+
/** Length of the tick line */
|
|
45
|
+
export let tickLength = 4;
|
|
46
|
+
|
|
47
|
+
/** Format tick labels */
|
|
48
|
+
export let format: FormatType | undefined = undefined;
|
|
49
|
+
|
|
50
|
+
/** Props to apply to each tick label */
|
|
51
|
+
export let tickLabelProps: Partial<ComponentProps<Text>> | undefined = undefined;
|
|
52
|
+
|
|
53
|
+
export let spring: boolean | Parameters<typeof springStore>[1] = undefined;
|
|
54
|
+
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
55
|
+
|
|
56
|
+
export let transitionIn = tweened
|
|
37
57
|
? fade
|
|
38
58
|
: () => {
|
|
39
59
|
return {};
|
|
40
|
-
|
|
41
|
-
export let transitionInParams = { easing: cubicIn };
|
|
42
|
-
|
|
60
|
+
};
|
|
61
|
+
export let transitionInParams: TransitionParams = { easing: cubicIn };
|
|
62
|
+
|
|
63
|
+
$: orientation =
|
|
43
64
|
placement === 'angle'
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
? 'angle'
|
|
66
|
+
: placement === 'radius'
|
|
67
|
+
? 'radius'
|
|
68
|
+
: ['top', 'bottom'].includes(placement)
|
|
69
|
+
? 'horizontal'
|
|
70
|
+
: 'vertical';
|
|
71
|
+
|
|
72
|
+
export let scale: any = undefined;
|
|
73
|
+
$: _scale = scale ?? (['horizontal', 'angle'].includes(orientation) ? $xScale : $yScale);
|
|
74
|
+
|
|
75
|
+
export let classes: {
|
|
76
|
+
root?: string;
|
|
77
|
+
label?: string;
|
|
78
|
+
} = {};
|
|
79
|
+
|
|
80
|
+
$: [xRangeMin, xRangeMax] = extent<number>($xRange) as [number, number];
|
|
81
|
+
$: [yRangeMin, yRangeMax] = extent<number>($yRange) as [number, number];
|
|
82
|
+
|
|
83
|
+
$: tickVals = Array.isArray(ticks)
|
|
56
84
|
? ticks
|
|
57
85
|
: typeof ticks === 'function'
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
86
|
+
? ticks(_scale)
|
|
87
|
+
: isScaleBand(_scale)
|
|
88
|
+
? ticks
|
|
89
|
+
? _scale.domain().filter((v: any, i: number) => i % ticks === 0)
|
|
90
|
+
: _scale.domain()
|
|
91
|
+
: _scale.ticks(ticks ?? (placement === 'left' || placement === 'right' ? 4 : undefined));
|
|
92
|
+
|
|
93
|
+
function getCoords(tick: any) {
|
|
65
94
|
switch (placement) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
case 'top':
|
|
96
|
+
return {
|
|
97
|
+
x: _scale(tick) + (isScaleBand(_scale) ? _scale.bandwidth() / 2 : 0),
|
|
98
|
+
y: yRangeMin,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
case 'bottom':
|
|
102
|
+
return {
|
|
103
|
+
x: _scale(tick) + (isScaleBand(_scale) ? _scale.bandwidth() / 2 : 0),
|
|
104
|
+
y: yRangeMax,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
case 'left':
|
|
108
|
+
return {
|
|
109
|
+
x: xRangeMin,
|
|
110
|
+
y: _scale(tick) + (isScaleBand(_scale) ? _scale.bandwidth() / 2 : 0),
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
case 'right':
|
|
114
|
+
return {
|
|
115
|
+
x: xRangeMax,
|
|
116
|
+
y: _scale(tick) + (isScaleBand(_scale) ? _scale.bandwidth() / 2 : 0),
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
case 'angle':
|
|
120
|
+
return {
|
|
121
|
+
x: _scale(tick),
|
|
122
|
+
y: yRangeMax,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
case 'radius':
|
|
126
|
+
return {
|
|
127
|
+
x: xRangeMin,
|
|
128
|
+
y: _scale(tick),
|
|
129
|
+
};
|
|
96
130
|
}
|
|
97
|
-
}
|
|
98
|
-
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function getDefaultTickLabelProps(tick: any): ComponentProps<Text> {
|
|
99
134
|
switch (placement) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
case 'top':
|
|
136
|
+
return {
|
|
137
|
+
textAnchor: 'middle',
|
|
138
|
+
verticalAnchor: 'end',
|
|
139
|
+
dy: -tickLength - 2, // manually adjusted until Text supports custom styles
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
case 'bottom':
|
|
143
|
+
return {
|
|
144
|
+
textAnchor: 'middle',
|
|
145
|
+
verticalAnchor: 'start',
|
|
146
|
+
dy: tickLength, // manually adjusted until Text supports custom styles
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
case 'left':
|
|
150
|
+
return {
|
|
151
|
+
textAnchor: 'end',
|
|
152
|
+
verticalAnchor: 'middle',
|
|
153
|
+
dx: -tickLength,
|
|
154
|
+
dy: -2, // manually adjusted until Text supports custom styles
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
case 'right':
|
|
158
|
+
return {
|
|
159
|
+
textAnchor: 'start',
|
|
160
|
+
verticalAnchor: 'middle',
|
|
161
|
+
dx: tickLength,
|
|
162
|
+
dy: -2, // manually adjusted until Text supports custom styles
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
case 'angle':
|
|
166
|
+
const xValue = _scale(tick); // angle in radians
|
|
167
|
+
return {
|
|
168
|
+
textAnchor:
|
|
169
|
+
xValue === 0 ||
|
|
170
|
+
Math.abs(xValue - Math.PI) < 0.01 || // ~180deg
|
|
171
|
+
Math.abs(xValue - Math.PI * 2) < 0.01 // ~360deg
|
|
172
|
+
? 'middle'
|
|
173
|
+
: xValue > Math.PI
|
|
174
|
+
? 'end'
|
|
175
|
+
: 'start',
|
|
176
|
+
verticalAnchor: 'middle',
|
|
177
|
+
dx: Math.sin(xValue) * (tickLength + 2),
|
|
178
|
+
dy: -Math.cos(xValue) * (tickLength + 4), // manually adjusted until Text supports custom styles
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
case 'radius':
|
|
182
|
+
return {
|
|
183
|
+
textAnchor: 'middle',
|
|
184
|
+
verticalAnchor: 'middle',
|
|
185
|
+
dx: 2,
|
|
186
|
+
dy: -2, // manually adjusted until Text supports custom styles
|
|
187
|
+
};
|
|
141
188
|
}
|
|
142
|
-
}
|
|
143
|
-
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
$: resolvedLabelProps = {
|
|
144
192
|
value: label,
|
|
145
|
-
x:
|
|
193
|
+
x:
|
|
194
|
+
placement === 'left' || (orientation === 'horizontal' && labelPlacement === 'start')
|
|
146
195
|
? -$padding.left
|
|
147
196
|
: placement === 'right' || (orientation === 'horizontal' && labelPlacement === 'end')
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
y:
|
|
197
|
+
? $width + $padding.right
|
|
198
|
+
: $width / 2,
|
|
199
|
+
y:
|
|
200
|
+
placement === 'top' || (orientation === 'vertical' && labelPlacement === 'start')
|
|
151
201
|
? -$padding.top
|
|
152
202
|
: orientation === 'vertical' && labelPlacement === 'middle'
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
textAnchor:
|
|
203
|
+
? $height / 2
|
|
204
|
+
: placement === 'bottom' || labelPlacement === 'end'
|
|
205
|
+
? $height + $padding.bottom
|
|
206
|
+
: 0,
|
|
207
|
+
textAnchor:
|
|
208
|
+
labelPlacement === 'middle'
|
|
158
209
|
? 'middle'
|
|
159
210
|
: placement === 'right' || (orientation === 'horizontal' && labelPlacement === 'end')
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
verticalAnchor:
|
|
163
|
-
|
|
164
|
-
|
|
211
|
+
? 'end'
|
|
212
|
+
: 'start',
|
|
213
|
+
verticalAnchor:
|
|
214
|
+
placement === 'top' ||
|
|
215
|
+
(orientation === 'vertical' && labelPlacement === 'start') ||
|
|
216
|
+
(placement === 'left' && labelPlacement === 'middle')
|
|
165
217
|
? 'start'
|
|
166
218
|
: 'end',
|
|
167
219
|
rotate: orientation === 'vertical' && labelPlacement === 'middle' ? -90 : 0,
|
|
168
220
|
capHeight: '.5rem', // text-[10px]
|
|
169
221
|
...labelProps,
|
|
170
|
-
class: cls(
|
|
171
|
-
|
|
222
|
+
class: cls(
|
|
223
|
+
'label text-[10px] stroke-surface-100 [stroke-width:2px] font-light',
|
|
224
|
+
classes.label,
|
|
225
|
+
labelProps?.class
|
|
226
|
+
),
|
|
227
|
+
} satisfies ComponentProps<Text>;
|
|
172
228
|
</script>
|
|
173
229
|
|
|
174
230
|
<g class={cls('Axis placement-{placement}', classes.root, $$props.class)}>
|
|
175
231
|
{#if rule !== false}
|
|
176
|
-
{@const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
{...lineProps}
|
|
186
|
-
class={cls('rule stroke-surface-content/50', lineProps?.class)}
|
|
187
|
-
/>
|
|
188
|
-
{/if}
|
|
189
|
-
|
|
190
|
-
{#if orientation === 'horizontal'}
|
|
191
|
-
<Line
|
|
192
|
-
x1={$xRange[0] || 0}
|
|
193
|
-
x2={$xRange[1] || 0}
|
|
194
|
-
y1={placement === 'top' ? yRangeMin : yRangeMax}
|
|
195
|
-
y2={placement === 'top' ? yRangeMin : yRangeMax}
|
|
196
|
-
{tweened}
|
|
197
|
-
{spring}
|
|
198
|
-
{...lineProps}
|
|
199
|
-
class={cls('rule stroke-surface-content/50', lineProps?.class)}
|
|
200
|
-
/>
|
|
201
|
-
{/if}
|
|
202
|
-
|
|
203
|
-
<!-- TODO: angle rule? -->
|
|
204
|
-
|
|
205
|
-
{#if orientation === 'radius'}
|
|
206
|
-
<Circle
|
|
207
|
-
r={$yRange[0] || 0}
|
|
208
|
-
{tweened}
|
|
209
|
-
{spring}
|
|
210
|
-
{...lineProps}
|
|
211
|
-
class={cls('rule stroke-surface-content/20 fill-none', lineProps?.class)}
|
|
212
|
-
/>
|
|
213
|
-
{/if}
|
|
232
|
+
{@const ruleProps = typeof rule === 'object' ? rule : null}
|
|
233
|
+
<Rule
|
|
234
|
+
x={placement === 'left' || placement === 'right' ? placement : placement === 'angle'}
|
|
235
|
+
y={placement === 'top' || placement === 'bottom' ? placement : placement === 'radius'}
|
|
236
|
+
{tweened}
|
|
237
|
+
{spring}
|
|
238
|
+
{...ruleProps}
|
|
239
|
+
class={cls('rule stroke-surface-content/50', ruleProps?.class)}
|
|
240
|
+
/>
|
|
214
241
|
{/if}
|
|
215
242
|
|
|
216
243
|
{#if label}
|
|
@@ -219,10 +246,14 @@ $: resolvedLabelProps = {
|
|
|
219
246
|
|
|
220
247
|
{#each tickVals as tick, index (tick)}
|
|
221
248
|
{@const tickCoords = getCoords(tick)}
|
|
222
|
-
{@const
|
|
249
|
+
{@const [radialTickCoordsX, radialTickCoordsY] = pointRadial(tickCoords.x, tickCoords.y)}
|
|
250
|
+
{@const [radialTickMarkCoordsX, radialTickMarkCoordsY] = pointRadial(
|
|
251
|
+
tickCoords.x,
|
|
252
|
+
tickCoords.y + tickLength
|
|
253
|
+
)}
|
|
223
254
|
{@const resolvedTickLabelProps = {
|
|
224
|
-
x: orientation === 'angle' ?
|
|
225
|
-
y: orientation === 'angle' ?
|
|
255
|
+
x: orientation === 'angle' ? radialTickCoordsX : tickCoords.x,
|
|
256
|
+
y: orientation === 'angle' ? radialTickCoordsY : tickCoords.y,
|
|
226
257
|
value: formatValue(tick, format ?? _scale.tickFormat?.() ?? ((v) => v)),
|
|
227
258
|
...getDefaultTickLabelProps(tick),
|
|
228
259
|
tweened,
|
|
@@ -236,50 +267,15 @@ $: resolvedLabelProps = {
|
|
|
236
267
|
|
|
237
268
|
<g in:transitionIn={transitionInParams}>
|
|
238
269
|
{#if grid !== false}
|
|
239
|
-
{@const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
{...lineProps}
|
|
249
|
-
class={cls('grid stroke-surface-content/10', lineProps?.class)}
|
|
250
|
-
/>
|
|
251
|
-
{:else if orientation === 'vertical'}
|
|
252
|
-
<Line
|
|
253
|
-
x1={0}
|
|
254
|
-
y1={tickCoords.y}
|
|
255
|
-
x2={$width}
|
|
256
|
-
y2={tickCoords.y}
|
|
257
|
-
{tweened}
|
|
258
|
-
{spring}
|
|
259
|
-
{...lineProps}
|
|
260
|
-
class={cls('grid stroke-surface-content/10', lineProps?.class)}
|
|
261
|
-
/>
|
|
262
|
-
{:else if orientation === 'angle'}
|
|
263
|
-
{@const [x1, y1] = pointRadial(tickCoords.x, yRangeMin)}
|
|
264
|
-
{@const [x2, y2] = pointRadial(tickCoords.x, yRangeMax)}
|
|
265
|
-
|
|
266
|
-
<Line
|
|
267
|
-
{x1}
|
|
268
|
-
{y1}
|
|
269
|
-
{x2}
|
|
270
|
-
{y2}
|
|
271
|
-
{tweened}
|
|
272
|
-
{spring}
|
|
273
|
-
{...lineProps}
|
|
274
|
-
class={cls('grid stroke-surface-content/10', lineProps?.class)}
|
|
275
|
-
/>
|
|
276
|
-
{:else if orientation === 'radius'}
|
|
277
|
-
<circle
|
|
278
|
-
r={tickCoords.y}
|
|
279
|
-
{...lineProps}
|
|
280
|
-
class={cls('grid stroke-surface-content/10 fill-none', lineProps?.class)}
|
|
281
|
-
/>
|
|
282
|
-
{/if}
|
|
270
|
+
{@const ruleProps = typeof grid === 'object' ? grid : null}
|
|
271
|
+
<Rule
|
|
272
|
+
x={orientation === 'horizontal' || orientation === 'angle' ? tick : false}
|
|
273
|
+
y={orientation === 'vertical' || orientation === 'radius' ? tick : false}
|
|
274
|
+
{tweened}
|
|
275
|
+
{spring}
|
|
276
|
+
{...ruleProps}
|
|
277
|
+
class={cls('grid stroke-surface-content/10', ruleProps?.class)}
|
|
278
|
+
/>
|
|
283
279
|
{/if}
|
|
284
280
|
|
|
285
281
|
<!-- Tick marks -->
|
|
@@ -303,7 +299,18 @@ $: resolvedLabelProps = {
|
|
|
303
299
|
{spring}
|
|
304
300
|
class="tick stroke-surface-content/50"
|
|
305
301
|
/>
|
|
302
|
+
{:else if orientation === 'angle'}
|
|
303
|
+
<Line
|
|
304
|
+
x1={radialTickCoordsX}
|
|
305
|
+
y1={radialTickCoordsY}
|
|
306
|
+
x2={radialTickMarkCoordsX}
|
|
307
|
+
y2={radialTickMarkCoordsY}
|
|
308
|
+
{tweened}
|
|
309
|
+
{spring}
|
|
310
|
+
class="tick stroke-surface-content/50"
|
|
311
|
+
/>
|
|
306
312
|
{/if}
|
|
313
|
+
<!-- TODO: Add tick marks for radial (angle)? -->
|
|
307
314
|
|
|
308
315
|
<slot name="tickLabel" labelProps={resolvedTickLabelProps} {index}>
|
|
309
316
|
<Text {...resolvedTickLabelProps} />
|
|
@@ -5,6 +5,7 @@ import type { SVGAttributes } from 'svelte/elements';
|
|
|
5
5
|
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
6
6
|
import { type FormatType } from '@layerstack/utils';
|
|
7
7
|
import type { TransitionParams } from 'svelte-ux';
|
|
8
|
+
import Rule from './Rule.svelte';
|
|
8
9
|
import Text from './Text.svelte';
|
|
9
10
|
import { type AnyScale } from '../utils/scales.js';
|
|
10
11
|
declare const __propDef: {
|
|
@@ -14,7 +15,7 @@ declare const __propDef: {
|
|
|
14
15
|
label?: string | undefined;
|
|
15
16
|
labelPlacement?: ("start" | "middle" | "end") | undefined;
|
|
16
17
|
labelProps?: Partial<ComponentProps<Text>> | undefined;
|
|
17
|
-
rule?: (boolean |
|
|
18
|
+
rule?: (boolean | Partial<ComponentProps<Rule>>) | undefined;
|
|
18
19
|
grid?: (boolean | Pick<SVGAttributes<SVGElement>, "class" | "style">) | undefined;
|
|
19
20
|
ticks?: number | any[] | ((scale: AnyScale) => any) | null | undefined;
|
|
20
21
|
tickLength?: number | undefined;
|