-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from RhoInc/hoverlap
Overlap tooltips
- Loading branch information
Showing
5 changed files
with
137 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/callbacks/onResize/addEventListeners/functions/addOverlapTitle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import checkPointOverlap from './checkPointOverlap'; | ||
|
||
export default function addOverlapTitle(d, chart) { | ||
// check for overlapping points | ||
var overlap = checkPointOverlap.call(this, d, chart); | ||
|
||
// If there are overlapping points, add a note in the details section. | ||
|
||
if (overlap.length > 0) { | ||
var titleEl = d3.select(this).select('title'); | ||
var currentTitle = titleEl.text(); | ||
var hasOverlapNote = currentTitle.search('overlapping'); //minor hack ... | ||
if (hasOverlapNote == -1) { | ||
var newTitle = currentTitle + '\nNumber of overlapping point(s) = ' + overlap.length; | ||
titleEl.text(newTitle); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/callbacks/onResize/addEventListeners/functions/checkPointOverlap.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export default function checkPointOverlap(d, chart) { | ||
// Get the position of the clicked point | ||
const click_x = d3 | ||
.select(this) | ||
.select('circle') | ||
.attr('cx'); | ||
const click_y = d3 | ||
.select(this) | ||
.select('circle') | ||
.attr('cy'); | ||
const click_r = d3 | ||
.select(this) | ||
.select('circle') | ||
.attr('r'); | ||
const click_id = d.values.raw[0][chart.config.id_col]; | ||
|
||
// See if any other points overlap | ||
var overlap_ids = chart.points | ||
.filter(function(f) { | ||
const point_id = f.values.raw[0][chart.config.id_col]; | ||
const point_x = d3 | ||
.select(this) | ||
.select('circle') | ||
.attr('cx'); | ||
const point_y = d3 | ||
.select(this) | ||
.select('circle') | ||
.attr('cy'); | ||
const distance_x2 = Math.pow(click_x - point_x, 2); | ||
const distance_y2 = Math.pow(click_y - point_y, 2); | ||
const distance = Math.sqrt(distance_x2 + distance_y2); | ||
|
||
const max_distance = click_r * 2; | ||
const overlap = distance <= max_distance; | ||
const diff_id = point_id != click_id; | ||
return diff_id & overlap; | ||
}) | ||
.data() | ||
.map(d => d.values.raw[0][chart.config.id_col]); | ||
|
||
return overlap_ids; | ||
} |