Skip to content

Commit

Permalink
tip on a geo mark without a projection should not collapse the chart (#…
Browse files Browse the repository at this point in the history
…1746)

* fix collapsing bug (#1742)

* avoid array.includes

---------

Co-authored-by: Mike Bostock <mbostock@gmail.com>
  • Loading branch information
Fil and mbostock committed Aug 21, 2023
1 parent e2ed033 commit 9747e02
Show file tree
Hide file tree
Showing 6 changed files with 6,329 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {arrayify, map, yes, maybeIntervalTransform, subarray} from "./options.js
import {createProjection, getGeometryChannels, hasProjection} from "./projection.js";
import {createScales, createScaleFunctions, autoScaleRange, exposeScales} from "./scales.js";
import {innerDimensions, outerDimensions} from "./scales.js";
import {position, registry as scaleRegistry} from "./scales/index.js";
import {isPosition, registry as scaleRegistry} from "./scales/index.js";
import {applyInlineStyles, maybeClassName} from "./style.js";
import {initializer} from "./transforms/basic.js";
import {consumeWarnings, warn} from "./warnings.js";
Expand Down Expand Up @@ -201,7 +201,7 @@ export function plot(options = {}) {
// channels as-is rather than creating new scales, and assume that
// they already have the scale’s transform applied, if any (e.g., when
// generating ticks for the axis mark).
if (scale != null && scaleRegistry.get(scale) !== position) {
if (scale != null && !isPosition(scaleRegistry.get(scale))) {
applyScaleTransform(channel, options);
newByScale.add(scale);
}
Expand Down
5 changes: 5 additions & 0 deletions src/scales/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const opacity = Symbol("opacity");
export const symbol = Symbol("symbol");

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

// TODO Rather than hard-coding the list of known scale names, collect the names
Expand All @@ -40,3 +41,7 @@ export const registry = new Map([
["length", length],
["projection", projection]
]);

export function isPosition(kind) {
return kind === position || kind === projection;
}
9 changes: 8 additions & 1 deletion src/transforms/centroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ export function centroid({geometry = identity, ...options} = {}) {
const Y = new Float64Array(n);
const path = geoPath(projection);
for (let i = 0; i < n; ++i) [X[i], Y[i]] = path.centroid(G[i]);
return {data, facets, channels: {x: {value: X, source: null}, y: {value: Y, source: null}}};
return {
data,
facets,
channels: {
x: {value: X, scale: projection == null ? "x" : null, source: null},
y: {value: Y, scale: projection == null ? "y" : null, source: null}
}
};
});
}

Expand Down
Loading

0 comments on commit 9747e02

Please sign in to comment.