Skip to content

tip on a geo mark without a projection should not collapse the chart #1746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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