Skip to content

Commit

Permalink
tip ignores literal colors (#2091)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock authored Jun 16, 2024
1 parent 7c8a465 commit ca6fb81
Show file tree
Hide file tree
Showing 5 changed files with 442 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ export function inferChannelScale(name, channel) {
case "stroke":
case "color":
channel.scale = scale !== true && isEvery(value, isColor) ? null : "color";
channel.defaultScale = "color";
break;
case "fillOpacity":
case "strokeOpacity":
case "opacity":
channel.scale = scale !== true && isEvery(value, isOpacity) ? null : "opacity";
channel.defaultScale = "opacity";
break;
case "symbol":
if (scale !== true && isEvery(value, isSymbol)) {
Expand All @@ -61,6 +63,7 @@ export function inferChannelScale(name, channel) {
} else {
channel.scale = "symbol";
}
channel.defaultScale = "symbol";
break;
default:
channel.scale = registry.has(name) ? name : null;
Expand Down
2 changes: 1 addition & 1 deletion src/legends.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function legendOptions({className, ...context}, {label, ticks, tickFormat} = {},

function legendColor(color, {legend = true, ...options}) {
if (legend === true) legend = color.type === "ordinal" ? "swatches" : "ramp";
if (color.domain === undefined) return;
if (color.domain === undefined) return; // no identity legend
switch (`${legend}`.toLowerCase()) {
case "swatches":
return legendSwatches(color, options);
Expand Down
6 changes: 5 additions & 1 deletion src/marks/tip.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@ function getSourceChannels(channels, scales) {
for (const key in channels) {
if (key in sources || key in format || ignoreChannels.has(key)) continue;
const source = getSource(channels, key);
if (source) sources[key] = source;
if (source) {
// Ignore color channels if the values are all literal colors.
if (source.scale == null && source.defaultScale === "color") continue;
sources[key] = source;
}
}

// And lastly facet channels, but only if this mark is faceted.
Expand Down
Loading

0 comments on commit ca6fb81

Please sign in to comment.