layerchart 2.0.0-next.1 → 2.0.0-next.2
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/actions/movable.d.ts +28 -0
- package/dist/actions/movable.js +91 -0
- package/dist/components/AnnotationLine.svelte +155 -0
- package/dist/components/AnnotationLine.svelte.d.ts +28 -0
- package/dist/components/AnnotationPoint.svelte +121 -0
- package/dist/components/AnnotationPoint.svelte.d.ts +32 -0
- package/dist/components/AnnotationRange.svelte +147 -0
- package/dist/components/AnnotationRange.svelte.d.ts +40 -0
- package/dist/components/Arc.svelte +344 -151
- package/dist/components/Arc.svelte.d.ts +138 -0
- package/dist/components/Area.svelte +165 -149
- package/dist/components/Area.svelte.d.ts +45 -0
- package/dist/components/Axis.svelte +287 -174
- package/dist/components/Axis.svelte.d.ts +116 -0
- package/dist/components/Bar.svelte +163 -107
- package/dist/components/Bar.svelte.d.ts +48 -0
- package/dist/components/Bars.svelte +54 -68
- package/dist/components/Bars.svelte.d.ts +27 -0
- package/dist/components/Blur.svelte +31 -7
- package/dist/components/Blur.svelte.d.ts +23 -21
- package/dist/components/Bounds.svelte +49 -19
- package/dist/components/Bounds.svelte.d.ts +24 -50
- package/dist/components/BrushContext.svelte +296 -168
- package/dist/components/BrushContext.svelte.d.ts +97 -65
- package/dist/components/Calendar.svelte +116 -59
- package/dist/components/Calendar.svelte.d.ts +50 -31
- package/dist/components/Chart.svelte +1289 -398
- package/dist/components/Chart.svelte.d.ts +535 -410
- package/dist/components/ChartClipPath.svelte +37 -15
- package/dist/components/ChartClipPath.svelte.d.ts +21 -19
- package/dist/components/Circle.svelte +124 -85
- package/dist/components/Circle.svelte.d.ts +52 -0
- package/dist/components/CircleClipPath.svelte +76 -16
- package/dist/components/CircleClipPath.svelte.d.ts +46 -0
- package/dist/components/ClipPath.svelte +60 -15
- package/dist/components/ClipPath.svelte.d.ts +40 -27
- package/dist/components/ColorRamp.svelte +75 -9
- package/dist/components/ColorRamp.svelte.d.ts +37 -19
- package/dist/components/ComputedStyles.svelte +17 -5
- package/dist/components/ComputedStyles.svelte.d.ts +11 -19
- package/dist/components/Connector.svelte +149 -0
- package/dist/components/Connector.svelte.d.ts +51 -0
- package/dist/components/Dagre.svelte +211 -122
- package/dist/components/Dagre.svelte.d.ts +119 -56
- package/dist/components/ForceSimulation.svelte +215 -90
- package/dist/components/ForceSimulation.svelte.d.ts +82 -35
- package/dist/components/Frame.svelte +33 -13
- package/dist/components/Frame.svelte.d.ts +13 -17
- package/dist/components/GeoCircle.svelte +29 -16
- package/dist/components/GeoCircle.svelte.d.ts +22 -24
- package/dist/components/GeoContext.svelte +113 -72
- package/dist/components/GeoContext.svelte.d.ts +49 -41
- package/dist/components/GeoEdgeFade.svelte +47 -12
- package/dist/components/GeoEdgeFade.svelte.d.ts +17 -19
- package/dist/components/GeoPath.svelte +157 -127
- package/dist/components/GeoPath.svelte.d.ts +48 -36
- package/dist/components/GeoPoint.svelte +52 -20
- package/dist/components/GeoPoint.svelte.d.ts +25 -22
- package/dist/components/GeoSpline.svelte +75 -26
- package/dist/components/GeoSpline.svelte.d.ts +29 -20
- package/dist/components/GeoTile.svelte +100 -49
- package/dist/components/GeoTile.svelte.d.ts +38 -23
- package/dist/components/GeoVisible.svelte +17 -9
- package/dist/components/GeoVisible.svelte.d.ts +10 -18
- package/dist/components/Graticule.svelte +28 -13
- package/dist/components/Graticule.svelte.d.ts +11 -52
- package/dist/components/Grid.svelte +226 -114
- package/dist/components/Grid.svelte.d.ts +70 -0
- package/dist/components/Group.svelte +132 -105
- package/dist/components/Group.svelte.d.ts +53 -0
- package/dist/components/Highlight.svelte +409 -307
- package/dist/components/Highlight.svelte.d.ts +107 -0
- package/dist/components/Hull.svelte +96 -45
- package/dist/components/Hull.svelte.d.ts +40 -30
- package/dist/components/Labels.svelte +125 -46
- package/dist/components/Labels.svelte.d.ts +70 -27
- package/dist/components/Legend.svelte +374 -190
- package/dist/components/Legend.svelte.d.ts +95 -44
- package/dist/components/Line.svelte +163 -125
- package/dist/components/Line.svelte.d.ts +75 -0
- package/dist/components/LinearGradient.svelte +153 -78
- package/dist/components/LinearGradient.svelte.d.ts +66 -31
- package/dist/components/Link.svelte +160 -104
- package/dist/components/Link.svelte.d.ts +54 -0
- package/dist/components/Marker.svelte +100 -39
- package/dist/components/Marker.svelte.d.ts +59 -27
- package/dist/components/MarkerWrapper.svelte +35 -0
- package/dist/components/MarkerWrapper.svelte.d.ts +18 -0
- package/dist/components/MonthPath.svelte +65 -20
- package/dist/components/MonthPath.svelte.d.ts +23 -17
- package/dist/components/MotionPath.svelte +80 -24
- package/dist/components/MotionPath.svelte.d.ts +46 -27
- package/dist/components/Pack.svelte +53 -17
- package/dist/components/Pack.svelte.d.ts +42 -21
- package/dist/components/Partition.svelte +64 -22
- package/dist/components/Partition.svelte.d.ts +49 -26
- package/dist/components/Pattern.svelte +297 -11
- package/dist/components/Pattern.svelte.d.ts +103 -19
- package/dist/components/Pie.svelte +122 -76
- package/dist/components/Pie.svelte.d.ts +65 -51
- package/dist/components/Point.svelte +20 -9
- package/dist/components/Point.svelte.d.ts +16 -20
- package/dist/components/Points.svelte +148 -137
- package/dist/components/Points.svelte.d.ts +45 -34
- package/dist/components/RadialGradient.svelte +143 -70
- package/dist/components/RadialGradient.svelte.d.ts +69 -31
- package/dist/components/Rect.svelte +121 -102
- package/dist/components/Rect.svelte.d.ts +36 -0
- package/dist/components/RectClipPath.svelte +82 -18
- package/dist/components/RectClipPath.svelte.d.ts +55 -0
- package/dist/components/Rule.svelte +105 -62
- package/dist/components/Rule.svelte.d.ts +40 -19
- package/dist/components/Sankey.svelte +132 -55
- package/dist/components/Sankey.svelte.d.ts +61 -31
- package/dist/components/Spline.svelte +281 -218
- package/dist/components/Spline.svelte.d.ts +95 -0
- package/dist/components/Text.svelte +437 -176
- package/dist/components/Text.svelte.d.ts +130 -0
- package/dist/components/Threshold.svelte +48 -16
- package/dist/components/Threshold.svelte.d.ts +29 -31
- package/dist/components/TileImage.svelte +103 -30
- package/dist/components/TileImage.svelte.d.ts +48 -23
- package/dist/components/TransformContext.svelte +365 -171
- package/dist/components/TransformControls.svelte +50 -26
- package/dist/components/TransformControls.svelte.d.ts +27 -19
- package/dist/components/Tree.svelte +74 -33
- package/dist/components/Tree.svelte.d.ts +42 -30
- package/dist/components/Treemap.svelte +119 -42
- package/dist/components/Treemap.svelte.d.ts +75 -27
- package/dist/components/Voronoi.svelte +106 -75
- package/dist/components/Voronoi.svelte.d.ts +40 -41
- package/dist/components/charts/ArcChart.svelte +464 -0
- package/dist/components/charts/ArcChart.svelte.d.ts +90 -0
- package/dist/components/charts/AreaChart.svelte +450 -393
- package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
- package/dist/components/charts/BarChart.svelte +454 -389
- package/dist/components/charts/BarChart.svelte.d.ts +76 -0
- package/dist/components/charts/ChartAnnotations.svelte +37 -0
- package/dist/components/charts/ChartAnnotations.svelte.d.ts +10 -0
- package/dist/components/charts/DefaultTooltip.svelte +60 -0
- package/dist/components/charts/DefaultTooltip.svelte.d.ts +10 -0
- package/dist/components/charts/LineChart.svelte +369 -314
- package/dist/components/charts/LineChart.svelte.d.ts +53 -0
- package/dist/components/charts/PieChart.svelte +458 -316
- package/dist/components/charts/PieChart.svelte.d.ts +137 -353
- package/dist/components/charts/ScatterChart.svelte +334 -296
- package/dist/components/charts/ScatterChart.svelte.d.ts +39 -0
- package/dist/components/charts/index.d.ts +8 -0
- package/dist/components/charts/index.js +7 -0
- package/dist/components/charts/types.d.ts +253 -0
- package/dist/components/charts/utils.svelte.d.ts +30 -0
- package/dist/components/charts/utils.svelte.js +55 -0
- package/dist/components/index.d.ts +76 -4
- package/dist/components/index.js +76 -5
- package/dist/components/layout/Canvas.svelte +321 -155
- package/dist/components/layout/Canvas.svelte.d.ts +104 -55
- package/dist/components/layout/Html.svelte +82 -42
- package/dist/components/layout/Html.svelte.d.ts +39 -28
- package/dist/components/layout/Layer.svelte +39 -0
- package/dist/components/layout/Layer.svelte.d.ts +17 -0
- package/dist/components/layout/Svg.svelte +122 -70
- package/dist/components/layout/Svg.svelte.d.ts +53 -34
- package/dist/components/layout/WebGL.svelte +135 -0
- package/dist/components/layout/WebGL.svelte.d.ts +50 -0
- package/dist/components/tooltip/Tooltip.svelte +246 -78
- package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
- package/dist/components/tooltip/TooltipContext.svelte +409 -271
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +86 -55
- package/dist/components/tooltip/TooltipHeader.svelte +100 -11
- package/dist/components/tooltip/TooltipHeader.svelte.d.ts +43 -23
- package/dist/components/tooltip/TooltipItem.svelte +167 -27
- package/dist/components/tooltip/TooltipItem.svelte.d.ts +63 -31
- package/dist/components/tooltip/TooltipList.svelte +22 -3
- package/dist/components/tooltip/TooltipList.svelte.d.ts +6 -17
- package/dist/components/tooltip/TooltipSeparator.svelte +27 -1
- package/dist/components/tooltip/TooltipSeparator.svelte.d.ts +6 -15
- package/dist/components/tooltip/index.d.ts +6 -0
- package/dist/components/tooltip/index.js +6 -0
- package/dist/components/tooltip/tooltipMetaContext.d.ts +79 -0
- package/dist/components/tooltip/tooltipMetaContext.js +139 -0
- package/dist/components/types.d.ts +1 -0
- package/dist/components/types.js +1 -0
- package/dist/docs/Blockquote.svelte.d.ts +18 -14
- package/dist/docs/Code.svelte.d.ts +26 -22
- package/dist/docs/ConnectorSweepMenuField.svelte +17 -0
- package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +7 -0
- package/dist/docs/ConnectorTypeMenuField.svelte +17 -0
- package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +7 -0
- package/dist/docs/CurveMenuField.svelte +14 -3
- package/dist/docs/CurveMenuField.svelte.d.ts +9 -18
- package/dist/docs/GeoDebug.svelte +47 -42
- package/dist/docs/GeoDebug.svelte.d.ts +4 -16
- package/dist/docs/Header1.svelte.d.ts +27 -16
- package/dist/docs/Json.svelte.d.ts +20 -16
- package/dist/docs/Layout.svelte.d.ts +18 -13
- package/dist/docs/Link.svelte.d.ts +33 -21
- package/dist/docs/PathDataMenuField.svelte +14 -10
- package/dist/docs/PathDataMenuField.svelte.d.ts +8 -18
- package/dist/docs/Preview.svelte +20 -7
- package/dist/docs/Preview.svelte.d.ts +12 -22
- package/dist/docs/TilesetField.svelte.d.ts +21 -17
- package/dist/docs/TransformDebug.svelte +5 -6
- package/dist/docs/TransformDebug.svelte.d.ts +18 -14
- package/dist/docs/ViewSourceButton.svelte.d.ts +21 -17
- package/dist/types/d3-shape-extentions.d.ts +7 -0
- package/dist/utils/afterTick.d.ts +5 -0
- package/dist/utils/afterTick.js +8 -0
- package/dist/utils/arcText.svelte.d.ts +57 -0
- package/dist/utils/arcText.svelte.js +262 -0
- package/dist/utils/array.d.ts +9 -1
- package/dist/utils/array.js +13 -0
- package/dist/utils/attributes.d.ts +29 -0
- package/dist/utils/attributes.js +40 -0
- package/dist/utils/canvas.js +47 -10
- package/dist/utils/chart.d.ts +78 -0
- package/dist/utils/chart.js +512 -0
- package/dist/utils/color.d.ts +1 -0
- package/dist/utils/color.js +8 -0
- package/dist/utils/common.d.ts +3 -5
- package/dist/utils/common.js +3 -2
- package/dist/utils/connectorUtils.d.ts +21 -0
- package/dist/utils/connectorUtils.js +111 -0
- package/dist/utils/createId.d.ts +7 -0
- package/dist/utils/createId.js +9 -0
- package/dist/utils/debug.d.ts +1 -0
- package/dist/utils/debug.js +84 -0
- package/dist/utils/filterObject.d.ts +9 -0
- package/dist/utils/filterObject.js +12 -0
- package/dist/utils/graph/dagre.d.ts +34 -0
- package/dist/utils/graph/dagre.js +78 -0
- package/dist/utils/graph/dagre.test.d.ts +1 -0
- package/dist/utils/{graph.test.js → graph/dagre.test.js} +19 -33
- package/dist/utils/graph/sankey.d.ts +28 -0
- package/dist/utils/{graph.js → graph/sankey.js} +13 -41
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/key.svelte.d.ts +3 -0
- package/dist/utils/key.svelte.js +11 -0
- package/dist/utils/legendPayload.d.ts +7 -0
- package/dist/utils/legendPayload.js +8 -0
- package/dist/utils/motion.svelte.d.ts +140 -0
- package/dist/utils/motion.svelte.js +180 -0
- package/dist/utils/motion.test.d.ts +1 -0
- package/dist/utils/motion.test.js +213 -0
- package/dist/utils/{rect.d.ts → rect.svelte.d.ts} +7 -4
- package/dist/utils/rect.svelte.js +105 -0
- package/dist/utils/scales.svelte.d.ts +90 -0
- package/dist/utils/{scales.js → scales.svelte.js} +100 -39
- package/dist/utils/stack.d.ts +2 -3
- package/dist/utils/stack.js +1 -1
- package/dist/utils/string.js +87 -0
- package/dist/utils/ticks.d.ts +8 -2
- package/dist/utils/ticks.js +28 -0
- package/dist/utils/ticks.test.d.ts +1 -0
- package/dist/utils/ticks.test.js +67 -0
- package/dist/utils/types.d.ts +81 -0
- package/package.json +21 -19
- package/dist/components/ChartContext.svelte +0 -295
- package/dist/components/ChartContext.svelte.d.ts +0 -139
- package/dist/components/TransformContext.svelte.d.ts +0 -158
- package/dist/stores/motionStore.d.ts +0 -30
- package/dist/stores/motionStore.js +0 -62
- package/dist/utils/graph.d.ts +0 -37
- package/dist/utils/rect.js +0 -107
- package/dist/utils/scales.d.ts +0 -66
- /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
|
@@ -1,55 +1,129 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { asAny, type Without } from '../utils/types.js';
|
|
3
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
4
|
+
import type { Snippet } from 'svelte';
|
|
5
|
+
|
|
6
|
+
export type LinearGradientPropsWithoutHTML = {
|
|
7
|
+
/**
|
|
8
|
+
* Unique id for linearGradient
|
|
9
|
+
*/
|
|
10
|
+
id?: string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Array array of strings (colors), will equally distributed from 0-100%.
|
|
14
|
+
* If array of tuples, will use first value as the offset, and second as color
|
|
15
|
+
*
|
|
16
|
+
* @default `['var(--tw-gradient-from)', 'var(--tw-gradient-to)']`
|
|
17
|
+
*/
|
|
18
|
+
stops?: string[] | [string | number, string][];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Apply color stops top-to-bottom (true) or left-to-right (false)
|
|
22
|
+
*
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
vertical?: boolean;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @default '0%'
|
|
29
|
+
*/
|
|
30
|
+
x1?: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @default '0%'
|
|
34
|
+
*/
|
|
35
|
+
y1?: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @default vertical ? '0%' : '100%'
|
|
39
|
+
*/
|
|
40
|
+
x2?: string;
|
|
41
|
+
/**
|
|
42
|
+
* @default vertical ? '100%' : '0%'
|
|
43
|
+
*/
|
|
44
|
+
y2?: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Rotate the gradient by a given angle in degrees
|
|
48
|
+
*/
|
|
49
|
+
rotate?: number;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Define the coordinate system for attributes (i.e. gradientUnits)
|
|
53
|
+
*
|
|
54
|
+
* @default 'objectBoundingBox'
|
|
55
|
+
*/
|
|
56
|
+
units?: 'objectBoundingBox' | 'userSpaceOnUse';
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A bindable reference to the underlying `<linearGradient>` element
|
|
60
|
+
*
|
|
61
|
+
* @bindable
|
|
62
|
+
*/
|
|
63
|
+
ref?: SVGLinearGradientElement;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Render as a child of the gradient and will opt out of the default stops
|
|
67
|
+
* being rendered.
|
|
68
|
+
*/
|
|
69
|
+
stopsContent?: Snippet;
|
|
70
|
+
|
|
71
|
+
children?: Snippet<[{ id: string; gradient: string }]>;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type LinearGradientProps = LinearGradientPropsWithoutHTML &
|
|
75
|
+
Without<SVGAttributes<SVGLinearGradientElement>, LinearGradientPropsWithoutHTML>;
|
|
76
|
+
</script>
|
|
4
77
|
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
78
|
+
<script lang="ts">
|
|
79
|
+
import { getChartContext, getRenderContext } from './Chart.svelte';
|
|
80
|
+
import { registerCanvasComponent } from './layout/Canvas.svelte';
|
|
8
81
|
import { createLinearGradient, getComputedStyles } from '../utils/canvas.js';
|
|
9
82
|
import { parsePercent } from '../utils/math.js';
|
|
83
|
+
import { createId } from '../utils/createId.js';
|
|
84
|
+
import { extractLayerProps, layerClass } from '../utils/attributes.js';
|
|
85
|
+
import { cls } from '@layerstack/tailwind';
|
|
86
|
+
|
|
87
|
+
const uid = $props.id();
|
|
88
|
+
|
|
89
|
+
let {
|
|
90
|
+
id = createId('linearGradient-', uid),
|
|
91
|
+
stops = ['var(--tw-gradient-from)', 'var(--tw-gradient-to)'],
|
|
92
|
+
vertical = false,
|
|
93
|
+
x1 = '0%',
|
|
94
|
+
y1 = '0%',
|
|
95
|
+
x2 = vertical ? '0%' : '100%',
|
|
96
|
+
y2 = vertical ? '100%' : '0%',
|
|
97
|
+
rotate,
|
|
98
|
+
units = 'objectBoundingBox',
|
|
99
|
+
ref: refProp = $bindable(),
|
|
100
|
+
class: className,
|
|
101
|
+
stopsContent,
|
|
102
|
+
children,
|
|
103
|
+
...restProps
|
|
104
|
+
}: LinearGradientProps = $props();
|
|
105
|
+
|
|
106
|
+
let ref = $state<SVGLinearGradientElement>();
|
|
107
|
+
$effect.pre(() => {
|
|
108
|
+
refProp = ref;
|
|
109
|
+
});
|
|
10
110
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/** 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 */
|
|
15
|
-
export let stops: string[] | [string | number, string][] = [
|
|
16
|
-
'var(--tw-gradient-from)',
|
|
17
|
-
'var(--tw-gradient-to)',
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
/** Apply color stops top-to-bottom (true) or left-to-right (false) */
|
|
21
|
-
export let vertical = false;
|
|
22
|
-
export let x1 = '0%';
|
|
23
|
-
export let y1 = '0%';
|
|
24
|
-
export let x2 = vertical ? '0%' : '100%';
|
|
25
|
-
export let y2 = vertical ? '100%' : '0%';
|
|
26
|
-
|
|
27
|
-
export let rotate: number | undefined = undefined;
|
|
28
|
-
|
|
29
|
-
/** Define the coordinate system for attributes (i.e. gradientUnits) */
|
|
30
|
-
export let units: 'objectBoundingBox' | 'userSpaceOnUse' = 'objectBoundingBox';
|
|
31
|
-
|
|
32
|
-
let className: string | undefined = undefined;
|
|
33
|
-
export { className as class };
|
|
34
|
-
|
|
35
|
-
const { width, height, padding } = chartContext();
|
|
36
|
-
|
|
37
|
-
const renderContext = getRenderContext();
|
|
38
|
-
const canvasContext = getCanvasContext();
|
|
111
|
+
const ctx = getChartContext();
|
|
112
|
+
const renderCtx = getRenderContext();
|
|
39
113
|
|
|
40
|
-
let canvasGradient
|
|
114
|
+
let canvasGradient = $state<CanvasGradient>();
|
|
41
115
|
|
|
42
|
-
function render(
|
|
116
|
+
function render(_ctx: CanvasRenderingContext2D) {
|
|
43
117
|
// Use `getComputedStyles()` to convert each stop (if using CSS variables and/or classes) to color values
|
|
44
118
|
const _stops = stops.map((stop, i) => {
|
|
45
119
|
if (Array.isArray(stop)) {
|
|
46
|
-
const { fill } = getComputedStyles(
|
|
120
|
+
const { fill } = getComputedStyles(_ctx.canvas, {
|
|
47
121
|
styles: { fill: stop[1] },
|
|
48
122
|
classes: className,
|
|
49
123
|
});
|
|
50
124
|
return { offset: parsePercent(stop[0]), color: fill };
|
|
51
125
|
} else {
|
|
52
|
-
const { fill } = getComputedStyles(
|
|
126
|
+
const { fill } = getComputedStyles(_ctx.canvas, {
|
|
53
127
|
styles: { fill: stop },
|
|
54
128
|
classes: className,
|
|
55
129
|
});
|
|
@@ -57,41 +131,38 @@
|
|
|
57
131
|
}
|
|
58
132
|
});
|
|
59
133
|
|
|
60
|
-
// TODO: Use x1/y1/x2/y2 values (convert from
|
|
134
|
+
// TODO: Use x1/y1/x2/y2 values (convert from percentage strings)
|
|
61
135
|
const gradient = createLinearGradient(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
vertical ?
|
|
66
|
-
vertical ?
|
|
136
|
+
_ctx,
|
|
137
|
+
ctx.padding.left,
|
|
138
|
+
ctx.padding.top,
|
|
139
|
+
vertical ? ctx.padding.left : ctx.width - ctx.padding.right,
|
|
140
|
+
vertical ? ctx.height + ctx.padding.bottom : ctx.padding.top,
|
|
67
141
|
_stops
|
|
68
142
|
);
|
|
69
143
|
|
|
70
144
|
canvasGradient = gradient;
|
|
71
145
|
}
|
|
72
146
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
$: if (renderContext === 'canvas') {
|
|
80
|
-
canvasUnregister = canvasContext.register({ name: 'Gradient', render });
|
|
147
|
+
if (renderCtx === 'canvas') {
|
|
148
|
+
registerCanvasComponent({
|
|
149
|
+
name: 'Gradient',
|
|
150
|
+
render,
|
|
151
|
+
deps: () => [x1, y1, x2, y2, stops, className],
|
|
152
|
+
});
|
|
81
153
|
}
|
|
82
|
-
|
|
83
|
-
onDestroy(() => {
|
|
84
|
-
if (renderContext === 'canvas') {
|
|
85
|
-
canvasUnregister();
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
154
|
</script>
|
|
89
155
|
|
|
90
|
-
{#if
|
|
91
|
-
|
|
92
|
-
|
|
156
|
+
{#if renderCtx === 'canvas'}
|
|
157
|
+
<!--
|
|
158
|
+
TODO: we can probably pass the context to coerce this type so we don't need a bunch
|
|
159
|
+
of predicates to check if the gradient is a CanvasGradient or not...
|
|
160
|
+
-->
|
|
161
|
+
{@render children?.({ id, gradient: asAny(canvasGradient) })}
|
|
162
|
+
{:else if renderCtx === 'svg'}
|
|
93
163
|
<defs>
|
|
94
164
|
<linearGradient
|
|
165
|
+
bind:this={ref}
|
|
95
166
|
{id}
|
|
96
167
|
{x1}
|
|
97
168
|
{y1}
|
|
@@ -99,25 +170,29 @@
|
|
|
99
170
|
{y2}
|
|
100
171
|
gradientTransform={rotate ? `rotate(${rotate})` : ''}
|
|
101
172
|
gradientUnits={units}
|
|
102
|
-
{
|
|
173
|
+
{...extractLayerProps(restProps, 'linear-gradient')}
|
|
103
174
|
>
|
|
104
|
-
|
|
105
|
-
{
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
175
|
+
{#if stopsContent}
|
|
176
|
+
{@render stopsContent?.()}
|
|
177
|
+
{:else if stops}
|
|
178
|
+
{#each stops as stop, i}
|
|
179
|
+
{#if Array.isArray(stop)}
|
|
180
|
+
<stop
|
|
181
|
+
offset={stop[0]}
|
|
182
|
+
stop-color={stop[1]}
|
|
183
|
+
class={cls(layerClass('linear-gradient-stop'), className)}
|
|
184
|
+
/>
|
|
185
|
+
{:else}
|
|
186
|
+
<stop
|
|
187
|
+
offset="{i * (100 / (stops.length - 1))}%"
|
|
188
|
+
stop-color={stop}
|
|
189
|
+
class={cls(layerClass('linear-gradient-stop'), className)}
|
|
190
|
+
/>
|
|
191
|
+
{/if}
|
|
192
|
+
{/each}
|
|
193
|
+
{/if}
|
|
119
194
|
</linearGradient>
|
|
120
195
|
</defs>
|
|
121
196
|
|
|
122
|
-
|
|
197
|
+
{@render children?.({ id, gradient: `url(#${id})` })}
|
|
123
198
|
{/if}
|
|
@@ -1,32 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import { type Without } from '../utils/types.js';
|
|
2
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
export type LinearGradientPropsWithoutHTML = {
|
|
5
|
+
/**
|
|
6
|
+
* Unique id for linearGradient
|
|
7
|
+
*/
|
|
8
|
+
id?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Array array of strings (colors), will equally distributed from 0-100%.
|
|
11
|
+
* If array of tuples, will use first value as the offset, and second as color
|
|
12
|
+
*
|
|
13
|
+
* @default `['var(--tw-gradient-from)', 'var(--tw-gradient-to)']`
|
|
14
|
+
*/
|
|
15
|
+
stops?: string[] | [string | number, string][];
|
|
16
|
+
/**
|
|
17
|
+
* Apply color stops top-to-bottom (true) or left-to-right (false)
|
|
18
|
+
*
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
vertical?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* @default '0%'
|
|
24
|
+
*/
|
|
25
|
+
x1?: string;
|
|
26
|
+
/**
|
|
27
|
+
* @default '0%'
|
|
28
|
+
*/
|
|
29
|
+
y1?: string;
|
|
30
|
+
/**
|
|
31
|
+
* @default vertical ? '0%' : '100%'
|
|
32
|
+
*/
|
|
33
|
+
x2?: string;
|
|
34
|
+
/**
|
|
35
|
+
* @default vertical ? '100%' : '0%'
|
|
36
|
+
*/
|
|
37
|
+
y2?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Rotate the gradient by a given angle in degrees
|
|
40
|
+
*/
|
|
41
|
+
rotate?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Define the coordinate system for attributes (i.e. gradientUnits)
|
|
44
|
+
*
|
|
45
|
+
* @default 'objectBoundingBox'
|
|
46
|
+
*/
|
|
47
|
+
units?: 'objectBoundingBox' | 'userSpaceOnUse';
|
|
48
|
+
/**
|
|
49
|
+
* A bindable reference to the underlying `<linearGradient>` element
|
|
50
|
+
*
|
|
51
|
+
* @bindable
|
|
52
|
+
*/
|
|
53
|
+
ref?: SVGLinearGradientElement;
|
|
54
|
+
/**
|
|
55
|
+
* Render as a child of the gradient and will opt out of the default stops
|
|
56
|
+
* being rendered.
|
|
57
|
+
*/
|
|
58
|
+
stopsContent?: Snippet;
|
|
59
|
+
children?: Snippet<[{
|
|
60
|
+
id: string;
|
|
61
|
+
gradient: string;
|
|
62
|
+
}]>;
|
|
26
63
|
};
|
|
27
|
-
export type LinearGradientProps =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export default
|
|
31
|
-
}
|
|
32
|
-
export {};
|
|
64
|
+
export type LinearGradientProps = LinearGradientPropsWithoutHTML & Without<SVGAttributes<SVGLinearGradientElement>, LinearGradientPropsWithoutHTML>;
|
|
65
|
+
declare const LinearGradient: import("svelte").Component<LinearGradientProps, {}, "ref">;
|
|
66
|
+
type LinearGradient = ReturnType<typeof LinearGradient>;
|
|
67
|
+
export default LinearGradient;
|
|
@@ -1,6 +1,73 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { MarkerOptions } from './MarkerWrapper.svelte';
|
|
3
|
+
import type { Without } from '../utils/types.js';
|
|
4
|
+
import type { MotionNoneOption, MotionTweenOption } from '../utils/motion.svelte.js';
|
|
5
|
+
import { curveBumpX, curveBumpY, type CurveFactory } from 'd3-shape';
|
|
6
|
+
|
|
7
|
+
export type LinkPropsWithoutHTML = {
|
|
8
|
+
// Override what is used from context
|
|
9
|
+
data?: any;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Update source and target accessors to be compatible with d3-sankey. see: https://github.com/d3/d3-sankey#sankeyLinkHorizontal
|
|
13
|
+
*
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
sankey?: boolean;
|
|
17
|
+
source?: (d: any) => any;
|
|
18
|
+
target?: (d: any) => any;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Convenient property to swap x/y accessor logic
|
|
22
|
+
*/
|
|
23
|
+
orientation?: 'vertical' | 'horizontal';
|
|
24
|
+
|
|
25
|
+
x?: (d: any) => any;
|
|
26
|
+
y?: (d: any) => any;
|
|
27
|
+
curve?: CurveFactory;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Marker to attach to both start and end points of the line
|
|
31
|
+
*/
|
|
32
|
+
marker?: MarkerOptions;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Marker to attach to the middle point of the line
|
|
36
|
+
*/
|
|
37
|
+
markerMid?: MarkerOptions;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Marker to attach to the start point of the line
|
|
41
|
+
*/
|
|
42
|
+
markerStart?: MarkerOptions;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Marker to attach to the end point of the line
|
|
46
|
+
*/
|
|
47
|
+
markerEnd?: MarkerOptions;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Apply explicit coordinates to the line. Useful when dealing with
|
|
51
|
+
* force simulation links.
|
|
52
|
+
*/
|
|
53
|
+
explicitCoords?: {
|
|
54
|
+
x1: number;
|
|
55
|
+
y1: number;
|
|
56
|
+
x2: number;
|
|
57
|
+
y2: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
motion?: MotionTweenOption | MotionNoneOption;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type LinkProps = LinkPropsWithoutHTML & Without<ConnectorProps, LinkPropsWithoutHTML>;
|
|
64
|
+
|
|
65
|
+
const FALLBACK_COORDS = { x: 0, y: 0 };
|
|
66
|
+
</script>
|
|
67
|
+
|
|
1
68
|
<script lang="ts">
|
|
2
69
|
/*
|
|
3
|
-
|
|
70
|
+
TODO:
|
|
4
71
|
- [ ] Show path progressively show / animated in on load. Also fix sliding in from left side (at last in from bottom)
|
|
5
72
|
- [ ] Support link types
|
|
6
73
|
- [ ] https://airbnb.io/visx/linktypes
|
|
@@ -13,109 +80,98 @@
|
|
|
13
80
|
- [ ] Investigate: https://observablehq.com/@fil/sankey-link-paths
|
|
14
81
|
- [ ] Use for annotations - https://github.com/techniq/layerchart/issues/11
|
|
15
82
|
*/
|
|
16
|
-
import
|
|
17
|
-
import
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
import Connector, { type ConnectorProps } from './Connector.svelte';
|
|
84
|
+
import { extractLayerProps } from '../utils/attributes.js';
|
|
85
|
+
|
|
86
|
+
let {
|
|
87
|
+
data,
|
|
88
|
+
sankey = false,
|
|
89
|
+
source: sourceProp,
|
|
90
|
+
target: targetProp,
|
|
91
|
+
orientation: orientationProp,
|
|
92
|
+
x: xProp,
|
|
93
|
+
y: yProp,
|
|
94
|
+
curve: curveProp,
|
|
95
|
+
explicitCoords,
|
|
96
|
+
type = 'd3',
|
|
97
|
+
sweep = 'none',
|
|
98
|
+
...restProps
|
|
99
|
+
}: LinkProps = $props();
|
|
100
|
+
|
|
101
|
+
const sourceAccessor = $derived.by(() => {
|
|
102
|
+
if (sourceProp) return sourceProp;
|
|
103
|
+
if (sankey) return (d: any) => ({ node: d.source, y: d.y0, isSource: true });
|
|
104
|
+
return (d: any) => d.source;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const targetAccessor = $derived.by(() => {
|
|
108
|
+
if (targetProp) return targetProp;
|
|
109
|
+
if (sankey) return (d: any) => ({ node: d.target, y: d.y1, isSource: false });
|
|
110
|
+
return (d: any) => d.target;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const orientation = $derived.by(() => {
|
|
114
|
+
if (orientationProp) return orientationProp;
|
|
115
|
+
if (sankey) return 'horizontal';
|
|
116
|
+
return 'vertical';
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const curve = $derived.by(() => {
|
|
120
|
+
if (curveProp) return curveProp;
|
|
121
|
+
if (orientation === 'horizontal') return curveBumpX;
|
|
122
|
+
return curveBumpY;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const xAccessor = $derived.by(() => {
|
|
126
|
+
if (xProp) return xProp;
|
|
127
|
+
if (sankey) return (d: any) => (d.isSource ? d.node.x1 : d.node.x0);
|
|
128
|
+
return (d: any) => (orientation === 'horizontal' ? d.y : d.x);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const yAccessor = $derived.by(() => {
|
|
132
|
+
if (yProp) return yProp;
|
|
133
|
+
if (sankey) return (d: any) => d.y;
|
|
134
|
+
return (d: any) => (orientation === 'horizontal' ? d.x : d.y);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const sourceCoords = $derived.by(() => {
|
|
138
|
+
if (explicitCoords) return { x: explicitCoords.x1, y: explicitCoords.y1 };
|
|
139
|
+
if (!data) return FALLBACK_COORDS;
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
const sourceData = sourceAccessor(data);
|
|
143
|
+
if (sourceData == null) return FALLBACK_COORDS;
|
|
144
|
+
const xVal = xAccessor(sourceData);
|
|
145
|
+
const yVal = yAccessor(sourceData);
|
|
146
|
+
return { x: Number.isFinite(xVal) ? xVal : 0, y: Number.isFinite(yVal) ? yVal : 0 };
|
|
147
|
+
} catch (e) {
|
|
148
|
+
console.error('Error accessing source coordinates:', e, 'Data:', data);
|
|
149
|
+
return FALLBACK_COORDS;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const targetCoords = $derived.by(() => {
|
|
154
|
+
if (explicitCoords) return { x: explicitCoords.x2, y: explicitCoords.y2 };
|
|
155
|
+
if (!data) return FALLBACK_COORDS;
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
const targetData = targetAccessor(data);
|
|
159
|
+
if (targetData == null) return FALLBACK_COORDS;
|
|
160
|
+
const xVal = xAccessor(targetData);
|
|
161
|
+
const yVal = yAccessor(targetData);
|
|
162
|
+
return { x: Number.isFinite(xVal) ? xVal : 0, y: Number.isFinite(yVal) ? yVal : 0 };
|
|
163
|
+
} catch (e) {
|
|
164
|
+
console.error('Error accessing target coordinates:', e, 'Data:', data);
|
|
165
|
+
return FALLBACK_COORDS;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
79
168
|
</script>
|
|
80
169
|
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
{onclick}
|
|
89
|
-
{onpointerenter}
|
|
90
|
-
{onpointermove}
|
|
91
|
-
{onpointerleave}
|
|
92
|
-
{onpointerover}
|
|
93
|
-
{onpointerout}
|
|
94
|
-
{...$$restProps}
|
|
170
|
+
<Connector
|
|
171
|
+
source={sourceCoords}
|
|
172
|
+
target={targetCoords}
|
|
173
|
+
{type}
|
|
174
|
+
{curve}
|
|
175
|
+
{sweep}
|
|
176
|
+
{...extractLayerProps(restProps, 'link')}
|
|
95
177
|
/>
|
|
96
|
-
|
|
97
|
-
<slot name="markerStart" id={markerStartId}>
|
|
98
|
-
{#if markerStart}
|
|
99
|
-
<Marker
|
|
100
|
-
id={markerStartId}
|
|
101
|
-
type={typeof markerStart === 'string' ? markerStart : undefined}
|
|
102
|
-
{...typeof markerStart === 'object' ? markerStart : null}
|
|
103
|
-
/>
|
|
104
|
-
{/if}
|
|
105
|
-
</slot>
|
|
106
|
-
|
|
107
|
-
<slot name="markerMid" id={markerMidId}>
|
|
108
|
-
<Marker
|
|
109
|
-
id={markerMidId}
|
|
110
|
-
type={typeof markerMid === 'string' ? markerMid : undefined}
|
|
111
|
-
{...typeof markerMid === 'object' ? markerMid : null}
|
|
112
|
-
/>
|
|
113
|
-
</slot>
|
|
114
|
-
|
|
115
|
-
<slot name="markerEnd" id={markerEndId}>
|
|
116
|
-
<Marker
|
|
117
|
-
id={markerEndId}
|
|
118
|
-
type={typeof markerEnd === 'string' ? markerEnd : undefined}
|
|
119
|
-
{...typeof markerEnd === 'object' ? markerEnd : null}
|
|
120
|
-
/>
|
|
121
|
-
</slot>
|