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,177 +1,289 @@
|
|
|
1
|
-
<script lang="ts">
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Transition, TransitionParams, Without } from '../utils/types.js';
|
|
3
|
+
import { extractTweenConfig, type MotionProp } from '../utils/motion.svelte.js';
|
|
2
4
|
import type { SVGAttributes } from 'svelte/elements';
|
|
5
|
+
|
|
6
|
+
export type GridPropsWithoutHTML<In extends Transition = Transition> = {
|
|
7
|
+
/**
|
|
8
|
+
* Draw a x-axis lines
|
|
9
|
+
*
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
x?: boolean | Pick<SVGAttributes<SVGElement>, 'class' | 'style'>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Draw a y-axis lines
|
|
16
|
+
*
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
y?: boolean | Pick<SVGAttributes<SVGElement>, 'class' | 'style'>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Control the number of x-axis ticks
|
|
23
|
+
*/
|
|
24
|
+
xTicks?: TicksConfig;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Control the number of y-axis ticks
|
|
28
|
+
*
|
|
29
|
+
* @default !isScaleBand(ctx.yScale) ? 4 : undefined
|
|
30
|
+
*/
|
|
31
|
+
yTicks?: TicksConfig;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Line alignment when band scale is used (x or y axis)
|
|
35
|
+
*
|
|
36
|
+
* @default 'center'
|
|
37
|
+
*/
|
|
38
|
+
bandAlign?: 'center' | 'between';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Render `y` lines with circles or linear splines
|
|
42
|
+
*
|
|
43
|
+
* @default 'circle'
|
|
44
|
+
*/
|
|
45
|
+
radialY?: 'circle' | 'linear';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Classes to apply to the rendered elements.
|
|
49
|
+
*
|
|
50
|
+
* @default {}
|
|
51
|
+
*/
|
|
52
|
+
classes?: {
|
|
53
|
+
root?: string;
|
|
54
|
+
line?: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Transition function for entering elements
|
|
59
|
+
* @default defaults to fade if motion is tweened
|
|
60
|
+
*/
|
|
61
|
+
transitionIn?: In;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Parameters for the transitionIn function
|
|
65
|
+
* @default { easing: cubicIn }
|
|
66
|
+
*/
|
|
67
|
+
transitionInParams?: TransitionParams<In>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A reference to the underlying outermost `<g>` element.
|
|
71
|
+
*
|
|
72
|
+
* @bindable
|
|
73
|
+
*/
|
|
74
|
+
ref?: SVGGElement;
|
|
75
|
+
|
|
76
|
+
motion?: MotionProp;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type GridProps<In extends Transition = Transition> = Omit<
|
|
80
|
+
GridPropsWithoutHTML<In> & Without<SVGAttributes<SVGGElement>, GridPropsWithoutHTML<In>>,
|
|
81
|
+
'children'
|
|
82
|
+
>;
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<script lang="ts">
|
|
3
86
|
import { fade } from 'svelte/transition';
|
|
4
87
|
import { cubicIn } from 'svelte/easing';
|
|
5
|
-
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
6
88
|
|
|
7
|
-
import { curveLinearClosed } from 'd3-shape';
|
|
89
|
+
import { curveLinearClosed, pointRadial } from 'd3-shape';
|
|
8
90
|
|
|
9
91
|
import { cls } from '@layerstack/tailwind';
|
|
10
|
-
import type { TransitionParams } from 'svelte-ux'; // TODO: Replace with `@layerstack/svelte-types` or similar
|
|
11
92
|
|
|
12
|
-
import {
|
|
13
|
-
import { isScaleBand, type AnyScale } from '../utils/scales.js';
|
|
93
|
+
import { isScaleBand } from '../utils/scales.svelte.js';
|
|
14
94
|
|
|
95
|
+
import Circle from './Circle.svelte';
|
|
96
|
+
import Line from './Line.svelte';
|
|
15
97
|
import Rule from './Rule.svelte';
|
|
16
98
|
import Spline from './Spline.svelte';
|
|
17
|
-
import
|
|
99
|
+
import { getChartContext } from './Chart.svelte';
|
|
100
|
+
import { extractLayerProps, layerClass } from '../utils/attributes.js';
|
|
101
|
+
import { resolveTickVals, type TicksConfig } from '../utils/ticks.js';
|
|
102
|
+
|
|
103
|
+
const ctx = getChartContext();
|
|
104
|
+
|
|
105
|
+
let {
|
|
106
|
+
x = false,
|
|
107
|
+
y = false,
|
|
108
|
+
xTicks,
|
|
109
|
+
yTicks: yTicksProp,
|
|
110
|
+
bandAlign = 'center',
|
|
111
|
+
radialY = 'circle',
|
|
112
|
+
motion,
|
|
113
|
+
transitionIn: transitionInProp,
|
|
114
|
+
transitionInParams = { easing: cubicIn },
|
|
115
|
+
classes = {},
|
|
116
|
+
class: className,
|
|
117
|
+
ref: refProp = $bindable(),
|
|
118
|
+
...restProps
|
|
119
|
+
}: GridProps = $props();
|
|
18
120
|
|
|
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
|
-
export let transitionInParams: TransitionParams = { easing: cubicIn };
|
|
50
|
-
|
|
51
|
-
export let classes: {
|
|
52
|
-
root?: string;
|
|
53
|
-
line?: string;
|
|
54
|
-
} = {};
|
|
55
|
-
|
|
56
|
-
function getTickVals(scale: AnyScale, ticks: TicksConfig): any[] {
|
|
57
|
-
return Array.isArray(ticks)
|
|
58
|
-
? ticks
|
|
59
|
-
: typeof ticks === 'function'
|
|
60
|
-
? ticks(scale)
|
|
61
|
-
: isScaleBand(scale)
|
|
62
|
-
? ticks
|
|
63
|
-
? scale.domain().filter((v: any, i: number) => i % ticks === 0)
|
|
64
|
-
: scale.domain()
|
|
65
|
-
: scale.ticks?.(ticks);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
$: xTickVals = getTickVals($xScale, xTicks);
|
|
69
|
-
$: yTickVals = getTickVals($yScale, yTicks);
|
|
70
|
-
|
|
71
|
-
$: xBandOffset = isScaleBand($xScale)
|
|
72
|
-
? bandAlign === 'between'
|
|
73
|
-
? -($xScale.padding() * $xScale.step()) / 2 // before
|
|
74
|
-
: $xScale.step() / 2 - ($xScale.padding() * $xScale.step()) / 2 // center
|
|
75
|
-
: 0;
|
|
76
|
-
|
|
77
|
-
$: yBandOffset = isScaleBand($yScale)
|
|
78
|
-
? bandAlign === 'between'
|
|
79
|
-
? -($yScale.padding() * $yScale.step()) / 2 // before
|
|
80
|
-
: $yScale.step() / 2 - ($yScale.padding() * $yScale.step()) / 2 // center
|
|
81
|
-
: 0;
|
|
121
|
+
let ref = $state<SVGGElement>();
|
|
122
|
+
|
|
123
|
+
$effect.pre(() => {
|
|
124
|
+
refProp = ref;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const yTicks = $derived(yTicksProp ?? (!isScaleBand(ctx.yScale) ? 4 : undefined));
|
|
128
|
+
|
|
129
|
+
const tweenConfig = $derived(extractTweenConfig(motion));
|
|
130
|
+
|
|
131
|
+
const transitionIn = $derived((transitionInProp ?? tweenConfig?.options) ? fade : () => ({}));
|
|
132
|
+
|
|
133
|
+
const xTickVals = $derived(resolveTickVals(ctx.xScale, xTicks));
|
|
134
|
+
const yTickVals = $derived(resolveTickVals(ctx.yScale, yTicks));
|
|
135
|
+
|
|
136
|
+
const xBandOffset = $derived(
|
|
137
|
+
isScaleBand(ctx.xScale)
|
|
138
|
+
? bandAlign === 'between'
|
|
139
|
+
? -(ctx.xScale.padding() * ctx.xScale.step()) / 2 // before
|
|
140
|
+
: ctx.xScale.step() / 2 - (ctx.xScale.padding() * ctx.xScale.step()) / 2 // center
|
|
141
|
+
: 0
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const yBandOffset = $derived(
|
|
145
|
+
isScaleBand(ctx.yScale)
|
|
146
|
+
? bandAlign === 'between'
|
|
147
|
+
? -(ctx.yScale.padding() * ctx.yScale.step()) / 2 // before
|
|
148
|
+
: ctx.yScale.step() / 2 - (ctx.yScale.padding() * ctx.yScale.step()) / 2 // center
|
|
149
|
+
: 0
|
|
150
|
+
);
|
|
82
151
|
</script>
|
|
83
152
|
|
|
84
|
-
<g class={cls('
|
|
153
|
+
<g bind:this={ref} class={cls(layerClass('grid'), classes.root, className)} {...restProps}>
|
|
85
154
|
{#if x}
|
|
86
|
-
{@const splineProps =
|
|
87
|
-
|
|
155
|
+
{@const splineProps = extractLayerProps(x, 'grid-x-line')}
|
|
156
|
+
|
|
157
|
+
<g in:transitionIn={transitionInParams} class={layerClass('grid-x')}>
|
|
88
158
|
{#each xTickVals as x (x)}
|
|
89
|
-
{#if
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
{
|
|
97
|
-
{
|
|
159
|
+
{#if ctx.radial}
|
|
160
|
+
{@const [x1, y1] = pointRadial(ctx.xScale(x), ctx.yRange[0])}
|
|
161
|
+
{@const [x2, y2] = pointRadial(ctx.xScale(x), ctx.yRange[1])}
|
|
162
|
+
<Line
|
|
163
|
+
{x1}
|
|
164
|
+
{y1}
|
|
165
|
+
{x2}
|
|
166
|
+
{y2}
|
|
167
|
+
motion={tweenConfig}
|
|
98
168
|
{...splineProps}
|
|
99
|
-
class={cls(
|
|
169
|
+
class={cls(
|
|
170
|
+
layerClass('grid-x-radial-line'),
|
|
171
|
+
'stroke-surface-content/10',
|
|
172
|
+
classes.line,
|
|
173
|
+
splineProps?.class
|
|
174
|
+
)}
|
|
100
175
|
/>
|
|
101
176
|
{:else}
|
|
102
177
|
<Rule
|
|
103
178
|
{x}
|
|
104
179
|
xOffset={xBandOffset}
|
|
105
|
-
{
|
|
106
|
-
{spring}
|
|
180
|
+
{motion}
|
|
107
181
|
{...splineProps}
|
|
108
|
-
class={cls(
|
|
182
|
+
class={cls(
|
|
183
|
+
layerClass('grid-x-rule'),
|
|
184
|
+
'stroke-surface-content/10',
|
|
185
|
+
classes.line,
|
|
186
|
+
splineProps?.class
|
|
187
|
+
)}
|
|
109
188
|
/>
|
|
110
189
|
{/if}
|
|
111
190
|
{/each}
|
|
112
191
|
|
|
113
192
|
<!-- Add extra rule after last band -->
|
|
114
|
-
{#if isScaleBand(
|
|
193
|
+
{#if isScaleBand(ctx.xScale) && bandAlign === 'between' && !ctx.radial && xTickVals.length}
|
|
115
194
|
<Rule
|
|
116
195
|
x={xTickVals[xTickVals.length - 1]}
|
|
117
|
-
xOffset={
|
|
118
|
-
{
|
|
119
|
-
{spring}
|
|
196
|
+
xOffset={ctx.xScale.step() + xBandOffset}
|
|
197
|
+
{motion}
|
|
120
198
|
{...splineProps}
|
|
121
|
-
class={cls(
|
|
199
|
+
class={cls(
|
|
200
|
+
layerClass('grid-x-end-rule'),
|
|
201
|
+
'stroke-surface-content/10',
|
|
202
|
+
classes.line,
|
|
203
|
+
splineProps?.class
|
|
204
|
+
)}
|
|
122
205
|
/>
|
|
123
206
|
{/if}
|
|
124
207
|
</g>
|
|
125
208
|
{/if}
|
|
126
209
|
|
|
127
210
|
{#if y}
|
|
128
|
-
{@const splineProps =
|
|
129
|
-
<g in:transitionIn={transitionInParams}>
|
|
211
|
+
{@const splineProps = extractLayerProps(y, 'grid-y-line')}
|
|
212
|
+
<g in:transitionIn={transitionInParams} class={layerClass('grid-y')}>
|
|
130
213
|
{#each yTickVals as y (y)}
|
|
131
|
-
{#if
|
|
214
|
+
{#if ctx.radial}
|
|
132
215
|
{#if radialY === 'circle'}
|
|
133
216
|
<Circle
|
|
134
|
-
r={
|
|
135
|
-
{
|
|
136
|
-
{spring}
|
|
217
|
+
r={ctx.yScale(y) + yBandOffset}
|
|
218
|
+
{motion}
|
|
137
219
|
{...splineProps}
|
|
138
|
-
class={cls(
|
|
220
|
+
class={cls(
|
|
221
|
+
layerClass('grid-y-radial-circle'),
|
|
222
|
+
'fill-none stroke-surface-content/10',
|
|
223
|
+
classes.line,
|
|
224
|
+
splineProps?.class
|
|
225
|
+
)}
|
|
139
226
|
/>
|
|
140
227
|
{:else}
|
|
141
228
|
<Spline
|
|
142
229
|
data={xTickVals.map((x) => ({ x, y }))}
|
|
143
230
|
x="x"
|
|
144
231
|
y="y"
|
|
145
|
-
|
|
146
|
-
{tweened}
|
|
147
|
-
{spring}
|
|
232
|
+
motion={tweenConfig}
|
|
148
233
|
curve={curveLinearClosed}
|
|
149
234
|
{...splineProps}
|
|
150
|
-
class={cls(
|
|
235
|
+
class={cls(
|
|
236
|
+
layerClass('grid-y-radial-line'),
|
|
237
|
+
'stroke-surface-content/10',
|
|
238
|
+
classes.line,
|
|
239
|
+
splineProps?.class
|
|
240
|
+
)}
|
|
151
241
|
/>
|
|
152
242
|
{/if}
|
|
153
243
|
{:else}
|
|
154
244
|
<Rule
|
|
155
245
|
{y}
|
|
156
246
|
yOffset={yBandOffset}
|
|
157
|
-
{
|
|
158
|
-
{spring}
|
|
247
|
+
{motion}
|
|
159
248
|
{...splineProps}
|
|
160
|
-
class={cls(
|
|
249
|
+
class={cls(
|
|
250
|
+
layerClass('grid-y-rule'),
|
|
251
|
+
'stroke-surface-content/10',
|
|
252
|
+
classes.line,
|
|
253
|
+
splineProps?.class
|
|
254
|
+
)}
|
|
161
255
|
/>
|
|
162
256
|
{/if}
|
|
163
257
|
{/each}
|
|
164
258
|
|
|
165
259
|
<!-- Add extra rule after last band -->
|
|
166
|
-
{#if isScaleBand(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
260
|
+
{#if isScaleBand(ctx.yScale) && bandAlign === 'between' && yTickVals.length}
|
|
261
|
+
{#if ctx.radial}
|
|
262
|
+
<Circle
|
|
263
|
+
r={ctx.yScale(yTickVals[yTickVals.length - 1])! + ctx.yScale.step() + yBandOffset}
|
|
264
|
+
{motion}
|
|
265
|
+
{...splineProps}
|
|
266
|
+
class={cls(
|
|
267
|
+
layerClass('grid-y-radial-circle'),
|
|
268
|
+
'fill-none stroke-surface-content/10',
|
|
269
|
+
classes.line,
|
|
270
|
+
splineProps?.class
|
|
271
|
+
)}
|
|
272
|
+
/>
|
|
273
|
+
{:else}
|
|
274
|
+
<Rule
|
|
275
|
+
y={yTickVals[yTickVals.length - 1]}
|
|
276
|
+
yOffset={ctx.yScale.step() + yBandOffset}
|
|
277
|
+
{motion}
|
|
278
|
+
{...splineProps}
|
|
279
|
+
class={cls(
|
|
280
|
+
layerClass('grid-y-end-rule'),
|
|
281
|
+
'stroke-surface-content/10',
|
|
282
|
+
classes.line,
|
|
283
|
+
splineProps?.class
|
|
284
|
+
)}
|
|
285
|
+
/>
|
|
286
|
+
{/if}
|
|
175
287
|
{/if}
|
|
176
288
|
</g>
|
|
177
289
|
{/if}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Transition, TransitionParams, Without } from '../utils/types.js';
|
|
2
|
+
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
3
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
4
|
+
export type GridPropsWithoutHTML<In extends Transition = Transition> = {
|
|
5
|
+
/**
|
|
6
|
+
* Draw a x-axis lines
|
|
7
|
+
*
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
x?: boolean | Pick<SVGAttributes<SVGElement>, 'class' | 'style'>;
|
|
11
|
+
/**
|
|
12
|
+
* Draw a y-axis lines
|
|
13
|
+
*
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
y?: boolean | Pick<SVGAttributes<SVGElement>, 'class' | 'style'>;
|
|
17
|
+
/**
|
|
18
|
+
* Control the number of x-axis ticks
|
|
19
|
+
*/
|
|
20
|
+
xTicks?: TicksConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Control the number of y-axis ticks
|
|
23
|
+
*
|
|
24
|
+
* @default !isScaleBand(ctx.yScale) ? 4 : undefined
|
|
25
|
+
*/
|
|
26
|
+
yTicks?: TicksConfig;
|
|
27
|
+
/**
|
|
28
|
+
* Line alignment when band scale is used (x or y axis)
|
|
29
|
+
*
|
|
30
|
+
* @default 'center'
|
|
31
|
+
*/
|
|
32
|
+
bandAlign?: 'center' | 'between';
|
|
33
|
+
/**
|
|
34
|
+
* Render `y` lines with circles or linear splines
|
|
35
|
+
*
|
|
36
|
+
* @default 'circle'
|
|
37
|
+
*/
|
|
38
|
+
radialY?: 'circle' | 'linear';
|
|
39
|
+
/**
|
|
40
|
+
* Classes to apply to the rendered elements.
|
|
41
|
+
*
|
|
42
|
+
* @default {}
|
|
43
|
+
*/
|
|
44
|
+
classes?: {
|
|
45
|
+
root?: string;
|
|
46
|
+
line?: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Transition function for entering elements
|
|
50
|
+
* @default defaults to fade if motion is tweened
|
|
51
|
+
*/
|
|
52
|
+
transitionIn?: In;
|
|
53
|
+
/**
|
|
54
|
+
* Parameters for the transitionIn function
|
|
55
|
+
* @default { easing: cubicIn }
|
|
56
|
+
*/
|
|
57
|
+
transitionInParams?: TransitionParams<In>;
|
|
58
|
+
/**
|
|
59
|
+
* A reference to the underlying outermost `<g>` element.
|
|
60
|
+
*
|
|
61
|
+
* @bindable
|
|
62
|
+
*/
|
|
63
|
+
ref?: SVGGElement;
|
|
64
|
+
motion?: MotionProp;
|
|
65
|
+
};
|
|
66
|
+
export type GridProps<In extends Transition = Transition> = Omit<GridPropsWithoutHTML<In> & Without<SVGAttributes<SVGGElement>, GridPropsWithoutHTML<In>>, 'children'>;
|
|
67
|
+
import { type TicksConfig } from '../utils/ticks.js';
|
|
68
|
+
declare const Grid: import("svelte").Component<GridProps<Transition>, {}, "ref">;
|
|
69
|
+
type Grid = ReturnType<typeof Grid>;
|
|
70
|
+
export default Grid;
|