Skip to content

Commit ec968dd

Browse files
committed
apply suggestions from code review
note: the test snapshot changed _for the better_. utcTickInterval picks the best interval for the actual domain
1 parent 763f0fd commit ec968dd

2 files changed

Lines changed: 35 additions & 21 deletions

File tree

src/marks/contour.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {blur2, contours, geoPath, max, min, nice, range, ticks, thresholdSturges, scaleUtc} from "d3";
1+
import {blur2, contours, geoPath, max, min, nice, range, ticks, thresholdSturges, utcTickInterval} from "d3";
22
import {createChannels} from "../channel.js";
33
import {create} from "../context.js";
4-
import {labelof, identity, arrayify, map, isTemporal} from "../options.js";
4+
import {labelof, identity, arrayify, map, isTemporal, coerceNumbers} from "../options.js";
55
import {applyPosition} from "../projection.js";
66
import {applyChannelStyles, applyDirectStyles, applyIndirectStyles, applyTransform, styles} from "../style.js";
77
import {initializer} from "../transforms/basic.js";
@@ -116,7 +116,7 @@ function contourGeometry({thresholds, interval, ...options}) {
116116
const kx = w / dx;
117117
const ky = h / dy;
118118
const temporal = isTemporal(channels.value.value);
119-
const V = temporal && this.blur > 0 ? Float64Array.from(channels.value.value) : channels.value.value;
119+
const V = this.blur > 0 ? coerceNumbers(channels.value.value) : channels.value.value;
120120
const VV = []; // V per facet
121121

122122
// Interpolate the raster grid, as needed.
@@ -192,7 +192,10 @@ function maybeTicks(thresholds, V, min, max, temporal) {
192192
if (typeof thresholds?.range === "function") return thresholds.range(thresholds.floor(min), max);
193193
if (typeof thresholds === "function") thresholds = thresholds(V, min, max);
194194
if (typeof thresholds !== "number") return arrayify(thresholds);
195-
if (temporal) return scaleUtc().domain([min, max]).nice(thresholds).ticks(thresholds);
195+
if (temporal) {
196+
thresholds = utcTickInterval(min, max, thresholds);
197+
return thresholds.range(thresholds.floor(min), max);
198+
}
196199
const tz = ticks(...nice(min, max, thresholds), thresholds);
197200
while (tz[tz.length - 1] >= max) tz.pop();
198201
while (tz[1] < min) tz.shift();

0 commit comments

Comments
 (0)