Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1.  
  2.  
  3. var w = 1000,
  4. h = 1000;
  5. var M = 50;
  6. var vis = d3.select("body").append("svg")
  7. .attr("width", w)
  8. .attr("height", h);
  9.  
  10. var lineFunction = d3.svg.line()
  11. .x(function(d) { return d.x; })
  12. .y(function(d) { return d.y; })
  13. .interpolate("basis");
  14. //Example usage function
  15. var d = draw_curve(100, 0 , 400, 200, 100);
  16.  
  17. var lineGraph = vis.append("path")
  18. .attr("d", d)
  19. .attr("stroke", "red")
  20. .attr("stroke-width", 10)
  21. .attr("fill", "none");
  22.  
  23. console.log(d);
  24.  
  25.  
  26. /**
  27. * @params x1, y1, x2, y2 - coordinates
  28. * @return attribute D for an SVG PATH
  29. */
  30. function draw_curve(Ax, Ay, Bx, By, M) {
  31. var theta = Math.atan((By - Ay) / (Bx - Ax));
  32. var costheta = ((Bx - Ax) < 0 ? -1 : 1) * Math.cos(theta);
  33. var sintheta = ((Bx - Ax) < 0 ? -1 : 1) * Math.sin(theta);
  34. var c = M * sintheta;
  35. var d = M * costheta;
  36. var Kx = (Ax + (Bx - Ax) / 2) - c;
  37. var Ky = (Ay + (By - Ay) / 2) + d;
  38. return ["M" + Ax, Ay, "Q" + Kx, Ky, " " + Bx, By];
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement