layerchart 0.42.0 → 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 +71 -85
- 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 +4 -3
- package/dist/components/ForceSimulation.svelte.d.ts +1 -2
- 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 +5 -2
|
@@ -16,31 +16,15 @@ export const Svg = _Svg;
|
|
|
16
16
|
export const WebGL = _WebGL;
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
|
-
<script>import {
|
|
19
|
+
<script generics="TData">import { accessor } from '../index.js/utils/common.js';
|
|
20
|
+
import { onMount } from 'svelte';
|
|
20
21
|
import { max, min } from 'd3-array';
|
|
21
|
-
import { get } from 'lodash-es';
|
|
22
22
|
import { isScaleBand } from '../utils/scales.js';
|
|
23
|
+
import ChartContext from './ChartContext.svelte';
|
|
23
24
|
import GeoContext from './GeoContext.svelte';
|
|
24
25
|
import TooltipContext from './TooltipContext.svelte';
|
|
25
26
|
import TransformContext from './TransformContext.svelte';
|
|
26
27
|
import { geoFitObjectTransform } from '../utils/geo.js';
|
|
27
|
-
/**
|
|
28
|
-
* Resolve a value from data based on the accessor type
|
|
29
|
-
*/
|
|
30
|
-
function getValue(accessor, d) {
|
|
31
|
-
if (Array.isArray(accessor)) {
|
|
32
|
-
return accessor.map((a) => getValue(a, d));
|
|
33
|
-
}
|
|
34
|
-
else if (typeof accessor === 'function') {
|
|
35
|
-
return accessor(d) || 0;
|
|
36
|
-
}
|
|
37
|
-
else if (typeof accessor === 'string') {
|
|
38
|
-
return get(d, accessor);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
throw new Error('Unexpected accessor: ' + accessor);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
28
|
export let data = [];
|
|
45
29
|
export let x = undefined;
|
|
46
30
|
export let y = undefined;
|
|
@@ -50,8 +34,8 @@ export let yScale = undefined;
|
|
|
50
34
|
*/
|
|
51
35
|
export let xBaseline = null;
|
|
52
36
|
let xDomain = undefined;
|
|
53
|
-
$: if (xBaseline != null) {
|
|
54
|
-
const xValues = data.flatMap((
|
|
37
|
+
$: if (xBaseline != null && Array.isArray(data)) {
|
|
38
|
+
const xValues = data.flatMap(accessor(x));
|
|
55
39
|
xDomain = [min([xBaseline, ...xValues]), max([xBaseline, ...xValues])];
|
|
56
40
|
}
|
|
57
41
|
/**
|
|
@@ -59,8 +43,8 @@ $: if (xBaseline != null) {
|
|
|
59
43
|
*/
|
|
60
44
|
export let yBaseline = null;
|
|
61
45
|
let yDomain = undefined;
|
|
62
|
-
$: if (yBaseline != null) {
|
|
63
|
-
const yValues = data.flatMap((
|
|
46
|
+
$: if (yBaseline != null && Array.isArray(data)) {
|
|
47
|
+
const yValues = data.flatMap(accessor(y));
|
|
64
48
|
yDomain = [min([yBaseline, ...yValues]), max([yBaseline, ...yValues])];
|
|
65
49
|
}
|
|
66
50
|
/**
|
|
@@ -75,6 +59,7 @@ export let geo = undefined;
|
|
|
75
59
|
export let tooltip = undefined;
|
|
76
60
|
/** Props passed to TransformContext */
|
|
77
61
|
export let transform = undefined;
|
|
62
|
+
// @ts-expect-error will only be undefined until bind:transformContext runs
|
|
78
63
|
export let transformContext = undefined;
|
|
79
64
|
// Binded for access within TransformContext
|
|
80
65
|
let geoProjection = undefined;
|
|
@@ -110,8 +95,6 @@ onMount(() => {
|
|
|
110
95
|
let:rScale
|
|
111
96
|
let:rGet
|
|
112
97
|
let:padding
|
|
113
|
-
let:data
|
|
114
|
-
let:flatData
|
|
115
98
|
>
|
|
116
99
|
<!-- Apply `fitGeojson` using TransformContext instead of GeoContext if `applyTransform` is used -->
|
|
117
100
|
{@const initialTransform =
|
|
@@ -119,65 +102,68 @@ onMount(() => {
|
|
|
119
102
|
? geoFitObjectTransform(geo.projection(), [width, height], geo.fitGeojson)
|
|
120
103
|
: undefined}
|
|
121
104
|
|
|
122
|
-
{
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
105
|
+
<ChartContext {data} let:data let:flatData>
|
|
106
|
+
{#key isMounted}
|
|
107
|
+
<TransformContext
|
|
108
|
+
bind:this={transformContext}
|
|
109
|
+
mode={transform?.mode ?? geo?.applyTransform?.length ? 'manual' : 'none'}
|
|
110
|
+
initialTranslate={initialTransform?.translate}
|
|
111
|
+
initialScale={initialTransform?.scale}
|
|
112
|
+
processTranslate={geo
|
|
113
|
+
? (x, y, deltaX, deltaY, scale) => {
|
|
114
|
+
if (geo.applyTransform?.includes('rotate')) {
|
|
115
|
+
// When applying transform to rotate, invert `y` values and reduce sensitivity based on projection scale
|
|
116
|
+
// see: https://observablehq.com/@benoldenburg/simple-globe and https://observablehq.com/@michael-keith/draggable-globe-in-d3
|
|
117
|
+
// @ts-expect-error
|
|
118
|
+
const projectionScale = $geoProjection.scale();
|
|
119
|
+
const sensitivity = 75;
|
|
120
|
+
return {
|
|
121
|
+
x: x + deltaX * (sensitivity / projectionScale),
|
|
122
|
+
y: y + deltaY * (sensitivity / projectionScale) * -1,
|
|
123
|
+
};
|
|
124
|
+
} else if (geo.applyTransform?.includes('translate')) {
|
|
125
|
+
// When applying to `translate`, use pointer values as is (with no `scale` adjustment)
|
|
126
|
+
return { x: x + deltaX, y: y + deltaY };
|
|
127
|
+
} else {
|
|
128
|
+
// Apply default TransformContext.processTransform (passing `undefined` below appears to not work when checking for `geo?.applyTransform` exists)
|
|
129
|
+
return { x: x + deltaX / scale, y: y + deltaY / scale };
|
|
130
|
+
}
|
|
145
131
|
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
</
|
|
180
|
-
</
|
|
181
|
-
|
|
182
|
-
|
|
132
|
+
: undefined}
|
|
133
|
+
{...transform}
|
|
134
|
+
let:transform={_transform}
|
|
135
|
+
on:transform
|
|
136
|
+
on:dragstart
|
|
137
|
+
on:dragend
|
|
138
|
+
>
|
|
139
|
+
<GeoContext {...geo} bind:geo={geoProjection} let:projection>
|
|
140
|
+
{@const tooltipProps = typeof tooltip === 'object' ? tooltip : {}}
|
|
141
|
+
<TooltipContext {...tooltipProps} let:tooltip>
|
|
142
|
+
<slot
|
|
143
|
+
{aspectRatio}
|
|
144
|
+
{containerHeight}
|
|
145
|
+
{containerWidth}
|
|
146
|
+
{height}
|
|
147
|
+
{width}
|
|
148
|
+
{element}
|
|
149
|
+
{projection}
|
|
150
|
+
transform={_transform}
|
|
151
|
+
{tooltip}
|
|
152
|
+
{xScale}
|
|
153
|
+
{xGet}
|
|
154
|
+
{yScale}
|
|
155
|
+
{yGet}
|
|
156
|
+
{zScale}
|
|
157
|
+
{zGet}
|
|
158
|
+
{rScale}
|
|
159
|
+
{rGet}
|
|
160
|
+
{padding}
|
|
161
|
+
{data}
|
|
162
|
+
{flatData}
|
|
163
|
+
/>
|
|
164
|
+
</TooltipContext>
|
|
165
|
+
</GeoContext>
|
|
166
|
+
</TransformContext>
|
|
167
|
+
{/key}
|
|
168
|
+
</ChartContext>
|
|
183
169
|
</LayerCake>
|
|
@@ -7,25 +7,217 @@ export declare const Canvas: typeof _Canvas;
|
|
|
7
7
|
export declare const Html: typeof _Html;
|
|
8
8
|
export declare const Svg: typeof _Svg;
|
|
9
9
|
export declare const WebGL: typeof _WebGL;
|
|
10
|
-
import { type
|
|
11
|
-
import
|
|
12
|
-
import
|
|
10
|
+
import { type Accessor } from '../index.js/utils/common.js';
|
|
11
|
+
import type { HierarchyNode } from 'd3-hierarchy';
|
|
12
|
+
import type { SankeyGraph } from 'd3-sankey';
|
|
13
|
+
import { type AnyScale } from '../utils/scales.js';
|
|
13
14
|
import TransformContext from './TransformContext.svelte';
|
|
14
|
-
declare
|
|
15
|
-
props: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
declare class __sveltets_Render<TData> {
|
|
16
|
+
props(): {
|
|
17
|
+
/** Whether this chart should be rendered server side. @default false */
|
|
18
|
+
ssr?: boolean;
|
|
19
|
+
/** Whether to allow pointer events via CSS. Set this to `false` to set `pointer-events: none;` on all components, disabling all mouse interaction. @default true */
|
|
20
|
+
pointerEvents?: boolean;
|
|
21
|
+
/** Determine the positioning of the wrapper div. Set this to `'absolute'` when you want to stack cakes. @default 'relative' */
|
|
22
|
+
position?: string;
|
|
23
|
+
/** If `true`, set all scale ranges to `[0, 100]`. Ranges reversed via `xReverse`, `yReverse`, `zReverse` or `rReverse` props will continue to be reversed as usual. @default false */
|
|
24
|
+
percentRange?: boolean;
|
|
25
|
+
/** Override the automated width. */
|
|
26
|
+
width?: number;
|
|
27
|
+
/** Override the automated height. */
|
|
28
|
+
height?: number;
|
|
29
|
+
/** The bound container width. */
|
|
30
|
+
containerWidth?: number;
|
|
31
|
+
/**The bound container height. */
|
|
32
|
+
containerHeight?: number;
|
|
33
|
+
/** The .layercake-container `<div>` tag. Useful for bindings. */
|
|
34
|
+
element?: HTMLDivElement;
|
|
35
|
+
/** If `data` is not a flat array of objects and you want to use any of the scales, set a flat version of the data via the `flatData` prop. */
|
|
36
|
+
data?: SankeyGraph<any, any> | TData[] | HierarchyNode<TData> | undefined;
|
|
37
|
+
/** A flat version of data. */
|
|
38
|
+
flatData?: any[];
|
|
39
|
+
/** The x accessor. The key in each row of data that corresponds to the x-field. This can be a string, an accessor function, a number or an array of any combination of those types. This property gets converted to a function when you access it through the context. */
|
|
40
|
+
x?: Accessor<TData>;
|
|
41
|
+
/** The y accessor. The key in each row of data that corresponds to the y-field. This can be a string, an accessor function, a number or an array of any combination of those types. This property gets converted to a function when you access it through the context. */
|
|
42
|
+
y?: Accessor<TData>;
|
|
43
|
+
/** The z accessor. The key in each row of data that corresponds to the z-field. This can be a string, an accessor function, a number or an array of any combination of those types. This property gets converted to a function when you access it through the context. */
|
|
44
|
+
z?: Accessor<TData>;
|
|
45
|
+
/** The r accessor. The key in each row of data that corresponds to the r-field. This can be a string, an accessor function, a number or an array of any combination of those types. This property gets converted to a function when you access it through the context. */
|
|
46
|
+
r?: Accessor<TData>;
|
|
47
|
+
/** Set a min or max. For linear scales, if you want to inherit the value from the data's extent, set that value to `null`. This value can also be an array because sometimes your scales are [piecewise](https://github.com/d3/d3-scale#continuous_domain) or are a list of discrete values such as in [ordinal scales](https://github.com/d3/d3-scale#ordinal-scales), useful for color series. Set it to a function that receives the computed domain and lets you return a modified domain, useful for sorting values. */
|
|
48
|
+
xDomain?: Function | string[] | [number | Date | null, number | Date | null] | (number | null)[] | Date[] | null[] | null;
|
|
49
|
+
/** Set a min or max. For linear scales, if you want to inherit the value from the data's extent, set that value to `null`. Set it to a function that receives the computed domain and lets you return a modified domain, useful for sorting values. */
|
|
50
|
+
yDomain?: Function | string[] | [number | Date | null, number | Date | null] | (number | null)[] | Date[] | null[] | null;
|
|
51
|
+
/** Set a min or max. For linear scales, if you want to inherit the value from the data's extent, set that value to `null`. This value can also be an array because sometimes your scales are [piecewise](https://github.com/d3/d3-scale#continuous_domain) or are a list of discrete values such as in [ordinal scales](https://github.com/d3/d3-scale#ordinal-scales), useful for color series. Set it to a function that receives the computed domain and lets you return a modified domain, useful for sorting values. */
|
|
52
|
+
zDomain?: Function | string[] | [number | Date | null, number | Date | null] | (number | null)[] | Date[] | null[] | null;
|
|
53
|
+
/** Set a min or max. For linear scales, if you want to inherit the value from the data's extent, set that value to `null`. This value can also be an array because sometimes your scales are [piecewise](https://github.com/d3/d3-scale#continuous_domain) or are a list of discrete values such as in [ordinal scales](https://github.com/d3/d3-scale#ordinal-scales), useful for color series. Set it to a function that receives the computed domain and lets you return a modified domain, useful for sorting values. */
|
|
54
|
+
rDomain?: Function | string[] | [number | Date | null, number | Date | null] | (number | null)[] | Date[] | null[] | null;
|
|
55
|
+
/** Applies D3's [scale.nice()](https://github.com/d3/d3-scale#continuous_nice) to the x domain. @default false */
|
|
56
|
+
xNice?: boolean | number;
|
|
57
|
+
/** Applies D3's [scale.nice()](https://github.com/d3/d3-scale#continuous_nice) to the y domain. @default false */
|
|
58
|
+
yNice?: boolean | number;
|
|
59
|
+
/** Applies D3's [scale.nice()](https://github.com/d3/d3-scale#continuous_nice) to the z domain. @default false */
|
|
60
|
+
zNice?: boolean | number;
|
|
61
|
+
/** Applies D3's [scale.nice()](https://github.com/d3/d3-scale#continuous_nice) to the r domain. @default false */
|
|
62
|
+
rNice?: boolean | number;
|
|
63
|
+
/** @type Assign a pixel value to add to the min or max of the scale. This will increase the scales domain by the scale unit equivalent of the provided pixels. */
|
|
64
|
+
xPadding?: [number, number];
|
|
65
|
+
/** @type Assign a pixel value to add to the min or max of the scale. This will increase the scales domain by the scale unit equivalent of the provided pixels. */
|
|
66
|
+
yPadding?: [number, number];
|
|
67
|
+
/** @type Assign a pixel value to add to the min or max of the scale. This will increase the scales domain by the scale unit equivalent of the provided pixels. */
|
|
68
|
+
zPadding?: [number, number];
|
|
69
|
+
/** @type Assign a pixel value to add to the min or max of the scale. This will increase the scales domain by the scale unit equivalent of the provided pixels. */
|
|
70
|
+
rPadding?: [number, number];
|
|
71
|
+
/** @type {Function} [xScale=d3.scaleLinear] The D3 scale that should be used for the x-dimension. Pass in an instantiated D3 scale if you want to override the default or you want to extra options. */
|
|
72
|
+
xScale?: AnyScale;
|
|
73
|
+
/** @type {Function} [yScale=d3.scaleLinear] The D3 scale that should be used for the x-dimension. Pass in an instantiated D3 scale if you want to override the default or you want to extra options. */
|
|
74
|
+
yScale?: AnyScale;
|
|
75
|
+
/** @type {Function} [zScale=d3.scaleLinear] The D3 scale that should be used for the x-dimension. Pass in an instantiated D3 scale if you want to override the default or you want to extra options. */
|
|
76
|
+
zScale?: AnyScale;
|
|
77
|
+
/** @type {Function} [rScale=d3.scaleSqrt] The D3 scale that should be used for the x-dimension. Pass in an instantiated D3 scale if you want to override the default or you want to extra options. */
|
|
78
|
+
rScale?: AnyScale;
|
|
79
|
+
/** @type Override the default x range of `[0, width]` by setting an array or function with argument `({ width, height})` that returns an array. Setting this prop overrides `xReverse`. This can also be a list of numbers or strings for scales with discrete ranges like [scaleThreshhold](https://github.com/d3/d3-scale#threshold-scales) or [scaleQuantize](https://github.com/d3/d3-scale#quantize-scales). */
|
|
80
|
+
xRange?: string[] | number[] | ((args: {
|
|
81
|
+
width: number;
|
|
82
|
+
height: number;
|
|
83
|
+
}) => number[] | string[]) | undefined;
|
|
84
|
+
/** Override the default y range of `[0, height]` by setting an array or function with argument `({ width, height})` that returns an array. Setting this prop overrides `yReverse`. This can also be a list of numbers or strings for scales with discrete ranges like [scaleThreshhold](https://github.com/d3/d3-scale#threshold-scales) or [scaleQuantize](https://github.com/d3/d3-scale#quantize-scales). */
|
|
85
|
+
yRange?: string[] | number[] | ((args: {
|
|
86
|
+
width: number;
|
|
87
|
+
height: number;
|
|
88
|
+
}) => number[] | string[]) | undefined;
|
|
89
|
+
/** Override the default z range of `[0, width]` by setting an array or function with argument `({ width, height})` that returns an array. Setting this prop overrides `zReverse`. This can also be a list of numbers or strings for scales with discrete ranges like [scaleThreshhold](https://github.com/d3/d3-scale#threshold-scales) or [scaleQuantize](https://github.com/d3/d3-scale#quantize-scales). */
|
|
90
|
+
zRange?: string[] | number[] | ((args: {
|
|
91
|
+
width: number;
|
|
92
|
+
height: number;
|
|
93
|
+
}) => number[] | string[]) | undefined;
|
|
94
|
+
/** Override the default r range of `[1, 25]` by setting an array or function with argument `({ width, height})` that returns an array. Setting this prop overrides `rReverse`. This can also be a list of numbers or strings for scales with discrete ranges like [scaleThreshhold](https://github.com/d3/d3-scale#threshold-scales) or [scaleQuantize](https://github.com/d3/d3-scale#quantize-scales). */
|
|
95
|
+
rRange?: string[] | number[] | ((args: {
|
|
96
|
+
width: number;
|
|
97
|
+
height: number;
|
|
98
|
+
}) => number[] | string[]) | undefined;
|
|
99
|
+
/** Reverse the default x range. By default this is `false` and the range is `[0, width]`. Ignored if you set the xRange prop. @default false */
|
|
100
|
+
xReverse?: boolean;
|
|
101
|
+
/** Reverse the default y range. By default this is `true` and the range is `[height, 0]` unless using an ordinal scale with a `.bandwidth` method for `yScale`. Ignored if you set the `yRange` prop. @default true */
|
|
102
|
+
yReverse?: boolean;
|
|
103
|
+
/** @type {Boolean} [zReverse=false] Reverse the default z range. By default this is `false` and the range is `[0, width]`. Ignored if you set the zRange prop. @default false */
|
|
104
|
+
zReverse?: boolean;
|
|
105
|
+
/** @type {Boolean} [rReverse=false] Reverse the default r range. By default this is `false` and the range is `[1, 25]`. Ignored if you set the rRange prop. @default false */
|
|
106
|
+
rReverse?: boolean;
|
|
107
|
+
/** @type {Boolean} [xDomainSort=true] Only used when scale is ordinal. Set whether the calculated unique items come back sorted. */
|
|
108
|
+
xDomainSort?: boolean;
|
|
109
|
+
/** @type {Boolean} [yDomainSort=true] Only used when scale is ordinal. Set whether the calculated unique items come back sorted. */
|
|
110
|
+
yDomainSort?: boolean;
|
|
111
|
+
/** @type {Boolean} [zDomainSort=true] Only used when scale is ordinal. Set whether the calculated unique items come back sorted. */
|
|
112
|
+
zDomainSort?: boolean;
|
|
113
|
+
/** @type {Boolean} [rDomainSort=true] Only used when scale is ordinal. Set whether the calculated unique items come back sorted. */
|
|
114
|
+
rDomainSort?: boolean;
|
|
115
|
+
/** The amount of padding to put around your chart. It operates like CSS box-sizing: border-box; where values are subtracted from the parent container's width and height, the same as a [D3 margin convention](https://bl.ocks.org/mbostock/3019563). */
|
|
116
|
+
padding?: {
|
|
117
|
+
top?: Number;
|
|
118
|
+
right?: Number;
|
|
119
|
+
bottom?: Number;
|
|
120
|
+
left?: Number;
|
|
121
|
+
} | undefined;
|
|
122
|
+
/** Manually set the extents of the x, y or r scale as a two-dimensional array of the min and max you want. Setting values here will skip any dynamic extent calculation of the data for that dimension. */
|
|
123
|
+
extents?: {
|
|
124
|
+
x?: [min: Number, max: Number];
|
|
125
|
+
y?: [min: Number, max: Number];
|
|
126
|
+
r?: [min: Number, max: Number];
|
|
127
|
+
z?: [min: Number, max: Number];
|
|
128
|
+
} | undefined;
|
|
129
|
+
/** Any extra configuration values you want available on the LayerCake context. This could be useful for color lookups or additional constants. */
|
|
130
|
+
custom?: Record<string, any>;
|
|
131
|
+
/** @type {Boolean} debug Enable debug printing to the console. Useful to inspect your scales and dimensions. */
|
|
132
|
+
debug?: boolean;
|
|
133
|
+
/** @type {Boolean} [verbose=true] Show warnings in the console. */
|
|
134
|
+
verbose?: boolean;
|
|
135
|
+
/** x value guaranteed to be visible in xDomain. Useful with optional negative values since `xDomain={[0, null]}` would ignore negative values */
|
|
21
136
|
xBaseline?: number | null;
|
|
137
|
+
/** y value guaranteed to be visible in yDomain. Useful with optional negative values since `yDomain={[0, null]}` would ignore negative values */
|
|
22
138
|
yBaseline?: number | null;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
139
|
+
/** Props passed to GeoContext */
|
|
140
|
+
geo?: Partial<{
|
|
141
|
+
projection?: (() => import("d3-geo").GeoProjection) | undefined;
|
|
142
|
+
fitGeojson?: import("d3-geo").GeoPermissibleObjects | undefined;
|
|
143
|
+
fixedAspectRatio?: number | undefined;
|
|
144
|
+
clipAngle?: number | undefined;
|
|
145
|
+
clipExtent?: [[number, number], [number, number]] | undefined;
|
|
146
|
+
rotate?: {
|
|
147
|
+
yaw: number;
|
|
148
|
+
pitch: number;
|
|
149
|
+
roll: number;
|
|
150
|
+
} | undefined;
|
|
151
|
+
scale?: number | undefined;
|
|
152
|
+
translate?: [number, number] | undefined;
|
|
153
|
+
center?: [number, number] | undefined;
|
|
154
|
+
applyTransform?: ("scale" | "translate" | "rotate")[];
|
|
155
|
+
reflectX?: boolean | undefined;
|
|
156
|
+
reflectY?: boolean | undefined;
|
|
157
|
+
geo?: import("svelte/store").Writable<import("d3-geo").GeoProjection>;
|
|
158
|
+
}> | undefined;
|
|
159
|
+
/** Props passed to TooltipContext */
|
|
160
|
+
tooltip?: boolean | Partial<{
|
|
161
|
+
mode?: "bisect-x" | "bisect-y" | "band" | "bisect-band" | "bounds" | "voronoi" | "quadtree" | "manual";
|
|
162
|
+
findTooltipData?: "closest" | "left" | "right";
|
|
163
|
+
raiseTarget?: boolean;
|
|
164
|
+
radius?: number;
|
|
165
|
+
debug?: boolean;
|
|
166
|
+
onClick?: ({ data }: {
|
|
167
|
+
data: any;
|
|
168
|
+
}) => any;
|
|
169
|
+
}> | undefined;
|
|
170
|
+
/** Props passed to TransformContext */
|
|
171
|
+
transform?: Partial<{
|
|
172
|
+
mode?: "none" | "canvas" | "manual";
|
|
173
|
+
translateOnScale?: boolean;
|
|
174
|
+
spring?: boolean | Parameters<typeof import("../stores/motionStore").motionStore>[1]["spring"];
|
|
175
|
+
tweened?: boolean | Parameters<typeof import("../stores/motionStore").motionStore>[1]["tweened"];
|
|
176
|
+
processTranslate?: (x: number, y: number, deltaX: number, deltaY: number, scale: number) => {
|
|
177
|
+
x: number;
|
|
178
|
+
y: number;
|
|
179
|
+
};
|
|
180
|
+
disablePointer?: boolean;
|
|
181
|
+
initialScrollMode?: "none" | "scale" | "translate";
|
|
182
|
+
clickDistance?: number;
|
|
183
|
+
initialTranslate?: {
|
|
184
|
+
x: number;
|
|
185
|
+
y: number;
|
|
186
|
+
} | undefined;
|
|
187
|
+
translate?: import("svelte/motion").Spring<{
|
|
188
|
+
x: number;
|
|
189
|
+
y: number;
|
|
190
|
+
}> | import("svelte/motion").Tweened<{
|
|
191
|
+
x: number;
|
|
192
|
+
y: number;
|
|
193
|
+
}> | import("svelte/store").Writable<{
|
|
194
|
+
x: number;
|
|
195
|
+
y: number;
|
|
196
|
+
}>;
|
|
197
|
+
initialScale?: number | undefined;
|
|
198
|
+
scale?: import("svelte/motion").Spring<number> | import("svelte/motion").Tweened<number> | import("svelte/store").Writable<number>;
|
|
199
|
+
setScrollMode?: (mode: "none" | "scale" | "translate") => void;
|
|
200
|
+
reset?: () => void;
|
|
201
|
+
zoomIn?: () => void;
|
|
202
|
+
zoomOut?: () => void;
|
|
203
|
+
translateCenter?: () => void;
|
|
204
|
+
zoomTo?: (center: {
|
|
205
|
+
x: number;
|
|
206
|
+
y: number;
|
|
207
|
+
}, rect?: {
|
|
208
|
+
width: number;
|
|
209
|
+
height: number;
|
|
210
|
+
}) => void;
|
|
211
|
+
setTranslate?: (point: {
|
|
212
|
+
x: number;
|
|
213
|
+
y: number;
|
|
214
|
+
}, options?: import("../stores/motionStore").MotionOptions) => void;
|
|
215
|
+
setScale?: (value: number, options?: import("../stores/motionStore").MotionOptions) => void;
|
|
216
|
+
}> | undefined;
|
|
217
|
+
/** Expose to support `bind:transformContext` for imperative control (`transformContext.translate(...)`) */
|
|
26
218
|
transformContext?: TransformContext;
|
|
27
219
|
};
|
|
28
|
-
events: {
|
|
220
|
+
events(): {
|
|
29
221
|
transform: CustomEvent<{
|
|
30
222
|
scale: number;
|
|
31
223
|
translate: {
|
|
@@ -38,7 +230,7 @@ declare const __propDef: {
|
|
|
38
230
|
} & {
|
|
39
231
|
[evt: string]: CustomEvent<any>;
|
|
40
232
|
};
|
|
41
|
-
slots: {
|
|
233
|
+
slots(): {
|
|
42
234
|
default: {
|
|
43
235
|
aspectRatio: number;
|
|
44
236
|
containerHeight: number;
|
|
@@ -46,7 +238,7 @@ declare const __propDef: {
|
|
|
46
238
|
height: number;
|
|
47
239
|
width: number;
|
|
48
240
|
element: Element;
|
|
49
|
-
projection: import("d3-geo").GeoProjection
|
|
241
|
+
projection: import("d3-geo").GeoProjection;
|
|
50
242
|
transform: {
|
|
51
243
|
scale: number;
|
|
52
244
|
setScale: (value: number, options?: import("../stores/motionStore").MotionOptions) => void;
|
|
@@ -70,7 +262,7 @@ declare const __propDef: {
|
|
|
70
262
|
tooltip: {
|
|
71
263
|
y: number;
|
|
72
264
|
x: number;
|
|
73
|
-
data:
|
|
265
|
+
data: any;
|
|
74
266
|
show: (e: PointerEvent, tooltipData?: any) => void;
|
|
75
267
|
hide: () => void;
|
|
76
268
|
};
|
|
@@ -93,14 +285,14 @@ declare const __propDef: {
|
|
|
93
285
|
bottom?: number | undefined;
|
|
94
286
|
left?: number | undefined;
|
|
95
287
|
};
|
|
96
|
-
data:
|
|
97
|
-
flatData:
|
|
288
|
+
data: unknown[] | SankeyGraph<any, any> | HierarchyNode<unknown>;
|
|
289
|
+
flatData: import("svelte/store").Readable<unknown[] | HierarchyNode<unknown>>;
|
|
98
290
|
};
|
|
99
291
|
};
|
|
100
|
-
}
|
|
101
|
-
export type ChartProps =
|
|
102
|
-
export type ChartEvents =
|
|
103
|
-
export type ChartSlots =
|
|
104
|
-
export default class Chart extends SvelteComponentTyped<ChartProps
|
|
292
|
+
}
|
|
293
|
+
export type ChartProps<TData> = ReturnType<__sveltets_Render<TData>['props']>;
|
|
294
|
+
export type ChartEvents<TData> = ReturnType<__sveltets_Render<TData>['events']>;
|
|
295
|
+
export type ChartSlots<TData> = ReturnType<__sveltets_Render<TData>['slots']>;
|
|
296
|
+
export default class Chart<TData> extends SvelteComponentTyped<ChartProps<TData>, ChartEvents<TData>, ChartSlots<TData>> {
|
|
105
297
|
}
|
|
106
298
|
export {};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { chartContext } from './ChartContext.svelte';
|
|
2
2
|
import RectClipPath from './RectClipPath.svelte';
|
|
3
|
-
const { width, height, padding } =
|
|
3
|
+
const { width, height, padding } = chartContext();
|
|
4
4
|
/** Include padding area (ex. axis) */
|
|
5
5
|
export let full = false;
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<RectClipPath
|
|
9
|
-
x={full ? -$padding.left : 0}
|
|
10
|
-
y={full ? -$padding.top : 0}
|
|
11
|
-
width={$width + (full ? $padding
|
|
12
|
-
height={$height + (full ? $padding
|
|
9
|
+
x={full && $padding.left ? -$padding.left : 0}
|
|
10
|
+
y={full && $padding.top ? -$padding.top : 0}
|
|
11
|
+
width={$width + (full ? ($padding?.left ?? 0) + ($padding?.right ?? 0) : 0)}
|
|
12
|
+
height={$height + (full ? ($padding?.top ?? 0) + ($padding?.bottom ?? 0) : 0)}
|
|
13
13
|
on:click
|
|
14
14
|
{...$$restProps}
|
|
15
15
|
>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!-- Wrapper to allow getting LayerCake context from <Chart> and exposing with a strongly type context getter -->
|
|
2
|
+
<script context="module">import { getContext, setContext } from 'svelte';
|
|
3
|
+
import {} from 'svelte/store';
|
|
4
|
+
export const chartContextKey = Symbol();
|
|
5
|
+
export function chartContext() {
|
|
6
|
+
return getContext(chartContextKey);
|
|
7
|
+
}
|
|
8
|
+
function setChartContext(context) {
|
|
9
|
+
setContext(chartContextKey, context);
|
|
10
|
+
}
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<script generics="TData">const layerCakeContext = getContext('LayerCake');
|
|
14
|
+
setChartContext(layerCakeContext);
|
|
15
|
+
// Added to try to pass TData downward
|
|
16
|
+
export let data = []; // Same as `ComponentProps<Chart<TData>>` but causes circular reference
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<slot {data} flatData={layerCakeContext.data} />
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { AnyScale } from '../index.js/utils/scales.js';
|
|
3
|
+
import type { HierarchyNode } from 'd3-hierarchy';
|
|
4
|
+
import { type Readable } from 'svelte/store';
|
|
5
|
+
export declare const chartContextKey: unique symbol;
|
|
6
|
+
type LayerCakeContext<TData> = {
|
|
7
|
+
activeGetters: Readable<{
|
|
8
|
+
x: (d: TData) => any;
|
|
9
|
+
y: (d: TData) => any;
|
|
10
|
+
z: (d: TData) => any;
|
|
11
|
+
r: (d: TData) => any;
|
|
12
|
+
}>;
|
|
13
|
+
width: Readable<number>;
|
|
14
|
+
height: Readable<number>;
|
|
15
|
+
percentRange: Readable<boolean>;
|
|
16
|
+
aspectRatio: Readable<number>;
|
|
17
|
+
containerWidth: Readable<number>;
|
|
18
|
+
containerHeight: Readable<number>;
|
|
19
|
+
x: Readable<(d: TData) => any>;
|
|
20
|
+
y: Readable<(d: TData) => any>;
|
|
21
|
+
z: Readable<(d: TData) => any>;
|
|
22
|
+
r: Readable<(d: TData) => any>;
|
|
23
|
+
custom: Readable<Object>;
|
|
24
|
+
data: Readable<TData[] | HierarchyNode<TData>>;
|
|
25
|
+
xNice: Readable<number | boolean>;
|
|
26
|
+
yNice: Readable<number | boolean>;
|
|
27
|
+
zNice: Readable<number | boolean>;
|
|
28
|
+
rNice: Readable<number | boolean>;
|
|
29
|
+
xDomainSort: Readable<boolean>;
|
|
30
|
+
yDomainSort: Readable<boolean>;
|
|
31
|
+
zDomainSort: Readable<boolean>;
|
|
32
|
+
rDomainSort: Readable<boolean>;
|
|
33
|
+
xReverse: Readable<boolean>;
|
|
34
|
+
yReverse: Readable<boolean>;
|
|
35
|
+
zReverse: Readable<boolean>;
|
|
36
|
+
rReverse: Readable<boolean>;
|
|
37
|
+
xPadding: Readable<[number, number]>;
|
|
38
|
+
yPadding: Readable<[number, number]>;
|
|
39
|
+
zPadding: Readable<[number, number]>;
|
|
40
|
+
rPadding: Readable<[number, number]>;
|
|
41
|
+
padding: Readable<{
|
|
42
|
+
top: number;
|
|
43
|
+
bottom: number;
|
|
44
|
+
left: number;
|
|
45
|
+
right: number;
|
|
46
|
+
}>;
|
|
47
|
+
flatData: Readable<TData[]>;
|
|
48
|
+
extents: Readable<{}>;
|
|
49
|
+
xDomain: Readable<any>;
|
|
50
|
+
yDomain: Readable<any>;
|
|
51
|
+
zDomain: Readable<any>;
|
|
52
|
+
rDomain: Readable<any>;
|
|
53
|
+
xRange: Readable<any>;
|
|
54
|
+
yRange: Readable<any>;
|
|
55
|
+
zRange: Readable<any>;
|
|
56
|
+
rRange: Readable<any>;
|
|
57
|
+
config: Readable<any>;
|
|
58
|
+
xScale: Readable<AnyScale>;
|
|
59
|
+
xGet: Readable<any>;
|
|
60
|
+
yScale: Readable<AnyScale>;
|
|
61
|
+
yGet: Readable<any>;
|
|
62
|
+
zScale: Readable<AnyScale>;
|
|
63
|
+
zGet: Readable<any>;
|
|
64
|
+
rScale: Readable<AnyScale>;
|
|
65
|
+
rGet: Readable<any>;
|
|
66
|
+
};
|
|
67
|
+
export type ChartContext<TData> = LayerCakeContext<TData> & {};
|
|
68
|
+
export declare function chartContext<TData = any>(): ChartContext<TData>;
|
|
69
|
+
import type { SankeyGraph } from 'd3-sankey';
|
|
70
|
+
declare class __sveltets_Render<TData> {
|
|
71
|
+
props(): {
|
|
72
|
+
data?: SankeyGraph<any, any> | TData[] | HierarchyNode<TData> | undefined;
|
|
73
|
+
};
|
|
74
|
+
events(): {} & {
|
|
75
|
+
[evt: string]: CustomEvent<any>;
|
|
76
|
+
};
|
|
77
|
+
slots(): {
|
|
78
|
+
default: {
|
|
79
|
+
data: SankeyGraph<any, any> | TData[] | HierarchyNode<TData>;
|
|
80
|
+
flatData: Readable<TData[] | HierarchyNode<TData>>;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export type ChartContextProps<TData> = ReturnType<__sveltets_Render<TData>['props']>;
|
|
85
|
+
export type ChartContextEvents<TData> = ReturnType<__sveltets_Render<TData>['events']>;
|
|
86
|
+
export type ChartContextSlots<TData> = ReturnType<__sveltets_Render<TData>['slots']>;
|
|
87
|
+
export default class ChartContext<TData> extends SvelteComponentTyped<ChartContextProps<TData>, ChartContextEvents<TData>, ChartContextSlots<TData>> {
|
|
88
|
+
}
|
|
89
|
+
export {};
|
|
@@ -21,6 +21,7 @@ export let disabled = false;
|
|
|
21
21
|
{#if disabled}
|
|
22
22
|
<slot />
|
|
23
23
|
{:else}
|
|
24
|
+
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
24
25
|
<g style:clip-path="url(#{id})" on:click on:pointermove on:pointerleave on:keydown>
|
|
25
26
|
<slot {id} url="url(#{id})" {useId} />
|
|
26
27
|
</g>
|