layerchart 2.0.0-next.4 → 2.0.0-next.40
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 +65 -27
- 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/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 +35 -35
- package/dist/utils/object.js +0 -2
|
@@ -20,30 +20,32 @@
|
|
|
20
20
|
*
|
|
21
21
|
* @bindable
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
pathRef?: SVGPathElement;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
export type MonthPathProps = MonthPathPropsWithoutHTML &
|
|
27
|
-
|
|
27
|
+
// we omit the spline props to avoid conflicts with attribute names since we are
|
|
28
|
+
// passing them through to `<Spline />`
|
|
29
|
+
Without<SVGAttributes<SVGPathElement>, MonthPathPropsWithoutHTML & SplinePropsWithoutHTML>;
|
|
28
30
|
</script>
|
|
29
31
|
|
|
30
32
|
<script lang="ts">
|
|
31
33
|
import { timeWeek, timeYear } from 'd3-time';
|
|
32
|
-
import { endOfMonth } from 'date-fns';
|
|
33
34
|
import { cls } from '@layerstack/tailwind';
|
|
34
|
-
import {
|
|
35
|
+
import { endOfInterval } from '@layerstack/utils';
|
|
36
|
+
import Spline, { type SplinePropsWithoutHTML } from './Spline.svelte';
|
|
35
37
|
|
|
36
38
|
let {
|
|
37
39
|
date,
|
|
38
40
|
cellSize: cellSizeProp,
|
|
39
|
-
|
|
41
|
+
pathRef: pathRefProp = $bindable(),
|
|
40
42
|
class: className,
|
|
41
43
|
...restProps
|
|
42
44
|
}: MonthPathProps = $props();
|
|
43
45
|
|
|
44
|
-
let
|
|
46
|
+
let pathRef = $state<SVGPathElement>();
|
|
45
47
|
$effect.pre(() => {
|
|
46
|
-
|
|
48
|
+
pathRefProp = pathRef;
|
|
47
49
|
});
|
|
48
50
|
|
|
49
51
|
const cellSize = $derived(
|
|
@@ -55,7 +57,7 @@
|
|
|
55
57
|
const startWeek = $derived(timeWeek.count(timeYear(date), date));
|
|
56
58
|
|
|
57
59
|
// end of month
|
|
58
|
-
const monthEnd = $derived(
|
|
60
|
+
const monthEnd = $derived(endOfInterval('month', date));
|
|
59
61
|
const endDayOfWeek = $derived(monthEnd.getDay());
|
|
60
62
|
const endWeek = $derived(timeWeek.count(timeYear(monthEnd), monthEnd));
|
|
61
63
|
|
|
@@ -68,10 +70,22 @@
|
|
|
68
70
|
`);
|
|
69
71
|
</script>
|
|
70
72
|
|
|
71
|
-
<
|
|
72
|
-
bind:
|
|
73
|
-
|
|
73
|
+
<Spline
|
|
74
|
+
bind:pathRef
|
|
75
|
+
{pathData}
|
|
74
76
|
fill="none"
|
|
75
|
-
class={cls(
|
|
77
|
+
class={cls('lc-month-path', className)}
|
|
76
78
|
{...restProps}
|
|
77
79
|
/>
|
|
80
|
+
|
|
81
|
+
<style>
|
|
82
|
+
@layer components {
|
|
83
|
+
:global(:where(.lc-month-path)) {
|
|
84
|
+
--stroke-color: color-mix(
|
|
85
|
+
in oklab,
|
|
86
|
+
var(--color-surface-content, currentColor) 20%,
|
|
87
|
+
transparent
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
</style>
|
|
@@ -16,9 +16,10 @@ export type MonthPathPropsWithoutHTML = {
|
|
|
16
16
|
*
|
|
17
17
|
* @bindable
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
pathRef?: SVGPathElement;
|
|
20
20
|
};
|
|
21
|
-
export type MonthPathProps = MonthPathPropsWithoutHTML & Without<SVGAttributes<SVGPathElement>, MonthPathPropsWithoutHTML>;
|
|
22
|
-
|
|
21
|
+
export type MonthPathProps = MonthPathPropsWithoutHTML & Without<SVGAttributes<SVGPathElement>, MonthPathPropsWithoutHTML & SplinePropsWithoutHTML>;
|
|
22
|
+
import { type SplinePropsWithoutHTML } from './Spline.svelte';
|
|
23
|
+
declare const MonthPath: import("svelte").Component<MonthPathProps, {}, "pathRef">;
|
|
23
24
|
type MonthPath = ReturnType<typeof MonthPath>;
|
|
24
25
|
export default MonthPath;
|
|
@@ -25,10 +25,17 @@ export type PackProps<T> = {
|
|
|
25
25
|
nodes: HierarchyCircularNode<T>[];
|
|
26
26
|
}]>;
|
|
27
27
|
};
|
|
28
|
+
declare function $$render<T>(): {
|
|
29
|
+
props: PackProps<T>;
|
|
30
|
+
exports: {};
|
|
31
|
+
bindings: "nodes";
|
|
32
|
+
slots: {};
|
|
33
|
+
events: {};
|
|
34
|
+
};
|
|
28
35
|
declare class __sveltets_Render<T> {
|
|
29
|
-
props():
|
|
30
|
-
events():
|
|
31
|
-
slots():
|
|
36
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
37
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
38
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
32
39
|
bindings(): "nodes";
|
|
33
40
|
exports(): {};
|
|
34
41
|
}
|
|
@@ -32,10 +32,17 @@ export type PartitionProps<T> = {
|
|
|
32
32
|
nodes: HierarchyRectangularNode<T>[];
|
|
33
33
|
}]>;
|
|
34
34
|
};
|
|
35
|
+
declare function $$render<T>(): {
|
|
36
|
+
props: PartitionProps<T>;
|
|
37
|
+
exports: {};
|
|
38
|
+
bindings: "nodes";
|
|
39
|
+
slots: {};
|
|
40
|
+
events: {};
|
|
41
|
+
};
|
|
35
42
|
declare class __sveltets_Render<T> {
|
|
36
|
-
props():
|
|
37
|
-
events():
|
|
38
|
-
slots():
|
|
43
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
44
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
45
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
39
46
|
bindings(): "nodes";
|
|
40
47
|
exports(): {};
|
|
41
48
|
}
|
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
const lineDefs = Array.isArray(linesProp) ? linesProp : linesProp === true ? [{}] : [linesProp];
|
|
155
155
|
for (const line of lineDefs) {
|
|
156
156
|
// const spacing = Math.abs(line.spacing);
|
|
157
|
-
const stroke = line.color ?? 'var(--color-surface-content)';
|
|
157
|
+
const stroke = line.color ?? 'var(--color-surface-content, currentColor)';
|
|
158
158
|
const strokeWidth = line.width ?? 1;
|
|
159
159
|
const opacity = line.opacity ?? 1;
|
|
160
160
|
|
|
@@ -217,7 +217,7 @@
|
|
|
217
217
|
cx: size / 4,
|
|
218
218
|
cy: size / 4,
|
|
219
219
|
r: circle.radius ?? 1,
|
|
220
|
-
fill: circle.color ?? 'var(--color-surface-content)',
|
|
220
|
+
fill: circle.color ?? 'var(--color-surface-content, currentColor)',
|
|
221
221
|
opacity: circle.opacity ?? 1,
|
|
222
222
|
},
|
|
223
223
|
{
|
|
@@ -225,7 +225,7 @@
|
|
|
225
225
|
cx: (size * 3) / 4,
|
|
226
226
|
cy: (size * 3) / 4,
|
|
227
227
|
r: circle.radius ?? 1,
|
|
228
|
-
fill: circle.color ?? 'var(--color-surface-content)',
|
|
228
|
+
fill: circle.color ?? 'var(--color-surface-content, currentColor)',
|
|
229
229
|
opacity: circle.opacity ?? 1,
|
|
230
230
|
}
|
|
231
231
|
);
|
|
@@ -235,7 +235,7 @@
|
|
|
235
235
|
cx: size / 2,
|
|
236
236
|
cy: size / 2,
|
|
237
237
|
r: circle.radius ?? 1,
|
|
238
|
-
fill: circle.color ?? 'var(--color-surface-content)',
|
|
238
|
+
fill: circle.color ?? 'var(--color-surface-content, currentColor)',
|
|
239
239
|
opacity: circle.opacity ?? 1,
|
|
240
240
|
});
|
|
241
241
|
}
|
|
@@ -265,7 +265,7 @@
|
|
|
265
265
|
{width}
|
|
266
266
|
{height}
|
|
267
267
|
patternUnits="userSpaceOnUse"
|
|
268
|
-
{...extractLayerProps(restProps, 'pattern')}
|
|
268
|
+
{...extractLayerProps(restProps, 'lc-pattern')}
|
|
269
269
|
>
|
|
270
270
|
{#if patternContent}
|
|
271
271
|
{@render patternContent?.()}
|
|
@@ -81,7 +81,6 @@
|
|
|
81
81
|
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
82
82
|
import { getChartContext } from './Chart.svelte';
|
|
83
83
|
import type { Snippet } from 'svelte';
|
|
84
|
-
import { layerClass } from '../utils/attributes.js';
|
|
85
84
|
|
|
86
85
|
/*
|
|
87
86
|
TODO:
|
|
@@ -140,7 +139,7 @@
|
|
|
140
139
|
{:else}
|
|
141
140
|
{#each arcs as arc}
|
|
142
141
|
<Arc
|
|
143
|
-
class=
|
|
142
|
+
class="lc-pie-arc"
|
|
144
143
|
startAngle={arc.startAngle}
|
|
145
144
|
endAngle={arc.endAngle}
|
|
146
145
|
padAngle={arc.padAngle}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
4
|
|
|
5
5
|
export type Point = { x: number; y: number; r: number; xValue: any; yValue: any; data: any };
|
|
6
6
|
type Offset = number | ((value: number, context: any) => number) | undefined;
|
|
@@ -37,13 +37,6 @@
|
|
|
37
37
|
*/
|
|
38
38
|
offsetY?: Offset;
|
|
39
39
|
|
|
40
|
-
/**
|
|
41
|
-
* Enable showing links between related points (array x/y accessors)
|
|
42
|
-
*
|
|
43
|
-
* @default false
|
|
44
|
-
*/
|
|
45
|
-
links?: boolean | Partial<ComponentProps<typeof Link>>;
|
|
46
|
-
|
|
47
40
|
children?: Snippet<[{ points: Point[] }]>;
|
|
48
41
|
} & CommonStyleProps;
|
|
49
42
|
|
|
@@ -52,11 +45,9 @@
|
|
|
52
45
|
</script>
|
|
53
46
|
|
|
54
47
|
<script lang="ts">
|
|
55
|
-
import { extent } from 'd3-array';
|
|
56
48
|
import { pointRadial } from 'd3-shape';
|
|
57
49
|
|
|
58
50
|
import Circle, { type CircleProps } from './Circle.svelte';
|
|
59
|
-
import Link from './Link.svelte';
|
|
60
51
|
import { isScaleBand, type AnyScale } from '../utils/scales.svelte.js';
|
|
61
52
|
import { accessor, type Accessor } from '../utils/common.js';
|
|
62
53
|
import { getChartContext } from './Chart.svelte';
|
|
@@ -71,7 +62,6 @@
|
|
|
71
62
|
r = 5,
|
|
72
63
|
offsetX,
|
|
73
64
|
offsetY,
|
|
74
|
-
links = false,
|
|
75
65
|
fill,
|
|
76
66
|
fillOpacity,
|
|
77
67
|
stroke,
|
|
@@ -103,9 +93,14 @@
|
|
|
103
93
|
const scaledX: number = ctx.xScale(xVal);
|
|
104
94
|
const scaledY: number = ctx.yScale(yVal);
|
|
105
95
|
|
|
96
|
+
const x = scaledX + getOffset(scaledX, offsetX, ctx.xScale);
|
|
97
|
+
const y = scaledY + getOffset(scaledY, offsetY, ctx.yScale);
|
|
98
|
+
|
|
99
|
+
const radialPoint = pointRadial(x, y);
|
|
100
|
+
|
|
106
101
|
return {
|
|
107
|
-
x:
|
|
108
|
-
y:
|
|
102
|
+
x: ctx.radial ? radialPoint[0] : x,
|
|
103
|
+
y: ctx.radial ? radialPoint[1] : y,
|
|
109
104
|
r: ctx.config.r ? ctx.rGet(d) : r,
|
|
110
105
|
xValue: xVal,
|
|
111
106
|
yValue: yVal,
|
|
@@ -131,78 +126,22 @@
|
|
|
131
126
|
return [];
|
|
132
127
|
}) as Point[]
|
|
133
128
|
);
|
|
134
|
-
|
|
135
|
-
const _links = $derived(
|
|
136
|
-
pointsData.flatMap((d: any) => {
|
|
137
|
-
const xValue = xAccessor(d);
|
|
138
|
-
const yValue = yAccessor(d);
|
|
139
|
-
|
|
140
|
-
if (Array.isArray(xValue)) {
|
|
141
|
-
/*
|
|
142
|
-
x={["prop1" ,"prop2"]}
|
|
143
|
-
y="prop3"
|
|
144
|
-
*/
|
|
145
|
-
const [xMin, xMax] = extent(ctx.xGet(d)) as unknown as [number, number];
|
|
146
|
-
const y = ctx.yGet(d) + getOffset(ctx.yGet(d), offsetY, ctx.yScale);
|
|
147
|
-
return {
|
|
148
|
-
source: {
|
|
149
|
-
x: xMin + getOffset(xMin, offsetX, ctx.xScale) + (ctx.config.r ? ctx.rGet(d) : r),
|
|
150
|
-
y,
|
|
151
|
-
},
|
|
152
|
-
target: {
|
|
153
|
-
x: xMax + getOffset(xMax, offsetX, ctx.xScale) - (ctx.config.r ? ctx.rGet(d) : r),
|
|
154
|
-
y: y,
|
|
155
|
-
},
|
|
156
|
-
data: d,
|
|
157
|
-
};
|
|
158
|
-
} else if (Array.isArray(yValue)) {
|
|
159
|
-
/*
|
|
160
|
-
x="prop1"
|
|
161
|
-
y={["prop2" ,"prop3"]}
|
|
162
|
-
*/
|
|
163
|
-
const x = ctx.xGet(d) + getOffset(ctx.xGet(d), offsetX, ctx.xScale);
|
|
164
|
-
const [yMin, yMax] = extent(ctx.yGet(d)) as unknown as [number, number];
|
|
165
|
-
return {
|
|
166
|
-
source: {
|
|
167
|
-
x: x,
|
|
168
|
-
y: yMin + getOffset(yMin, offsetY, ctx.yScale),
|
|
169
|
-
},
|
|
170
|
-
target: {
|
|
171
|
-
x: x,
|
|
172
|
-
y: yMax + getOffset(yMax, offsetY, ctx.yScale),
|
|
173
|
-
},
|
|
174
|
-
data: d,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
})
|
|
178
|
-
);
|
|
179
129
|
</script>
|
|
180
130
|
|
|
181
131
|
{#if children}
|
|
182
132
|
{@render children({ points })}
|
|
183
133
|
{:else}
|
|
184
|
-
{#if links}
|
|
185
|
-
{#each _links as link}
|
|
186
|
-
<Link
|
|
187
|
-
data={link}
|
|
188
|
-
stroke={fill ?? (ctx.config.c ? ctx.cGet(link.data) : null)}
|
|
189
|
-
{...extractLayerProps(links, 'points-link')}
|
|
190
|
-
/>
|
|
191
|
-
{/each}
|
|
192
|
-
{/if}
|
|
193
|
-
|
|
194
134
|
{#each points as point}
|
|
195
|
-
{@const radialPoint = pointRadial(point.x, point.y)}
|
|
196
135
|
<Circle
|
|
197
|
-
cx={
|
|
198
|
-
cy={
|
|
136
|
+
cx={point.x}
|
|
137
|
+
cy={point.y}
|
|
199
138
|
r={point.r}
|
|
200
139
|
fill={fill ?? (ctx.config.c ? ctx.cGet(point.data) : null)}
|
|
201
140
|
{fillOpacity}
|
|
202
141
|
{stroke}
|
|
203
142
|
{strokeWidth}
|
|
204
143
|
{opacity}
|
|
205
|
-
{...extractLayerProps(restProps, 'point')}
|
|
144
|
+
{...extractLayerProps(restProps, 'lc-point')}
|
|
206
145
|
/>
|
|
207
146
|
{/each}
|
|
208
147
|
{/if}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
3
|
export type Point = {
|
|
4
4
|
x: number;
|
|
5
5
|
y: number;
|
|
@@ -36,19 +36,12 @@ export type PointsPropsWithoutHTML = {
|
|
|
36
36
|
* The offset of the point in the y direction
|
|
37
37
|
*/
|
|
38
38
|
offsetY?: Offset;
|
|
39
|
-
/**
|
|
40
|
-
* Enable showing links between related points (array x/y accessors)
|
|
41
|
-
*
|
|
42
|
-
* @default false
|
|
43
|
-
*/
|
|
44
|
-
links?: boolean | Partial<ComponentProps<typeof Link>>;
|
|
45
39
|
children?: Snippet<[{
|
|
46
40
|
points: Point[];
|
|
47
41
|
}]>;
|
|
48
42
|
} & CommonStyleProps;
|
|
49
43
|
export type PointsProps = PointsPropsWithoutHTML & Omit<Without<CircleProps, PointsPropsWithoutHTML>, 'ref'>;
|
|
50
44
|
import { type CircleProps } from './Circle.svelte';
|
|
51
|
-
import Link from './Link.svelte';
|
|
52
45
|
import { type Accessor } from '../utils/common.js';
|
|
53
46
|
declare const Points: import("svelte").Component<PointsProps, {}, "">;
|
|
54
47
|
type Points = ReturnType<typeof Points>;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
3
|
+
|
|
4
|
+
export type PolygonPropsWithoutHTML = {
|
|
5
|
+
/**
|
|
6
|
+
* The center x position of the polygon.
|
|
7
|
+
*
|
|
8
|
+
* @default 0
|
|
9
|
+
*/
|
|
10
|
+
cx?: number;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The initial center x position of the polygon.
|
|
14
|
+
*
|
|
15
|
+
* @default cx
|
|
16
|
+
*/
|
|
17
|
+
initialCx?: number;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The center y position of the polygon.
|
|
21
|
+
*
|
|
22
|
+
* @default 0
|
|
23
|
+
*/
|
|
24
|
+
cy?: number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The initial center y position of the polygon.
|
|
28
|
+
*
|
|
29
|
+
* @default cy
|
|
30
|
+
*/
|
|
31
|
+
initialCy?: number;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The radius of the polygon.
|
|
35
|
+
*
|
|
36
|
+
* @default 1
|
|
37
|
+
*/
|
|
38
|
+
r?: number;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The initial radius of the polygon.
|
|
42
|
+
*
|
|
43
|
+
* @default r
|
|
44
|
+
*/
|
|
45
|
+
initialR?: number;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The number of points or explicit points to create the polygon.
|
|
49
|
+
*
|
|
50
|
+
* @default 4
|
|
51
|
+
*/
|
|
52
|
+
points?: number | { x: number; y: number }[];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The radius of the curve for rounded corners.
|
|
56
|
+
*
|
|
57
|
+
* @default 0
|
|
58
|
+
*/
|
|
59
|
+
cornerRadius?: number;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The rotation of the polygon.
|
|
63
|
+
*
|
|
64
|
+
* @default 0
|
|
65
|
+
*/
|
|
66
|
+
rotate?: number;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The percent to inset the odd points of the star (<1 inset, >1 outset)
|
|
70
|
+
*
|
|
71
|
+
* @default 0
|
|
72
|
+
*/
|
|
73
|
+
inset?: number;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The horizontal stretch factor of the polygon.
|
|
77
|
+
*
|
|
78
|
+
* @default 1
|
|
79
|
+
*/
|
|
80
|
+
scaleX?: number;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The vertical stretch factor of the polygon.
|
|
84
|
+
*
|
|
85
|
+
* @default 1
|
|
86
|
+
*/
|
|
87
|
+
scaleY?: number;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The skew angle in degrees along the X axis.
|
|
91
|
+
*
|
|
92
|
+
* @default 0
|
|
93
|
+
*/
|
|
94
|
+
skewX?: number;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The skew angle in degrees along the Y axis.
|
|
98
|
+
*
|
|
99
|
+
* @default 0
|
|
100
|
+
*/
|
|
101
|
+
skewY?: number;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The tilt factor for x-coordinates.
|
|
105
|
+
*
|
|
106
|
+
* @default 1
|
|
107
|
+
*/
|
|
108
|
+
tiltX?: number;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The tilt factor for y-coordinates.
|
|
112
|
+
*
|
|
113
|
+
* @default 1
|
|
114
|
+
*/
|
|
115
|
+
tiltY?: number;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A bindable reference to the `<path>` element
|
|
119
|
+
*
|
|
120
|
+
* @bindable
|
|
121
|
+
*/
|
|
122
|
+
ref?: SVGPathElement;
|
|
123
|
+
|
|
124
|
+
motion?: MotionProp;
|
|
125
|
+
} & CommonStyleProps;
|
|
126
|
+
|
|
127
|
+
export type PolygonProps = PolygonPropsWithoutHTML &
|
|
128
|
+
Without<SVGAttributes<Element>, PolygonPropsWithoutHTML>;
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
<script lang="ts">
|
|
132
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
133
|
+
import { cls } from '@layerstack/tailwind';
|
|
134
|
+
import { merge } from 'lodash-es';
|
|
135
|
+
import { interpolatePath } from 'd3-interpolate-path';
|
|
136
|
+
|
|
137
|
+
import { getRenderContext } from './Chart.svelte';
|
|
138
|
+
import {
|
|
139
|
+
createMotion,
|
|
140
|
+
extractTweenConfig,
|
|
141
|
+
type MotionProp,
|
|
142
|
+
type ResolvedMotion,
|
|
143
|
+
} from '../utils/motion.svelte.js';
|
|
144
|
+
import { registerCanvasComponent } from './layout/Canvas.svelte';
|
|
145
|
+
import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
146
|
+
import { createKey } from '../utils/key.svelte.js';
|
|
147
|
+
import { polygon } from '../utils/shape.js';
|
|
148
|
+
import { roundedPolygonPath } from '../utils/path.js';
|
|
149
|
+
|
|
150
|
+
let {
|
|
151
|
+
cx = 0,
|
|
152
|
+
initialCx: initialCxProp,
|
|
153
|
+
cy = 0,
|
|
154
|
+
initialCy: initialCyProp,
|
|
155
|
+
r = 1,
|
|
156
|
+
initialR: initialRProp,
|
|
157
|
+
points = 4,
|
|
158
|
+
cornerRadius = 0,
|
|
159
|
+
rotate = 0,
|
|
160
|
+
inset = 0,
|
|
161
|
+
scaleX = 1,
|
|
162
|
+
scaleY = 1,
|
|
163
|
+
skewX = 0,
|
|
164
|
+
skewY = 0,
|
|
165
|
+
tiltX = 0,
|
|
166
|
+
tiltY = 0,
|
|
167
|
+
motion,
|
|
168
|
+
fill,
|
|
169
|
+
fillOpacity,
|
|
170
|
+
stroke,
|
|
171
|
+
strokeWidth,
|
|
172
|
+
opacity,
|
|
173
|
+
class: className,
|
|
174
|
+
ref: refProp = $bindable(),
|
|
175
|
+
...restProps
|
|
176
|
+
}: PolygonProps = $props();
|
|
177
|
+
|
|
178
|
+
let ref = $state<SVGPathElement>();
|
|
179
|
+
|
|
180
|
+
$effect.pre(() => {
|
|
181
|
+
refProp = ref;
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const initialCx = initialCxProp ?? cx;
|
|
185
|
+
const initialCy = initialCyProp ?? cy;
|
|
186
|
+
const initialR = initialRProp ?? r;
|
|
187
|
+
|
|
188
|
+
const motionCx = createMotion(initialCx, () => cx, motion);
|
|
189
|
+
const motionCy = createMotion(initialCy, () => cy, motion);
|
|
190
|
+
const motionR = createMotion(initialR, () => r, motion);
|
|
191
|
+
|
|
192
|
+
let polygonPoints = $derived(
|
|
193
|
+
typeof points === 'number'
|
|
194
|
+
? polygon({
|
|
195
|
+
cx: motionCx.current,
|
|
196
|
+
cy: motionCy.current,
|
|
197
|
+
count: points,
|
|
198
|
+
radius: motionR.current,
|
|
199
|
+
rotate,
|
|
200
|
+
inset,
|
|
201
|
+
scaleX,
|
|
202
|
+
scaleY,
|
|
203
|
+
skewX,
|
|
204
|
+
skewY,
|
|
205
|
+
tiltX,
|
|
206
|
+
tiltY,
|
|
207
|
+
})
|
|
208
|
+
: points
|
|
209
|
+
);
|
|
210
|
+
let d = $derived(roundedPolygonPath(polygonPoints, cornerRadius));
|
|
211
|
+
|
|
212
|
+
const extractedTween = extractTweenConfig(motion);
|
|
213
|
+
|
|
214
|
+
const tweenedOptions: ResolvedMotion | undefined = extractedTween
|
|
215
|
+
? {
|
|
216
|
+
type: extractedTween.type,
|
|
217
|
+
options: { interpolate: interpolatePath, ...extractedTween.options },
|
|
218
|
+
}
|
|
219
|
+
: undefined;
|
|
220
|
+
|
|
221
|
+
const tweenedState = createMotion(null, () => d, tweenedOptions);
|
|
222
|
+
|
|
223
|
+
const renderCtx = getRenderContext();
|
|
224
|
+
|
|
225
|
+
function render(
|
|
226
|
+
ctx: CanvasRenderingContext2D,
|
|
227
|
+
styleOverrides: ComputedStylesOptions | undefined
|
|
228
|
+
) {
|
|
229
|
+
renderPathData(
|
|
230
|
+
ctx,
|
|
231
|
+
tweenedState.current,
|
|
232
|
+
styleOverrides
|
|
233
|
+
? merge({ styles: { strokeWidth } }, styleOverrides)
|
|
234
|
+
: {
|
|
235
|
+
styles: { fill, fillOpacity, stroke, strokeWidth, opacity },
|
|
236
|
+
classes: cls('lc-polygon', className),
|
|
237
|
+
}
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// TODO: Use objectId to work around Svelte 4 reactivity issue (even when memoizing gradients)
|
|
242
|
+
const fillKey = createKey(() => fill);
|
|
243
|
+
const strokeKey = createKey(() => stroke);
|
|
244
|
+
|
|
245
|
+
if (renderCtx === 'canvas') {
|
|
246
|
+
registerCanvasComponent({
|
|
247
|
+
name: 'Polygon',
|
|
248
|
+
render,
|
|
249
|
+
events: {
|
|
250
|
+
click: restProps.onclick,
|
|
251
|
+
pointerenter: restProps.onpointerenter,
|
|
252
|
+
pointermove: restProps.onpointermove,
|
|
253
|
+
pointerleave: restProps.onpointerleave,
|
|
254
|
+
pointerdown: restProps.onpointerdown,
|
|
255
|
+
pointerover: restProps.onpointerover,
|
|
256
|
+
pointerout: restProps.onpointerout,
|
|
257
|
+
touchmove: restProps.ontouchmove,
|
|
258
|
+
},
|
|
259
|
+
deps: () => [
|
|
260
|
+
fillKey.current,
|
|
261
|
+
fillOpacity,
|
|
262
|
+
strokeKey.current,
|
|
263
|
+
strokeWidth,
|
|
264
|
+
opacity,
|
|
265
|
+
className,
|
|
266
|
+
tweenedState.current,
|
|
267
|
+
],
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
</script>
|
|
271
|
+
|
|
272
|
+
{#if renderCtx === 'svg'}
|
|
273
|
+
<path
|
|
274
|
+
d={tweenedState.current}
|
|
275
|
+
{fill}
|
|
276
|
+
fill-opacity={fillOpacity}
|
|
277
|
+
{stroke}
|
|
278
|
+
stroke-width={strokeWidth}
|
|
279
|
+
{opacity}
|
|
280
|
+
class={cls('lc-polygon', className)}
|
|
281
|
+
{...restProps}
|
|
282
|
+
bind:this={ref}
|
|
283
|
+
/>
|
|
284
|
+
{/if}
|
|
285
|
+
|
|
286
|
+
<style>
|
|
287
|
+
@layer base {
|
|
288
|
+
:global(:where(.lc-polygon)) {
|
|
289
|
+
--fill-color: var(--color-surface-content, currentColor);
|
|
290
|
+
--stroke-color: initial;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/* Svg | Canvas layers */
|
|
294
|
+
:global(:where(.lc-layout-svg .lc-polygon, svg.lc-polygon):not([fill])) {
|
|
295
|
+
fill: var(--fill-color);
|
|
296
|
+
}
|
|
297
|
+
:global(:where(.lc-layout-svg .lc-polygon, svg.lc-polygon):not([stroke])) {
|
|
298
|
+
stroke: var(--stroke-color);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/* Html layers */
|
|
302
|
+
:global(:where(.lc-layout-html .lc-polygon):not([background-color])) {
|
|
303
|
+
background-color: var(--fill-color);
|
|
304
|
+
}
|
|
305
|
+
:global(:where(.lc-layout-html .lc-polygon):not([border-color])) {
|
|
306
|
+
border-color: var(--stroke-color);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
</style>
|