svelteplot 0.0.1-alpha.9 → 0.1.3-next.3
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/LICENSE.md +5 -0
- package/README.md +3 -36
- package/dist/Mark.svelte +292 -0
- package/dist/Mark.svelte.d.ts +22 -0
- package/dist/Plot.svelte +148 -156
- package/dist/Plot.svelte.d.ts +15 -15
- package/dist/constants.d.ts +14 -0
- package/dist/constants.js +109 -0
- package/dist/core/Facet.svelte +59 -0
- package/dist/core/Facet.svelte.d.ts +18 -0
- package/dist/core/FacetAxes.svelte +66 -0
- package/dist/core/FacetAxes.svelte.d.ts +4 -0
- package/dist/core/FacetGrid.svelte +86 -0
- package/dist/core/FacetGrid.svelte.d.ts +13 -0
- package/dist/core/Plot.svelte +567 -0
- package/dist/core/Plot.svelte.d.ts +14 -0
- package/dist/helpers/arrowPath.d.ts +14 -0
- package/dist/helpers/arrowPath.js +129 -0
- package/dist/helpers/autoProjection.d.ts +19 -0
- package/dist/helpers/autoProjection.js +87 -0
- package/dist/helpers/autoScales.d.ts +23 -0
- package/dist/helpers/autoScales.js +203 -0
- package/dist/helpers/autoTicks.d.ts +3 -0
- package/dist/helpers/autoTicks.js +40 -0
- package/dist/helpers/autoTimeFormat.d.ts +2 -2
- package/dist/helpers/autoTimeFormat.js +34 -5
- package/dist/helpers/callWithProps.d.ts +8 -0
- package/dist/helpers/callWithProps.js +13 -0
- package/dist/helpers/colors.js +17 -2
- package/dist/helpers/curves.d.ts +3 -0
- package/dist/helpers/curves.js +42 -0
- package/dist/helpers/data.d.ts +9 -0
- package/dist/helpers/data.js +16 -0
- package/dist/helpers/facets.d.ts +12 -0
- package/dist/helpers/facets.js +49 -0
- package/dist/helpers/formats.d.ts +3 -0
- package/dist/helpers/formats.js +3 -0
- package/dist/helpers/getBaseStyles.d.ts +7 -2
- package/dist/helpers/getBaseStyles.js +34 -10
- package/dist/helpers/getLogTicks.js +5 -5
- package/dist/helpers/group.d.ts +6 -0
- package/dist/helpers/group.js +53 -0
- package/dist/helpers/index.d.ts +18 -0
- package/dist/helpers/index.js +53 -0
- package/dist/helpers/isRawValue.d.ts +2 -0
- package/dist/helpers/isRawValue.js +5 -0
- package/dist/helpers/isValid.d.ts +6 -0
- package/dist/helpers/isValid.js +6 -0
- package/dist/helpers/math.d.ts +19 -0
- package/dist/helpers/math.js +116 -0
- package/dist/helpers/mergeDeep.d.ts +1 -1
- package/dist/helpers/noise.d.ts +1 -0
- package/dist/helpers/noise.js +72 -0
- package/dist/helpers/projection.d.ts +33 -0
- package/dist/helpers/projection.js +100 -0
- package/dist/helpers/reduce.d.ts +10 -0
- package/dist/helpers/reduce.js +85 -0
- package/dist/helpers/regressionLoess.d.ts +12 -0
- package/dist/helpers/regressionLoess.js +47 -0
- package/dist/helpers/removeIdenticalLines.d.ts +8 -1
- package/dist/helpers/removeIdenticalLines.js +14 -7
- package/dist/helpers/resolve.d.ts +17 -0
- package/dist/helpers/resolve.js +152 -0
- package/dist/helpers/roundedRect.d.ts +9 -0
- package/dist/helpers/roundedRect.js +31 -0
- package/dist/helpers/scales.d.ts +42 -0
- package/dist/helpers/scales.js +309 -0
- package/dist/helpers/time.d.ts +6 -0
- package/dist/helpers/time.js +282 -0
- package/dist/helpers/typeChecks.d.ts +8 -5
- package/dist/helpers/typeChecks.js +27 -6
- package/dist/index.d.ts +49 -1
- package/dist/index.js +53 -2
- package/dist/marks/Area.svelte +146 -0
- package/dist/marks/Area.svelte.d.ts +30 -0
- package/dist/marks/AreaX.svelte +27 -0
- package/dist/marks/AreaX.svelte.d.ts +12 -0
- package/dist/marks/AreaY.svelte +38 -0
- package/dist/marks/AreaY.svelte.d.ts +19 -0
- package/dist/marks/Arrow.svelte +139 -0
- package/dist/marks/Arrow.svelte.d.ts +44 -0
- package/dist/marks/AxisX.svelte +198 -93
- package/dist/marks/AxisX.svelte.d.ts +17 -16
- package/dist/marks/AxisY.svelte +176 -62
- package/dist/marks/AxisY.svelte.d.ts +17 -14
- package/dist/marks/BarX.svelte +81 -0
- package/dist/marks/BarX.svelte.d.ts +4 -0
- package/dist/marks/BarY.svelte +95 -0
- package/dist/marks/BarY.svelte.d.ts +4 -0
- package/dist/marks/BollingerX.svelte +44 -0
- package/dist/marks/BollingerX.svelte.d.ts +18 -0
- package/dist/marks/BollingerY.svelte +39 -0
- package/dist/marks/BollingerY.svelte.d.ts +18 -0
- package/dist/marks/BoxX.svelte +89 -0
- package/dist/marks/BoxX.svelte.d.ts +4 -0
- package/dist/marks/BoxY.svelte +110 -0
- package/dist/marks/BoxY.svelte.d.ts +29 -0
- package/dist/marks/Cell.svelte +110 -0
- package/dist/marks/Cell.svelte.d.ts +16 -0
- package/dist/marks/CellX.svelte +24 -0
- package/dist/marks/CellX.svelte.d.ts +3 -0
- package/dist/marks/CellY.svelte +24 -0
- package/dist/marks/CellY.svelte.d.ts +3 -0
- package/dist/marks/ColorLegend.svelte +148 -27
- package/dist/marks/ColorLegend.svelte.d.ts +12 -13
- package/dist/marks/CustomMark.svelte +43 -0
- package/dist/marks/CustomMark.svelte.d.ts +16 -0
- package/dist/marks/CustomMarkHTML.svelte +103 -0
- package/dist/marks/CustomMarkHTML.svelte.d.ts +17 -0
- package/dist/marks/DifferenceY.svelte +144 -0
- package/dist/marks/DifferenceY.svelte.d.ts +30 -0
- package/dist/marks/Dot.svelte +128 -73
- package/dist/marks/Dot.svelte.d.ts +24 -14
- package/dist/marks/DotX.svelte +15 -3
- package/dist/marks/DotX.svelte.d.ts +8 -16
- package/dist/marks/DotY.svelte +8 -3
- package/dist/marks/DotY.svelte.d.ts +5 -17
- package/dist/marks/Frame.svelte +32 -31
- package/dist/marks/Frame.svelte.d.ts +7 -14
- package/dist/marks/Geo.svelte +102 -0
- package/dist/marks/Geo.svelte.d.ts +10 -0
- package/dist/marks/Graticule.svelte +28 -0
- package/dist/marks/Graticule.svelte.d.ts +9 -0
- package/dist/marks/GridX.svelte +67 -36
- package/dist/marks/GridX.svelte.d.ts +7 -18
- package/dist/marks/GridY.svelte +64 -25
- package/dist/marks/GridY.svelte.d.ts +7 -14
- package/dist/marks/HTMLTooltip.svelte +91 -0
- package/dist/marks/HTMLTooltip.svelte.d.ts +11 -0
- package/dist/marks/Line.svelte +219 -58
- package/dist/marks/Line.svelte.d.ts +30 -14
- package/dist/marks/LineX.svelte +8 -8
- package/dist/marks/LineX.svelte.d.ts +4 -17
- package/dist/marks/LineY.svelte +7 -8
- package/dist/marks/LineY.svelte.d.ts +4 -17
- package/dist/marks/Link.svelte +173 -0
- package/dist/marks/Link.svelte.d.ts +21 -0
- package/dist/marks/Pointer.svelte +126 -0
- package/dist/marks/Pointer.svelte.d.ts +23 -0
- package/dist/marks/Rect.svelte +103 -0
- package/dist/marks/Rect.svelte.d.ts +15 -0
- package/dist/marks/RectX.svelte +33 -0
- package/dist/marks/RectX.svelte.d.ts +15 -0
- package/dist/marks/RectY.svelte +33 -0
- package/dist/marks/RectY.svelte.d.ts +15 -0
- package/dist/marks/RegressionX.svelte +26 -0
- package/dist/marks/RegressionX.svelte.d.ts +4 -0
- package/dist/marks/RegressionY.svelte +26 -0
- package/dist/marks/RegressionY.svelte.d.ts +4 -0
- package/dist/marks/RuleX.svelte +52 -28
- package/dist/marks/RuleX.svelte.d.ts +14 -14
- package/dist/marks/RuleY.svelte +52 -28
- package/dist/marks/RuleY.svelte.d.ts +14 -14
- package/dist/marks/Sphere.svelte +8 -0
- package/dist/marks/Sphere.svelte.d.ts +51 -0
- package/dist/marks/Spike.svelte +15 -0
- package/dist/marks/Spike.svelte.d.ts +4 -0
- package/dist/marks/SymbolLegend.svelte +27 -12
- package/dist/marks/SymbolLegend.svelte.d.ts +8 -14
- package/dist/marks/Text.svelte +185 -0
- package/dist/marks/Text.svelte.d.ts +26 -0
- package/dist/marks/TickX.svelte +89 -0
- package/dist/marks/TickX.svelte.d.ts +22 -0
- package/dist/marks/TickY.svelte +90 -0
- package/dist/marks/TickY.svelte.d.ts +22 -0
- package/dist/marks/Vector.svelte +213 -0
- package/dist/marks/Vector.svelte.d.ts +31 -0
- package/dist/marks/helpers/BaseAxisX.svelte +210 -0
- package/dist/marks/helpers/BaseAxisX.svelte.d.ts +24 -0
- package/dist/marks/helpers/BaseAxisY.svelte +187 -0
- package/dist/marks/helpers/BaseAxisY.svelte.d.ts +23 -0
- package/dist/marks/helpers/CanvasLayer.svelte +38 -0
- package/dist/marks/helpers/CanvasLayer.svelte.d.ts +13 -0
- package/dist/marks/helpers/DotCanvas.svelte +184 -0
- package/dist/marks/helpers/DotCanvas.svelte.d.ts +11 -0
- package/dist/marks/helpers/GeoCanvas.svelte +165 -0
- package/dist/marks/helpers/GeoCanvas.svelte.d.ts +13 -0
- package/dist/marks/helpers/GroupMultiple.svelte +17 -0
- package/dist/marks/helpers/GroupMultiple.svelte.d.ts +9 -0
- package/dist/marks/helpers/Marker.svelte +93 -0
- package/dist/marks/helpers/Marker.svelte.d.ts +10 -0
- package/dist/marks/helpers/MarkerPath.svelte +164 -0
- package/dist/marks/helpers/MarkerPath.svelte.d.ts +44 -0
- package/dist/marks/helpers/Regression.svelte +174 -0
- package/dist/marks/helpers/Regression.svelte.d.ts +26 -0
- package/dist/marks/helpers/events.d.ts +8 -0
- package/dist/marks/helpers/events.js +64 -0
- package/dist/transforms/bin.d.ts +51 -0
- package/dist/transforms/bin.js +171 -0
- package/dist/transforms/bollinger.d.ts +21 -0
- package/dist/transforms/bollinger.js +53 -0
- package/dist/transforms/centroid.d.ts +9 -0
- package/dist/transforms/centroid.js +13 -0
- package/dist/transforms/facet.d.ts +1 -0
- package/dist/transforms/facet.js +1 -0
- package/dist/transforms/filter.d.ts +2 -0
- package/dist/transforms/filter.js +8 -0
- package/dist/transforms/group.d.ts +66 -0
- package/dist/transforms/group.js +109 -0
- package/dist/transforms/interval.d.ts +11 -0
- package/dist/transforms/interval.js +34 -0
- package/dist/transforms/jitter.d.ts +0 -0
- package/dist/transforms/jitter.js +1 -0
- package/dist/transforms/map.d.ts +10 -0
- package/dist/transforms/map.js +89 -0
- package/dist/transforms/normalize.d.ts +9 -0
- package/dist/transforms/normalize.js +86 -0
- package/dist/transforms/recordize.d.ts +13 -0
- package/dist/transforms/recordize.js +75 -0
- package/dist/transforms/rename.d.ts +14 -0
- package/dist/transforms/rename.js +42 -0
- package/dist/transforms/select.d.ts +35 -0
- package/dist/transforms/select.js +55 -0
- package/dist/transforms/shift.d.ts +13 -0
- package/dist/transforms/shift.js +45 -0
- package/dist/transforms/sort.d.ts +28 -0
- package/dist/transforms/sort.js +61 -0
- package/dist/transforms/stack.d.ts +10 -0
- package/dist/transforms/stack.js +110 -0
- package/dist/transforms/window.d.ts +22 -0
- package/dist/transforms/window.js +73 -0
- package/dist/types.d.ts +625 -188
- package/dist/ui/Checkbox.svelte +6 -0
- package/dist/ui/Checkbox.svelte.d.ts +13 -0
- package/dist/ui/RadioInput.svelte +27 -0
- package/dist/ui/RadioInput.svelte.d.ts +9 -0
- package/dist/ui/Select.svelte +27 -0
- package/dist/ui/Select.svelte.d.ts +9 -0
- package/dist/ui/Slider.svelte +47 -0
- package/dist/ui/Slider.svelte.d.ts +11 -0
- package/dist/ui/Spiral.svelte +46 -0
- package/dist/ui/Spiral.svelte.d.ts +15 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +4 -0
- package/package.json +79 -40
- package/LICENSE +0 -11
- package/dist/classes/Channel.svelte.js +0 -74
- package/dist/classes/Mark.svelte.js +0 -17
- package/dist/classes/Plot.svelte.js +0 -98
- package/dist/contants.d.ts +0 -3
- package/dist/contants.js +0 -40
- package/dist/helpers/GroupMultiple.svelte +0 -8
- package/dist/helpers/GroupMultiple.svelte.d.ts +0 -19
- package/dist/helpers/createScale.d.ts +0 -5
- package/dist/helpers/createScale.js +0 -57
- package/dist/helpers/resolveChannel.d.ts +0 -2
- package/dist/helpers/resolveChannel.js +0 -28
- package/dist/helpers/wrapArray.d.ts +0 -2
- package/dist/helpers/wrapArray.js +0 -4
- package/dist/marks/BaseMark.svelte +0 -22
- package/dist/marks/BaseMark.svelte.d.ts +0 -19
package/dist/marks/AxisX.svelte
CHANGED
|
@@ -1,101 +1,206 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import Mark from '../Mark.svelte';
|
|
4
|
+
import BaseAxisX from './helpers/BaseAxisX.svelte';
|
|
5
|
+
import type {
|
|
6
|
+
PlotContext,
|
|
7
|
+
BaseMarkProps,
|
|
8
|
+
RawValue,
|
|
9
|
+
ConstantAccessor,
|
|
10
|
+
FacetContext,
|
|
11
|
+
DefaultOptions
|
|
12
|
+
} from '../types.js';
|
|
13
|
+
import autoTimeFormat from '../helpers/autoTimeFormat.js';
|
|
14
|
+
import { derived } from 'svelte/store';
|
|
15
|
+
import { autoTicks } from '../helpers/autoTicks.js';
|
|
16
|
+
import { resolveScaledStyles } from '../helpers/resolve.js';
|
|
17
|
+
|
|
18
|
+
const DEFAULTS = {
|
|
19
|
+
tickSize: 6,
|
|
20
|
+
tickPadding: 3,
|
|
21
|
+
tickFontSize: 11,
|
|
22
|
+
axisXAnchor: 'bottom',
|
|
23
|
+
...getContext<Partial<DefaultOptions>>('svelteplot/_defaults')
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type AxisXProps = BaseMarkProps & {
|
|
27
|
+
data?: RawValue[];
|
|
28
|
+
automatic?: boolean;
|
|
29
|
+
title?: string;
|
|
30
|
+
anchor?: 'top' | 'bottom';
|
|
31
|
+
interval?: string | number;
|
|
32
|
+
facetAnchor?: 'auto' | 'top-empty' | 'bottom-empty' | 'top' | 'bottom';
|
|
33
|
+
labelAnchor?: 'auto' | 'left' | 'center' | 'right';
|
|
34
|
+
tickSize?: number;
|
|
35
|
+
tickFontSize?: ConstantAccessor<number>;
|
|
36
|
+
tickPadding?: number;
|
|
37
|
+
tickFormat?:
|
|
38
|
+
| 'auto'
|
|
39
|
+
| Intl.DateTimeFormatOptions
|
|
40
|
+
| Intl.NumberFormatOptions
|
|
41
|
+
| ((d: RawValue) => string);
|
|
42
|
+
tickClass?: ConstantAccessor<string>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let {
|
|
46
|
+
data = [],
|
|
47
|
+
automatic = false,
|
|
48
|
+
title,
|
|
49
|
+
anchor = DEFAULTS.axisXAnchor,
|
|
50
|
+
facetAnchor = 'auto',
|
|
51
|
+
interval,
|
|
52
|
+
tickSize = DEFAULTS.tickSize,
|
|
53
|
+
tickFontSize = DEFAULTS.tickFontSize,
|
|
54
|
+
tickPadding = DEFAULTS.tickPadding,
|
|
55
|
+
labelAnchor,
|
|
56
|
+
tickFormat,
|
|
57
|
+
tickClass,
|
|
58
|
+
...options
|
|
59
|
+
}: AxisXProps = $props();
|
|
60
|
+
|
|
61
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
62
|
+
let plot = $derived(getPlotState());
|
|
63
|
+
|
|
64
|
+
let autoTickCount = $derived(
|
|
65
|
+
Math.max(3, Math.round(plot.facetWidth / plot.options.x.tickSpacing))
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
let ticks: RawValue[] = $derived(
|
|
69
|
+
data.length > 0
|
|
70
|
+
? // use custom tick values if user passed any as prop
|
|
71
|
+
data
|
|
72
|
+
: // use custom scale tick values if user passed any as plot scale option
|
|
73
|
+
autoTicks(
|
|
74
|
+
plot.scales.x.type,
|
|
75
|
+
plot.options.x.ticks,
|
|
76
|
+
interval || plot.options.x.interval,
|
|
77
|
+
plot.scales.x.domain,
|
|
78
|
+
plot.scales.x.fn,
|
|
79
|
+
autoTickCount
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
let tickFmt = $derived(tickFormat || plot.options.x.tickFormat);
|
|
84
|
+
|
|
85
|
+
let useTickFormat = $derived(
|
|
86
|
+
typeof tickFmt === 'function'
|
|
87
|
+
? tickFmt
|
|
88
|
+
: plot.scales.x.type === 'band' || plot.scales.x.type === 'point'
|
|
89
|
+
? (d) => d
|
|
90
|
+
: plot.scales.x.type === 'time'
|
|
91
|
+
? // time scale
|
|
92
|
+
typeof tickFmt === 'object'
|
|
93
|
+
? (d: Date) => Intl.DateTimeFormat(plot.options.locale, tickFmt).format(d)
|
|
94
|
+
: autoTimeFormat(plot.scales.x, plot.plotWidth, plot.options.locale)
|
|
95
|
+
: // numeric scale
|
|
96
|
+
typeof tickFmt === 'object'
|
|
97
|
+
? (d: number) => Intl.NumberFormat(plot.options.locale, tickFmt).format(d)
|
|
98
|
+
: // auto
|
|
99
|
+
(d: RawValue) =>
|
|
100
|
+
Intl.NumberFormat(plot.options.locale, {
|
|
101
|
+
...DEFAULTS.numberFormat,
|
|
102
|
+
style: plot.options.x.percent ? 'percent' : 'decimal'
|
|
103
|
+
}).format(d)
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
let optionsLabel = $derived(plot.options?.x?.label);
|
|
107
|
+
|
|
108
|
+
let scaleType = $derived(plot.scales.x.type);
|
|
109
|
+
let isQuantitative = $derived(scaleType !== 'point' && scaleType !== 'band');
|
|
110
|
+
|
|
111
|
+
let useTitle = $derived(
|
|
112
|
+
title ||
|
|
113
|
+
(optionsLabel === null
|
|
114
|
+
? null
|
|
115
|
+
: optionsLabel !== undefined
|
|
116
|
+
? optionsLabel
|
|
117
|
+
: plot.scales.x.autoTitle
|
|
118
|
+
? isQuantitative
|
|
119
|
+
? plot.options.x?.reverse
|
|
120
|
+
? `← ${plot.scales.x.autoTitle}${plot.options.x.percent ? ' (%)' : ''}`
|
|
121
|
+
: `${plot.scales.x.autoTitle}${plot.options.x.percent ? ' (%)' : ''} →`
|
|
122
|
+
: plot.scales.x.autoTitle
|
|
123
|
+
: '')
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
let useLabelAnchor = $derived(labelAnchor || plot.options?.x?.labelAnchor || 'auto');
|
|
127
|
+
let titleAlign = $derived(
|
|
128
|
+
useLabelAnchor === 'auto' ? (isQuantitative ? 'right' : 'center') : useLabelAnchor
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const { getFacetState } = getContext<FacetContext>('svelteplot/facet');
|
|
132
|
+
let { left, top, bottom, bottomEmpty, topEmpty } = $derived(getFacetState());
|
|
133
|
+
|
|
134
|
+
let useFacetAnchor = $derived(
|
|
135
|
+
facetAnchor !== 'auto' ? facetAnchor : anchor === 'bottom' ? 'bottom-empty' : 'top-empty'
|
|
136
|
+
);
|
|
137
|
+
let showAxis = $state(false);
|
|
138
|
+
$effect.pre(() => {
|
|
139
|
+
showAxis =
|
|
140
|
+
useFacetAnchor === 'top'
|
|
141
|
+
? top
|
|
142
|
+
: useFacetAnchor === 'bottom'
|
|
143
|
+
? bottom
|
|
144
|
+
: useFacetAnchor === 'top-empty'
|
|
145
|
+
? topEmpty
|
|
146
|
+
: bottomEmpty;
|
|
147
|
+
});
|
|
39
148
|
</script>
|
|
40
149
|
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
150
|
+
<Mark
|
|
151
|
+
type="axisX"
|
|
152
|
+
data={data.length ? data.map((tick) => ({ __x: tick })) : []}
|
|
153
|
+
channels={['x']}
|
|
154
|
+
{...options}
|
|
155
|
+
x="__x"
|
|
156
|
+
{automatic}>
|
|
157
|
+
{#if left && top && useTitle}
|
|
158
|
+
<text
|
|
159
|
+
style={resolveScaledStyles(
|
|
160
|
+
null,
|
|
161
|
+
{
|
|
162
|
+
...options,
|
|
163
|
+
stroke: null,
|
|
164
|
+
textAnchor:
|
|
165
|
+
titleAlign === 'right'
|
|
166
|
+
? 'end'
|
|
167
|
+
: titleAlign === 'center'
|
|
168
|
+
? 'middle'
|
|
169
|
+
: 'start'
|
|
170
|
+
},
|
|
171
|
+
{},
|
|
172
|
+
plot,
|
|
173
|
+
'fill'
|
|
174
|
+
)}
|
|
175
|
+
x={plot.options.marginLeft +
|
|
176
|
+
plot.plotWidth * (titleAlign === 'right' ? 1 : titleAlign === 'center' ? 0.5 : 0)}
|
|
177
|
+
y={anchor === 'top' ? 13 : plot.height - 13}
|
|
178
|
+
class="axis-x-title"
|
|
179
|
+
dominant-baseline={anchor === 'top' ? 'auto' : 'hanging'}>{useTitle}</text>
|
|
180
|
+
{/if}
|
|
181
|
+
{#if showAxis}
|
|
182
|
+
<BaseAxisX
|
|
183
|
+
scaleFn={plot.scales.x.fn}
|
|
184
|
+
scaleType={plot.scales.x.type}
|
|
185
|
+
tickFormat={useTickFormat}
|
|
186
|
+
{ticks}
|
|
187
|
+
marginTop={plot.options.marginTop}
|
|
188
|
+
height={plot.facetHeight}
|
|
189
|
+
{anchor}
|
|
190
|
+
{tickSize}
|
|
191
|
+
{tickPadding}
|
|
192
|
+
{tickFontSize}
|
|
193
|
+
{tickClass}
|
|
194
|
+
{options}
|
|
195
|
+
title={useTitle}
|
|
196
|
+
{plot} />
|
|
197
|
+
{/if}
|
|
198
|
+
</Mark>
|
|
83
199
|
|
|
84
200
|
<style>
|
|
85
201
|
text {
|
|
86
|
-
text-anchor: middle;
|
|
87
202
|
font-size: 11px;
|
|
88
|
-
|
|
89
|
-
fill:
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
text.axis-title {
|
|
93
|
-
text-anchor: end;
|
|
94
|
-
}
|
|
95
|
-
.x-tick line {
|
|
96
|
-
stroke: currentColor;
|
|
97
|
-
}
|
|
98
|
-
.x-tick line.grid {
|
|
99
|
-
stroke: #d9d9d9;
|
|
203
|
+
opacity: 0.8;
|
|
204
|
+
fill: currentColor;
|
|
100
205
|
}
|
|
101
206
|
</style>
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { BaseMarkProps, RawValue, ConstantAccessor } from '../types.js';
|
|
2
|
+
type AxisXProps = BaseMarkProps & {
|
|
3
|
+
data?: RawValue[];
|
|
4
|
+
automatic?: boolean;
|
|
5
|
+
title?: string;
|
|
6
|
+
anchor?: 'top' | 'bottom';
|
|
7
|
+
interval?: string | number;
|
|
8
|
+
facetAnchor?: 'auto' | 'top-empty' | 'bottom-empty' | 'top' | 'bottom';
|
|
9
|
+
labelAnchor?: 'auto' | 'left' | 'center' | 'right';
|
|
10
|
+
tickSize?: number;
|
|
11
|
+
tickFontSize?: ConstantAccessor<number>;
|
|
12
|
+
tickPadding?: number;
|
|
13
|
+
tickFormat?: 'auto' | Intl.DateTimeFormatOptions | Intl.NumberFormatOptions | ((d: RawValue) => string);
|
|
14
|
+
tickClass?: ConstantAccessor<string>;
|
|
11
15
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export
|
|
15
|
-
export default class AxisX extends SvelteComponent<AxisXProps, AxisXEvents, AxisXSlots> {
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
16
|
+
declare const AxisX: import("svelte").Component<AxisXProps, {}, "">;
|
|
17
|
+
type AxisX = ReturnType<typeof AxisX>;
|
|
18
|
+
export default AxisX;
|
package/dist/marks/AxisY.svelte
CHANGED
|
@@ -1,70 +1,184 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import BaseAxisY from './helpers/BaseAxisY.svelte';
|
|
4
|
+
import Mark from '../Mark.svelte';
|
|
5
|
+
import type {
|
|
6
|
+
PlotContext,
|
|
7
|
+
BaseMarkProps,
|
|
8
|
+
RawValue,
|
|
9
|
+
DataRecord,
|
|
10
|
+
FacetContext,
|
|
11
|
+
DefaultOptions
|
|
12
|
+
} from '../types.js';
|
|
13
|
+
import getBaseStyles from '../helpers/getBaseStyles.js';
|
|
14
|
+
import autoTimeFormat from '../helpers/autoTimeFormat.js';
|
|
15
|
+
import type { ConstantAccessor } from '../types.js';
|
|
16
|
+
import { autoTicks } from '../helpers/autoTicks.js';
|
|
17
|
+
import { resolveScaledStyles } from '../helpers/resolve.js';
|
|
18
|
+
|
|
19
|
+
const DEFAULTS = {
|
|
20
|
+
tickSize: 6,
|
|
21
|
+
tickPadding: 3,
|
|
22
|
+
tickFontSize: 11,
|
|
23
|
+
axisYAnchor: 'left',
|
|
24
|
+
...getContext<Partial<DefaultOptions>>('svelteplot/_defaults')
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type AxisYProps = BaseMarkProps & {
|
|
28
|
+
data?: RawValue[];
|
|
29
|
+
automatic?: boolean;
|
|
30
|
+
title?: string;
|
|
31
|
+
anchor?: 'left' | 'right';
|
|
32
|
+
facetAnchor?: 'auto' | 'left' | 'right' | 'left-empty' | 'right-empty';
|
|
33
|
+
lineAnchor?: 'top' | 'center' | 'bottom';
|
|
34
|
+
tickSize?: number;
|
|
35
|
+
tickFontSize?: ConstantAccessor<number>;
|
|
36
|
+
tickPadding?: number;
|
|
37
|
+
tickFormat?:
|
|
38
|
+
| 'auto'
|
|
39
|
+
| Intl.DateTimeFormatOptions
|
|
40
|
+
| Intl.NumberFormatOptions
|
|
41
|
+
| ((d: RawValue) => string);
|
|
42
|
+
tickClass?: ConstantAccessor<string>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let {
|
|
46
|
+
data = [],
|
|
47
|
+
automatic = false,
|
|
48
|
+
title,
|
|
49
|
+
anchor = DEFAULTS.axisYAnchor,
|
|
50
|
+
facetAnchor = 'auto',
|
|
51
|
+
lineAnchor = 'center',
|
|
52
|
+
tickSize = DEFAULTS.tickSize,
|
|
53
|
+
tickFontSize = DEFAULTS.tickFontSize,
|
|
54
|
+
tickPadding = DEFAULTS.tickPadding,
|
|
55
|
+
tickFormat,
|
|
56
|
+
tickClass,
|
|
57
|
+
...options
|
|
58
|
+
}: AxisYProps = $props();
|
|
59
|
+
|
|
60
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
61
|
+
const plot = $derived(getPlotState());
|
|
62
|
+
|
|
63
|
+
const autoTickCount = $derived(
|
|
64
|
+
Math.max(2, Math.round(plot.facetHeight / plot.options.y.tickSpacing))
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const ticks: RawValue[] = $derived(
|
|
68
|
+
data.length > 0
|
|
69
|
+
? // use custom tick values if user passed any as prop
|
|
70
|
+
data
|
|
71
|
+
: // use custom scale tick values if user passed any as plot scale option
|
|
72
|
+
autoTicks(
|
|
73
|
+
plot.scales.y.type,
|
|
74
|
+
plot.options.y.ticks,
|
|
75
|
+
plot.options.y.interval,
|
|
76
|
+
plot.scales.y.domain,
|
|
77
|
+
plot.scales.y.fn,
|
|
78
|
+
autoTickCount
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const tickFmt = $derived(tickFormat || plot.options.y.tickFormat);
|
|
83
|
+
|
|
84
|
+
const useTickFormat = $derived(
|
|
85
|
+
typeof tickFmt === 'function'
|
|
86
|
+
? tickFmt
|
|
87
|
+
: plot.scales.y.type === 'band' || plot.scales.y.type === 'point'
|
|
88
|
+
? (d) => d
|
|
89
|
+
: plot.scales.y.type === 'time'
|
|
90
|
+
? // time scale
|
|
91
|
+
typeof tickFmt === 'object'
|
|
92
|
+
? (d: Date) => Intl.DateTimeFormat(plot.options.locale, tickFmt).format(d)
|
|
93
|
+
: autoTimeFormat(plot.scales.y, plot.plotWidth, plot.options.locale)
|
|
94
|
+
: // numeric scale
|
|
95
|
+
typeof tickFmt === 'object'
|
|
96
|
+
? (d: number) => Intl.NumberFormat(plot.options.locale, tickFmt).format(d)
|
|
97
|
+
: // auto
|
|
98
|
+
(d: RawValue) =>
|
|
99
|
+
Intl.NumberFormat(plot.options.locale, {
|
|
100
|
+
...DEFAULTS.numberFormat,
|
|
101
|
+
style: plot.options.y.percent ? 'percent' : 'decimal'
|
|
102
|
+
}).format(d)
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const optionsLabel = $derived(plot.options.y.label);
|
|
106
|
+
|
|
107
|
+
const useTitle = $derived(
|
|
108
|
+
title ||
|
|
109
|
+
(optionsLabel === null
|
|
110
|
+
? null
|
|
111
|
+
: optionsLabel !== undefined
|
|
112
|
+
? optionsLabel
|
|
113
|
+
: plot.scales.y.autoTitle
|
|
114
|
+
? `↑ ${plot.scales.y.autoTitle}${plot.options.y.percent ? ' (%)' : ''}`
|
|
115
|
+
: '')
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const { getFacetState } = getContext<FacetContext>('svelteplot/facet');
|
|
119
|
+
const { left, leftEmpty, right, rightEmpty, top } = $derived(getFacetState());
|
|
120
|
+
|
|
121
|
+
const useFacetAnchor = $derived(
|
|
122
|
+
facetAnchor !== 'auto' ? facetAnchor : anchor === 'left' ? 'left-empty' : 'right-empty'
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
let showAxis = $state(false);
|
|
126
|
+
$effect.pre(() => {
|
|
127
|
+
showAxis =
|
|
128
|
+
useFacetAnchor === 'left'
|
|
129
|
+
? left
|
|
130
|
+
: useFacetAnchor === 'right'
|
|
131
|
+
? right
|
|
132
|
+
: useFacetAnchor === 'left-empty'
|
|
133
|
+
? leftEmpty
|
|
134
|
+
: rightEmpty;
|
|
135
|
+
});
|
|
28
136
|
</script>
|
|
29
137
|
|
|
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
|
-
|
|
138
|
+
<Mark
|
|
139
|
+
type="axisY"
|
|
140
|
+
data={data.length ? data.map((tick) => ({ __y: tick })) : []}
|
|
141
|
+
channels={['y']}
|
|
142
|
+
{...{ ...options, y: '__y' }}
|
|
143
|
+
{automatic}>
|
|
144
|
+
{#if left && top && useTitle}
|
|
145
|
+
<text
|
|
146
|
+
style={resolveScaledStyles(
|
|
147
|
+
null,
|
|
148
|
+
{ ...options, stroke: null, textAnchor: anchor === 'left' ? 'start' : 'end' },
|
|
149
|
+
{},
|
|
150
|
+
plot,
|
|
151
|
+
'fill'
|
|
152
|
+
)}
|
|
153
|
+
x={anchor === 'left' ? 0 : plot.width}
|
|
154
|
+
y={5}
|
|
155
|
+
class="axis-x-title"
|
|
156
|
+
dominant-baseline="hanging">{useTitle}</text>
|
|
157
|
+
{/if}
|
|
158
|
+
{#if showAxis}
|
|
159
|
+
<BaseAxisY
|
|
160
|
+
scaleFn={plot.scales.y.fn}
|
|
161
|
+
scaleType={plot.scales.y.type}
|
|
162
|
+
tickFormat={useTickFormat}
|
|
163
|
+
{ticks}
|
|
164
|
+
marginLeft={plot.options.marginLeft}
|
|
165
|
+
width={plot.facetWidth}
|
|
166
|
+
{anchor}
|
|
167
|
+
{lineAnchor}
|
|
168
|
+
{tickSize}
|
|
169
|
+
{tickPadding}
|
|
170
|
+
{tickFontSize}
|
|
171
|
+
{tickClass}
|
|
172
|
+
{options}
|
|
173
|
+
title={useTitle}
|
|
174
|
+
{plot} />
|
|
175
|
+
{/if}
|
|
176
|
+
</Mark>
|
|
55
177
|
|
|
56
178
|
<style>
|
|
57
179
|
text {
|
|
58
180
|
font-size: 11px;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
text.is-left {
|
|
62
|
-
text-anchor: end;
|
|
63
|
-
}
|
|
64
|
-
text.axis-title {
|
|
65
|
-
text-anchor: start;
|
|
66
|
-
}
|
|
67
|
-
.y-tick line {
|
|
68
|
-
stroke: currentColor;
|
|
181
|
+
opacity: 0.8;
|
|
182
|
+
fill: currentColor;
|
|
69
183
|
}
|
|
70
184
|
</style>
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import type { BaseMarkProps, RawValue } from '../types.js';
|
|
2
|
+
import type { ConstantAccessor } from '../types.js';
|
|
3
|
+
type AxisYProps = BaseMarkProps & {
|
|
4
|
+
data?: RawValue[];
|
|
5
|
+
automatic?: boolean;
|
|
6
|
+
title?: string;
|
|
7
|
+
anchor?: 'left' | 'right';
|
|
8
|
+
facetAnchor?: 'auto' | 'left' | 'right' | 'left-empty' | 'right-empty';
|
|
9
|
+
lineAnchor?: 'top' | 'center' | 'bottom';
|
|
10
|
+
tickSize?: number;
|
|
11
|
+
tickFontSize?: ConstantAccessor<number>;
|
|
12
|
+
tickPadding?: number;
|
|
13
|
+
tickFormat?: 'auto' | Intl.DateTimeFormatOptions | Intl.NumberFormatOptions | ((d: RawValue) => string);
|
|
14
|
+
tickClass?: ConstantAccessor<string>;
|
|
9
15
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
export default class AxisY extends SvelteComponent<AxisYProps, AxisYEvents, AxisYSlots> {
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
16
|
+
declare const AxisY: import("svelte").Component<AxisYProps, {}, "">;
|
|
17
|
+
type AxisY = ReturnType<typeof AxisY>;
|
|
18
|
+
export default AxisY;
|