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
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Transition, TransitionParams, Without } from '../utils/types.js';
|
|
2
|
+
export type AxisPropsWithoutHTML<In extends Transition = Transition> = {
|
|
3
|
+
/**
|
|
4
|
+
* Location of axis
|
|
5
|
+
*/
|
|
6
|
+
placement: 'top' | 'bottom' | 'left' | 'right' | 'angle' | 'radius';
|
|
7
|
+
/**
|
|
8
|
+
* The label for the axis.
|
|
9
|
+
*
|
|
10
|
+
* Can either be a string or a snippet to render custom content.
|
|
11
|
+
* The snippet receives spreadable props to apply to the label.
|
|
12
|
+
*/
|
|
13
|
+
label?: string | Snippet<[{
|
|
14
|
+
props: ComponentProps<typeof Text>;
|
|
15
|
+
}]>;
|
|
16
|
+
/**
|
|
17
|
+
* Location of axis label
|
|
18
|
+
* @default 'middle'
|
|
19
|
+
*/
|
|
20
|
+
labelPlacement?: 'start' | 'middle' | 'end';
|
|
21
|
+
/**
|
|
22
|
+
* Props applied to label Text
|
|
23
|
+
*/
|
|
24
|
+
labelProps?: Partial<ComponentProps<typeof Text>>;
|
|
25
|
+
/**
|
|
26
|
+
* Draw a rule line. Use Rule component for greater rendering order control
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
rule?: boolean | Partial<ComponentProps<typeof Rule>>;
|
|
30
|
+
/**
|
|
31
|
+
* Draw grid lines
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
grid?: boolean | Pick<SVGAttributes<SVGElement>, 'class' | 'style'>;
|
|
35
|
+
/**
|
|
36
|
+
* Control the number of ticks
|
|
37
|
+
*/
|
|
38
|
+
ticks?: TicksConfig;
|
|
39
|
+
/**
|
|
40
|
+
* Length of the tick line
|
|
41
|
+
* @default 4
|
|
42
|
+
*/
|
|
43
|
+
tickLength?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Whether to render tick marks.
|
|
46
|
+
*
|
|
47
|
+
* @default true
|
|
48
|
+
*/
|
|
49
|
+
tickMarks?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Format tick labels
|
|
52
|
+
*/
|
|
53
|
+
format?: FormatType;
|
|
54
|
+
/**
|
|
55
|
+
* Props to apply to each tick label
|
|
56
|
+
*/
|
|
57
|
+
tickLabelProps?: Partial<ComponentProps<typeof Text>>;
|
|
58
|
+
/**
|
|
59
|
+
* A snippet to render your own custom tick label.
|
|
60
|
+
*/
|
|
61
|
+
tickLabel?: Snippet<[{
|
|
62
|
+
props: ComponentProps<typeof Text>;
|
|
63
|
+
index: number;
|
|
64
|
+
}]>;
|
|
65
|
+
/**
|
|
66
|
+
* Transition function for entering elements
|
|
67
|
+
* @default defaults to fade if the motion prop is set to tweened
|
|
68
|
+
*/
|
|
69
|
+
transitionIn?: In;
|
|
70
|
+
/**
|
|
71
|
+
* Parameters for the transitionIn function
|
|
72
|
+
* @default { easing: cubicIn }
|
|
73
|
+
*/
|
|
74
|
+
transitionInParams?: TransitionParams<In>;
|
|
75
|
+
/**
|
|
76
|
+
* Scale for the axis
|
|
77
|
+
*/
|
|
78
|
+
scale?: any;
|
|
79
|
+
/**
|
|
80
|
+
* Classes for styling various parts of the axis
|
|
81
|
+
* @default {}
|
|
82
|
+
*/
|
|
83
|
+
classes?: {
|
|
84
|
+
root?: string;
|
|
85
|
+
label?: string;
|
|
86
|
+
rule?: string;
|
|
87
|
+
tick?: string;
|
|
88
|
+
tickLabel?: string;
|
|
89
|
+
};
|
|
90
|
+
motion?: MotionProp;
|
|
91
|
+
};
|
|
92
|
+
export type AxisProps<In extends Transition = Transition> = AxisPropsWithoutHTML<In> & Without<SVGAttributes<SVGGElement>, AxisPropsWithoutHTML<In>>;
|
|
93
|
+
import { type ComponentProps, type Snippet } from 'svelte';
|
|
94
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
95
|
+
import { type FormatType } from '@layerstack/utils';
|
|
96
|
+
import Rule from './Rule.svelte';
|
|
97
|
+
import Text from './Text.svelte';
|
|
98
|
+
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
99
|
+
import { type TicksConfig } from '../utils/ticks.js';
|
|
100
|
+
declare class __sveltets_Render<T extends Transition = Transition> {
|
|
101
|
+
props(): AxisProps<T>;
|
|
102
|
+
events(): {};
|
|
103
|
+
slots(): {};
|
|
104
|
+
bindings(): "";
|
|
105
|
+
exports(): {};
|
|
106
|
+
}
|
|
107
|
+
interface $$IsomorphicComponent {
|
|
108
|
+
new <T extends Transition = Transition>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
109
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
110
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
111
|
+
<T extends Transition = Transition>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
112
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
113
|
+
}
|
|
114
|
+
declare const Axis: $$IsomorphicComponent;
|
|
115
|
+
type Axis<T extends Transition = Transition> = InstanceType<typeof Axis<T>>;
|
|
116
|
+
export default Axis;
|
|
@@ -1,89 +1,137 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { createDimensionGetter, type Insets } from '../utils/rect.svelte.js';
|
|
3
|
+
|
|
4
|
+
export type BarPropsWithoutHTML = {
|
|
5
|
+
bar: Object;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Override `x` from context. Useful for multiple Bar instances
|
|
9
|
+
*
|
|
10
|
+
* @default ctx.x
|
|
11
|
+
*/
|
|
12
|
+
x?: Accessor;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Override `y` from context. Useful for multiple Bar instances
|
|
16
|
+
*
|
|
17
|
+
* @default ctx.y
|
|
18
|
+
*/
|
|
19
|
+
y?: Accessor;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Override `x1` from context. Useful for multiple Bar instances
|
|
23
|
+
*
|
|
24
|
+
* @default ctx.x1
|
|
25
|
+
*/
|
|
26
|
+
x1?: Accessor;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Override `y1` from context. Useful for multiple Bar instances
|
|
30
|
+
*
|
|
31
|
+
* @default ctx.y1
|
|
32
|
+
*/
|
|
33
|
+
y1?: Accessor;
|
|
34
|
+
|
|
35
|
+
radius?: number;
|
|
36
|
+
|
|
37
|
+
insets?: Insets;
|
|
38
|
+
|
|
39
|
+
initialX?: number;
|
|
40
|
+
|
|
41
|
+
initialY?: number;
|
|
42
|
+
|
|
43
|
+
initialHeight?: number;
|
|
44
|
+
|
|
45
|
+
initialWidth?: number;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Control which corners are rounded with radius. Uses <path> instead of <rect> when not set
|
|
49
|
+
* to `all`
|
|
50
|
+
*/
|
|
51
|
+
rounded?:
|
|
52
|
+
| 'all'
|
|
53
|
+
| 'none'
|
|
54
|
+
| 'edge'
|
|
55
|
+
| 'top'
|
|
56
|
+
| 'bottom'
|
|
57
|
+
| 'left'
|
|
58
|
+
| 'right'
|
|
59
|
+
| 'top-left'
|
|
60
|
+
| 'top-right'
|
|
61
|
+
| 'bottom-left'
|
|
62
|
+
| 'bottom-right';
|
|
63
|
+
|
|
64
|
+
motion?: MotionProp<'x' | 'y' | 'width' | 'height'>;
|
|
65
|
+
} & CommonStyleProps;
|
|
66
|
+
|
|
67
|
+
export type BarProps = BarPropsWithoutHTML &
|
|
68
|
+
Without<
|
|
69
|
+
Omit<SVGAttributes<SVGElement>, 'width' | 'height' | 'x' | 'y' | 'offset'>,
|
|
70
|
+
BarPropsWithoutHTML
|
|
71
|
+
>;
|
|
72
|
+
</script>
|
|
73
|
+
|
|
1
74
|
<script lang="ts">
|
|
2
|
-
import {
|
|
75
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
76
|
+
import { greatestAbs } from '@layerstack/utils';
|
|
3
77
|
|
|
4
|
-
import { chartContext } from './ChartContext.svelte';
|
|
5
78
|
import Rect from './Rect.svelte';
|
|
6
79
|
import Spline from './Spline.svelte';
|
|
7
80
|
|
|
8
|
-
import {
|
|
9
|
-
import { isScaleBand } from '../utils/scales.js';
|
|
81
|
+
import { isScaleBand } from '../utils/scales.svelte.js';
|
|
10
82
|
import { accessor, type Accessor } from '../utils/common.js';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* Override `y` from context. Useful for multiple Bar instances
|
|
24
|
-
*/
|
|
25
|
-
export let y: Accessor = $yContext;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Override `x1` from context. Useful for multiple Bar instances
|
|
29
|
-
*/
|
|
30
|
-
export let x1: Accessor = undefined;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Override `y1` from context. Useful for multiple Bar instances
|
|
34
|
-
*/
|
|
35
|
-
export let y1: Accessor = undefined;
|
|
36
|
-
|
|
37
|
-
export let fill: string | undefined = undefined;
|
|
38
|
-
export let fillOpacity: number | undefined = undefined;
|
|
39
|
-
export let stroke = 'black';
|
|
40
|
-
export let strokeWidth = 0;
|
|
41
|
-
export let opacity: number | undefined = undefined;
|
|
42
|
-
export let radius = 0;
|
|
43
|
-
|
|
44
|
-
/** Control which corners are rounded with radius. Uses <path> instead of <rect> when not set to `all` */
|
|
45
|
-
export let rounded:
|
|
46
|
-
| 'all'
|
|
47
|
-
| 'none'
|
|
48
|
-
| 'edge'
|
|
49
|
-
| 'top'
|
|
50
|
-
| 'bottom'
|
|
51
|
-
| 'left'
|
|
52
|
-
| 'right'
|
|
53
|
-
| 'top-left'
|
|
54
|
-
| 'top-right'
|
|
55
|
-
| 'bottom-left'
|
|
56
|
-
| 'bottom-right' = 'all';
|
|
57
|
-
|
|
58
|
-
export let insets: Insets | undefined = undefined;
|
|
59
|
-
|
|
60
|
-
export let onclick: ((e: MouseEvent) => void) | undefined = undefined;
|
|
61
|
-
export let onpointerenter: ((e: PointerEvent) => void) | undefined = undefined;
|
|
62
|
-
export let onpointermove: ((e: PointerEvent) => void) | undefined = undefined;
|
|
63
|
-
export let onpointerleave: ((e: PointerEvent) => void) | undefined = undefined;
|
|
64
|
-
|
|
65
|
-
export let spring: ComponentProps<Rect>['spring'] = undefined;
|
|
66
|
-
export let tweened: ComponentProps<Rect>['tweened'] = undefined;
|
|
67
|
-
|
|
68
|
-
$: if (stroke === null || stroke === undefined) stroke = 'black';
|
|
69
|
-
|
|
70
|
-
$: getDimensions = createDimensionGetter(chartContext(), {
|
|
71
|
-
x,
|
|
72
|
-
y,
|
|
83
|
+
import { getChartContext } from './Chart.svelte';
|
|
84
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
85
|
+
import { extractLayerProps } from '../utils/attributes.js';
|
|
86
|
+
import { extractTweenConfig, type MotionProp } from '../utils/motion.svelte.js';
|
|
87
|
+
import Arc from './Arc.svelte';
|
|
88
|
+
|
|
89
|
+
const ctx = getChartContext();
|
|
90
|
+
|
|
91
|
+
let {
|
|
92
|
+
bar,
|
|
93
|
+
x = ctx.x,
|
|
94
|
+
y = ctx.y,
|
|
73
95
|
x1,
|
|
74
96
|
y1,
|
|
97
|
+
fill,
|
|
98
|
+
fillOpacity,
|
|
99
|
+
stroke: strokeProp = 'black',
|
|
100
|
+
strokeWidth = 0,
|
|
101
|
+
opacity,
|
|
102
|
+
radius = 0,
|
|
103
|
+
rounded: roundedProp = 'all',
|
|
104
|
+
motion,
|
|
75
105
|
insets,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
106
|
+
initialX,
|
|
107
|
+
initialY,
|
|
108
|
+
initialHeight,
|
|
109
|
+
initialWidth,
|
|
110
|
+
...restProps
|
|
111
|
+
}: BarProps = $props();
|
|
112
|
+
|
|
113
|
+
const stroke = $derived(strokeProp === null || strokeProp === undefined ? 'black' : strokeProp);
|
|
114
|
+
|
|
115
|
+
const getDimensions = $derived(
|
|
116
|
+
createDimensionGetter(ctx, () => ({
|
|
117
|
+
x,
|
|
118
|
+
y,
|
|
119
|
+
x1,
|
|
120
|
+
y1,
|
|
121
|
+
insets,
|
|
122
|
+
}))
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const dimensions = $derived(getDimensions(bar) ?? { x: 0, y: 0, width: 0, height: 0 });
|
|
126
|
+
|
|
127
|
+
const isVertical = $derived(isScaleBand(ctx.xScale));
|
|
128
|
+
const valueAccessor = $derived(accessor(isVertical ? y : x));
|
|
129
|
+
const value = $derived(valueAccessor(bar));
|
|
130
|
+
const resolvedValue = $derived(Array.isArray(value) ? greatestAbs(value) : value);
|
|
83
131
|
|
|
84
132
|
// Resolved `rounded="edge"` based on orientation and value
|
|
85
|
-
|
|
86
|
-
|
|
133
|
+
const rounded = $derived(
|
|
134
|
+
roundedProp === 'edge'
|
|
87
135
|
? isVertical
|
|
88
136
|
? resolvedValue >= 0
|
|
89
137
|
? 'top'
|
|
@@ -91,18 +139,18 @@
|
|
|
91
139
|
: resolvedValue >= 0
|
|
92
140
|
? 'right'
|
|
93
141
|
: 'left'
|
|
94
|
-
:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
142
|
+
: roundedProp
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const topLeft = $derived(['all', 'top', 'left', 'top-left'].includes(rounded));
|
|
146
|
+
const topRight = $derived(['all', 'top', 'right', 'top-right'].includes(rounded));
|
|
147
|
+
const bottomLeft = $derived(['all', 'bottom', 'left', 'bottom-left'].includes(rounded));
|
|
148
|
+
const bottomRight = $derived(['all', 'bottom', 'right', 'bottom-right'].includes(rounded));
|
|
149
|
+
const width = $derived(dimensions.width);
|
|
150
|
+
const height = $derived(dimensions.height);
|
|
151
|
+
const diameter = $derived(2 * radius);
|
|
152
|
+
const pathData = $derived(
|
|
153
|
+
`M${dimensions.x + radius},${dimensions.y} h${width - diameter}
|
|
106
154
|
${topRight ? `a${radius},${radius} 0 0 1 ${radius},${radius}` : `h${radius}v${radius}`}
|
|
107
155
|
v${height - diameter}
|
|
108
156
|
${bottomRight ? `a${radius},${radius} 0 0 1 ${-radius},${radius}` : `v${radius}h${-radius}`}
|
|
@@ -111,29 +159,43 @@
|
|
|
111
159
|
v${diameter - height}
|
|
112
160
|
${topLeft ? `a${radius},${radius} 0 0 1 ${radius},${-radius}` : `v${-radius}h${radius}`}
|
|
113
161
|
z`
|
|
114
|
-
|
|
115
|
-
|
|
162
|
+
.split('\n')
|
|
163
|
+
.join('')
|
|
164
|
+
);
|
|
116
165
|
</script>
|
|
117
166
|
|
|
118
|
-
{#if
|
|
167
|
+
{#if ctx.radial}
|
|
168
|
+
<Arc
|
|
169
|
+
innerRadius={dimensions.y}
|
|
170
|
+
outerRadius={dimensions.y + dimensions.height}
|
|
171
|
+
startAngle={dimensions.x}
|
|
172
|
+
endAngle={dimensions.x + dimensions.width}
|
|
173
|
+
{fill}
|
|
174
|
+
{fillOpacity}
|
|
175
|
+
{stroke}
|
|
176
|
+
{strokeWidth}
|
|
177
|
+
{opacity}
|
|
178
|
+
cornerRadius={radius}
|
|
179
|
+
{...extractLayerProps(restProps, 'bar')}
|
|
180
|
+
/>
|
|
181
|
+
{:else if rounded === 'all' || rounded === 'none' || radius === 0}
|
|
119
182
|
<Rect
|
|
120
183
|
{fill}
|
|
121
184
|
{fillOpacity}
|
|
122
185
|
{stroke}
|
|
123
186
|
{strokeWidth}
|
|
124
187
|
{opacity}
|
|
125
|
-
rx={
|
|
126
|
-
{
|
|
127
|
-
{
|
|
128
|
-
{
|
|
129
|
-
{
|
|
130
|
-
{
|
|
131
|
-
{onpointerleave}
|
|
132
|
-
on:touchmove
|
|
188
|
+
rx={rounded === 'none' ? 0 : radius}
|
|
189
|
+
{motion}
|
|
190
|
+
{initialX}
|
|
191
|
+
{initialY}
|
|
192
|
+
{initialHeight}
|
|
193
|
+
{initialWidth}
|
|
133
194
|
{...dimensions}
|
|
134
|
-
{
|
|
195
|
+
{...extractLayerProps(restProps, 'bar')}
|
|
135
196
|
/>
|
|
136
197
|
{:else}
|
|
198
|
+
{@const tweenMotion = extractTweenConfig(motion)}
|
|
137
199
|
<Spline
|
|
138
200
|
{pathData}
|
|
139
201
|
{fill}
|
|
@@ -141,13 +203,7 @@
|
|
|
141
203
|
{stroke}
|
|
142
204
|
{strokeWidth}
|
|
143
205
|
{opacity}
|
|
144
|
-
{
|
|
145
|
-
{
|
|
146
|
-
{onclick}
|
|
147
|
-
{onpointerenter}
|
|
148
|
-
{onpointermove}
|
|
149
|
-
{onpointerleave}
|
|
150
|
-
on:touchmove
|
|
151
|
-
{...$$restProps}
|
|
206
|
+
motion={tweenMotion}
|
|
207
|
+
{...extractLayerProps(restProps, 'bar')}
|
|
152
208
|
/>
|
|
153
209
|
{/if}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type Insets } from '../utils/rect.svelte.js';
|
|
2
|
+
export type BarPropsWithoutHTML = {
|
|
3
|
+
bar: Object;
|
|
4
|
+
/**
|
|
5
|
+
* Override `x` from context. Useful for multiple Bar instances
|
|
6
|
+
*
|
|
7
|
+
* @default ctx.x
|
|
8
|
+
*/
|
|
9
|
+
x?: Accessor;
|
|
10
|
+
/**
|
|
11
|
+
* Override `y` from context. Useful for multiple Bar instances
|
|
12
|
+
*
|
|
13
|
+
* @default ctx.y
|
|
14
|
+
*/
|
|
15
|
+
y?: Accessor;
|
|
16
|
+
/**
|
|
17
|
+
* Override `x1` from context. Useful for multiple Bar instances
|
|
18
|
+
*
|
|
19
|
+
* @default ctx.x1
|
|
20
|
+
*/
|
|
21
|
+
x1?: Accessor;
|
|
22
|
+
/**
|
|
23
|
+
* Override `y1` from context. Useful for multiple Bar instances
|
|
24
|
+
*
|
|
25
|
+
* @default ctx.y1
|
|
26
|
+
*/
|
|
27
|
+
y1?: Accessor;
|
|
28
|
+
radius?: number;
|
|
29
|
+
insets?: Insets;
|
|
30
|
+
initialX?: number;
|
|
31
|
+
initialY?: number;
|
|
32
|
+
initialHeight?: number;
|
|
33
|
+
initialWidth?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Control which corners are rounded with radius. Uses <path> instead of <rect> when not set
|
|
36
|
+
* to `all`
|
|
37
|
+
*/
|
|
38
|
+
rounded?: 'all' | 'none' | 'edge' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
39
|
+
motion?: MotionProp<'x' | 'y' | 'width' | 'height'>;
|
|
40
|
+
} & CommonStyleProps;
|
|
41
|
+
export type BarProps = BarPropsWithoutHTML & Without<Omit<SVGAttributes<SVGElement>, 'width' | 'height' | 'x' | 'y' | 'offset'>, BarPropsWithoutHTML>;
|
|
42
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
43
|
+
import { type Accessor } from '../utils/common.js';
|
|
44
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
45
|
+
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
46
|
+
declare const Bar: import("svelte").Component<BarProps, {}, "">;
|
|
47
|
+
type Bar = ReturnType<typeof Bar>;
|
|
48
|
+
export default Bar;
|
|
@@ -1,82 +1,68 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { chartDataArray, type Accessor } from '../utils/common.js';
|
|
8
|
-
import type { Insets } from '../utils/rect.js';
|
|
9
|
-
|
|
10
|
-
const { data: contextData, cGet, config } = chartContext();
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Override `data` from context. Useful for multiple Bar instances
|
|
14
|
-
*/
|
|
15
|
-
export let data: any = undefined;
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export type BarsPropsWithoutHTML = {
|
|
3
|
+
/**
|
|
4
|
+
* Override the data from the context.
|
|
5
|
+
*/
|
|
6
|
+
data?: any;
|
|
16
7
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Define unique value for {#each} `(key)` expressions
|
|
10
|
+
* to improve transitions.
|
|
11
|
+
*
|
|
12
|
+
* @default (d, index) => index
|
|
13
|
+
*/
|
|
14
|
+
key?: (d: any, index: number) => any;
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Event dispatched when an individual bar is clicked.
|
|
18
|
+
*/
|
|
19
|
+
onBarClick?: (e: MouseEvent, detail: { data: any }) => void;
|
|
26
20
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
children?: Snippet;
|
|
22
|
+
// TODO: investigate
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
} & Omit<BarPropsWithoutHTML, 'bar' | 'children'>;
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*/
|
|
35
|
-
export let y1: Accessor = undefined;
|
|
36
|
-
|
|
37
|
-
export let stroke = 'black';
|
|
38
|
-
export let strokeWidth = 0;
|
|
39
|
-
export let radius = 0;
|
|
40
|
-
export let fill: string | undefined = undefined;
|
|
41
|
-
export let fillOpacity: number | undefined = undefined;
|
|
42
|
-
export let opacity: number | undefined = undefined;
|
|
43
|
-
|
|
44
|
-
/** Inset the rect for amount of padding. Useful with multiple bars (bullet, overlap, etc) */
|
|
45
|
-
export let insets: Insets | undefined = undefined;
|
|
46
|
-
|
|
47
|
-
/** Define unique value for {#each} `(key)` expressions to improve transitions. `index` position used by default */
|
|
48
|
-
export let key: (d: any, index: number) => any = (d, i) => i;
|
|
26
|
+
export type BarsProps = BarsPropsWithoutHTML & Omit<BarProps, 'bar'>;
|
|
27
|
+
</script>
|
|
49
28
|
|
|
50
|
-
|
|
51
|
-
|
|
29
|
+
<script lang="ts">
|
|
30
|
+
import Bar, { type BarProps, type BarPropsWithoutHTML } from './Bar.svelte';
|
|
31
|
+
import { chartDataArray } from '../utils/common.js';
|
|
32
|
+
import { getChartContext } from './Chart.svelte';
|
|
33
|
+
import type { Snippet } from 'svelte';
|
|
34
|
+
import { extractLayerProps, layerClass } from '../utils/attributes.js';
|
|
52
35
|
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
let {
|
|
37
|
+
fill,
|
|
38
|
+
key = (_, i) => i,
|
|
39
|
+
data: dataProp,
|
|
40
|
+
onBarClick = () => {},
|
|
41
|
+
children,
|
|
42
|
+
radius = 0,
|
|
43
|
+
strokeWidth = 0,
|
|
44
|
+
stroke = 'black',
|
|
45
|
+
...restProps
|
|
46
|
+
}: BarsProps = $props();
|
|
55
47
|
|
|
56
|
-
|
|
48
|
+
const ctx = getChartContext();
|
|
49
|
+
const data = $derived(chartDataArray(dataProp ?? ctx.data));
|
|
57
50
|
</script>
|
|
58
51
|
|
|
59
|
-
<g class=
|
|
60
|
-
|
|
61
|
-
{
|
|
52
|
+
<g class={layerClass('bars')}>
|
|
53
|
+
{#if children}
|
|
54
|
+
{@render children()}
|
|
55
|
+
{:else}
|
|
56
|
+
{#each data as d, i (key(d, i))}
|
|
62
57
|
<Bar
|
|
63
|
-
bar={d}
|
|
64
|
-
{x}
|
|
65
|
-
{y}
|
|
66
|
-
{x1}
|
|
67
|
-
{y1}
|
|
68
|
-
fill={fill ?? ($config.c ? $cGet(d) : null)}
|
|
69
|
-
{fillOpacity}
|
|
70
|
-
{stroke}
|
|
71
|
-
{strokeWidth}
|
|
72
|
-
{opacity}
|
|
73
58
|
{radius}
|
|
74
|
-
{
|
|
75
|
-
{
|
|
76
|
-
{
|
|
77
|
-
|
|
78
|
-
{
|
|
59
|
+
{strokeWidth}
|
|
60
|
+
{stroke}
|
|
61
|
+
bar={d}
|
|
62
|
+
fill={fill ?? (ctx.config.c ? ctx.cGet(d) : null)}
|
|
63
|
+
onclick={(e) => onBarClick(e, { data: d })}
|
|
64
|
+
{...extractLayerProps(restProps, 'bars-bar')}
|
|
79
65
|
/>
|
|
80
66
|
{/each}
|
|
81
|
-
|
|
67
|
+
{/if}
|
|
82
68
|
</g>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type BarsPropsWithoutHTML = {
|
|
2
|
+
/**
|
|
3
|
+
* Override the data from the context.
|
|
4
|
+
*/
|
|
5
|
+
data?: any;
|
|
6
|
+
/**
|
|
7
|
+
* Define unique value for {#each} `(key)` expressions
|
|
8
|
+
* to improve transitions.
|
|
9
|
+
*
|
|
10
|
+
* @default (d, index) => index
|
|
11
|
+
*/
|
|
12
|
+
key?: (d: any, index: number) => any;
|
|
13
|
+
/**
|
|
14
|
+
* Event dispatched when an individual bar is clicked.
|
|
15
|
+
*/
|
|
16
|
+
onBarClick?: (e: MouseEvent, detail: {
|
|
17
|
+
data: any;
|
|
18
|
+
}) => void;
|
|
19
|
+
children?: Snippet;
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
} & Omit<BarPropsWithoutHTML, 'bar' | 'children'>;
|
|
22
|
+
export type BarsProps = BarsPropsWithoutHTML & Omit<BarProps, 'bar'>;
|
|
23
|
+
import { type BarProps, type BarPropsWithoutHTML } from './Bar.svelte';
|
|
24
|
+
import type { Snippet } from 'svelte';
|
|
25
|
+
declare const Bars: import("svelte").Component<BarsProps, {}, "">;
|
|
26
|
+
type Bars = ReturnType<typeof Bars>;
|
|
27
|
+
export default Bars;
|