layerchart 2.0.0-next.4 → 2.0.0-next.41
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 +15 -2
- package/dist/components/AnnotationPoint.svelte +29 -11
- package/dist/components/AnnotationRange.svelte +18 -4
- package/dist/components/Arc.svelte +5 -5
- package/dist/components/Area.svelte +10 -2
- package/dist/components/Axis.svelte +175 -58
- package/dist/components/Axis.svelte.d.ts +23 -6
- package/dist/components/Bar.svelte +20 -15
- package/dist/components/Bar.svelte.d.ts +2 -2
- package/dist/components/Bars.svelte +4 -4
- package/dist/components/Blur.svelte +7 -6
- package/dist/components/Blur.svelte.d.ts +2 -5
- package/dist/components/BrushContext.svelte +45 -45
- package/dist/components/Calendar.svelte +31 -10
- package/dist/components/Calendar.svelte.d.ts +2 -1
- package/dist/components/Chart.svelte +76 -27
- package/dist/components/Chart.svelte.d.ts +26 -8
- package/dist/components/ChartClipPath.svelte +1 -1
- package/dist/components/Circle.svelte +44 -3
- package/dist/components/CircleClipPath.svelte +8 -1
- package/dist/components/ClipPath.svelte +1 -2
- package/dist/components/ColorRamp.svelte +1 -1
- package/dist/components/ComputedStyles.svelte +9 -2
- package/dist/components/Connector.svelte +3 -3
- package/dist/components/Connector.svelte.d.ts +1 -1
- package/dist/components/Ellipse.svelte +228 -0
- package/dist/components/Ellipse.svelte.d.ts +64 -0
- package/dist/components/ForceSimulation.svelte +184 -50
- package/dist/components/ForceSimulation.svelte.d.ts +95 -21
- package/dist/components/Frame.svelte +1 -1
- package/dist/components/GeoCircle.svelte +1 -1
- package/dist/components/GeoEdgeFade.svelte +1 -1
- package/dist/components/GeoPath.svelte +30 -8
- package/dist/components/GeoPoint.svelte +4 -5
- package/dist/components/GeoSpline.svelte +5 -5
- package/dist/components/GeoSpline.svelte.d.ts +1 -1
- package/dist/components/GeoTile.svelte +1 -1
- package/dist/components/Graticule.svelte +5 -5
- package/dist/components/Grid.svelte +60 -63
- package/dist/components/Group.svelte +13 -8
- package/dist/components/Group.svelte.d.ts +10 -3
- package/dist/components/Highlight.svelte +55 -28
- package/dist/components/Highlight.svelte.d.ts +4 -0
- package/dist/components/Hull.svelte +12 -5
- package/dist/components/Labels.svelte +24 -13
- package/dist/components/Labels.svelte.d.ts +12 -5
- package/dist/components/Legend.svelte +143 -70
- package/dist/components/Legend.svelte.d.ts +12 -8
- package/dist/components/Line.svelte +40 -3
- package/dist/components/LinearGradient.svelte +35 -4
- package/dist/components/Link.svelte +1 -1
- package/dist/components/Marker.svelte +37 -26
- package/dist/components/MonthPath.svelte +26 -12
- package/dist/components/MonthPath.svelte.d.ts +4 -3
- package/dist/components/MotionPath.svelte +1 -1
- package/dist/components/Pack.svelte.d.ts +10 -3
- package/dist/components/Partition.svelte.d.ts +10 -3
- package/dist/components/Pattern.svelte +5 -5
- package/dist/components/Pie.svelte +1 -2
- package/dist/components/Points.svelte +11 -72
- package/dist/components/Points.svelte.d.ts +1 -8
- package/dist/components/Polygon.svelte +309 -0
- package/dist/components/Polygon.svelte.d.ts +115 -0
- package/dist/components/RadialGradient.svelte +4 -6
- package/dist/components/Rect.svelte +55 -5
- package/dist/components/Rect.svelte.d.ts +2 -2
- package/dist/components/RectClipPath.svelte +4 -3
- package/dist/components/RectClipPath.svelte.d.ts +2 -2
- package/dist/components/Rule.svelte +167 -77
- package/dist/components/Rule.svelte.d.ts +7 -2
- package/dist/components/Spline.svelte +59 -28
- package/dist/components/Spline.svelte.d.ts +12 -4
- package/dist/components/Text.svelte +121 -73
- package/dist/components/Text.svelte.d.ts +6 -0
- package/dist/components/TileImage.svelte +19 -4
- package/dist/components/TransformContext.svelte +9 -3
- package/dist/components/TransformControls.svelte +89 -38
- package/dist/components/Tree.svelte.d.ts +10 -3
- package/dist/components/Treemap.svelte +63 -26
- package/dist/components/Treemap.svelte.d.ts +21 -14
- package/dist/components/Voronoi.svelte +12 -13
- package/dist/components/charts/ArcChart.svelte +43 -71
- package/dist/components/charts/ArcChart.svelte.d.ts +10 -3
- package/dist/components/charts/AreaChart.svelte +29 -59
- package/dist/components/charts/AreaChart.svelte.d.ts +10 -3
- package/dist/components/charts/BarChart.svelte +79 -71
- package/dist/components/charts/BarChart.svelte.d.ts +10 -3
- package/dist/components/charts/DefaultTooltip.svelte +3 -3
- package/dist/components/charts/DefaultTooltip.svelte.d.ts +1 -1
- package/dist/components/charts/LineChart.svelte +69 -75
- package/dist/components/charts/LineChart.svelte.d.ts +21 -8
- package/dist/components/charts/PieChart.svelte +44 -71
- package/dist/components/charts/PieChart.svelte.d.ts +10 -3
- package/dist/components/charts/ScatterChart.svelte +10 -39
- package/dist/components/charts/ScatterChart.svelte.d.ts +10 -3
- package/dist/components/charts/utils.svelte.d.ts +1 -19
- package/dist/components/charts/utils.svelte.js +7 -35
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +5 -1
- package/dist/components/layout/Canvas.svelte +96 -69
- package/dist/components/layout/Canvas.svelte.d.ts +6 -0
- package/dist/components/layout/Html.svelte +15 -9
- package/dist/components/layout/Layer.svelte +6 -4
- package/dist/components/layout/Layer.svelte.d.ts +6 -4
- package/dist/components/layout/Svg.svelte +19 -11
- package/dist/components/layout/WebGL.svelte +26 -6
- package/dist/components/layout/WebGL.svelte.d.ts +5 -2
- package/dist/components/tooltip/Tooltip.svelte +73 -36
- package/dist/components/tooltip/Tooltip.svelte.d.ts +10 -3
- package/dist/components/tooltip/TooltipContext.svelte +167 -54
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +19 -5
- package/dist/components/tooltip/TooltipHeader.svelte +32 -18
- package/dist/components/tooltip/TooltipHeader.svelte.d.ts +3 -3
- package/dist/components/tooltip/TooltipItem.svelte +46 -37
- package/dist/components/tooltip/TooltipItem.svelte.d.ts +3 -3
- package/dist/components/tooltip/TooltipList.svelte +12 -10
- package/dist/components/tooltip/TooltipSeparator.svelte +18 -10
- package/dist/components/tooltip/tooltipMetaContext.d.ts +2 -2
- package/dist/docs/Blockquote.svelte +6 -4
- package/dist/docs/Blockquote.svelte.d.ts +4 -19
- package/dist/docs/Code.svelte +70 -28
- package/dist/docs/Code.svelte.d.ts +9 -24
- 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/Preview.svelte +22 -23
- package/dist/docs/Preview.svelte.d.ts +5 -6
- package/dist/docs/TilesetField.svelte +20 -19
- package/dist/docs/TilesetField.svelte.d.ts +5 -22
- package/dist/docs/ViewSourceButton.svelte +10 -7
- package/dist/docs/ViewSourceButton.svelte.d.ts +7 -21
- package/dist/states/series.svelte.d.ts +30 -0
- package/dist/states/series.svelte.js +54 -0
- package/dist/styles/daisyui-5.css +6 -0
- package/dist/styles/shadcn-svelte.css +11 -0
- package/dist/styles/skeleton-3.css +15 -0
- package/dist/utils/arcText.svelte.js +4 -4
- package/dist/utils/array.d.ts +11 -0
- package/dist/utils/array.js +23 -0
- package/dist/utils/array.test.d.ts +1 -0
- package/dist/utils/array.test.js +200 -0
- package/dist/utils/attributes.d.ts +3 -13
- package/dist/utils/attributes.js +4 -18
- package/dist/utils/canvas.d.ts +77 -0
- package/dist/utils/canvas.js +105 -41
- package/dist/utils/common.d.ts +9 -0
- package/dist/utils/common.js +18 -1
- package/dist/utils/common.test.js +26 -1
- package/dist/utils/genData.d.ts +22 -8
- package/dist/utils/genData.js +34 -14
- package/dist/utils/graph/dagre.d.ts +4 -4
- package/dist/utils/graph/dagre.js +5 -7
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/math.d.ts +17 -0
- package/dist/utils/math.js +17 -0
- package/dist/utils/motion.svelte.js +1 -1
- package/dist/utils/path.d.ts +10 -0
- package/dist/utils/path.js +30 -0
- package/dist/utils/rect.svelte.d.ts +2 -2
- package/dist/utils/rect.svelte.js +73 -1
- package/dist/utils/scales.svelte.d.ts +9 -3
- package/dist/utils/scales.svelte.js +47 -4
- package/dist/utils/shape.d.ts +43 -0
- package/dist/utils/shape.js +59 -0
- package/dist/utils/stack.js +1 -1
- package/dist/utils/string.d.ts +49 -0
- package/dist/utils/string.js +4 -2
- package/dist/utils/ticks.d.ts +15 -4
- package/dist/utils/ticks.js +140 -159
- package/dist/utils/ticks.test.js +16 -26
- package/dist/utils/treemap.d.ts +1 -1
- package/dist/utils/types.d.ts +15 -2
- package/package.json +36 -35
- package/dist/utils/object.js +0 -2
|
@@ -71,7 +71,8 @@
|
|
|
71
71
|
Without<
|
|
72
72
|
Omit<SVGAttributes<SVGElement>, 'width' | 'height' | 'x' | 'y' | 'offset'>,
|
|
73
73
|
BarPropsWithoutHTML
|
|
74
|
-
|
|
74
|
+
> &
|
|
75
|
+
CommonEvents;
|
|
75
76
|
</script>
|
|
76
77
|
|
|
77
78
|
<script lang="ts">
|
|
@@ -81,10 +82,10 @@
|
|
|
81
82
|
import Rect from './Rect.svelte';
|
|
82
83
|
import Spline from './Spline.svelte';
|
|
83
84
|
|
|
84
|
-
import { isScaleBand } from '../utils/scales.svelte.js';
|
|
85
|
+
import { isScaleBand, isScaleTime } from '../utils/scales.svelte.js';
|
|
85
86
|
import { accessor, type Accessor } from '../utils/common.js';
|
|
86
87
|
import { getChartContext } from './Chart.svelte';
|
|
87
|
-
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
88
|
+
import type { CommonEvents, CommonStyleProps, Without } from '../utils/types.js';
|
|
88
89
|
import { extractLayerProps } from '../utils/attributes.js';
|
|
89
90
|
import { extractTweenConfig, type MotionProp } from '../utils/motion.svelte.js';
|
|
90
91
|
import Arc from './Arc.svelte';
|
|
@@ -127,7 +128,7 @@
|
|
|
127
128
|
|
|
128
129
|
const dimensions = $derived(getDimensions(data) ?? { x: 0, y: 0, width: 0, height: 0 });
|
|
129
130
|
|
|
130
|
-
const isVertical = $derived(isScaleBand(ctx.xScale));
|
|
131
|
+
const isVertical = $derived(isScaleBand(ctx.xScale) || isScaleTime(ctx.xScale));
|
|
131
132
|
const valueAccessor = $derived(accessor(isVertical ? y : x));
|
|
132
133
|
const value = $derived(valueAccessor(data));
|
|
133
134
|
const resolvedValue = $derived(Array.isArray(value) ? greatestAbs(value) : value);
|
|
@@ -136,10 +137,10 @@
|
|
|
136
137
|
const rounded = $derived(
|
|
137
138
|
roundedProp === 'edge'
|
|
138
139
|
? isVertical
|
|
139
|
-
? resolvedValue >= 0
|
|
140
|
+
? resolvedValue >= 0 && ctx.yRange[0] > ctx.yRange[1] // not inverted (bottom to top)
|
|
140
141
|
? 'top'
|
|
141
142
|
: 'bottom'
|
|
142
|
-
: resolvedValue >= 0
|
|
143
|
+
: resolvedValue >= 0 && ctx.xRange[0] < ctx.xRange[1] // not inverted (left to right)
|
|
143
144
|
? 'right'
|
|
144
145
|
: 'left'
|
|
145
146
|
: roundedProp
|
|
@@ -151,16 +152,20 @@
|
|
|
151
152
|
const bottomRight = $derived(['all', 'bottom', 'right', 'bottom-right'].includes(rounded));
|
|
152
153
|
const width = $derived(dimensions.width);
|
|
153
154
|
const height = $derived(dimensions.height);
|
|
154
|
-
|
|
155
|
+
|
|
156
|
+
// Clamp radius to prevent extending beyond bounding box
|
|
157
|
+
const r = $derived(Math.min(radius, width / 2, height / 2));
|
|
158
|
+
const diameter = $derived(2 * r);
|
|
159
|
+
|
|
155
160
|
const pathData = $derived(
|
|
156
|
-
`M${dimensions.x +
|
|
157
|
-
${topRight ? `a${
|
|
161
|
+
`M${dimensions.x + r},${dimensions.y} h${width - diameter}
|
|
162
|
+
${topRight ? `a${r},${r} 0 0 1 ${r},${r}` : `h${r}v${r}`}
|
|
158
163
|
v${height - diameter}
|
|
159
|
-
${bottomRight ? `a${
|
|
164
|
+
${bottomRight ? `a${r},${r} 0 0 1 ${-r},${r}` : `v${r}h${-r}`}
|
|
160
165
|
h${diameter - width}
|
|
161
|
-
${bottomLeft ? `a${
|
|
166
|
+
${bottomLeft ? `a${r},${r} 0 0 1 ${-r},${-r}` : `h${-r}v${-r}`}
|
|
162
167
|
v${diameter - height}
|
|
163
|
-
${topLeft ? `a${
|
|
168
|
+
${topLeft ? `a${r},${r} 0 0 1 ${r},${-r}` : `v${-r}h${r}`}
|
|
164
169
|
z`
|
|
165
170
|
.split('\n')
|
|
166
171
|
.join('')
|
|
@@ -179,7 +184,7 @@
|
|
|
179
184
|
{strokeWidth}
|
|
180
185
|
{opacity}
|
|
181
186
|
cornerRadius={radius}
|
|
182
|
-
{...extractLayerProps(restProps, 'bar')}
|
|
187
|
+
{...extractLayerProps(restProps, 'lc-bar')}
|
|
183
188
|
/>
|
|
184
189
|
{:else if rounded === 'all' || rounded === 'none' || radius === 0}
|
|
185
190
|
<Rect
|
|
@@ -195,7 +200,7 @@
|
|
|
195
200
|
{initialHeight}
|
|
196
201
|
{initialWidth}
|
|
197
202
|
{...dimensions}
|
|
198
|
-
{...extractLayerProps(restProps, 'bar')}
|
|
203
|
+
{...extractLayerProps(restProps, 'lc-bar')}
|
|
199
204
|
/>
|
|
200
205
|
{:else}
|
|
201
206
|
{@const tweenMotion = extractTweenConfig(motion)}
|
|
@@ -207,6 +212,6 @@
|
|
|
207
212
|
{strokeWidth}
|
|
208
213
|
{opacity}
|
|
209
214
|
motion={tweenMotion}
|
|
210
|
-
{...extractLayerProps(restProps, 'bar')}
|
|
215
|
+
{...extractLayerProps(restProps, 'lc-bar')}
|
|
211
216
|
/>
|
|
212
217
|
{/if}
|
|
@@ -41,10 +41,10 @@ export type BarPropsWithoutHTML = {
|
|
|
41
41
|
rounded?: 'all' | 'none' | 'edge' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
42
42
|
motion?: MotionProp<'x' | 'y' | 'width' | 'height'>;
|
|
43
43
|
} & CommonStyleProps;
|
|
44
|
-
export type BarProps = BarPropsWithoutHTML & Without<Omit<SVGAttributes<SVGElement>, 'width' | 'height' | 'x' | 'y' | 'offset'>, BarPropsWithoutHTML
|
|
44
|
+
export type BarProps = BarPropsWithoutHTML & Without<Omit<SVGAttributes<SVGElement>, 'width' | 'height' | 'x' | 'y' | 'offset'>, BarPropsWithoutHTML> & CommonEvents;
|
|
45
45
|
import type { SVGAttributes } from 'svelte/elements';
|
|
46
46
|
import { type Accessor } from '../utils/common.js';
|
|
47
|
-
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
47
|
+
import type { CommonEvents, CommonStyleProps, Without } from '../utils/types.js';
|
|
48
48
|
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
49
49
|
declare const Bar: import("svelte").Component<BarProps, {}, "">;
|
|
50
50
|
type Bar = ReturnType<typeof Bar>;
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
import Bar, { type BarProps, type BarPropsWithoutHTML } from './Bar.svelte';
|
|
33
33
|
import Group from './Group.svelte';
|
|
34
34
|
|
|
35
|
-
import { chartDataArray } from '../utils/common.js';
|
|
36
35
|
import { getChartContext } from './Chart.svelte';
|
|
37
|
-
import {
|
|
36
|
+
import { chartDataArray } from '../utils/common.js';
|
|
37
|
+
import { extractLayerProps } from '../utils/attributes.js';
|
|
38
38
|
|
|
39
39
|
let {
|
|
40
40
|
fill,
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
const data = $derived(chartDataArray(dataProp ?? ctx.data));
|
|
53
53
|
</script>
|
|
54
54
|
|
|
55
|
-
<Group class=
|
|
55
|
+
<Group class="lc-bars">
|
|
56
56
|
{#if children}
|
|
57
57
|
{@render children()}
|
|
58
58
|
{:else}
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
{stroke}
|
|
65
65
|
fill={fill ?? (ctx.config.c ? ctx.cGet(d) : null)}
|
|
66
66
|
onclick={(e) => onBarClick(e, { data: d })}
|
|
67
|
-
{...extractLayerProps(restProps, 'bars-bar')}
|
|
67
|
+
{...extractLayerProps(restProps, 'lc-bars-bar')}
|
|
68
68
|
/>
|
|
69
69
|
{/each}
|
|
70
70
|
{/if}
|
|
@@ -14,9 +14,9 @@
|
|
|
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
|
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
import type { Snippet } from 'svelte';
|
|
25
25
|
import { getRenderContext } from './Chart.svelte';
|
|
26
26
|
import { createId } from '../utils/createId.js';
|
|
27
|
-
import { layerClass } from '../utils/attributes.js';
|
|
28
27
|
|
|
29
28
|
const uid = $props.id();
|
|
30
29
|
|
|
@@ -35,14 +34,16 @@
|
|
|
35
34
|
|
|
36
35
|
{#if renderContext === 'svg'}
|
|
37
36
|
<defs>
|
|
38
|
-
<filter {id} class=
|
|
37
|
+
<filter {id} class="lc-blur-filter">
|
|
39
38
|
<feGaussianBlur in="SourceGraphic" {stdDeviation} />
|
|
40
39
|
</filter>
|
|
41
40
|
</defs>
|
|
42
41
|
|
|
43
42
|
{#if children}
|
|
44
|
-
<g filter="url(#{id})" class=
|
|
45
|
-
{@render children(
|
|
43
|
+
<g filter="url(#{id})" class="lc-blur-g">
|
|
44
|
+
{@render children()}
|
|
46
45
|
</g>
|
|
47
46
|
{/if}
|
|
47
|
+
{:else if children}
|
|
48
|
+
{@render children()}
|
|
48
49
|
{/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, {}, "">;
|
|
@@ -148,7 +148,6 @@
|
|
|
148
148
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
149
149
|
import { getChartContext } from './Chart.svelte';
|
|
150
150
|
import type { Snippet } from 'svelte';
|
|
151
|
-
import { layerClass } from '../utils/attributes.js';
|
|
152
151
|
|
|
153
152
|
const ctx = getChartContext();
|
|
154
153
|
|
|
@@ -319,7 +318,7 @@
|
|
|
319
318
|
_range.width < RESET_THRESHOLD ||
|
|
320
319
|
_range.height < RESET_THRESHOLD
|
|
321
320
|
) {
|
|
322
|
-
// Clicked on frame, or pointer delta was
|
|
321
|
+
// Clicked on frame, or pointer delta was less than threshold (default: 1px)
|
|
323
322
|
if (ignoreResetClick) {
|
|
324
323
|
logger.debug('ignoring frame click reset');
|
|
325
324
|
} else {
|
|
@@ -463,7 +462,6 @@
|
|
|
463
462
|
{#if disabled}
|
|
464
463
|
{@render children?.({ brushContext })}
|
|
465
464
|
{:else}
|
|
466
|
-
{@const handleClass = layerClass('brush-handle')}
|
|
467
465
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
468
466
|
<div
|
|
469
467
|
bind:this={rootEl}
|
|
@@ -471,12 +469,12 @@
|
|
|
471
469
|
style:left="{ctx.padding.left}px"
|
|
472
470
|
style:width="{ctx.width}px"
|
|
473
471
|
style:height="{ctx.height}px"
|
|
474
|
-
class={cls(
|
|
472
|
+
class={cls('lc-brush-context')}
|
|
475
473
|
onpointerdown={createRange}
|
|
476
474
|
ondblclick={() => selectAll()}
|
|
477
475
|
>
|
|
478
476
|
<div
|
|
479
|
-
class={cls(
|
|
477
|
+
class={cls('lc-brush-container')}
|
|
480
478
|
style:top="-{ctx.padding.top ?? 0}px"
|
|
481
479
|
style:left="-{ctx.padding.left ?? 0}px"
|
|
482
480
|
style:width="{ctx.containerWidth}px"
|
|
@@ -492,13 +490,7 @@
|
|
|
492
490
|
style:top="{_range.y}px"
|
|
493
491
|
style:width="{_range.width}px"
|
|
494
492
|
style:height="{_range.height}px"
|
|
495
|
-
class={cls(
|
|
496
|
-
layerClass('brush-range'),
|
|
497
|
-
'absolute bg-surface-content/10 cursor-move select-none',
|
|
498
|
-
'z-10',
|
|
499
|
-
classes.range,
|
|
500
|
-
range?.class
|
|
501
|
-
)}
|
|
493
|
+
class={cls('lc-brush-range', classes.range, range?.class)}
|
|
502
494
|
onpointerdown={adjustRange}
|
|
503
495
|
ondblclick={() => reset()}
|
|
504
496
|
></div>
|
|
@@ -511,14 +503,7 @@
|
|
|
511
503
|
style:width="{_range.width}px"
|
|
512
504
|
style:height="{handleSize}px"
|
|
513
505
|
data-position="top"
|
|
514
|
-
class={cls(
|
|
515
|
-
handleClass,
|
|
516
|
-
'cursor-ns-resize select-none',
|
|
517
|
-
'range absolute',
|
|
518
|
-
'z-10',
|
|
519
|
-
classes.handle,
|
|
520
|
-
handle?.class
|
|
521
|
-
)}
|
|
506
|
+
class={cls('lc-brush-handle', classes.handle, handle?.class)}
|
|
522
507
|
onpointerdown={adjustTop}
|
|
523
508
|
ondblclick={(e) => {
|
|
524
509
|
e.stopPropagation();
|
|
@@ -536,15 +521,7 @@
|
|
|
536
521
|
style:width="{_range.width}px"
|
|
537
522
|
style:height="{handleSize}px"
|
|
538
523
|
data-position="bottom"
|
|
539
|
-
class={cls(
|
|
540
|
-
handleClass,
|
|
541
|
-
'handle bottom',
|
|
542
|
-
'cursor-ns-resize select-none',
|
|
543
|
-
'range absolute',
|
|
544
|
-
'z-10',
|
|
545
|
-
classes.handle,
|
|
546
|
-
handle?.class
|
|
547
|
-
)}
|
|
524
|
+
class={cls('lc-brush-handle', classes.handle, handle?.class)}
|
|
548
525
|
onpointerdown={adjustBottom}
|
|
549
526
|
ondblclick={(e) => {
|
|
550
527
|
e.stopPropagation();
|
|
@@ -564,14 +541,7 @@
|
|
|
564
541
|
style:width="{handleSize}px"
|
|
565
542
|
style:height="{_range.height}px"
|
|
566
543
|
data-position="left"
|
|
567
|
-
class={cls(
|
|
568
|
-
handleClass,
|
|
569
|
-
'cursor-ew-resize select-none',
|
|
570
|
-
'range absolute',
|
|
571
|
-
'z-10',
|
|
572
|
-
classes.handle,
|
|
573
|
-
handle?.class
|
|
574
|
-
)}
|
|
544
|
+
class={cls('lc-brush-handle', classes.handle, handle?.class)}
|
|
575
545
|
onpointerdown={adjustLeft}
|
|
576
546
|
ondblclick={(e) => {
|
|
577
547
|
e.stopPropagation();
|
|
@@ -589,14 +559,7 @@
|
|
|
589
559
|
style:width="{handleSize}px"
|
|
590
560
|
style:height="{_range.height}px"
|
|
591
561
|
data-position="right"
|
|
592
|
-
class={cls(
|
|
593
|
-
handleClass,
|
|
594
|
-
'cursor-ew-resize select-none',
|
|
595
|
-
'range absolute',
|
|
596
|
-
'z-10',
|
|
597
|
-
classes.handle,
|
|
598
|
-
handle?.class
|
|
599
|
-
)}
|
|
562
|
+
class={cls('lc-brush-handle', classes.handle, handle?.class)}
|
|
600
563
|
onpointerdown={adjustRight}
|
|
601
564
|
ondblclick={(e) => {
|
|
602
565
|
e.stopPropagation();
|
|
@@ -610,3 +573,40 @@
|
|
|
610
573
|
{/if}
|
|
611
574
|
</div>
|
|
612
575
|
{/if}
|
|
576
|
+
|
|
577
|
+
<style>
|
|
578
|
+
@layer base {
|
|
579
|
+
:where(.lc-brush-context) {
|
|
580
|
+
position: absolute;
|
|
581
|
+
touch-action: none;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
:where(.lc-brush-container) {
|
|
585
|
+
position: absolute;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
:where(.lc-brush-range) {
|
|
589
|
+
position: absolute;
|
|
590
|
+
cursor: move;
|
|
591
|
+
user-select: none;
|
|
592
|
+
z-index: 10;
|
|
593
|
+
background: color-mix(in oklab, var(--color-surface-content, currentColor) 10%, transparent);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
:where(.lc-brush-handle) {
|
|
597
|
+
position: absolute;
|
|
598
|
+
user-select: none;
|
|
599
|
+
z-index: 10;
|
|
600
|
+
|
|
601
|
+
&[data-position='top'],
|
|
602
|
+
&[data-position='bottom'] {
|
|
603
|
+
cursor: ns-resize;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
&[data-position='left'],
|
|
607
|
+
&[data-position='right'] {
|
|
608
|
+
cursor: ew-resize;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
</style>
|
|
@@ -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
|
|
@@ -128,20 +128,41 @@
|
|
|
128
128
|
fill={cell.color}
|
|
129
129
|
onpointermove={(e) => tooltip?.show(e, cell.data)}
|
|
130
130
|
onpointerleave={(e) => tooltip?.hide()}
|
|
131
|
-
{
|
|
131
|
+
strokeWidth={1}
|
|
132
|
+
{...extractLayerProps(restProps, 'lc-calendar-cell')}
|
|
132
133
|
/>
|
|
133
134
|
{/each}
|
|
134
135
|
{/if}
|
|
135
136
|
|
|
136
137
|
{#if monthPath}
|
|
137
138
|
{#each yearMonths as date}
|
|
138
|
-
<MonthPath {date} {cellSize} {...extractLayerProps(monthPath, 'calendar-month-path')} />
|
|
139
|
+
<MonthPath {date} {cellSize} {...extractLayerProps(monthPath, 'lc-calendar-month-path')} />
|
|
140
|
+
{/each}
|
|
141
|
+
{/if}
|
|
139
142
|
|
|
143
|
+
{#if monthLabel}
|
|
144
|
+
{#each yearMonths as date}
|
|
140
145
|
<Text
|
|
141
146
|
x={timeWeek.count(timeYear.floor(date), timeWeek.ceil(date)) * cellSize[0]}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
{...extractLayerProps(monthLabel, 'calendar-month-label'
|
|
147
|
+
value={format(date, 'month', { variant: 'short' })}
|
|
148
|
+
capHeight="7px"
|
|
149
|
+
{...extractLayerProps(monthLabel, 'lc-calendar-month-label')}
|
|
145
150
|
/>
|
|
146
151
|
{/each}
|
|
147
152
|
{/if}
|
|
153
|
+
|
|
154
|
+
<style>
|
|
155
|
+
@layer components {
|
|
156
|
+
:global(:where(.lc-calendar-cell)) {
|
|
157
|
+
--stroke-color: color-mix(
|
|
158
|
+
in oklab,
|
|
159
|
+
var(--color-surface-content, currentColor) 5%,
|
|
160
|
+
transparent
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
:global(:where(.lc-calendar-month-label)) {
|
|
165
|
+
font-size: 12px;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
</style>
|
|
@@ -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>;
|