ControlFanContainer.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. @nodename@DataModel = new ht.DataModel();
  2. globalVarNameList.push('@nodename@DataModel');
  3. //@nodename@graphPane = new GraphPaneContainer(@nodename@DataModel,@x@,@y@,@width@,@height@,'@backgroundcolor@');
  4. //document.body.appendChild(@nodename@graphPane.getView());
  5. //@nodename@graphPane.getGraphView().setEditable(true);
  6. @nodename@graphPane= new ht.graph.GraphView(@nodename@DataModel);
  7. globalVarNameList.push('@nodename@graphPane');
  8. jQuery.isArray(graphView.graphViewList) && graphView.graphViewList.push(@nodename@graphPane);
  9. @nodename@graphPane.setScrollBarSize(8);
  10. $(@nodename@graphPane.getView()).css({
  11. border: "1px solid @backgroundcolor@",
  12. boxSizing: 'content-box'
  13. });
  14. var @nodename@ = new ht.HtmlNode();
  15. @nodename@.setScalable(false);
  16. @nodename@.s({
  17. '2d.selectable': true,
  18. '2d.movable': false
  19. });
  20. @nodename@.setHtml(@nodename@graphPane);
  21. @nodename@.setPosition({x:@x@*ratio.ratioX,y:@y@*ratio.ratioY});
  22. @nodename@.setWidth(@width@*ratio.ratioX);
  23. @nodename@.setHeight(@height@*ratio.ratioY);
  24. @nodename@.setPadding(0);
  25. dataModel.add(@nodename@);
  26. globalAliasObj['@alias@'] = @nodename@;
  27. @nodename@._allowChildScale = @allowChildScale@;
  28. (function () {
  29. var s = @nodename@.s;
  30. @nodename@.s = function () {
  31. var args = Array.prototype.slice.call(arguments, 0);
  32. var paneView = @nodename@graphPane.getView();
  33. if (args[0] === '2d.visible' && args[1] !== undefined) {
  34. if (args[1] === false) {
  35. paneView.style.display = 'none';
  36. } else {
  37. paneView.style.display = 'block';
  38. }
  39. }
  40. return s.apply(@nodename@, args);
  41. }
  42. })();
  43. var @nodename@timer = setTimeout(function setFanContainer() {
  44. var graphPane = @nodename@graphPane,
  45. hNode = @nodename@,
  46. zoomValue = graphView.getZoom();
  47. function resetZoomAndPosition(zoom) {
  48. graphPane.setZoom(zoom);
  49. graphPane.tx(0);
  50. graphPane.ty(0);
  51. }
  52. function resizeOverEvent (e) {
  53. var blockList = graphPane.blockList;
  54. var bw = blockList[0].getWidth(),
  55. bh = blockList[0].getHeight(),
  56. halfBw = bw * 0.5,
  57. halfBh = bh * 0.5,
  58. verticalInterval = @verticalInterval@;
  59. if (graphPane.ty() !== 0) {
  60. graphPane.ty(0);
  61. }
  62. if (graphPane.tx() !== 0) {
  63. graphPane.tx(0);
  64. }
  65. function reArrange() {
  66. var w = $(graphPane.getView()).width(),
  67. h = $(graphPane.getView()).height();
  68. var block, index, count, hInterval, totalInterval, rowIndex = -1, px, py, ox, oy, fx, fy, fp;
  69. if (blockList.length === 1) {
  70. graphPane.adjustTranslateY = function () {
  71. return 0;
  72. }
  73. graphPane.setScrollBarColor('rgba(122, 122, 122, 0)');
  74. } else {
  75. graphPane.adjustTranslateY = adjustTranslateY;
  76. graphPane.setScrollBarColor('rgba(122, 122, 122, 0.4)');
  77. }
  78. graphPane.totalWidth = w;
  79. count = Math.floor(w / bw) || 1;
  80. totalInterval = w % bw;
  81. totalInterval = totalInterval < 0 ? 0 : totalInterval;
  82. hInterval = Math.floor(totalInterval/count);
  83. for ( var i = 0, len = blockList.length; i < len; i++) {
  84. block = blockList[i];
  85. index = i % count;
  86. if (index === 0) {
  87. rowIndex++;
  88. }
  89. px = index * (bw + hInterval) + halfBw;
  90. py = rowIndex * (bh + verticalInterval) + halfBh;
  91. fp = block.getPosition();
  92. fx = fp.x;
  93. fy = fp.y;
  94. ox = px - fx;
  95. oy = py - fy;
  96. // 如果容器内有多个图元,则位置加1,防止过于靠近上部我左侧而出现滚动条
  97. if (len > 1) {
  98. ox += 1;
  99. oy += 1;
  100. }
  101. if (hNode._allowChildScale) { // 图元可缩放时按原来位置排列
  102. block.setPosition(px, py);
  103. } else {
  104. block.setPosition(fx + ox, fy + oy); // 图元不可绽放时按计算的位置排列
  105. }
  106. }
  107. }
  108. reArrange();
  109. setTimeout(reArrange, 50);
  110. }
  111. function adjustTranslateY (value) {
  112. var contentSize = graphPane.getContentRect();
  113. var min = graphPane.getHeight() - contentSize.height - 50;
  114. value = value > 0 ? 0 : value;
  115. value = value < min ? min : value;
  116. return value;
  117. }
  118. function adjustTranslateX (value) {
  119. return 0;
  120. }
  121. graphView.mp(function(e) {
  122. if (e.property !== 'zoom') {
  123. return ;
  124. }
  125. resetZoomAndPosition(e.newValue);
  126. })
  127. graphPane.getView().addEventListener('mouseover', function (e) {
  128. e.preventDefault();
  129. e.stopPropagation();
  130. graphView.setInteractors(null);
  131. });
  132. graphPane.getView().addEventListener('mouseleave', function (e) {
  133. e.preventDefault();
  134. e.stopPropagation();
  135. graphView.setEditable(false);
  136. })
  137. graphPane.setZoom(zoomValue);
  138. resetZoomAndPosition(zoomValue);
  139. //graphPane.setAutoHideScrollBar(false);
  140. graphPane.setAutoHideScrollBar(true);
  141. graphPane.setScrollBarSize(10);
  142. graphPane.setScrollBarColor('rgba(122, 122, 122, 0.4)');
  143. graphPane.setInteractors(null);
  144. graphPane.setInteractors([
  145. new ht.graph.ScrollBarInteractor(graphPane),
  146. new ht.graph.DefaultInteractor(graphPane)
  147. ]);
  148. graphPane.adjustTranslateY = adjustTranslateY;
  149. graphPane.adjustTranslateX = adjustTranslateX;
  150. graphPane.handleScroll = function(data) {
  151. var t = graphPane.ty() - data.deltaY;
  152. var contentSize = graphPane.getContentRect();
  153. var min = contentSize.height - graphPane.getHeight() + 50;
  154. if (min <= 50)
  155. return ;
  156. graphPane.setTranslate(0, t, true);
  157. }
  158. graphPane.setPannable(false);
  159. graphPane.setMovableFunc(function(data){return false});
  160. resizeOverEvent();
  161. $window.off('resizeOver', resizeOverEvent).on('resizeOver', resizeOverEvent);
  162. clearTimeout(@nodename@timer);
  163. }, 80);