svelteplot 0.10.3-pr-490.2 → 0.10.3-pr-491.0
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/Mark.svelte +42 -25
- package/dist/Mark.svelte.d.ts +9 -2
- package/dist/Plot.svelte +21 -15
- package/dist/core/FacetAxes.svelte +13 -8
- package/dist/core/FacetGrid.svelte +4 -4
- package/dist/core/Plot.svelte +24 -24
- package/dist/types/plot.d.ts +12 -0
- package/package.json +1 -1
package/dist/Mark.svelte
CHANGED
|
@@ -9,7 +9,14 @@
|
|
|
9
9
|
children?: Snippet<
|
|
10
10
|
[
|
|
11
11
|
{
|
|
12
|
-
mark:
|
|
12
|
+
mark: {
|
|
13
|
+
id: symbol;
|
|
14
|
+
type: MarkType;
|
|
15
|
+
channels: ScaledChannelName[];
|
|
16
|
+
scales: Set<ScaleName>;
|
|
17
|
+
data: DataRecord[];
|
|
18
|
+
options: GenericMarkOptions;
|
|
19
|
+
};
|
|
13
20
|
usedScales: ReturnType<typeof getUsedScales>;
|
|
14
21
|
scaledData: ScaledDataRecord<Datum>[];
|
|
15
22
|
}
|
|
@@ -121,7 +128,7 @@
|
|
|
121
128
|
mark.channels = channels;
|
|
122
129
|
mark.scales = new Set(
|
|
123
130
|
channels
|
|
124
|
-
.filter((channel) => options[channel] !== 0)
|
|
131
|
+
.filter((channel) => (options as any)[channel] !== 0)
|
|
125
132
|
.map((channel) => CHANNEL_SCALE[channel])
|
|
126
133
|
);
|
|
127
134
|
mark.data = untrack(() => data);
|
|
@@ -149,10 +156,10 @@
|
|
|
149
156
|
ScaleName
|
|
150
157
|
][]) {
|
|
151
158
|
// check if the mark has defined an accessor for this channel
|
|
152
|
-
if (options?.[channel] !== undefined && out[channel] === undefined) {
|
|
159
|
+
if ((options as any)?.[channel] !== undefined && out[channel] === undefined) {
|
|
153
160
|
// resolve value
|
|
154
|
-
out[channel] = resolveChannel(channel, row, options
|
|
155
|
-
if (options[channel] === INDEX) {
|
|
161
|
+
out[channel] = resolveChannel(channel, row, options as any);
|
|
162
|
+
if ((options as any)[channel] === INDEX) {
|
|
156
163
|
const scale = plot.scales[CHANNEL_SCALE[channel]];
|
|
157
164
|
if (scale.type === 'band' || scale.type === 'point') {
|
|
158
165
|
out[channel] = scale.domain[out[channel] % scale.domain.length];
|
|
@@ -167,7 +174,13 @@
|
|
|
167
174
|
let prevResolvedData: ResolvedDataRecord[] = [];
|
|
168
175
|
|
|
169
176
|
$effect(() => {
|
|
170
|
-
if (
|
|
177
|
+
if (
|
|
178
|
+
isDifferent(
|
|
179
|
+
data as unknown as ResolvedDataRecord[],
|
|
180
|
+
mark.data as unknown as ResolvedDataRecord[]
|
|
181
|
+
) ||
|
|
182
|
+
isDifferent(resolvedData, prevResolvedData)
|
|
183
|
+
) {
|
|
171
184
|
prevResolvedData = resolvedData;
|
|
172
185
|
// data has changed
|
|
173
186
|
mark.data = data;
|
|
@@ -191,11 +204,11 @@
|
|
|
191
204
|
|
|
192
205
|
const errors = $derived([
|
|
193
206
|
...required
|
|
194
|
-
.filter((name) => options[name] == null)
|
|
207
|
+
.filter((name) => (options as any)[name] == null)
|
|
195
208
|
.map((name) => `missing channel value for ${mark.type} mark: ${name}`),
|
|
196
209
|
...Object.entries(requiredScales)
|
|
197
210
|
.filter(([scale, types]) => {
|
|
198
|
-
return !types.includes(plot.scales[scale].type);
|
|
211
|
+
return !types.includes((plot.scales as any)[scale].type);
|
|
199
212
|
})
|
|
200
213
|
.map(
|
|
201
214
|
([scale, types]) => `scale type mismatch for ${scale} (needs ${types.join(' or ')})`
|
|
@@ -204,7 +217,7 @@
|
|
|
204
217
|
|
|
205
218
|
$effect(() => {
|
|
206
219
|
for (const name of required) {
|
|
207
|
-
if (options[name] == null) throw new Error(`missing channel value: ${name}`);
|
|
220
|
+
if ((options as any)[name] == null) throw new Error(`missing channel value: ${name}`);
|
|
208
221
|
}
|
|
209
222
|
});
|
|
210
223
|
|
|
@@ -219,19 +232,21 @@
|
|
|
219
232
|
const out: ScaledDataRecord<Datum> = {
|
|
220
233
|
datum: row.datum,
|
|
221
234
|
resolved: row,
|
|
222
|
-
index: row[INDEX],
|
|
223
|
-
valid: true
|
|
235
|
+
index: (row as any)[INDEX],
|
|
236
|
+
valid: true,
|
|
237
|
+
dx: 0,
|
|
238
|
+
dy: 0
|
|
224
239
|
};
|
|
225
240
|
// compute dx/dy
|
|
226
|
-
out.dx = Number(resolveProp<number>(options.dx, out.datum, 0));
|
|
227
|
-
out.dy = Number(resolveProp<number>(options.dy, out.datum, 0));
|
|
241
|
+
out.dx = Number(resolveProp<number, Datum>(options.dx, out.datum, 0));
|
|
242
|
+
out.dy = Number(resolveProp<number, Datum>(options.dy, out.datum, 0));
|
|
228
243
|
|
|
229
244
|
// special handling if there's a projection, e.g. a line mark
|
|
230
245
|
if (plot.scales.projection && mark.type !== 'geo') {
|
|
231
246
|
for (const suffix of ['', '1', '2']) {
|
|
232
247
|
if (
|
|
233
|
-
options?.[`x${suffix}`] !== undefined &&
|
|
234
|
-
options?.[`y${suffix}`] !== undefined
|
|
248
|
+
(options as any)?.[`x${suffix}`] !== undefined &&
|
|
249
|
+
(options as any)?.[`y${suffix}`] !== undefined
|
|
235
250
|
) {
|
|
236
251
|
// we have two-dimensional accessors
|
|
237
252
|
// for the x and y channels
|
|
@@ -243,12 +258,11 @@
|
|
|
243
258
|
row.x,
|
|
244
259
|
row.y,
|
|
245
260
|
usedScales.x,
|
|
246
|
-
usedScales.y
|
|
247
|
-
suffix
|
|
261
|
+
usedScales.y
|
|
248
262
|
);
|
|
249
263
|
|
|
250
|
-
out[`x${suffix}`] = x;
|
|
251
|
-
out[`y${suffix}`] = y;
|
|
264
|
+
(out as any)[`x${suffix}`] = x;
|
|
265
|
+
(out as any)[`y${suffix}`] = y;
|
|
252
266
|
out.valid =
|
|
253
267
|
out.valid &&
|
|
254
268
|
isValid(row.x) &&
|
|
@@ -265,11 +279,14 @@
|
|
|
265
279
|
ScaleName
|
|
266
280
|
][]) {
|
|
267
281
|
// check if the mark has defined an accessor for this channel
|
|
268
|
-
if (
|
|
282
|
+
if (
|
|
283
|
+
(options as any)?.[channel] != null &&
|
|
284
|
+
(out as any)[channel] === undefined
|
|
285
|
+
) {
|
|
269
286
|
// resolve value
|
|
270
287
|
const value = row[channel];
|
|
271
288
|
// if this channel was renamed, use the original channel for scaling
|
|
272
|
-
const origChannel = options?.[RENAME]?.[channel] || channel;
|
|
289
|
+
const origChannel = (options as any)?.[RENAME]?.[channel] || channel;
|
|
273
290
|
const scaled = usedScales[channel]
|
|
274
291
|
? scale === 'x'
|
|
275
292
|
? projectX(origChannel as 'x' | 'x1' | 'x2', plot.scales, value)
|
|
@@ -283,12 +300,12 @@
|
|
|
283
300
|
out.valid = out.valid && (scale === 'color' || isValid(value));
|
|
284
301
|
|
|
285
302
|
// apply dx/dy transform
|
|
286
|
-
out[channel] =
|
|
303
|
+
(out as any)[channel] =
|
|
287
304
|
Number.isFinite(scaled) && (scale === 'x' || scale === 'y')
|
|
288
305
|
? scaled + (scale === 'x' ? out.dx : out.dy)
|
|
289
306
|
: scaled;
|
|
290
307
|
} else if (defaults[channel]) {
|
|
291
|
-
out[channel] = defaults[channel];
|
|
308
|
+
(out as any)[channel] = defaults[channel];
|
|
292
309
|
}
|
|
293
310
|
}
|
|
294
311
|
|
|
@@ -300,10 +317,10 @@
|
|
|
300
317
|
|
|
301
318
|
function dodge<T>(data: ScaledDataRecord<Datum>[], options: BaseMarkProps<T>) {
|
|
302
319
|
if (options.dodgeX) {
|
|
303
|
-
return dodgeX({ data, ...options }, plot);
|
|
320
|
+
return dodgeX({ data, ...options } as any, plot) as ScaledDataRecord<Datum>[];
|
|
304
321
|
}
|
|
305
322
|
if (options.dodgeY) {
|
|
306
|
-
return dodgeY({ data, ...options }, plot);
|
|
323
|
+
return dodgeY({ data, ...options } as any, plot) as ScaledDataRecord<Datum>[];
|
|
307
324
|
}
|
|
308
325
|
return data;
|
|
309
326
|
}
|
package/dist/Mark.svelte.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Snippet } from 'svelte';
|
|
2
|
-
import type { ScaledChannelName, MarkType, DataRecord, ChannelAccessor, ScaleName, RawValue, ScaledDataRecord, ScaleType } from './types/index.js';
|
|
2
|
+
import type { ScaledChannelName, MarkType, DataRecord, GenericMarkOptions, ChannelAccessor, ScaleName, RawValue, ScaledDataRecord, ScaleType } from './types/index.js';
|
|
3
3
|
import { getUsedScales } from './helpers/scales.js';
|
|
4
4
|
declare function $$render<Datum extends DataRecord>(): {
|
|
5
5
|
props: Partial<Partial<{
|
|
@@ -145,7 +145,14 @@ declare function $$render<Datum extends DataRecord>(): {
|
|
|
145
145
|
required?: ScaledChannelName[];
|
|
146
146
|
requiredScales?: Partial<Record<ScaleName, ScaleType[]>>;
|
|
147
147
|
children?: Snippet<[{
|
|
148
|
-
mark:
|
|
148
|
+
mark: {
|
|
149
|
+
id: symbol;
|
|
150
|
+
type: MarkType;
|
|
151
|
+
channels: ScaledChannelName[];
|
|
152
|
+
scales: Set<ScaleName>;
|
|
153
|
+
data: DataRecord[];
|
|
154
|
+
options: GenericMarkOptions;
|
|
155
|
+
};
|
|
149
156
|
usedScales: ReturnType<typeof getUsedScales>;
|
|
150
157
|
scaledData: ScaledDataRecord<Datum>[];
|
|
151
158
|
}]>;
|
package/dist/Plot.svelte
CHANGED
|
@@ -45,16 +45,16 @@
|
|
|
45
45
|
if (
|
|
46
46
|
projection &&
|
|
47
47
|
typeof projection !== 'function' &&
|
|
48
|
-
typeof projection?.type !== 'function'
|
|
48
|
+
typeof (projection as any)?.type !== 'function'
|
|
49
49
|
) {
|
|
50
50
|
const { type: projFactory, aspectRatio } = namedProjection(
|
|
51
|
-
isObject(projection) ? projection.type : projection
|
|
52
|
-
);
|
|
51
|
+
isObject(projection) ? (projection as any).type : (projection as string)
|
|
52
|
+
) as { type: any; aspectRatio: number };
|
|
53
53
|
return {
|
|
54
54
|
...(isObject(projection) ? projection : {}),
|
|
55
55
|
type: projFactory,
|
|
56
56
|
aspectRatio
|
|
57
|
-
};
|
|
57
|
+
} as any;
|
|
58
58
|
}
|
|
59
59
|
return projection;
|
|
60
60
|
});
|
|
@@ -62,8 +62,9 @@
|
|
|
62
62
|
const scales = $derived(
|
|
63
63
|
Object.fromEntries(
|
|
64
64
|
['x', 'y', 'r', 'color', 'opacity', 'symbol', 'length', 'fx', 'fy'].map((scale) => {
|
|
65
|
-
const scaleOpts = maybeScaleOptions(restOptions[scale]);
|
|
66
|
-
const scaleFn =
|
|
65
|
+
const scaleOpts = maybeScaleOptions((restOptions as any)[scale]);
|
|
66
|
+
const scaleFn =
|
|
67
|
+
(scaleOpts as any)?.scale || (scale === 'color' ? autoScaleColor : autoScale);
|
|
67
68
|
return [scale, { ...scaleOpts, scale: scaleFn }];
|
|
68
69
|
})
|
|
69
70
|
)
|
|
@@ -72,9 +73,9 @@
|
|
|
72
73
|
function maybeScaleOptions(
|
|
73
74
|
scaleOptions: undefined | false | RawValue[] | object
|
|
74
75
|
): Partial<ScaleOptions> | undefined {
|
|
75
|
-
if (scaleOptions === false) return { axis: false };
|
|
76
|
+
if (scaleOptions === false) return { axis: false } as any;
|
|
76
77
|
if (Array.isArray(scaleOptions)) return { domain: scaleOptions };
|
|
77
|
-
return scaleOptions || {};
|
|
78
|
+
return (scaleOptions as any) || {};
|
|
78
79
|
}
|
|
79
80
|
</script>
|
|
80
81
|
|
|
@@ -84,7 +85,7 @@
|
|
|
84
85
|
<!-- also pass on user header -->
|
|
85
86
|
{#if userHeader}{@render userHeader?.()}{/if}
|
|
86
87
|
{#if restOptions.color?.legend}
|
|
87
|
-
<ColorLegend />
|
|
88
|
+
<ColorLegend class={null} />
|
|
88
89
|
{/if}
|
|
89
90
|
{#if restOptions.symbol?.legend}
|
|
90
91
|
<SymbolLegend />
|
|
@@ -110,8 +111,8 @@
|
|
|
110
111
|
restOptions.color?.legend ||
|
|
111
112
|
restOptions.symbol?.legend
|
|
112
113
|
? header
|
|
113
|
-
:
|
|
114
|
-
footer={userFooter || restOptions?.caption ? footer :
|
|
114
|
+
: undefined}
|
|
115
|
+
footer={userFooter || restOptions?.caption ? footer : undefined}
|
|
115
116
|
projection={projectionOpts}
|
|
116
117
|
implicitScales
|
|
117
118
|
{...scales}>
|
|
@@ -157,11 +158,16 @@
|
|
|
157
158
|
{@render parentChildren?.({
|
|
158
159
|
options,
|
|
159
160
|
scales,
|
|
161
|
+
hasProjection,
|
|
162
|
+
hasExplicitAxisX,
|
|
163
|
+
hasExplicitAxisY,
|
|
164
|
+
hasExplicitGridX,
|
|
165
|
+
hasExplicitGridY,
|
|
160
166
|
...restProps
|
|
161
167
|
})}
|
|
162
|
-
{#snippet failed(error, reset)}
|
|
168
|
+
{#snippet failed(error: unknown, reset: () => void)}
|
|
163
169
|
<text class="error" transform="translate(10,10)">
|
|
164
|
-
{#each error.message.split('\n') as line, i (i)}
|
|
170
|
+
{#each (error as Error).message.split('\n') as line, i (i)}
|
|
165
171
|
<tspan x="0" dy={i ? 14 : 0}>{line}</tspan>
|
|
166
172
|
{/each}
|
|
167
173
|
</text>{/snippet}
|
|
@@ -171,8 +177,8 @@
|
|
|
171
177
|
<FacetAxes />
|
|
172
178
|
{/snippet}
|
|
173
179
|
</Plot>
|
|
174
|
-
{#snippet failed(error)}
|
|
175
|
-
<div class="error">Error: {error.message}</div>
|
|
180
|
+
{#snippet failed(error: unknown)}
|
|
181
|
+
<div class="error">Error: {(error as Error).message}</div>
|
|
176
182
|
{/snippet}
|
|
177
183
|
</svelte:boundary>
|
|
178
184
|
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
const facetXScale = $derived(
|
|
24
24
|
scaleBand()
|
|
25
25
|
.paddingInner(plot.options.fx?.paddingInner ?? plot.options.fx?.padding ?? 0.1)
|
|
26
|
-
.domain(fxValues)
|
|
26
|
+
.domain(fxValues as string[])
|
|
27
27
|
.rangeRound([0, plot.plotWidth])
|
|
28
28
|
);
|
|
29
29
|
const facetYScale = $derived(
|
|
30
30
|
scaleBand()
|
|
31
31
|
.paddingInner(plot.options.fy?.paddingInner ?? plot.options.fy?.padding ?? 0.1)
|
|
32
|
-
.domain(fyValues)
|
|
32
|
+
.domain(fyValues as string[])
|
|
33
33
|
.rangeRound([0, plot.plotHeight])
|
|
34
34
|
);
|
|
35
35
|
</script>
|
|
@@ -39,17 +39,20 @@
|
|
|
39
39
|
<g transform="translate({plot.options.marginLeft}, 0)">
|
|
40
40
|
<BaseAxisX
|
|
41
41
|
class="facet-axis-x"
|
|
42
|
-
scaleFn={facetXScale}
|
|
42
|
+
scaleFn={facetXScale as any}
|
|
43
43
|
scaleType="band"
|
|
44
44
|
ticks={fxValues}
|
|
45
|
-
tickFormat={plot.options.fx.tickFormat || ((d) => d)}
|
|
45
|
+
tickFormat={(plot.options.fx.tickFormat || ((d: any) => d)) as any}
|
|
46
46
|
tickFontSize={11}
|
|
47
47
|
tickSize={0}
|
|
48
48
|
tickPadding={plot.options.x.axis === plot.options.fx.axis ||
|
|
49
49
|
plot.options.x.axis === 'both'
|
|
50
50
|
? 25
|
|
51
51
|
: 5}
|
|
52
|
-
anchor={plot.options.fx.axis
|
|
52
|
+
anchor={plot.options.fx.axis === 'both'
|
|
53
|
+
? 'top'
|
|
54
|
+
: (plot.options.fx.axis as 'top' | 'bottom' | undefined)}
|
|
55
|
+
title={null}
|
|
53
56
|
options={plot.options.fx.axisOptions || {}}
|
|
54
57
|
{...plot.options.fx.axisProps || {}}
|
|
55
58
|
height={plot.plotHeight}
|
|
@@ -61,14 +64,16 @@
|
|
|
61
64
|
<g transform="translate(0, {plot.options.marginTop})">
|
|
62
65
|
<BaseAxisY
|
|
63
66
|
class="facet-axis-y"
|
|
64
|
-
scaleFn={facetYScale}
|
|
67
|
+
scaleFn={facetYScale as any}
|
|
65
68
|
scaleType="band"
|
|
66
69
|
ticks={fyValues}
|
|
67
|
-
tickFormat={plot.options.fy.tickFormat || ((d) => d)}
|
|
70
|
+
tickFormat={(plot.options.fy.tickFormat || ((d: any) => d)) as any}
|
|
68
71
|
tickFontSize={11}
|
|
69
72
|
tickSize={0}
|
|
70
73
|
tickPadding={5}
|
|
71
|
-
anchor={plot.options.fy.axis
|
|
74
|
+
anchor={plot.options.fy.axis === 'both'
|
|
75
|
+
? 'right'
|
|
76
|
+
: (plot.options.fy.axis as 'left' | 'right' | undefined)}
|
|
72
77
|
lineAnchor="center"
|
|
73
78
|
options={plot.options.fy.axisOptions || {}}
|
|
74
79
|
{...plot.options.fy.axisProps || {}}
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
? (plot.options.fx?.paddingInner ?? plot.options.fx?.padding ?? 0.1)
|
|
44
44
|
: 0
|
|
45
45
|
)
|
|
46
|
-
.domain(fxValues)
|
|
46
|
+
.domain(fxValues as string[])
|
|
47
47
|
.rangeRound([0, plot.plotWidth])
|
|
48
48
|
);
|
|
49
49
|
const facetYScale = $derived(
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
? (plot.options.fy?.paddingInner ?? plot.options.fy?.padding ?? 0.1)
|
|
55
55
|
: 0
|
|
56
56
|
)
|
|
57
|
-
.domain(fyValues)
|
|
57
|
+
.domain(fyValues as string[])
|
|
58
58
|
.rangeRound([0, plot.plotHeight])
|
|
59
59
|
);
|
|
60
60
|
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
data-facet={i * fyValues.length + j}
|
|
76
76
|
fill="currentColor"
|
|
77
77
|
style:display={emptyFacets.get(facetX)?.get(facetY) ? 'none' : 'block'}
|
|
78
|
-
transform="translate({useFacetX ? facetXScale(facetX) : 0}, {useFacetY
|
|
79
|
-
? facetYScale(facetY)
|
|
78
|
+
transform="translate({useFacetX ? facetXScale(facetX as string) : 0}, {useFacetY
|
|
79
|
+
? facetYScale(facetY as string)
|
|
80
80
|
: 0})">
|
|
81
81
|
<!-- facets need invisible rect -->
|
|
82
82
|
<rect
|
package/dist/core/Plot.svelte
CHANGED
|
@@ -94,8 +94,8 @@
|
|
|
94
94
|
axisY: {
|
|
95
95
|
anchor: 'left',
|
|
96
96
|
implicit: true,
|
|
97
|
-
...USER_DEFAULTS.axis,
|
|
98
|
-
...USER_DEFAULTS.axisY
|
|
97
|
+
...(USER_DEFAULTS.axis as any),
|
|
98
|
+
...(USER_DEFAULTS.axisY as any)
|
|
99
99
|
},
|
|
100
100
|
gridX: {
|
|
101
101
|
implicit: false,
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
...asGridDefaults(USER_DEFAULTS.grid),
|
|
108
108
|
...asGridDefaults(USER_DEFAULTS.gridY)
|
|
109
109
|
}
|
|
110
|
-
};
|
|
110
|
+
} as PlotDefaults;
|
|
111
111
|
|
|
112
112
|
let {
|
|
113
113
|
header,
|
|
@@ -171,7 +171,7 @@
|
|
|
171
171
|
);
|
|
172
172
|
|
|
173
173
|
const explicitDomains = $derived(
|
|
174
|
-
new Set(SCALES.filter((scale) => !!initialOptions[scale]?.domain))
|
|
174
|
+
new Set(SCALES.filter((scale) => !!(initialOptions as any)[scale]?.domain))
|
|
175
175
|
);
|
|
176
176
|
|
|
177
177
|
// one-dimensional plots have different automatic margins and heights
|
|
@@ -184,7 +184,7 @@
|
|
|
184
184
|
explicitScales,
|
|
185
185
|
explicitDomains,
|
|
186
186
|
hasProjection: !!initialOptions.projection,
|
|
187
|
-
margin: initialOptions.margin,
|
|
187
|
+
margin: initialOptions.margin as number | 'auto' | undefined,
|
|
188
188
|
inset: initialOptions.inset
|
|
189
189
|
})
|
|
190
190
|
);
|
|
@@ -217,7 +217,7 @@
|
|
|
217
217
|
|
|
218
218
|
const defaultPointScaleHeight = $derived(
|
|
219
219
|
explicitScales.has('r') && plotOptions.r.range
|
|
220
|
-
? plotOptions.r.range[1] * 2
|
|
220
|
+
? (plotOptions.r.range[1] as number) * 2
|
|
221
221
|
: DEFAULTS.pointScaleHeight
|
|
222
222
|
);
|
|
223
223
|
|
|
@@ -233,8 +233,8 @@
|
|
|
233
233
|
? plotOptions.height(plotWidth)
|
|
234
234
|
: maybeNumber(plotOptions.height) === null || plotOptions.height === 'auto'
|
|
235
235
|
? Math.round(
|
|
236
|
-
preScales.projection && preScales.projection.aspectRatio
|
|
237
|
-
? ((plotWidth * preScales.projection.aspectRatio) / xFacetCount) *
|
|
236
|
+
preScales.projection && (preScales.projection as any).aspectRatio
|
|
237
|
+
? ((plotWidth * (preScales.projection as any).aspectRatio) / xFacetCount) *
|
|
238
238
|
yFacetCount +
|
|
239
239
|
plotOptions.marginTop +
|
|
240
240
|
plotOptions.marginBottom
|
|
@@ -260,7 +260,7 @@
|
|
|
260
260
|
: maybeNumber(plotOptions.height)
|
|
261
261
|
);
|
|
262
262
|
|
|
263
|
-
const plotHeight = $derived(height - plotOptions.marginTop - plotOptions.marginBottom);
|
|
263
|
+
const plotHeight = $derived((height ?? 0) - plotOptions.marginTop - plotOptions.marginBottom);
|
|
264
264
|
|
|
265
265
|
// TODO: check if there's still a reason to store and expose the plot body element
|
|
266
266
|
let plotBody: HTMLDivElement | null = $state(null);
|
|
@@ -280,7 +280,7 @@
|
|
|
280
280
|
const scales = computeScales(
|
|
281
281
|
plotOptions,
|
|
282
282
|
facetWidth || width,
|
|
283
|
-
facetHeight
|
|
283
|
+
facetHeight ?? height ?? 0,
|
|
284
284
|
hasFilledDotMarks,
|
|
285
285
|
marks,
|
|
286
286
|
DEFAULTS
|
|
@@ -293,9 +293,9 @@
|
|
|
293
293
|
return {
|
|
294
294
|
options: plotOptions,
|
|
295
295
|
width,
|
|
296
|
-
height,
|
|
297
|
-
facetWidth,
|
|
298
|
-
facetHeight,
|
|
296
|
+
height: height ?? 0,
|
|
297
|
+
facetWidth: facetWidth ?? undefined,
|
|
298
|
+
facetHeight: facetHeight ?? undefined,
|
|
299
299
|
plotHeight,
|
|
300
300
|
plotWidth,
|
|
301
301
|
scales,
|
|
@@ -303,7 +303,7 @@
|
|
|
303
303
|
hasFilledDotMarks,
|
|
304
304
|
body: plotBody,
|
|
305
305
|
css
|
|
306
|
-
};
|
|
306
|
+
} as any;
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
setContext('svelteplot', {
|
|
@@ -363,11 +363,11 @@
|
|
|
363
363
|
const xDomainExtent =
|
|
364
364
|
x.type === 'band' || x.type === 'point'
|
|
365
365
|
? x.domain.length
|
|
366
|
-
: Math.abs(x.domain[1] - x.domain[0]);
|
|
366
|
+
: Math.abs((x.domain[1] as number) - (x.domain[0] as number));
|
|
367
367
|
const yDomainExtent =
|
|
368
368
|
y.type === 'band' || y.type === 'point'
|
|
369
369
|
? y.domain.length
|
|
370
|
-
: Math.abs(y.domain[1] - y.domain[0]);
|
|
370
|
+
: Math.abs((y.domain[1] as number) - (y.domain[0] as number));
|
|
371
371
|
return (
|
|
372
372
|
((plotWidth / xDomainExtent) * yDomainExtent) / aspectRatio + marginTop + marginBottom
|
|
373
373
|
);
|
|
@@ -378,10 +378,10 @@
|
|
|
378
378
|
opts: PlotOptionsParameters
|
|
379
379
|
): ResolvedPlotOptions {
|
|
380
380
|
return mergeDeep<PlotOptions>(
|
|
381
|
-
{}
|
|
382
|
-
{ sortOrdinalDomains: DEFAULTS.sortOrdinalDomains }
|
|
383
|
-
smartDefaultPlotOptions(opts),
|
|
384
|
-
initialOptions
|
|
381
|
+
{} as Partial<PlotOptions>,
|
|
382
|
+
{ sortOrdinalDomains: DEFAULTS.sortOrdinalDomains } as Partial<PlotOptions>,
|
|
383
|
+
smartDefaultPlotOptions(opts) as any,
|
|
384
|
+
initialOptions as any
|
|
385
385
|
) as ResolvedPlotOptions;
|
|
386
386
|
}
|
|
387
387
|
|
|
@@ -510,14 +510,14 @@
|
|
|
510
510
|
padding: 0,
|
|
511
511
|
align: 0
|
|
512
512
|
},
|
|
513
|
-
color: { type: 'auto', unknown: DEFAULTS.unknown },
|
|
513
|
+
color: { type: 'auto' as any, unknown: DEFAULTS.unknown },
|
|
514
514
|
length: { type: 'linear' },
|
|
515
515
|
symbol: { type: 'ordinal' },
|
|
516
516
|
fx: { type: 'band', axis: 'top' },
|
|
517
517
|
fy: { type: 'band', axis: 'right' },
|
|
518
518
|
locale: DEFAULTS.locale,
|
|
519
519
|
css: DEFAULTS.css
|
|
520
|
-
};
|
|
520
|
+
} as ResolvedPlotOptions;
|
|
521
521
|
}
|
|
522
522
|
|
|
523
523
|
const mapXY = $derived((x: RawValue, y: RawValue) => {
|
|
@@ -548,7 +548,7 @@
|
|
|
548
548
|
{#if children}
|
|
549
549
|
{@render children({
|
|
550
550
|
width,
|
|
551
|
-
height,
|
|
551
|
+
height: height ?? 0,
|
|
552
552
|
options: plotOptions,
|
|
553
553
|
scales: plotState.scales,
|
|
554
554
|
mapXY,
|
|
@@ -564,7 +564,7 @@
|
|
|
564
564
|
{#if overlay}<div class="plot-overlay">
|
|
565
565
|
{@render overlay?.({
|
|
566
566
|
width,
|
|
567
|
-
height,
|
|
567
|
+
height: height ?? 0,
|
|
568
568
|
options: plotOptions,
|
|
569
569
|
scales: plotState.scales,
|
|
570
570
|
mapXY,
|
package/dist/types/plot.d.ts
CHANGED
|
@@ -495,6 +495,12 @@ export type PlotOptions = {
|
|
|
495
495
|
height: number;
|
|
496
496
|
options: ResolvedPlotOptions;
|
|
497
497
|
scales: PlotScales;
|
|
498
|
+
hasProjection: boolean;
|
|
499
|
+
hasExplicitAxisX: boolean;
|
|
500
|
+
hasExplicitAxisY: boolean;
|
|
501
|
+
hasExplicitGridX: boolean;
|
|
502
|
+
hasExplicitGridY: boolean;
|
|
503
|
+
[key: string]: any;
|
|
498
504
|
}
|
|
499
505
|
]>;
|
|
500
506
|
/**
|
|
@@ -522,6 +528,12 @@ export type PlotOptions = {
|
|
|
522
528
|
height: number;
|
|
523
529
|
options: ResolvedPlotOptions;
|
|
524
530
|
scales: PlotScales;
|
|
531
|
+
hasProjection: boolean;
|
|
532
|
+
hasExplicitAxisX: boolean;
|
|
533
|
+
hasExplicitAxisY: boolean;
|
|
534
|
+
hasExplicitGridX: boolean;
|
|
535
|
+
hasExplicitGridY: boolean;
|
|
536
|
+
[key: string]: any;
|
|
525
537
|
}
|
|
526
538
|
]>;
|
|
527
539
|
/**
|