|
1 |
| -import {blur2, contours, geoPath, max, min, nice, range, ticks, thresholdSturges} from "d3"; |
| 1 | +import {blur2, contours, geoPath, max, min, nice, range, ticks, thresholdSturges, scaleUtc} from "d3"; |
2 | 2 | import {createChannels} from "../channel.js";
|
3 | 3 | import {create} from "../context.js";
|
4 |
| -import {labelof, identity, arrayify, map} from "../options.js"; |
| 4 | +import {labelof, identity, arrayify, map, isTemporal} from "../options.js"; |
5 | 5 | import {applyPosition} from "../projection.js";
|
6 | 6 | import {applyChannelStyles, applyDirectStyles, applyIndirectStyles, applyTransform, styles} from "../style.js";
|
7 | 7 | import {initializer} from "../transforms/basic.js";
|
@@ -115,7 +115,8 @@ function contourGeometry({thresholds, interval, ...options}) {
|
115 | 115 | const {pixelSize: k, width: w = Math.round(Math.abs(dx) / k), height: h = Math.round(Math.abs(dy) / k)} = this;
|
116 | 116 | const kx = w / dx;
|
117 | 117 | const ky = h / dy;
|
118 |
| - const V = channels.value.value; |
| 118 | + const temporal = isTemporal(channels.value.value); |
| 119 | + const V = temporal && this.blur > 0 ? Float64Array.from(channels.value.value) : channels.value.value; |
119 | 120 | const VV = []; // V per facet
|
120 | 121 |
|
121 | 122 | // Interpolate the raster grid, as needed.
|
@@ -149,7 +150,7 @@ function contourGeometry({thresholds, interval, ...options}) {
|
149 | 150 | if (this.blur > 0) for (const V of VV) blur2({data: V, width: w, height: h}, this.blur);
|
150 | 151 |
|
151 | 152 | // Compute the contour thresholds.
|
152 |
| - const T = maybeTicks(thresholds, V, ...finiteExtent(VV)); |
| 153 | + const T = maybeTicks(thresholds, V, ...finiteExtent(VV), temporal); |
153 | 154 | if (T === null) throw new Error(`unsupported thresholds: ${thresholds}`);
|
154 | 155 |
|
155 | 156 | // Compute the (maybe faceted) contours.
|
@@ -187,10 +188,11 @@ function contourGeometry({thresholds, interval, ...options}) {
|
187 | 188 | // thresholds across facets. When an interval is used, note that the lowest
|
188 | 189 | // threshold should be below (or equal) to the lowest value, or else some data
|
189 | 190 | // will be missing.
|
190 |
| -function maybeTicks(thresholds, V, min, max) { |
| 191 | +function maybeTicks(thresholds, V, min, max, temporal) { |
191 | 192 | if (typeof thresholds?.range === "function") return thresholds.range(thresholds.floor(min), max);
|
192 | 193 | if (typeof thresholds === "function") thresholds = thresholds(V, min, max);
|
193 | 194 | if (typeof thresholds !== "number") return arrayify(thresholds);
|
| 195 | + if (temporal) return scaleUtc().domain([min, max]).nice(thresholds).ticks(thresholds); |
194 | 196 | const tz = ticks(...nice(min, max, thresholds), thresholds);
|
195 | 197 | while (tz[tz.length - 1] >= max) tz.pop();
|
196 | 198 | while (tz[1] < min) tz.shift();
|
|
0 commit comments