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
|
@@ -64,7 +64,7 @@ export let track = false;
|
|
|
64
64
|
const { yRange } = chartContext();
|
|
65
65
|
$: scale = scaleLinear().domain(domain).range(range);
|
|
66
66
|
function getOuterRadius(outerRadius, chartRadius) {
|
|
67
|
-
if (outerRadius
|
|
67
|
+
if (!outerRadius) {
|
|
68
68
|
return chartRadius;
|
|
69
69
|
}
|
|
70
70
|
else if (outerRadius > 1) {
|
|
@@ -149,6 +149,14 @@ export let offset = 0;
|
|
|
149
149
|
$: angle = ((startAngle ?? 0) + (endAngle ?? 0)) / 2;
|
|
150
150
|
$: xOffset = Math.sin(angle) * offset;
|
|
151
151
|
$: yOffset = -Math.cos(angle) * offset;
|
|
152
|
+
/**
|
|
153
|
+
* Tooltip context to setup pointer events to show tooltip for related data. Must set `data` prop as well
|
|
154
|
+
*/
|
|
155
|
+
export let tooltip = undefined;
|
|
156
|
+
/**
|
|
157
|
+
* Data to set when showing tooltip
|
|
158
|
+
*/
|
|
159
|
+
export let data = undefined;
|
|
152
160
|
</script>
|
|
153
161
|
|
|
154
162
|
{#if track}
|
|
@@ -165,6 +173,15 @@ $: yOffset = -Math.cos(angle) * offset;
|
|
|
165
173
|
d={arc()}
|
|
166
174
|
transform="translate({xOffset}, {yOffset})"
|
|
167
175
|
{...$$restProps}
|
|
176
|
+
on:pointerenter={(e) => tooltip?.show(e, data)}
|
|
177
|
+
on:pointermove={(e) => tooltip?.show(e, data)}
|
|
178
|
+
on:pointerleave={(e) => tooltip?.hide()}
|
|
179
|
+
on:touchmove={(e) => {
|
|
180
|
+
if (tooltip) {
|
|
181
|
+
// Prevent touch to not interfer with pointer when using tooltip
|
|
182
|
+
e.preventDefault();
|
|
183
|
+
}
|
|
184
|
+
}}
|
|
168
185
|
on:click
|
|
169
186
|
on:pointerenter
|
|
170
187
|
on:pointermove
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import type { SVGAttributes } from 'svelte/elements';
|
|
3
3
|
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
4
|
+
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
4
5
|
declare const __propDef: {
|
|
5
6
|
props: {
|
|
6
7
|
[x: string]: any;
|
|
@@ -18,6 +19,8 @@ declare const __propDef: {
|
|
|
18
19
|
padAngle?: number | undefined;
|
|
19
20
|
track?: (boolean | SVGAttributes<SVGPathElement>) | undefined;
|
|
20
21
|
offset?: number | undefined;
|
|
22
|
+
tooltip?: TooltipContextValue | undefined;
|
|
23
|
+
data?: any;
|
|
21
24
|
};
|
|
22
25
|
events: {
|
|
23
26
|
click: MouseEvent;
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
<script>import {} from 'svelte';
|
|
2
2
|
import { area as d3Area, areaRadial } from 'd3-shape';
|
|
3
|
-
import { max } from 'd3-array';
|
|
3
|
+
import { max, min } from 'd3-array';
|
|
4
4
|
import { interpolatePath } from 'd3-interpolate-path';
|
|
5
|
-
import { cls } from '
|
|
5
|
+
import { cls } from '@layerstack/tailwind';
|
|
6
6
|
import { motionStore } from '../stores/motionStore.js';
|
|
7
7
|
import { chartContext } from './ChartContext.svelte';
|
|
8
8
|
import Spline from './Spline.svelte';
|
|
9
9
|
import { accessor } from '../utils/common.js';
|
|
10
10
|
import { isScaleBand } from '../utils/scales.js';
|
|
11
|
-
const { data: contextData, xScale, yScale,
|
|
11
|
+
const { data: contextData, xScale, yScale, x: contextX, y, yDomain, yRange, config, radial, } = chartContext();
|
|
12
12
|
/** Override data instead of using context */
|
|
13
13
|
export let data = undefined;
|
|
14
14
|
/** Pass `<path d={...} />` explicitly instead of calculating from data / context */
|
|
15
15
|
export let pathData = undefined;
|
|
16
|
-
/** Use radial instead of cartesian area generator, mapping `x` to `angle` and `y0`/`y1 to `innerRadius`/`outerRadius. Radial lines are positioned relative to the origin, use transform (ex. `<Group center>`) to change the origin */
|
|
17
|
-
export let radial = false;
|
|
18
16
|
/** Override x accessor */
|
|
19
17
|
export let x = undefined;
|
|
20
18
|
/** Override y0 accessor. Defaults to max($yRange) */
|
|
@@ -28,9 +26,9 @@ export let curve = undefined;
|
|
|
28
26
|
export let defined = undefined;
|
|
29
27
|
/** Enable showing line */
|
|
30
28
|
export let line = false;
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
29
|
+
const xAccessor = x ? accessor(x) : $contextX;
|
|
30
|
+
const y0Accessor = y0 ? accessor(y0) : (d) => min($yDomain);
|
|
31
|
+
const y1Accessor = y1 ? accessor(y1) : $y;
|
|
34
32
|
$: xOffset = isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0;
|
|
35
33
|
$: yOffset = isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0;
|
|
36
34
|
$: tweenedOptions = tweened
|
|
@@ -38,26 +36,59 @@ $: tweenedOptions = tweened
|
|
|
38
36
|
: false;
|
|
39
37
|
$: tweened_d = motionStore('', { tweened: tweenedOptions });
|
|
40
38
|
$: {
|
|
41
|
-
const path = radial
|
|
39
|
+
const path = $radial
|
|
42
40
|
? areaRadial()
|
|
43
|
-
.angle((d) =>
|
|
44
|
-
.innerRadius((d) =>
|
|
45
|
-
.outerRadius((d) =>
|
|
41
|
+
.angle((d) => $xScale(xAccessor(d)))
|
|
42
|
+
.innerRadius((d) => $yScale(y0Accessor(d)))
|
|
43
|
+
.outerRadius((d) => $yScale(y1Accessor(d)))
|
|
46
44
|
: d3Area()
|
|
47
|
-
.x((d) =>
|
|
48
|
-
.y0((d) =>
|
|
49
|
-
|
|
45
|
+
.x((d) => $xScale(xAccessor(d)) + xOffset)
|
|
46
|
+
.y0((d) => {
|
|
47
|
+
let value = max($yRange);
|
|
48
|
+
if (y0) {
|
|
49
|
+
value = $yScale(y0Accessor(d));
|
|
50
|
+
}
|
|
51
|
+
else if (Array.isArray($config.y) && $config.y[0] === 0) {
|
|
52
|
+
// Use first value if `y` defined as an array (ex. `<Chart y={[0,1]}>`)
|
|
53
|
+
// TODO: Would be nice if this also handled multi-series (<Chart y={['apples', 'bananas', 'oranges']}>) as well as delta values (<Chart y={['baseline', 'value']}>)
|
|
54
|
+
value = $yScale($y(d)[0]);
|
|
55
|
+
}
|
|
56
|
+
return value + yOffset;
|
|
57
|
+
})
|
|
58
|
+
.y1((d) => {
|
|
59
|
+
let value = max($yRange);
|
|
60
|
+
if (y1) {
|
|
61
|
+
value = $yScale(y1Accessor(d));
|
|
62
|
+
}
|
|
63
|
+
else if (Array.isArray($config.y) && $config.y[1] === 1) {
|
|
64
|
+
// Use second value if `y` defined as an array (ex. `<Chart y={[0,1]}>`)
|
|
65
|
+
// TODO: Would be nice if this also handled multi-series (<Chart y={['apples', 'bananas', 'oranges']}>) as well as delta values (<Chart y={['baseline', 'value']}>)
|
|
66
|
+
value = $yScale($y(d)[1]);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// Expect single value defined for `y` (ex. `<Chart y="value">`)
|
|
70
|
+
value = $yScale($y(d));
|
|
71
|
+
}
|
|
72
|
+
return value + yOffset;
|
|
73
|
+
});
|
|
74
|
+
path.defined(defined ?? ((d) => xAccessor(d) != null && y1Accessor(d) != null));
|
|
50
75
|
if (curve)
|
|
51
76
|
path.curve(curve);
|
|
52
|
-
if (defined)
|
|
53
|
-
path.defined(defined);
|
|
54
77
|
const d = pathData ?? path(data ?? $contextData);
|
|
55
78
|
tweened_d.set(d ?? '');
|
|
56
79
|
}
|
|
57
80
|
</script>
|
|
58
81
|
|
|
59
82
|
{#if line}
|
|
60
|
-
<Spline
|
|
83
|
+
<Spline
|
|
84
|
+
{data}
|
|
85
|
+
{x}
|
|
86
|
+
y={y1}
|
|
87
|
+
{curve}
|
|
88
|
+
{defined}
|
|
89
|
+
{tweened}
|
|
90
|
+
{...typeof line === 'object' ? line : null}
|
|
91
|
+
/>
|
|
61
92
|
{/if}
|
|
62
93
|
|
|
63
94
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
@@ -3,7 +3,8 @@ import { fade } from 'svelte/transition';
|
|
|
3
3
|
import { cubicIn } from 'svelte/easing';
|
|
4
4
|
import { extent } from 'd3-array';
|
|
5
5
|
import { pointRadial } from 'd3-shape';
|
|
6
|
-
import { format as formatValue
|
|
6
|
+
import { format as formatValue } from '@layerstack/utils';
|
|
7
|
+
import { cls } from '@layerstack/tailwind';
|
|
7
8
|
import { chartContext } from './ChartContext.svelte';
|
|
8
9
|
import Circle from './Circle.svelte';
|
|
9
10
|
import Line from './Line.svelte';
|
|
@@ -3,7 +3,8 @@ import { type ComponentProps } from 'svelte';
|
|
|
3
3
|
import { fade } from 'svelte/transition';
|
|
4
4
|
import type { SVGAttributes } from 'svelte/elements';
|
|
5
5
|
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
6
|
-
import { type FormatType
|
|
6
|
+
import { type FormatType } from '@layerstack/utils';
|
|
7
|
+
import type { TransitionParams } from 'svelte-ux';
|
|
7
8
|
import Text from './Text.svelte';
|
|
8
9
|
import { type AnyScale } from '../utils/scales.js';
|
|
9
10
|
declare const __propDef: {
|
|
@@ -13,6 +13,14 @@ export let x = $xContext;
|
|
|
13
13
|
* Override `y` from context. Useful for multiple Bar instances
|
|
14
14
|
*/
|
|
15
15
|
export let y = $yContext;
|
|
16
|
+
/**
|
|
17
|
+
* Override `x1` from context. Useful for multiple Bar instances
|
|
18
|
+
*/
|
|
19
|
+
export let x1 = undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Override `y1` from context. Useful for multiple Bar instances
|
|
22
|
+
*/
|
|
23
|
+
export let y1 = undefined;
|
|
16
24
|
export let fill = undefined;
|
|
17
25
|
export let stroke = 'black';
|
|
18
26
|
export let strokeWidth = 0;
|
|
@@ -20,9 +28,6 @@ export let radius = 0;
|
|
|
20
28
|
/** Control which corners are rounded with radius. Uses <path> instead of <rect> when not set to `all` */
|
|
21
29
|
export let rounded = 'all';
|
|
22
30
|
export let inset = 0;
|
|
23
|
-
export let groupBy = undefined;
|
|
24
|
-
export let groupPaddingInner = 0.2;
|
|
25
|
-
export let groupPaddingOuter = 0;
|
|
26
31
|
export let spring = undefined;
|
|
27
32
|
export let tweened = undefined;
|
|
28
33
|
$: if (stroke === null || stroke === undefined)
|
|
@@ -30,12 +35,9 @@ $: if (stroke === null || stroke === undefined)
|
|
|
30
35
|
$: getDimensions = createDimensionGetter(chartContext(), {
|
|
31
36
|
x,
|
|
32
37
|
y,
|
|
33
|
-
|
|
38
|
+
x1,
|
|
39
|
+
y1,
|
|
34
40
|
inset,
|
|
35
|
-
groupPadding: {
|
|
36
|
-
inner: groupPaddingInner,
|
|
37
|
-
outer: groupPaddingOuter,
|
|
38
|
-
},
|
|
39
41
|
});
|
|
40
42
|
$: dimensions = $getDimensions(bar) ?? { x: 0, y: 0, width: 0, height: 0 };
|
|
41
43
|
$: topLeft = ['all', 'top', 'left', 'top-left'].includes(rounded);
|
|
@@ -69,6 +71,10 @@ $: pathData = `M${dimensions.x + radius},${dimensions.y} h${width - diameter}
|
|
|
69
71
|
{...dimensions}
|
|
70
72
|
{...$$restProps}
|
|
71
73
|
on:click
|
|
74
|
+
on:pointerenter
|
|
75
|
+
on:pointermove
|
|
76
|
+
on:pointerleave
|
|
77
|
+
on:touchmove
|
|
72
78
|
/>
|
|
73
79
|
{:else}
|
|
74
80
|
<Spline
|
|
@@ -80,5 +86,9 @@ $: pathData = `M${dimensions.x + radius},${dimensions.y} h${width - diameter}
|
|
|
80
86
|
stroke-width={strokeWidth}
|
|
81
87
|
{...$$restProps}
|
|
82
88
|
on:click
|
|
89
|
+
on:pointerenter
|
|
90
|
+
on:pointermove
|
|
91
|
+
on:pointerleave
|
|
92
|
+
on:touchmove
|
|
83
93
|
/>
|
|
84
94
|
{/if}
|
|
@@ -8,20 +8,23 @@ declare const __propDef: {
|
|
|
8
8
|
bar: Object;
|
|
9
9
|
x?: Accessor;
|
|
10
10
|
y?: Accessor;
|
|
11
|
+
x1?: Accessor;
|
|
12
|
+
y1?: Accessor;
|
|
11
13
|
fill?: string | undefined;
|
|
12
14
|
stroke?: string | undefined;
|
|
13
15
|
strokeWidth?: number | undefined;
|
|
14
16
|
radius?: number | undefined;
|
|
15
17
|
rounded?: ("all" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
|
|
16
18
|
inset?: number | undefined;
|
|
17
|
-
groupBy?: string | undefined;
|
|
18
|
-
groupPaddingInner?: number | undefined;
|
|
19
|
-
groupPaddingOuter?: number | undefined;
|
|
20
19
|
spring?: ComponentProps<Rect>["spring"];
|
|
21
20
|
tweened?: ComponentProps<Rect>["tweened"];
|
|
22
21
|
};
|
|
23
22
|
events: {
|
|
24
23
|
click: MouseEvent;
|
|
24
|
+
pointerenter: PointerEvent;
|
|
25
|
+
pointermove: PointerEvent;
|
|
26
|
+
pointerleave: PointerEvent;
|
|
27
|
+
touchmove: CustomEvent<any>;
|
|
25
28
|
} & {
|
|
26
29
|
[evt: string]: CustomEvent<any>;
|
|
27
30
|
};
|
|
@@ -3,7 +3,11 @@ import { chartContext } from './ChartContext.svelte';
|
|
|
3
3
|
import Bar from './Bar.svelte';
|
|
4
4
|
import Rect from './Rect.svelte';
|
|
5
5
|
import { chartDataArray } from '../utils/common.js';
|
|
6
|
-
const { data,
|
|
6
|
+
const { data: contextData, cGet, config } = chartContext();
|
|
7
|
+
/**
|
|
8
|
+
* Override `data` from context. Useful for multiple Bar instances
|
|
9
|
+
*/
|
|
10
|
+
export let data = undefined;
|
|
7
11
|
/**
|
|
8
12
|
* Override `x` from context. Useful for multiple Bar instances
|
|
9
13
|
*/
|
|
@@ -12,6 +16,14 @@ export let x = undefined;
|
|
|
12
16
|
* Override `y` from context. Useful for multiple Bar instances
|
|
13
17
|
*/
|
|
14
18
|
export let y = undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Override `x1` from context. Useful for multiple Bar instances
|
|
21
|
+
*/
|
|
22
|
+
export let x1 = undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Override `y1` from context. Useful for multiple Bar instances
|
|
25
|
+
*/
|
|
26
|
+
export let y1 = undefined;
|
|
15
27
|
export let stroke = 'black';
|
|
16
28
|
export let strokeWidth = 0;
|
|
17
29
|
export let radius = 0;
|
|
@@ -19,29 +31,24 @@ export let radius = 0;
|
|
|
19
31
|
export let inset = 0;
|
|
20
32
|
export let spring = undefined;
|
|
21
33
|
export let tweened = undefined;
|
|
22
|
-
// See: https://svelte.dev/repl/7000c5ce05b84cd98ccbfb2768b4be3d?version=3.38.3
|
|
23
|
-
export let groupBy = undefined;
|
|
24
|
-
export let groupPaddingInner = 0.2;
|
|
25
|
-
export let groupPaddingOuter = 0;
|
|
26
34
|
</script>
|
|
27
35
|
|
|
28
36
|
<g class="Bars">
|
|
29
37
|
<slot>
|
|
30
|
-
{#each chartDataArray($
|
|
38
|
+
{#each chartDataArray(data ?? $contextData) as item}
|
|
31
39
|
<Bar
|
|
32
40
|
bar={item}
|
|
33
41
|
{x}
|
|
34
42
|
{y}
|
|
35
|
-
|
|
43
|
+
{x1}
|
|
44
|
+
{y1}
|
|
45
|
+
fill={$config.c ? $cGet(item) : null}
|
|
36
46
|
{stroke}
|
|
37
47
|
{strokeWidth}
|
|
38
48
|
{radius}
|
|
49
|
+
{inset}
|
|
39
50
|
{spring}
|
|
40
51
|
{tweened}
|
|
41
|
-
{groupBy}
|
|
42
|
-
{inset}
|
|
43
|
-
{groupPaddingInner}
|
|
44
|
-
{groupPaddingOuter}
|
|
45
52
|
{...$$restProps}
|
|
46
53
|
/>
|
|
47
54
|
{/each}
|
|
@@ -5,17 +5,17 @@ import { type Accessor } from '../utils/common.js';
|
|
|
5
5
|
declare const __propDef: {
|
|
6
6
|
props: {
|
|
7
7
|
[x: string]: any;
|
|
8
|
+
data?: any;
|
|
8
9
|
x?: Accessor;
|
|
9
10
|
y?: Accessor;
|
|
11
|
+
x1?: Accessor;
|
|
12
|
+
y1?: Accessor;
|
|
10
13
|
stroke?: string | undefined;
|
|
11
14
|
strokeWidth?: number | undefined;
|
|
12
15
|
radius?: number | undefined;
|
|
13
16
|
inset?: number | undefined;
|
|
14
17
|
spring?: ComponentProps<Rect>["spring"];
|
|
15
18
|
tweened?: ComponentProps<Rect>["tweened"];
|
|
16
|
-
groupBy?: string | undefined;
|
|
17
|
-
groupPaddingInner?: number | undefined;
|
|
18
|
-
groupPaddingOuter?: number | undefined;
|
|
19
19
|
};
|
|
20
20
|
events: {
|
|
21
21
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script>import { createEventDispatcher } from 'svelte';
|
|
2
2
|
import { extent } from 'd3-array';
|
|
3
|
-
import { clamp
|
|
3
|
+
import { clamp } from '@layerstack/utils';
|
|
4
|
+
import { cls } from '@layerstack/tailwind';
|
|
4
5
|
import { chartContext } from './ChartContext.svelte';
|
|
5
6
|
import Frame from './Frame.svelte';
|
|
6
7
|
import { localPoint } from '../utils/event.js';
|
|
@@ -19,7 +19,7 @@ export let monthPath = false;
|
|
|
19
19
|
* Tooltip context to setup mouse events to show tooltip for related data
|
|
20
20
|
*/
|
|
21
21
|
export let tooltip = undefined;
|
|
22
|
-
const { width, height, x,
|
|
22
|
+
const { width, height, x, cGet, data, config } = chartContext();
|
|
23
23
|
$: yearDays = timeDays(start, end);
|
|
24
24
|
$: yearMonths = timeMonths(start, end);
|
|
25
25
|
$: yearWeeks = timeWeek.count(start, end);
|
|
@@ -37,7 +37,7 @@ $: cells = yearDays.map((date) => {
|
|
|
37
37
|
return {
|
|
38
38
|
x: timeWeek.count(timeYear(date), date) * cellWidth,
|
|
39
39
|
y: date.getDay() * cellHeight,
|
|
40
|
-
color: $config.
|
|
40
|
+
color: $config.c ? $cGet(cellData) : 'transparent',
|
|
41
41
|
data: cellData,
|
|
42
42
|
};
|
|
43
43
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import { type ComponentProps } from 'svelte';
|
|
3
|
-
import type { TooltipContextValue } from './TooltipContext.svelte';
|
|
3
|
+
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
4
4
|
import MonthPath from './MonthPath.svelte';
|
|
5
5
|
declare const __propDef: {
|
|
6
6
|
props: {
|
|
@@ -1,34 +1,31 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
// TODO: Workaround for sveld error: `Cannot read properties of null (reading 'type')` in `ComponentParser`
|
|
4
|
-
// See: https://github.com/carbon-design-system/sveld/issues/104
|
|
5
|
-
import { LayerCake,
|
|
6
|
-
// Canvas as _Canvas,
|
|
7
|
-
// Html as _Html,
|
|
8
|
-
// Svg as _Svg,
|
|
9
|
-
WebGL as _WebGL, } from 'layercake';
|
|
10
|
-
import _Canvas from './layout/Canvas.svelte';
|
|
11
|
-
import _Html from './layout/Html.svelte';
|
|
12
|
-
import _Svg from './layout/Svg.svelte';
|
|
13
|
-
export const Canvas = _Canvas;
|
|
14
|
-
export const Html = _Html;
|
|
15
|
-
export const Svg = _Svg;
|
|
16
|
-
export const WebGL = _WebGL;
|
|
17
|
-
</script>
|
|
18
|
-
|
|
19
|
-
<script generics="TData">import { accessor } from '../utils/common.js';
|
|
20
|
-
import { onMount } from 'svelte';
|
|
1
|
+
<script generics="TData">import { onMount } from 'svelte';
|
|
2
|
+
import { LayerCake } from 'layercake';
|
|
21
3
|
import { max, min } from 'd3-array';
|
|
22
|
-
import { isScaleBand } from '../utils/scales.js';
|
|
23
4
|
import ChartContext from './ChartContext.svelte';
|
|
24
5
|
import GeoContext from './GeoContext.svelte';
|
|
25
|
-
import TooltipContext from './TooltipContext.svelte';
|
|
6
|
+
import TooltipContext from './tooltip/TooltipContext.svelte';
|
|
26
7
|
import TransformContext from './TransformContext.svelte';
|
|
8
|
+
import { accessor } from '../utils/common.js';
|
|
9
|
+
import { isScaleBand } from '../utils/scales.js';
|
|
27
10
|
import { geoFitObjectTransform } from '../utils/geo.js';
|
|
28
11
|
export let data = [];
|
|
29
12
|
export let x = undefined;
|
|
13
|
+
export let xRange = undefined;
|
|
30
14
|
export let y = undefined;
|
|
31
15
|
export let yScale = undefined;
|
|
16
|
+
export let yRange = undefined;
|
|
17
|
+
export let x1 = undefined;
|
|
18
|
+
export let x1Scale = undefined;
|
|
19
|
+
export let x1Domain = undefined;
|
|
20
|
+
export let x1Range = undefined;
|
|
21
|
+
export let y1 = undefined;
|
|
22
|
+
export let y1Scale = undefined;
|
|
23
|
+
export let y1Domain = undefined;
|
|
24
|
+
export let y1Range = undefined;
|
|
25
|
+
export let c = undefined;
|
|
26
|
+
export let cScale = undefined;
|
|
27
|
+
export let cDomain = undefined;
|
|
28
|
+
export let cRange = undefined;
|
|
32
29
|
/**
|
|
33
30
|
* x value guaranteed to be visible in xDomain. Useful with optional negative values since `xDomain={[0, null]}` would ignore negative values
|
|
34
31
|
*/
|
|
@@ -53,6 +50,8 @@ $: if (yBaseline != null && Array.isArray(data)) {
|
|
|
53
50
|
* see: https://github.com/mhkeller/layercake/issues/83
|
|
54
51
|
*/
|
|
55
52
|
$: yReverse = yScale ? !isScaleBand(yScale) : true;
|
|
53
|
+
/** Use radial instead of cartesian coordinates, mapping `x` to `angle` and `y`` to radial. Radial lines are positioned relative to the origin, use transform (ex. `<Group center>`) to change the origin */
|
|
54
|
+
export let radial = false;
|
|
56
55
|
/** Props passed to GeoContext */
|
|
57
56
|
export let geo = undefined;
|
|
58
57
|
/** Props passed to TooltipContext */
|
|
@@ -69,16 +68,31 @@ let isMounted = false;
|
|
|
69
68
|
onMount(() => {
|
|
70
69
|
isMounted = true;
|
|
71
70
|
});
|
|
71
|
+
// TODO: Hacks until LayerCake has better typings (`Accessor<TData>`)
|
|
72
|
+
$: _x = x;
|
|
73
|
+
$: _y = y;
|
|
74
|
+
$: _yRange =
|
|
75
|
+
yRange ??
|
|
76
|
+
(radial
|
|
77
|
+
? ({ height }) => [0, height / 2]
|
|
78
|
+
: undefined);
|
|
72
79
|
</script>
|
|
73
80
|
|
|
81
|
+
<!-- Remove domain sorting by default: https://github.com/mhkeller/layercake/issues/147 -->
|
|
74
82
|
<LayerCake
|
|
75
83
|
{data}
|
|
76
|
-
{
|
|
84
|
+
x={_x}
|
|
77
85
|
{xDomain}
|
|
78
|
-
{
|
|
86
|
+
xRange={xRange ?? (radial ? [0, 2 * Math.PI] : undefined)}
|
|
87
|
+
y={_y}
|
|
79
88
|
{yScale}
|
|
80
89
|
{yDomain}
|
|
90
|
+
yRange={_yRange}
|
|
81
91
|
{yReverse}
|
|
92
|
+
xDomainSort={false}
|
|
93
|
+
yDomainSort={false}
|
|
94
|
+
zDomainSort={false}
|
|
95
|
+
rDomainSort={false}
|
|
82
96
|
{...$$restProps}
|
|
83
97
|
let:aspectRatio
|
|
84
98
|
let:containerHeight
|
|
@@ -86,12 +100,16 @@ onMount(() => {
|
|
|
86
100
|
let:height
|
|
87
101
|
let:width
|
|
88
102
|
let:element
|
|
103
|
+
let:x
|
|
89
104
|
let:xScale
|
|
90
105
|
let:xGet
|
|
106
|
+
let:y
|
|
91
107
|
let:yScale
|
|
92
108
|
let:yGet
|
|
109
|
+
let:z
|
|
93
110
|
let:zScale
|
|
94
111
|
let:zGet
|
|
112
|
+
let:r
|
|
95
113
|
let:rScale
|
|
96
114
|
let:rGet
|
|
97
115
|
let:padding
|
|
@@ -102,7 +120,35 @@ onMount(() => {
|
|
|
102
120
|
? geoFitObjectTransform(geo.projection(), [width, height], geo.fitGeojson)
|
|
103
121
|
: undefined}
|
|
104
122
|
|
|
105
|
-
<ChartContext
|
|
123
|
+
<ChartContext
|
|
124
|
+
{data}
|
|
125
|
+
{radial}
|
|
126
|
+
{x1}
|
|
127
|
+
{x1Scale}
|
|
128
|
+
{x1Domain}
|
|
129
|
+
{x1Range}
|
|
130
|
+
{y1}
|
|
131
|
+
{y1Scale}
|
|
132
|
+
{y1Domain}
|
|
133
|
+
{y1Range}
|
|
134
|
+
{c}
|
|
135
|
+
{cScale}
|
|
136
|
+
{cDomain}
|
|
137
|
+
{cRange}
|
|
138
|
+
let:data
|
|
139
|
+
let:flatData
|
|
140
|
+
let:config
|
|
141
|
+
let:x1
|
|
142
|
+
let:x1Scale
|
|
143
|
+
let:x1Get
|
|
144
|
+
let:y1
|
|
145
|
+
let:y1Scale
|
|
146
|
+
let:y1Get
|
|
147
|
+
let:c
|
|
148
|
+
let:cScale
|
|
149
|
+
let:cGet
|
|
150
|
+
on:resize
|
|
151
|
+
>
|
|
106
152
|
{#key isMounted}
|
|
107
153
|
<TransformContext
|
|
108
154
|
bind:this={transformContext}
|
|
@@ -149,17 +195,31 @@ onMount(() => {
|
|
|
149
195
|
{projection}
|
|
150
196
|
transform={_transform}
|
|
151
197
|
{tooltip}
|
|
198
|
+
{x}
|
|
152
199
|
{xScale}
|
|
153
200
|
{xGet}
|
|
201
|
+
{y}
|
|
154
202
|
{yScale}
|
|
155
203
|
{yGet}
|
|
204
|
+
{z}
|
|
156
205
|
{zScale}
|
|
157
206
|
{zGet}
|
|
207
|
+
{r}
|
|
158
208
|
{rScale}
|
|
159
209
|
{rGet}
|
|
210
|
+
{x1}
|
|
211
|
+
{x1Scale}
|
|
212
|
+
{x1Get}
|
|
213
|
+
{y1}
|
|
214
|
+
{y1Scale}
|
|
215
|
+
{y1Get}
|
|
216
|
+
{c}
|
|
217
|
+
{cScale}
|
|
218
|
+
{cGet}
|
|
160
219
|
{padding}
|
|
161
220
|
{data}
|
|
162
221
|
{flatData}
|
|
222
|
+
{config}
|
|
163
223
|
/>
|
|
164
224
|
</TooltipContext>
|
|
165
225
|
</GeoContext>
|