layerchart 0.54.0 → 0.55.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 +170 -144
- package/dist/components/Area.svelte +96 -67
- package/dist/components/Area.svelte.d.ts +1 -0
- package/dist/components/Axis.svelte +205 -155
- package/dist/components/Bar.svelte +72 -45
- package/dist/components/Bars.svelte +45 -34
- package/dist/components/Blur.svelte +5 -3
- package/dist/components/Bounds.svelte +37 -21
- package/dist/components/Brush.svelte +269 -112
- package/dist/components/Brush.svelte.d.ts +7 -0
- package/dist/components/Calendar.svelte +51 -38
- package/dist/components/Chart.svelte +295 -74
- package/dist/components/Chart.svelte.d.ts +17 -17
- package/dist/components/ChartClipPath.svelte +8 -5
- package/dist/components/ChartContext.svelte +243 -93
- package/dist/components/ChartContext.svelte.d.ts +15 -23
- package/dist/components/Circle.svelte +25 -16
- package/dist/components/CircleClipPath.svelte +16 -10
- package/dist/components/ClipPath.svelte +11 -7
- package/dist/components/ColorRamp.svelte +12 -10
- package/dist/components/ForceSimulation.svelte +185 -116
- package/dist/components/Frame.svelte +10 -6
- package/dist/components/GeoCircle.svelte +15 -9
- package/dist/components/GeoContext.svelte +109 -62
- package/dist/components/GeoEdgeFade.svelte +20 -14
- package/dist/components/GeoPath.svelte +107 -69
- package/dist/components/GeoPoint.svelte +32 -18
- package/dist/components/GeoSpline.svelte +30 -22
- package/dist/components/GeoTile.svelte +40 -30
- package/dist/components/GeoVisible.svelte +10 -7
- package/dist/components/Graticule.svelte +14 -8
- package/dist/components/Grid.svelte +75 -48
- package/dist/components/Group.svelte +43 -31
- package/dist/components/Highlight.svelte +284 -243
- package/dist/components/HitCanvas.svelte +75 -42
- package/dist/components/Hull.svelte +40 -20
- package/dist/components/Labels.svelte +81 -70
- package/dist/components/Legend.svelte +105 -74
- package/dist/components/Legend.svelte.d.ts +1 -1
- package/dist/components/Line.svelte +65 -19
- package/dist/components/Line.svelte.d.ts +13 -1
- package/dist/components/LinearGradient.svelte +21 -15
- package/dist/components/Link.svelte +94 -22
- package/dist/components/Link.svelte.d.ts +17 -1
- package/dist/components/Marker.svelte +81 -0
- package/dist/components/Marker.svelte.d.ts +28 -0
- package/dist/components/MonthPath.svelte +23 -16
- package/dist/components/MotionPath.svelte +34 -25
- package/dist/components/Pack.svelte +21 -14
- package/dist/components/Partition.svelte +35 -20
- package/dist/components/Pattern.svelte +8 -6
- package/dist/components/Pie.svelte +76 -57
- package/dist/components/Point.svelte +11 -7
- package/dist/components/Points.svelte +178 -143
- package/dist/components/RadialGradient.svelte +25 -18
- package/dist/components/Rect.svelte +33 -19
- package/dist/components/RectClipPath.svelte +16 -11
- package/dist/components/Rule.svelte +50 -42
- package/dist/components/Sankey.svelte +55 -30
- package/dist/components/Spline.svelte +167 -96
- package/dist/components/Spline.svelte.d.ts +15 -0
- package/dist/components/Text.svelte +137 -104
- package/dist/components/Threshold.svelte +18 -7
- package/dist/components/TileImage.svelte +56 -50
- package/dist/components/TransformContext.svelte +235 -135
- package/dist/components/TransformControls.svelte +57 -29
- package/dist/components/TransformControls.svelte.d.ts +1 -1
- package/dist/components/Tree.svelte +33 -23
- package/dist/components/Treemap.svelte +69 -41
- package/dist/components/Voronoi.svelte +55 -28
- package/dist/components/charts/AreaChart.svelte +138 -87
- package/dist/components/charts/AreaChart.svelte.d.ts +4 -4
- package/dist/components/charts/BarChart.svelte +179 -114
- package/dist/components/charts/BarChart.svelte.d.ts +4 -4
- package/dist/components/charts/LineChart.svelte +97 -53
- package/dist/components/charts/LineChart.svelte.d.ts +4 -4
- package/dist/components/charts/PieChart.svelte +104 -54
- package/dist/components/charts/PieChart.svelte.d.ts +3 -3
- package/dist/components/charts/ScatterChart.svelte +83 -48
- package/dist/components/charts/ScatterChart.svelte.d.ts +4 -4
- package/dist/components/layout/Canvas.svelte +63 -43
- package/dist/components/layout/Html.svelte +28 -18
- package/dist/components/layout/Svg.svelte +47 -32
- package/dist/components/tooltip/Tooltip.svelte +137 -91
- package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContext.svelte +315 -249
- package/dist/components/tooltip/TooltipHeader.svelte +9 -3
- package/dist/components/tooltip/TooltipItem.svelte +17 -9
- package/dist/components/tooltip/TooltipList.svelte +2 -1
- package/dist/components/tooltip/TooltipSeparator.svelte +3 -2
- package/dist/docs/Blockquote.svelte +4 -3
- package/dist/docs/Code.svelte +15 -8
- package/dist/docs/CurveMenuField.svelte +17 -12
- package/dist/docs/GeoDebug.svelte +13 -9
- package/dist/docs/Header1.svelte +2 -1
- package/dist/docs/Json.svelte +6 -4
- package/dist/docs/Layout.svelte +6 -6
- package/dist/docs/PathDataMenuField.svelte +52 -44
- package/dist/docs/Preview.svelte +39 -33
- package/dist/docs/TilesetField.svelte +80 -62
- package/dist/docs/TransformDebug.svelte +8 -5
- package/dist/docs/ViewSourceButton.svelte +13 -9
- package/dist/stores/motionStore.d.ts +1 -1
- package/dist/utils/scales.d.ts +3 -3
- package/package.json +29 -30
|
@@ -1,27 +1,42 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export let
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
partition as d3Partition,
|
|
4
|
+
type HierarchyNode,
|
|
5
|
+
type HierarchyRectangularNode,
|
|
6
|
+
} from 'd3-hierarchy';
|
|
7
|
+
import { chartContext } from './ChartContext.svelte';
|
|
8
|
+
|
|
9
|
+
const { data, width, height } = chartContext();
|
|
10
|
+
|
|
11
|
+
export let orientation: 'vertical' | 'horizontal' = 'horizontal';
|
|
12
|
+
|
|
13
|
+
export let size: [number, number] | undefined = undefined;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* see: https://github.com/d3/d3-hierarchy#tree_nodeSize
|
|
17
|
+
*/
|
|
18
|
+
export let padding: number | undefined = undefined;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* see: https://github.com/d3/d3-hierarchy#tree_nodeSize
|
|
22
|
+
*/
|
|
23
|
+
export let round: boolean | undefined = undefined;
|
|
24
|
+
|
|
25
|
+
let partition: ReturnType<typeof d3Partition>;
|
|
26
|
+
$: {
|
|
27
|
+
partition = d3Partition().size(
|
|
28
|
+
size ?? (orientation === 'horizontal' ? [$height, $width] : [$width, $height])
|
|
29
|
+
);
|
|
30
|
+
|
|
17
31
|
if (padding) {
|
|
18
|
-
|
|
32
|
+
partition.padding(padding);
|
|
19
33
|
}
|
|
20
34
|
if (round) {
|
|
21
|
-
|
|
35
|
+
partition.round(round);
|
|
22
36
|
}
|
|
23
|
-
}
|
|
24
|
-
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
$: partitionData = partition($data as HierarchyNode<any>) as HierarchyRectangularNode<any>;
|
|
25
40
|
</script>
|
|
26
41
|
|
|
27
42
|
<slot nodes={partitionData.descendants()} />
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
<script
|
|
2
|
-
// https://
|
|
3
|
-
// https://
|
|
4
|
-
|
|
5
|
-
export let
|
|
6
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// https://developer.mozilla.org/en-US/docs/Web/SVG/Element/pattern
|
|
3
|
+
// https://airbnb.io/visx/patterns
|
|
4
|
+
// https://github.com/airbnb/visx/tree/master/packages/visx-pattern/src/patterns
|
|
5
|
+
export let id: string;
|
|
6
|
+
|
|
7
|
+
export let width: number;
|
|
8
|
+
export let height: number;
|
|
7
9
|
</script>
|
|
8
10
|
|
|
9
11
|
<defs>
|
|
@@ -1,65 +1,84 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
let
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
3
|
+
import { pie as d3pie } from 'd3-shape';
|
|
4
|
+
import { min, max } from 'd3-array';
|
|
5
|
+
|
|
6
|
+
import Arc from './Arc.svelte';
|
|
7
|
+
import { chartContext } from './ChartContext.svelte';
|
|
8
|
+
import { degreesToRadians } from '../utils/math.js';
|
|
9
|
+
import { motionStore } from '../stores/motionStore.js';
|
|
10
|
+
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
TODO:
|
|
14
|
+
- [ ] Offset (always, on hover)
|
|
15
|
+
- [ ] Labels
|
|
16
|
+
- [ ] Multiple nested circles (zScale, or take in data to override context data). See Path/Area/Threshold
|
|
17
|
+
- [ ] Hover events / change innerRadius / outerRadius, etc
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export let data: any[] | undefined = undefined; // TODO: Update Type
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Range [min,max] in degrees. See also startAngle/endAngle
|
|
24
|
+
*/
|
|
25
|
+
export let range = [0, 360]; // degrees
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Start angle in radians
|
|
29
|
+
*/
|
|
30
|
+
export let startAngle: number | undefined = undefined;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* End angle in radians
|
|
34
|
+
*/
|
|
35
|
+
export let endAngle: number | undefined = undefined;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Define innerRadius.
|
|
39
|
+
* value >= 1: discrete value
|
|
40
|
+
* value > 0: percent of `outerRadius`
|
|
41
|
+
* value < 0: offset of `outerRadius`
|
|
42
|
+
* default: yRange min
|
|
43
|
+
*/
|
|
44
|
+
export let innerRadius: number | undefined = undefined;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Define outerRadius. Defaults to yRange max/2 (ie. chart height / 2)
|
|
48
|
+
*/
|
|
49
|
+
export let outerRadius: number | undefined = undefined;
|
|
50
|
+
|
|
51
|
+
export let cornerRadius = 0;
|
|
52
|
+
export let padAngle = 0;
|
|
53
|
+
|
|
54
|
+
export let spring: boolean | Parameters<typeof springStore>[1] = undefined;
|
|
55
|
+
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Offset all arcs from center
|
|
59
|
+
*/
|
|
60
|
+
export let offset = 0;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Tooltip context to setup pointer events to show tooltip for related data
|
|
64
|
+
*/
|
|
65
|
+
export let tooltip: TooltipContextValue | undefined = undefined;
|
|
66
|
+
|
|
67
|
+
const { data: contextData, x, y, xRange, c, cScale, config, width, height } = chartContext();
|
|
68
|
+
|
|
69
|
+
// @ts-expect-error
|
|
70
|
+
$: resolved_endAngle = endAngle ?? degreesToRadians($config.xRange ? max($xRange) : max(range));
|
|
71
|
+
let tweened_endAngle = motionStore(0, { spring, tweened });
|
|
72
|
+
$: tweened_endAngle.set(resolved_endAngle);
|
|
73
|
+
|
|
74
|
+
$: pie = d3pie<any>()
|
|
57
75
|
// @ts-expect-error
|
|
58
76
|
.startAngle(startAngle ?? degreesToRadians($config.xRange ? min($xRange) : min(range)))
|
|
59
77
|
.endAngle($tweened_endAngle)
|
|
60
78
|
.padAngle(padAngle)
|
|
61
79
|
.value($x);
|
|
62
|
-
|
|
80
|
+
|
|
81
|
+
$: arcs = pie(data ?? (Array.isArray($contextData) ? $contextData : []));
|
|
63
82
|
</script>
|
|
64
83
|
|
|
65
84
|
<slot {arcs}>
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { chartContext } from './ChartContext.svelte';
|
|
3
|
+
|
|
4
|
+
const context = chartContext() as any;
|
|
5
|
+
const { xGet, yGet } = context;
|
|
6
|
+
|
|
7
|
+
/** Single data point to translate to x/y */
|
|
8
|
+
export let d;
|
|
9
|
+
|
|
10
|
+
$: x = $xGet(d);
|
|
11
|
+
$: y = $yGet(d);
|
|
8
12
|
</script>
|
|
9
13
|
|
|
10
14
|
<slot {x} {y} />
|
|
@@ -1,171 +1,206 @@
|
|
|
1
|
-
<script context="module">
|
|
1
|
+
<script lang="ts" context="module">
|
|
2
|
+
export type Point = { x: number; y: number; r: number; xValue: any; yValue: any; data: any };
|
|
2
3
|
</script>
|
|
3
4
|
|
|
4
|
-
<script>
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { getContext, type ComponentProps } from 'svelte';
|
|
7
|
+
import type { Readable } from 'svelte/store';
|
|
8
|
+
import { extent } from 'd3-array';
|
|
9
|
+
import { pointRadial } from 'd3-shape';
|
|
10
|
+
import { notNull } from '@layerstack/utils/typeGuards';
|
|
11
|
+
|
|
12
|
+
import { chartContext } from './ChartContext.svelte';
|
|
13
|
+
import Circle from './Circle.svelte';
|
|
14
|
+
import Link from './Link.svelte';
|
|
15
|
+
import { isScaleBand, type AnyScale } from '../utils/scales.js';
|
|
16
|
+
|
|
17
|
+
const context = chartContext() as any;
|
|
18
|
+
const {
|
|
19
|
+
data: contextData,
|
|
20
|
+
x,
|
|
21
|
+
xScale,
|
|
22
|
+
xGet,
|
|
23
|
+
y,
|
|
24
|
+
yScale,
|
|
25
|
+
yGet,
|
|
26
|
+
cGet,
|
|
27
|
+
rGet,
|
|
28
|
+
padding,
|
|
29
|
+
containerWidth,
|
|
30
|
+
containerHeight,
|
|
31
|
+
config,
|
|
32
|
+
radial,
|
|
33
|
+
} = context;
|
|
34
|
+
|
|
35
|
+
type Offset = number | ((value: number, context: any) => number) | undefined;
|
|
36
|
+
|
|
37
|
+
/** Override data instead of using context */
|
|
38
|
+
export let data: any = undefined;
|
|
39
|
+
|
|
40
|
+
export let r = 5;
|
|
41
|
+
export let offsetX: Offset = undefined;
|
|
42
|
+
export let offsetY: Offset = undefined;
|
|
43
|
+
|
|
44
|
+
/** Enable showing links between related points (array x/y accessors) */
|
|
45
|
+
export let links: boolean | Partial<ComponentProps<Link>> = false;
|
|
46
|
+
|
|
47
|
+
export let fill: string | undefined = undefined;
|
|
48
|
+
export let stroke: string | undefined = undefined;
|
|
49
|
+
export let strokeWidth: number | string | undefined = undefined;
|
|
50
|
+
|
|
51
|
+
/** Render to canvas */
|
|
52
|
+
export let render: ((ctx: CanvasRenderingContext2D, points: Point[]) => any) | undefined =
|
|
53
|
+
undefined;
|
|
54
|
+
|
|
55
|
+
let className: string | undefined = undefined;
|
|
56
|
+
export { className as class };
|
|
57
|
+
|
|
58
|
+
const canvas = getContext<{ ctx: Readable<CanvasRenderingContext2D> }>('canvas');
|
|
59
|
+
const DEFAULT_FILL = 'rgb(0, 0, 0)';
|
|
60
|
+
|
|
61
|
+
function getOffset(value: any, offset: Offset, scale: AnyScale) {
|
|
31
62
|
if (typeof offset === 'function') {
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
else
|
|
38
|
-
|
|
63
|
+
return offset(value, context);
|
|
64
|
+
} else if (offset != null) {
|
|
65
|
+
return offset;
|
|
66
|
+
} else if (isScaleBand(scale) && !$radial) {
|
|
67
|
+
return scale.bandwidth() / 2;
|
|
68
|
+
} else {
|
|
69
|
+
return 0;
|
|
39
70
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
$:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
/*
|
|
51
|
-
x={["prop1" ,"prop2"]}
|
|
52
|
-
y="prop3"
|
|
53
|
-
*/
|
|
54
|
-
return xValue.filter(notNull).map((xValue) => {
|
|
55
|
-
return {
|
|
56
|
-
x: $xScale(xValue) + getOffset($xScale(xValue), offsetX, $xScale),
|
|
57
|
-
y: $yScale(yValue) + getOffset($yScale(yValue), offsetY, $yScale),
|
|
58
|
-
r: $config.r ? $rGet(d) : r,
|
|
59
|
-
xValue,
|
|
60
|
-
yValue,
|
|
61
|
-
data: d,
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
else if (Array.isArray(yValue)) {
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
$: pointsData = data ?? $contextData;
|
|
74
|
+
|
|
75
|
+
$: points = pointsData
|
|
76
|
+
.flatMap((d: any) => {
|
|
77
|
+
const xValue = $x(d);
|
|
78
|
+
const yValue = $y(d);
|
|
79
|
+
|
|
80
|
+
if (Array.isArray(xValue)) {
|
|
66
81
|
/*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
x={["prop1" ,"prop2"]}
|
|
83
|
+
y="prop3"
|
|
84
|
+
*/
|
|
85
|
+
return xValue.filter(notNull).map((xValue: number) => {
|
|
86
|
+
return {
|
|
87
|
+
x: $xScale(xValue) + getOffset($xScale(xValue), offsetX, $xScale),
|
|
88
|
+
y: $yScale(yValue) + getOffset($yScale(yValue), offsetY, $yScale),
|
|
89
|
+
r: $config.r ? $rGet(d) : r,
|
|
90
|
+
xValue,
|
|
91
|
+
yValue,
|
|
92
|
+
data: d,
|
|
93
|
+
};
|
|
79
94
|
});
|
|
80
|
-
|
|
81
|
-
else if (xValue != null && yValue != null) {
|
|
95
|
+
} else if (Array.isArray(yValue)) {
|
|
82
96
|
/*
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return {
|
|
97
|
+
x="prop1"
|
|
98
|
+
y={["prop2" ,"prop3"]}
|
|
99
|
+
*/
|
|
100
|
+
return yValue.filter(notNull).map((yValue: number) => {
|
|
101
|
+
return {
|
|
87
102
|
x: $xScale(xValue) + getOffset($xScale(xValue), offsetX, $xScale),
|
|
88
103
|
y: $yScale(yValue) + getOffset($yScale(yValue), offsetY, $yScale),
|
|
89
104
|
r: $config.r ? $rGet(d) : r,
|
|
90
105
|
xValue,
|
|
91
106
|
yValue,
|
|
92
107
|
data: d,
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
} else if (xValue != null && yValue != null) {
|
|
111
|
+
/*
|
|
112
|
+
x="prop1"
|
|
113
|
+
y="prop2"
|
|
114
|
+
*/
|
|
115
|
+
return {
|
|
116
|
+
x: $xScale(xValue) + getOffset($xScale(xValue), offsetX, $xScale),
|
|
117
|
+
y: $yScale(yValue) + getOffset($yScale(yValue), offsetY, $yScale),
|
|
118
|
+
r: $config.r ? $rGet(d) : r,
|
|
119
|
+
xValue,
|
|
120
|
+
yValue,
|
|
121
|
+
data: d,
|
|
93
122
|
};
|
|
94
|
-
|
|
95
|
-
})
|
|
96
|
-
.filter((p) => p);
|
|
97
|
-
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
.filter((p: Point) => p) as Point[];
|
|
126
|
+
|
|
127
|
+
$: _links = pointsData.flatMap((d: any) => {
|
|
98
128
|
const xValue = $x(d);
|
|
99
129
|
const yValue = $y(d);
|
|
130
|
+
|
|
100
131
|
if (Array.isArray(xValue)) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
132
|
+
/*
|
|
133
|
+
x={["prop1" ,"prop2"]}
|
|
134
|
+
y="prop3"
|
|
135
|
+
*/
|
|
136
|
+
const [xMin, xMax] = extent($xGet(d)) as unknown as [number, number];
|
|
137
|
+
const y = $yGet(d) + getOffset($yGet(d), offsetY, $yScale);
|
|
138
|
+
return {
|
|
139
|
+
source: {
|
|
140
|
+
x: xMin + getOffset(xMin, offsetX, $xScale) + ($config.r ? $rGet(d) : r),
|
|
141
|
+
y,
|
|
142
|
+
},
|
|
143
|
+
target: {
|
|
144
|
+
x: xMax + getOffset(xMax, offsetX, $xScale) - ($config.r ? $rGet(d) : r),
|
|
145
|
+
y: y,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
} else if (Array.isArray(yValue)) {
|
|
149
|
+
/*
|
|
150
|
+
x="prop1"
|
|
151
|
+
y={["prop2" ,"prop3"]}
|
|
152
|
+
*/
|
|
153
|
+
const x = $xGet(d) + getOffset($xGet(d), offsetX, $xScale);
|
|
154
|
+
const [yMin, yMax] = extent($yGet(d)) as unknown as [number, number];
|
|
155
|
+
return {
|
|
156
|
+
source: {
|
|
157
|
+
x: x,
|
|
158
|
+
y: yMin + getOffset(yMin, offsetY, $yScale),
|
|
159
|
+
},
|
|
160
|
+
target: {
|
|
161
|
+
x: x,
|
|
162
|
+
y: yMax + getOffset(yMax, offsetY, $yScale),
|
|
163
|
+
},
|
|
164
|
+
};
|
|
117
165
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
source: {
|
|
127
|
-
x: x,
|
|
128
|
-
y: yMin + getOffset(yMin, offsetY, $yScale),
|
|
129
|
-
},
|
|
130
|
-
target: {
|
|
131
|
-
x: x,
|
|
132
|
-
y: yMax + getOffset(yMax, offsetY, $yScale),
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
$: renderContext = canvas ? 'canvas' : 'svg';
|
|
138
|
-
$: ctx = canvas?.ctx;
|
|
139
|
-
$: if (renderContext === 'canvas' && $ctx) {
|
|
140
|
-
let computedStyles = {};
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
$: renderContext = canvas ? 'canvas' : 'svg';
|
|
169
|
+
$: ctx = canvas?.ctx;
|
|
170
|
+
$: if (renderContext === 'canvas' && $ctx) {
|
|
171
|
+
let computedStyles: Partial<CSSStyleDeclaration> = {};
|
|
172
|
+
|
|
141
173
|
// Transfer classes defined on <GeoPath> to <canvas> to enable window.getComputedStyle() retrieval (Tailwind classes, etc)
|
|
142
174
|
if (className) {
|
|
143
|
-
|
|
144
|
-
|
|
175
|
+
$ctx.canvas.classList.add(...className.split(' '));
|
|
176
|
+
computedStyles = window.getComputedStyle($ctx.canvas);
|
|
145
177
|
}
|
|
178
|
+
|
|
146
179
|
// Clear with negative offset due to Canvas `context.translate(...)`
|
|
147
180
|
$ctx.clearRect(-$padding.left, -$padding.top, $containerWidth, $containerHeight);
|
|
181
|
+
|
|
148
182
|
if (render) {
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
183
|
+
render($ctx, points);
|
|
184
|
+
} else {
|
|
185
|
+
points.forEach((point) => {
|
|
186
|
+
$ctx.beginPath();
|
|
187
|
+
$ctx.arc(point.x, point.y, point.r, 0, 2 * Math.PI, false);
|
|
188
|
+
|
|
189
|
+
$ctx.lineWidth = Number(strokeWidth ?? 0);
|
|
190
|
+
$ctx.strokeStyle =
|
|
191
|
+
(stroke ?? computedStyles.stroke === 'none')
|
|
192
|
+
? 'transparent'
|
|
193
|
+
: (computedStyles.stroke ?? '');
|
|
194
|
+
$ctx.stroke();
|
|
195
|
+
|
|
196
|
+
$ctx.fillStyle =
|
|
197
|
+
fill ??
|
|
198
|
+
(computedStyles.fill !== DEFAULT_FILL ? computedStyles.fill : undefined) ??
|
|
199
|
+
'transparent';
|
|
200
|
+
$ctx.fill();
|
|
201
|
+
});
|
|
167
202
|
}
|
|
168
|
-
}
|
|
203
|
+
}
|
|
169
204
|
</script>
|
|
170
205
|
|
|
171
206
|
<slot {points}>
|
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
export let
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { uniqueId } from '@layerstack/utils';
|
|
3
|
+
|
|
4
|
+
/** Unique id for linearGradient */
|
|
5
|
+
export let id: string = uniqueId('radialGradient-');
|
|
6
|
+
|
|
7
|
+
/** Array array of strings (colors), will equally distributed from 0-100%. If array of tuples, will use first value as the offset, and second as color */
|
|
8
|
+
export let stops: string[] | [string | number, string][] = [
|
|
6
9
|
'var(--tw-gradient-from)',
|
|
7
10
|
'var(--tw-gradient-to)',
|
|
8
|
-
];
|
|
9
|
-
|
|
10
|
-
export let
|
|
11
|
-
export let
|
|
12
|
-
export let
|
|
13
|
-
export let
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
export let cx = '50%';
|
|
14
|
+
export let cy = '50%';
|
|
15
|
+
export let fx = cx;
|
|
16
|
+
export let fy = cy;
|
|
17
|
+
export let r = '50%';
|
|
18
|
+
// TODO: Svelte / Typescript does not know `<radialRadiant fr="...">`
|
|
19
|
+
// export let fr = '0%';
|
|
20
|
+
|
|
21
|
+
/** Indicates how the gradient behaves if it starts or ends inside the bounds of the shape containing the gradient */
|
|
22
|
+
export let spreadMethod: 'pad' | 'reflect' | 'repeat' = 'pad';
|
|
23
|
+
|
|
24
|
+
export let transform: string | null | undefined = undefined;
|
|
25
|
+
|
|
26
|
+
/** Define the coordinate system for attributes (i.e. gradientUnits) */
|
|
27
|
+
export let units: 'objectBoundingBox' | 'userSpaceOnUse' = 'objectBoundingBox';
|
|
21
28
|
</script>
|
|
22
29
|
|
|
23
30
|
<defs>
|