layerchart 2.0.0-next.43 → 2.0.0-next.45
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/LICENSE +1 -1
- package/dist/components/AnnotationLine.svelte +1 -1
- package/dist/components/AnnotationPoint.svelte +1 -1
- package/dist/components/AnnotationRange.svelte +16 -15
- package/dist/components/Arc.svelte +10 -10
- package/dist/components/Arc.svelte.d.ts +4 -4
- package/dist/components/Arc.svelte.test.d.ts +1 -0
- package/dist/components/Arc.svelte.test.js +868 -0
- package/dist/components/Area.svelte +9 -7
- package/dist/components/Axis.svelte +2 -1
- package/dist/components/Axis.svelte.d.ts +1 -0
- package/dist/components/Bar.svelte +3 -3
- package/dist/components/Bars.svelte +1 -1
- package/dist/components/Blur.svelte +3 -3
- package/dist/components/Bounds.svelte +1 -1
- package/dist/components/BrushContext.svelte +1 -1
- package/dist/components/Calendar.svelte +2 -2
- package/dist/components/Calendar.svelte.d.ts +1 -1
- package/dist/components/Chart.svelte +63 -137
- package/dist/components/Chart.svelte.d.ts +23 -88
- package/dist/components/ChartClipPath.svelte +1 -1
- package/dist/components/Circle.svelte +17 -8
- package/dist/components/Circle.svelte.d.ts +3 -0
- package/dist/components/ClipPath.svelte +4 -4
- package/dist/components/Connector.svelte +4 -4
- package/dist/components/Connector.svelte.d.ts +3 -3
- package/dist/components/Ellipse.svelte +7 -7
- package/dist/components/Frame.svelte +1 -1
- package/dist/components/GeoContext.svelte +4 -20
- package/dist/components/GeoContext.svelte.d.ts +2 -6
- package/dist/components/GeoEdgeFade.svelte +1 -1
- package/dist/components/GeoPath.svelte +42 -107
- package/dist/components/GeoPath.svelte.d.ts +5 -4
- package/dist/components/GeoPoint.svelte +5 -5
- package/dist/components/GeoSpline.svelte +2 -14
- package/dist/components/GeoSpline.svelte.d.ts +1 -1
- package/dist/components/GeoTile.svelte +7 -6
- package/dist/components/GeoVisible.svelte +1 -1
- package/dist/components/Graticule.svelte +4 -7
- package/dist/components/Graticule.svelte.d.ts +2 -1
- package/dist/components/Grid.svelte +1 -1
- package/dist/components/Group.svelte +8 -8
- package/dist/components/Highlight.svelte +18 -16
- package/dist/components/Hull.svelte +2 -2
- package/dist/components/Labels.svelte +1 -1
- package/dist/components/Legend.svelte +1 -1
- package/dist/components/Line.svelte +9 -7
- package/dist/components/LinearGradient.svelte +8 -7
- package/dist/components/MonthPath.svelte +5 -11
- package/dist/components/MonthPath.svelte.d.ts +2 -2
- package/dist/components/Pack.svelte +4 -6
- package/dist/components/Pack.svelte.d.ts +2 -4
- package/dist/components/Partition.svelte +4 -3
- package/dist/components/Partition.svelte.d.ts +2 -1
- package/dist/components/Path.svelte +344 -0
- package/dist/components/Path.svelte.d.ts +72 -0
- package/dist/components/Pattern.svelte +6 -6
- package/dist/components/Pie.svelte +2 -2
- package/dist/components/Pie.svelte.d.ts +1 -1
- package/dist/components/Point.svelte +1 -1
- package/dist/components/Points.svelte +1 -1
- package/dist/components/Polygon.svelte +8 -6
- package/dist/components/RadialGradient.svelte +7 -7
- package/dist/components/Rect.svelte +32 -10
- package/dist/components/Rect.svelte.d.ts +4 -1
- package/dist/components/Rule.svelte +1 -1
- package/dist/components/Sankey.svelte +1 -1
- package/dist/components/Spline.svelte +13 -337
- package/dist/components/Spline.svelte.d.ts +10 -73
- package/dist/components/Text.svelte +9 -7
- package/dist/components/Threshold.svelte +3 -3
- package/dist/components/TransformContext.svelte +10 -143
- package/dist/components/TransformControls.svelte +2 -2
- package/dist/components/TransformControls.svelte.d.ts +1 -1
- package/dist/components/Tree.svelte +4 -3
- package/dist/components/Tree.svelte.d.ts +2 -1
- package/dist/components/Treemap.svelte +4 -3
- package/dist/components/Treemap.svelte.d.ts +2 -1
- package/dist/components/Voronoi.svelte +5 -5
- package/dist/components/charts/ArcChart.svelte +14 -6
- package/dist/components/charts/ArcChart.svelte.d.ts +1 -1
- package/dist/components/charts/AreaChart.svelte +12 -6
- package/dist/components/charts/BarChart.svelte +12 -6
- package/dist/components/charts/DefaultTooltip.svelte +1 -1
- package/dist/components/charts/LineChart.svelte +12 -6
- package/dist/components/charts/PieChart.svelte +14 -6
- package/dist/components/charts/PieChart.svelte.d.ts +1 -1
- package/dist/components/charts/ScatterChart.svelte +11 -9
- package/dist/components/charts/types.d.ts +7 -6
- package/dist/components/index.d.ts +14 -12
- package/dist/components/index.js +14 -12
- package/dist/components/{layout → layers}/Canvas.svelte +13 -60
- package/dist/components/{layout → layers}/Canvas.svelte.d.ts +2 -32
- package/dist/components/{layout → layers}/Html.svelte +18 -3
- package/dist/components/{layout → layers}/Html.svelte.d.ts +7 -0
- package/dist/components/layers/Layer.svelte +85 -0
- package/dist/components/{layout → layers}/Layer.svelte.d.ts +7 -3
- package/dist/components/{layout → layers}/Svg.svelte +18 -3
- package/dist/components/{layout → layers}/Svg.svelte.d.ts +7 -0
- package/dist/components/{layout → layers}/WebGL.svelte +1 -1
- package/dist/components/{layout → layers}/WebGL.svelte.d.ts +3 -3
- package/dist/components/tests/TestHarness.svelte +76 -0
- package/dist/components/tests/TestHarness.svelte.d.ts +19 -0
- package/dist/components/tooltip/Tooltip.svelte +3 -3
- package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContext.svelte +13 -45
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +2 -14
- package/dist/components/tooltip/tooltipMetaContext.d.ts +2 -2
- package/dist/components/tooltip/tooltipMetaContext.js +2 -2
- package/dist/contexts/canvas.d.ts +33 -0
- package/dist/contexts/canvas.js +14 -0
- package/dist/contexts/chart.d.ts +84 -0
- package/dist/contexts/chart.js +10 -0
- package/dist/contexts/geo.d.ts +6 -0
- package/dist/contexts/geo.js +12 -0
- package/dist/contexts/index.d.ts +6 -0
- package/dist/contexts/index.js +6 -0
- package/dist/contexts/layer.d.ts +3 -0
- package/dist/contexts/layer.js +8 -0
- package/dist/contexts/settings.d.ts +4 -0
- package/dist/contexts/settings.js +10 -0
- package/dist/contexts/tooltip.d.ts +15 -0
- package/dist/contexts/tooltip.js +8 -0
- package/dist/contexts/transform.d.ts +95 -0
- package/dist/contexts/transform.js +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/states/settings.svelte.d.ts +12 -0
- package/dist/states/settings.svelte.js +10 -0
- package/dist/states/transform.svelte.d.ts +9 -0
- package/dist/states/transform.svelte.js +31 -0
- package/dist/styles/skeleton-4.css +15 -0
- package/dist/utils/arcText.svelte.d.ts +1 -1
- package/dist/utils/canvas.d.ts +7 -3
- package/dist/utils/canvas.js +78 -11
- package/dist/utils/color.js +11 -8
- package/dist/utils/common.d.ts +8 -1
- package/dist/utils/common.js +9 -10
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/motion.svelte.js +0 -1
- package/dist/utils/rect.svelte.d.ts +1 -1
- package/dist/utils/rect.svelte.js +17 -9
- package/dist/utils/string.d.ts +3 -1
- package/package.json +32 -54
- package/README.md +0 -41
- package/dist/components/layout/Layer.svelte +0 -41
- package/dist/docs/Blockquote.svelte +0 -17
- package/dist/docs/Blockquote.svelte.d.ts +0 -5
- package/dist/docs/Code.svelte +0 -80
- package/dist/docs/Code.svelte.d.ts +0 -14
- package/dist/docs/ConnectorSweepMenuField.svelte +0 -17
- package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +0 -7
- package/dist/docs/ConnectorTypeMenuField.svelte +0 -17
- package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +0 -7
- package/dist/docs/CurveMenuField.svelte +0 -44
- package/dist/docs/CurveMenuField.svelte.d.ts +0 -9
- package/dist/docs/GeoDebug.svelte +0 -60
- package/dist/docs/GeoDebug.svelte.d.ts +0 -4
- package/dist/docs/Header1.svelte +0 -16
- package/dist/docs/Header1.svelte.d.ts +0 -5
- package/dist/docs/Json.svelte +0 -36
- package/dist/docs/Json.svelte.d.ts +0 -10
- package/dist/docs/Layout.svelte +0 -21
- package/dist/docs/Layout.svelte.d.ts +0 -8
- package/dist/docs/Link.svelte +0 -9
- package/dist/docs/Link.svelte.d.ts +0 -5
- package/dist/docs/PathDataMenuField.svelte +0 -78
- package/dist/docs/PathDataMenuField.svelte.d.ts +0 -9
- package/dist/docs/Preview.svelte +0 -104
- package/dist/docs/Preview.svelte.d.ts +0 -13
- package/dist/docs/TilesetField.svelte +0 -136
- package/dist/docs/TilesetField.svelte.d.ts +0 -6
- package/dist/docs/TransformDebug.svelte +0 -22
- package/dist/docs/TransformDebug.svelte.d.ts +0 -20
- package/dist/docs/ViewSourceButton.svelte +0 -53
- package/dist/docs/ViewSourceButton.svelte.d.ts +0 -11
- /package/dist/{utils → contexts}/legendPayload.d.ts +0 -0
- /package/dist/{utils → contexts}/legendPayload.js +0 -0
|
@@ -55,6 +55,14 @@
|
|
|
55
55
|
*/
|
|
56
56
|
ignoreTransform?: boolean;
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Whether to clip overflow content.
|
|
60
|
+
* When true, sets `overflow: hidden` on the SVG.
|
|
61
|
+
*
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
clip?: boolean;
|
|
65
|
+
|
|
58
66
|
children?: Snippet<[{ ref: SVGElement }]>;
|
|
59
67
|
};
|
|
60
68
|
|
|
@@ -63,9 +71,10 @@
|
|
|
63
71
|
</script>
|
|
64
72
|
|
|
65
73
|
<script lang="ts">
|
|
66
|
-
import { getTransformContext } from '
|
|
74
|
+
import { getTransformContext } from '../../contexts/transform.js';
|
|
67
75
|
|
|
68
|
-
import {
|
|
76
|
+
import { setLayerContext } from '../../contexts/layer.js';
|
|
77
|
+
import { getChartContext } from '../../contexts/chart.js';
|
|
69
78
|
|
|
70
79
|
let {
|
|
71
80
|
ref: refProp = $bindable(),
|
|
@@ -75,6 +84,7 @@
|
|
|
75
84
|
viewBox,
|
|
76
85
|
ignoreTransform = false,
|
|
77
86
|
center = false,
|
|
87
|
+
clip = false,
|
|
78
88
|
class: className,
|
|
79
89
|
title,
|
|
80
90
|
defs,
|
|
@@ -103,7 +113,7 @@
|
|
|
103
113
|
}
|
|
104
114
|
});
|
|
105
115
|
|
|
106
|
-
|
|
116
|
+
setLayerContext('svg');
|
|
107
117
|
</script>
|
|
108
118
|
|
|
109
119
|
<svg
|
|
@@ -114,6 +124,7 @@
|
|
|
114
124
|
style:z-index={zIndex}
|
|
115
125
|
class={['lc-layout-svg', className]}
|
|
116
126
|
class:disablePointerEvents={pointerEvents === false}
|
|
127
|
+
class:clip
|
|
117
128
|
role="figure"
|
|
118
129
|
{...restProps}
|
|
119
130
|
>
|
|
@@ -152,6 +163,10 @@
|
|
|
152
163
|
&.disablePointerEvents {
|
|
153
164
|
pointer-events: none;
|
|
154
165
|
}
|
|
166
|
+
|
|
167
|
+
&.clip {
|
|
168
|
+
overflow: hidden;
|
|
169
|
+
}
|
|
155
170
|
}
|
|
156
171
|
}
|
|
157
172
|
</style>
|
|
@@ -44,6 +44,13 @@ type SVGPropsWithoutHTML = {
|
|
|
44
44
|
* Useful to add static elements such as legends.
|
|
45
45
|
*/
|
|
46
46
|
ignoreTransform?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether to clip overflow content.
|
|
49
|
+
* When true, sets `overflow: hidden` on the SVG.
|
|
50
|
+
*
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
clip?: boolean;
|
|
47
54
|
children?: Snippet<[{
|
|
48
55
|
ref: SVGElement;
|
|
49
56
|
}]>;
|
|
@@ -48,6 +48,6 @@ export type WebGLContextValue = {
|
|
|
48
48
|
};
|
|
49
49
|
export declare function setWebGLContext(context: WebGLContextValue): WebGLContextValue;
|
|
50
50
|
export declare function getWebGLContext(): WebGLContextValue;
|
|
51
|
-
declare const
|
|
52
|
-
type
|
|
53
|
-
export default
|
|
51
|
+
declare const WebGL: import("svelte").Component<WebGLProps, {}, "ref" | "context">;
|
|
52
|
+
type WebGL = ReturnType<typeof WebGL>;
|
|
53
|
+
export default WebGL;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export const componentTestId = 'test-lc-component';
|
|
3
|
+
export const chartTestId = 'test-lc-chart';
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import type { Component as ComponentType } from 'svelte';
|
|
8
|
+
import Chart from '../Chart.svelte';
|
|
9
|
+
import Layer from '../layers/Layer.svelte';
|
|
10
|
+
|
|
11
|
+
type ChildComponent = {
|
|
12
|
+
component: ComponentType;
|
|
13
|
+
props?: Record<string, any> | ((snippetProps: any) => Record<string, any>);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
let {
|
|
17
|
+
useChart = true,
|
|
18
|
+
chartProps = {},
|
|
19
|
+
layer = 'svg',
|
|
20
|
+
layerProps = {},
|
|
21
|
+
component,
|
|
22
|
+
componentProps = {},
|
|
23
|
+
childComponents = [],
|
|
24
|
+
}: {
|
|
25
|
+
useChart?: boolean;
|
|
26
|
+
chartProps?: Record<string, any>;
|
|
27
|
+
layer?: 'svg' | 'html' | 'canvas';
|
|
28
|
+
layerProps?: Record<string, any>;
|
|
29
|
+
component: ComponentType;
|
|
30
|
+
componentProps?: Record<string, any>;
|
|
31
|
+
childComponents?: ChildComponent[];
|
|
32
|
+
} = $props();
|
|
33
|
+
|
|
34
|
+
const TestComponent = $derived(component);
|
|
35
|
+
|
|
36
|
+
// Merge defaults with chartProps so chartProps can override defaults
|
|
37
|
+
const mergedChartProps = $derived({
|
|
38
|
+
height: 300,
|
|
39
|
+
...chartProps,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Merge future defaults with componentProps so componentProps can override defaults
|
|
43
|
+
const mergedComponentProps = $derived({
|
|
44
|
+
...componentProps,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
function resolveProps(
|
|
48
|
+
props: Record<string, any> | ((snippetProps: any) => Record<string, any>) | undefined,
|
|
49
|
+
snippetProps: any
|
|
50
|
+
): Record<string, any> {
|
|
51
|
+
if (typeof props === 'function') {
|
|
52
|
+
return props(snippetProps);
|
|
53
|
+
}
|
|
54
|
+
return props ?? {};
|
|
55
|
+
}
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
{#snippet Component()}
|
|
59
|
+
<TestComponent {...mergedComponentProps} data-testid={componentTestId}>
|
|
60
|
+
{#snippet children(snippetProps: any)}
|
|
61
|
+
{#each childComponents as child}
|
|
62
|
+
<child.component {...resolveProps(child.props, snippetProps)} />
|
|
63
|
+
{/each}
|
|
64
|
+
{/snippet}
|
|
65
|
+
</TestComponent>
|
|
66
|
+
{/snippet}
|
|
67
|
+
|
|
68
|
+
{#if useChart}
|
|
69
|
+
<Chart {...mergedChartProps} data-testid={chartTestId}>
|
|
70
|
+
<Layer center type={layer} {...layerProps}>
|
|
71
|
+
{@render Component()}
|
|
72
|
+
</Layer>
|
|
73
|
+
</Chart>
|
|
74
|
+
{:else}
|
|
75
|
+
{@render Component()}
|
|
76
|
+
{/if}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const componentTestId = "test-lc-component";
|
|
2
|
+
export declare const chartTestId = "test-lc-chart";
|
|
3
|
+
import type { Component as ComponentType } from 'svelte';
|
|
4
|
+
type ChildComponent = {
|
|
5
|
+
component: ComponentType;
|
|
6
|
+
props?: Record<string, any> | ((snippetProps: any) => Record<string, any>);
|
|
7
|
+
};
|
|
8
|
+
type $$ComponentProps = {
|
|
9
|
+
useChart?: boolean;
|
|
10
|
+
chartProps?: Record<string, any>;
|
|
11
|
+
layer?: 'svg' | 'html' | 'canvas';
|
|
12
|
+
layerProps?: Record<string, any>;
|
|
13
|
+
component: ComponentType;
|
|
14
|
+
componentProps?: Record<string, any>;
|
|
15
|
+
childComponents?: ChildComponent[];
|
|
16
|
+
};
|
|
17
|
+
declare const TestHarness: ComponentType<$$ComponentProps, {}, "">;
|
|
18
|
+
type TestHarness = ReturnType<typeof TestHarness>;
|
|
19
|
+
export default TestHarness;
|
|
@@ -158,10 +158,10 @@
|
|
|
158
158
|
import { cls } from '@layerstack/tailwind';
|
|
159
159
|
|
|
160
160
|
import { isScaleBand } from '../../utils/scales.svelte.js';
|
|
161
|
-
import { getChartContext, type ChartContextValue } from '
|
|
162
|
-
import { getTooltipContext } from '
|
|
161
|
+
import { getChartContext, type ChartContextValue } from '../../contexts/chart.js';
|
|
162
|
+
import { getTooltipContext } from '../../contexts/tooltip.js';
|
|
163
163
|
import { createMotion, type MotionProp } from '../../utils/motion.svelte.js';
|
|
164
|
-
import {
|
|
164
|
+
import { type Snippet } from 'svelte';
|
|
165
165
|
|
|
166
166
|
let {
|
|
167
167
|
anchor = 'top-left',
|
|
@@ -131,7 +131,7 @@ export type TooltipPropsWithoutHTML<T = any> = {
|
|
|
131
131
|
context?: ChartContextValue<T, any, any>;
|
|
132
132
|
};
|
|
133
133
|
export type TooltipProps<T = any> = TooltipPropsWithoutHTML<T> & Without<HTMLAttributes<HTMLElement>, TooltipPropsWithoutHTML<T>>;
|
|
134
|
-
import { type ChartContextValue } from '
|
|
134
|
+
import { type ChartContextValue } from '../../contexts/chart.js';
|
|
135
135
|
import { type MotionProp } from '../../utils/motion.svelte.js';
|
|
136
136
|
import { type Snippet } from 'svelte';
|
|
137
137
|
declare function $$render<T = any>(): {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
import { Context } from 'runed';
|
|
3
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
3
|
import type { Without } from '../../utils/types.js';
|
|
4
|
+
import { setTooltipContext, type TooltipContextValue } from '../../contexts/tooltip.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type TooltipMode =
|
|
6
|
+
export type TooltipMode =
|
|
9
7
|
| 'bisect-x' // requires values to be sorted
|
|
10
8
|
| 'bisect-y' // requires values to be sorted
|
|
11
9
|
| 'band'
|
|
@@ -17,40 +15,6 @@
|
|
|
17
15
|
| 'quadtree-y' // ignores x values (constant 0)
|
|
18
16
|
| 'manual';
|
|
19
17
|
|
|
20
|
-
export type TooltipContextValue<T = any> = {
|
|
21
|
-
x: number;
|
|
22
|
-
y: number;
|
|
23
|
-
data: T | null;
|
|
24
|
-
payload: TooltipPayload[];
|
|
25
|
-
show(
|
|
26
|
-
e: PointerEvent | MouseEvent | TouchEvent,
|
|
27
|
-
tooltipData?: any,
|
|
28
|
-
payload?: TooltipPayload
|
|
29
|
-
): void;
|
|
30
|
-
hide(e?: PointerEvent): void;
|
|
31
|
-
mode: TooltipMode;
|
|
32
|
-
isHoveringTooltipArea: boolean;
|
|
33
|
-
isHoveringTooltipContent: boolean;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// const defaultContext = {
|
|
37
|
-
// x: 0,
|
|
38
|
-
// y: 0,
|
|
39
|
-
// data: null as any,
|
|
40
|
-
// payload: [],
|
|
41
|
-
// show: () => {},
|
|
42
|
-
// hide: () => {},
|
|
43
|
-
// mode: 'manual',
|
|
44
|
-
// } as TooltipContextValue;
|
|
45
|
-
|
|
46
|
-
export function getTooltipContext<T = any>() {
|
|
47
|
-
return _TooltipContext.get() as TooltipContextValue<T>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function setTooltipContext<T = any>(tooltip: TooltipContextValue<T>) {
|
|
51
|
-
return _TooltipContext.set(tooltip) as TooltipContextValue<T>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
18
|
type TooltipContextPropsWithoutHTML<T = any> = {
|
|
55
19
|
/**
|
|
56
20
|
* The tooltip interaction mode
|
|
@@ -136,9 +100,9 @@
|
|
|
136
100
|
import { sortFunc, localPoint } from '@layerstack/utils';
|
|
137
101
|
import { cls } from '@layerstack/tailwind';
|
|
138
102
|
|
|
139
|
-
import { getChartContext } from '
|
|
140
|
-
import { getGeoContext } from '
|
|
141
|
-
import Svg from './../
|
|
103
|
+
import { getChartContext } from '../../contexts/chart.js';
|
|
104
|
+
import { getGeoContext } from '../../contexts/geo.js';
|
|
105
|
+
import Svg from './../layers/Svg.svelte';
|
|
142
106
|
import Arc from '../Arc.svelte';
|
|
143
107
|
import ChartClipPath from './../ChartClipPath.svelte';
|
|
144
108
|
import Voronoi from './../Voronoi.svelte';
|
|
@@ -523,11 +487,13 @@
|
|
|
523
487
|
const xVal = ctx.x(d);
|
|
524
488
|
const start = ctx.xInterval.floor(xVal);
|
|
525
489
|
const end = ctx.xInterval.offset(start);
|
|
490
|
+
const xStart = ctx.xScale(start);
|
|
491
|
+
const xEnd = ctx.xScale(end);
|
|
526
492
|
|
|
527
493
|
return {
|
|
528
|
-
x:
|
|
494
|
+
x: Math.min(xStart, xEnd),
|
|
529
495
|
y: isScaleBand(ctx.yScale) ? y - yOffset : min(ctx.yRange),
|
|
530
|
-
width:
|
|
496
|
+
width: Math.abs(xEnd - xStart),
|
|
531
497
|
height: isScaleBand(ctx.yScale) ? ctx.yScale.step() : fullHeight,
|
|
532
498
|
data: d,
|
|
533
499
|
};
|
|
@@ -536,12 +502,14 @@
|
|
|
536
502
|
const yVal = ctx.y(d);
|
|
537
503
|
const start = ctx.yInterval.floor(yVal);
|
|
538
504
|
const end = ctx.yInterval.offset(start);
|
|
505
|
+
const yStart = ctx.yScale(start);
|
|
506
|
+
const yEnd = ctx.yScale(end);
|
|
539
507
|
|
|
540
508
|
return {
|
|
541
509
|
x: isScaleBand(ctx.xScale) ? x - xOffset : min(ctx.xRange),
|
|
542
|
-
y:
|
|
510
|
+
y: Math.min(yStart, yEnd),
|
|
543
511
|
width: isScaleBand(ctx.xScale) ? ctx.xScale.step() : fullWidth,
|
|
544
|
-
height:
|
|
512
|
+
height: Math.abs(yEnd - yStart),
|
|
545
513
|
data: d,
|
|
546
514
|
};
|
|
547
515
|
} else if (isScaleTime(ctx.xScale)) {
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
2
|
import type { Without } from '../../utils/types.js';
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
data: T | null;
|
|
8
|
-
payload: TooltipPayload[];
|
|
9
|
-
show(e: PointerEvent | MouseEvent | TouchEvent, tooltipData?: any, payload?: TooltipPayload): void;
|
|
10
|
-
hide(e?: PointerEvent): void;
|
|
11
|
-
mode: TooltipMode;
|
|
12
|
-
isHoveringTooltipArea: boolean;
|
|
13
|
-
isHoveringTooltipContent: boolean;
|
|
14
|
-
};
|
|
15
|
-
export declare function getTooltipContext<T = any>(): TooltipContextValue<T>;
|
|
3
|
+
import { type TooltipContextValue } from '../../contexts/tooltip.js';
|
|
4
|
+
export type TooltipMode = 'bisect-x' | 'bisect-y' | 'band' | 'bisect-band' | 'bounds' | 'voronoi' | 'quadtree' | 'quadtree-x' | 'quadtree-y' | 'manual';
|
|
16
5
|
type TooltipContextPropsWithoutHTML<T = any> = {
|
|
17
6
|
/**
|
|
18
7
|
* The tooltip interaction mode
|
|
@@ -81,7 +70,6 @@ type TooltipContextPropsWithoutHTML<T = any> = {
|
|
|
81
70
|
};
|
|
82
71
|
export type TooltipContextProps<T = any> = TooltipContextPropsWithoutHTML<T> & Without<HTMLAttributes<HTMLElement>, TooltipContextPropsWithoutHTML<T>>;
|
|
83
72
|
import type { Snippet } from 'svelte';
|
|
84
|
-
import { type TooltipPayload } from './tooltipMetaContext.js';
|
|
85
73
|
declare function $$render<TData = any>(): {
|
|
86
74
|
props: TooltipContextProps<TData>;
|
|
87
75
|
exports: {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
1
2
|
import { type Accessor } from '../../utils/common.js';
|
|
2
3
|
import type { SeriesData } from '../charts/index.js';
|
|
3
|
-
import type { ChartContextValue } from '
|
|
4
|
-
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
4
|
+
import type { ChartContextValue } from '../../contexts/chart.js';
|
|
5
5
|
export type SimplifiedChartType = 'bar' | 'area' | 'line' | 'pie' | 'scatter';
|
|
6
6
|
export type BarTooltipMetaContextValue = {
|
|
7
7
|
type: 'bar';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Additional meta data that can be set by the various simplified chart components
|
|
2
2
|
// to provide additional payload data to the tooltip for ease of composition.
|
|
3
|
+
import { Context } from 'runed';
|
|
4
|
+
import { format } from '@layerstack/utils';
|
|
3
5
|
import { accessor, findRelatedData } from '../../utils/common.js';
|
|
4
6
|
import { asAny } from '../../utils/types.js';
|
|
5
|
-
import { format } from '@layerstack/utils';
|
|
6
|
-
import { Context } from 'runed';
|
|
7
7
|
function handleBarTooltipPayload({ ctx, data, metaCtx, }) {
|
|
8
8
|
const seriesItems = metaCtx.stackSeries
|
|
9
9
|
? [...metaCtx.visibleSeries].reverse()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { MouseEventHandler, PointerEventHandler, TouchEventHandler } from 'svelte/elements';
|
|
2
|
+
import type { ComputedStylesOptions } from '../utils/canvas.js';
|
|
3
|
+
export type ComponentRender<T extends Element = Element> = {
|
|
4
|
+
name: string;
|
|
5
|
+
render: (ctx: CanvasRenderingContext2D, styleOverrides?: ComputedStylesOptions) => any;
|
|
6
|
+
retainState?: boolean;
|
|
7
|
+
events?: {
|
|
8
|
+
click?: MouseEventHandler<T> | null;
|
|
9
|
+
dblclick?: MouseEventHandler<T> | null;
|
|
10
|
+
pointerenter?: PointerEventHandler<T> | null;
|
|
11
|
+
pointerover?: PointerEventHandler<T> | null;
|
|
12
|
+
pointermove?: PointerEventHandler<T> | null;
|
|
13
|
+
pointerleave?: PointerEventHandler<T> | null;
|
|
14
|
+
pointerout?: PointerEventHandler<T> | null;
|
|
15
|
+
pointerdown?: PointerEventHandler<T> | null;
|
|
16
|
+
touchmove?: TouchEventHandler<T> | null;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Optional dependencies to track and invalidate the canvas context when they change.
|
|
20
|
+
*/
|
|
21
|
+
deps?: () => any[];
|
|
22
|
+
};
|
|
23
|
+
export type CanvasContextValue = {
|
|
24
|
+
/**
|
|
25
|
+
* Register component to render.
|
|
26
|
+
*
|
|
27
|
+
* Returns method to unregister on component destroy
|
|
28
|
+
*/
|
|
29
|
+
register<T extends Element>(component: ComponentRender<T>): () => void;
|
|
30
|
+
invalidate(): void;
|
|
31
|
+
};
|
|
32
|
+
export declare function getCanvasContext(): CanvasContextValue;
|
|
33
|
+
export declare function setCanvasContext(context: CanvasContextValue): CanvasContextValue;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Context } from 'runed';
|
|
2
|
+
const CanvasContext = new Context('CanvasContext');
|
|
3
|
+
const defaultCanvasContext = {
|
|
4
|
+
register: (_) => {
|
|
5
|
+
return () => { };
|
|
6
|
+
},
|
|
7
|
+
invalidate: () => { },
|
|
8
|
+
};
|
|
9
|
+
export function getCanvasContext() {
|
|
10
|
+
return CanvasContext.getOr(defaultCanvasContext);
|
|
11
|
+
}
|
|
12
|
+
export function setCanvasContext(context) {
|
|
13
|
+
return CanvasContext.set(context);
|
|
14
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { TimeInterval } from 'd3-time';
|
|
2
|
+
import type { AxisKey, DataType, Extents, Nice, Padding, PaddingArray, XRangeWithScale, YRangeWithScale } from '../utils/types.js';
|
|
3
|
+
import { type AnyScale, type DomainType } from '../utils/scales.svelte.js';
|
|
4
|
+
import type { GeoContextValue } from './geo.js';
|
|
5
|
+
import type { TooltipContextValue } from './tooltip.js';
|
|
6
|
+
import type { TransformContextValue } from './transform.js';
|
|
7
|
+
import type { BrushContextValue } from '../components/BrushContext.svelte';
|
|
8
|
+
import type { PreservedChartConfig } from '../components/Chart.svelte';
|
|
9
|
+
export type ChartContextValue<T = any, XScale extends AnyScale = AnyScale, YScale extends AnyScale = AnyScale> = {
|
|
10
|
+
activeGetters: Record<AxisKey, (d: T) => any>;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
percentRange: boolean;
|
|
14
|
+
aspectRatio: number;
|
|
15
|
+
containerRef: HTMLElement | undefined;
|
|
16
|
+
containerWidth: number;
|
|
17
|
+
containerHeight: number;
|
|
18
|
+
config: PreservedChartConfig<T, XScale, YScale>;
|
|
19
|
+
x: (d: T) => any;
|
|
20
|
+
y: (d: T) => any;
|
|
21
|
+
z: (d: T) => any;
|
|
22
|
+
r: (d: T) => any;
|
|
23
|
+
x1: (d: T) => any;
|
|
24
|
+
y1: (d: T) => any;
|
|
25
|
+
c: (d: T) => any;
|
|
26
|
+
data: DataType<T>;
|
|
27
|
+
xNice: Nice;
|
|
28
|
+
yNice: Nice;
|
|
29
|
+
zNice: Nice;
|
|
30
|
+
rNice: Nice;
|
|
31
|
+
xDomainSort: boolean;
|
|
32
|
+
yDomainSort: boolean;
|
|
33
|
+
zDomainSort: boolean;
|
|
34
|
+
rDomainSort: boolean;
|
|
35
|
+
xReverse: boolean;
|
|
36
|
+
yReverse: boolean;
|
|
37
|
+
zReverse: boolean;
|
|
38
|
+
rReverse: boolean;
|
|
39
|
+
xPadding: PaddingArray;
|
|
40
|
+
yPadding: PaddingArray;
|
|
41
|
+
zPadding: PaddingArray;
|
|
42
|
+
rPadding: PaddingArray;
|
|
43
|
+
padding: Padding;
|
|
44
|
+
flatData: T[];
|
|
45
|
+
extents: Extents;
|
|
46
|
+
xDomain: number[];
|
|
47
|
+
yDomain: number[];
|
|
48
|
+
zDomain: DomainType;
|
|
49
|
+
rDomain: DomainType;
|
|
50
|
+
cDomain: DomainType;
|
|
51
|
+
x1Domain: DomainType;
|
|
52
|
+
y1Domain: DomainType;
|
|
53
|
+
xRange: any[];
|
|
54
|
+
yRange: any[];
|
|
55
|
+
zRange: any[];
|
|
56
|
+
rRange: any[];
|
|
57
|
+
cRange: readonly string[] | string[] | undefined;
|
|
58
|
+
x1Range: XRangeWithScale<XScale> | undefined;
|
|
59
|
+
y1Range: YRangeWithScale<YScale> | undefined;
|
|
60
|
+
meta: Record<string, any>;
|
|
61
|
+
xScale: AnyScale;
|
|
62
|
+
yScale: AnyScale;
|
|
63
|
+
zScale: AnyScale;
|
|
64
|
+
rScale: AnyScale;
|
|
65
|
+
cScale: AnyScale | null;
|
|
66
|
+
x1Scale: AnyScale | null;
|
|
67
|
+
y1Scale: AnyScale | null;
|
|
68
|
+
yGet: (d: T) => any;
|
|
69
|
+
xGet: (d: T) => any;
|
|
70
|
+
zGet: (d: T) => any;
|
|
71
|
+
rGet: (d: T) => any;
|
|
72
|
+
cGet: (d: T) => any;
|
|
73
|
+
x1Get: (d: T) => any;
|
|
74
|
+
y1Get: (d: T) => any;
|
|
75
|
+
xInterval: TimeInterval | null;
|
|
76
|
+
yInterval: TimeInterval | null;
|
|
77
|
+
radial: boolean;
|
|
78
|
+
tooltip: TooltipContextValue<T>;
|
|
79
|
+
geo: GeoContextValue;
|
|
80
|
+
brush: BrushContextValue;
|
|
81
|
+
transform: TransformContextValue;
|
|
82
|
+
};
|
|
83
|
+
export declare function getChartContext<T, XScale extends AnyScale = AnyScale, YScale extends AnyScale = AnyScale>(): ChartContextValue<T, XScale, YScale>;
|
|
84
|
+
export declare function setChartContext<T, XScale extends AnyScale = AnyScale, YScale extends AnyScale = AnyScale>(context: ChartContextValue<T, XScale, YScale>): ChartContextValue<T, XScale, YScale>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from 'runed';
|
|
2
|
+
import {} from '../utils/scales.svelte.js';
|
|
3
|
+
const _ChartContext = new Context('ChartContext');
|
|
4
|
+
export function getChartContext() {
|
|
5
|
+
return _ChartContext.getOr({});
|
|
6
|
+
}
|
|
7
|
+
export function setChartContext(context) {
|
|
8
|
+
// @ts-expect-error - shh
|
|
9
|
+
return _ChartContext.set(context);
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Context } from 'runed';
|
|
2
|
+
import {} from 'd3-geo';
|
|
3
|
+
/**
|
|
4
|
+
* Access or set the current GeoContext.
|
|
5
|
+
*/
|
|
6
|
+
const _GeoContext = new Context('GeoContext');
|
|
7
|
+
export function getGeoContext() {
|
|
8
|
+
return _GeoContext.getOr({ projection: undefined });
|
|
9
|
+
}
|
|
10
|
+
export function setGeoContext(geo) {
|
|
11
|
+
return _GeoContext.set(geo);
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from 'runed';
|
|
2
|
+
import { Settings, defaultSettings } from '../states/settings.svelte.js';
|
|
3
|
+
const _SettingsContext = new Context('Settings');
|
|
4
|
+
/** Get the current settings context, or default if not set */
|
|
5
|
+
export function getSettings() {
|
|
6
|
+
return _SettingsContext.getOr(defaultSettings);
|
|
7
|
+
}
|
|
8
|
+
export function setSettings(settings) {
|
|
9
|
+
return _SettingsContext.set(new Settings(settings));
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TooltipPayload } from '../components/tooltip/tooltipMetaContext.js';
|
|
2
|
+
import type { TooltipMode } from '../components/tooltip/TooltipContext.svelte';
|
|
3
|
+
export type TooltipContextValue<T = any> = {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
data: T | null;
|
|
7
|
+
payload: TooltipPayload[];
|
|
8
|
+
show(e: PointerEvent | MouseEvent | TouchEvent, tooltipData?: any, payload?: TooltipPayload): void;
|
|
9
|
+
hide(e?: PointerEvent): void;
|
|
10
|
+
mode: TooltipMode;
|
|
11
|
+
isHoveringTooltipArea: boolean;
|
|
12
|
+
isHoveringTooltipContent: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function getTooltipContext<T = any>(): TooltipContextValue<T>;
|
|
15
|
+
export declare function setTooltipContext<T = any>(tooltip: TooltipContextValue<T>): TooltipContextValue<T>;
|