Skip to content

Commit 9747e02

Browse files
Filmbostock
andcommitted
tip on a geo mark without a projection should not collapse the chart (#1746)
* fix collapsing bug (#1742) * avoid array.includes --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent e2ed033 commit 9747e02

File tree

6 files changed

+6329
-3
lines changed

6 files changed

+6329
-3
lines changed

src/plot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {arrayify, map, yes, maybeIntervalTransform, subarray} from "./options.js
1414
import {createProjection, getGeometryChannels, hasProjection} from "./projection.js";
1515
import {createScales, createScaleFunctions, autoScaleRange, exposeScales} from "./scales.js";
1616
import {innerDimensions, outerDimensions} from "./scales.js";
17-
import {position, registry as scaleRegistry} from "./scales/index.js";
17+
import {isPosition, registry as scaleRegistry} from "./scales/index.js";
1818
import {applyInlineStyles, maybeClassName} from "./style.js";
1919
import {initializer} from "./transforms/basic.js";
2020
import {consumeWarnings, warn} from "./warnings.js";
@@ -201,7 +201,7 @@ export function plot(options = {}) {
201201
// channels as-is rather than creating new scales, and assume that
202202
// they already have the scale’s transform applied, if any (e.g., when
203203
// generating ticks for the axis mark).
204-
if (scale != null && scaleRegistry.get(scale) !== position) {
204+
if (scale != null && !isPosition(scaleRegistry.get(scale))) {
205205
applyScaleTransform(channel, options);
206206
newByScale.add(scale);
207207
}

src/scales/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const opacity = Symbol("opacity");
2323
export const symbol = Symbol("symbol");
2424

2525
// There isn’t really a projection scale; this represents x and y for geometry.
26+
// This is used to denote channels that should be projected.
2627
export const projection = Symbol("projection");
2728

2829
// TODO Rather than hard-coding the list of known scale names, collect the names
@@ -40,3 +41,7 @@ export const registry = new Map([
4041
["length", length],
4142
["projection", projection]
4243
]);
44+
45+
export function isPosition(kind) {
46+
return kind === position || kind === projection;
47+
}

src/transforms/centroid.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ export function centroid({geometry = identity, ...options} = {}) {
1111
const Y = new Float64Array(n);
1212
const path = geoPath(projection);
1313
for (let i = 0; i < n; ++i) [X[i], Y[i]] = path.centroid(G[i]);
14-
return {data, facets, channels: {x: {value: X, source: null}, y: {value: Y, source: null}}};
14+
return {
15+
data,
16+
facets,
17+
channels: {
18+
x: {value: X, scale: projection == null ? "x" : null, source: null},
19+
y: {value: Y, scale: projection == null ? "y" : null, source: null}
20+
}
21+
};
1522
});
1623
}
1724

0 commit comments

Comments
 (0)