layerchart 2.0.0-next.2 → 2.0.0-next.20
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/AnnotationLine.svelte +17 -29
- package/dist/components/AnnotationLine.svelte.d.ts +4 -2
- package/dist/components/AnnotationPoint.svelte +11 -13
- package/dist/components/AnnotationPoint.svelte.d.ts +4 -2
- package/dist/components/AnnotationRange.svelte +3 -3
- package/dist/components/Arc.svelte +2 -2
- package/dist/components/Axis.svelte +52 -24
- package/dist/components/Axis.svelte.d.ts +14 -3
- package/dist/components/Bar.svelte +7 -4
- package/dist/components/Bar.svelte.d.ts +4 -1
- package/dist/components/Bars.svelte +9 -6
- package/dist/components/Bars.svelte.d.ts +3 -3
- package/dist/components/Blur.svelte +20 -12
- package/dist/components/Blur.svelte.d.ts +2 -5
- package/dist/components/Calendar.svelte +10 -6
- package/dist/components/Calendar.svelte.d.ts +2 -1
- package/dist/components/Chart.svelte +2 -2
- package/dist/components/ClipPath.svelte +14 -9
- package/dist/components/Connector.svelte +2 -2
- package/dist/components/Connector.svelte.d.ts +1 -1
- package/dist/components/Ellipse.svelte +187 -0
- package/dist/components/Ellipse.svelte.d.ts +64 -0
- package/dist/components/ForceSimulation.svelte +168 -50
- package/dist/components/ForceSimulation.svelte.d.ts +80 -21
- package/dist/components/GeoEdgeFade.svelte +4 -3
- package/dist/components/GeoEdgeFade.svelte.d.ts +2 -2
- package/dist/components/GeoPath.svelte +12 -5
- package/dist/components/GeoPoint.svelte +1 -2
- package/dist/components/GeoSpline.svelte +4 -4
- package/dist/components/GeoSpline.svelte.d.ts +1 -1
- package/dist/components/Graticule.svelte +3 -2
- package/dist/components/Grid.svelte +8 -7
- package/dist/components/Grid.svelte.d.ts +2 -1
- package/dist/components/Group.svelte +45 -5
- package/dist/components/Group.svelte.d.ts +32 -4
- package/dist/components/Highlight.svelte +1 -1
- package/dist/components/Hull.svelte +4 -4
- package/dist/components/Hull.svelte.d.ts +2 -2
- package/dist/components/Labels.svelte +6 -4
- package/dist/components/Labels.svelte.d.ts +2 -2
- package/dist/components/Legend.svelte +8 -5
- package/dist/components/Legend.svelte.d.ts +3 -3
- package/dist/components/MonthPath.svelte +14 -11
- package/dist/components/MonthPath.svelte.d.ts +4 -3
- package/dist/components/Polygon.svelte +285 -0
- package/dist/components/Polygon.svelte.d.ts +115 -0
- package/dist/components/RadialGradient.svelte +1 -3
- package/dist/components/Rule.svelte +3 -2
- package/dist/components/Spline.svelte +30 -18
- package/dist/components/Spline.svelte.d.ts +12 -4
- package/dist/components/Text.svelte +60 -48
- package/dist/components/Text.svelte.d.ts +6 -0
- package/dist/components/Treemap.svelte +63 -26
- package/dist/components/Treemap.svelte.d.ts +11 -11
- package/dist/components/Voronoi.svelte +55 -36
- package/dist/components/Voronoi.svelte.d.ts +5 -3
- package/dist/components/charts/ArcChart.svelte +2 -2
- package/dist/components/charts/AreaChart.svelte +9 -10
- package/dist/components/charts/BarChart.svelte +63 -53
- package/dist/components/charts/DefaultTooltip.svelte +1 -1
- package/dist/components/charts/LineChart.svelte +8 -5
- package/dist/components/charts/PieChart.svelte +2 -2
- package/dist/components/charts/ScatterChart.svelte +0 -2
- package/dist/components/charts/utils.svelte.d.ts +3 -3
- package/dist/components/charts/utils.svelte.js +7 -3
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +4 -0
- package/dist/components/layout/Canvas.svelte +67 -49
- package/dist/components/layout/Canvas.svelte.d.ts +6 -0
- package/dist/components/layout/Layer.svelte +6 -4
- package/dist/components/layout/Layer.svelte.d.ts +6 -4
- package/dist/components/tooltip/Tooltip.svelte +14 -7
- package/dist/components/tooltip/TooltipContext.svelte +25 -8
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipHeader.svelte +5 -4
- package/dist/components/tooltip/TooltipHeader.svelte.d.ts +3 -3
- package/dist/components/tooltip/TooltipItem.svelte +5 -4
- package/dist/components/tooltip/TooltipItem.svelte.d.ts +3 -3
- package/dist/components/tooltip/TooltipList.svelte +1 -1
- package/dist/components/tooltip/tooltipMetaContext.d.ts +2 -2
- package/dist/docs/Blockquote.svelte +3 -1
- package/dist/docs/Blockquote.svelte.d.ts +4 -19
- package/dist/docs/Code.svelte +20 -12
- package/dist/docs/Code.svelte.d.ts +9 -23
- package/dist/docs/Header1.svelte +4 -2
- package/dist/docs/Header1.svelte.d.ts +4 -28
- package/dist/docs/Json.svelte +11 -3
- package/dist/docs/Json.svelte.d.ts +9 -21
- package/dist/docs/Layout.svelte +10 -7
- package/dist/docs/Layout.svelte.d.ts +4 -19
- package/dist/docs/Link.svelte +7 -3
- package/dist/docs/Link.svelte.d.ts +4 -38
- package/dist/docs/TilesetField.svelte +20 -19
- package/dist/docs/TilesetField.svelte.d.ts +5 -22
- package/dist/docs/ViewSourceButton.svelte +7 -4
- package/dist/docs/ViewSourceButton.svelte.d.ts +7 -21
- package/dist/utils/arcText.svelte.js +4 -4
- package/dist/utils/canvas.d.ts +77 -0
- package/dist/utils/canvas.js +105 -41
- package/dist/utils/genData.d.ts +14 -0
- package/dist/utils/genData.js +24 -6
- package/dist/utils/path.d.ts +10 -0
- package/dist/utils/path.js +30 -0
- package/dist/utils/scales.svelte.d.ts +3 -2
- package/dist/utils/scales.svelte.js +7 -3
- package/dist/utils/shape.d.ts +43 -0
- package/dist/utils/shape.js +59 -0
- package/dist/utils/string.d.ts +49 -0
- package/dist/utils/string.js +4 -2
- package/dist/utils/ticks.d.ts +4 -4
- package/dist/utils/ticks.js +106 -159
- package/dist/utils/ticks.test.js +6 -16
- package/dist/utils/treemap.d.ts +1 -1
- package/package.json +25 -22
- package/dist/utils/object.js +0 -2
|
@@ -17,8 +17,11 @@
|
|
|
17
17
|
/** Placement of the label */
|
|
18
18
|
labelPlacement?: Placement;
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
|
|
20
|
+
/** X offset of the label */
|
|
21
|
+
labelXOffset?: number;
|
|
22
|
+
|
|
23
|
+
/** Y offset of the label */
|
|
24
|
+
labelYOffset?: number;
|
|
22
25
|
|
|
23
26
|
/** Classes for inner elements */
|
|
24
27
|
props?: {
|
|
@@ -44,7 +47,8 @@
|
|
|
44
47
|
y,
|
|
45
48
|
label,
|
|
46
49
|
labelPlacement = 'top-right',
|
|
47
|
-
|
|
50
|
+
labelXOffset = 0,
|
|
51
|
+
labelYOffset = 0,
|
|
48
52
|
props,
|
|
49
53
|
}: AnnotationLineProps = $props();
|
|
50
54
|
|
|
@@ -62,25 +66,17 @@
|
|
|
62
66
|
const labelProps = $derived<ComponentProps<typeof Text>>(
|
|
63
67
|
isVertical
|
|
64
68
|
? {
|
|
65
|
-
x:
|
|
66
|
-
line.x1 +
|
|
67
|
-
(['top', 'bottom'].includes(labelPlacement)
|
|
68
|
-
? 0 // Offset applies to `y`
|
|
69
|
-
: labelPlacement.includes('left')
|
|
70
|
-
? -labelOffset
|
|
71
|
-
: labelOffset),
|
|
69
|
+
x: line.x1 + (labelPlacement.includes('left') ? -labelXOffset : labelXOffset),
|
|
72
70
|
y:
|
|
73
71
|
(labelPlacement.includes('top')
|
|
74
72
|
? line.y2
|
|
75
73
|
: labelPlacement.includes('bottom')
|
|
76
74
|
? line.y1
|
|
77
75
|
: (line.y1 - line.y2) / 2) +
|
|
78
|
-
(
|
|
79
|
-
? -
|
|
80
|
-
:
|
|
81
|
-
|
|
82
|
-
: 0),
|
|
83
|
-
dy: -2, // adjust for smaler font size
|
|
76
|
+
(['top', 'bottom-left', 'bottom-right'].includes(labelPlacement)
|
|
77
|
+
? -labelYOffset
|
|
78
|
+
: labelYOffset),
|
|
79
|
+
dy: -2, // adjust for smaller font size
|
|
84
80
|
textAnchor: labelPlacement.includes('left')
|
|
85
81
|
? 'end'
|
|
86
82
|
: labelPlacement.includes('right')
|
|
@@ -104,19 +100,11 @@
|
|
|
104
100
|
: labelPlacement.includes('right')
|
|
105
101
|
? line.x2
|
|
106
102
|
: (line.x2 - line.x1) / 2) +
|
|
107
|
-
(
|
|
108
|
-
? -
|
|
109
|
-
:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
y:
|
|
113
|
-
line.y1 +
|
|
114
|
-
(['left', 'right'].includes(labelPlacement)
|
|
115
|
-
? 0 // Offset applies to `x`
|
|
116
|
-
: labelPlacement.includes('top')
|
|
117
|
-
? -labelOffset
|
|
118
|
-
: labelOffset),
|
|
119
|
-
dy: -2, // adjust for smaler font size
|
|
103
|
+
(['left', 'top-right', 'bottom-right'].includes(labelPlacement)
|
|
104
|
+
? -labelXOffset
|
|
105
|
+
: labelXOffset),
|
|
106
|
+
y: line.y1 + (labelPlacement.includes('top') ? -labelYOffset : labelYOffset),
|
|
107
|
+
dy: -2, // adjust for smaller font size
|
|
120
108
|
textAnchor:
|
|
121
109
|
labelPlacement === 'left'
|
|
122
110
|
? 'end' // place beside line
|
|
@@ -11,8 +11,10 @@ export type AnnotationLinePropsWithoutHTML = {
|
|
|
11
11
|
label?: string;
|
|
12
12
|
/** Placement of the label */
|
|
13
13
|
labelPlacement?: Placement;
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
/** X offset of the label */
|
|
15
|
+
labelXOffset?: number;
|
|
16
|
+
/** Y offset of the label */
|
|
17
|
+
labelYOffset?: number;
|
|
16
18
|
/** Classes for inner elements */
|
|
17
19
|
props?: {
|
|
18
20
|
label?: Partial<ComponentProps<typeof Text>>;
|
|
@@ -20,8 +20,11 @@
|
|
|
20
20
|
/** Placement of the label */
|
|
21
21
|
labelPlacement?: Placement;
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/** X offset of the label */
|
|
24
|
+
labelXOffset?: number;
|
|
25
|
+
|
|
26
|
+
/** Y offset of the label */
|
|
27
|
+
labelYOffset?: number;
|
|
25
28
|
|
|
26
29
|
/** Details (description, etc) useful to display in tooltip */
|
|
27
30
|
details?: any;
|
|
@@ -51,7 +54,8 @@
|
|
|
51
54
|
r = 4,
|
|
52
55
|
label,
|
|
53
56
|
labelPlacement = 'center',
|
|
54
|
-
|
|
57
|
+
labelXOffset = 0,
|
|
58
|
+
labelYOffset = 0,
|
|
55
59
|
details,
|
|
56
60
|
props,
|
|
57
61
|
}: AnnotationPointProps = $props();
|
|
@@ -66,18 +70,12 @@
|
|
|
66
70
|
const labelProps = $derived<ComponentProps<typeof Text>>({
|
|
67
71
|
x:
|
|
68
72
|
point.x +
|
|
69
|
-
(
|
|
70
|
-
? -
|
|
71
|
-
: labelPlacement.includes('right')
|
|
72
|
-
? r + labelOffset
|
|
73
|
-
: 0),
|
|
73
|
+
((['top', 'center', 'bottom'].includes(labelPlacement) ? 0 : r) + labelXOffset) *
|
|
74
|
+
(labelPlacement.includes('left') ? -1 : 1),
|
|
74
75
|
y:
|
|
75
76
|
point.y +
|
|
76
|
-
(
|
|
77
|
-
? -
|
|
78
|
-
: labelPlacement.includes('bottom')
|
|
79
|
-
? r + labelOffset
|
|
80
|
-
: 0),
|
|
77
|
+
((['left', 'center', 'right'].includes(labelPlacement) ? 0 : r) + labelYOffset) *
|
|
78
|
+
(labelPlacement.includes('top') ? -1 : 1),
|
|
81
79
|
dy: -2, // adjust for smaler font size
|
|
82
80
|
textAnchor: labelPlacement.includes('left')
|
|
83
81
|
? 'end'
|
|
@@ -13,8 +13,10 @@ export type AnnotationPointPropsWithoutHTML = {
|
|
|
13
13
|
label?: string;
|
|
14
14
|
/** Placement of the label */
|
|
15
15
|
labelPlacement?: Placement;
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/** X offset of the label */
|
|
17
|
+
labelXOffset?: number;
|
|
18
|
+
/** Y offset of the label */
|
|
19
|
+
labelYOffset?: number;
|
|
18
20
|
/** Details (description, etc) useful to display in tooltip */
|
|
19
21
|
details?: any;
|
|
20
22
|
/** Classes for inner elements */
|
|
@@ -118,13 +118,13 @@
|
|
|
118
118
|
</script>
|
|
119
119
|
|
|
120
120
|
{#if fill || className}
|
|
121
|
-
<Rect {...rect} {fill} class={cls(props?.rect?.class, className)} />
|
|
121
|
+
<Rect {...rect} {...props?.rect} {fill} class={cls(props?.rect?.class, className)} />
|
|
122
122
|
{/if}
|
|
123
123
|
|
|
124
124
|
{#if gradient}
|
|
125
125
|
<LinearGradient {...gradient}>
|
|
126
126
|
{#snippet children({ gradient })}
|
|
127
|
-
<Rect {...rect}
|
|
127
|
+
<Rect {...rect} {...props?.rect} fill={gradient} />
|
|
128
128
|
{/snippet}
|
|
129
129
|
</LinearGradient>
|
|
130
130
|
{/if}
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
{#if pattern}
|
|
133
133
|
<Pattern {...pattern}>
|
|
134
134
|
{#snippet children({ pattern })}
|
|
135
|
-
<Rect {...rect}
|
|
135
|
+
<Rect {...rect} {...props?.rect} fill={pattern} />
|
|
136
136
|
{/snippet}
|
|
137
137
|
</Pattern>
|
|
138
138
|
{/if}
|
|
@@ -401,13 +401,13 @@
|
|
|
401
401
|
<Spline
|
|
402
402
|
pathData={trackArc()}
|
|
403
403
|
stroke="none"
|
|
404
|
-
bind:
|
|
404
|
+
bind:pathRef={trackRef}
|
|
405
405
|
{...extractLayerProps(track, 'arc-track')}
|
|
406
406
|
/>
|
|
407
407
|
{/if}
|
|
408
408
|
|
|
409
409
|
<Spline
|
|
410
|
-
bind:
|
|
410
|
+
bind:pathRef={ref}
|
|
411
411
|
pathData={arc()}
|
|
412
412
|
transform="translate({xOffset}, {yOffset})"
|
|
413
413
|
{fill}
|
|
@@ -43,6 +43,18 @@
|
|
|
43
43
|
*/
|
|
44
44
|
ticks?: TicksConfig;
|
|
45
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
|
+
|
|
46
58
|
/**
|
|
47
59
|
* Length of the tick line
|
|
48
60
|
* @default 4
|
|
@@ -59,7 +71,7 @@
|
|
|
59
71
|
/**
|
|
60
72
|
* Format tick labels
|
|
61
73
|
*/
|
|
62
|
-
format?: FormatType;
|
|
74
|
+
format?: FormatType | FormatConfig;
|
|
63
75
|
|
|
64
76
|
/**
|
|
65
77
|
* Props to apply to each tick label
|
|
@@ -104,21 +116,20 @@
|
|
|
104
116
|
};
|
|
105
117
|
|
|
106
118
|
export type AxisProps<In extends Transition = Transition> = AxisPropsWithoutHTML<In> &
|
|
107
|
-
Without<
|
|
119
|
+
Without<GroupProps, AxisPropsWithoutHTML<In>>;
|
|
108
120
|
</script>
|
|
109
121
|
|
|
110
122
|
<script lang="ts" generics="T extends Transition = Transition">
|
|
111
123
|
import { type ComponentProps, type Snippet } from 'svelte';
|
|
112
|
-
import { fade } from 'svelte/transition';
|
|
113
|
-
import { cubicIn } from 'svelte/easing';
|
|
114
124
|
import type { SVGAttributes } from 'svelte/elements';
|
|
115
125
|
|
|
116
126
|
import { extent } from 'd3-array';
|
|
117
127
|
import { pointRadial } from 'd3-shape';
|
|
118
128
|
|
|
119
|
-
import {
|
|
129
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
120
130
|
import { cls } from '@layerstack/tailwind';
|
|
121
131
|
|
|
132
|
+
import Group, { type GroupProps } from './Group.svelte';
|
|
122
133
|
import Line from './Line.svelte';
|
|
123
134
|
import Rule from './Rule.svelte';
|
|
124
135
|
import Text from './Text.svelte';
|
|
@@ -126,8 +137,8 @@
|
|
|
126
137
|
|
|
127
138
|
import { getChartContext } from './Chart.svelte';
|
|
128
139
|
import { extractLayerProps, layerClass } from '../utils/attributes.js';
|
|
129
|
-
import {
|
|
130
|
-
import { resolveTickVals, type TicksConfig } from '../utils/ticks.js';
|
|
140
|
+
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
141
|
+
import { resolveTickFormat, resolveTickVals, type TicksConfig } from '../utils/ticks.js';
|
|
131
142
|
|
|
132
143
|
let {
|
|
133
144
|
placement,
|
|
@@ -137,13 +148,19 @@
|
|
|
137
148
|
rule = false,
|
|
138
149
|
grid = false,
|
|
139
150
|
ticks,
|
|
151
|
+
tickSpacing = ['top', 'bottom', 'angle'].includes(placement)
|
|
152
|
+
? 80
|
|
153
|
+
: ['left', 'right', 'radius'].includes(placement)
|
|
154
|
+
? 50
|
|
155
|
+
: undefined,
|
|
156
|
+
tickMultiline = false,
|
|
140
157
|
tickLength = 4,
|
|
141
158
|
tickMarks = true,
|
|
142
159
|
format,
|
|
143
160
|
tickLabelProps,
|
|
144
161
|
motion,
|
|
145
|
-
transitionIn
|
|
146
|
-
transitionInParams
|
|
162
|
+
transitionIn,
|
|
163
|
+
transitionInParams,
|
|
147
164
|
scale: scaleProp,
|
|
148
165
|
classes = {},
|
|
149
166
|
class: className,
|
|
@@ -151,13 +168,6 @@
|
|
|
151
168
|
...restProps
|
|
152
169
|
}: AxisProps<T> = $props();
|
|
153
170
|
|
|
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
171
|
const ctx = getChartContext();
|
|
162
172
|
|
|
163
173
|
const orientation = $derived(
|
|
@@ -177,7 +187,27 @@
|
|
|
177
187
|
const xRangeMinMax = $derived(extent<number>(ctx.xRange)) as [number, number];
|
|
178
188
|
const yRangeMinMax = $derived(extent<number>(ctx.yRange)) as [number, number];
|
|
179
189
|
|
|
180
|
-
const
|
|
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));
|
|
181
211
|
|
|
182
212
|
function getCoords(tick: any) {
|
|
183
213
|
switch (placement) {
|
|
@@ -342,7 +372,7 @@
|
|
|
342
372
|
}) satisfies ComponentProps<typeof Text>;
|
|
343
373
|
</script>
|
|
344
374
|
|
|
345
|
-
<
|
|
375
|
+
<Group
|
|
346
376
|
{...restProps}
|
|
347
377
|
data-placement={placement}
|
|
348
378
|
class={cls(layerClass('axis'), `placement-${placement}`, classes.root, className)}
|
|
@@ -374,7 +404,7 @@
|
|
|
374
404
|
{@const resolvedTickLabelProps = {
|
|
375
405
|
x: orientation === 'angle' ? radialTickCoordsX : tickCoords.x,
|
|
376
406
|
y: orientation === 'angle' ? radialTickCoordsY : tickCoords.y,
|
|
377
|
-
value:
|
|
407
|
+
value: tickFormat(tick, index),
|
|
378
408
|
...getDefaultTickLabelProps(tick),
|
|
379
409
|
motion,
|
|
380
410
|
...tickLabelProps,
|
|
@@ -386,7 +416,7 @@
|
|
|
386
416
|
),
|
|
387
417
|
}}
|
|
388
418
|
|
|
389
|
-
<
|
|
419
|
+
<Group {transitionIn} {transitionInParams} class={layerClass('axis-tick-group')}>
|
|
390
420
|
{#if grid !== false}
|
|
391
421
|
{@const ruleProps = extractLayerProps(grid, 'axis-grid')}
|
|
392
422
|
<Rule
|
|
@@ -404,7 +434,6 @@
|
|
|
404
434
|
'stroke-surface-content/50',
|
|
405
435
|
classes.tick
|
|
406
436
|
)}
|
|
407
|
-
<!-- Tick marks -->
|
|
408
437
|
{#if orientation === 'horizontal'}
|
|
409
438
|
<Line
|
|
410
439
|
x1={tickCoords.x}
|
|
@@ -434,13 +463,12 @@
|
|
|
434
463
|
/>
|
|
435
464
|
{/if}
|
|
436
465
|
{/if}
|
|
437
|
-
<!-- TODO: Add tick marks for radial (angle)? -->
|
|
438
466
|
|
|
439
467
|
{#if tickLabel}
|
|
440
468
|
{@render tickLabel({ props: resolvedTickLabelProps, index })}
|
|
441
469
|
{:else}
|
|
442
470
|
<Text {...resolvedTickLabelProps} />
|
|
443
471
|
{/if}
|
|
444
|
-
</
|
|
472
|
+
</Group>
|
|
445
473
|
{/each}
|
|
446
|
-
</
|
|
474
|
+
</Group>
|
|
@@ -36,6 +36,16 @@ export type AxisPropsWithoutHTML<In extends Transition = Transition> = {
|
|
|
36
36
|
* Control the number of ticks
|
|
37
37
|
*/
|
|
38
38
|
ticks?: TicksConfig;
|
|
39
|
+
/**
|
|
40
|
+
* Width or height of each tick in pxiels (responsive reduce)
|
|
41
|
+
*/
|
|
42
|
+
tickSpacing?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Whether to render tick labels on multiple lines for additional context
|
|
45
|
+
*
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
tickMultiline?: boolean;
|
|
39
49
|
/**
|
|
40
50
|
* Length of the tick line
|
|
41
51
|
* @default 4
|
|
@@ -50,7 +60,7 @@ export type AxisPropsWithoutHTML<In extends Transition = Transition> = {
|
|
|
50
60
|
/**
|
|
51
61
|
* Format tick labels
|
|
52
62
|
*/
|
|
53
|
-
format?: FormatType;
|
|
63
|
+
format?: FormatType | FormatConfig;
|
|
54
64
|
/**
|
|
55
65
|
* Props to apply to each tick label
|
|
56
66
|
*/
|
|
@@ -89,10 +99,11 @@ export type AxisPropsWithoutHTML<In extends Transition = Transition> = {
|
|
|
89
99
|
};
|
|
90
100
|
motion?: MotionProp;
|
|
91
101
|
};
|
|
92
|
-
export type AxisProps<In extends Transition = Transition> = AxisPropsWithoutHTML<In> & Without<
|
|
102
|
+
export type AxisProps<In extends Transition = Transition> = AxisPropsWithoutHTML<In> & Without<GroupProps, AxisPropsWithoutHTML<In>>;
|
|
93
103
|
import { type ComponentProps, type Snippet } from 'svelte';
|
|
94
104
|
import type { SVGAttributes } from 'svelte/elements';
|
|
95
|
-
import { type FormatType } from '@layerstack/utils';
|
|
105
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
106
|
+
import { type GroupProps } from './Group.svelte';
|
|
96
107
|
import Rule from './Rule.svelte';
|
|
97
108
|
import Text from './Text.svelte';
|
|
98
109
|
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import { createDimensionGetter, type Insets } from '../utils/rect.svelte.js';
|
|
3
3
|
|
|
4
4
|
export type BarPropsWithoutHTML = {
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* data to render the bar from
|
|
7
|
+
*/
|
|
8
|
+
data: Object;
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* Override `x` from context. Useful for multiple Bar instances
|
|
@@ -89,7 +92,7 @@
|
|
|
89
92
|
const ctx = getChartContext();
|
|
90
93
|
|
|
91
94
|
let {
|
|
92
|
-
|
|
95
|
+
data,
|
|
93
96
|
x = ctx.x,
|
|
94
97
|
y = ctx.y,
|
|
95
98
|
x1,
|
|
@@ -122,11 +125,11 @@
|
|
|
122
125
|
}))
|
|
123
126
|
);
|
|
124
127
|
|
|
125
|
-
const dimensions = $derived(getDimensions(
|
|
128
|
+
const dimensions = $derived(getDimensions(data) ?? { x: 0, y: 0, width: 0, height: 0 });
|
|
126
129
|
|
|
127
130
|
const isVertical = $derived(isScaleBand(ctx.xScale));
|
|
128
131
|
const valueAccessor = $derived(accessor(isVertical ? y : x));
|
|
129
|
-
const value = $derived(valueAccessor(
|
|
132
|
+
const value = $derived(valueAccessor(data));
|
|
130
133
|
const resolvedValue = $derived(Array.isArray(value) ? greatestAbs(value) : value);
|
|
131
134
|
|
|
132
135
|
// Resolved `rounded="edge"` based on orientation and value
|
|
@@ -21,16 +21,19 @@
|
|
|
21
21
|
children?: Snippet;
|
|
22
22
|
// TODO: investigate
|
|
23
23
|
[key: string]: any;
|
|
24
|
-
} & Omit<BarPropsWithoutHTML, '
|
|
24
|
+
} & Omit<BarPropsWithoutHTML, 'data' | 'children'>;
|
|
25
25
|
|
|
26
|
-
export type BarsProps = BarsPropsWithoutHTML & Omit<BarProps, '
|
|
26
|
+
export type BarsProps = BarsPropsWithoutHTML & Omit<BarProps, 'data'>;
|
|
27
27
|
</script>
|
|
28
28
|
|
|
29
29
|
<script lang="ts">
|
|
30
|
+
import type { Snippet } from 'svelte';
|
|
31
|
+
|
|
30
32
|
import Bar, { type BarProps, type BarPropsWithoutHTML } from './Bar.svelte';
|
|
33
|
+
import Group from './Group.svelte';
|
|
34
|
+
|
|
31
35
|
import { chartDataArray } from '../utils/common.js';
|
|
32
36
|
import { getChartContext } from './Chart.svelte';
|
|
33
|
-
import type { Snippet } from 'svelte';
|
|
34
37
|
import { extractLayerProps, layerClass } from '../utils/attributes.js';
|
|
35
38
|
|
|
36
39
|
let {
|
|
@@ -49,20 +52,20 @@
|
|
|
49
52
|
const data = $derived(chartDataArray(dataProp ?? ctx.data));
|
|
50
53
|
</script>
|
|
51
54
|
|
|
52
|
-
<
|
|
55
|
+
<Group class={layerClass('bars')}>
|
|
53
56
|
{#if children}
|
|
54
57
|
{@render children()}
|
|
55
58
|
{:else}
|
|
56
59
|
{#each data as d, i (key(d, i))}
|
|
57
60
|
<Bar
|
|
61
|
+
data={d}
|
|
58
62
|
{radius}
|
|
59
63
|
{strokeWidth}
|
|
60
64
|
{stroke}
|
|
61
|
-
bar={d}
|
|
62
65
|
fill={fill ?? (ctx.config.c ? ctx.cGet(d) : null)}
|
|
63
66
|
onclick={(e) => onBarClick(e, { data: d })}
|
|
64
67
|
{...extractLayerProps(restProps, 'bars-bar')}
|
|
65
68
|
/>
|
|
66
69
|
{/each}
|
|
67
70
|
{/if}
|
|
68
|
-
</
|
|
71
|
+
</Group>
|
|
@@ -18,10 +18,10 @@ export type BarsPropsWithoutHTML = {
|
|
|
18
18
|
}) => void;
|
|
19
19
|
children?: Snippet;
|
|
20
20
|
[key: string]: any;
|
|
21
|
-
} & Omit<BarPropsWithoutHTML, '
|
|
22
|
-
export type BarsProps = BarsPropsWithoutHTML & Omit<BarProps, '
|
|
23
|
-
import { type BarProps, type BarPropsWithoutHTML } from './Bar.svelte';
|
|
21
|
+
} & Omit<BarPropsWithoutHTML, 'data' | 'children'>;
|
|
22
|
+
export type BarsProps = BarsPropsWithoutHTML & Omit<BarProps, 'data'>;
|
|
24
23
|
import type { Snippet } from 'svelte';
|
|
24
|
+
import { type BarProps, type BarPropsWithoutHTML } from './Bar.svelte';
|
|
25
25
|
declare const Bars: import("svelte").Component<BarsProps, {}, "">;
|
|
26
26
|
type Bars = ReturnType<typeof Bars>;
|
|
27
27
|
export default Bars;
|
|
@@ -14,29 +14,37 @@
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The default children snippet which provides
|
|
17
|
-
* the id
|
|
17
|
+
* the id for the filter.
|
|
18
18
|
*/
|
|
19
|
-
children?: Snippet
|
|
19
|
+
children?: Snippet;
|
|
20
20
|
};
|
|
21
21
|
</script>
|
|
22
22
|
|
|
23
23
|
<script lang="ts">
|
|
24
|
+
import type { Snippet } from 'svelte';
|
|
25
|
+
import { getRenderContext } from './Chart.svelte';
|
|
24
26
|
import { createId } from '../utils/createId.js';
|
|
25
27
|
import { layerClass } from '../utils/attributes.js';
|
|
26
|
-
|
|
28
|
+
|
|
27
29
|
const uid = $props.id();
|
|
28
30
|
|
|
29
31
|
let { id = createId('blur-', uid), stdDeviation = 5, children }: BlurProps = $props();
|
|
32
|
+
|
|
33
|
+
const renderContext = getRenderContext();
|
|
30
34
|
</script>
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
<
|
|
34
|
-
<
|
|
35
|
-
|
|
36
|
-
</
|
|
36
|
+
{#if renderContext === 'svg'}
|
|
37
|
+
<defs>
|
|
38
|
+
<filter {id} class={layerClass('blur-filter')}>
|
|
39
|
+
<feGaussianBlur in="SourceGraphic" {stdDeviation} />
|
|
40
|
+
</filter>
|
|
41
|
+
</defs>
|
|
37
42
|
|
|
38
|
-
{#if children}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
{#if children}
|
|
44
|
+
<g filter="url(#{id})" class={layerClass('blur-g')}>
|
|
45
|
+
{@render children()}
|
|
46
|
+
</g>
|
|
47
|
+
{/if}
|
|
48
|
+
{:else if children}
|
|
49
|
+
{@render children()}
|
|
42
50
|
{/if}
|
|
@@ -11,12 +11,9 @@ export type BlurProps = {
|
|
|
11
11
|
stdDeviation?: number;
|
|
12
12
|
/**
|
|
13
13
|
* The default children snippet which provides
|
|
14
|
-
* the id
|
|
14
|
+
* the id for the filter.
|
|
15
15
|
*/
|
|
16
|
-
children?: Snippet
|
|
17
|
-
id: string;
|
|
18
|
-
url: string;
|
|
19
|
-
}]>;
|
|
16
|
+
children?: Snippet;
|
|
20
17
|
};
|
|
21
18
|
import type { Snippet } from 'svelte';
|
|
22
19
|
declare const Blur: import("svelte").Component<BlurProps, {}, "">;
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
/**
|
|
37
37
|
* Props to pass to the `<text>` element for month labels.
|
|
38
38
|
*/
|
|
39
|
-
monthLabel?: Partial<ComponentProps<typeof Text>>;
|
|
39
|
+
monthLabel?: boolean | Partial<ComponentProps<typeof Text>>;
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Tooltip context to setup mouse events to show tooltip for related data
|
|
43
43
|
*/
|
|
44
44
|
tooltipContext?: TooltipContextValue;
|
|
45
45
|
|
|
46
|
-
children?: Snippet<[{ cells: CalendarCell[] }]>;
|
|
46
|
+
children?: Snippet<[{ cells: CalendarCell[]; cellSize: [number, number] }]>;
|
|
47
47
|
} & Omit<
|
|
48
48
|
RectPropsWithoutHTML,
|
|
49
49
|
'children' | 'x' | 'y' | 'width' | 'height' | 'fill' | 'onpointermove' | 'onpointerleave'
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
import { type ComponentProps, type Snippet } from 'svelte';
|
|
58
58
|
import { timeDays, timeMonths, timeWeek, timeYear } from 'd3-time';
|
|
59
59
|
import { index } from 'd3-array';
|
|
60
|
-
import { format } from '
|
|
60
|
+
import { format } from '@layerstack/utils';
|
|
61
61
|
|
|
62
62
|
import Rect, { type RectPropsWithoutHTML } from './Rect.svelte';
|
|
63
63
|
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
start,
|
|
75
75
|
cellSize: cellSizeProp,
|
|
76
76
|
monthPath = false,
|
|
77
|
+
monthLabel = true,
|
|
77
78
|
tooltipContext: tooltip,
|
|
78
79
|
children,
|
|
79
|
-
monthLabel,
|
|
80
80
|
...restProps
|
|
81
81
|
}: CalendarPropsWithoutHTML = $props();
|
|
82
82
|
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
</script>
|
|
118
118
|
|
|
119
119
|
{#if children}
|
|
120
|
-
{@render children({ cells })}
|
|
120
|
+
{@render children({ cells, cellSize })}
|
|
121
121
|
{:else}
|
|
122
122
|
{#each cells as cell}
|
|
123
123
|
<Rect
|
|
@@ -136,11 +136,15 @@
|
|
|
136
136
|
{#if monthPath}
|
|
137
137
|
{#each yearMonths as date}
|
|
138
138
|
<MonthPath {date} {cellSize} {...extractLayerProps(monthPath, 'calendar-month-path')} />
|
|
139
|
+
{/each}
|
|
140
|
+
{/if}
|
|
139
141
|
|
|
142
|
+
{#if monthLabel}
|
|
143
|
+
{#each yearMonths as date}
|
|
140
144
|
<Text
|
|
141
145
|
x={timeWeek.count(timeYear.floor(date), timeWeek.ceil(date)) * cellSize[0]}
|
|
142
146
|
y={-4}
|
|
143
|
-
value={format(date, '
|
|
147
|
+
value={format(date, 'month', { variant: 'short' })}
|
|
144
148
|
{...extractLayerProps(monthLabel, 'calendar-month-label', 'text-xs')}
|
|
145
149
|
/>
|
|
146
150
|
{/each}
|
|
@@ -30,13 +30,14 @@ export type CalendarPropsWithoutHTML = {
|
|
|
30
30
|
/**
|
|
31
31
|
* Props to pass to the `<text>` element for month labels.
|
|
32
32
|
*/
|
|
33
|
-
monthLabel?: Partial<ComponentProps<typeof Text>>;
|
|
33
|
+
monthLabel?: boolean | Partial<ComponentProps<typeof Text>>;
|
|
34
34
|
/**
|
|
35
35
|
* Tooltip context to setup mouse events to show tooltip for related data
|
|
36
36
|
*/
|
|
37
37
|
tooltipContext?: TooltipContextValue;
|
|
38
38
|
children?: Snippet<[{
|
|
39
39
|
cells: CalendarCell[];
|
|
40
|
+
cellSize: [number, number];
|
|
40
41
|
}]>;
|
|
41
42
|
} & Omit<RectPropsWithoutHTML, 'children' | 'x' | 'y' | 'width' | 'height' | 'fill' | 'onpointermove' | 'onpointerleave'>;
|
|
42
43
|
export type CalendarProps = CalendarPropsWithoutHTML & Without<SVGAttributes<SVGRectElement>, CalendarPropsWithoutHTML>;
|