svelteplot 0.2.8 → 0.2.9-pr-95.1
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/Plot.svelte +81 -69
- package/dist/core/Plot.svelte +1 -1
- package/dist/helpers/autoTicks.js +9 -8
- package/dist/helpers/colors.d.ts +1 -1
- package/dist/helpers/index.d.ts +2 -2
- package/dist/helpers/scales.d.ts +1 -1
- package/dist/helpers/scales.js +18 -1
- package/dist/helpers/typeChecks.d.ts +4 -4
- package/dist/marks/AxisX.svelte +33 -6
- package/dist/marks/AxisX.svelte.d.ts +12 -1
- package/dist/marks/AxisY.svelte +32 -4
- package/dist/marks/AxisY.svelte.d.ts +12 -1
- package/dist/marks/BollingerX.svelte.d.ts +1 -1
- package/dist/marks/BollingerY.svelte.d.ts +1 -1
- package/dist/marks/Sphere.svelte.d.ts +1 -56
- package/dist/marks/helpers/BaseAxisX.svelte +59 -53
- package/dist/marks/helpers/BaseAxisX.svelte.d.ts +1 -0
- package/dist/marks/helpers/BaseAxisY.svelte +24 -18
- package/dist/marks/helpers/BaseAxisY.svelte.d.ts +1 -0
- package/dist/marks/helpers/MarkerPath.svelte.d.ts +1 -41
- package/dist/transforms/bollinger.d.ts +1 -8
- package/dist/transforms/centroid.d.ts +1 -8
- package/dist/transforms/group.d.ts +4 -12
- package/dist/transforms/interval.d.ts +2 -6
- package/dist/transforms/map.d.ts +4 -10
- package/dist/transforms/normalize.d.ts +2 -6
- package/dist/transforms/select.d.ts +7 -21
- package/dist/transforms/sort.d.ts +3 -16
- package/dist/transforms/window.d.ts +2 -14
- package/dist/ui/ExamplesGrid.svelte +64 -0
- package/dist/ui/ExamplesGrid.svelte.d.ts +11 -0
- package/package.json +121 -117
package/dist/Plot.svelte
CHANGED
|
@@ -91,89 +91,101 @@
|
|
|
91
91
|
<!-- There's a bug triggering RangeError: Maximum call stack size exceeded
|
|
92
92
|
when using SveltePlot in ssr, so for now, we're disabling it -->
|
|
93
93
|
|
|
94
|
-
<
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
{#if
|
|
123
|
-
|
|
94
|
+
<svelte:boundary>
|
|
95
|
+
<Plot
|
|
96
|
+
{overlay}
|
|
97
|
+
{underlay}
|
|
98
|
+
{...restOptions}
|
|
99
|
+
header={userHeader ||
|
|
100
|
+
restOptions.title ||
|
|
101
|
+
restOptions.subtitle ||
|
|
102
|
+
restOptions.color?.legend ||
|
|
103
|
+
restOptions.symbol?.legend
|
|
104
|
+
? header
|
|
105
|
+
: null}
|
|
106
|
+
footer={userFooter || restOptions?.caption ? footer : null}
|
|
107
|
+
projection={projectionOpts}
|
|
108
|
+
implicitScales
|
|
109
|
+
{...scales}>
|
|
110
|
+
{#snippet children({
|
|
111
|
+
hasProjection,
|
|
112
|
+
hasExplicitAxisX,
|
|
113
|
+
hasExplicitAxisY,
|
|
114
|
+
hasExplicitGridX,
|
|
115
|
+
hasExplicitGridY,
|
|
116
|
+
options,
|
|
117
|
+
scales,
|
|
118
|
+
...restProps
|
|
119
|
+
})}
|
|
120
|
+
<svelte:boundary onerror={(err) => console.warn(err)}>
|
|
121
|
+
<!-- implicit axes -->
|
|
122
|
+
{#if !hasProjection && !hasExplicitAxisX}
|
|
123
|
+
{#if options.axes && (options.x.axis === 'top' || options.x.axis === 'both')}
|
|
124
|
+
<AxisX anchor="top" automatic />
|
|
125
|
+
{/if}
|
|
126
|
+
{#if options.axes && (options.x.axis === 'bottom' || options.x.axis === 'both')}
|
|
127
|
+
<AxisX anchor="bottom" automatic />
|
|
128
|
+
{/if}
|
|
124
129
|
{/if}
|
|
125
|
-
{#if
|
|
126
|
-
|
|
130
|
+
{#if !hasProjection && !hasExplicitAxisY}
|
|
131
|
+
{#if options.axes && (options.y.axis === 'left' || options.y.axis === 'both')}
|
|
132
|
+
<AxisY anchor="left" automatic />
|
|
133
|
+
{/if}
|
|
134
|
+
{#if options.axes && (options.y.axis === 'right' || options.y.axis === 'both')}
|
|
135
|
+
<AxisY anchor="right" automatic />
|
|
136
|
+
{/if}
|
|
127
137
|
{/if}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
<AxisY anchor="left" automatic />
|
|
138
|
+
<!-- implicit grids -->
|
|
139
|
+
{#if !hasExplicitGridX && (options.grid || options.x.grid)}
|
|
140
|
+
<GridX automatic />
|
|
132
141
|
{/if}
|
|
133
|
-
{#if
|
|
134
|
-
<
|
|
142
|
+
{#if !hasExplicitGridY && (options.grid || options.y.grid)}
|
|
143
|
+
<GridY automatic />
|
|
135
144
|
{/if}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
</svelte:boundary>
|
|
160
|
-
{/snippet}
|
|
161
|
-
{#snippet facetAxes()}
|
|
162
|
-
<FacetAxes />
|
|
145
|
+
<!-- implicit frame -->
|
|
146
|
+
{#if options.frame}
|
|
147
|
+
<Frame automatic />
|
|
148
|
+
{/if}
|
|
149
|
+
{@render parentChildren?.({
|
|
150
|
+
options,
|
|
151
|
+
scales,
|
|
152
|
+
...restProps
|
|
153
|
+
})}
|
|
154
|
+
{#snippet failed(error, reset)}
|
|
155
|
+
<text class="error" transform="translate(10,10)">
|
|
156
|
+
{#each error.message.split('\n') as line, i (i)}
|
|
157
|
+
<tspan x="0" dy={i ? 14 : 0}>{line}</tspan>
|
|
158
|
+
{/each}
|
|
159
|
+
</text>{/snippet}
|
|
160
|
+
</svelte:boundary>
|
|
161
|
+
{/snippet}
|
|
162
|
+
{#snippet facetAxes()}
|
|
163
|
+
<FacetAxes />
|
|
164
|
+
{/snippet}
|
|
165
|
+
</Plot>
|
|
166
|
+
{#snippet failed(error)}
|
|
167
|
+
<div class="error">Error: {error.message}</div>
|
|
163
168
|
{/snippet}
|
|
164
|
-
</
|
|
169
|
+
</svelte:boundary>
|
|
165
170
|
|
|
166
171
|
<style>
|
|
167
172
|
:root {
|
|
168
173
|
--plot-bg: white;
|
|
169
174
|
--plot-fg: currentColor;
|
|
170
175
|
}
|
|
171
|
-
|
|
172
|
-
stroke: var(--plot-bg);
|
|
173
|
-
fill: crimson;
|
|
176
|
+
.error {
|
|
174
177
|
font-size: 11px;
|
|
175
178
|
stroke-width: 3px;
|
|
176
179
|
font-weight: bold;
|
|
180
|
+
}
|
|
181
|
+
text.error {
|
|
182
|
+
stroke: var(--plot-bg);
|
|
183
|
+
fill: crimson;
|
|
177
184
|
paint-order: stroke fill;
|
|
178
185
|
}
|
|
186
|
+
div.error {
|
|
187
|
+
color: crimson;
|
|
188
|
+
white-space: pre-wrap;
|
|
189
|
+
line-height: 1.1;
|
|
190
|
+
}
|
|
179
191
|
</style>
|
package/dist/core/Plot.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { maybeTimeInterval } from './time.js';
|
|
2
|
-
import { range as rangei } from 'd3-array';
|
|
2
|
+
import { extent, range as rangei } from 'd3-array';
|
|
3
3
|
export function maybeInterval(interval) {
|
|
4
4
|
if (interval == null)
|
|
5
5
|
return;
|
|
@@ -30,11 +30,12 @@ export function maybeInterval(interval) {
|
|
|
30
30
|
return interval;
|
|
31
31
|
}
|
|
32
32
|
export function autoTicks(type, ticks, interval, domain, scaleFn, count) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
if (ticks)
|
|
34
|
+
return ticks;
|
|
35
|
+
if (interval) {
|
|
36
|
+
const [lo, hi] = extent(domain);
|
|
37
|
+
const I = maybeInterval(interval, type);
|
|
38
|
+
return I.range(lo, I.offset(hi));
|
|
39
|
+
}
|
|
40
|
+
return typeof scaleFn.ticks === 'function' ? scaleFn.ticks(count) : [];
|
|
40
41
|
}
|
package/dist/helpers/colors.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ type SchemeGetter = (n: number) => readonly string[];
|
|
|
6
6
|
export declare function isOrdinalScheme(scheme: ColorScheme): boolean;
|
|
7
7
|
export declare function ordinalScheme(scheme: string): SchemeGetter | undefined;
|
|
8
8
|
export declare function ordinalRange(scheme: string, length: number): readonly string[] | undefined;
|
|
9
|
-
export declare function maybeBooleanRange(domain: boolean[], scheme?: string):
|
|
9
|
+
export declare function maybeBooleanRange(domain: boolean[], scheme?: string): any[] | undefined;
|
|
10
10
|
export declare function isQuantitativeScheme(scheme: string): boolean;
|
|
11
11
|
export declare function quantitativeScheme(scheme: string): typeof interpolateBrBG | undefined;
|
|
12
12
|
export declare function isDivergingScheme(scheme: string): boolean;
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { Snippet } from 'svelte';
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns first argument that is not null or undefined
|
|
5
5
|
*/
|
|
6
|
-
export declare function coalesce(...args: (RawValue | undefined | null)[]):
|
|
7
|
-
export declare function testFilter(datum: DataRecord, options: Record<ChannelName, ChannelAccessor>):
|
|
6
|
+
export declare function coalesce(...args: (RawValue | undefined | null)[]): any;
|
|
7
|
+
export declare function testFilter(datum: DataRecord, options: Record<ChannelName, ChannelAccessor>): any;
|
|
8
8
|
export declare function randomId(): string;
|
|
9
9
|
export declare function isSnippet(value: unknown): value is Snippet;
|
|
10
10
|
export declare function isValid(value: RawValue | undefined): value is number | Date | string;
|
package/dist/helpers/scales.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare function createScale<T extends ScaleOptions>(name: ScaleName, sca
|
|
|
15
15
|
autoTitle?: undefined;
|
|
16
16
|
} | {
|
|
17
17
|
type: ScaleType;
|
|
18
|
-
domain:
|
|
18
|
+
domain: any;
|
|
19
19
|
range: any;
|
|
20
20
|
fn: any;
|
|
21
21
|
skip: Map<ScaledChannelName, Set<symbol>>;
|
package/dist/helpers/scales.js
CHANGED
|
@@ -5,6 +5,7 @@ import { isSymbolOrNull } from './typeChecks.js';
|
|
|
5
5
|
import { resolveProp, toChannelOption } from './resolve.js';
|
|
6
6
|
import isDataRecord from './isDataRecord.js';
|
|
7
7
|
import { createProjection } from './projection.js';
|
|
8
|
+
import { maybeInterval } from './autoTicks.js';
|
|
8
9
|
/**
|
|
9
10
|
* compute the plot scales
|
|
10
11
|
*/
|
|
@@ -148,7 +149,7 @@ export function createScale(name, scaleOptions, marks, plotOptions, plotWidth, p
|
|
|
148
149
|
valueArr.sort(ascending);
|
|
149
150
|
}
|
|
150
151
|
const valueArray = type === 'quantile' || type === 'quantile-cont' ? allDataValues.toSorted() : valueArr;
|
|
151
|
-
|
|
152
|
+
let domain = scaleOptions.domain
|
|
152
153
|
? isOrdinal
|
|
153
154
|
? scaleOptions.domain
|
|
154
155
|
: extent(scaleOptions.zero ? [0, ...scaleOptions.domain] : scaleOptions.domain)
|
|
@@ -162,6 +163,16 @@ export function createScale(name, scaleOptions, marks, plotOptions, plotWidth, p
|
|
|
162
163
|
? valueArray.toReversed()
|
|
163
164
|
: valueArray
|
|
164
165
|
: extent(scaleOptions.zero ? [0, ...valueArray] : valueArray);
|
|
166
|
+
if (scaleOptions.interval) {
|
|
167
|
+
if (isOrdinal) {
|
|
168
|
+
domain = domainFromInterval(domain, scaleOptions.interval, name);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
if (markTypes.size > 0) {
|
|
172
|
+
console.warn('Setting interval via axis options is only supported for ordinal scales');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
165
176
|
if (!scaleOptions.scale) {
|
|
166
177
|
throw new Error(`No scale function defined for ${name}`);
|
|
167
178
|
}
|
|
@@ -192,6 +203,12 @@ export function createScale(name, scaleOptions, marks, plotOptions, plotWidth, p
|
|
|
192
203
|
: null
|
|
193
204
|
};
|
|
194
205
|
}
|
|
206
|
+
function domainFromInterval(domain, interval, name) {
|
|
207
|
+
const interval_ = maybeInterval(interval);
|
|
208
|
+
const [lo, hi] = extent(domain);
|
|
209
|
+
const out = interval_.range(lo, interval_.offset(hi));
|
|
210
|
+
return name === 'y' ? out.toReversed() : out;
|
|
211
|
+
}
|
|
195
212
|
/**
|
|
196
213
|
* Infer a scale type based on the scale name, the data values mapped to it and
|
|
197
214
|
* the mark types that are bound to the scale
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { RawValue } from '../types.js';
|
|
2
|
-
export declare function isBooleanOrNull(v: RawValue):
|
|
2
|
+
export declare function isBooleanOrNull(v: RawValue): boolean;
|
|
3
3
|
export declare function isDate(v: RawValue): v is Date;
|
|
4
|
-
export declare function isDateOrNull(v: RawValue | null | undefined):
|
|
4
|
+
export declare function isDateOrNull(v: RawValue | null | undefined): boolean;
|
|
5
5
|
export declare function isNumberOrNull(v: RawValue | null | undefined): boolean;
|
|
6
6
|
export declare function isNumberOrNullOrNaN(v: RawValue | null | undefined): boolean;
|
|
7
|
-
export declare function isStringOrNull(v: RawValue | null | undefined):
|
|
7
|
+
export declare function isStringOrNull(v: RawValue | null | undefined): boolean;
|
|
8
8
|
export declare function isSymbolOrNull(v: RawValue | null | undefined): boolean;
|
|
9
|
-
export declare function isColorOrNull(v: RawValue | null | undefined):
|
|
9
|
+
export declare function isColorOrNull(v: RawValue | null | undefined): any;
|
|
10
10
|
export declare function isOpacityOrNull(v: RawValue): boolean;
|
package/dist/marks/AxisX.svelte
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Renders a horizontal axis with labels and tick marks
|
|
3
3
|
-->
|
|
4
4
|
<script module lang="ts">
|
|
5
|
+
import type { XOR } from 'ts-essentials';
|
|
5
6
|
export type AxisXMarkProps = Omit<
|
|
6
7
|
BaseMarkProps,
|
|
7
8
|
'fill' | 'fillOpacity' | 'paintOrder' | 'title' | 'href' | 'target'
|
|
@@ -22,7 +23,20 @@
|
|
|
22
23
|
| Intl.NumberFormatOptions
|
|
23
24
|
| ((d: RawValue) => string);
|
|
24
25
|
tickClass?: ConstantAccessor<string>;
|
|
25
|
-
|
|
26
|
+
/** ticks is a shorthand for defining data, tickCount or interval */
|
|
27
|
+
ticks?: number | string | RawValue[];
|
|
28
|
+
/** set to false or null to disable tick labels */
|
|
29
|
+
text: boolean | null;
|
|
30
|
+
} & XOR<
|
|
31
|
+
{
|
|
32
|
+
/** approximate number of ticks to be generated */
|
|
33
|
+
tickCount?: number;
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
/** approximate number of pixels between generated ticks */
|
|
37
|
+
tickSpacing?: number;
|
|
38
|
+
}
|
|
39
|
+
>;
|
|
26
40
|
</script>
|
|
27
41
|
|
|
28
42
|
<script lang="ts">
|
|
@@ -51,12 +65,13 @@
|
|
|
51
65
|
};
|
|
52
66
|
|
|
53
67
|
let {
|
|
54
|
-
|
|
68
|
+
ticks: magicTicks,
|
|
69
|
+
data = Array.isArray(magicTicks) ? magicTicks : [],
|
|
55
70
|
automatic = false,
|
|
56
71
|
title,
|
|
57
72
|
anchor = DEFAULTS.axisXAnchor as 'top' | 'bottom',
|
|
58
73
|
facetAnchor = 'auto',
|
|
59
|
-
interval,
|
|
74
|
+
interval = typeof magicTicks === 'string' ? magicTicks : undefined,
|
|
60
75
|
tickSize = DEFAULTS.tickSize,
|
|
61
76
|
tickFontSize = DEFAULTS.tickFontSize,
|
|
62
77
|
tickPadding = DEFAULTS.tickPadding,
|
|
@@ -64,6 +79,9 @@
|
|
|
64
79
|
tickFormat,
|
|
65
80
|
tickClass,
|
|
66
81
|
class: className,
|
|
82
|
+
tickCount = typeof magicTicks === 'number' ? magicTicks : undefined,
|
|
83
|
+
tickSpacing,
|
|
84
|
+
text = true,
|
|
67
85
|
...options
|
|
68
86
|
}: AxisXMarkProps = $props();
|
|
69
87
|
|
|
@@ -71,7 +89,11 @@
|
|
|
71
89
|
const plot = $derived(getPlotState());
|
|
72
90
|
|
|
73
91
|
const autoTickCount = $derived(
|
|
74
|
-
|
|
92
|
+
tickCount != null
|
|
93
|
+
? tickCount
|
|
94
|
+
: tickSpacing != null
|
|
95
|
+
? Math.max(3, Math.round(plot.facetWidth / tickSpacing))
|
|
96
|
+
: Math.max(3, Math.round(plot.facetWidth / plot.options.x.tickSpacing))
|
|
75
97
|
);
|
|
76
98
|
|
|
77
99
|
const ticks: RawValue[] = $derived(
|
|
@@ -89,9 +111,9 @@
|
|
|
89
111
|
)
|
|
90
112
|
);
|
|
91
113
|
|
|
92
|
-
|
|
114
|
+
const tickFmt = $derived(tickFormat || plot.options.x.tickFormat);
|
|
93
115
|
|
|
94
|
-
|
|
116
|
+
const useTickFormat = $derived(
|
|
95
117
|
typeof tickFmt === 'function'
|
|
96
118
|
? tickFmt
|
|
97
119
|
: plot.scales.x.type === 'band' || plot.scales.x.type === 'point'
|
|
@@ -107,6 +129,10 @@
|
|
|
107
129
|
: // auto
|
|
108
130
|
(d: RawValue) =>
|
|
109
131
|
Intl.NumberFormat(plot.options.locale, {
|
|
132
|
+
// use compact notation if range covers multipe magnitudes
|
|
133
|
+
...(new Set(ticks.map(Math.log10).map(Math.round)).size > 1
|
|
134
|
+
? { notation: 'compact' }
|
|
135
|
+
: {}),
|
|
110
136
|
...DEFAULTS.numberFormat,
|
|
111
137
|
style: plot.options.x.percent ? 'percent' : 'decimal'
|
|
112
138
|
}).format(d)
|
|
@@ -197,6 +223,7 @@
|
|
|
197
223
|
{tickPadding}
|
|
198
224
|
{tickFontSize}
|
|
199
225
|
{tickClass}
|
|
226
|
+
{text}
|
|
200
227
|
{options}
|
|
201
228
|
title={useTitle}
|
|
202
229
|
{plot} />
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { XOR } from 'ts-essentials';
|
|
1
2
|
export type AxisXMarkProps = Omit<BaseMarkProps, 'fill' | 'fillOpacity' | 'paintOrder' | 'title' | 'href' | 'target'> & {
|
|
2
3
|
data?: RawValue[];
|
|
3
4
|
automatic?: boolean;
|
|
@@ -11,7 +12,17 @@ export type AxisXMarkProps = Omit<BaseMarkProps, 'fill' | 'fillOpacity' | 'paint
|
|
|
11
12
|
tickPadding?: number;
|
|
12
13
|
tickFormat?: 'auto' | Intl.DateTimeFormatOptions | Intl.NumberFormatOptions | ((d: RawValue) => string);
|
|
13
14
|
tickClass?: ConstantAccessor<string>;
|
|
14
|
-
|
|
15
|
+
/** ticks is a shorthand for defining data, tickCount or interval */
|
|
16
|
+
ticks?: number | string | RawValue[];
|
|
17
|
+
/** set to false or null to disable tick labels */
|
|
18
|
+
text: boolean | null;
|
|
19
|
+
} & XOR<{
|
|
20
|
+
/** approximate number of ticks to be generated */
|
|
21
|
+
tickCount?: number;
|
|
22
|
+
}, {
|
|
23
|
+
/** approximate number of pixels between generated ticks */
|
|
24
|
+
tickSpacing?: number;
|
|
25
|
+
}>;
|
|
15
26
|
import type { BaseMarkProps, RawValue, ConstantAccessor } from '../types.js';
|
|
16
27
|
/** Renders a horizontal axis with labels and tick marks */
|
|
17
28
|
declare const AxisX: import("svelte").Component<AxisXMarkProps, {}, "">;
|
package/dist/marks/AxisY.svelte
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Renders a vertical axis with labels and tick marks
|
|
3
3
|
-->
|
|
4
4
|
<script module lang="ts">
|
|
5
|
+
import type { XOR } from 'ts-essentials';
|
|
5
6
|
export type AxisYMarkProps = Omit<
|
|
6
7
|
BaseMarkProps,
|
|
7
8
|
'fill' | 'fillOpacity' | 'paintOrder' | 'title' | 'href' | 'target'
|
|
@@ -23,7 +24,20 @@
|
|
|
23
24
|
| Intl.NumberFormatOptions
|
|
24
25
|
| ((d: RawValue) => string);
|
|
25
26
|
tickClass?: ConstantAccessor<string>;
|
|
26
|
-
|
|
27
|
+
/** ticks is a shorthand for defining data, tickCount or interval */
|
|
28
|
+
ticks?: number | string | RawValue[];
|
|
29
|
+
/** set to false or null to disable tick labels */
|
|
30
|
+
text: boolean | null;
|
|
31
|
+
} & XOR<
|
|
32
|
+
{
|
|
33
|
+
/** approximate number of ticks to be generated */
|
|
34
|
+
tickCount?: number;
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
/** approximate number of pixels between generated ticks */
|
|
38
|
+
tickSpacing?: number;
|
|
39
|
+
}
|
|
40
|
+
>;
|
|
27
41
|
</script>
|
|
28
42
|
|
|
29
43
|
<script lang="ts">
|
|
@@ -51,17 +65,22 @@
|
|
|
51
65
|
};
|
|
52
66
|
|
|
53
67
|
let {
|
|
54
|
-
|
|
68
|
+
ticks: magicTicks,
|
|
69
|
+
data = Array.isArray(magicTicks) ? magicTicks : [],
|
|
55
70
|
automatic = false,
|
|
56
71
|
title,
|
|
57
72
|
anchor = DEFAULTS.axisYAnchor as 'left' | 'right',
|
|
58
73
|
facetAnchor = 'auto',
|
|
74
|
+
interval = typeof magicTicks === 'string' ? magicTicks : undefined,
|
|
59
75
|
lineAnchor = 'center',
|
|
60
76
|
tickSize = DEFAULTS.tickSize,
|
|
61
77
|
tickFontSize = DEFAULTS.tickFontSize,
|
|
62
78
|
tickPadding = DEFAULTS.tickPadding,
|
|
63
79
|
tickFormat,
|
|
64
80
|
tickClass,
|
|
81
|
+
tickCount = typeof magicTicks === 'number' ? magicTicks : undefined,
|
|
82
|
+
tickSpacing,
|
|
83
|
+
text = true,
|
|
65
84
|
...options
|
|
66
85
|
}: AxisYMarkProps = $props();
|
|
67
86
|
|
|
@@ -69,7 +88,11 @@
|
|
|
69
88
|
const plot = $derived(getPlotState());
|
|
70
89
|
|
|
71
90
|
const autoTickCount = $derived(
|
|
72
|
-
|
|
91
|
+
tickCount != null
|
|
92
|
+
? tickCount
|
|
93
|
+
: tickSpacing != null
|
|
94
|
+
? Math.max(3, Math.round(plot.facetHeight / tickSpacing))
|
|
95
|
+
: Math.max(2, Math.round(plot.facetHeight / plot.options.y.tickSpacing))
|
|
73
96
|
);
|
|
74
97
|
|
|
75
98
|
const ticks: RawValue[] = $derived(
|
|
@@ -80,7 +103,7 @@
|
|
|
80
103
|
autoTicks(
|
|
81
104
|
plot.scales.y.type,
|
|
82
105
|
plot.options.y.ticks,
|
|
83
|
-
plot.options.y.interval,
|
|
106
|
+
interval || plot.options.y.interval,
|
|
84
107
|
plot.scales.y.domain,
|
|
85
108
|
plot.scales.y.fn,
|
|
86
109
|
autoTickCount
|
|
@@ -105,6 +128,10 @@
|
|
|
105
128
|
: // auto
|
|
106
129
|
(d: RawValue) =>
|
|
107
130
|
Intl.NumberFormat(plot.options.locale, {
|
|
131
|
+
// use compact notation if range covers multipe magnitudes
|
|
132
|
+
...(new Set(ticks.map(Math.log10).map(Math.round)).size > 1
|
|
133
|
+
? { notation: 'compact' }
|
|
134
|
+
: {}),
|
|
108
135
|
...DEFAULTS.numberFormat,
|
|
109
136
|
style: plot.options.y.percent ? 'percent' : 'decimal'
|
|
110
137
|
}).format(d)
|
|
@@ -176,6 +203,7 @@
|
|
|
176
203
|
{tickFontSize}
|
|
177
204
|
{tickClass}
|
|
178
205
|
{options}
|
|
206
|
+
{text}
|
|
179
207
|
title={useTitle}
|
|
180
208
|
{plot} />
|
|
181
209
|
{/if}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { XOR } from 'ts-essentials';
|
|
1
2
|
export type AxisYMarkProps = Omit<BaseMarkProps, 'fill' | 'fillOpacity' | 'paintOrder' | 'title' | 'href' | 'target'> & {
|
|
2
3
|
data?: RawValue[];
|
|
3
4
|
automatic?: boolean;
|
|
@@ -12,7 +13,17 @@ export type AxisYMarkProps = Omit<BaseMarkProps, 'fill' | 'fillOpacity' | 'paint
|
|
|
12
13
|
tickPadding?: number;
|
|
13
14
|
tickFormat?: 'auto' | Intl.DateTimeFormatOptions | Intl.NumberFormatOptions | ((d: RawValue) => string);
|
|
14
15
|
tickClass?: ConstantAccessor<string>;
|
|
15
|
-
|
|
16
|
+
/** ticks is a shorthand for defining data, tickCount or interval */
|
|
17
|
+
ticks?: number | string | RawValue[];
|
|
18
|
+
/** set to false or null to disable tick labels */
|
|
19
|
+
text: boolean | null;
|
|
20
|
+
} & XOR<{
|
|
21
|
+
/** approximate number of ticks to be generated */
|
|
22
|
+
tickCount?: number;
|
|
23
|
+
}, {
|
|
24
|
+
/** approximate number of pixels between generated ticks */
|
|
25
|
+
tickSpacing?: number;
|
|
26
|
+
}>;
|
|
16
27
|
import type { BaseMarkProps, RawValue } from '../types.js';
|
|
17
28
|
import type { ConstantAccessor } from '../types.js';
|
|
18
29
|
/** Renders a vertical axis with labels and tick marks */
|
|
@@ -13,6 +13,6 @@ export type BollingerXMarkProps = BaseMarkProps & {
|
|
|
13
13
|
};
|
|
14
14
|
import type { BaseMarkProps, ChannelAccessor, DataRow } from '../types.js';
|
|
15
15
|
/** line representing a moving average and an area representing volatility as a band */
|
|
16
|
-
declare const BollingerX: import("svelte").Component<
|
|
16
|
+
declare const BollingerX: import("svelte").Component<any, {}, "">;
|
|
17
17
|
type BollingerX = ReturnType<typeof BollingerX>;
|
|
18
18
|
export default BollingerX;
|
|
@@ -13,6 +13,6 @@ export type BollingerYMarkProps = BaseMarkProps & {
|
|
|
13
13
|
};
|
|
14
14
|
import type { BaseMarkProps, ChannelAccessor, DataRow } from '../types.js';
|
|
15
15
|
/** line representing a moving average and an area representing volatility as a band */
|
|
16
|
-
declare const BollingerY: import("svelte").Component<
|
|
16
|
+
declare const BollingerY: import("svelte").Component<any, {}, "">;
|
|
17
17
|
type BollingerY = ReturnType<typeof BollingerY>;
|
|
18
18
|
export default BollingerY;
|
|
@@ -1,61 +1,6 @@
|
|
|
1
1
|
import { type BaseMarkProps } from '../types.js';
|
|
2
2
|
export type SphereMarkProps = BaseMarkProps;
|
|
3
3
|
/** Geo mark with Sphere geometry object */
|
|
4
|
-
declare const Sphere: import("svelte").Component<
|
|
5
|
-
filter?: import("../types.js").ConstantAccessor<boolean>;
|
|
6
|
-
facet?: "auto" | "include" | "exclude";
|
|
7
|
-
fx: import("../types.js").ChannelAccessor;
|
|
8
|
-
fy: import("../types.js").ChannelAccessor;
|
|
9
|
-
dx: import("../types.js").ConstantAccessor<number>;
|
|
10
|
-
dy: import("../types.js").ConstantAccessor<number>;
|
|
11
|
-
fill: import("../types.js").ConstantAccessor<string>;
|
|
12
|
-
fillOpacity: import("../types.js").ConstantAccessor<number>;
|
|
13
|
-
stroke: import("../types.js").ConstantAccessor<string>;
|
|
14
|
-
strokeWidth: import("../types.js").ConstantAccessor<number>;
|
|
15
|
-
strokeOpacity: import("../types.js").ConstantAccessor<number>;
|
|
16
|
-
strokeLinejoin: import("../types.js").ConstantAccessor<import("csstype").Property.StrokeLinejoin>;
|
|
17
|
-
strokeLinecap: import("../types.js").ConstantAccessor<import("csstype").Property.StrokeLinecap>;
|
|
18
|
-
strokeMiterlimit: import("../types.js").ConstantAccessor<number>;
|
|
19
|
-
opacity: import("../types.js").ConstantAccessor<number>;
|
|
20
|
-
strokeDasharray: import("../types.js").ConstantAccessor<string>;
|
|
21
|
-
strokeDashoffset: import("../types.js").ConstantAccessor<number>;
|
|
22
|
-
mixBlendMode: import("../types.js").ConstantAccessor<import("csstype").Property.MixBlendMode>;
|
|
23
|
-
clipPath: string;
|
|
24
|
-
imageFilter: import("../types.js").ConstantAccessor<string>;
|
|
25
|
-
shapeRendering: import("../types.js").ConstantAccessor<import("csstype").Property.ShapeRendering>;
|
|
26
|
-
paintOrder: import("../types.js").ConstantAccessor<string>;
|
|
27
|
-
onclick?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
28
|
-
ondblclick?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
29
|
-
onmouseup?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
30
|
-
onmousedown?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
31
|
-
onmouseenter?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
32
|
-
onmousemove?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
33
|
-
onmouseleave?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
34
|
-
onmouseout?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
35
|
-
onmouseover?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
36
|
-
onpointercancel?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
37
|
-
onpointerdown?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
38
|
-
onpointerup?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
39
|
-
onpointerenter?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
40
|
-
onpointerleave?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
41
|
-
onpointermove?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
42
|
-
onpointerover?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
43
|
-
onpointerout?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
44
|
-
ondrag?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
45
|
-
ondrop?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
46
|
-
ondragstart?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
47
|
-
ondragenter?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
48
|
-
ondragleave?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
49
|
-
ondragover?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
50
|
-
ondragend?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
51
|
-
ontouchstart?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
52
|
-
ontouchmove?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
53
|
-
ontouchend?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
54
|
-
ontouchcancel?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
55
|
-
oncontextmenu?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
56
|
-
onwheel?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
|
|
57
|
-
class: string | null;
|
|
58
|
-
cursor: import("../types.js").ConstantAccessor<import("csstype").Property.Cursor>;
|
|
59
|
-
}>, {}, "">;
|
|
4
|
+
declare const Sphere: import("svelte").Component<BaseMarkProps, {}, "">;
|
|
60
5
|
type Sphere = ReturnType<typeof Sphere>;
|
|
61
6
|
export default Sphere;
|