layerchart 2.0.0-next.3 → 2.0.0-next.31
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/AnnotationPoint.svelte +16 -9
- package/dist/components/AnnotationRange.svelte +3 -3
- package/dist/components/Arc.svelte +2 -2
- package/dist/components/Axis.svelte +83 -29
- package/dist/components/Axis.svelte.d.ts +13 -3
- package/dist/components/Bar.svelte +12 -8
- package/dist/components/Blur.svelte +5 -3
- package/dist/components/Blur.svelte.d.ts +2 -5
- package/dist/components/BrushContext.svelte +1 -1
- package/dist/components/Calendar.svelte +10 -6
- package/dist/components/Calendar.svelte.d.ts +2 -1
- package/dist/components/Chart.svelte +39 -3
- package/dist/components/Chart.svelte.d.ts +11 -0
- 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 +184 -50
- package/dist/components/ForceSimulation.svelte.d.ts +88 -21
- 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/Group.svelte +2 -2
- package/dist/components/Highlight.svelte +9 -6
- package/dist/components/Hull.svelte +1 -1
- package/dist/components/Labels.svelte +3 -2
- package/dist/components/Labels.svelte.d.ts +2 -2
- package/dist/components/Legend.svelte +19 -12
- package/dist/components/Legend.svelte.d.ts +5 -5
- 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/Spline.svelte +30 -18
- package/dist/components/Spline.svelte.d.ts +12 -4
- package/dist/components/Text.svelte +62 -60
- package/dist/components/Text.svelte.d.ts +6 -0
- package/dist/components/TransformControls.svelte +16 -20
- package/dist/components/Treemap.svelte +63 -26
- package/dist/components/Treemap.svelte.d.ts +11 -11
- package/dist/components/Voronoi.svelte +51 -33
- package/dist/components/Voronoi.svelte.d.ts +3 -1
- package/dist/components/charts/ArcChart.svelte +5 -3
- package/dist/components/charts/AreaChart.svelte +11 -11
- package/dist/components/charts/BarChart.svelte +72 -53
- package/dist/components/charts/DefaultTooltip.svelte +1 -1
- package/dist/components/charts/LineChart.svelte +10 -6
- package/dist/components/charts/PieChart.svelte +5 -3
- package/dist/components/charts/ScatterChart.svelte +2 -3
- package/dist/components/charts/utils.svelte.d.ts +2 -2
- package/dist/components/charts/utils.svelte.js +5 -1
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +5 -1
- 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 +136 -43
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +3 -3
- 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 +6 -4
- 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/Preview.svelte +6 -3
- package/dist/docs/TilesetField.svelte +20 -19
- package/dist/docs/TilesetField.svelte.d.ts +5 -22
- package/dist/docs/ViewSourceButton.svelte +9 -6
- package/dist/docs/ViewSourceButton.svelte.d.ts +7 -21
- 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/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/index.d.ts +1 -0
- package/dist/utils/index.js +1 -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 +69 -1
- 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 +15 -4
- package/dist/utils/ticks.js +144 -158
- package/dist/utils/ticks.test.js +11 -16
- package/dist/utils/treemap.d.ts +1 -1
- package/package.json +27 -25
- package/dist/utils/object.js +0 -2
|
@@ -1,44 +1,95 @@
|
|
|
1
|
-
import { type Force, type Simulation, type SimulationNodeDatum } from 'd3-force';
|
|
1
|
+
import { type Force, type Simulation, type SimulationLinkDatum, type SimulationNodeDatum } from 'd3-force';
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
-
type Forces = Record<string, Force<
|
|
3
|
+
export type Forces<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = Record<string, Force<NodeDatum, LinkDatum>>;
|
|
4
|
+
export type Data<TNode = any, TLink = any> = {
|
|
5
|
+
nodes: TNode[];
|
|
6
|
+
links?: TLink[];
|
|
7
|
+
};
|
|
4
8
|
export type LinkPosition = {
|
|
5
9
|
x1: number;
|
|
6
10
|
y1: number;
|
|
7
11
|
x2: number;
|
|
8
12
|
y2: number;
|
|
9
13
|
};
|
|
10
|
-
export type
|
|
14
|
+
export type OnStartEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
|
|
15
|
+
alpha: number;
|
|
16
|
+
alphaTarget: number;
|
|
17
|
+
simulation: Simulation<NodeDatum, LinkDatum>;
|
|
18
|
+
};
|
|
19
|
+
export type OnTickEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
|
|
20
|
+
alpha: number;
|
|
21
|
+
alphaTarget: number;
|
|
22
|
+
nodes: NodeDatum[];
|
|
23
|
+
links: LinkDatum[];
|
|
24
|
+
simulation: Simulation<NodeDatum, LinkDatum>;
|
|
25
|
+
};
|
|
26
|
+
export type OnEndEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
|
|
27
|
+
alpha: number;
|
|
28
|
+
alphaTarget: number;
|
|
29
|
+
simulation: Simulation<NodeDatum, LinkDatum>;
|
|
30
|
+
};
|
|
31
|
+
export type OnNodesChangeEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
|
|
32
|
+
alpha: number;
|
|
33
|
+
alphaTarget: number;
|
|
34
|
+
nodes: NodeDatum[];
|
|
35
|
+
links: LinkDatum[];
|
|
36
|
+
simulation: Simulation<NodeDatum, LinkDatum>;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Default initial alpha value of the simulation.
|
|
40
|
+
*/
|
|
41
|
+
export declare const DEFAULT_ALPHA: number;
|
|
42
|
+
/**
|
|
43
|
+
* Default target alpha value for the simulation.
|
|
44
|
+
*/
|
|
45
|
+
export declare const DEFAULT_ALPHA_TARGET: number;
|
|
46
|
+
/**
|
|
47
|
+
* Default alpha decay rate per tick.
|
|
48
|
+
*
|
|
49
|
+
* Formula: `1 - Math.pow(0.001, 1 / 300)`.
|
|
50
|
+
*/
|
|
51
|
+
export declare const DEFAULT_ALPHA_DECAY: number;
|
|
52
|
+
/**
|
|
53
|
+
* Default minimum alpha value at which simulation stops.
|
|
54
|
+
*/
|
|
55
|
+
export declare const DEFAULT_ALPHA_MIN: number;
|
|
56
|
+
/**
|
|
57
|
+
* Default velocity decay factor applied to nodes each tick.
|
|
58
|
+
*/
|
|
59
|
+
export declare const DEFAULT_VELOCITY_DECAY: number;
|
|
60
|
+
export type ForceSimulationProps<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
|
|
11
61
|
/**
|
|
12
62
|
* Force simulation parameters
|
|
13
63
|
*/
|
|
14
|
-
forces: Forces
|
|
64
|
+
forces: Forces<NodeDatum, LinkDatum>;
|
|
15
65
|
/**
|
|
16
|
-
* An
|
|
66
|
+
* An object with arrays of nodes and links,
|
|
67
|
+
* to be used for position calculation.
|
|
17
68
|
*/
|
|
18
|
-
|
|
69
|
+
data: Data<NodeDatum, LinkDatum>;
|
|
19
70
|
/**
|
|
20
71
|
* Current alpha value of the simulation
|
|
21
|
-
* @default
|
|
72
|
+
* @default DEFAULT_ALPHA
|
|
22
73
|
*/
|
|
23
74
|
alpha?: number;
|
|
24
75
|
/**
|
|
25
76
|
* Target alpha value for the simulation
|
|
26
|
-
* @default
|
|
77
|
+
* @default DEFAULT_ALPHA_TARGET
|
|
27
78
|
*/
|
|
28
79
|
alphaTarget?: number;
|
|
29
80
|
/**
|
|
30
81
|
* Alpha decay rate per tick
|
|
31
|
-
* @default
|
|
82
|
+
* @default DEFAULT_ALPHA_DECAY
|
|
32
83
|
*/
|
|
33
84
|
alphaDecay?: number;
|
|
34
85
|
/**
|
|
35
86
|
* Minimum alpha value at which simulation stops
|
|
36
|
-
* @default
|
|
87
|
+
* @default DEFAULT_ALPHA_MIN
|
|
37
88
|
*/
|
|
38
89
|
alphaMin?: number;
|
|
39
90
|
/**
|
|
40
91
|
* Velocity decay factor applied to nodes each tick
|
|
41
|
-
* @default
|
|
92
|
+
* @default DEFAULT_VELOCITY_DECAY
|
|
42
93
|
*/
|
|
43
94
|
velocityDecay?: number;
|
|
44
95
|
/**
|
|
@@ -59,26 +110,42 @@ export type ForceSimulationProps = {
|
|
|
59
110
|
/**
|
|
60
111
|
* Callback function triggered when simulation starts
|
|
61
112
|
*/
|
|
62
|
-
onStart?: () => void;
|
|
113
|
+
onStart?: (e: OnStartEvent<NodeDatum, LinkDatum | undefined>) => void;
|
|
114
|
+
/**
|
|
115
|
+
* Callback function triggered right before nodes get passed to the simulation
|
|
116
|
+
*/
|
|
117
|
+
onNodesChange?: (e: OnNodesChangeEvent<NodeDatum, LinkDatum | undefined>) => void;
|
|
63
118
|
/**
|
|
64
119
|
* Callback function triggered on each simulation tick
|
|
65
120
|
*/
|
|
66
|
-
onTick?: (e:
|
|
67
|
-
alpha: number;
|
|
68
|
-
alphaTarget: number;
|
|
69
|
-
}) => void;
|
|
121
|
+
onTick?: (e: OnTickEvent<NodeDatum, LinkDatum | undefined>) => void;
|
|
70
122
|
/**
|
|
71
123
|
* Callback function triggered when simulation ends
|
|
72
124
|
*/
|
|
73
|
-
onEnd?: () => void;
|
|
125
|
+
onEnd?: (e: OnEndEvent<NodeDatum, LinkDatum | undefined>) => void;
|
|
74
126
|
children?: Snippet<[
|
|
75
127
|
{
|
|
76
|
-
nodes:
|
|
77
|
-
|
|
128
|
+
nodes: NodeDatum[];
|
|
129
|
+
links: LinkDatum[];
|
|
78
130
|
linkPositions: LinkPosition[];
|
|
131
|
+
simulation: Simulation<NodeDatum, LinkDatum>;
|
|
79
132
|
}
|
|
80
133
|
]>;
|
|
81
134
|
};
|
|
82
|
-
declare
|
|
83
|
-
|
|
135
|
+
declare class __sveltets_Render<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> {
|
|
136
|
+
props(): ForceSimulationProps<NodeDatum, LinkDatum>;
|
|
137
|
+
events(): {};
|
|
138
|
+
slots(): {};
|
|
139
|
+
bindings(): "alpha";
|
|
140
|
+
exports(): {};
|
|
141
|
+
}
|
|
142
|
+
interface $$IsomorphicComponent {
|
|
143
|
+
new <NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']>, ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['events']>, ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['slots']>> & {
|
|
144
|
+
$$bindings?: ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['bindings']>;
|
|
145
|
+
} & ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['exports']>;
|
|
146
|
+
<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined>(internal: unknown, props: ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']> & {}): ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['exports']>;
|
|
147
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
|
|
148
|
+
}
|
|
149
|
+
declare const ForceSimulation: $$IsomorphicComponent;
|
|
150
|
+
type ForceSimulation<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = InstanceType<typeof ForceSimulation<NodeDatum, LinkDatum>>;
|
|
84
151
|
export default ForceSimulation;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
6
6
|
import { curveLinearClosed, type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
|
|
7
7
|
import {
|
|
8
|
+
geoPath as d3GeoPath,
|
|
8
9
|
geoTransform as d3geoTransform,
|
|
9
10
|
type GeoIdentityTransform,
|
|
10
11
|
type GeoPermissibleObjects,
|
|
@@ -105,6 +106,10 @@
|
|
|
105
106
|
const geoPath = $derived.by(() => {
|
|
106
107
|
geojson;
|
|
107
108
|
if (!projection) return;
|
|
109
|
+
// Only use geoCurvePath for custom curves (performance impact)
|
|
110
|
+
if (curve === curveLinearClosed) {
|
|
111
|
+
return d3GeoPath(projection);
|
|
112
|
+
}
|
|
108
113
|
return geoCurvePath(projection, curve);
|
|
109
114
|
});
|
|
110
115
|
|
|
@@ -157,16 +162,18 @@
|
|
|
157
162
|
name: 'GeoPath',
|
|
158
163
|
render,
|
|
159
164
|
events: {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
165
|
+
// Only register events if they are defined (so they are not registered with hit canvas unnecessarily)
|
|
166
|
+
click: onclick ? _onClick : undefined,
|
|
167
|
+
pointerenter: restProps.onpointerenter || tooltipContext ? _onPointerEnter : undefined,
|
|
168
|
+
pointermove: restProps.onpointermove || tooltipContext ? _onPointerMove : undefined,
|
|
169
|
+
pointerleave: restProps.onpointerleave || tooltipContext ? _onPointerLeave : undefined,
|
|
164
170
|
pointerdown: restProps.onpointerdown,
|
|
165
171
|
touchmove: restProps.ontouchmove,
|
|
166
172
|
},
|
|
167
173
|
deps: () => [
|
|
168
|
-
geojson,
|
|
169
174
|
projection,
|
|
175
|
+
geojson,
|
|
176
|
+
curve,
|
|
170
177
|
fillKey.current,
|
|
171
178
|
strokeKey.current,
|
|
172
179
|
strokeWidth,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
-
import
|
|
4
|
-
import Circle, { type CircleProps, type CirclePropsWithoutHTML } from './Circle.svelte';
|
|
3
|
+
import Circle, { type CircleProps } from './Circle.svelte';
|
|
5
4
|
import type { Without } from '../utils/types.js';
|
|
6
5
|
|
|
7
6
|
export type GeoPointPropsWithoutHTML = {
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
link,
|
|
43
43
|
loft = 1.0,
|
|
44
44
|
curve = curveNatural,
|
|
45
|
-
|
|
45
|
+
pathRef: pathRefProp = $bindable(),
|
|
46
46
|
...restProps
|
|
47
47
|
}: GeoSplineProps = $props();
|
|
48
48
|
|
|
49
|
-
let
|
|
49
|
+
let pathRef = $state<SVGPathElement>();
|
|
50
50
|
$effect.pre(() => {
|
|
51
|
-
|
|
51
|
+
pathRefProp = pathRef;
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
const geoCtx = getGeoContext();
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
</script>
|
|
77
77
|
|
|
78
78
|
<Spline
|
|
79
|
-
bind:
|
|
79
|
+
bind:pathRef
|
|
80
80
|
data={[source, middle, target]}
|
|
81
81
|
x={(d) => d[0]}
|
|
82
82
|
y={(d) => d[1]}
|
|
@@ -27,6 +27,6 @@ export type GeoSplinePropsWithoutHTML = {
|
|
|
27
27
|
curve?: CurveFactory | CurveFactoryLineOnly;
|
|
28
28
|
};
|
|
29
29
|
export type GeoSplineProps = GeoSplinePropsWithoutHTML & Without<SplineProps, GeoSplinePropsWithoutHTML>;
|
|
30
|
-
declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "
|
|
30
|
+
declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "pathRef">;
|
|
31
31
|
type GeoSpline = ReturnType<typeof GeoSpline>;
|
|
32
32
|
export default GeoSpline;
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
initialY: initialYProp,
|
|
101
101
|
center = false,
|
|
102
102
|
preventTouchMove = false,
|
|
103
|
-
opacity =
|
|
103
|
+
opacity = undefined,
|
|
104
104
|
motion,
|
|
105
105
|
transitionIn: transitionInProp,
|
|
106
106
|
transitionInParams: transitionInParamsProp,
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
name: 'Group',
|
|
145
145
|
render: (ctx) => {
|
|
146
146
|
const currentGlobalAlpha = ctx.globalAlpha;
|
|
147
|
-
ctx.globalAlpha = opacity;
|
|
147
|
+
ctx.globalAlpha = opacity ?? 1;
|
|
148
148
|
|
|
149
149
|
ctx.translate(motionX.current ?? 0, motionY.current ?? 0);
|
|
150
150
|
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
import { notNull } from '@layerstack/utils';
|
|
117
117
|
import { cls } from '@layerstack/tailwind';
|
|
118
118
|
|
|
119
|
-
import { isScaleBand } from '../utils/scales.svelte.js';
|
|
119
|
+
import { isScaleBand, isScaleTime } from '../utils/scales.svelte.js';
|
|
120
120
|
import { asAny } from '../utils/types.js';
|
|
121
121
|
import { getChartContext } from './Chart.svelte';
|
|
122
122
|
import { getTooltipContext } from './tooltip/TooltipContext.svelte';
|
|
@@ -158,7 +158,9 @@
|
|
|
158
158
|
Array.isArray(yValue) ? yValue.map((v) => ctx.yScale(v)) : ctx.yScale(yValue)
|
|
159
159
|
);
|
|
160
160
|
const yOffset = $derived(isScaleBand(ctx.yScale) && !ctx.radial ? ctx.yScale.bandwidth() / 2 : 0);
|
|
161
|
-
const axis = $derived(
|
|
161
|
+
const axis = $derived(
|
|
162
|
+
axisProp == null ? (isScaleBand(ctx.yScale) || isScaleTime(ctx.yScale) ? 'y' : 'x') : axisProp
|
|
163
|
+
);
|
|
162
164
|
|
|
163
165
|
const _lines: { x1: number; y1: number; x2: number; y2: number }[] = $derived.by(() => {
|
|
164
166
|
let tmpLines: { x1: number; y1: number; x2: number; y2: number }[] = [];
|
|
@@ -175,7 +177,7 @@
|
|
|
175
177
|
y2: max(ctx.yRange) as unknown as number,
|
|
176
178
|
})),
|
|
177
179
|
];
|
|
178
|
-
} else if (xCoord) {
|
|
180
|
+
} else if (xCoord != null) {
|
|
179
181
|
tmpLines = [
|
|
180
182
|
...tmpLines,
|
|
181
183
|
{
|
|
@@ -201,7 +203,7 @@
|
|
|
201
203
|
y2: yItem + yOffset,
|
|
202
204
|
})),
|
|
203
205
|
];
|
|
204
|
-
} else if (yCoord) {
|
|
206
|
+
} else if (yCoord != null) {
|
|
205
207
|
tmpLines = [
|
|
206
208
|
...tmpLines,
|
|
207
209
|
{
|
|
@@ -249,6 +251,7 @@
|
|
|
249
251
|
height: 0,
|
|
250
252
|
};
|
|
251
253
|
if (!highlightData) return tmpArea;
|
|
254
|
+
|
|
252
255
|
if (axis === 'x' || axis === 'both') {
|
|
253
256
|
// x area
|
|
254
257
|
if (Array.isArray(xCoord)) {
|
|
@@ -284,9 +287,9 @@
|
|
|
284
287
|
tmpArea.height = ctx.yScale.step();
|
|
285
288
|
} else {
|
|
286
289
|
// Find width to next data point
|
|
287
|
-
const index = ctx.flatData.findIndex((d) => Number(
|
|
290
|
+
const index = ctx.flatData.findIndex((d) => Number(y(d)) === Number(y(highlightData)));
|
|
288
291
|
const isLastPoint = index + 1 === ctx.flatData.length;
|
|
289
|
-
const nextDataPoint = isLastPoint ? max(ctx.yDomain) :
|
|
292
|
+
const nextDataPoint = isLastPoint ? max(ctx.yDomain) : y(ctx.flatData[index + 1]);
|
|
290
293
|
tmpArea.height = (ctx.yScale(nextDataPoint) ?? 0) - (yCoord ?? 0);
|
|
291
294
|
}
|
|
292
295
|
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
<script lang="ts">
|
|
56
56
|
import { min } from 'd3-array';
|
|
57
57
|
import { Delaunay } from 'd3-delaunay';
|
|
58
|
-
// @ts-expect-error
|
|
58
|
+
// @ts-expect-error - no types available
|
|
59
59
|
import { geoVoronoi } from 'd3-geo-voronoi';
|
|
60
60
|
import { curveLinearClosed } from 'd3-shape';
|
|
61
61
|
import { cls } from '@layerstack/tailwind';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import Text, { type TextProps } from './Text.svelte';
|
|
3
3
|
import { type ComponentProps, type Snippet } from 'svelte';
|
|
4
|
-
import { format as formatValue, type FormatType } from '@layerstack/utils';
|
|
4
|
+
import { format as formatValue, type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
5
5
|
import type { Without } from '../utils/types.js';
|
|
6
6
|
import Points, { type Point } from './Points.svelte';
|
|
7
7
|
import { accessor, type Accessor } from '../utils/common.js';
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
/**
|
|
52
52
|
* The format of the label
|
|
53
53
|
*/
|
|
54
|
-
format?: FormatType;
|
|
54
|
+
format?: FormatType | FormatConfig;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* Define unique value for {#each} `(key)` expressions to improve transitions.
|
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
|
|
110
110
|
const formattedValue = formatValue(
|
|
111
111
|
displayValue,
|
|
112
|
+
// @ts-expect-error - improve types
|
|
112
113
|
format ??
|
|
113
114
|
(value
|
|
114
115
|
? undefined
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Text, { type TextProps } from './Text.svelte';
|
|
2
2
|
import { type ComponentProps, type Snippet } from 'svelte';
|
|
3
|
-
import { type FormatType } from '@layerstack/utils';
|
|
3
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
4
4
|
import type { Without } from '../utils/types.js';
|
|
5
5
|
import { type Point } from './Points.svelte';
|
|
6
6
|
import { type Accessor } from '../utils/common.js';
|
|
@@ -42,7 +42,7 @@ export type LabelsPropsWithoutHTML<T = any> = {
|
|
|
42
42
|
/**
|
|
43
43
|
* The format of the label
|
|
44
44
|
*/
|
|
45
|
-
format?: FormatType;
|
|
45
|
+
format?: FormatType | FormatConfig;
|
|
46
46
|
/**
|
|
47
47
|
* Define unique value for {#each} `(key)` expressions to improve transitions.
|
|
48
48
|
* `index` position used by default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import type { Placement } from './types.js';
|
|
4
|
-
import type
|
|
4
|
+
import { asAny, type Without } from '../utils/types.js';
|
|
5
5
|
|
|
6
6
|
export type LegendItem = {
|
|
7
7
|
value: any;
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* @default width / 64
|
|
38
38
|
*/
|
|
39
39
|
ticks?: number;
|
|
40
|
-
tickFormat?: FormatType;
|
|
40
|
+
tickFormat?: FormatType | FormatConfig;
|
|
41
41
|
tickValues?: any[];
|
|
42
42
|
/**
|
|
43
43
|
* The font size of the tick labels.
|
|
@@ -86,9 +86,9 @@
|
|
|
86
86
|
title?: string;
|
|
87
87
|
label?: string;
|
|
88
88
|
tick?: string;
|
|
89
|
-
|
|
89
|
+
items?: string;
|
|
90
90
|
swatch?: string;
|
|
91
|
-
item?: (item: LegendItem) => string;
|
|
91
|
+
item?: string | ((item: LegendItem) => string);
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
/**
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
import { scaleBand, scaleLinear } from 'd3-scale';
|
|
111
111
|
import { quantize, interpolate, interpolateRound } from 'd3-interpolate';
|
|
112
112
|
import { quantile, range } from 'd3-array';
|
|
113
|
-
import { format, type FormatType } from '@layerstack/utils';
|
|
113
|
+
import { format, type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
114
114
|
|
|
115
115
|
import ColorRamp from './ColorRamp.svelte';
|
|
116
116
|
import { cls } from '@layerstack/tailwind';
|
|
@@ -245,6 +245,7 @@
|
|
|
245
245
|
const tickValues = range(thresholds.length);
|
|
246
246
|
const tickFormat = (i: number) => {
|
|
247
247
|
const value = thresholds[i];
|
|
248
|
+
// @ts-expect-error - improve types
|
|
248
249
|
return tickFormatProp ? format(value, tickFormatProp) : value;
|
|
249
250
|
};
|
|
250
251
|
|
|
@@ -360,7 +361,8 @@
|
|
|
360
361
|
classes.label
|
|
361
362
|
)}
|
|
362
363
|
>
|
|
363
|
-
|
|
364
|
+
<!-- @ts-expect-error - improve types -->
|
|
365
|
+
{tickFormatProp ? format(tick, asAny(tickFormatProp)) : tick}
|
|
364
366
|
</text>
|
|
365
367
|
|
|
366
368
|
{#if scaleConfig.tickLine}
|
|
@@ -381,7 +383,7 @@
|
|
|
381
383
|
layerClass('legend-swatch-group'),
|
|
382
384
|
'flex gap-x-4 gap-y-1',
|
|
383
385
|
orientation === 'vertical' && 'flex-col',
|
|
384
|
-
classes.
|
|
386
|
+
classes.items
|
|
385
387
|
)}
|
|
386
388
|
>
|
|
387
389
|
{#each scaleConfig.tickValues ?? scaleConfig.xScale?.ticks?.(ticks) ?? [] as tick}
|
|
@@ -390,26 +392,31 @@
|
|
|
390
392
|
<button
|
|
391
393
|
class={cls(
|
|
392
394
|
layerClass('legend-swatch-button'),
|
|
393
|
-
'flex gap-1',
|
|
395
|
+
'flex items-center gap-1 truncate',
|
|
394
396
|
!onclick && 'cursor-auto',
|
|
395
|
-
classes.item
|
|
397
|
+
typeof classes.item === 'function' ? classes.item(item) : classes.item
|
|
396
398
|
)}
|
|
397
399
|
onclick={(e) => onclick?.(e, item)}
|
|
398
400
|
onpointerenter={(e) => onpointerenter?.(e, item)}
|
|
399
401
|
onpointerleave={(e) => onpointerleave?.(e, item)}
|
|
400
402
|
>
|
|
401
403
|
<div
|
|
402
|
-
class={cls(
|
|
404
|
+
class={cls(
|
|
405
|
+
layerClass('legend-swatch'),
|
|
406
|
+
'h-4 w-4 shrink-0 rounded-full',
|
|
407
|
+
classes.swatch
|
|
408
|
+
)}
|
|
403
409
|
style:background-color={color}
|
|
404
410
|
></div>
|
|
405
411
|
<div
|
|
406
412
|
class={cls(
|
|
407
413
|
layerClass('legend-swatch-label'),
|
|
408
|
-
'text-xs text-surface-content whitespace-nowrap',
|
|
414
|
+
'text-xs text-surface-content truncate whitespace-nowrap',
|
|
409
415
|
classes.label
|
|
410
416
|
)}
|
|
411
417
|
>
|
|
412
|
-
|
|
418
|
+
<!-- @ts-expect-error - improve types -->
|
|
419
|
+
{tickFormatProp ? format(tick, asAny(tickFormatProp)) : tick}
|
|
413
420
|
</div>
|
|
414
421
|
</button>
|
|
415
422
|
{/each}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { Placement } from './types.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type Without } from '../utils/types.js';
|
|
4
4
|
export type LegendItem = {
|
|
5
5
|
value: any;
|
|
6
6
|
color: string;
|
|
@@ -30,7 +30,7 @@ export type LegendPropsWithoutHTML = {
|
|
|
30
30
|
* @default width / 64
|
|
31
31
|
*/
|
|
32
32
|
ticks?: number;
|
|
33
|
-
tickFormat?: FormatType;
|
|
33
|
+
tickFormat?: FormatType | FormatConfig;
|
|
34
34
|
tickValues?: any[];
|
|
35
35
|
/**
|
|
36
36
|
* The font size of the tick labels.
|
|
@@ -73,9 +73,9 @@ export type LegendPropsWithoutHTML = {
|
|
|
73
73
|
title?: string;
|
|
74
74
|
label?: string;
|
|
75
75
|
tick?: string;
|
|
76
|
-
|
|
76
|
+
items?: string;
|
|
77
77
|
swatch?: string;
|
|
78
|
-
item?: (item: LegendItem) => string;
|
|
78
|
+
item?: string | ((item: LegendItem) => string);
|
|
79
79
|
};
|
|
80
80
|
/**
|
|
81
81
|
* A bindable reference to the wrapping `<div>` element.
|
|
@@ -90,7 +90,7 @@ export type LegendPropsWithoutHTML = {
|
|
|
90
90
|
};
|
|
91
91
|
export type LegendProps = LegendPropsWithoutHTML & Without<HTMLAttributes<HTMLElement>, LegendPropsWithoutHTML>;
|
|
92
92
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
93
|
-
import { type FormatType } from '@layerstack/utils';
|
|
93
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
94
94
|
import type { AnyScale } from '../utils/scales.svelte.js';
|
|
95
95
|
declare const Legend: import("svelte").Component<LegendProps, {}, "ref">;
|
|
96
96
|
type Legend = ReturnType<typeof Legend>;
|
|
@@ -20,30 +20,33 @@
|
|
|
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
|
-
import { timeWeek, timeYear } from 'd3-time';
|
|
32
|
-
import { endOfMonth } from 'date-fns';
|
|
33
|
+
import { timeWeek, timeMonth, timeYear } from 'd3-time';
|
|
33
34
|
import { cls } from '@layerstack/tailwind';
|
|
35
|
+
import { endOfInterval } from '@layerstack/utils';
|
|
34
36
|
import { layerClass } from '../utils/attributes.js';
|
|
37
|
+
import Spline, { type SplinePropsWithoutHTML } from './Spline.svelte';
|
|
35
38
|
|
|
36
39
|
let {
|
|
37
40
|
date,
|
|
38
41
|
cellSize: cellSizeProp,
|
|
39
|
-
|
|
42
|
+
pathRef: pathRefProp = $bindable(),
|
|
40
43
|
class: className,
|
|
41
44
|
...restProps
|
|
42
45
|
}: MonthPathProps = $props();
|
|
43
46
|
|
|
44
|
-
let
|
|
47
|
+
let pathRef = $state<SVGPathElement>();
|
|
45
48
|
$effect.pre(() => {
|
|
46
|
-
|
|
49
|
+
pathRefProp = pathRef;
|
|
47
50
|
});
|
|
48
51
|
|
|
49
52
|
const cellSize = $derived(
|
|
@@ -55,7 +58,7 @@
|
|
|
55
58
|
const startWeek = $derived(timeWeek.count(timeYear(date), date));
|
|
56
59
|
|
|
57
60
|
// end of month
|
|
58
|
-
const monthEnd = $derived(
|
|
61
|
+
const monthEnd = $derived(endOfInterval('month', date));
|
|
59
62
|
const endDayOfWeek = $derived(monthEnd.getDay());
|
|
60
63
|
const endWeek = $derived(timeWeek.count(timeYear(monthEnd), monthEnd));
|
|
61
64
|
|
|
@@ -68,9 +71,9 @@
|
|
|
68
71
|
`);
|
|
69
72
|
</script>
|
|
70
73
|
|
|
71
|
-
<
|
|
72
|
-
bind:
|
|
73
|
-
|
|
74
|
+
<Spline
|
|
75
|
+
bind:pathRef
|
|
76
|
+
{pathData}
|
|
74
77
|
fill="none"
|
|
75
78
|
class={cls(layerClass('month-path'), 'stroke-surface-content/20', className)}
|
|
76
79
|
{...restProps}
|
|
@@ -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;
|