Skip to content

Commit bdae7d1

Browse files
authored
the dot or geo mark is empty if given a constant negative r (#1158)
0 is accepted, as it doesn't result in an error for dots, and may be useful for geo marks. fixes #1145
1 parent 0c080ad commit bdae7d1

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/marks/dot.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {path, symbolCircle} from "d3";
22
import {create} from "../context.js";
3-
import {positive} from "../defined.js";
3+
import {negative, positive} from "../defined.js";
44
import {identity, maybeFrameAnchor, maybeNumberChannel, maybeTuple} from "../options.js";
55
import {Mark} from "../plot.js";
66
import {
@@ -68,6 +68,8 @@ export class Dot extends Mark {
6868
const {x: X, y: Y, r: R, rotate: A, symbol: S} = channels;
6969
const [cx, cy] = applyFrameAnchor(this, dimensions);
7070
const circle = this.symbol === symbolCircle;
71+
const {r} = this;
72+
if (negative(r)) index = [];
7173
return create("svg:g", context)
7274
.call(applyIndirectStyles, this, scales, dimensions, context)
7375
.call(applyTransform, this, {x: X && x, y: Y && y})
@@ -84,7 +86,7 @@ export class Dot extends Mark {
8486
selection
8587
.attr("cx", X ? (i) => X[i] : cx)
8688
.attr("cy", Y ? (i) => Y[i] : cy)
87-
.attr("r", R ? (i) => R[i] : this.r);
89+
.attr("r", R ? (i) => R[i] : r);
8890
}
8991
: (selection) => {
9092
const translate =
@@ -106,8 +108,8 @@ export class Dot extends Mark {
106108
)
107109
.attr("d", (i) => {
108110
const p = path(),
109-
r = R ? R[i] : this.r;
110-
(S ? S[i] : this.symbol).draw(p, r * r * Math.PI);
111+
radius = R ? R[i] : r;
112+
(S ? S[i] : this.symbol).draw(p, radius * radius * Math.PI);
111113
return p;
112114
});
113115
}

src/marks/geo.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {geoGraticule10, geoPath} from "d3";
22
import {create} from "../context.js";
3-
import {positive} from "../defined.js";
3+
import {negative, positive} from "../defined.js";
44
import {identity, maybeNumberChannel} from "../options.js";
55
import {Mark} from "../plot.js";
66
import {applyChannelStyles, applyDirectStyles, applyIndirectStyles, applyTransform} from "../style.js";
@@ -34,7 +34,8 @@ export class Geo extends Mark {
3434
const {geometry: G, r: R} = channels;
3535
const path = geoPath(context.projection);
3636
const {r} = this;
37-
if (r !== undefined) path.pointRadius(r);
37+
if (negative(r)) index = [];
38+
else if (r !== undefined) path.pointRadius(r);
3839
return create("svg:g", context)
3940
.call(applyIndirectStyles, this, scales, dimensions, context)
4041
.call(applyTransform, this, scales)

0 commit comments

Comments
 (0)