Skip to content

Auto mark: no display with non-zero reducer and bar mark #1340

Closed
@tophtucker

Description

@tophtucker

See examples. You get a bunch of zero-height bars:

Plot.auto(olympians, {x: "date_of_birth", y: { value: "height", reduce: "mean" }, mark: "bar"}).plot()

The easy fix is to change the last row of this to use rectY instead of rect, on the theory that Plot.auto never has enough information to use Plot.rect effectively:

plot/src/marks/auto.js

Lines 159 to 174 in c489290

case "bar":
mark = yZero
? isOrdinalReduced(xReduce, X)
? barY
: rectY
: xZero
? isOrdinalReduced(yReduce, Y)
? barX
: rectX
: isOrdinalReduced(xReduce, X) && isOrdinalReduced(yReduce, Y)
? cell
: isOrdinalReduced(xReduce, X)
? barY
: isOrdinalReduced(yReduce, Y)
? barX
: rect;

That works in this case:

But it breaks the heatmap, because it gives it a zero baseline:

Plot.auto(penguins, {x: "culmen_length_mm", y: "body_mass_g", color: "count"}).plot()

Because we're inferring whether to show the zero baseline from the mark type:

plot/src/marks/auto.js

Lines 217 to 220 in c489290

// If zero-ness is not specified, default based on whether the resolved mark
// type will include a zero baseline. TODO Move this to autoSpec.
if (xZero === undefined) xZero = transform !== binX && (mark === barX || mark === areaX || mark === rectX);
if (yZero === undefined) yZero = transform !== binY && (mark === barY || mark === areaY || mark === rectY);

We could change that bit. But, moreover, the heatmap example shows that Plot.auto does sometimes have enough information to specify a rect mark: in the case of 2D binning. So just switching rect to rectY feels wrong.

Metadata

Metadata

Assignees

Labels

bugSomething isn’t working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions