Skip to content

Commit

Permalink
If a point has no stroke or fill, don't return it from pointSearch.
Browse files Browse the repository at this point in the history
Before, regardless of fill, the point could be returned (unless it had
no stroke and a radius of 0).
  • Loading branch information
manthey committed Jun 4, 2019
1 parent d9a3495 commit c9df9f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/pointFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ var pointFeature = function (arg) {
var min, max, data, idx = [], found = [], ifound = [], map, pt,
fgcs = m_this.gcs(), // this feature's gcs
corners,
fill = m_this.style.get('fill'),
stroke = m_this.style.get('stroke'),
strokeWidth = m_this.style.get('strokeWidth'),
radius = m_this.style.get('radius');
Expand Down Expand Up @@ -314,11 +315,14 @@ var pointFeature = function (arg) {
// Filter by circular region
idx.forEach(function (i) {
var d = data[i],
p = m_this.position()(d, i),
hasstroke = stroke(data[i], i);
if (!hasstroke && !fill(data[i], i)) {
return;
}
var p = m_this.position()(d, i),
dx, dy, rad, rad2;

rad = radius(data[i], i);
rad += stroke(data[i], i) ? strokeWidth(data[i], i) : 0;
rad += hasstroke ? strokeWidth(data[i], i) : 0;
if (rad) {
rad2 = rad * rad;
p = map.gcsToDisplay(p, fgcs);
Expand Down
9 changes: 8 additions & 1 deletion tests/cases/pointFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,16 @@ describe('geo.pointFeature', function () {
expect(pt.found.length).toBe(1);
pt = point.pointSearch(map.displayToGcs({x: p.x, y: p.y + 4.05}));
expect(pt.found.length).toBe(0);
/* We should match two coincident pointss */
/* We should match two coincident points */
pt = point.pointSearch({x: 50, y: 10});
expect(pt.found.length).toBe(2);
/* If a point has no fill or stroke, it won't be found. */
point.style({
fill: function (d, i) { return i !== 16; },
stroke: function (d, i) { return i !== 16; }
});
pt = point.pointSearch({x: 50, y: 10});
expect(pt.found.length).toBe(1);
/* If we have zero-length data, we get no matches */
point.data([]);
pt = point.pointSearch({x: 22, y: 10});
Expand Down

0 comments on commit c9df9f7

Please sign in to comment.