common.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - big data common</TITLE>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <link rel="stylesheet" href="../../../css/demo.css" type="text/css">
  7. <link rel="stylesheet" href="../../../css/zTreeStyle/zTreeStyle.css" type="text/css">
  8. <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
  9. <script type="text/javascript" src="../../../js/jquery.ztree.core-3.5.js"></script>
  10. <script type="text/javascript" src="../../../js/jquery.ztree.excheck-3.5.js"></script>
  11. <script type="text/javascript" src="../../../js/jquery.ztree.exedit-3.5.js"></script>
  12. <SCRIPT type="text/javascript">
  13. <!--
  14. var setting = {
  15. check: {
  16. enable: true
  17. },
  18. data: {
  19. simpleData: {
  20. enable: true
  21. }
  22. },
  23. callback: {
  24. onNodeCreated: onNodeCreated
  25. }
  26. };
  27. var dataMaker = function(count) {
  28. var nodes = [], pId = -1,
  29. min = 10, max = 90, level = 0, curLevel = [], prevLevel = [], levelCount,
  30. i = 0,j,k,l,m;
  31. while (i<count) {
  32. if (level == 0) {
  33. pId = -1;
  34. levelCount = Math.round(Math.random() * max) + min;
  35. for (j=0; j<levelCount && i<count; j++, i++) {
  36. var n = {id:i, pId:pId, name:"Big-" +i};
  37. nodes.push(n);
  38. curLevel.push(n);
  39. }
  40. } else {
  41. for (l=0, m=prevLevel.length; l<m && i<count; l++) {
  42. pId = prevLevel[l].id;
  43. levelCount = Math.round(Math.random() * max) + min;
  44. for (j=0; j<levelCount && i<count; j++, i++) {
  45. var n = {id:i, pId:pId, name:"Big-" +i};
  46. nodes.push(n);
  47. curLevel.push(n);
  48. }
  49. }
  50. }
  51. prevLevel = curLevel;
  52. curLevel = [];
  53. level++;
  54. }
  55. return nodes;
  56. }
  57. var ruler = {
  58. doc: null,
  59. ruler: null,
  60. cursor: null,
  61. minCount: 5000,
  62. count: 5000,
  63. stepCount:500,
  64. minWidth: 30,
  65. maxWidth: 215,
  66. init: function() {
  67. ruler.doc = $(document);
  68. ruler.ruler = $("#ruler");
  69. ruler.cursor = $("#cursor");
  70. if (ruler.ruler) {
  71. ruler.ruler.bind("mousedown", ruler.onMouseDown);
  72. }
  73. },
  74. onMouseDown: function(e) {
  75. ruler.drawRuler(e, true);
  76. ruler.doc.bind("mousemove", ruler.onMouseMove);
  77. ruler.doc.bind("mouseup", ruler.onMouseUp);
  78. ruler.doc.bind("selectstart", ruler.onSelect);
  79. $("body").css("cursor", "pointer");
  80. },
  81. onMouseMove: function(e) {
  82. ruler.drawRuler(e);
  83. return false;
  84. },
  85. onMouseUp: function(e) {
  86. $("body").css("cursor", "auto");
  87. ruler.doc.unbind("mousemove", ruler.onMouseMove);
  88. ruler.doc.unbind("mouseup", ruler.onMouseUp);
  89. ruler.doc.unbind("selectstart", ruler.onSelect);
  90. ruler.drawRuler(e);
  91. },
  92. onSelect: function (e) {
  93. return false;
  94. },
  95. getCount: function(end) {
  96. var start = ruler.ruler.offset().left+1;
  97. var c = Math.max((end - start), ruler.minWidth);
  98. c = Math.min(c, ruler.maxWidth);
  99. return {width:c, count:(c - ruler.minWidth)*ruler.stepCount + ruler.minCount};
  100. },
  101. drawRuler: function(e, animate) {
  102. var c = ruler.getCount(e.clientX);
  103. ruler.cursor.stop();
  104. if ($.browser.msie || !animate) {
  105. ruler.cursor.css({width:c.width});
  106. } else {
  107. ruler.cursor.animate({width:c.width}, {duration: "fast",easing: "swing", complete:null});
  108. }
  109. ruler.count = c.count;
  110. ruler.cursor.text(c.count);
  111. }
  112. }
  113. var showNodeCount = 0;
  114. function onNodeCreated(event, treeId, treeNode) {
  115. showNodeCount++;
  116. }
  117. function createTree () {
  118. var zNodes = dataMaker(ruler.count);
  119. showNodeCount = 0;
  120. $("#treeDemo").empty();
  121. setting.check.enable = $("#showChk").attr("checked");
  122. var time1 = new Date();
  123. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  124. var time2 = new Date();
  125. alert(" " + zNodes.length + " nodes are initialized, " + showNodeCount + " nodes generate the DOM object."
  126. + "\n\n Initialization zTree total time: " + (time2.getTime() - time1.getTime()) + " ms");
  127. }
  128. $(document).ready(function(){
  129. ruler.init("ruler");
  130. $("#createTree").bind("click", createTree);
  131. });
  132. //-->
  133. </SCRIPT>
  134. </HEAD>
  135. <BODY>
  136. <h1>One-time Large Data Loading</h1>
  137. <h6>[ File Path: bigdata/common.html ]</h6>
  138. <div class="content_wrap">
  139. <div class="zTreeDemoBackground left">
  140. <ul>
  141. <li><span>Adjust the total number of nodes to the test load speed: </span>
  142. <div id="ruler" class="ruler" title="can drag to adjust the number of nodes">
  143. <div id="cursor" class="cursor">5000</div>
  144. </div>
  145. <div style="width:220px; text-align: center;">
  146. <span>checkbox</span><input type="checkbox" id="showChk" title="whether to display checkbox" class="checkbox first" />&nbsp;&nbsp;&nbsp;&nbsp;
  147. [ <a id="createTree" href="#" title="Initialize zTree" onclick="return false;">Initialize zTree</a> ]
  148. </div>
  149. </li>
  150. </ul>
  151. <ul id="treeDemo" class="ztree"></ul>
  152. </div>
  153. <div class="right">
  154. <ul class="info">
  155. <li class="title"><h2>1, Explanation of large data load</h2>
  156. <ul class="list">
  157. <li>1) zTree v3.x optimized for one-time large data loading capacity, using a lazy loading technique, which does not expand the node does not create child nodes of the DOM.</li>
  158. <li class="highlight_red">2) If a maximum of 100 nodes each, but a total number of several thousand or even tens of thousands of nodes, and the parent node is collapsed by default to optimize the most obvious effect, very fast.</li>
  159. <li class="highlight_red">3) For the next level there are thousands of sub-node case, the optimization of lazy loading is invalid, proposal to consider asynchronous page loading.</li>
  160. <li class="highlight_red">4) if you set the data to all the parent nodes are expanded, the optimization of lazy loading is invalid, proposal to not expand all parent node when you initialize zTree.</li>
  161. <li>5) set the display checkbox / radio will affect some of the performance.</li>
  162. <li>6) DOM generated using addDiyDom function will affect the speed, the number of nodes determines the number of impact situations.</li>
  163. <li>7) Using 'onNodeCreated' callback function to manipulate nodes object will affect the speed, the degree of influence determined by the number of nodes.</li>
  164. </ul>
  165. </li>
  166. <li class="title"><h2>2, Explanation of setting</h2>
  167. <ul class="list">
  168. <li>No special configuration.</li>
  169. </ul>
  170. </li>
  171. <li class="title"><h2>3, Explanation of treeNode</h2>
  172. <ul class="list">
  173. <li>No special requirements on the node data, the user can add custom attributes.</li>
  174. </ul>
  175. </li>
  176. </ul>
  177. </div>
  178. </div>
  179. </BODY>
  180. </HTML>