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
package/dist/utils/genData.d.ts
CHANGED
|
@@ -23,21 +23,21 @@ export declare function createSeries<TKey extends string>(options: {
|
|
|
23
23
|
}): ({
|
|
24
24
|
x: number;
|
|
25
25
|
} & { [K in TKey]: number; })[];
|
|
26
|
-
export declare function createDateSeries<TKey extends string>(options
|
|
26
|
+
export declare function createDateSeries<TKey extends string>(options?: {
|
|
27
27
|
count?: number;
|
|
28
|
-
min
|
|
29
|
-
max
|
|
28
|
+
min?: number;
|
|
29
|
+
max?: number;
|
|
30
30
|
keys?: TKey[];
|
|
31
31
|
value?: 'number' | 'integer';
|
|
32
32
|
}): ({
|
|
33
33
|
date: Date;
|
|
34
34
|
} & { [K in TKey]: number; })[];
|
|
35
|
-
export declare function createTimeSeries<TKey extends string>(options
|
|
35
|
+
export declare function createTimeSeries<TKey extends string>(options?: {
|
|
36
36
|
count?: number;
|
|
37
|
-
min
|
|
38
|
-
max
|
|
39
|
-
keys
|
|
40
|
-
value
|
|
37
|
+
min?: number;
|
|
38
|
+
max?: number;
|
|
39
|
+
keys?: TKey[];
|
|
40
|
+
value?: 'number' | 'integer';
|
|
41
41
|
}): ({
|
|
42
42
|
name: string;
|
|
43
43
|
startDate: Date;
|
|
@@ -75,3 +75,17 @@ export declare function getSpiral({ angle, radius, count, width, height, }: {
|
|
|
75
75
|
x: number;
|
|
76
76
|
y: number;
|
|
77
77
|
}[];
|
|
78
|
+
interface SineWaveOptions {
|
|
79
|
+
numPoints: number;
|
|
80
|
+
frequency?: number;
|
|
81
|
+
amplitude?: number;
|
|
82
|
+
noiseLevel?: number;
|
|
83
|
+
phase?: number;
|
|
84
|
+
xMin?: number;
|
|
85
|
+
xMax?: number;
|
|
86
|
+
}
|
|
87
|
+
export declare function generateSineWave(options: SineWaveOptions): {
|
|
88
|
+
x: number;
|
|
89
|
+
y: number;
|
|
90
|
+
}[];
|
|
91
|
+
export {};
|
package/dist/utils/genData.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { timeMinute, timeDay } from 'd3-time';
|
|
2
2
|
import { cumsum } from 'd3-array';
|
|
3
3
|
import { randomNormal } from 'd3-random';
|
|
4
4
|
import { degreesToRadians, radiansToDegrees } from './math.js';
|
|
@@ -43,33 +43,35 @@ export function createSeries(options) {
|
|
|
43
43
|
};
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
export function createDateSeries(options) {
|
|
47
|
-
const now =
|
|
46
|
+
export function createDateSeries(options = {}) {
|
|
47
|
+
const now = timeDay.floor(new Date());
|
|
48
48
|
const count = options.count ?? 10;
|
|
49
|
-
const min = options.min;
|
|
50
|
-
const max = options.max;
|
|
49
|
+
const min = options.min ?? 0;
|
|
50
|
+
const max = options.max ?? 100;
|
|
51
51
|
const keys = options.keys ?? ['value'];
|
|
52
|
+
const valueType = options.value ?? 'number';
|
|
52
53
|
return Array.from({ length: count }).map((_, i) => {
|
|
53
54
|
return {
|
|
54
|
-
date:
|
|
55
|
+
date: timeDay.offset(now, -count + i),
|
|
55
56
|
...Object.fromEntries(keys.map((key) => {
|
|
56
57
|
return [
|
|
57
58
|
key,
|
|
58
|
-
|
|
59
|
+
valueType === 'integer' ? getRandomInteger(min, max) : getRandomNumber(min, max),
|
|
59
60
|
];
|
|
60
61
|
})),
|
|
61
62
|
};
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
|
-
export function createTimeSeries(options) {
|
|
65
|
+
export function createTimeSeries(options = {}) {
|
|
65
66
|
const count = options.count ?? 10;
|
|
66
|
-
const min = options.min;
|
|
67
|
-
const max = options.max;
|
|
67
|
+
const min = options.min ?? 0;
|
|
68
|
+
const max = options.max ?? 100;
|
|
68
69
|
const keys = options.keys ?? ['value'];
|
|
69
|
-
|
|
70
|
+
const valueType = options.value ?? 'number';
|
|
71
|
+
let lastStartDate = timeDay.floor(new Date());
|
|
70
72
|
const timeSeries = Array.from({ length: count }).map((_, i) => {
|
|
71
|
-
const startDate =
|
|
72
|
-
const endDate =
|
|
73
|
+
const startDate = timeMinute.offset(lastStartDate, getRandomInteger(0, 60));
|
|
74
|
+
const endDate = timeMinute.offset(startDate, getRandomInteger(5, 60));
|
|
73
75
|
lastStartDate = startDate;
|
|
74
76
|
return {
|
|
75
77
|
name: `item ${i + 1}`,
|
|
@@ -78,7 +80,7 @@ export function createTimeSeries(options) {
|
|
|
78
80
|
...Object.fromEntries(keys.map((key) => {
|
|
79
81
|
return [
|
|
80
82
|
key,
|
|
81
|
-
|
|
83
|
+
valueType === 'integer' ? getRandomInteger(min, max) : getRandomNumber(min, max),
|
|
82
84
|
];
|
|
83
85
|
})),
|
|
84
86
|
};
|
|
@@ -124,3 +126,21 @@ export function getSpiral({ angle, radius, count, width, height, }) {
|
|
|
124
126
|
};
|
|
125
127
|
});
|
|
126
128
|
}
|
|
129
|
+
export function generateSineWave(options) {
|
|
130
|
+
const { numPoints, frequency = 1, amplitude = 1, noiseLevel = 0, phase = 0, xMin = 0, xMax = 2 * Math.PI, } = options;
|
|
131
|
+
if (numPoints <= 0) {
|
|
132
|
+
throw new Error('Number of points must be greater than 0');
|
|
133
|
+
}
|
|
134
|
+
const points = [];
|
|
135
|
+
const xStep = (xMax - xMin) / (numPoints - 1);
|
|
136
|
+
for (let i = 0; i < numPoints; i++) {
|
|
137
|
+
const x = xMin + i * xStep;
|
|
138
|
+
// Generate base sine wave
|
|
139
|
+
const sineValue = amplitude * Math.sin(frequency * x + phase);
|
|
140
|
+
// Add random noise if specified
|
|
141
|
+
const noise = noiseLevel > 0 ? (Math.random() - 0.5) * 2 * noiseLevel : 0;
|
|
142
|
+
const y = sineValue + noise;
|
|
143
|
+
points.push({ x, y });
|
|
144
|
+
}
|
|
145
|
+
return points;
|
|
146
|
+
}
|
|
@@ -25,10 +25,10 @@ export declare function dagreGraph(data: DagreProps['data'], { nodes, nodeId, ed
|
|
|
25
25
|
filterNodes?: DagreProps['filterNodes'];
|
|
26
26
|
}): dagre.graphlib.Graph<{}>;
|
|
27
27
|
/**
|
|
28
|
-
* Get all upstream predecessors for dagre nodeId
|
|
28
|
+
* Get all upstream predecessors ids for dagre nodeId
|
|
29
29
|
*/
|
|
30
|
-
export declare function dagreAncestors(graph: dagre.graphlib.Graph, nodeId: string, maxDepth?: number, currentDepth?: number):
|
|
30
|
+
export declare function dagreAncestors(graph: dagre.graphlib.Graph, nodeId: string, maxDepth?: number, currentDepth?: number): string[];
|
|
31
31
|
/**
|
|
32
|
-
* Get all downstream descendants for dagre nodeId
|
|
32
|
+
* Get all downstream descendants ids for dagre nodeId
|
|
33
33
|
*/
|
|
34
|
-
export declare function dagreDescendants(graph: dagre.graphlib.Graph, nodeId: string, maxDepth?: number, currentDepth?: number):
|
|
34
|
+
export declare function dagreDescendants(graph: dagre.graphlib.Graph, nodeId: string, maxDepth?: number, currentDepth?: number): string[];
|
|
@@ -49,7 +49,7 @@ export function dagreGraph(data, { nodes = (d) => d.nodes, nodeId = (d) => d.id,
|
|
|
49
49
|
return g;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
* Get all upstream predecessors for dagre nodeId
|
|
52
|
+
* Get all upstream predecessors ids for dagre nodeId
|
|
53
53
|
*/
|
|
54
54
|
export function dagreAncestors(graph, nodeId, maxDepth = Infinity, currentDepth = 0) {
|
|
55
55
|
if (currentDepth === maxDepth) {
|
|
@@ -58,21 +58,19 @@ export function dagreAncestors(graph, nodeId, maxDepth = Infinity, currentDepth
|
|
|
58
58
|
const predecessors = graph.predecessors(nodeId) ?? [];
|
|
59
59
|
return [
|
|
60
60
|
...predecessors,
|
|
61
|
-
// @ts-expect-error: Types from dagre appear incorrect
|
|
62
61
|
...predecessors.flatMap((pId) => dagreAncestors(graph, pId, maxDepth, currentDepth + 1)),
|
|
63
62
|
];
|
|
64
63
|
}
|
|
65
64
|
/**
|
|
66
|
-
* Get all downstream descendants for dagre nodeId
|
|
65
|
+
* Get all downstream descendants ids for dagre nodeId
|
|
67
66
|
*/
|
|
68
67
|
export function dagreDescendants(graph, nodeId, maxDepth = Infinity, currentDepth = 0) {
|
|
69
68
|
if (currentDepth === maxDepth) {
|
|
70
69
|
return [];
|
|
71
70
|
}
|
|
72
|
-
const
|
|
71
|
+
const successors = graph.successors(nodeId) ?? [];
|
|
73
72
|
return [
|
|
74
|
-
...
|
|
75
|
-
|
|
76
|
-
...predecessors.flatMap((pId) => dagreDescendants(graph, pId, maxDepth, currentDepth + 1)),
|
|
73
|
+
...successors,
|
|
74
|
+
...successors.flatMap((pId) => dagreDescendants(graph, pId, maxDepth, currentDepth + 1)),
|
|
77
75
|
];
|
|
78
76
|
}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
package/dist/utils/math.d.ts
CHANGED
|
@@ -23,6 +23,23 @@ export declare function cartesianToPolar(x: number, y: number): {
|
|
|
23
23
|
radius: number;
|
|
24
24
|
radians: number;
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Calculate the angle and length between two points
|
|
28
|
+
* @param point1 - First point
|
|
29
|
+
* @param point2 - Second point
|
|
30
|
+
* @returns Angle in degrees and length
|
|
31
|
+
*/
|
|
32
|
+
export declare function pointsToAngleAndLength(point1: {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
}, point2: {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
}): {
|
|
39
|
+
radians: number;
|
|
40
|
+
angle: number;
|
|
41
|
+
length: number;
|
|
42
|
+
};
|
|
26
43
|
/** Convert celsius temperature to fahrenheit */
|
|
27
44
|
export declare function celsiusToFahrenheit(temperature: number): number;
|
|
28
45
|
/** Convert fahrenheit temperature to celsius */
|
package/dist/utils/math.js
CHANGED
|
@@ -37,6 +37,23 @@ export function cartesianToPolar(x, y) {
|
|
|
37
37
|
radians,
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Calculate the angle and length between two points
|
|
42
|
+
* @param point1 - First point
|
|
43
|
+
* @param point2 - Second point
|
|
44
|
+
* @returns Angle in degrees and length
|
|
45
|
+
*/
|
|
46
|
+
export function pointsToAngleAndLength(point1, point2) {
|
|
47
|
+
const dx = point2.x - point1.x;
|
|
48
|
+
const dy = point2.y - point1.y;
|
|
49
|
+
const radians = Math.atan2(dy, dx);
|
|
50
|
+
const length = Math.sqrt(dx * dx + dy * dy);
|
|
51
|
+
return {
|
|
52
|
+
radians,
|
|
53
|
+
angle: radiansToDegrees(radians),
|
|
54
|
+
length,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
40
57
|
/** Convert celsius temperature to fahrenheit */
|
|
41
58
|
export function celsiusToFahrenheit(temperature) {
|
|
42
59
|
return temperature * (9 / 5) + 32;
|
package/dist/utils/path.d.ts
CHANGED
|
@@ -17,5 +17,15 @@ export declare function spikePath({ x, y, width, height, }: {
|
|
|
17
17
|
width: number;
|
|
18
18
|
height: number;
|
|
19
19
|
}): string;
|
|
20
|
+
/** Create rounded polygon path
|
|
21
|
+
*
|
|
22
|
+
* @param coords - Array of points (x, y)
|
|
23
|
+
* @param radius - Radius of the curve
|
|
24
|
+
* @returns String of path data
|
|
25
|
+
*/
|
|
26
|
+
export declare function roundedPolygonPath(coords: {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
}[], radius: number): string;
|
|
20
30
|
/** Flatten all `y` coordinates to `0` */
|
|
21
31
|
export declare function flattenPathData(pathData: string, yOverride?: number): string;
|
package/dist/utils/path.js
CHANGED
|
@@ -36,6 +36,36 @@ export function spikePath({ x, y, width, height, }) {
|
|
|
36
36
|
`;
|
|
37
37
|
return pathData;
|
|
38
38
|
}
|
|
39
|
+
/** Create rounded polygon path
|
|
40
|
+
*
|
|
41
|
+
* @param coords - Array of points (x, y)
|
|
42
|
+
* @param radius - Radius of the curve
|
|
43
|
+
* @returns String of path data
|
|
44
|
+
*/
|
|
45
|
+
export function roundedPolygonPath(coords, radius) {
|
|
46
|
+
if (radius === 0) {
|
|
47
|
+
// Simple polygon with straight lines
|
|
48
|
+
return `M${coords[0].x},${coords[0].y}${coords
|
|
49
|
+
.slice(1)
|
|
50
|
+
.map((p) => `L${p.x},${p.y}`)
|
|
51
|
+
.join('')}Z`;
|
|
52
|
+
}
|
|
53
|
+
let path = '';
|
|
54
|
+
const length = coords.length + 1;
|
|
55
|
+
for (let i = 0; i < length; i++) {
|
|
56
|
+
const a = coords[i % coords.length];
|
|
57
|
+
const b = coords[(i + 1) % coords.length];
|
|
58
|
+
const t = Math.min(radius / Math.hypot(b.x - a.x, b.y - a.y), 0.5);
|
|
59
|
+
if (i == 0)
|
|
60
|
+
path += `M${a.x * (1 - t) + b.x * t},${a.y * (1 - t) + b.y * t}`;
|
|
61
|
+
if (i > 0)
|
|
62
|
+
path += `Q${a.x},${a.y} ${a.x * (1 - t) + b.x * t},${a.y * (1 - t) + b.y * t}`;
|
|
63
|
+
if (i < length - 1)
|
|
64
|
+
path += `L${a.x * t + b.x * (1 - t)},${a.y * t + b.y * (1 - t)}`;
|
|
65
|
+
}
|
|
66
|
+
path += 'Z';
|
|
67
|
+
return path;
|
|
68
|
+
}
|
|
39
69
|
/** Flatten all `y` coordinates to `0` */
|
|
40
70
|
export function flattenPathData(pathData, yOverride = 0) {
|
|
41
71
|
let result = pathData;
|
|
@@ -36,10 +36,10 @@ export declare function createDimensionGetter<TData>(ctx: ChartContextValue<TDat
|
|
|
36
36
|
y: any;
|
|
37
37
|
width: number;
|
|
38
38
|
height: number;
|
|
39
|
-
};
|
|
39
|
+
} | undefined;
|
|
40
40
|
/**
|
|
41
41
|
* If value is an array, returns first item, else returns original value
|
|
42
42
|
* Useful when x/y getters for band scale are an array (such as for histograms)
|
|
43
43
|
*/
|
|
44
|
-
export declare function firstValue(value: number | number[]): number;
|
|
44
|
+
export declare function firstValue(value: number | number[] | undefined): number | undefined;
|
|
45
45
|
export {};
|
|
@@ -59,7 +59,7 @@ export function createDimensionGetter(ctx, getOptions) {
|
|
|
59
59
|
const width = Math.max(0, ctx.xScale(right) - ctx.xScale(left) - insets.left - insets.right);
|
|
60
60
|
return { x, y, width, height };
|
|
61
61
|
}
|
|
62
|
-
else {
|
|
62
|
+
else if (isScaleBand(ctx.xScale)) {
|
|
63
63
|
// Vertical band or linear
|
|
64
64
|
const x = firstValue(ctx.xScale(_x(item))) + (ctx.x1Scale ? ctx.x1Scale(_x1(item)) : 0) + insets.left;
|
|
65
65
|
const width = Math.max(0, ctx.xScale.bandwidth
|
|
@@ -90,10 +90,82 @@ export function createDimensionGetter(ctx, getOptions) {
|
|
|
90
90
|
top = min([0, yDomainMinMax[1]]);
|
|
91
91
|
bottom = yValue;
|
|
92
92
|
}
|
|
93
|
+
// If yRange is inverted (drawing from top), swap top and bottom
|
|
94
|
+
if (ctx.yRange[0] < ctx.yRange[1]) {
|
|
95
|
+
[top, bottom] = [bottom, top];
|
|
96
|
+
}
|
|
97
|
+
const y = ctx.yScale(top) + insets.top;
|
|
98
|
+
const height = ctx.yScale(bottom) - ctx.yScale(top) - insets.bottom - insets.top;
|
|
99
|
+
return { x, y, width, height };
|
|
100
|
+
}
|
|
101
|
+
else if (ctx.xInterval) {
|
|
102
|
+
// x-axis time scale with interval
|
|
103
|
+
const xValue = _x(item);
|
|
104
|
+
const start = ctx.xInterval.floor(xValue);
|
|
105
|
+
const end = ctx.xInterval.offset(start);
|
|
106
|
+
const x = ctx.xScale(start) + insets.left;
|
|
107
|
+
const width = ctx.xScale(end) - x - insets.right;
|
|
108
|
+
const yValue = _y(item);
|
|
109
|
+
let top = 0;
|
|
110
|
+
let bottom = 0;
|
|
111
|
+
if (Array.isArray(yValue)) {
|
|
112
|
+
// Array contains both top and bottom values (stack, etc);
|
|
113
|
+
top = max(yValue);
|
|
114
|
+
bottom = min(yValue);
|
|
115
|
+
}
|
|
116
|
+
else if (yValue == null) {
|
|
117
|
+
// null/undefined value
|
|
118
|
+
top = 0;
|
|
119
|
+
bottom = 0;
|
|
120
|
+
}
|
|
121
|
+
else if (yValue > 0) {
|
|
122
|
+
// Positive value
|
|
123
|
+
top = yValue;
|
|
124
|
+
bottom = max([0, yDomainMinMax[0]]);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// Negative value
|
|
128
|
+
top = min([0, yDomainMinMax[1]]);
|
|
129
|
+
bottom = yValue;
|
|
130
|
+
}
|
|
93
131
|
const y = ctx.yScale(top) + insets.top;
|
|
94
132
|
const height = ctx.yScale(bottom) - ctx.yScale(top) - insets.bottom - insets.top;
|
|
95
133
|
return { x, y, width, height };
|
|
96
134
|
}
|
|
135
|
+
else if (ctx.yInterval) {
|
|
136
|
+
// y-axis time scale with interval
|
|
137
|
+
const yValue = _y(item);
|
|
138
|
+
const start = ctx.yInterval.floor(yValue);
|
|
139
|
+
const end = ctx.yInterval.offset(start);
|
|
140
|
+
const y = ctx.yScale(start) + insets.top;
|
|
141
|
+
const height = ctx.yScale(end) - y - insets.bottom;
|
|
142
|
+
const xValue = _x(item);
|
|
143
|
+
let left = 0;
|
|
144
|
+
let right = 0;
|
|
145
|
+
if (Array.isArray(xValue)) {
|
|
146
|
+
// Array contains both top and bottom values (stack, etc);
|
|
147
|
+
left = min(xValue);
|
|
148
|
+
right = max(xValue);
|
|
149
|
+
}
|
|
150
|
+
else if (xValue == null) {
|
|
151
|
+
// null/undefined value
|
|
152
|
+
left = 0;
|
|
153
|
+
right = 0;
|
|
154
|
+
}
|
|
155
|
+
else if (xValue > 0) {
|
|
156
|
+
// Positive value
|
|
157
|
+
left = max([0, xDomainMinMax[0]]);
|
|
158
|
+
right = xValue;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
// Negative value
|
|
162
|
+
left = xValue;
|
|
163
|
+
right = min([0, xDomainMinMax[1]]);
|
|
164
|
+
}
|
|
165
|
+
const x = ctx.xScale(left) + insets.left;
|
|
166
|
+
const width = ctx.xScale(right) - x - insets.right;
|
|
167
|
+
return { x, y, width, height };
|
|
168
|
+
}
|
|
97
169
|
};
|
|
98
170
|
}
|
|
99
171
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type ScaleBand } from 'd3-scale';
|
|
1
|
+
import { type ScaleBand, type ScaleTime } from 'd3-scale';
|
|
2
2
|
import { type MotionProp, type MotionOptions, type SpringOptions, type TweenOptions } from './motion.svelte.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type Accessor } from './common.js';
|
|
4
4
|
import type { OnlyObjects } from './types.js';
|
|
5
5
|
export type AnyScale<TInput extends SingleDomainType = any, TOutput extends SingleDomainType = any, TScaleArgs extends any[] | readonly any[] = any[]> = {
|
|
6
6
|
(value: TInput): TOutput;
|
|
@@ -23,6 +23,9 @@ export type AnyScale<TInput extends SingleDomainType = any, TOutput extends Sing
|
|
|
23
23
|
thresholds?: () => TInput[];
|
|
24
24
|
quantiles?: () => TInput[];
|
|
25
25
|
};
|
|
26
|
+
export declare function isScaleBand(scale: AnyScale<any, any>): scale is ScaleBand<any>;
|
|
27
|
+
export declare function isScaleTime(scale: AnyScale<any, any>): scale is ScaleTime<any, any>;
|
|
28
|
+
export declare function isScaleNumeric(scale: AnyScale<any, any>): scale is ScaleTime<any, any>;
|
|
26
29
|
export declare function getRange(scale: any): any[];
|
|
27
30
|
export type SingleDomainType = number | string | Date | null | undefined;
|
|
28
31
|
export type DomainType = (number | string | Date | null | undefined)[] | null | undefined;
|
|
@@ -45,7 +48,6 @@ export declare function createMotionScale<Domain, Range>(scale: AnyScale, motion
|
|
|
45
48
|
* https://gist.github.com/LuisSevillano/d53a1dc529eef518780c6df99613e2fd
|
|
46
49
|
*/
|
|
47
50
|
export declare function scaleBandInvert(scale: ScaleBand<any>): (value: number) => any;
|
|
48
|
-
export declare function isScaleBand(scale: AnyScale<any, any>): scale is ScaleBand<any>;
|
|
49
51
|
/**
|
|
50
52
|
* Generic way to invert a scale value, handling scaleBand and continuous scales (linear, time, etc).
|
|
51
53
|
* Useful to map mouse event location (x,y) to domain value
|
|
@@ -53,6 +55,10 @@ export declare function isScaleBand(scale: AnyScale<any, any>): scale is ScaleBa
|
|
|
53
55
|
export declare function scaleInvert(scale: AnyScale<any, any>, value: number): any;
|
|
54
56
|
/** Create new copy of scale with domain and range */
|
|
55
57
|
export declare function createScale(scale: AnyScale, domain: DomainType, range: any[] | readonly any[] | Function, context?: Record<any, any>): AnyScale<any, any, any[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Auto-detect scale type based on domain values or data values
|
|
60
|
+
*/
|
|
61
|
+
export declare function autoScale(domain?: DomainType, data?: any[], propAccessor?: Accessor<any>): AnyScale;
|
|
56
62
|
/**
|
|
57
63
|
* Create a `scaleBand()` within another scaleBand()'s bandwidth
|
|
58
64
|
* (typically a x1 of an x0 scale, used for grouping)
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { unique } from '@layerstack/utils';
|
|
2
|
-
import { scaleBand } from 'd3-scale';
|
|
2
|
+
import { scaleBand, scaleLinear, scaleTime } from 'd3-scale';
|
|
3
3
|
import { createControlledMotion, } from './motion.svelte.js';
|
|
4
4
|
import { Spring, Tween } from 'svelte/motion';
|
|
5
|
+
import { accessor } from './common.js';
|
|
5
6
|
function isAnyScale(scale) {
|
|
6
7
|
return typeof scale === 'function' && typeof scale.range === 'function';
|
|
7
8
|
}
|
|
9
|
+
export function isScaleBand(scale) {
|
|
10
|
+
return typeof scale.bandwidth === 'function';
|
|
11
|
+
}
|
|
12
|
+
export function isScaleTime(scale) {
|
|
13
|
+
const domain = scale.domain();
|
|
14
|
+
return domain[0] instanceof Date || domain[1] instanceof Date;
|
|
15
|
+
}
|
|
16
|
+
export function isScaleNumeric(scale) {
|
|
17
|
+
const domain = scale.domain();
|
|
18
|
+
return typeof domain[0] === 'number' || typeof domain[1] === 'number';
|
|
19
|
+
}
|
|
8
20
|
export function getRange(scale) {
|
|
9
21
|
if (isAnyScale(scale)) {
|
|
10
22
|
return scale.range();
|
|
@@ -54,9 +66,6 @@ export function scaleBandInvert(scale) {
|
|
|
54
66
|
return domain[Math.max(0, Math.min(index, domain.length - 1))];
|
|
55
67
|
};
|
|
56
68
|
}
|
|
57
|
-
export function isScaleBand(scale) {
|
|
58
|
-
return typeof scale.bandwidth === 'function';
|
|
59
|
-
}
|
|
60
69
|
/**
|
|
61
70
|
* Generic way to invert a scale value, handling scaleBand and continuous scales (linear, time, etc).
|
|
62
71
|
* Useful to map mouse event location (x,y) to domain value
|
|
@@ -83,6 +92,40 @@ export function createScale(scale, domain, range, context) {
|
|
|
83
92
|
}
|
|
84
93
|
return scaleCopy;
|
|
85
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Auto-detect scale type based on domain values or data values
|
|
97
|
+
*/
|
|
98
|
+
export function autoScale(domain, data, propAccessor) {
|
|
99
|
+
let values = null;
|
|
100
|
+
if (domain && domain.length > 0 && domain.some((d) => d != null)) {
|
|
101
|
+
// Determine based on non-null domain values
|
|
102
|
+
values = domain.filter((d) => d != null);
|
|
103
|
+
}
|
|
104
|
+
else if (data && data.length > 0 && propAccessor) {
|
|
105
|
+
// Determine based on data values
|
|
106
|
+
const value = accessor(propAccessor)(data[0]);
|
|
107
|
+
// If accessor defined with an array (ex. `x={['start', 'end']}`) use both values
|
|
108
|
+
if (Array.isArray(value)) {
|
|
109
|
+
values = value;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
values = [value];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (values) {
|
|
116
|
+
if (values.some((v) => v instanceof Date)) {
|
|
117
|
+
return scaleTime();
|
|
118
|
+
}
|
|
119
|
+
else if (values.some((v) => typeof v === 'number')) {
|
|
120
|
+
return scaleLinear();
|
|
121
|
+
}
|
|
122
|
+
else if (values.some((v) => typeof v === 'string')) {
|
|
123
|
+
return scaleBand();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// fallback to linear scale
|
|
127
|
+
return scaleLinear();
|
|
128
|
+
}
|
|
86
129
|
/**
|
|
87
130
|
* Create a `scaleBand()` within another scaleBand()'s bandwidth
|
|
88
131
|
* (typically a x1 of an x0 scale, used for grouping)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Get points to create a polygon with given number of points and radius
|
|
2
|
+
*
|
|
3
|
+
* @param count - Number of points
|
|
4
|
+
* @param radius - Radius of the polygon
|
|
5
|
+
* @returns Array of points (angle, radius)
|
|
6
|
+
*/
|
|
7
|
+
export declare function polygonPoints(count: number, radius: number, rotate?: number): {
|
|
8
|
+
angle: number;
|
|
9
|
+
radius: number;
|
|
10
|
+
}[];
|
|
11
|
+
/** Create polygon
|
|
12
|
+
*
|
|
13
|
+
* @param cx - Center x coordinate
|
|
14
|
+
* @param cy - Center y coordinate
|
|
15
|
+
* @param count - Number of points
|
|
16
|
+
* @param radius - Radius of the polygon
|
|
17
|
+
* @param rotate - Rotation of the polygon (degrees)
|
|
18
|
+
* @param inset - Percent to inset odd points (<1 inset, >1 outset)
|
|
19
|
+
* @param scaleX - Horizontal stretch factor
|
|
20
|
+
* @param scaleY - Vertical stretch factor
|
|
21
|
+
* @param skewX - Skew angle in degrees along the X axis
|
|
22
|
+
* @param skewY - Skew angle in degrees along the Y axis
|
|
23
|
+
* @param tiltX - Tilt factor for x-coordinates (0 = no tilt, positive moves points top => down, negative moves points bottom => up)
|
|
24
|
+
* @param tiltY - Tilt factor for y-coordinates (0 = no tilt, positive moves points left => right, negative moves points right => left)
|
|
25
|
+
* @returns Array of points (x, y)
|
|
26
|
+
*/
|
|
27
|
+
export declare function polygon(options: {
|
|
28
|
+
cx: number;
|
|
29
|
+
cy: number;
|
|
30
|
+
count: number;
|
|
31
|
+
radius: number;
|
|
32
|
+
rotate?: number;
|
|
33
|
+
inset?: number;
|
|
34
|
+
scaleX?: number;
|
|
35
|
+
scaleY?: number;
|
|
36
|
+
skewX?: number;
|
|
37
|
+
skewY?: number;
|
|
38
|
+
tiltX?: number;
|
|
39
|
+
tiltY?: number;
|
|
40
|
+
}): {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
}[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { range } from 'd3-array';
|
|
2
|
+
import { degreesToRadians } from './math.js';
|
|
3
|
+
/** Get points to create a polygon with given number of points and radius
|
|
4
|
+
*
|
|
5
|
+
* @param count - Number of points
|
|
6
|
+
* @param radius - Radius of the polygon
|
|
7
|
+
* @returns Array of points (angle, radius)
|
|
8
|
+
*/
|
|
9
|
+
export function polygonPoints(count, radius, rotate = 0) {
|
|
10
|
+
const angle = 360 / count;
|
|
11
|
+
return range(count).map((index) => {
|
|
12
|
+
return {
|
|
13
|
+
angle: degreesToRadians(angle * index) + degreesToRadians(rotate),
|
|
14
|
+
radius,
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** Create polygon
|
|
19
|
+
*
|
|
20
|
+
* @param cx - Center x coordinate
|
|
21
|
+
* @param cy - Center y coordinate
|
|
22
|
+
* @param count - Number of points
|
|
23
|
+
* @param radius - Radius of the polygon
|
|
24
|
+
* @param rotate - Rotation of the polygon (degrees)
|
|
25
|
+
* @param inset - Percent to inset odd points (<1 inset, >1 outset)
|
|
26
|
+
* @param scaleX - Horizontal stretch factor
|
|
27
|
+
* @param scaleY - Vertical stretch factor
|
|
28
|
+
* @param skewX - Skew angle in degrees along the X axis
|
|
29
|
+
* @param skewY - Skew angle in degrees along the Y axis
|
|
30
|
+
* @param tiltX - Tilt factor for x-coordinates (0 = no tilt, positive moves points top => down, negative moves points bottom => up)
|
|
31
|
+
* @param tiltY - Tilt factor for y-coordinates (0 = no tilt, positive moves points left => right, negative moves points right => left)
|
|
32
|
+
* @returns Array of points (x, y)
|
|
33
|
+
*/
|
|
34
|
+
export function polygon(options) {
|
|
35
|
+
const { cx, cy, count, radius, rotate = 0, inset = 1, scaleX = 1, scaleY = 1, skewX = 0, skewY = 0, tiltX = 0, tiltY = 0, } = options;
|
|
36
|
+
const skewXRad = degreesToRadians(skewX);
|
|
37
|
+
const skewYRad = degreesToRadians(skewY);
|
|
38
|
+
return polygonPoints(count, radius, rotate).map(({ angle, radius }, i) => {
|
|
39
|
+
// inset
|
|
40
|
+
const insetScale = i % 2 == 0 ? 1 : 1 - inset;
|
|
41
|
+
// scale
|
|
42
|
+
let x = radius * insetScale * Math.cos(angle) * scaleX;
|
|
43
|
+
let y = radius * insetScale * Math.sin(angle) * scaleY;
|
|
44
|
+
// tilt
|
|
45
|
+
const normalizedY = (y + radius) / (2 * radius);
|
|
46
|
+
const normalizedX = (x + radius) / (2 * radius);
|
|
47
|
+
const tiltScaleX = tiltX > 0 ? 1 + tiltX * (1 - normalizedY) : 1 - tiltX * normalizedY;
|
|
48
|
+
const tiltScaleY = tiltY > 0 ? 1 + tiltY * (1 - normalizedX) : 1 - tiltY * normalizedX;
|
|
49
|
+
x *= tiltScaleX;
|
|
50
|
+
y *= tiltScaleY;
|
|
51
|
+
// skew
|
|
52
|
+
const xSkewed = x + Math.tan(skewXRad) * y;
|
|
53
|
+
const ySkewed = y + Math.tan(skewYRad) * x;
|
|
54
|
+
return {
|
|
55
|
+
x: cx + xSkewed,
|
|
56
|
+
y: cy + ySkewed,
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}
|
package/dist/utils/stack.js
CHANGED
|
@@ -91,7 +91,7 @@ export function stackOffsetSeparated(series, order) {
|
|
|
91
91
|
return;
|
|
92
92
|
// Standard series
|
|
93
93
|
for (var i = 1, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
|
|
94
|
-
(s0 = s1), (s1 = series[order[i]]);
|
|
94
|
+
((s0 = s1), (s1 = series[order[i]]));
|
|
95
95
|
// @ts-expect-error
|
|
96
96
|
let base = max(s0, (d) => d[1]) + gap; // here is where you calculate the maximum of the previous layer
|
|
97
97
|
for (var j = 0; j < m; ++j) {
|