This repository has been archived by the owner on Nov 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Map tooltips #1921
Merged
Merged
Map tooltips #1921
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c08cbfc
Add preliminary tips
gemfarmer b84d73c
hide tooltip
gemfarmer b283d27
accound for height overlap
gemfarmer 0add13f
eric feedback tweeks, bug picking
gemfarmer 826e7d5
remove href attr
gemfarmer 9d04d42
hound
gemfarmer c8a36a3
restore self
gemfarmer 5127550
hound
gemfarmer ed9a107
color changes
gemfarmer 4b7437d
updated tooltip to tooltip wrapper, now works on ffx
gemfarmer 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
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 |
---|---|---|
|
@@ -21,3 +21,4 @@ | |
@import 'flowchart'; | ||
@import 'tabs'; | ||
@import 'sticky'; | ||
@import 'tooltip'; |
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 @@ | ||
.eiti-tooltip { | ||
background: $white; | ||
border: 2px solid $greenest-land; | ||
max-width: 300px; | ||
padding: $base-padding-lite; | ||
padding-bottom: ($base-padding-lite / 2); | ||
padding-top: 0.23em; // to account for verticality of text | ||
position: absolute; | ||
z-index: 9000; | ||
|
||
p { | ||
@include heading('para-sm'); | ||
|
||
color: $greenest-land; | ||
font-weight: $weight-bold; | ||
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. Properties should be ordered color, font-weight, margin |
||
margin: 0; | ||
} | ||
} |
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,122 @@ | ||
(function(exports) { | ||
|
||
var depixelize = function(value) { | ||
if (value.indexOf('px') > -1) { | ||
return +value.substr(0, value.length - 2); | ||
} else { | ||
return value; | ||
} | ||
}; | ||
|
||
var pixelize = function(value) { | ||
return value + 'px'; | ||
}; | ||
|
||
var hideTooltip = function (tooltip) { | ||
tooltip.attr('aria-hidden', true); | ||
}; | ||
|
||
var attached = function() { | ||
var self = d3.select(this); | ||
var svg = d3.select('svg'); | ||
var svgParent = self; | ||
var titles = self.selectAll('title'); | ||
var tiles = self.selectAll('use'); | ||
|
||
var tooltip, | ||
tooltipText; | ||
|
||
var init = function(initialize) { | ||
tooltip = self.select('.eiti-tooltip'); | ||
|
||
if (tooltip.empty()) { | ||
tooltip = self.append('div') | ||
.classed('eiti-tooltip', true); | ||
} | ||
|
||
tooltip | ||
.attr('aria-hidden', true); | ||
|
||
tooltipText = tooltip.select('p'); | ||
|
||
if (tooltipText.empty()) { | ||
tooltipText = tooltip.append('p'); | ||
} | ||
|
||
// clear <title> text | ||
// if no javascript runs, <title> will serve as the tooltip | ||
// otherwise, clear it so that it doesn't interfere with | ||
// this tooltip | ||
titles.text(''); | ||
}; | ||
|
||
var update = function() { | ||
var event = event || d3.event || window.event; | ||
var elem = event.target || event.srcElement; | ||
|
||
var parentElement = d3.select(elem.parentElement); | ||
var title = parentElement.select('title'); | ||
|
||
init(); | ||
|
||
tooltipText.text(function(){ | ||
return title.attr('desc'); | ||
}); | ||
|
||
tooltip | ||
.attr('aria-hidden', false) | ||
.attr('aria-label', function(){ | ||
return title.attr('alt'); | ||
}) | ||
.style('left', function() { | ||
var tooltipWidth = depixelize(tooltip.style('width')); | ||
var svgWidth = depixelize(svg.style('width')); | ||
|
||
if (svgWidth <= tooltipWidth + event.layerX) { | ||
return pixelize(event.layerX - tooltipWidth); | ||
} else { | ||
return pixelize(event.layerX); | ||
} | ||
}) | ||
.style('top', function() { | ||
var tooltipHeight = depixelize(tooltip.style('height')); | ||
var svgHeight = depixelize(svg.style('height')); | ||
|
||
if (svgHeight <= tooltipHeight + event.layerY) { | ||
return pixelize(event.layerY - tooltipHeight); | ||
} else { | ||
return pixelize(event.layerY); | ||
} | ||
}); | ||
}; | ||
|
||
var hide = function () { | ||
var event = event || window.event; | ||
var elem = event.target || event.srcElement; | ||
if (elem.nodeName === 'svg') { | ||
var tooltip = self.select('.eiti-tooltip'); | ||
hideTooltip(tooltip); | ||
} | ||
}; | ||
|
||
init(this); | ||
|
||
tiles.on('mouseover', update); | ||
svg.on('mouseout', hide); | ||
}; | ||
|
||
var detached = function() { }; | ||
|
||
exports.EITITooltipWrapper = document.registerElement('eiti-tooltip-wrapper', { | ||
extends: 'div', | ||
prototype: Object.create( | ||
HTMLElement.prototype, | ||
{ | ||
attachedCallback: {value: attached}, | ||
detachdCallback: {value: detached} | ||
} | ||
) | ||
}); | ||
|
||
})(this); | ||
|
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.
Properties should be ordered background, border, max-width, padding, padding-bottom, padding-top, position, z-index