Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. var treeCreator = function(){};
  2.  
  3.  
  4. treeCreator.prototype.callbacktest = function(svgContainer){
  5. alert('the element has been dropped');
  6. };
  7.  
  8. treeCreator.prototype.createTreeNode = function(theSVG){
  9. $('#tobeDropped').remove();
  10. theSVG.append("circle")
  11. .style("stroke","green")
  12. .style("fill","white")
  13. .attr("r",40)
  14. .attr("cx", 100)
  15. .attr("cy", 100)
  16. .on("mouseover", function () {
  17. d3.select(this).style("fill", "aliceblue");
  18. })
  19. .on("mouseout", function () {
  20. d3.select(this).style("fill", "red");
  21. });
  22. };
  23.  
  24. $(document).ready(function(){
  25.  
  26. $('#tobeDropped').draggable({containment:'#mainContainer'});
  27.  
  28. var theSVG = d3.select('#dropInSVG')
  29. .append("svg")
  30. .attr("width",200)
  31. .attr("height",200);
  32.  
  33. var positionLabel = theSVG.append("text")
  34. .attr("x", 10)
  35. .attr("y", 30).text("begin log");
  36. theSVG.on("mousemove", function () {
  37. var position = d3.mouse(this);
  38. positionLabel.text(position);
  39. });
  40.  
  41. var tc = new treeCreator();
  42.  
  43. $('#dropInSVG').droppable({
  44. drop: function(){
  45. tc.createTreeNode(theSVG);
  46. }
  47. });
  48.  
  49. });
  50.  
  51. function updatePosition() {
  52. var position = d3.mouse(theSVG.node());
  53. positionLabel.text(position);
  54. }
  55.  
  56. var dragging = false;
  57.  
  58. $('#tobeDropped').draggable({
  59. containment: '#mainContainer',
  60. start: function() { dragging = true; },
  61. stop: function() { dragging = false; },
  62. drag: updatePosition
  63. });
  64.  
  65. theSVG.on("mousemove", function () {
  66. if (dragging) return;
  67. updatePosition();
  68. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement