loadTest.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ;(function() {
  2. var endpoints = {};
  3. window.jsPlumbDemo = {
  4. anchors:[ "TopCenter", "BottomCenter" ],
  5. elements:10,
  6. spacing:400,
  7. endpoint:{
  8. endpoint: [ "Dot", { radius:15 } ],
  9. paintStyle:{ fillStyle:"#456", outlineColor:"black", outlineWidth:1 },
  10. connectorHoverStyle:{strokeStyle:"#943"},
  11. isSource:true,
  12. isTarget:true,
  13. maxConnections:-1
  14. },
  15. init : function() {
  16. // for bulk drawing operations this is recommended.
  17. jsPlumb.setSuspendDrawing(true);
  18. var st = (new Date()).getTime(),
  19. ww = $(window).width(),
  20. x = 0, y = 0;
  21. for (var i = 0; i < jsPlumbDemo.elements; i++) {
  22. var div = document.createElement("div");
  23. div.style.left = x + "px";
  24. div.style.top = y + "px";
  25. div.style.zIndex = 100;
  26. div.className = "jspLoad";
  27. div.setAttribute("id", "div-" + i);
  28. x += jsPlumbDemo.spacing;
  29. if (x > ww) {
  30. x = 0;
  31. y += jsPlumbDemo.spacing;
  32. }
  33. div.style.backgroundColor = "#123";
  34. document.body.appendChild(div);
  35. var _e = [];
  36. for (var j = 0; j < jsPlumbDemo.anchors.length; j++) {
  37. _e.push(jsPlumb.addEndpoint( div, { anchor:jsPlumbDemo.anchors[j] }, jsPlumbDemo.endpoint ));
  38. }
  39. endpoints["div-" + i] = _e;
  40. }
  41. var connCount = 0;
  42. for (var i = 0; i < jsPlumbDemo.elements; i++) {
  43. for (var j = 0; j < jsPlumbDemo.elements; j++) {
  44. if (i != j) {
  45. var ep1 = endpoints["div-" + i],
  46. ep2 = endpoints["div-" + j];
  47. for (var k = 0; k < ep1.length; k++) {
  48. for (var l = 0; l < ep2.length; l++) {
  49. jsPlumb.connect({source:ep1[k], target:ep2[l]});
  50. connCount ++;
  51. }
  52. }
  53. }
  54. }
  55. }
  56. var t = (new Date()).getTime();
  57. jsPlumb.draggable($(".jspLoad"));
  58. var st2 = (new Date()).getTime();
  59. // instruct jsplumb to unsuspend drawing, and to do a repaint.
  60. jsPlumb.setSuspendDrawing(false, true);
  61. var t2 = (new Date()).getTime();
  62. $("#result").html("created " + connCount + " connections in " + (t-st) + " milliseconds<br/>repainted in " + (t2-st2) + " milliseconds");
  63. },
  64. reset : function() {
  65. $(".jspLoad").remove();
  66. }
  67. };
  68. })();