Skip to content

Commit

Permalink
prevent charts from making their own tooltip if another tooltip from …
Browse files Browse the repository at this point in the history
…a different chart already exists in the dom. This is particularly useful for React-like frameworks that like to tell the chart to re-render as it prevents them from creating a new tooltip each time
  • Loading branch information
jcarver989 committed Feb 8, 2017
1 parent 9e14233 commit aa1a84d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions dist/suave-charts.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions src/coffeescript/tooltip.coffee
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
class Tooltip
constructor: (doc) ->
@cssClass = "suave-tooltip"
@tip = d3.select(doc.createElement('div'))
node = doc.querySelector("." + @cssClass) || doc.createElement('div')
@tip = d3.select(node)
@tip.attr("class", @cssClass)
doc.body.appendChild(@tip.node())

html: (content) =>
html: (content) =>
@tip.html(content)

show: (node) =>
offset = @offset(node)
offset = @offset(node)
@tip.attr("class", "#{@cssClass} show")
@tip.style({
"position" : "absolute",
Expand All @@ -35,6 +36,6 @@ class Tooltip
scrollY = window.scrollY

{ top: nodeCoords.top - (tipHeight + 10) + window.scrollY, left: nodeCenter - (tipWidth / 2) + window.scrollX }


module.exports = Tooltip

0 comments on commit aa1a84d

Please sign in to comment.