layerchart 0.44.0 → 0.51.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 +18 -1
- package/dist/components/Arc.svelte.d.ts +3 -0
- package/dist/components/Area.svelte +49 -18
- package/dist/components/Area.svelte.d.ts +0 -1
- package/dist/components/Axis.svelte +2 -1
- package/dist/components/Axis.svelte.d.ts +2 -1
- package/dist/components/Bar.svelte +18 -8
- package/dist/components/Bar.svelte.d.ts +6 -3
- package/dist/components/Bars.svelte +18 -11
- package/dist/components/Bars.svelte.d.ts +3 -3
- package/dist/components/Blur.svelte +1 -1
- package/dist/components/Brush.svelte +2 -1
- package/dist/components/Calendar.svelte +2 -2
- package/dist/components/Calendar.svelte.d.ts +1 -1
- package/dist/components/Chart.svelte +85 -25
- package/dist/components/Chart.svelte.d.ts +77 -37
- package/dist/components/ChartContext.svelte +124 -6
- package/dist/components/ChartContext.svelte.d.ts +50 -2
- package/dist/components/Circle.svelte +1 -1
- package/dist/components/CircleClipPath.svelte +1 -1
- package/dist/components/ClipPath.svelte +1 -1
- package/dist/components/GeoPath.svelte +1 -1
- package/dist/components/GeoPath.svelte.d.ts +1 -1
- package/dist/components/Highlight.svelte +45 -19
- package/dist/components/Highlight.svelte.d.ts +2 -3
- package/dist/components/HitCanvas.svelte +1 -1
- package/dist/components/Hull.svelte +1 -1
- package/dist/components/Labels.svelte +39 -73
- package/dist/components/Labels.svelte.d.ts +2 -5
- package/dist/components/Legend.svelte +5 -5
- package/dist/components/Legend.svelte.d.ts +2 -2
- package/dist/components/Line.svelte +1 -1
- package/dist/components/LinearGradient.svelte +1 -1
- package/dist/components/MotionPath.svelte +1 -1
- package/dist/components/Pie.svelte +18 -41
- package/dist/components/Pie.svelte.d.ts +2 -3
- package/dist/components/Points.svelte +110 -56
- package/dist/components/Points.svelte.d.ts +20 -2
- package/dist/components/RadialGradient.svelte +1 -1
- package/dist/components/Rect.svelte +2 -1
- package/dist/components/Rect.svelte.d.ts +1 -0
- package/dist/components/RectClipPath.svelte +1 -1
- package/dist/components/Rule.svelte +1 -1
- package/dist/components/Spline.svelte +26 -18
- package/dist/components/Spline.svelte.d.ts +1 -1
- package/dist/components/Text.svelte +1 -1
- package/dist/components/Threshold.svelte +19 -81
- package/dist/components/Threshold.svelte.d.ts +13 -20
- package/dist/components/TransformContext.svelte.d.ts +2 -2
- package/dist/components/TransformControls.svelte +2 -1
- package/dist/components/TransformControls.svelte.d.ts +2 -2
- package/dist/components/Voronoi.svelte +15 -5
- package/dist/components/Voronoi.svelte.d.ts +6 -1
- package/dist/components/charts/AreaChart.svelte +182 -0
- package/dist/components/charts/AreaChart.svelte.d.ts +261 -0
- package/dist/components/charts/BarChart.svelte +207 -0
- package/dist/components/charts/BarChart.svelte.d.ts +241 -0
- package/dist/components/charts/LineChart.svelte +138 -0
- package/dist/components/charts/LineChart.svelte.d.ts +260 -0
- package/dist/components/charts/PieChart.svelte +146 -0
- package/dist/components/charts/PieChart.svelte.d.ts +220 -0
- package/dist/components/charts/ScatterChart.svelte +133 -0
- package/dist/components/charts/ScatterChart.svelte.d.ts +236 -0
- package/dist/components/charts/index.d.ts +5 -0
- package/dist/components/charts/index.js +5 -0
- package/dist/components/index.d.ts +2 -6
- package/dist/components/index.js +3 -6
- package/dist/components/layout/Canvas.svelte +1 -1
- package/dist/components/layout/Html.svelte +1 -1
- package/dist/components/layout/Svg.svelte +14 -4
- package/dist/components/layout/Svg.svelte.d.ts +1 -0
- package/dist/components/{Tooltip.svelte → tooltip/Tooltip.svelte} +5 -28
- package/dist/components/{Tooltip.svelte.d.ts → tooltip/Tooltip.svelte.d.ts} +1 -5
- package/dist/components/{TooltipContext.svelte → tooltip/TooltipContext.svelte} +20 -12
- package/dist/components/tooltip/TooltipHeader.svelte +21 -0
- package/dist/components/tooltip/TooltipHeader.svelte.d.ts +23 -0
- package/dist/components/tooltip/TooltipItem.svelte +37 -0
- package/dist/components/{TooltipItem.svelte.d.ts → tooltip/TooltipItem.svelte.d.ts} +4 -1
- package/dist/components/tooltip/TooltipList.svelte +12 -0
- package/dist/components/tooltip/TooltipList.svelte.d.ts +18 -0
- package/dist/components/tooltip/TooltipSeparator.svelte +4 -0
- package/dist/components/tooltip/index.d.ts +6 -0
- package/dist/components/tooltip/index.js +6 -0
- package/dist/docs/Blockquote.svelte +2 -1
- package/dist/docs/Code.svelte +2 -1
- package/dist/docs/CurveMenuField.svelte +2 -1
- package/dist/docs/GeoDebug.svelte +3 -1
- package/dist/docs/Json.svelte +1 -1
- package/dist/docs/Preview.svelte +2 -1
- package/dist/docs/TransformDebug.svelte +2 -1
- package/dist/utils/common.d.ts +1 -1
- package/dist/utils/common.js +2 -2
- package/dist/utils/common.test.d.ts +8 -0
- package/dist/utils/common.test.js +38 -0
- package/dist/utils/event.js +1 -1
- package/dist/utils/genData.d.ts +2 -2
- package/dist/utils/genData.js +20 -20
- package/dist/utils/math.d.ts +2 -2
- package/dist/utils/math.js +8 -2
- package/dist/utils/rect.d.ts +4 -10
- package/dist/utils/rect.js +15 -19
- package/dist/utils/scales.d.ts +8 -2
- package/dist/utils/scales.js +15 -1
- package/dist/utils/stack.d.ts +2 -2
- package/dist/utils/stack.js +37 -20
- package/dist/utils/stack.test.d.ts +6 -0
- package/dist/utils/stack.test.js +136 -0
- package/dist/utils/string.js +41 -0
- package/dist/utils/ticks.js +1 -2
- package/package.json +9 -3
- package/dist/components/AreaStack.svelte +0 -47
- package/dist/components/AreaStack.svelte.d.ts +0 -28
- package/dist/components/TooltipItem.svelte +0 -26
- package/dist/components/TooltipSeparator.svelte +0 -4
- /package/dist/components/{TooltipContext.svelte.d.ts → tooltip/TooltipContext.svelte.d.ts} +0 -0
- /package/dist/components/{TooltipSeparator.svelte.d.ts → tooltip/TooltipSeparator.svelte.d.ts} +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
<script generics="TData">import {} from 'svelte';
|
|
2
|
+
import { scaleLinear, scaleTime } from 'd3-scale';
|
|
3
|
+
import { format } from '@layerstack/utils';
|
|
4
|
+
import Axis from '../Axis.svelte';
|
|
5
|
+
import Chart from '../Chart.svelte';
|
|
6
|
+
import Highlight from '../Highlight.svelte';
|
|
7
|
+
import Labels from '../Labels.svelte';
|
|
8
|
+
import Points from '../Points.svelte';
|
|
9
|
+
import Svg from '../layout/Svg.svelte';
|
|
10
|
+
import * as Tooltip from '../tooltip/index.js';
|
|
11
|
+
import { accessor, chartDataArray } from '../../utils/common.js';
|
|
12
|
+
export let data = [];
|
|
13
|
+
export let x = undefined;
|
|
14
|
+
export let y = undefined;
|
|
15
|
+
export let series = [{ key: 'default', data: chartDataArray(data), color: 'hsl(var(--color-primary))' }];
|
|
16
|
+
export let axis = true;
|
|
17
|
+
export let labels = false;
|
|
18
|
+
// Default xScale based on first data's `x` value
|
|
19
|
+
$: xScale = accessor(x)(chartDataArray(data)[0]) instanceof Date ? scaleTime() : scaleLinear();
|
|
20
|
+
export let props = {};
|
|
21
|
+
let chartData = series
|
|
22
|
+
.flatMap((s) => s.data?.map((d) => ({ seriesKey: s.key, ...d })))
|
|
23
|
+
.filter((d) => d);
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<Chart
|
|
27
|
+
data={chartData}
|
|
28
|
+
{x}
|
|
29
|
+
{xScale}
|
|
30
|
+
{y}
|
|
31
|
+
yNice
|
|
32
|
+
padding={axis === false ? undefined : { left: 16, bottom: 16 }}
|
|
33
|
+
tooltip={{ mode: 'voronoi' }}
|
|
34
|
+
{...$$restProps}
|
|
35
|
+
let:x
|
|
36
|
+
let:xScale
|
|
37
|
+
let:y
|
|
38
|
+
let:yScale
|
|
39
|
+
let:r
|
|
40
|
+
let:width
|
|
41
|
+
let:height
|
|
42
|
+
let:padding
|
|
43
|
+
let:tooltip
|
|
44
|
+
let:config
|
|
45
|
+
>
|
|
46
|
+
{@const slotProps = { x, xScale, y, yScale, width, height, padding, tooltip, series }}
|
|
47
|
+
{@const activeSeries = tooltip.data
|
|
48
|
+
? (series.find((s) => s.key === tooltip.data.seriesKey) ?? series[0])
|
|
49
|
+
: null}
|
|
50
|
+
|
|
51
|
+
<slot {...slotProps}>
|
|
52
|
+
<Svg>
|
|
53
|
+
<slot name="axis" {...slotProps}>
|
|
54
|
+
{#if axis}
|
|
55
|
+
<Axis
|
|
56
|
+
placement="left"
|
|
57
|
+
grid
|
|
58
|
+
rule
|
|
59
|
+
format={(value) => format(value, undefined, { variant: 'short' })}
|
|
60
|
+
{...typeof axis === 'object' ? axis : null}
|
|
61
|
+
{...props.yAxis}
|
|
62
|
+
/>
|
|
63
|
+
<Axis
|
|
64
|
+
placement="bottom"
|
|
65
|
+
grid
|
|
66
|
+
rule
|
|
67
|
+
format={(value) => format(value, undefined, { variant: 'short' })}
|
|
68
|
+
{...typeof axis === 'object' ? axis : null}
|
|
69
|
+
{...props.xAxis}
|
|
70
|
+
/>
|
|
71
|
+
{/if}
|
|
72
|
+
</slot>
|
|
73
|
+
|
|
74
|
+
<slot name="below-marks" {...slotProps} />
|
|
75
|
+
|
|
76
|
+
<slot name="marks" {...slotProps}>
|
|
77
|
+
{#each series as s}
|
|
78
|
+
<Points
|
|
79
|
+
data={s.data}
|
|
80
|
+
stroke={s.color}
|
|
81
|
+
fill={s.color}
|
|
82
|
+
fill-opacity={0.3}
|
|
83
|
+
{...props.points}
|
|
84
|
+
{...s.props}
|
|
85
|
+
/>
|
|
86
|
+
{/each}
|
|
87
|
+
</slot>
|
|
88
|
+
|
|
89
|
+
<slot name="above-marks" {...slotProps} />
|
|
90
|
+
|
|
91
|
+
<slot name="highlight" {...slotProps}>
|
|
92
|
+
<Highlight points={{ fill: activeSeries?.color }} lines axis="both" {...props.highlight} />
|
|
93
|
+
</slot>
|
|
94
|
+
|
|
95
|
+
{#if labels}
|
|
96
|
+
<Labels
|
|
97
|
+
format={(value) => format(value)}
|
|
98
|
+
{...props.highlight}
|
|
99
|
+
{...typeof labels === 'object' ? labels : null}
|
|
100
|
+
/>
|
|
101
|
+
{/if}
|
|
102
|
+
</Svg>
|
|
103
|
+
|
|
104
|
+
<slot name="tooltip" {...slotProps}>
|
|
105
|
+
<Tooltip.Root let:data>
|
|
106
|
+
{#if activeSeries?.key !== 'default'}
|
|
107
|
+
<Tooltip.Header color={activeSeries?.color}>
|
|
108
|
+
{activeSeries?.label ?? activeSeries?.key}
|
|
109
|
+
</Tooltip.Header>
|
|
110
|
+
{/if}
|
|
111
|
+
<Tooltip.List>
|
|
112
|
+
<Tooltip.Item
|
|
113
|
+
label={typeof config.x === 'string' ? config.x : 'x'}
|
|
114
|
+
value={x(data)}
|
|
115
|
+
{format}
|
|
116
|
+
/>
|
|
117
|
+
<Tooltip.Item
|
|
118
|
+
label={typeof config.y === 'string' ? config.y : 'y'}
|
|
119
|
+
value={y(data)}
|
|
120
|
+
{format}
|
|
121
|
+
/>
|
|
122
|
+
{#if config.r}
|
|
123
|
+
<Tooltip.Item
|
|
124
|
+
label={typeof config.r === 'string' ? config.r : 'r'}
|
|
125
|
+
value={r(data)}
|
|
126
|
+
{format}
|
|
127
|
+
/>
|
|
128
|
+
{/if}
|
|
129
|
+
</Tooltip.List>
|
|
130
|
+
</Tooltip.Root>
|
|
131
|
+
</slot>
|
|
132
|
+
</slot>
|
|
133
|
+
</Chart>
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import { type ComponentProps } from 'svelte';
|
|
3
|
+
import Axis from '../Axis.svelte';
|
|
4
|
+
import Highlight from '../Highlight.svelte';
|
|
5
|
+
import Labels from '../Labels.svelte';
|
|
6
|
+
import Points from '../Points.svelte';
|
|
7
|
+
import { type Accessor } from '../../utils/common.js';
|
|
8
|
+
declare class __sveltets_Render<TData> {
|
|
9
|
+
props(): {
|
|
10
|
+
ssr?: boolean;
|
|
11
|
+
pointerEvents?: boolean;
|
|
12
|
+
position?: string;
|
|
13
|
+
percentRange?: boolean;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
containerWidth?: number;
|
|
17
|
+
containerHeight?: number;
|
|
18
|
+
element?: HTMLDivElement;
|
|
19
|
+
data?: import("d3-sankey").SankeyGraph<any, any> | import("d3-hierarchy").HierarchyNode<TData> | TData[] | undefined;
|
|
20
|
+
flatData?: any[];
|
|
21
|
+
x?: Accessor<TData>;
|
|
22
|
+
y?: Accessor<TData>;
|
|
23
|
+
z?: Accessor<TData>;
|
|
24
|
+
r?: Accessor<TData>;
|
|
25
|
+
x1?: Accessor<TData>;
|
|
26
|
+
y1?: Accessor<TData>;
|
|
27
|
+
c?: Accessor<TData>;
|
|
28
|
+
xDomain?: import("../../utils/scales").DomainType;
|
|
29
|
+
yDomain?: import("../../utils/scales").DomainType;
|
|
30
|
+
zDomain?: import("../../utils/scales").DomainType;
|
|
31
|
+
rDomain?: import("../../utils/scales").DomainType;
|
|
32
|
+
x1Domain?: import("../../utils/scales").DomainType;
|
|
33
|
+
y1Domain?: import("../../utils/scales").DomainType;
|
|
34
|
+
cDomain?: import("../../utils/scales").DomainType;
|
|
35
|
+
xNice?: boolean | number;
|
|
36
|
+
yNice?: boolean | number;
|
|
37
|
+
zNice?: boolean | number;
|
|
38
|
+
rNice?: boolean | number;
|
|
39
|
+
xPadding?: [number, number];
|
|
40
|
+
yPadding?: [number, number];
|
|
41
|
+
zPadding?: [number, number];
|
|
42
|
+
rPadding?: [number, number];
|
|
43
|
+
xScale?: import("../../utils/scales").AnyScale;
|
|
44
|
+
yScale?: import("../../utils/scales").AnyScale;
|
|
45
|
+
zScale?: import("../../utils/scales").AnyScale;
|
|
46
|
+
rScale?: import("../../utils/scales").AnyScale;
|
|
47
|
+
x1Scale?: import("../../utils/scales").AnyScale;
|
|
48
|
+
y1Scale?: import("../../utils/scales").AnyScale;
|
|
49
|
+
cScale?: import("../../utils/scales").AnyScale;
|
|
50
|
+
xRange?: string[] | number[] | ((args: {
|
|
51
|
+
width: number;
|
|
52
|
+
height: number;
|
|
53
|
+
}) => number[] | string[]) | undefined;
|
|
54
|
+
yRange?: string[] | number[] | ((args: {
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
}) => number[] | string[]) | undefined;
|
|
58
|
+
zRange?: string[] | number[] | ((args: {
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
}) => number[] | string[]) | undefined;
|
|
62
|
+
rRange?: string[] | number[] | ((args: {
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
}) => number[] | string[]) | undefined;
|
|
66
|
+
x1Range?: string[] | number[] | ((args: {
|
|
67
|
+
xScale: import("../../utils/scales").AnyScale;
|
|
68
|
+
width: number;
|
|
69
|
+
height: number;
|
|
70
|
+
}) => number[] | string[]) | undefined;
|
|
71
|
+
y1Range?: string[] | number[] | ((args: {
|
|
72
|
+
yScale: import("../../utils/scales").AnyScale;
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
}) => number[] | string[]) | undefined;
|
|
76
|
+
cRange?: string[];
|
|
77
|
+
xReverse?: boolean;
|
|
78
|
+
yReverse?: boolean;
|
|
79
|
+
zReverse?: boolean;
|
|
80
|
+
rReverse?: boolean;
|
|
81
|
+
xDomainSort?: boolean;
|
|
82
|
+
yDomainSort?: boolean;
|
|
83
|
+
zDomainSort?: boolean;
|
|
84
|
+
rDomainSort?: boolean;
|
|
85
|
+
padding?: {
|
|
86
|
+
top?: Number;
|
|
87
|
+
right?: Number;
|
|
88
|
+
bottom?: Number;
|
|
89
|
+
left?: Number;
|
|
90
|
+
} | undefined;
|
|
91
|
+
extents?: {
|
|
92
|
+
x?: [min: Number, max: Number];
|
|
93
|
+
y?: [min: Number, max: Number];
|
|
94
|
+
r?: [min: Number, max: Number];
|
|
95
|
+
z?: [min: Number, max: Number];
|
|
96
|
+
} | undefined;
|
|
97
|
+
custom?: Record<string, any>;
|
|
98
|
+
debug?: boolean;
|
|
99
|
+
verbose?: boolean;
|
|
100
|
+
xBaseline?: number | null;
|
|
101
|
+
yBaseline?: number | null;
|
|
102
|
+
radial?: boolean;
|
|
103
|
+
geo?: Partial<{
|
|
104
|
+
projection?: (() => import("d3-geo").GeoProjection) | undefined;
|
|
105
|
+
fitGeojson?: import("d3-geo").GeoPermissibleObjects | undefined;
|
|
106
|
+
fixedAspectRatio?: number | undefined;
|
|
107
|
+
clipAngle?: number | undefined;
|
|
108
|
+
clipExtent?: [[number, number], [number, number]] | undefined;
|
|
109
|
+
rotate?: {
|
|
110
|
+
yaw: number;
|
|
111
|
+
pitch: number;
|
|
112
|
+
roll: number;
|
|
113
|
+
} | undefined;
|
|
114
|
+
scale?: number | undefined;
|
|
115
|
+
translate?: [number, number] | undefined;
|
|
116
|
+
center?: [number, number] | undefined;
|
|
117
|
+
applyTransform?: ("scale" | "translate" | "rotate")[];
|
|
118
|
+
reflectX?: boolean | undefined;
|
|
119
|
+
reflectY?: boolean | undefined;
|
|
120
|
+
geo?: import("svelte/store").Writable<import("d3-geo").GeoProjection>;
|
|
121
|
+
}> | undefined;
|
|
122
|
+
tooltip?: boolean | Partial<{
|
|
123
|
+
mode?: "bisect-x" | "bisect-y" | "band" | "bisect-band" | "bounds" | "voronoi" | "quadtree" | "manual";
|
|
124
|
+
findTooltipData?: "closest" | "left" | "right";
|
|
125
|
+
raiseTarget?: boolean;
|
|
126
|
+
radius?: number;
|
|
127
|
+
debug?: boolean;
|
|
128
|
+
onClick?: ({ data }: {
|
|
129
|
+
data: any;
|
|
130
|
+
}) => any;
|
|
131
|
+
}> | undefined;
|
|
132
|
+
transform?: Partial<{
|
|
133
|
+
mode?: "canvas" | "manual" | "none";
|
|
134
|
+
translateOnScale?: boolean;
|
|
135
|
+
spring?: boolean | Parameters<typeof import("../../stores/motionStore").motionStore>[1]["spring"];
|
|
136
|
+
tweened?: boolean | Parameters<typeof import("../../stores/motionStore").motionStore>[1]["tweened"];
|
|
137
|
+
processTranslate?: (x: number, y: number, deltaX: number, deltaY: number, scale: number) => {
|
|
138
|
+
x: number;
|
|
139
|
+
y: number;
|
|
140
|
+
};
|
|
141
|
+
disablePointer?: boolean;
|
|
142
|
+
initialScrollMode?: "none" | "scale" | "translate";
|
|
143
|
+
clickDistance?: number;
|
|
144
|
+
initialTranslate?: {
|
|
145
|
+
x: number;
|
|
146
|
+
y: number;
|
|
147
|
+
} | undefined;
|
|
148
|
+
translate?: import("svelte/motion").Spring<{
|
|
149
|
+
x: number;
|
|
150
|
+
y: number;
|
|
151
|
+
}> | import("svelte/motion").Tweened<{
|
|
152
|
+
x: number;
|
|
153
|
+
y: number;
|
|
154
|
+
}> | import("svelte/store").Writable<{
|
|
155
|
+
x: number;
|
|
156
|
+
y: number;
|
|
157
|
+
}>;
|
|
158
|
+
initialScale?: number | undefined;
|
|
159
|
+
scale?: import("svelte/store").Writable<number> | import("svelte/motion").Spring<number> | import("svelte/motion").Tweened<number>;
|
|
160
|
+
setScrollMode?: (mode: "none" | "scale" | "translate") => void;
|
|
161
|
+
reset?: () => void;
|
|
162
|
+
zoomIn?: () => void;
|
|
163
|
+
zoomOut?: () => void;
|
|
164
|
+
translateCenter?: () => void;
|
|
165
|
+
zoomTo?: (center: {
|
|
166
|
+
x: number;
|
|
167
|
+
y: number;
|
|
168
|
+
}, rect?: {
|
|
169
|
+
width: number;
|
|
170
|
+
height: number;
|
|
171
|
+
}) => void;
|
|
172
|
+
setTranslate?: (point: {
|
|
173
|
+
x: number;
|
|
174
|
+
y: number;
|
|
175
|
+
}, options?: import("../../stores/motionStore").MotionOptions) => void;
|
|
176
|
+
setScale?: (value: number, options?: import("../../stores/motionStore").MotionOptions) => void;
|
|
177
|
+
}> | undefined;
|
|
178
|
+
transformContext?: import("..").TransformContext;
|
|
179
|
+
} & {
|
|
180
|
+
series?: {
|
|
181
|
+
key: string;
|
|
182
|
+
label?: string;
|
|
183
|
+
data: TData[];
|
|
184
|
+
color?: string;
|
|
185
|
+
props?: Partial<ComponentProps<Points>>;
|
|
186
|
+
}[] | undefined;
|
|
187
|
+
labels?: boolean | {
|
|
188
|
+
[x: string]: any;
|
|
189
|
+
placement?: ("inside" | "outside" | "center") | undefined;
|
|
190
|
+
offset?: number | undefined;
|
|
191
|
+
format?: import("@layerstack/utils").FormatType | undefined;
|
|
192
|
+
};
|
|
193
|
+
axis?: boolean | {
|
|
194
|
+
placement: "top" | "bottom" | "left" | "right" | "angle" | "radius";
|
|
195
|
+
label?: string;
|
|
196
|
+
labelPlacement?: "start" | "middle" | "end";
|
|
197
|
+
labelProps?: Partial<ComponentProps<import("..").Text>> | undefined;
|
|
198
|
+
rule?: boolean | Pick<import("svelte/elements").SVGAttributes<SVGElement>, "class" | "style">;
|
|
199
|
+
grid?: boolean | Pick<import("svelte/elements").SVGAttributes<SVGElement>, "class" | "style">;
|
|
200
|
+
ticks?: number | any[] | ((scale: import("../../utils/scales").AnyScale) => any) | null | undefined;
|
|
201
|
+
tickLength?: number;
|
|
202
|
+
format?: import("@layerstack/utils").FormatType | undefined;
|
|
203
|
+
tickLabelProps?: Partial<ComponentProps<import("..").Text>> | undefined;
|
|
204
|
+
spring?: boolean | Parameters<typeof import("svelte/motion").spring>[1];
|
|
205
|
+
tweened?: boolean | Parameters<typeof import("svelte/motion").tweened>[1];
|
|
206
|
+
transitionIn?: typeof import("svelte/transition").fade | (() => {});
|
|
207
|
+
transitionInParams?: import("svelte-ux").TransitionParams;
|
|
208
|
+
scale?: any;
|
|
209
|
+
};
|
|
210
|
+
props?: {
|
|
211
|
+
xAxis?: Partial<ComponentProps<Axis>>;
|
|
212
|
+
yAxis?: Partial<ComponentProps<Axis>>;
|
|
213
|
+
points?: Partial<ComponentProps<Points>>;
|
|
214
|
+
highlight?: Partial<ComponentProps<Highlight>>;
|
|
215
|
+
labels?: Partial<ComponentProps<Labels>>;
|
|
216
|
+
} | undefined;
|
|
217
|
+
};
|
|
218
|
+
events(): {} & {
|
|
219
|
+
[evt: string]: CustomEvent<any>;
|
|
220
|
+
};
|
|
221
|
+
slots(): {
|
|
222
|
+
default: any;
|
|
223
|
+
axis: any;
|
|
224
|
+
'below-marks': any;
|
|
225
|
+
marks: any;
|
|
226
|
+
'above-marks': any;
|
|
227
|
+
highlight: any;
|
|
228
|
+
tooltip: any;
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
export type ScatterChartProps<TData> = ReturnType<__sveltets_Render<TData>['props']>;
|
|
232
|
+
export type ScatterChartEvents<TData> = ReturnType<__sveltets_Render<TData>['events']>;
|
|
233
|
+
export type ScatterChartSlots<TData> = ReturnType<__sveltets_Render<TData>['slots']>;
|
|
234
|
+
export default class ScatterChart<TData> extends SvelteComponentTyped<ScatterChartProps<TData>, ScatterChartEvents<TData>, ScatterChartSlots<TData>> {
|
|
235
|
+
}
|
|
236
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as AreaChart } from './AreaChart.svelte';
|
|
2
|
+
export { default as BarChart } from './BarChart.svelte';
|
|
3
|
+
export { default as LineChart } from './LineChart.svelte';
|
|
4
|
+
export { default as PieChart } from './PieChart.svelte';
|
|
5
|
+
export { default as ScatterChart } from './ScatterChart.svelte';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as AreaChart } from './AreaChart.svelte';
|
|
2
|
+
export { default as BarChart } from './BarChart.svelte';
|
|
3
|
+
export { default as LineChart } from './LineChart.svelte';
|
|
4
|
+
export { default as PieChart } from './PieChart.svelte';
|
|
5
|
+
export { default as ScatterChart } from './ScatterChart.svelte';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Html, WebGL } from 'layercake';
|
|
2
|
+
export * from './charts/index.js';
|
|
2
3
|
export { default as Arc } from './Arc.svelte';
|
|
3
4
|
export { default as Area } from './Area.svelte';
|
|
4
|
-
export { default as AreaStack } from './AreaStack.svelte';
|
|
5
5
|
export { default as Axis } from './Axis.svelte';
|
|
6
6
|
export { default as Bar } from './Bar.svelte';
|
|
7
7
|
export { default as Bars } from './Bars.svelte';
|
|
@@ -53,12 +53,8 @@ export { default as Svg } from './layout/Svg.svelte';
|
|
|
53
53
|
export { default as Text } from './Text.svelte';
|
|
54
54
|
export { default as Threshold } from './Threshold.svelte';
|
|
55
55
|
export { default as TileImage } from './TileImage.svelte';
|
|
56
|
-
export
|
|
57
|
-
export { default as TooltipContext } from './TooltipContext.svelte';
|
|
58
|
-
export { default as TooltipItem } from './TooltipItem.svelte';
|
|
59
|
-
export { default as TooltipSeparator } from './TooltipSeparator.svelte';
|
|
56
|
+
export * as Tooltip from './tooltip/index.js';
|
|
60
57
|
export { default as TransformContext, transformContext } from './TransformContext.svelte';
|
|
61
|
-
export { default as TransformControls } from './TransformControls.svelte';
|
|
62
58
|
export { default as Tree } from './Tree.svelte';
|
|
63
59
|
export { default as Treemap } from './Treemap.svelte';
|
|
64
60
|
export { default as Voronoi } from './Voronoi.svelte';
|
package/dist/components/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Re-export for easy access (Svg and Canvas are provided by LayerChart)
|
|
2
2
|
export { Html, WebGL } from 'layercake';
|
|
3
|
+
export * from './charts/index.js';
|
|
3
4
|
export { default as Arc } from './Arc.svelte';
|
|
4
5
|
export { default as Area } from './Area.svelte';
|
|
5
|
-
export { default as AreaStack } from './AreaStack.svelte';
|
|
6
6
|
export { default as Axis } from './Axis.svelte';
|
|
7
7
|
export { default as Bar } from './Bar.svelte';
|
|
8
8
|
export { default as Bars } from './Bars.svelte';
|
|
@@ -54,12 +54,9 @@ export { default as Svg } from './layout/Svg.svelte';
|
|
|
54
54
|
export { default as Text } from './Text.svelte';
|
|
55
55
|
export { default as Threshold } from './Threshold.svelte';
|
|
56
56
|
export { default as TileImage } from './TileImage.svelte';
|
|
57
|
-
export
|
|
58
|
-
export { default as TooltipContext } from './TooltipContext.svelte';
|
|
59
|
-
export { default as TooltipItem } from './TooltipItem.svelte';
|
|
60
|
-
export { default as TooltipSeparator } from './TooltipSeparator.svelte';
|
|
57
|
+
export * as Tooltip from './tooltip/index.js';
|
|
61
58
|
export { default as TransformContext, transformContext } from './TransformContext.svelte';
|
|
62
|
-
export { default as TransformControls } from './TransformControls.svelte';
|
|
59
|
+
// export { default as TransformControls } from './TransformControls.svelte'; // TODO: Restore once no longer using `svelet-ux` or `@mdi/js` (as they are dev dependencies)
|
|
63
60
|
export { default as Tree } from './Tree.svelte';
|
|
64
61
|
export { default as Treemap } from './Treemap.svelte';
|
|
65
62
|
export { default as Voronoi } from './Voronoi.svelte';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>import { onMount, setContext } from 'svelte';
|
|
2
2
|
import { writable } from 'svelte/store';
|
|
3
3
|
import { scaleCanvas } from 'layercake';
|
|
4
|
-
import { cls } from '
|
|
4
|
+
import { cls } from '@layerstack/tailwind';
|
|
5
5
|
import { chartContext } from '../ChartContext.svelte';
|
|
6
6
|
import { transformContext } from '../TransformContext.svelte';
|
|
7
7
|
const { width, height, containerWidth, containerHeight, padding } = chartContext();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<script>import { cls } from '
|
|
1
|
+
<script>import { cls } from '@layerstack/tailwind';
|
|
2
2
|
import { chartContext } from '../ChartContext.svelte';
|
|
3
3
|
import { transformContext } from '../TransformContext.svelte';
|
|
4
4
|
/** The layer's `<svg>` tag. Useful for bindings. */
|
|
@@ -19,9 +19,15 @@ export let labelledBy = undefined;
|
|
|
19
19
|
export let describedBy = undefined;
|
|
20
20
|
/** Shorthand to set the contents of `<title></title>` for accessibility. You can also set arbitrary HTML via the "title" slot but this is a convenient shorthand. If you use the "title" slot, this prop is ignored. */
|
|
21
21
|
export let title = undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Translate children to center, useful for radial layouts
|
|
24
|
+
*/
|
|
25
|
+
export let center = false;
|
|
22
26
|
const { containerWidth, containerHeight, width, height, padding } = chartContext();
|
|
23
27
|
const { mode, scale, translate } = transformContext();
|
|
24
|
-
|
|
28
|
+
$: transform = center
|
|
29
|
+
? `translate(${center === 'x' || center === true ? $width / 2 : 0}, ${center === 'y' || center === true ? $height / 2 : 0})`
|
|
30
|
+
: '';
|
|
25
31
|
$: if (mode === 'canvas') {
|
|
26
32
|
const center = { x: $width / 2, y: $height / 2 };
|
|
27
33
|
const newTranslate = {
|
|
@@ -65,8 +71,12 @@ $: if (mode === 'canvas') {
|
|
|
65
71
|
class="layercake-layout-svg_g"
|
|
66
72
|
transform="translate({$padding.left}, {$padding.top})"
|
|
67
73
|
>
|
|
68
|
-
|
|
74
|
+
{#if transform}
|
|
75
|
+
<g {transform}>
|
|
76
|
+
<slot {element}></slot>
|
|
77
|
+
</g>
|
|
78
|
+
{:else}
|
|
69
79
|
<slot {element}></slot>
|
|
70
|
-
|
|
80
|
+
{/if}
|
|
71
81
|
</g>
|
|
72
82
|
</svg>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script>import { fade } from 'svelte/transition';
|
|
2
|
-
import { cls } from '
|
|
3
|
-
import { chartContext } from '
|
|
2
|
+
import { cls } from '@layerstack/tailwind';
|
|
3
|
+
import { chartContext } from './../ChartContext.svelte';
|
|
4
4
|
import { tooltipContext } from './TooltipContext.svelte';
|
|
5
|
-
import { motionStore } from '
|
|
5
|
+
import { motionStore } from '../../stores/motionStore.js';
|
|
6
6
|
/** `x` position of tooltip. By default uses the pointer/mouse, can also snap to data or an explicit fixed position. */
|
|
7
7
|
export let x = 'pointer';
|
|
8
8
|
/** `y` position of tooltip. By default uses the pointer/mouse, can also snap to data or an explicit fixed position. */
|
|
@@ -16,7 +16,6 @@ export let contained = 'container'; // TODO: Support 'window' using getBoundingC
|
|
|
16
16
|
export let variant = 'default';
|
|
17
17
|
/** Set to `false` to disable spring transitions */
|
|
18
18
|
export let motion = true;
|
|
19
|
-
export let header = undefined;
|
|
20
19
|
export let classes = {};
|
|
21
20
|
const { padding, xGet, yGet, containerWidth, containerHeight } = chartContext();
|
|
22
21
|
const tooltip = tooltipContext();
|
|
@@ -109,11 +108,7 @@ $: if ($tooltip?.data) {
|
|
|
109
108
|
>
|
|
110
109
|
<div
|
|
111
110
|
class={cls(
|
|
112
|
-
variant !== 'none' && [
|
|
113
|
-
'px-2 py-1 h-full rounded elevation-1',
|
|
114
|
-
'[&_.label]:text-xs [&_.label]:text-right [&_.label]:whitespace-nowrap',
|
|
115
|
-
['[&_.value]:text-sm [&_.value]:tabular-nums'],
|
|
116
|
-
],
|
|
111
|
+
variant !== 'none' && ['text-sm py-1 px-2 h-full rounded elevation-1'],
|
|
117
112
|
{
|
|
118
113
|
default: [
|
|
119
114
|
'bg-surface-100/90 dark:bg-surface-300/90 backdrop-filter backdrop-blur-[2px] text-surface-content',
|
|
@@ -129,26 +124,8 @@ $: if ($tooltip?.data) {
|
|
|
129
124
|
$$props.class
|
|
130
125
|
)}
|
|
131
126
|
>
|
|
132
|
-
{#if header || $$slots.header}
|
|
133
|
-
<div
|
|
134
|
-
class={cls(
|
|
135
|
-
variant !== 'none' && 'text-center font-semibold whitespace-nowrap',
|
|
136
|
-
classes.header
|
|
137
|
-
)}
|
|
138
|
-
>
|
|
139
|
-
<slot name="header" data={$tooltip.data}>
|
|
140
|
-
{header?.($tooltip.data)}
|
|
141
|
-
</slot>
|
|
142
|
-
</div>
|
|
143
|
-
{/if}
|
|
144
|
-
|
|
145
127
|
{#if $$slots.default}
|
|
146
|
-
<div
|
|
147
|
-
class={cls(
|
|
148
|
-
variant !== 'none' && 'grid grid-cols-[1fr,auto] gap-x-2 gap-y-1 items-center pt-1',
|
|
149
|
-
classes.content
|
|
150
|
-
)}
|
|
151
|
-
>
|
|
128
|
+
<div class={cls(classes.content)}>
|
|
152
129
|
<slot data={$tooltip.data} />
|
|
153
130
|
</div>
|
|
154
131
|
{/if}
|
|
@@ -6,11 +6,10 @@ declare const __propDef: {
|
|
|
6
6
|
y?: "pointer" | "data" | number | undefined;
|
|
7
7
|
xOffset?: number | undefined;
|
|
8
8
|
yOffset?: number | undefined;
|
|
9
|
-
anchor?: ("
|
|
9
|
+
anchor?: ("left" | "right" | "center" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
|
|
10
10
|
contained?: ("container" | false) | undefined;
|
|
11
11
|
variant?: ("default" | "invert" | "none") | undefined;
|
|
12
12
|
motion?: boolean | undefined;
|
|
13
|
-
header?: ((data: any) => any) | undefined;
|
|
14
13
|
classes?: {
|
|
15
14
|
root?: string;
|
|
16
15
|
container?: string;
|
|
@@ -22,9 +21,6 @@ declare const __propDef: {
|
|
|
22
21
|
[evt: string]: CustomEvent<any>;
|
|
23
22
|
};
|
|
24
23
|
slots: {
|
|
25
|
-
header: {
|
|
26
|
-
data: any;
|
|
27
|
-
};
|
|
28
24
|
default: {
|
|
29
25
|
data: any;
|
|
30
26
|
};
|
|
@@ -19,15 +19,17 @@ function setTooltipContext(tooltip) {
|
|
|
19
19
|
import { writable } from 'svelte/store';
|
|
20
20
|
import { bisector, max, min } from 'd3-array';
|
|
21
21
|
import { quadtree as d3Quadtree } from 'd3-quadtree';
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
|
|
22
|
+
import { sortFunc } from '@layerstack/utils';
|
|
23
|
+
import { cls } from '@layerstack/tailwind';
|
|
24
|
+
import Svg from './../layout/Svg.svelte';
|
|
25
|
+
import { chartContext } from './../ChartContext.svelte';
|
|
26
|
+
import ChartClipPath from './../ChartClipPath.svelte';
|
|
27
|
+
import Voronoi from './../Voronoi.svelte';
|
|
28
|
+
import { localPoint } from '../../utils/event.js';
|
|
29
|
+
import { isScaleBand, scaleInvert } from '../../utils/scales.js';
|
|
30
|
+
import { cartesianToPolar } from '../../utils/math.js';
|
|
31
|
+
import { quadtreeRects } from '../../utils/quadtree.js';
|
|
32
|
+
const { flatData, x, xScale, xGet, xRange, y, yScale, yGet, yRange, width, height, containerWidth, containerHeight, padding, radial, } = chartContext();
|
|
31
33
|
/*
|
|
32
34
|
TODO: Defaults to consider (if possible to detect scale type, which might not be possible)
|
|
33
35
|
- scaleTime / scaleLinear: bisect
|
|
@@ -137,8 +139,15 @@ function showTooltip(e, tooltipData) {
|
|
|
137
139
|
if (tooltipData == null) {
|
|
138
140
|
switch (mode) {
|
|
139
141
|
case 'bisect-x': {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
let xValueAtPoint;
|
|
143
|
+
if ($radial) {
|
|
144
|
+
// Assume radial is always centered
|
|
145
|
+
const { radians } = cartesianToPolar(localX - $width / 2, localY - $height / 2);
|
|
146
|
+
xValueAtPoint = scaleInvert($xScale, radians);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
xValueAtPoint = scaleInvert($xScale, localX - $padding.left);
|
|
150
|
+
}
|
|
142
151
|
const index = bisectX($flatData, xValueAtPoint, 1);
|
|
143
152
|
const previousValue = $flatData[index - 1];
|
|
144
153
|
const currentValue = $flatData[index];
|
|
@@ -330,7 +339,6 @@ $: triggerPointEvents = ['bisect-x', 'bisect-y', 'bisect-band', 'quadtree'].incl
|
|
|
330
339
|
<Svg>
|
|
331
340
|
<Voronoi
|
|
332
341
|
on:pointerenter={(e) => {
|
|
333
|
-
// @ts-expect-error
|
|
334
342
|
showTooltip(e.detail.event, e.detail.data);
|
|
335
343
|
}}
|
|
336
344
|
on:pointermove={(e) => {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script>import { cls } from '@layerstack/tailwind';
|
|
2
|
+
export let color = undefined;
|
|
3
|
+
export let classes = {};
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<div
|
|
7
|
+
class={cls(
|
|
8
|
+
'TooltipHeader',
|
|
9
|
+
'font-semibold whitespace-nowrap border-b mb-1 pb-1 flex items-center gap-2',
|
|
10
|
+
classes.root,
|
|
11
|
+
$$props.class
|
|
12
|
+
)}
|
|
13
|
+
>
|
|
14
|
+
{#if color}
|
|
15
|
+
<div
|
|
16
|
+
class={cls('color', 'inline-block size-2 rounded-full bg-[--color]', classes.color)}
|
|
17
|
+
style:--color={color}
|
|
18
|
+
></div>
|
|
19
|
+
{/if}
|
|
20
|
+
<slot />
|
|
21
|
+
</div>
|