svelteplot 0.14.1 → 0.14.2-pr-550.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.
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
regressionLoess
|
|
44
44
|
} from '../../regression/index.js';
|
|
45
45
|
import { resolveChannel } from '../../helpers/resolve.js';
|
|
46
|
-
import { isTemporalScale } from '../../helpers/typeChecks.js';
|
|
47
46
|
import { confidenceInterval } from '../../helpers/math.js';
|
|
48
47
|
import callWithProps from '../../helpers/callWithProps.js';
|
|
49
48
|
import type { DataRecord, FacetContext, RawValue } from '../../types/index.js';
|
|
@@ -93,8 +92,12 @@
|
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
// Convert generated points back to Date for time scales so downstream marks render correctly.
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
// Takes a boolean instead of the scale type to avoid a circular dependency: if we used
|
|
96
|
+
// plot.scales[independent].type, the Line mark would register numeric __x values during the
|
|
97
|
+
// first render pass (before the scale type is resolved), causing scale inference to see a mix
|
|
98
|
+
// of Dates and numbers and fall back to 'linear' permanently.
|
|
99
|
+
function toOutputX(value: number, isTemporal: boolean): RawValue {
|
|
100
|
+
return isTemporal ? new Date(value) : value;
|
|
98
101
|
}
|
|
99
102
|
|
|
100
103
|
function makeTicks(domain: [number, number], count = 40): number[] {
|
|
@@ -129,6 +132,14 @@
|
|
|
129
132
|
|
|
130
133
|
const regressionFn = $derived(maybeRegression(type));
|
|
131
134
|
|
|
135
|
+
// Detect temporality from the raw data rather than from the computed scale type to avoid a
|
|
136
|
+
// circular dependency that would cause the scale type to be permanently inferred as 'linear'.
|
|
137
|
+
// Scan for the first row that resolves to a non-null independent value — checking only
|
|
138
|
+
// filteredData[0] would give false negatives when the leading row has a missing/null value.
|
|
139
|
+
const independentIsDate = $derived(
|
|
140
|
+
filteredData.some((d) => resolveChannel(independent, d, options as any) instanceof Date)
|
|
141
|
+
);
|
|
142
|
+
|
|
132
143
|
// Build a clean numeric input set for regression fitting, dropping invalid rows early.
|
|
133
144
|
const regressionInput = $derived(
|
|
134
145
|
filteredData
|
|
@@ -193,18 +204,18 @@
|
|
|
193
204
|
// Prefer batch prediction when supported, then per-point predict, then raw curve output.
|
|
194
205
|
if (typeof regression.predictMany === 'function') {
|
|
195
206
|
return regression.predictMany(regrPoints).map((__y, i) => ({
|
|
196
|
-
__x: toOutputX(regrPoints[i],
|
|
207
|
+
__x: toOutputX(regrPoints[i], independentIsDate),
|
|
197
208
|
__y
|
|
198
209
|
}));
|
|
199
210
|
}
|
|
200
211
|
if (typeof regression.predict === 'function') {
|
|
201
212
|
return regrPoints.map((point) => ({
|
|
202
|
-
__x: toOutputX(point,
|
|
213
|
+
__x: toOutputX(point, independentIsDate),
|
|
203
214
|
__y: regression.predict!(point)
|
|
204
215
|
}));
|
|
205
216
|
}
|
|
206
217
|
return regression.map(([__x, __y]) => ({
|
|
207
|
-
__x: toOutputX(__x,
|
|
218
|
+
__x: toOutputX(__x, independentIsDate),
|
|
208
219
|
__y
|
|
209
220
|
}));
|
|
210
221
|
});
|
|
@@ -230,7 +241,7 @@
|
|
|
230
241
|
return regrPoints.map((x) => {
|
|
231
242
|
const { x: __x, left, right } = confBandGen(x);
|
|
232
243
|
return {
|
|
233
|
-
__x: toOutputX(__x,
|
|
244
|
+
__x: toOutputX(__x, independentIsDate),
|
|
234
245
|
__y1: left,
|
|
235
246
|
__y2: right
|
|
236
247
|
};
|