layerchart 2.0.0-next.0 → 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 +25 -24
- 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,73 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export type BrushRange = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
};
|
|
4
7
|
export type BrushContextValue = {
|
|
5
8
|
xDomain: DomainType;
|
|
6
9
|
yDomain: DomainType;
|
|
7
10
|
isActive: boolean;
|
|
8
|
-
range:
|
|
9
|
-
x: number;
|
|
10
|
-
y: number;
|
|
11
|
-
width: number;
|
|
12
|
-
height: number;
|
|
13
|
-
};
|
|
11
|
+
range: BrushRange;
|
|
14
12
|
handleSize: number;
|
|
15
13
|
};
|
|
16
|
-
export
|
|
17
|
-
export declare function
|
|
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
|
-
|
|
14
|
+
export declare function getBrushContext(): BrushContextValue;
|
|
15
|
+
export declare function setBrushContext(brush: BrushContextValue): BrushContextValue;
|
|
16
|
+
type BrushEventPayload = {
|
|
17
|
+
xDomain: DomainType | null;
|
|
18
|
+
yDomain: DomainType | null;
|
|
19
|
+
};
|
|
20
|
+
type BrushContextPropsWithoutHTML = {
|
|
21
|
+
/**
|
|
22
|
+
* The axis to apply brushing
|
|
23
|
+
*
|
|
24
|
+
* @default 'x'
|
|
25
|
+
*/
|
|
26
|
+
axis?: 'x' | 'y' | 'both';
|
|
27
|
+
/**
|
|
28
|
+
* Size of the draggable handles (width/height)
|
|
29
|
+
*
|
|
30
|
+
* @default 5
|
|
31
|
+
*/
|
|
32
|
+
handleSize?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Only show range while actively brushing.
|
|
35
|
+
* Useful with `brushEnd` event
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
resetOnEnd?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Ignore click to reset.
|
|
42
|
+
* Useful to add click handlers to marks. Requires external resetting (button, another chart, etc)
|
|
43
|
+
*
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
ignoreResetClick?: boolean;
|
|
47
|
+
xDomain?: DomainType;
|
|
48
|
+
yDomain?: DomainType;
|
|
49
|
+
/**
|
|
50
|
+
* Mode of operation
|
|
51
|
+
* - `integrated`: use with single chart
|
|
52
|
+
* - `separated`: use with separate (typically smaller) chart and state can be managed
|
|
53
|
+
* externally (sync with other charts, etc). Show active selection when domain does not equal
|
|
54
|
+
* original
|
|
55
|
+
*
|
|
56
|
+
* @default 'integrated'
|
|
57
|
+
*/
|
|
58
|
+
mode?: 'integrated' | 'separated';
|
|
59
|
+
/**
|
|
60
|
+
* Disable brush
|
|
61
|
+
*
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
disabled?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Attributes passed to the range <div> element
|
|
67
|
+
*/
|
|
68
|
+
range?: Partial<HTMLAttributes<HTMLElement>>;
|
|
69
|
+
/**
|
|
70
|
+
* Attributes passed to the handle <div> elements
|
|
71
|
+
*/
|
|
72
|
+
handle?: Partial<HTMLAttributes<HTMLElement>>;
|
|
73
|
+
/**
|
|
74
|
+
* Classes to apply to the various elements rendered
|
|
75
|
+
*
|
|
76
|
+
* @default {}
|
|
77
|
+
*/
|
|
78
|
+
classes?: {
|
|
79
|
+
root?: string;
|
|
80
|
+
frame?: string;
|
|
81
|
+
range?: string;
|
|
82
|
+
handle?: string;
|
|
83
|
+
labels?: string;
|
|
66
84
|
};
|
|
85
|
+
onChange?: (detail: BrushEventPayload) => void;
|
|
86
|
+
onBrushStart?: (detail: BrushEventPayload) => void;
|
|
87
|
+
onBrushEnd?: (detail: BrushEventPayload) => void;
|
|
88
|
+
onReset?: (detail: BrushEventPayload) => void;
|
|
89
|
+
/**
|
|
90
|
+
* A reference to this brush's context for use in parent
|
|
91
|
+
* components.
|
|
92
|
+
*
|
|
93
|
+
* @bindable
|
|
94
|
+
*/
|
|
95
|
+
brushContext?: BrushContextValue;
|
|
96
|
+
children?: Snippet<[{
|
|
97
|
+
brushContext: BrushContextValue;
|
|
98
|
+
}]>;
|
|
67
99
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
export
|
|
100
|
+
import { type DomainType } from '../utils/scales.svelte.js';
|
|
101
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
102
|
+
import type { Snippet } from 'svelte';
|
|
103
|
+
declare const BrushContext: import("svelte").Component<BrushContextPropsWithoutHTML, {}, "brushContext">;
|
|
104
|
+
type BrushContext = ReturnType<typeof BrushContext>;
|
|
105
|
+
export default BrushContext;
|
|
@@ -1,90 +1,147 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export type CalendarCell = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
color: any;
|
|
6
|
+
data: any;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type CalendarPropsWithoutHTML = {
|
|
10
|
+
/**
|
|
11
|
+
* The start date of the calendar.
|
|
12
|
+
*/
|
|
13
|
+
start: Date;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The end date of the calendar.
|
|
17
|
+
*/
|
|
18
|
+
end: Date;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Size of the cell in the calendar.
|
|
22
|
+
*
|
|
23
|
+
* - `number`: sets width/height as same value (square).
|
|
24
|
+
* - `array`: sets as [width,height].
|
|
25
|
+
* - `undefined/omitted`: is derived from Chart width/height
|
|
26
|
+
*/
|
|
27
|
+
cellSize?: number | [number, number];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Enable drawing path around each month. If object, pass as props to underlying <path>
|
|
31
|
+
*
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
monthPath?: boolean | Partial<ComponentProps<typeof MonthPath>>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Props to pass to the `<text>` element for month labels.
|
|
38
|
+
*/
|
|
39
|
+
monthLabel?: Partial<ComponentProps<typeof Text>>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Tooltip context to setup mouse events to show tooltip for related data
|
|
43
|
+
*/
|
|
44
|
+
tooltipContext?: TooltipContextValue;
|
|
45
|
+
|
|
46
|
+
children?: Snippet<[{ cells: CalendarCell[] }]>;
|
|
47
|
+
} & Omit<
|
|
48
|
+
RectPropsWithoutHTML,
|
|
49
|
+
'children' | 'x' | 'y' | 'width' | 'height' | 'fill' | 'onpointermove' | 'onpointerleave'
|
|
50
|
+
>;
|
|
51
|
+
|
|
52
|
+
export type CalendarProps = CalendarPropsWithoutHTML &
|
|
53
|
+
Without<SVGAttributes<SVGRectElement>, CalendarPropsWithoutHTML>;
|
|
54
|
+
</script>
|
|
55
|
+
|
|
1
56
|
<script lang="ts">
|
|
2
|
-
import { type ComponentProps } from 'svelte';
|
|
57
|
+
import { type ComponentProps, type Snippet } from 'svelte';
|
|
3
58
|
import { timeDays, timeMonths, timeWeek, timeYear } from 'd3-time';
|
|
4
59
|
import { index } from 'd3-array';
|
|
5
60
|
import { format } from 'date-fns';
|
|
6
61
|
|
|
7
|
-
import {
|
|
8
|
-
import Rect from './Rect.svelte';
|
|
62
|
+
import Rect, { type RectPropsWithoutHTML } from './Rect.svelte';
|
|
9
63
|
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
10
64
|
import MonthPath from './MonthPath.svelte';
|
|
11
65
|
import Text from './Text.svelte';
|
|
12
66
|
import { chartDataArray } from '../utils/common.js';
|
|
67
|
+
import { getChartContext } from './Chart.svelte';
|
|
68
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
69
|
+
import type { Without } from '../utils/types.js';
|
|
70
|
+
import { extractLayerProps } from '../utils/attributes.js';
|
|
71
|
+
|
|
72
|
+
let {
|
|
73
|
+
end,
|
|
74
|
+
start,
|
|
75
|
+
cellSize: cellSizeProp,
|
|
76
|
+
monthPath = false,
|
|
77
|
+
tooltipContext: tooltip,
|
|
78
|
+
children,
|
|
79
|
+
monthLabel,
|
|
80
|
+
...restProps
|
|
81
|
+
}: CalendarPropsWithoutHTML = $props();
|
|
82
|
+
|
|
83
|
+
const ctx = getChartContext();
|
|
84
|
+
|
|
85
|
+
const yearDays = $derived(timeDays(start, end));
|
|
86
|
+
const yearMonths = $derived(timeMonths(start, end));
|
|
87
|
+
const yearWeeks = $derived(timeWeek.count(start, end));
|
|
88
|
+
const chartCellWidth = $derived(ctx.width / (yearWeeks + 1));
|
|
89
|
+
const chartCellHeight = $derived(ctx.height / 7);
|
|
90
|
+
// Use smallest to fit, and keep square aspect
|
|
91
|
+
const chartCellSize = $derived(Math.min(chartCellWidth, chartCellHeight));
|
|
13
92
|
|
|
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
|
-
$: chartCellSize = Math.min(chartCellWidth, chartCellHeight); // Use smallest to fit, and keep square aspect
|
|
39
|
-
|
|
40
|
-
$: [cellWidth, cellHeight] = Array.isArray(cellSize)
|
|
41
|
-
? cellSize
|
|
42
|
-
: typeof cellSize === 'number'
|
|
43
|
-
? [cellSize, cellSize]
|
|
44
|
-
: [chartCellSize, chartCellSize];
|
|
45
|
-
|
|
46
|
-
$: dataByDate = data && $config.x ? index(chartDataArray($data), (d) => $x(d)) : new Map();
|
|
47
|
-
|
|
48
|
-
$: cells = yearDays.map((date) => {
|
|
49
|
-
const cellData = dataByDate.get(date) ?? { date };
|
|
50
|
-
return {
|
|
51
|
-
x: timeWeek.count(timeYear(date), date) * cellWidth,
|
|
52
|
-
y: date.getDay() * cellHeight,
|
|
53
|
-
color: $config.c ? $cGet(cellData) : 'transparent',
|
|
54
|
-
data: cellData,
|
|
55
|
-
};
|
|
56
|
-
});
|
|
93
|
+
// [width, height]
|
|
94
|
+
const cellSize: [number, number] = $derived(
|
|
95
|
+
Array.isArray(cellSizeProp)
|
|
96
|
+
? cellSizeProp
|
|
97
|
+
: typeof cellSizeProp === 'number'
|
|
98
|
+
? [cellSizeProp, cellSizeProp]
|
|
99
|
+
: [chartCellSize, chartCellSize]
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const dataByDate = $derived(
|
|
103
|
+
ctx.data && ctx.config.x ? index(chartDataArray(ctx.data), (d) => ctx.x(d)) : new Map()
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const cells = $derived(
|
|
107
|
+
yearDays.map((date) => {
|
|
108
|
+
const cellData = dataByDate.get(date) ?? { date };
|
|
109
|
+
return {
|
|
110
|
+
x: timeWeek.count(timeYear(date), date) * cellSize[0],
|
|
111
|
+
y: date.getDay() * cellSize[1],
|
|
112
|
+
color: ctx.config.c ? ctx.cGet(cellData) : 'transparent',
|
|
113
|
+
data: cellData,
|
|
114
|
+
};
|
|
115
|
+
})
|
|
116
|
+
) satisfies CalendarCell[];
|
|
57
117
|
</script>
|
|
58
118
|
|
|
59
|
-
|
|
119
|
+
{#if children}
|
|
120
|
+
{@render children({ cells })}
|
|
121
|
+
{:else}
|
|
60
122
|
{#each cells as cell}
|
|
61
123
|
<Rect
|
|
62
124
|
x={cell.x}
|
|
63
125
|
y={cell.y}
|
|
64
|
-
width={
|
|
65
|
-
height={
|
|
126
|
+
width={cellSize[0]}
|
|
127
|
+
height={cellSize[1]}
|
|
66
128
|
fill={cell.color}
|
|
67
129
|
onpointermove={(e) => tooltip?.show(e, cell.data)}
|
|
68
130
|
onpointerleave={(e) => tooltip?.hide()}
|
|
69
|
-
|
|
70
|
-
{...$$restProps}
|
|
131
|
+
{...extractLayerProps(restProps, 'calendar-cell', 'stroke-surface-content/5')}
|
|
71
132
|
/>
|
|
72
133
|
{/each}
|
|
73
|
-
|
|
134
|
+
{/if}
|
|
74
135
|
|
|
75
136
|
{#if monthPath}
|
|
76
137
|
{#each yearMonths as date}
|
|
77
|
-
<MonthPath
|
|
78
|
-
{date}
|
|
79
|
-
cellSize={[cellWidth, cellHeight]}
|
|
80
|
-
{...typeof monthPath === 'object' ? monthPath : null}
|
|
81
|
-
/>
|
|
138
|
+
<MonthPath {date} {cellSize} {...extractLayerProps(monthPath, 'calendar-month-path')} />
|
|
82
139
|
|
|
83
140
|
<Text
|
|
84
|
-
x={timeWeek.count(timeYear.floor(date), timeWeek.ceil(date)) *
|
|
141
|
+
x={timeWeek.count(timeYear.floor(date), timeWeek.ceil(date)) * cellSize[0]}
|
|
85
142
|
y={-4}
|
|
86
143
|
value={format(date, 'MMM')}
|
|
87
|
-
|
|
144
|
+
{...extractLayerProps(monthLabel, 'calendar-month-label', 'text-xs')}
|
|
88
145
|
/>
|
|
89
146
|
{/each}
|
|
90
147
|
{/if}
|
|
@@ -1,33 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export type CalendarCell = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
color: any;
|
|
5
|
+
data: any;
|
|
6
|
+
};
|
|
7
|
+
export type CalendarPropsWithoutHTML = {
|
|
8
|
+
/**
|
|
9
|
+
* The start date of the calendar.
|
|
10
|
+
*/
|
|
11
|
+
start: Date;
|
|
12
|
+
/**
|
|
13
|
+
* The end date of the calendar.
|
|
14
|
+
*/
|
|
15
|
+
end: Date;
|
|
16
|
+
/**
|
|
17
|
+
* Size of the cell in the calendar.
|
|
18
|
+
*
|
|
19
|
+
* - `number`: sets width/height as same value (square).
|
|
20
|
+
* - `array`: sets as [width,height].
|
|
21
|
+
* - `undefined/omitted`: is derived from Chart width/height
|
|
22
|
+
*/
|
|
23
|
+
cellSize?: number | [number, number];
|
|
24
|
+
/**
|
|
25
|
+
* Enable drawing path around each month. If object, pass as props to underlying <path>
|
|
26
|
+
*
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
monthPath?: boolean | Partial<ComponentProps<typeof MonthPath>>;
|
|
30
|
+
/**
|
|
31
|
+
* Props to pass to the `<text>` element for month labels.
|
|
32
|
+
*/
|
|
33
|
+
monthLabel?: Partial<ComponentProps<typeof Text>>;
|
|
34
|
+
/**
|
|
35
|
+
* Tooltip context to setup mouse events to show tooltip for related data
|
|
36
|
+
*/
|
|
37
|
+
tooltipContext?: TooltipContextValue;
|
|
38
|
+
children?: Snippet<[{
|
|
39
|
+
cells: CalendarCell[];
|
|
40
|
+
}]>;
|
|
41
|
+
} & Omit<RectPropsWithoutHTML, 'children' | 'x' | 'y' | 'width' | 'height' | 'fill' | 'onpointermove' | 'onpointerleave'>;
|
|
42
|
+
export type CalendarProps = CalendarPropsWithoutHTML & Without<SVGAttributes<SVGRectElement>, CalendarPropsWithoutHTML>;
|
|
43
|
+
import { type ComponentProps, type Snippet } from 'svelte';
|
|
44
|
+
import { type RectPropsWithoutHTML } from './Rect.svelte';
|
|
3
45
|
import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
|
|
4
46
|
import MonthPath from './MonthPath.svelte';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
monthPath?: (boolean | Partial<ComponentProps<MonthPath>>) | undefined;
|
|
12
|
-
tooltip?: TooltipContextValue | undefined;
|
|
13
|
-
};
|
|
14
|
-
events: {
|
|
15
|
-
[evt: string]: CustomEvent<any>;
|
|
16
|
-
};
|
|
17
|
-
slots: {
|
|
18
|
-
default: {
|
|
19
|
-
cells: {
|
|
20
|
-
x: number;
|
|
21
|
-
y: number;
|
|
22
|
-
color: any;
|
|
23
|
-
data: any;
|
|
24
|
-
}[];
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
export type CalendarProps = typeof __propDef.props;
|
|
29
|
-
export type CalendarEvents = typeof __propDef.events;
|
|
30
|
-
export type CalendarSlots = typeof __propDef.slots;
|
|
31
|
-
export default class Calendar extends SvelteComponentTyped<CalendarProps, CalendarEvents, CalendarSlots> {
|
|
32
|
-
}
|
|
33
|
-
export {};
|
|
47
|
+
import Text from './Text.svelte';
|
|
48
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
49
|
+
import type { Without } from '../utils/types.js';
|
|
50
|
+
declare const Calendar: import("svelte").Component<CalendarPropsWithoutHTML, {}, "">;
|
|
51
|
+
type Calendar = ReturnType<typeof Calendar>;
|
|
52
|
+
export default Calendar;
|