Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. var tooltip = d3.select("body")
  2. .append("div")
  3. .style("position", "absolute")
  4. .style("z-index", "10")
  5. .style("visibility", "hidden")
  6. .style("background", "white")
  7. .text("a simple tooltip");
  8.  
  9.  
  10. var svg = d3.select('body').append('svg')
  11. .attr('height',h)
  12. .attr('width',w)
  13.  
  14.  
  15. var circles = svg.selectAll('circle')
  16. .data(data.nodes)
  17. .enter()
  18. .append('circle')
  19. .attr('cx', function (d) { return d.x })
  20. .attr('cy', function (d) { return d.y })
  21. .attr('r', function (d) { return d.amount/50 })
  22. .attr('fill', function (d) { return "blue" })
  23. .attr('stroke','yellow')
  24. .attr('stroke-width',0)
  25. .on('mouseover',function() {
  26. d3.select(this)
  27. .transition()
  28. .duration(1000)
  29. .attr('stroke-width',5)
  30. .attr('opacity',1)
  31. svg.selectAll('circle')
  32. .attr('opacity',0);
  33. svg.selectAll('line')
  34. .attr('opacity',0)
  35. })
  36.  
  37. .on('mouseout',function () {
  38. d3.select(this)
  39. .transition()
  40. .duration(1000)
  41. .attr('stroke-width',0)
  42. svg.selectAll("circle") .attr("opacity", 1)
  43. svg.selectAll('line')
  44. .attr('opacity',1)
  45. })
  46.  
  47.  
  48.  
  49. d3.select("body")
  50. .selectAll('div')
  51. .on("mouseover", function(d){tooltip.text(d); return tooltip.style("visibility", "visible");})
  52. .on("mouseout", function(){return tooltip.style("visibility", "hidden");})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement