-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Better hover for choropleth traces #1401
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bdbb3d6
replace nested geo SVG with cliped <g geolayer> in main SVG
etpinard ec6c1b1
add handler for 'nameOverride' field in pointData
etpinard 8c29dfb
refactor Choropleth plot
etpinard b461dc1
rm (now useless) Geo.updateFx method
etpinard 919fe42
no need to manually clear hover labels on zoom reset
etpinard c32d445
new geo baselines
etpinard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2762,11 +2762,6 @@ function makePlotFramework(gd) { | |
fullLayout._glcontainer.enter().append('div') | ||
.classed('gl-container', true); | ||
|
||
fullLayout._geocontainer = fullLayout._paperdiv.selectAll('.geo-container') | ||
.data([0]); | ||
fullLayout._geocontainer.enter().append('div') | ||
.classed('geo-container', true); | ||
|
||
fullLayout._paperdiv.selectAll('.main-svg').remove(); | ||
|
||
fullLayout._paper = fullLayout._paperdiv.insert('svg', ':first-child') | ||
|
@@ -2810,6 +2805,9 @@ function makePlotFramework(gd) { | |
// single ternary layer for the whole plot | ||
fullLayout._ternarylayer = fullLayout._paper.append('g').classed('ternarylayer', true); | ||
|
||
// single geo layer for the whole plot | ||
fullLayout._geolayer = fullLayout._paper.append('g').classed('geolayer', true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now geo lies side-by-side with other SVG subplot types 🎉 |
||
|
||
// upper shape layer | ||
// (only for shapes to be drawn above the whole plot, including subplots) | ||
var layerAbove = fullLayout._paper.append('g') | ||
|
@@ -2824,7 +2822,6 @@ function makePlotFramework(gd) { | |
|
||
// fill in image server scrape-svg | ||
fullLayout._glimages = fullLayout._paper.append('g').classed('glimages', true); | ||
fullLayout._geoimages = fullLayout._paper.append('g').classed('geoimages', true); | ||
|
||
// lastly info (legend, annotations) and hover layers go on top | ||
// these are in a different svg element normally, but get collapsed into a single | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
module.exports = function eventData(out, pt) { | ||
out.location = pt.location; | ||
out.z = pt.z; | ||
|
||
return out; | ||
}; |
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,68 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
var Axes = require('../../plots/cartesian/axes'); | ||
var attributes = require('./attributes'); | ||
|
||
module.exports = function hoverPoints(pointData) { | ||
var cd = pointData.cd; | ||
var trace = cd[0].trace; | ||
var geo = pointData.subplot; | ||
|
||
// set on choropleth paths 'mouseover' | ||
var pt = geo.choroplethHoverPt; | ||
|
||
if(!pt) return; | ||
|
||
var centroid = geo.projection(pt.properties.ct); | ||
|
||
pointData.x0 = pointData.x1 = centroid[0]; | ||
pointData.y0 = pointData.y1 = centroid[1]; | ||
|
||
pointData.index = pt.index; | ||
pointData.location = pt.id; | ||
pointData.z = pt.z; | ||
|
||
makeHoverInfo(pointData, trace, pt, geo.mockAxis); | ||
|
||
return [pointData]; | ||
}; | ||
|
||
function makeHoverInfo(pointData, trace, pt, axis) { | ||
var hoverinfo = trace.hoverinfo; | ||
|
||
var parts = (hoverinfo === 'all') ? | ||
attributes.hoverinfo.flags : | ||
hoverinfo.split('+'); | ||
|
||
var hasName = (parts.indexOf('name') !== -1), | ||
hasLocation = (parts.indexOf('location') !== -1), | ||
hasZ = (parts.indexOf('z') !== -1), | ||
hasText = (parts.indexOf('text') !== -1), | ||
hasIdAsNameLabel = !hasName && hasLocation; | ||
|
||
var text = []; | ||
|
||
function formatter(val) { | ||
return Axes.tickText(axis, axis.c2l(val), 'hover').text; | ||
} | ||
|
||
if(hasIdAsNameLabel) pointData.nameOverride = pt.id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see ec6c1b1 |
||
else { | ||
if(hasName) pointData.nameOverride = trace.name; | ||
if(hasLocation) text.push(pt.id); | ||
} | ||
|
||
if(hasZ) text.push(formatter(pt.z)); | ||
if(hasText) text.push(pt.tx); | ||
|
||
pointData.extraText = text.join('<br>'); | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An artefact from the first iteration back in July 2015 - where I found that
Fx.lonehover
worked best off a plain<div>
(fast-forward today, this not longer the case).