Guest User

Untitled

a guest
Oct 2nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. let seq = svg.append("g")
  2. // .attr("class", "seq")
  3. .attr("transform", "translate(" + margin.left + "," + margin.top + ")")
  4. .attr("clip-path", "url(#clip)")
  5. .style("clip-path", "url(#clip)")
  6.  
  7. seq.append("clipPath")
  8. .attr("id", "clip")
  9. .append("rect")
  10. .attr("x", -80)
  11. .attr("width", width)
  12. .attr("height", height);
  13.  
  14. let mainChart = seq.append("g")
  15. .attr("class", "mainchart")
  16. .attr("transform", "translate(" + -80 + "," + -10 + ")")
  17.  
  18. //draw a x-axis with domain below
  19. svg.append("g")
  20. .attr("class", "x axis")
  21. .attr("transform", "translate(0," + (height) + ")")
  22. .call(xAxis.tickFormat(axisTimeFormat))
  23. svg.append("g")
  24. .attr("class", "y axis")
  25. .call(yAxis.ticks(7).tickFormat(d3.format("s")));
  26.  
  27. seq = mainChart.selectAll(".bar.stack")
  28. .data(this.data)
  29. .enter().append("g")
  30. .attr("class", "bar stack")
  31. .attr("transform", function (d, i) { return "translate(" + x(d.key) + ",0 )"; }.bind(this));
  32. seq.selectAll("rect")
  33. .data(function (d) { return d.row; })
  34. .enter().append("rect")
  35. .attr("class", function (d) {
  36. return chartId + " " + d.name
  37. }.bind(this))
  38. .attr("width", 15)
  39. .attr("y", function (d) { return y(d.y0) - y(d.y1) > 0 ? y(d.y1) : y(d.y0); }.bind(this))
  40. .attr("height", function (d) {
  41. return Math.abs(y(d.y0) - y(d.y1));
  42. }.bind(this))
  43. .style("fill", function (d) { return color(d.name); }.bind(this))
  44.  
  45. //draw a x-axis across 0th value
  46. mainChart.selectAll('line.matched_peak')
  47. .data(this.data)
  48. .enter()
  49. .append("line")
  50. .attr("class", "matched_peak")
  51. .attr("y1", y(-5))
  52. .attr("y2", y(-5))
  53. .attr("x2", width)
  54. .attr("stroke", "black");
  55.  
  56. mainChart.call(zoom);
  57.  
  58. var zoom = d3.behavior.zoom().y(subYScale).scaleExtent([1, 10])
  59. .on("zoom",
  60. function () {
  61. d3.event['sourceEvent'].preventDefault();
  62. var t = d3.event['translate'];
  63. var s = d3.event['scale'];
  64.  
  65. svg.select(".x.axis").call(xAxis.tickFormat(axisTimeFormat).ticks(10));
  66. mainChart.attr("transform", "translate(" + t[0] + ",-10)scale(" + s + ",1)");
  67.  
  68. seq.selectAll("rect")
  69. .data(function (d) { return d.row; })
  70. .enter().append("rect")
  71. .attr("class", function (d) {
  72. return chartId + " " + d.name
  73. }.bind(this))
  74. .attr("width", 20)
  75. .attr("y", function (d) { return y(d.y0) - y(d.y1) > 0 ? y(d.y1) : y(d.y0); }.bind(this))
  76. .attr("height", function (d) {
  77. return Math.abs(y(d.y0) - y(d.y1));
  78. //Math.abs(y(d.y0) - y(d.y1)) < 10 && Math.abs(y(d.y0) - y(d.y1)) !=0 ? 20 : Math.abs(y(d.y0) - y(d.y1));
  79. }.bind(this))
  80. .style("fill", function (d) { return color(d.name); }.bind(this))
  81.  
  82. zoom.scale(s);
  83. }
  84.  
  85. chart.selectAll('g .stack rect,g .legend,.text-tooltip').call(tip)
  86. .on('mouseover', function (d) {
  87. if (typeof d === 'object') {
  88. d3.select(this).style("opacity", 0.3)
  89. } else {
  90. svg.selectAll("." + chartId).style("opacity", 0.3);
  91. svg.selectAll("." + d).style("opacity", 1);
  92. }
  93. tip.show(d);
  94. })
Add Comment
Please, Sign In to add comment