Skip to content
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

fix hexbin default stroke #1641

Merged
merged 1 commit into from
May 26, 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
7 changes: 4 additions & 3 deletions src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export function styles(
imageFilter,
paintOrder,
pointerEvents,
shapeRendering
shapeRendering,
channels
},
{
ariaLabel: cariaLabel,
Expand Down Expand Up @@ -81,9 +82,9 @@ export function styles(
// default fill becomes none. Similarly for marks that stroke by stroke, the
// default stroke only applies if the fill is (constant) none.
if (isNoneish(defaultFill)) {
if (!isNoneish(defaultStroke) && !isNoneish(fill)) defaultStroke = "none";
if (!isNoneish(defaultStroke) && (!isNoneish(fill) || channels?.fill)) defaultStroke = "none";
} else {
if (isNoneish(defaultStroke) && !isNoneish(stroke)) defaultFill = "none";
if (isNoneish(defaultStroke) && (!isNoneish(stroke) || channels?.stroke)) defaultFill = "none";
}

const [vfill, cfill] = maybeColorChannel(fill, defaultFill);
Expand Down
16 changes: 9 additions & 7 deletions src/transforms/hexbin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isNoneish, map, number, valueof} from "../options.js";
import {map, number, valueof} from "../options.js";
import {applyPosition} from "../projection.js";
import {sqrt3} from "../symbol.js";
import {initializer} from "./basic.js";
Expand All @@ -13,17 +13,19 @@ export const ox = 0.5,
oy = 0;

export function hexbin(outputs = {fill: "count"}, {binWidth, ...options} = {}) {
const {z} = options;

// TODO filter e.g. to show empty hexbins?
// TODO disallow x, x1, x2, y, y1, y2 reducers?
binWidth = binWidth === undefined ? 20 : number(binWidth);
outputs = maybeOutputs(outputs, options);

// A fill output means a fill channel, and hence the stroke should default to
// none (assuming a mark that defaults to fill and no stroke, such as dot).
// Note that it’s safe to mutate options here because we just created it with
// the rest operator above.
const {z, fill, stroke} = options;
if (stroke === undefined && isNoneish(fill) && hasOutput(outputs, "fill")) options.stroke = "none";
// A fill output means a fill channel; declaring the channel here instead of
// waiting for the initializer allows the mark constructor to determine that
// the stroke should default to none (assuming a mark that defaults to fill
// and no stroke, such as dot). Note that it’s safe to mutate options here
// because we just created it with the rest operator above.
if (hasOutput(outputs, "fill")) options.channels = {...options.channels, fill: {value: []}};

// Populate default values for the r and symbol options, as appropriate.
if (options.symbol === undefined) options.symbol = "hexagon";
Expand Down
Loading