Skip to content

Commit 14ce030

Browse files
authored
fix hexbin default stroke (#1641)
1 parent 90d20a5 commit 14ce030

File tree

4 files changed

+332
-10
lines changed

4 files changed

+332
-10
lines changed

src/style.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export function styles(
4747
imageFilter,
4848
paintOrder,
4949
pointerEvents,
50-
shapeRendering
50+
shapeRendering,
51+
channels
5152
},
5253
{
5354
ariaLabel: cariaLabel,
@@ -81,9 +82,9 @@ export function styles(
8182
// default fill becomes none. Similarly for marks that stroke by stroke, the
8283
// default stroke only applies if the fill is (constant) none.
8384
if (isNoneish(defaultFill)) {
84-
if (!isNoneish(defaultStroke) && !isNoneish(fill)) defaultStroke = "none";
85+
if (!isNoneish(defaultStroke) && (!isNoneish(fill) || channels?.fill)) defaultStroke = "none";
8586
} else {
86-
if (isNoneish(defaultStroke) && !isNoneish(stroke)) defaultFill = "none";
87+
if (isNoneish(defaultStroke) && (!isNoneish(stroke) || channels?.stroke)) defaultFill = "none";
8788
}
8889

8990
const [vfill, cfill] = maybeColorChannel(fill, defaultFill);

src/transforms/hexbin.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {isNoneish, map, number, valueof} from "../options.js";
1+
import {map, number, valueof} from "../options.js";
22
import {applyPosition} from "../projection.js";
33
import {sqrt3} from "../symbol.js";
44
import {initializer} from "./basic.js";
@@ -13,17 +13,19 @@ export const ox = 0.5,
1313
oy = 0;
1414

1515
export function hexbin(outputs = {fill: "count"}, {binWidth, ...options} = {}) {
16+
const {z} = options;
17+
1618
// TODO filter e.g. to show empty hexbins?
1719
// TODO disallow x, x1, x2, y, y1, y2 reducers?
1820
binWidth = binWidth === undefined ? 20 : number(binWidth);
1921
outputs = maybeOutputs(outputs, options);
2022

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

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

0 commit comments

Comments
 (0)