diff --git a/src/legends.js b/src/legends.js index 90b054d65e..31dc25adbb 100644 --- a/src/legends.js +++ b/src/legends.js @@ -5,8 +5,8 @@ import {legendRamp} from "./legends/ramp.js"; import {legendSwatches, legendSymbols} from "./legends/swatches.js"; const legendRegistry = new Map([ - ["color", legendColor], ["symbol", legendSymbols], + ["color", legendColor], ["opacity", legendOpacity] ]); diff --git a/src/marks/dot.js b/src/marks/dot.js index 6210621b2d..fd600837ca 100644 --- a/src/marks/dot.js +++ b/src/marks/dot.js @@ -42,8 +42,8 @@ export class Dot extends Mark { const fillChannel = channels.find(({name}) => name === "fill"); const strokeChannel = channels.find(({name}) => name === "stroke"); symbolChannel.hint = { - fill: fillChannel ? (fillChannel.value === symbolChannel.value ? "color" : true) : this.fill, - stroke: strokeChannel ? (strokeChannel.value === symbolChannel.value ? "color" : true) : this.stroke + fill: fillChannel ? (fillChannel.value === symbolChannel.value ? "color" : "currentColor") : this.fill, + stroke: strokeChannel ? (strokeChannel.value === symbolChannel.value ? "color" : "currentColor") : this.stroke }; } } diff --git a/test/output/symbolLegendDifferentColor.html b/test/output/symbolLegendDifferentColor.html new file mode 100644 index 0000000000..c015a21c2b --- /dev/null +++ b/test/output/symbolLegendDifferentColor.html @@ -0,0 +1,50 @@ +
+ + + A + + B + + C + + D + + E + + F +
\ No newline at end of file diff --git a/test/plots/legend-symbol.js b/test/plots/legend-symbol.js index 8b13e641c7..5e7dbf4c7d 100644 --- a/test/plots/legend-symbol.js +++ b/test/plots/legend-symbol.js @@ -5,20 +5,27 @@ export function symbolLegendBasic() { return Plot.legend({symbol: {domain: "ABCDEF"}}); } -// TODO There’s no way to define a standalone symbol legend with a color scale, -// since the color scale takes priority if both are specified. +// TODO It would be nice if the symbol scale’s range automatically defaulted to +// d3.symbolsFill given the presence of fill “color”. export function symbolLegendColorFill() { - return Plot.plot({color: {domain: "ABCDEF"}, symbol: {domain: "ABCDEF", range: d3.symbolsFill}}).legend("symbol", {fill: "color"}); + return Plot.legend({color: {domain: "ABCDEF"}, symbol: {domain: "ABCDEF", range: d3.symbolsFill}, fill: "color"}); } -// TODO There’s no way to define a standalone symbol legend with a color scale, -// since the color scale takes priority if both are specified. +// TODO It would be nice if the stroke option defaulted to “color” given the +// presence of a color scale (and no fill option). export function symbolLegendColorStroke() { - return Plot.plot({color: {domain: "ABCDEF"}, symbol: {domain: "ABCDEF"}}).legend("symbol", {stroke: "color"}); + return Plot.legend({color: {domain: "ABCDEF"}, symbol: {domain: "ABCDEF"}, stroke: "color"}); } -// TODO It would be nice if the symbol hint could apply here; but the hint is -// currently only set by marks that have matching channels. +// Note: The symbol hint requires reference equality for channel definitions, +// and so doesn’t consider the fill and symbol channels to be using the same +// encoding here. +export function symbolLegendDifferentColor() { + return Plot.dotX("ABCDEF", {fill: d => d, symbol: d => d}).plot().legend("symbol"); +} + +// TODO It would be nice if the symbol scale’s range automatically defaulted to +// d3.symbolsFill given the presence of the fill option. export function symbolLegendFill() { return Plot.legend({symbol: {domain: "ABCDEF", range: d3.symbolsFill}, fill: "red"}); }