layerchart 0.41.6 → 0.43.0
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/Arc.svelte +27 -20
- package/dist/components/Arc.svelte.d.ts +2 -2
- package/dist/components/Area.svelte +11 -7
- package/dist/components/Area.svelte.d.ts +3 -3
- package/dist/components/AreaStack.svelte +3 -2
- package/dist/components/Axis.svelte +38 -41
- package/dist/components/Axis.svelte.d.ts +5 -4
- package/dist/components/Bar.svelte +6 -5
- package/dist/components/Bar.svelte.d.ts +3 -2
- package/dist/components/Bars.svelte +5 -4
- package/dist/components/Bars.svelte.d.ts +3 -2
- package/dist/components/Bounds.svelte +7 -5
- package/dist/components/Bounds.svelte.d.ts +8 -8
- package/dist/components/Brush.svelte +8 -6
- package/dist/components/Brush.svelte.d.ts +2 -2
- package/dist/components/Calendar.svelte +4 -3
- package/dist/components/Chart.svelte +72 -86
- package/dist/components/Chart.svelte.d.ts +216 -24
- package/dist/components/ChartClipPath.svelte +6 -6
- package/dist/components/ChartContext.svelte +19 -0
- package/dist/components/ChartContext.svelte.d.ts +89 -0
- package/dist/components/Circle.svelte +1 -0
- package/dist/components/ClipPath.svelte +1 -0
- package/dist/components/ForceSimulation.svelte +182 -25
- package/dist/components/ForceSimulation.svelte.d.ts +11 -1
- package/dist/components/Frame.svelte +8 -7
- package/dist/components/Frame.svelte.d.ts +1 -1
- package/dist/components/GeoCircle.svelte.d.ts +1 -2
- package/dist/components/GeoContext.svelte +2 -1
- package/dist/components/GeoContext.svelte.d.ts +5 -5
- package/dist/components/GeoEdgeFade.svelte +2 -5
- package/dist/components/GeoPath.svelte +9 -5
- package/dist/components/GeoPath.svelte.d.ts +7 -4
- package/dist/components/GeoPoint.svelte +0 -1
- package/dist/components/GeoSpline.svelte +2 -11
- package/dist/components/GeoTile.svelte +3 -1
- package/dist/components/Group.svelte +4 -2
- package/dist/components/Highlight.svelte +16 -10
- package/dist/components/Highlight.svelte.d.ts +16 -15
- package/dist/components/HitCanvas.svelte +5 -2
- package/dist/components/HitCanvas.svelte.d.ts +1 -1
- package/dist/components/Hull.svelte +6 -3
- package/dist/components/Labels.svelte +5 -4
- package/dist/components/Labels.svelte.d.ts +0 -1
- package/dist/components/Legend.svelte +4 -4
- package/dist/components/Legend.svelte.d.ts +2 -2
- package/dist/components/Line.svelte +1 -0
- package/dist/components/Link.svelte +3 -1
- package/dist/components/Pack.svelte +4 -3
- package/dist/components/Partition.svelte +3 -3
- package/dist/components/Partition.svelte.d.ts +2 -1
- package/dist/components/Pie.svelte +7 -6
- package/dist/components/Pie.svelte.d.ts +2 -4
- package/dist/components/Point.svelte +2 -2
- package/dist/components/Points.svelte +4 -3
- package/dist/components/RadialGradient.svelte +2 -2
- package/dist/components/RadialGradient.svelte.d.ts +0 -1
- package/dist/components/Rect.svelte +1 -0
- package/dist/components/Rule.svelte +3 -3
- package/dist/components/Sankey.svelte +9 -3
- package/dist/components/Sankey.svelte.d.ts +2 -2
- package/dist/components/Spline.svelte +9 -6
- package/dist/components/Spline.svelte.d.ts +2 -2
- package/dist/components/Text.svelte +1 -2
- package/dist/components/Threshold.svelte +2 -2
- package/dist/components/Threshold.svelte.d.ts +2 -2
- package/dist/components/TileImage.svelte +4 -1
- package/dist/components/Tooltip.svelte +3 -3
- package/dist/components/TooltipContext.svelte +46 -15
- package/dist/components/TooltipContext.svelte.d.ts +1 -1
- package/dist/components/TooltipItem.svelte.d.ts +1 -1
- package/dist/components/TransformContext.svelte +17 -6
- package/dist/components/TransformControls.svelte +1 -0
- package/dist/components/Tree.svelte +4 -3
- package/dist/components/Tree.svelte.d.ts +3 -3
- package/dist/components/Treemap.svelte +11 -12
- package/dist/components/Treemap.svelte.d.ts +6 -6
- package/dist/components/Voronoi.svelte +8 -3
- package/dist/components/layout/Canvas.svelte +5 -3
- package/dist/components/layout/Html.svelte +3 -3
- package/dist/components/layout/Svg.svelte +6 -3
- package/dist/docs/Code.svelte +2 -3
- package/dist/docs/GeoDebug.svelte +4 -4
- package/dist/docs/Link.svelte +2 -4
- package/dist/docs/Link.svelte.d.ts +14 -5
- package/dist/docs/Preview.svelte +1 -1
- package/dist/docs/TilesetField.svelte +1 -1
- package/dist/docs/TilesetField.svelte.d.ts +1 -1
- package/dist/docs/ViewSourceButton.svelte +4 -4
- package/dist/docs/ViewSourceButton.svelte.d.ts +5 -3
- package/dist/stores/motionStore.d.ts +2 -2
- package/dist/stores/motionStore.js +4 -2
- package/dist/utils/array.d.ts +5 -0
- package/dist/utils/array.js +7 -0
- package/dist/utils/common.d.ts +2 -0
- package/dist/utils/common.js +18 -0
- package/dist/utils/genData.d.ts +23 -23
- package/dist/utils/genData.js +3 -2
- package/dist/utils/geo.d.ts +3 -3
- package/dist/utils/geo.js +2 -0
- package/dist/utils/graph.d.ts +1 -1
- package/dist/utils/graph.js +3 -3
- package/dist/utils/hierarchy.d.ts +1 -1
- package/dist/utils/hierarchy.js +1 -0
- package/dist/utils/rect.d.ts +5 -3
- package/dist/utils/rect.js +7 -11
- package/dist/utils/scales.d.ts +21 -12
- package/dist/utils/scales.js +3 -1
- package/dist/utils/stack.d.ts +5 -2
- package/dist/utils/stack.js +20 -7
- package/dist/utils/threshold.js +1 -0
- package/dist/utils/treemap.d.ts +5 -2
- package/dist/utils/treemap.js +1 -1
- package/package.json +6 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { get } from 'lodash-es';
|
|
2
|
+
export function accessor(prop) {
|
|
3
|
+
if (Array.isArray(prop)) {
|
|
4
|
+
return (d) => prop.map((p) => accessor(p)(d));
|
|
5
|
+
}
|
|
6
|
+
else if (typeof prop === 'function') {
|
|
7
|
+
// function
|
|
8
|
+
return prop;
|
|
9
|
+
}
|
|
10
|
+
else if (typeof prop === 'string') {
|
|
11
|
+
// path
|
|
12
|
+
return (d) => get(d, prop);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
// return full object
|
|
16
|
+
return (d) => d;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/dist/utils/genData.d.ts
CHANGED
|
@@ -14,35 +14,35 @@ export declare function getRandomInteger(min: number, max: number, includeMax?:
|
|
|
14
14
|
export declare function randomWalk(options?: {
|
|
15
15
|
count?: number;
|
|
16
16
|
}): number[];
|
|
17
|
-
export declare function createSeries(options: {
|
|
17
|
+
export declare function createSeries<TKey extends string>(options: {
|
|
18
18
|
count?: number;
|
|
19
19
|
min: number;
|
|
20
20
|
max: number;
|
|
21
|
-
keys?:
|
|
21
|
+
keys?: TKey[];
|
|
22
22
|
value?: 'number' | 'integer';
|
|
23
|
-
}): {
|
|
23
|
+
}): ({
|
|
24
24
|
x: number;
|
|
25
|
-
}[];
|
|
26
|
-
export declare function createDateSeries(options: {
|
|
25
|
+
} & { [K in TKey]: number; })[];
|
|
26
|
+
export declare function createDateSeries<TKey extends string>(options: {
|
|
27
27
|
count?: number;
|
|
28
28
|
min: number;
|
|
29
29
|
max: number;
|
|
30
|
-
keys?:
|
|
30
|
+
keys?: TKey[];
|
|
31
31
|
value?: 'number' | 'integer';
|
|
32
|
-
}): {
|
|
32
|
+
}): ({
|
|
33
33
|
date: Date;
|
|
34
|
-
}[];
|
|
35
|
-
export declare function createTimeSeries(options: {
|
|
34
|
+
} & { [K in TKey]: number; })[];
|
|
35
|
+
export declare function createTimeSeries<TKey extends string>(options: {
|
|
36
36
|
count?: number;
|
|
37
37
|
min: number;
|
|
38
38
|
max: number;
|
|
39
|
-
keys:
|
|
39
|
+
keys: TKey[];
|
|
40
40
|
value: 'number' | 'integer';
|
|
41
|
-
}): {
|
|
41
|
+
}): ({
|
|
42
42
|
name: string;
|
|
43
43
|
startDate: Date;
|
|
44
44
|
endDate: Date;
|
|
45
|
-
}[];
|
|
45
|
+
} & { [K in TKey]: number; })[];
|
|
46
46
|
export declare const wideData: {
|
|
47
47
|
year: string;
|
|
48
48
|
apples: number;
|
|
@@ -56,21 +56,21 @@ export declare const longData: {
|
|
|
56
56
|
fruit: string;
|
|
57
57
|
value: number;
|
|
58
58
|
}[];
|
|
59
|
-
export declare function getPhyllotaxis({ radius, count, width, height }: {
|
|
60
|
-
radius:
|
|
61
|
-
count:
|
|
62
|
-
width:
|
|
63
|
-
height:
|
|
59
|
+
export declare function getPhyllotaxis({ radius, count, width, height, }: {
|
|
60
|
+
radius: number;
|
|
61
|
+
count: number;
|
|
62
|
+
width: number;
|
|
63
|
+
height: number;
|
|
64
64
|
}): {
|
|
65
65
|
x: number;
|
|
66
66
|
y: number;
|
|
67
67
|
}[];
|
|
68
|
-
export declare function getSpiral({ angle, radius, count, width, height }: {
|
|
69
|
-
angle:
|
|
70
|
-
radius:
|
|
71
|
-
count:
|
|
72
|
-
width:
|
|
73
|
-
height:
|
|
68
|
+
export declare function getSpiral({ angle, radius, count, width, height, }: {
|
|
69
|
+
angle: number;
|
|
70
|
+
radius: number;
|
|
71
|
+
count: number;
|
|
72
|
+
width: number;
|
|
73
|
+
height: number;
|
|
74
74
|
}): {
|
|
75
75
|
x: number;
|
|
76
76
|
y: number;
|
package/dist/utils/genData.js
CHANGED
|
@@ -23,6 +23,7 @@ export function getRandomInteger(min, max, includeMax = true) {
|
|
|
23
23
|
*/
|
|
24
24
|
export function randomWalk(options) {
|
|
25
25
|
const random = randomNormal();
|
|
26
|
+
// @ts-expect-error
|
|
26
27
|
return Array.from(cumsum({ length: options?.count ?? 100 }, random));
|
|
27
28
|
}
|
|
28
29
|
export function createSeries(options) {
|
|
@@ -108,12 +109,12 @@ export const longData = [
|
|
|
108
109
|
{ year: '2016', basket: 2, fruit: 'cherries', value: 720 },
|
|
109
110
|
{ year: '2016', basket: 2, fruit: 'dates', value: 400 },
|
|
110
111
|
];
|
|
111
|
-
export function getPhyllotaxis({ radius, count, width, height }) {
|
|
112
|
+
export function getPhyllotaxis({ radius, count, width, height, }) {
|
|
112
113
|
// Phyllotaxis: https://www.youtube.com/watch?v=KWoJgHFYWxY
|
|
113
114
|
const rads = Math.PI * (3 - Math.sqrt(5)); // ~2.4 rads or ~137.5 degrees
|
|
114
115
|
return getSpiral({ angle: radiansToDegrees(rads), radius, count, width, height });
|
|
115
116
|
}
|
|
116
|
-
export function getSpiral({ angle, radius, count, width, height }) {
|
|
117
|
+
export function getSpiral({ angle, radius, count, width, height, }) {
|
|
117
118
|
return Array.from({ length: count }, (_, i) => {
|
|
118
119
|
const r = radius * Math.sqrt(i);
|
|
119
120
|
const a = degreesToRadians(angle * i);
|
package/dist/utils/geo.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { geoPath as d3geoPath, type GeoProjection, type GeoStreamWrapper } from 'd3-geo';
|
|
2
2
|
import { type Path } from 'd3-path';
|
|
3
3
|
import { type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
|
|
4
4
|
/**
|
|
5
5
|
* Render a geoPath() using curve factory
|
|
6
6
|
* @see {@link https://observablehq.com/@d3/context-to-curve}
|
|
7
7
|
*/
|
|
8
|
-
export declare function geoCurvePath(projection: GeoProjection | GeoStreamWrapper | null, curve: CurveFactory | CurveFactoryLineOnly, context?: CanvasRenderingContext2D | Path):
|
|
8
|
+
export declare function geoCurvePath(projection: GeoProjection | GeoStreamWrapper | null, curve: CurveFactory | CurveFactoryLineOnly, context?: CanvasRenderingContext2D | Path): ReturnType<typeof d3geoPath>;
|
|
9
9
|
/**
|
|
10
10
|
* Return the point on Earth's surface that is diametrically opposite to another point
|
|
11
11
|
* @see: https://en.wikipedia.org/wiki/Antipodes
|
|
@@ -15,7 +15,7 @@ export declare function antipode([longitude, latitude]: [number, number]): [numb
|
|
|
15
15
|
* Check if point ([x, y]) is visible on projection
|
|
16
16
|
* @see: https://observablehq.com/@d3/testing-projection-visibility
|
|
17
17
|
*/
|
|
18
|
-
export declare function isVisible(projection: GeoProjection | GeoStreamWrapper): ([x, y]: [
|
|
18
|
+
export declare function isVisible(projection: GeoProjection | GeoStreamWrapper): ([x, y]: [number, number]) => boolean;
|
|
19
19
|
export declare function geoFitObjectTransform(projection: GeoProjection, size: [number, number], object: Parameters<typeof projection.fitSize>[1]): {
|
|
20
20
|
translate: {
|
|
21
21
|
x: number;
|
package/dist/utils/geo.js
CHANGED
|
@@ -14,6 +14,7 @@ export function geoCurvePath(projection, curve, context) {
|
|
|
14
14
|
};
|
|
15
15
|
// Expose geoPath properties such as `.centroid()`
|
|
16
16
|
Object.setPrototypeOf(fn, geoPath);
|
|
17
|
+
// @ts-expect-error
|
|
17
18
|
return fn;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
@@ -52,6 +53,7 @@ export function antipode([longitude, latitude]) {
|
|
|
52
53
|
*/
|
|
53
54
|
export function isVisible(projection) {
|
|
54
55
|
let visible;
|
|
56
|
+
// @ts-expect-error
|
|
55
57
|
const stream = projection.stream({
|
|
56
58
|
point() {
|
|
57
59
|
visible = true;
|
package/dist/utils/graph.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare function graphFromHierarchy(hierarchy: ReturnType<typeof d3Hierar
|
|
|
19
19
|
* Create graph from node (and target node/links downward)
|
|
20
20
|
*/
|
|
21
21
|
export declare function graphFromNode(node: SankeyNodeMinimal<any, any>): {
|
|
22
|
-
nodes:
|
|
22
|
+
nodes: any[];
|
|
23
23
|
links: any[];
|
|
24
24
|
};
|
|
25
25
|
/**
|
package/dist/utils/graph.js
CHANGED
|
@@ -7,8 +7,8 @@ export function graphFromCsv(csv) {
|
|
|
7
7
|
? {
|
|
8
8
|
source,
|
|
9
9
|
target,
|
|
10
|
-
// @ts-
|
|
11
|
-
value: !value || isNaN((value = +value)) ? 1 : value,
|
|
10
|
+
// @ts-expect-error
|
|
11
|
+
value: !value || isNaN((value = +value)) ? 1 : +value,
|
|
12
12
|
// color: linkColor,
|
|
13
13
|
}
|
|
14
14
|
: null);
|
|
@@ -29,7 +29,7 @@ export function graphFromHierarchy(hierarchy) {
|
|
|
29
29
|
export function graphFromNode(node) {
|
|
30
30
|
const nodes = [node];
|
|
31
31
|
const links = [];
|
|
32
|
-
node.sourceLinks
|
|
32
|
+
node.sourceLinks?.forEach((link) => {
|
|
33
33
|
nodes.push(link.target);
|
|
34
34
|
links.push(link);
|
|
35
35
|
if (link.target.sourceLinks.length) {
|
|
@@ -3,4 +3,4 @@ import type { HierarchyNode } from 'd3-hierarchy';
|
|
|
3
3
|
* Find first ancestor matching filter, including node.
|
|
4
4
|
* Similar to `node.find()` (https://github.com/d3/d3-hierarchy#node_find) but checks ancestors instead of descendants
|
|
5
5
|
*/
|
|
6
|
-
export declare function findAncestor<T = any>(node: HierarchyNode<T>, filter: (node:
|
|
6
|
+
export declare function findAncestor<T = any>(node: HierarchyNode<T>, filter: (node: HierarchyNode<T>) => boolean): HierarchyNode<T> | null;
|
package/dist/utils/hierarchy.js
CHANGED
package/dist/utils/rect.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { ChartContext } from '../components/ChartContext.svelte';
|
|
2
|
+
import { type Accessor } from './common.js';
|
|
1
3
|
type DimensionGetterOptions = {
|
|
2
4
|
/** Override `x` accessor from context */
|
|
3
|
-
x?:
|
|
5
|
+
x?: Accessor;
|
|
4
6
|
/** Override `y` accessor from context */
|
|
5
|
-
y?:
|
|
7
|
+
y?: Accessor;
|
|
6
8
|
groupBy?: string;
|
|
7
9
|
inset?: number;
|
|
8
10
|
groupPadding?: {
|
|
@@ -10,7 +12,7 @@ type DimensionGetterOptions = {
|
|
|
10
12
|
outer?: number;
|
|
11
13
|
};
|
|
12
14
|
};
|
|
13
|
-
export declare function createDimensionGetter(context:
|
|
15
|
+
export declare function createDimensionGetter<TData>(context: ChartContext<TData>, options?: DimensionGetterOptions): import("svelte/store").Readable<(item: any) => {
|
|
14
16
|
x: any;
|
|
15
17
|
y: number;
|
|
16
18
|
width: number;
|
package/dist/utils/rect.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { derived } from 'svelte/store';
|
|
2
2
|
import { max, min } from 'd3-array';
|
|
3
3
|
import { groupScaleBand, isScaleBand } from './scales.js';
|
|
4
|
+
import { accessor } from './common.js';
|
|
4
5
|
// TOOD: Pass in overrides for `x` and `y` accessors
|
|
5
6
|
export function createDimensionGetter(context, options) {
|
|
6
7
|
const { flatData, xGet, yGet, xScale, yScale, x: xAccessor, y: yAccessor } = context;
|
|
@@ -10,19 +11,17 @@ export function createDimensionGetter(context, options) {
|
|
|
10
11
|
// Use `xscale.domain()` instead of `$xDomain` to include `nice()` being applied
|
|
11
12
|
const [minXDomain, maxXDomain] = $xScale.domain();
|
|
12
13
|
const [minYDomain, maxYDomain] = $yScale.domain();
|
|
14
|
+
// @ts-expect-error
|
|
13
15
|
return function getter(item) {
|
|
14
16
|
if (isScaleBand($yScale)) {
|
|
15
17
|
// Horizontal band
|
|
16
18
|
const y1Scale = groupBy
|
|
17
19
|
? groupScaleBand($yScale, $flatData, groupBy, options?.groupPadding)
|
|
18
20
|
: null;
|
|
21
|
+
// @ts-expect-error
|
|
19
22
|
const y = firstValue($yGet(item)) + (y1Scale ? y1Scale(item[groupBy]) : 0) + inset / 2;
|
|
20
23
|
const height = Math.max(0, $yScale.bandwidth ? (y1Scale ? y1Scale.bandwidth() : $yScale.bandwidth()) - inset : 0);
|
|
21
|
-
const _x = options?.x
|
|
22
|
-
? typeof options.x === 'string'
|
|
23
|
-
? (d) => d[options.x]
|
|
24
|
-
: options?.x
|
|
25
|
-
: $xAccessor;
|
|
24
|
+
const _x = accessor(options?.x ?? $xAccessor);
|
|
26
25
|
const xValue = _x(item);
|
|
27
26
|
let left = 0;
|
|
28
27
|
let right = 0;
|
|
@@ -55,16 +54,13 @@ export function createDimensionGetter(context, options) {
|
|
|
55
54
|
}
|
|
56
55
|
else {
|
|
57
56
|
// Vertical band or linear
|
|
58
|
-
const x1Scale = groupBy
|
|
57
|
+
const x1Scale = groupBy && isScaleBand($xScale)
|
|
59
58
|
? groupScaleBand($xScale, $flatData, groupBy, options?.groupPadding)
|
|
60
59
|
: null;
|
|
60
|
+
// @ts-expect-error
|
|
61
61
|
const x = firstValue($xGet(item)) + (x1Scale ? x1Scale(item[groupBy]) : 0) + inset / 2;
|
|
62
62
|
const width = Math.max(0, $xScale.bandwidth ? (x1Scale ? x1Scale.bandwidth() : $xScale.bandwidth()) - inset : 0);
|
|
63
|
-
const _y = options?.y
|
|
64
|
-
? typeof options.y === 'string'
|
|
65
|
-
? (d) => d[options.y]
|
|
66
|
-
: options?.y
|
|
67
|
-
: $yAccessor;
|
|
63
|
+
const _y = accessor(options?.y ?? $yAccessor);
|
|
68
64
|
const yValue = _y(item);
|
|
69
65
|
let top = 0;
|
|
70
66
|
let bottom = 0;
|
package/dist/utils/scales.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { tweened, spring } from 'svelte/motion';
|
|
2
2
|
import { type MotionOptions } from '../stores/motionStore.js';
|
|
3
3
|
import { type ScaleBand } from 'd3-scale';
|
|
4
|
+
export type AnyScale<Domain = any, Range = any, Input = Domain, Output = any> = {
|
|
5
|
+
(value: Input): Output;
|
|
6
|
+
invert?: (value: Output) => Input;
|
|
7
|
+
domain(): Domain[];
|
|
8
|
+
range(): Range[];
|
|
9
|
+
bandwidth?: Function;
|
|
10
|
+
ticks?: Function;
|
|
11
|
+
tickFormat?: Function;
|
|
12
|
+
};
|
|
4
13
|
/**
|
|
5
14
|
* Implemenation for missing `scaleBand().invert()`
|
|
6
15
|
*
|
|
@@ -11,13 +20,13 @@ import { type ScaleBand } from 'd3-scale';
|
|
|
11
20
|
* https://github.com/d3/d3-scale/blob/11777dac7d4b0b3e229d658aee3257ea67bd5ffa/src/band.js#L32
|
|
12
21
|
* https://gist.github.com/LuisSevillano/d53a1dc529eef518780c6df99613e2fd
|
|
13
22
|
*/
|
|
14
|
-
export declare function scaleBandInvert(scale: any): (value:
|
|
15
|
-
export declare function isScaleBand(scale: any):
|
|
23
|
+
export declare function scaleBandInvert(scale: ScaleBand<any>): (value: number) => any;
|
|
24
|
+
export declare function isScaleBand(scale: AnyScale<any, any>): scale is ScaleBand<any>;
|
|
16
25
|
/**
|
|
17
26
|
* Generic way to invert a scale value, handling scaleBand and continuous scales (linear, time, etc).
|
|
18
27
|
* Useful to map mouse event location (x,y) to domain value
|
|
19
28
|
*/
|
|
20
|
-
export declare function scaleInvert(scale: any, value: number): any;
|
|
29
|
+
export declare function scaleInvert(scale: AnyScale<any, any>, value: number): any;
|
|
21
30
|
/** Create a `scaleBand()` within another scaleBand()'s bandwidth (typically a x1 of an x0 scale, used for grouping) */
|
|
22
31
|
export declare function groupScaleBand<Domain extends {
|
|
23
32
|
toString(): string;
|
|
@@ -28,24 +37,24 @@ export declare function groupScaleBand<Domain extends {
|
|
|
28
37
|
/**
|
|
29
38
|
* Animate d3-scale as domain and/or range are updated using tweened store
|
|
30
39
|
*/
|
|
31
|
-
export declare function tweenedScale(scale: any, tweenedOptions?: Parameters<typeof tweened
|
|
40
|
+
export declare function tweenedScale<Domain, Range>(scale: any, tweenedOptions?: Parameters<typeof tweened<any>>[1]): {
|
|
32
41
|
subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: import("svelte/store").Invalidator<any> | undefined) => import("svelte/store").Unsubscriber;
|
|
33
|
-
domain: (values:
|
|
34
|
-
range: (values:
|
|
42
|
+
domain: (values: Domain) => Promise<void>;
|
|
43
|
+
range: (values: Range) => Promise<void>;
|
|
35
44
|
};
|
|
36
45
|
/**
|
|
37
46
|
* Animate d3-scale as domain and/or range are updated using spring store
|
|
38
47
|
*/
|
|
39
|
-
export declare function springScale(scale:
|
|
48
|
+
export declare function springScale<Domain, Range>(scale: AnyScale, springOptions?: Parameters<typeof spring>[1]): {
|
|
40
49
|
subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: import("svelte/store").Invalidator<any> | undefined) => import("svelte/store").Unsubscriber;
|
|
41
|
-
domain: (values:
|
|
42
|
-
range: (values:
|
|
50
|
+
domain: (values: Domain) => Promise<void>;
|
|
51
|
+
range: (values: Range) => Promise<void>;
|
|
43
52
|
};
|
|
44
53
|
/**
|
|
45
54
|
* Create a store wrapper around a d3-scale which interpolates the domain and/or range using `tweened()` or `spring()` stores. Fallbacks to `writable()` store if not interpolating
|
|
46
55
|
*/
|
|
47
|
-
export declare function motionScale(scale:
|
|
56
|
+
export declare function motionScale<Domain, Range>(scale: AnyScale, options: MotionOptions): {
|
|
48
57
|
subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: import("svelte/store").Invalidator<any> | undefined) => import("svelte/store").Unsubscriber;
|
|
49
|
-
domain: (values:
|
|
50
|
-
range: (values:
|
|
58
|
+
domain: (values: Domain) => void | Promise<void>;
|
|
59
|
+
range: (values: Range) => void | Promise<void>;
|
|
51
60
|
};
|
package/dist/utils/scales.js
CHANGED
|
@@ -35,7 +35,7 @@ export function scaleInvert(scale, value) {
|
|
|
35
35
|
return scaleBandInvert(scale)(value);
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
|
-
return scale.invert(value);
|
|
38
|
+
return scale.invert?.(value);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
/** Create a `scaleBand()` within another scaleBand()'s bandwidth (typically a x1 of an x0 scale, used for grouping) */
|
|
@@ -82,6 +82,7 @@ export function springScale(scale, springOptions = {}) {
|
|
|
82
82
|
const domainStore = spring(undefined, springOptions);
|
|
83
83
|
const rangeStore = spring(undefined, springOptions);
|
|
84
84
|
const tweenedScale = derived([domainStore, rangeStore], ([domain, range]) => {
|
|
85
|
+
// @ts-expect-error
|
|
85
86
|
const scaleInstance = scale.domain ? scale : scale(); // support `scaleLinear` or `scaleLinear()` (which could have `.interpolate()` and others set)
|
|
86
87
|
if (domain) {
|
|
87
88
|
scaleInstance.domain(domain);
|
|
@@ -104,6 +105,7 @@ export function motionScale(scale, options) {
|
|
|
104
105
|
const domainStore = motionStore(undefined, options);
|
|
105
106
|
const rangeStore = motionStore(undefined, options);
|
|
106
107
|
const tweenedScale = derived([domainStore, rangeStore], ([domain, range]) => {
|
|
108
|
+
// @ts-expect-error
|
|
107
109
|
const scaleInstance = scale.domain ? scale : scale(); // support `scaleLinear` or `scaleLinear()` (which could have `.interpolate()` and others set)
|
|
108
110
|
if (domain) {
|
|
109
111
|
scaleInstance.domain(domain);
|
package/dist/utils/stack.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { stackOffsetNone, stackOrderNone } from 'd3-shape';
|
|
2
2
|
type OrderType = typeof stackOrderNone;
|
|
3
3
|
type OffsetType = typeof stackOffsetNone;
|
|
4
|
-
export declare function createStackData(data:
|
|
4
|
+
export declare function createStackData<TData>(data: TData[], options: {
|
|
5
5
|
xKey: string;
|
|
6
6
|
groupBy?: string;
|
|
7
7
|
stackBy?: string;
|
|
8
8
|
order?: OrderType;
|
|
9
9
|
offset?: OffsetType;
|
|
10
|
-
}):
|
|
10
|
+
}): {
|
|
11
|
+
keys: (string | number)[];
|
|
12
|
+
values: number[];
|
|
13
|
+
}[];
|
|
11
14
|
/**
|
|
12
15
|
* Function to offset each layer by the maximum of the previous layer
|
|
13
16
|
* - see: https://observablehq.com/@mkfreeman/separated-bar-chart
|
package/dist/utils/stack.js
CHANGED
|
@@ -4,16 +4,21 @@ import { pivotWider } from './pivot.js';
|
|
|
4
4
|
export function createStackData(data, options) {
|
|
5
5
|
if (options.groupBy) {
|
|
6
6
|
// Group then Stack (if needed)
|
|
7
|
-
const groupedData = flatGroup(data,
|
|
7
|
+
const groupedData = flatGroup(data,
|
|
8
|
+
// @ts-expect-error
|
|
9
|
+
(d) => d[options.xKey],
|
|
10
|
+
// @ts-expect-error
|
|
11
|
+
(d) => d[options.groupBy ?? '']);
|
|
8
12
|
const result = groupedData.flatMap((d, i) => {
|
|
9
13
|
const groupKeys = d.slice(0, -1); // all but last item
|
|
10
14
|
const itemData = d.slice(-1)[0]; // last item
|
|
11
|
-
const pivotData = pivotWider(itemData, options.xKey, options.stackBy, 'value');
|
|
12
|
-
const stackKeys = [
|
|
15
|
+
const pivotData = pivotWider(itemData, options.xKey, options.stackBy ?? '', 'value');
|
|
16
|
+
const stackKeys = [
|
|
17
|
+
...new Set(itemData.map((d) => d[options.stackBy ?? ''])),
|
|
18
|
+
];
|
|
19
|
+
// @ts-expect-error
|
|
13
20
|
const stackData = stack().keys(stackKeys).order(options.order).offset(options.offset)(pivotData);
|
|
14
|
-
//console.log({ pivotData, stackData })
|
|
15
21
|
return stackData.flatMap((series) => {
|
|
16
|
-
//console.log({ series })
|
|
17
22
|
return series.flatMap((s) => {
|
|
18
23
|
return {
|
|
19
24
|
...itemData[0], // TODO: More than one should use stacks or aggregate values?
|
|
@@ -28,7 +33,9 @@ export function createStackData(data, options) {
|
|
|
28
33
|
else if (options.stackBy) {
|
|
29
34
|
// Stack only
|
|
30
35
|
const pivotData = pivotWider(data, options.xKey, options.stackBy, 'value');
|
|
31
|
-
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
const stackKeys = [...new Set(data.map((d) => d[options.stackBy ?? '']))];
|
|
38
|
+
// @ts-expect-error
|
|
32
39
|
const stackData = stack().keys(stackKeys).order(options.order).offset(options.offset)(pivotData);
|
|
33
40
|
const result = stackData.flatMap((series) => {
|
|
34
41
|
return series.flatMap((s) => {
|
|
@@ -45,10 +52,14 @@ export function createStackData(data, options) {
|
|
|
45
52
|
// No grouping or stacking. Aggregate based on `xKey`
|
|
46
53
|
return Array.from(rollup(data, (items) => {
|
|
47
54
|
return {
|
|
55
|
+
// @ts-expect-error
|
|
48
56
|
keys: [items[0][options.xKey]],
|
|
57
|
+
// @ts-expect-error
|
|
49
58
|
values: [0, sum(items, (d) => d.value)],
|
|
50
59
|
};
|
|
51
|
-
},
|
|
60
|
+
},
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
(d) => d[options.xKey]).values());
|
|
52
63
|
}
|
|
53
64
|
}
|
|
54
65
|
/**
|
|
@@ -56,6 +67,7 @@ export function createStackData(data, options) {
|
|
|
56
67
|
* - see: https://observablehq.com/@mkfreeman/separated-bar-chart
|
|
57
68
|
*/
|
|
58
69
|
// TODO: Try to find way to support separated with createStackData() (which has isolated stacked per group)
|
|
70
|
+
// @ts-expect-error
|
|
59
71
|
export function stackOffsetSeparated(series, order) {
|
|
60
72
|
const gap = 200; // TODO: Determine way to pass in as option (curry?)
|
|
61
73
|
if (!((n = series.length) > 1))
|
|
@@ -63,6 +75,7 @@ export function stackOffsetSeparated(series, order) {
|
|
|
63
75
|
// Standard series
|
|
64
76
|
for (var i = 1, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
|
|
65
77
|
(s0 = s1), (s1 = series[order[i]]);
|
|
78
|
+
// @ts-expect-error
|
|
66
79
|
let base = max(s0, (d) => d[1]) + gap; // here is where you calculate the maximum of the previous layer
|
|
67
80
|
for (var j = 0; j < m; ++j) {
|
|
68
81
|
// Set the height based on the data values, shifted up by the previous layer
|
package/dist/utils/threshold.js
CHANGED
|
@@ -6,6 +6,7 @@ import { scaleTime } from 'd3-scale';
|
|
|
6
6
|
*/
|
|
7
7
|
export function thresholdTime(n) {
|
|
8
8
|
// TODO: Unable to satisfy `ThresholdNumberArrayGenerator<Value extends number>` with `Date`
|
|
9
|
+
// @ts-expect-error
|
|
9
10
|
return (data, min, max) => {
|
|
10
11
|
return scaleTime().domain([min, max]).ticks(n);
|
|
11
12
|
};
|
package/dist/utils/treemap.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import type { HierarchyNode, HierarchyRectangularNode } from 'd3-hierarchy';
|
|
2
|
+
type TileFunc = (node: HierarchyRectangularNode<any>, x0: number, y0: number, x1: number, y1: number) => void;
|
|
1
3
|
/**
|
|
2
4
|
* This custom tiling function adapts the tiling function
|
|
3
5
|
* for the appropriate aspect ratio when the treemap is zoomed-in.
|
|
4
6
|
* see: https://observablehq.com/@d3/zoomable-treemap#tile and https://observablehq.com/@d3/stretched-treemap
|
|
5
7
|
*/
|
|
6
|
-
export declare function aspectTile(tile:
|
|
8
|
+
export declare function aspectTile(tile: TileFunc, width: number, height: number): TileFunc;
|
|
7
9
|
/**
|
|
8
10
|
* Show if the node (a) is a child of the selected (b), or any parent above selected
|
|
9
11
|
*/
|
|
10
|
-
export declare function isNodeVisible(a: any
|
|
12
|
+
export declare function isNodeVisible(a: HierarchyNode<any>, b: HierarchyNode<any> | null): boolean;
|
|
13
|
+
export {};
|
package/dist/utils/treemap.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export function aspectTile(tile, width, height) {
|
|
7
7
|
return (node, x0, y0, x1, y1) => {
|
|
8
8
|
tile(node, 0, 0, width, height);
|
|
9
|
-
for (const child of node.children) {
|
|
9
|
+
for (const child of node.children ?? []) {
|
|
10
10
|
child.x0 = x0 + (child.x0 / width) * (x1 - x0);
|
|
11
11
|
child.x1 = x0 + (child.x1 / width) * (x1 - x0);
|
|
12
12
|
child.y0 = y0 + (child.y0 / height) * (y1 - y0);
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"author": "Sean Lynch <techniq35@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "techniq/layerchart",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.43.0",
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@changesets/cli": "^2.27.5",
|
|
10
10
|
"@mdi/js": "^7.4.47",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
|
|
17
17
|
"@tailwindcss/typography": "^0.5.13",
|
|
18
18
|
"@types/d3-array": "^3.2.1",
|
|
19
|
+
"@types/d3-color": "^3.1.3",
|
|
19
20
|
"@types/d3-delaunay": "^6.0.4",
|
|
20
21
|
"@types/d3-dsv": "^3.0.7",
|
|
21
22
|
"@types/d3-force": "^3.0.10",
|
|
@@ -23,6 +24,7 @@
|
|
|
23
24
|
"@types/d3-hierarchy": "^3.1.7",
|
|
24
25
|
"@types/d3-interpolate": "^3.0.4",
|
|
25
26
|
"@types/d3-interpolate-path": "^2.0.3",
|
|
27
|
+
"@types/d3-path": "^3.1.0",
|
|
26
28
|
"@types/d3-quadtree": "^3.0.6",
|
|
27
29
|
"@types/d3-random": "^3.0.3",
|
|
28
30
|
"@types/d3-sankey": "^0.12.4",
|
|
@@ -35,6 +37,7 @@
|
|
|
35
37
|
"@types/shapefile": "^0.6.4",
|
|
36
38
|
"@types/topojson-client": "^3.1.4",
|
|
37
39
|
"@types/topojson-simplify": "^3.0.3",
|
|
40
|
+
"@types/topojson-specification": "^1.0.5",
|
|
38
41
|
"autoprefixer": "^10.4.19",
|
|
39
42
|
"marked": "^13.0.0",
|
|
40
43
|
"mdsvex": "^0.11.2",
|
|
@@ -85,9 +88,9 @@
|
|
|
85
88
|
"date-fns": "^3.6.0",
|
|
86
89
|
"layercake": "^8.3.0",
|
|
87
90
|
"lodash-es": "^4.17.21",
|
|
88
|
-
"posthog-js": "^1.
|
|
91
|
+
"posthog-js": "^1.140.1",
|
|
89
92
|
"shapefile": "^0.6.6",
|
|
90
|
-
"svelte-ux": "^0.
|
|
93
|
+
"svelte-ux": "^0.71.1",
|
|
91
94
|
"topojson-client": "^3.1.0"
|
|
92
95
|
},
|
|
93
96
|
"peerDependencies": {
|