黄箭头.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. ht.lib = ht.lib || {};
  2. if (!ht.lib['黄箭头']) {
  3. ht.lib['黄箭头'] = function (x, y, width, height, angle, localVarObj, localDynamicVar, nodename) {
  4. _ratio = GD.getRatioWithRotation(0, ratio);
  5. ht.lib['黄箭头'].superClass.constructor.apply(this);
  6. this.localVarObj = localVarObj;
  7. this.localDynamicVar = localDynamicVar;
  8. this.childNodes = [];
  9. this._styleObject = {};
  10. this._originWidth = 9.999939*_ratio.ratioX;
  11. this._originHeight = 36.61928*_ratio.ratioY;
  12. this._baseClass = "ht.lib.黄箭头";
  13. this._background = new ht.Node();
  14. this._background.setWidth(this._originWidth);
  15. this._background.setHeight(this._originHeight);
  16. this._background.setPosition(this._originWidth/2, this._originHeight/2);
  17. this._background.setImage({
  18. width: width,
  19. height: height,
  20. clip: true,
  21. comps: [
  22. {
  23. type: 'rect',
  24. background: 'rgba(0,255,0,0)',
  25. rect: [0,0,width, height]
  26. }
  27. ]
  28. });
  29. this._background.__parentLib = nodename;
  30. this._background.isLibBackground = true;
  31. this.childNodes.push(this._background);
  32. dataModel.add(this._background);
  33. /*@PageBackgroundInit@*/
  34. /*@PageBeforeInit@*/
  35. var Lib_黄箭头Node0_0points=[5, 8,5, 36],
  36. Lib_黄箭头Node0_0rect=ht.Default.unionPoint([{x:5,y:8},{x:5,y:36}]),
  37. Lib_黄箭头Node0_0compspts=[];
  38. _ratio = GD.getRatioWithRotation(0, ratio);
  39. var _startratio = GD.getRatioWithRotation(4.71238898038469, ratio),
  40. _endratio = GD.getRatioWithRotation(7.85398163397448, ratio);
  41. for(var i=0;i<Lib_黄箭头Node0_0points.length;i++){
  42. if(i%2==0){
  43. Lib_黄箭头Node0_0compspts.push(Lib_黄箭头Node0_0points[i]-Lib_黄箭头Node0_0rect.x);
  44. }else{
  45. Lib_黄箭头Node0_0compspts.push(Lib_黄箭头Node0_0points[i]-Lib_黄箭头Node0_0rect.y);
  46. }
  47. }
  48. var Lib_黄箭头Node0_0ptslength=Lib_黄箭头Node0_0compspts.length;
  49. if (Lib_黄箭头Node0_0rect.height === 0) {
  50. Lib_黄箭头Node0_0compspts[0] -= 0;
  51. Lib_黄箭头Node0_0compspts[Lib_黄箭头Node0_0ptslength-2] += 0;
  52. } else if (Lib_黄箭头Node0_0rect.width === 0){
  53. Lib_黄箭头Node0_0compspts[1] -= 0;
  54. Lib_黄箭头Node0_0compspts[Lib_黄箭头Node0_0ptslength-1] += 0;
  55. } else {
  56. Lib_黄箭头Node0_0compspts[0] -= 0;
  57. Lib_黄箭头Node0_0compspts[1] -= 0;
  58. Lib_黄箭头Node0_0compspts[Lib_黄箭头Node0_0ptslength-2] += 0;
  59. Lib_黄箭头Node0_0compspts[Lib_黄箭头Node0_0ptslength-1] += 0;
  60. }
  61. Lib_黄箭头Node0_0 = new ht.Node();
  62. Lib_黄箭头Node0_0.borderWidth = 2;
  63. Lib_黄箭头Node0_0rect.width = Lib_黄箭头Node0_0rect.width === 0 ? 0.0001 : Lib_黄箭头Node0_0rect.width;
  64. Lib_黄箭头Node0_0rect.height = Lib_黄箭头Node0_0rect.height === 0 ? 0.0001 : Lib_黄箭头Node0_0rect.height;
  65. var Lib_黄箭头Node0_0endCompspts = [Lib_黄箭头Node0_0compspts[Lib_黄箭头Node0_0ptslength-2],Lib_黄箭头Node0_0compspts[Lib_黄箭头Node0_0ptslength-1],0,0];
  66. var Lib_黄箭头Node0_0startCompspts = [Lib_黄箭头Node0_0compspts[0],Lib_黄箭头Node0_0compspts[1],0,0];
  67. Lib_黄箭头Node0_0.setImage(GD.getPolyLineJSON());
  68. Lib_黄箭头Node0_0.setPosition(Lib_黄箭头Node0_0rect.x+Lib_黄箭头Node0_0rect.width/2,Lib_黄箭头Node0_0rect.y+Lib_黄箭头Node0_0rect.height/2);
  69. Lib_黄箭头Node0_0.setSize(Lib_黄箭头Node0_0rect.width,Lib_黄箭头Node0_0rect.height);
  70. Lib_黄箭头Node0_0.setStyle("opacity",1);
  71. Lib_黄箭头Node0_0.s({'pixelPerfect':true});
  72. Lib_黄箭头Node0_0borderwidth=2;
  73. Lib_黄箭头Node0_0.setRotation(0);
  74. dataModel.add(Lib_黄箭头Node0_0);
  75. Lib_黄箭头Node0_0.a('node.points',Lib_黄箭头Node0_0compspts);
  76. Lib_黄箭头Node0_0.a('node.segments',[1,2]);
  77. Lib_黄箭头Node0_0.a('node.color','rgba(255,128,0,1)');
  78. Lib_黄箭头Node0_0.a('node.borderPattern',getDashStyle("@borderPattern@"));
  79. Lib_黄箭头Node0_0.a('node.borderColor','rgba(255,128,0,1)');
  80. Lib_黄箭头Node0_0.a('node.background','rgba(255,128,0,1)');
  81. Lib_黄箭头Node0_0.a('node.gradient','');
  82. Lib_黄箭头Node0_0.a('node.gradientcolor','rgba(255,128,0,1)');
  83. Lib_黄箭头Node0_0.a('node.endCompspts',Lib_黄箭头Node0_0endCompspts);
  84. Lib_黄箭头Node0_0.a('node.startCompspts',Lib_黄箭头Node0_0startCompspts);
  85. (function (node, img, compspts, endCompspts, startCompspts) {
  86. var position = node.getPosition(),
  87. w = node.getWidth()*_ratio.ratioX,
  88. h = node.getHeight()*_ratio.ratioY;
  89. function resetPoints(rx, ry) {
  90. for (var i = 0, len = compspts.length; i < len; i++) {
  91. if (i%2 === 0) {
  92. compspts[i]*=rx;
  93. } else {
  94. compspts[i]*=ry;
  95. }
  96. }
  97. endCompspts[0] = compspts[compspts.length-2];
  98. endCompspts[1] = compspts[compspts.length-1];
  99. endCompspts[2] *= rx;
  100. endCompspts[3] *= ry;
  101. node.a('node.offsetEndY', -(endCompspts[3]*0.5));
  102. node.a('node.offsetEndX', -(endCompspts[2]*0.5));
  103. startCompspts[0] = compspts[0];
  104. startCompspts[1] = compspts[1];
  105. startCompspts[2] *= rx;
  106. startCompspts[3] *= ry;
  107. node.a('node.offsetStartY', -(startCompspts[3]*0.5));
  108. node.a('node.offsetStartX', -(startCompspts[2]*0.5));
  109. node.a('node.endRotation', GD.calcRotationByStartAndEnd(compspts[i-4], compspts[i-3], compspts[i-2], compspts[i-1]));
  110. node.a('node.startRotation', GD.calcRotationByStartAndEnd(compspts[0], compspts[1], compspts[2], compspts[3]) + Math.PI);
  111. }
  112. node.setSize(w, h);
  113. node.setPosition(position.x * ratio.ratioX, position.y * ratio.ratioY);
  114. node.a('node.width', w);
  115. node.a('node.height', h);
  116. resetPoints(_ratio.ratioX, _ratio.ratioY);
  117. node.borderWidth = 2;
  118. node.a('node.borderwidth',node.borderWidth);
  119. node._nodename = 'Lib_黄箭头Node0_0';
  120. node._nodeType = 'line';
  121. zoomNodeList.push({
  122. node: node,
  123. attr: 'node.borderwidth'
  124. });
  125. var setWidth = node.setWidth,
  126. setHeight = node.setHeight,
  127. timer, rx = 1, ry = 1;
  128. node.setWidth = function (width) {
  129. var _width = this.getWidth();
  130. rx = width / _width;
  131. node.a('node.width', width);
  132. setWidth.apply(this, arguments);
  133. resetPoints(rx, 1);
  134. }
  135. node.setHeight = function (height) {
  136. var _height = this.getHeight();
  137. ry = height / _height;
  138. node.a('node.height', height);
  139. setHeight.apply(this, arguments);
  140. resetPoints(1, ry);
  141. }
  142. })(Lib_黄箭头Node0_0, Lib_黄箭头Node0_0.getImage(), Lib_黄箭头Node0_0compspts, Lib_黄箭头Node0_0endCompspts, Lib_黄箭头Node0_0startCompspts);
  143. var Lib_黄箭头Node0_1rect=ht.Default.unionPoint([{x: 0, y: 0},{x: 0, y: 0},{x: 9, y: 0},{x: 5, y: 10}]),
  144. Lib_黄箭头Node0_1points=[0,0,0,0,9,0,5,10],
  145. Lib_黄箭头Node0_1compsPoints=[],
  146. Lib_黄箭头Node0_1SetPoints = [{x: 0, y: 0},{x: 0, y: 0},{x: 9, y: 0},{x: 5, y: 10}],
  147. Lib_黄箭头Node0_1setSegments = [1,2,2,2];
  148. _ratio = GD.getRatioWithRotation(3.141593, ratio);
  149. for(var i=0;i<Lib_黄箭头Node0_1points.length;i++){
  150. if(i%2==0){
  151. Lib_黄箭头Node0_1compsPoints.push(Lib_黄箭头Node0_1points[i]-Lib_黄箭头Node0_1rect.x);
  152. }else{
  153. Lib_黄箭头Node0_1compsPoints.push(Lib_黄箭头Node0_1points[i]-Lib_黄箭头Node0_1rect.y);
  154. }
  155. }
  156. var Lib_黄箭头Node0_1 = new ht.Node();
  157. Lib_黄箭头Node0_1.setImage(GD.getPolyGonJSON());
  158. Lib_黄箭头Node0_1.setPosition(Lib_黄箭头Node0_1rect.x + Lib_黄箭头Node0_1rect.width/2, Lib_黄箭头Node0_1rect.y + Lib_黄箭头Node0_1rect.height/2);
  159. Lib_黄箭头Node0_1.setSize(Lib_黄箭头Node0_1rect.width, Lib_黄箭头Node0_1rect.height);
  160. Lib_黄箭头Node0_1.setRotation(3.141593);
  161. Lib_黄箭头Node0_1.borderWidth=0;
  162. Lib_黄箭头Node0_1.borderFillwidth=0*2;
  163. Lib_黄箭头Node0_1.s({'pixelPerfect':true});
  164. dataModel.add(Lib_黄箭头Node0_1);
  165. // Lib_黄箭头Node0_1.a('node.width', Lib_黄箭头Node0_1rect.width*_ratio.ratioX);
  166. // Lib_黄箭头Node0_1.a('node.height', Lib_黄箭头Node0_1rect.height*_ratio.ratioY);
  167. Lib_黄箭头Node0_1.a('node.clip', function(g,width,height,data) {
  168. var clippoints = Lib_黄箭头Node0_1SetPoints;
  169. if(clippoints.length<=3) return;
  170. if(Lib_黄箭头Node0_1.a('Lib_黄箭头Node0_1.isFill')=="false") return;
  171. var clipcompsPoints=[];
  172. var rect = ht.Default.unionPoint(clippoints);
  173. for(var i=0;i<clippoints.length;i++){
  174. clipcompsPoints.push({x:clippoints[i].x-rect.x,y:clippoints[i].y-rect.y});
  175. }
  176. var clipsegments=Lib_黄箭头Node0_1setSegments;
  177. g.beginPath();
  178. drawPoints(g,clipcompsPoints,clipsegments);
  179. g.clip();
  180. })
  181. Lib_黄箭头Node0_1.a('node.type', 'shape');
  182. Lib_黄箭头Node0_1.a('node.comsPoints', Lib_黄箭头Node0_1compsPoints);
  183. Lib_黄箭头Node0_1.a('node.closePath', true);
  184. Lib_黄箭头Node0_1.a('node.borderwidth', 0);
  185. Lib_黄箭头Node0_1.a('node.color', 'rgba(0,0,0,0)');
  186. Lib_黄箭头Node0_1.a('node.background','rgba(255,128,0,1)');
  187. Lib_黄箭头Node0_1.a('node.closePath', true);
  188. Lib_黄箭头Node0_1.a('node.closePath', true);
  189. Lib_黄箭头Node0_1.a('node.gradient','');
  190. Lib_黄箭头Node0_1.a('node.gradientcolor','rgba(255,128,0,1)');
  191. Lib_黄箭头Node0_1.a('node.isFill','false');
  192. Lib_黄箭头Node0_1.a('node.original',[0,0,0,0]);
  193. Lib_黄箭头Node0_1.a('node.fillrect',[0,0,0,0]);
  194. Lib_黄箭头Node0_1.a('node.fillbackcolor','rgba(255,128,0,1)');
  195. Lib_黄箭头Node0_1.a('node.fillgradient','');
  196. Lib_黄箭头Node0_1.a('node.fillgradientcolor','rgba(255,128,0,1)');
  197. Lib_黄箭头Node0_1.a('node.segments',Lib_黄箭头Node0_1setSegments);
  198. Lib_黄箭头Node0_1.a('node.borderPattern',"");
  199. (function (node, nodecompsPoints, setPoints) {
  200. var w = node.getWidth()*_ratio.ratioX,
  201. h = node.getHeight()*_ratio.ratioY,
  202. img = node.getImage();
  203. function resetPoints(rx, ry) {
  204. for (var i = 0, len = nodecompsPoints.length; i < len; i++) {
  205. if (i%2 === 0) {
  206. nodecompsPoints[i]*=rx;
  207. } else {
  208. nodecompsPoints[i]*=ry;
  209. }
  210. if (setPoints[i]) {
  211. setPoints[i].x *= rx;
  212. setPoints[i].y *= ry;
  213. }
  214. }
  215. }
  216. node.setSize(w, h);
  217. node.a('node.width', w);
  218. node.a('node.height', h);
  219. resetPoints(_ratio.ratioX, _ratio.ratioY);
  220. var position = node.getPosition();
  221. node.setPosition(position.x * ratio.ratioX, position.y * ratio.ratioY);
  222. node._nodename = 'Lib_黄箭头Node0_1';
  223. node._nodeType = 'polygon';
  224. zoomNodeList.push({
  225. node: node,
  226. attr: 'node.borderwidth'
  227. });
  228. // 重载setWidth, setHeight
  229. var setWidth = node.setWidth,
  230. setHeight = node.setHeight,
  231. timer, rx = 1, ry = 1;
  232. node.setWidth = function (width) {
  233. var _width = this.getWidth();
  234. rx = width / _width;
  235. node.a('node.width', width);
  236. setWidth.apply(this, arguments);
  237. resetPoints(rx, 1);
  238. }
  239. node.setHeight = function (height) {
  240. var _height = this.getHeight();
  241. ry = height / _height;
  242. node.a('node.height', height);
  243. setHeight.apply(this, arguments);
  244. resetPoints(1, ry);
  245. }
  246. })(Lib_黄箭头Node0_1, Lib_黄箭头Node0_1compsPoints, Lib_黄箭头Node0_1SetPoints );
  247. /*@GraphList@*/
  248. if(typeof(Lib_黄箭头Node0_1.borderWidth)!="undefined"){setDashStyle(Lib_黄箭头Node0_1,"Lib_黄箭头Node0_1",'NoDash',Lib_黄箭头Node0_1.borderWidth);}
  249. /*@PageInit@*/
  250. var localVarObj = this.localVarObj;
  251. var localDynamicVarObj = this.localDynamicVar();
  252. this['Lib_黄箭头Node0_0'] = Lib_黄箭头Node0_0;
  253. Lib_黄箭头Node0_0.__parentLib = nodename;
  254. Lib_黄箭头Node0_0.__parent = this;
  255. this.childNodes.push(Lib_黄箭头Node0_0);
  256. this['Lib_黄箭头Node0_1'] = Lib_黄箭头Node0_1;
  257. Lib_黄箭头Node0_1.__parentLib = nodename;
  258. Lib_黄箭头Node0_1.__parent = this;
  259. this.childNodes.push(Lib_黄箭头Node0_1);
  260. /*@ControlContextMenu@*/
  261. /*@Declare@*/
  262. this.init(x, y, width, height, angle);
  263. };
  264. ht.Default.def('ht.lib.黄箭头', Object, {
  265. refresh10ms: function () {
  266. var localVarObj = this.localVarObj;
  267. var localDynamicVarObj = this.localDynamicVar();
  268. var Lib_黄箭头Node0_0= this.Lib_黄箭头Node0_0;
  269. var Lib_黄箭头Node0_1= this.Lib_黄箭头Node0_1;
  270. /*@refresh10ms@*/
  271. },
  272. refresh100ms: function () {
  273. var localVarObj = this.localVarObj;
  274. var localDynamicVarObj = this.localDynamicVar();
  275. var Lib_黄箭头Node0_0= this.Lib_黄箭头Node0_0;
  276. var Lib_黄箭头Node0_1= this.Lib_黄箭头Node0_1;
  277. /*@refresh100ms@*/
  278. },
  279. refresh500ms: function () {
  280. var localVarObj = this.localVarObj;
  281. var localDynamicVarObj = this.localDynamicVar();
  282. var Lib_黄箭头Node0_0= this.Lib_黄箭头Node0_0;
  283. var Lib_黄箭头Node0_1= this.Lib_黄箭头Node0_1;
  284. /*@refresh500ms@*/
  285. },
  286. refresh1s: function () {
  287. var Counter1s = arguments[0] || 0;
  288. var localVarObj = this.localVarObj;
  289. var localDynamicVarObj = this.localDynamicVar();
  290. var Lib_黄箭头Node0_0= this.Lib_黄箭头Node0_0;
  291. var Lib_黄箭头Node0_1= this.Lib_黄箭头Node0_1;
  292. /*@refresh1s@*/
  293. },
  294. refresh5s: function () {
  295. var localVarObj = this.localVarObj;
  296. var localDynamicVarObj = this.localDynamicVar();
  297. var Lib_黄箭头Node0_0= this.Lib_黄箭头Node0_0;
  298. var Lib_黄箭头Node0_1= this.Lib_黄箭头Node0_1;
  299. /*@refresh5s@*/
  300. },
  301. /*@PageDynamic@*/
  302. onEvent: function (e, data, type, origin, offset, objMouseOn, ctm) {
  303. var localVarObj = this.localVarObj;
  304. var localDynamicVarObj = this.localDynamicVar();
  305. var Lib_黄箭头Node0_0= this.Lib_黄箭头Node0_0;
  306. var Lib_黄箭头Node0_1= this.Lib_黄箭头Node0_1;
  307. if (type === 'click') {
  308. /*@EvnentClicked@*/
  309. } else if (type === 'mousedown') {
  310. mouseX=e.clientX;
  311. mouseY=e.clientY;
  312. /*@EvnentMouseDown@*/
  313. } else if (type === 'mouseup') {
  314. /*@EvnentMouseUp@*/
  315. } else if (type === 'mousemove') {
  316. var mouseX, mouseY, position, zoom;
  317. position=origin.getLogicalPoint(e);
  318. zoom = graphView.getZoom();
  319. if (origin === graphView) {
  320. mouseX= position.x + origin.tx();
  321. mouseY = position.y + origin.ty();
  322. } else {
  323. offset = offset || {x: 0, y: 0};
  324. mouseX = position.x / zoom + offset.x + origin.tx();
  325. mouseY = position.y / zoom + offset.y + origin.ty();
  326. }
  327. /*@EvnentMouseLeave@*/
  328. /*@EvnentMouseOver@*/
  329. } else if (type === 'keydown') {
  330. /*@EvnentKeyDown@*/
  331. } else if (type === 'contextmenu') {
  332. /*@Declare@*/
  333. /*@SetNodeContextMenu@*/
  334. /*@SetPageContextMenu@*/
  335. }
  336. /*@LibEvent@*/
  337. },
  338. getBaseClass: function () {
  339. return this._baseClass;
  340. },
  341. getWidth: function () {
  342. return this._width;
  343. },
  344. getHeight: function () {
  345. return this._height;
  346. },
  347. getSize: function () {
  348. return {
  349. width: this._width,
  350. height: this._height
  351. }
  352. },
  353. setWidth: function (width) {
  354. if (width === undefined || width === null || width != width) {
  355. return ;
  356. }
  357. var originWidth = this._width;
  358. var ratio = width / originWidth;
  359. var childNodes = this.childNodes, childNode, p, op = this.getPosition(), w, cw, ox, rotation = this.getRotation();
  360. for (var i = 0, len = childNodes.length; i < len; i++) {
  361. childNode = childNodes[i];
  362. p = childNode.getPosition();
  363. cw = childNode.getWidth();
  364. w = cw >=2 ? cw * ratio : cw;
  365. childNode.setWidth(w);
  366. ox = op.x + (p.x - op.x) * ratio;
  367. childNode.setPosition(ox, p.y);
  368. rotation = GD.calcRotation(rotation);
  369. if (rotation === 0 || rotation === Math.PI) {
  370. // 图元未旋转
  371. ox = op.x + (p.x - op.x)*ratio;
  372. childNode.setPosition(ox, p.y);
  373. } else if (rotation === 90 * Math.PI / 180) {
  374. // 图元旋转以后
  375. ox = op.y + (p.y - op.y)*ratio;
  376. childNode.setPosition(p.x, ox);
  377. }
  378. }
  379. this._width = width;
  380. this._originWidth = width;
  381. this._ratioX = ratio;
  382. return this;
  383. },
  384. setHeight: function (height) {
  385. if (height === undefined || height === null || height != height) {
  386. return ;
  387. }
  388. var originHeight = this._height;
  389. var ratio = height / originHeight;
  390. var childNodes = this.childNodes, childNode, p, op = this.getPosition(), h, ch, oy, rotation = this.getRotation();
  391. for (var i = 0, len = childNodes.length; i < len; i++) {
  392. childNode = childNodes[i];
  393. p = childNode.getPosition();
  394. ch = childNode.getHeight();
  395. h = ch >=2 ? ch * ratio : ch;
  396. childNode.setHeight(h);
  397. rotation = GD.calcRotation(rotation);
  398. if (rotation === 0 || rotation === Math.PI) {
  399. // 图元未旋转
  400. oy = op.y + (p.y - op.y)*ratio;
  401. childNode.setPosition(p.x, oy);
  402. } else if (rotation === 90 * Math.PI / 180) {
  403. // 图元旋转以后
  404. oy = op.x + (p.x - op.x)*ratio;
  405. childNode.setPosition(oy, p.y);
  406. }
  407. }
  408. this._height = height;
  409. this._originHeight = height;
  410. this._ratioY = ratio;
  411. return this;
  412. },
  413. setSize: function (size) {
  414. // var args = Array.prototype.slice.call(arguments, 0);
  415. // var height, width;
  416. // if (args.length === 0) {
  417. // return ;
  418. // }else if (args.length === 1) {
  419. // height = args[0].height;
  420. // width = args[0].width;
  421. // } else {
  422. // width = args[0];
  423. // height = args[1];
  424. // }
  425. // var wh = GD.getRatioWithRotation(angle, wid)
  426. // this.setHeight(height);
  427. // this.setWidth(width);
  428. // return this;
  429. var args = Array.prototype.slice.call(arguments, 0);
  430. var height, width;
  431. if (args.length === 0) {
  432. return ;
  433. }else if (args.length === 1) {
  434. height = args[0].height;
  435. width = args[0].width;
  436. angle = 0;
  437. } else if (args.length === 2) {
  438. if (typeof args[0] === 'object') {
  439. width = args[0].width;
  440. height = args[0].height;
  441. angle = args[1] || 0;
  442. } else {
  443. width = args[0];
  444. height = args[1];
  445. angle = 0;
  446. }
  447. } else if (args.length === 3) {
  448. width = args[0];
  449. height = args[1];
  450. angle = args[2] || 0;
  451. }
  452. var wh = GD.getRatioWithRotation(0, width, height);
  453. this.setHeight(wh.ratioY);
  454. this.setWidth(wh.ratioX);
  455. return this;
  456. },
  457. getPosition: function () {
  458. return {
  459. x: this._x,
  460. y: this._y
  461. }
  462. },
  463. setPosition: function () {
  464. var args = Array.prototype.slice.call(arguments, 0), x, y;
  465. if (args.length === 0) {
  466. return this;
  467. } else if (args.length === 1) {
  468. if (typeof args[0] != 'object') {
  469. return this;
  470. }
  471. x = args[0].x;
  472. y = args[0].y;
  473. } else {
  474. x = args[0];
  475. y = args[1];
  476. }
  477. if ((x !== 0 && !x) || (y !== 0 && !y)) {
  478. return this;
  479. }
  480. // var childNodes = this.childNodes, offset, childNode, p;
  481. // for (var i = 0, len = childNodes.length; i < len; i++) {
  482. // childNode = childNodes[i];
  483. // p = childNode.getPosition();
  484. // childNode.setPosition(x - (this._x-p.x)*this._ratioX, y - (this._y-p.y)*this._ratioY);
  485. // }
  486. // this._x = x;
  487. // this._y = y;
  488. // return this;
  489. var childNodes, childNode, background, offset = {}, op, cp;
  490. childNodes = this.childNodes;
  491. background = this._background;
  492. op = background.getPosition();
  493. offset.x = x - op.x;
  494. offset.y = y - op.y;
  495. for (var i = 0, len = childNodes.length; i < len; i++) {
  496. childNode = childNodes[i];
  497. cp = childNode.getPosition();
  498. childNode.setPosition(cp.x + offset.x, cp.y + offset.y);
  499. }
  500. this._x = x;
  501. this._y = y;
  502. this._position = {x: x, y: y};
  503. return this;
  504. },
  505. getStyle: function (key) {
  506. if (!key) {
  507. return undefined;
  508. }
  509. return this._styleObject[key];
  510. },
  511. setStyle: function (key, value, force) {
  512. var childNodes = this.childNodes, childNode;
  513. for (var i = 0, len = childNodes.length; i < len; i++) {
  514. childNode = childNodes[i];
  515. if (key === '2d.visible') {
  516. if (value === graphView.isVisible(childNode)) {
  517. continue;
  518. }
  519. if (!value) {
  520. childNode._savedIsVisible = graphView.isVisible(childNode);
  521. childNode.s({
  522. '2d.visible': false
  523. })
  524. } else {
  525. childNode.s({
  526. '2d.visible': childNode._savedIsVisible
  527. })
  528. }
  529. continue;
  530. }
  531. childNode.s({
  532. key: value
  533. });
  534. }
  535. this._styleObject[key] = value;
  536. return this;
  537. },
  538. calcSize: function () {
  539. var background = this._background;
  540. var position = background.getPosition(),
  541. width = background.getWidth(),
  542. height = background.getHeight();
  543. this._width = width;
  544. this._height = height;
  545. this._x = position.x;
  546. this._y = position.y;
  547. this._position = {
  548. x: this._x,
  549. y: this._y
  550. }
  551. return this;
  552. return this;
  553. },
  554. s: function (styleObj, force) {
  555. var args = Array.prototype.slice.call(arguments, 0);
  556. var styleObj;
  557. if (args.length === 0) {
  558. return this;
  559. } else if (args.length === 1) {
  560. styleObj = args[0];
  561. } else {
  562. this.setStyle(args[0], args[1]);
  563. return this;
  564. }
  565. for (var key in styleObj) {
  566. if (!styleObj.hasOwnProperty(key)) {
  567. continue;
  568. }
  569. this.setStyle(key, styleObj[key], force);
  570. }
  571. return this;
  572. },
  573. init: function (x, y, width, height, angle) {
  574. var that = this;
  575. this.calcSize();
  576. (function (width, height, angle) {
  577. // that.setSize(width, height, angle);
  578. // var wh = GD.getRatioWithRotation(angle, width, height);
  579. // width = wh.ratioX;
  580. // height = wh.ratioY;
  581. var originHeight = that._height;
  582. var originWidth = that._width;
  583. var ratioY = height / originHeight;
  584. var ratioX = width / originWidth;
  585. var childNodes = that.childNodes,
  586. childNode,p, op = that.getPosition(), h, ch, oy, w, cw, ox, name, borderRatio, borderWidth;
  587. for (var i = 0, len = childNodes.length; i < len; i++) {
  588. childNode = childNodes[i];
  589. p = childNode.getPosition();
  590. childNode.originHeight = childNode.originHeight || childNode.getHeight();
  591. ch = childNode.getHeight();
  592. cw = childNode.getWidth();
  593. if (ch > 2) {
  594. h = ch * ratioY;
  595. childNode.setHeight(h);
  596. }
  597. if (cw > 2) {
  598. w = cw * ratioX;
  599. childNode.setWidth(w);
  600. }
  601. borderRatio = (ratioX + ratioY)*0.5;
  602. if (childNode._nodeType === 'line') { // 如果是线,
  603. if (childNode.getWidth() > childNode.getHeight()) {
  604. borderRatio = ratioX;
  605. } else {
  606. borderRatio = ratioY;
  607. }
  608. }
  609. name = childNode._nodename;
  610. // if (childNode.borderWidth && name && ch > 2 && cw > 2) {
  611. // borderWidth = childNode.borderWidth / borderRatio;
  612. // if (borderWidth > ch*0.5 || borderWidth > cw *0.5) {
  613. // // borderWidth = childNode.borderWidth;
  614. // }
  615. // childNode.borderWidth = borderWidth;
  616. // childNode.a(name + '.borderwidth', borderWidth);
  617. // }
  618. }
  619. that._height = height;
  620. that._originHeight = height;
  621. that._ratioY = ratioY;
  622. that._width = width;
  623. that._originWidth = width;
  624. that._ratioX = ratioX;
  625. })(width, height, angle);
  626. that._x = width / 2;
  627. that._y = height / 2;
  628. that._rotation = 0;
  629. // that.setPosition(x, y);
  630. (function (x, y) {
  631. var childNodes = that.childNodes, offset, childNode;
  632. var w2 = that.getWidth() / 2, h2 = that.getHeight()/2;
  633. for (var i = 0, len = childNodes.length; i < len; i++) {
  634. childNode = childNodes[i];
  635. offset = childNode.getPosition();
  636. childNode.setPosition(x + offset.x * that._ratioX - w2, y + offset.y * that._ratioY - h2);
  637. }
  638. that._x = x;
  639. that._y = y;
  640. })(x, y);
  641. // setTimeout(that.addEVent, 1000);
  642. },
  643. setRotation: function (angle) {
  644. var that = this, _angle = that.getRotation();
  645. if (angle!==0 && !angle || angle === _angle) {
  646. return this;
  647. }
  648. var childNodes = this.childNodes, childNode, p = this.getPosition(), px = p.x, py = p.y;
  649. for (var i = 0, len = childNodes.length; i < len; i++) {
  650. childNode = childNodes[i];
  651. var x = childNode.getPosition().x - px;
  652. var y = childNode.getPosition().y - py;
  653. childNode.setPosition(Math.cos(angle-_angle) * x - Math.sin(angle-_angle) * y + px, Math.cos(angle-_angle) * y + Math.sin(angle-_angle) * x + py);
  654. childNode.setRotation(angle);
  655. }
  656. this._rotation = angle;
  657. return this;
  658. },
  659. getRotation: function () {
  660. return this._rotation;
  661. },
  662. setScale: function (sx, sy) {
  663. var that = this,
  664. childNodes = this.childNodes,
  665. childNode;
  666. if (sx === undefined || sx === null) return ;
  667. if (sy === undefined || sy === null) {
  668. sy = sx;
  669. }
  670. for (var i = 0, len = childNodes.length; i < len; i++) {
  671. childNode = childNodes[i];
  672. if (typeof childNode.setScale === 'function') {
  673. childNode.setScale(sx, sy);
  674. }
  675. }
  676. },
  677. getScale: function () {
  678. return this._background.getScale();
  679. },
  680. setScaleX: function (sx) {
  681. if (sx === undefined || sx === null) return;
  682. var that = this,
  683. childNodes = this.childNodes,
  684. childNode;
  685. for (var i = 0, len = childNodes.length; i < len; i++) {
  686. childNode = childNodes[i];
  687. if (typeof childNode.setScaleX === 'function') {
  688. childNode.setScaleX(sx);
  689. }
  690. }
  691. },
  692. setScaleY: function (sy) {
  693. if (sy === undefined || sy === null) return;
  694. var that = this,
  695. childNodes = this.childNodes,
  696. childNode;
  697. for (var i = 0, len = childNodes.length; i < len; i++) {
  698. childNode = childNodes[i];
  699. if (typeof childNode.setScaleY === 'function') {
  700. childNode.setScaleY(sy);
  701. }
  702. }
  703. },
  704. getScaleX: function () {
  705. return this._background.getScaleX();
  706. },
  707. getScaleY: function () {
  708. return this._background.getScaleY();
  709. },
  710. evert: function () {
  711. var that = this,
  712. childNodes = this.childNodes,
  713. background = this._background,
  714. bp = background.getPosition(),
  715. bx = bp.x,
  716. by = bp.y,
  717. childNode, distanceX, distanceY, x, y, p, nx, ny;
  718. for (var i = 0, len = childNodes.length; i < len; i++) {
  719. childNode = childNodes[i];
  720. p = childNode.getPosition();
  721. x = p.x;
  722. y = p.y;
  723. distanceX = bx - x;
  724. distanceY = by - y;
  725. nx = bx + distanceX;
  726. ny = by + distanceY;
  727. childNode.setPosition(nx, ny);
  728. if (typeof childNode.setScale === 'function') {
  729. if (!(childNode._disallowEvert === true))
  730. childNode.setScale(-1, -1);
  731. }
  732. }
  733. },
  734. evertX: function () {
  735. var that = this,
  736. childNodes = this.childNodes,
  737. background = this._background,
  738. bx = background.getPosition().x,
  739. childNode, distance, x, p, nx;
  740. for (var i = 0, len = childNodes.length; i < len; i++) {
  741. childNode = childNodes[i];
  742. p = childNode.getPosition();
  743. x = p.x;
  744. distance = bx - x;
  745. nx = bx + distance;
  746. childNode.setPosition(nx, p.y);
  747. if (typeof childNode.setScaleX === 'function') {
  748. if (!(childNode._disallowEvert === true))
  749. childNode.setScaleX(-1);
  750. }
  751. }
  752. },
  753. evertY: function () {
  754. var that = this,
  755. childNodes = this.childNodes,
  756. background = this._background,
  757. by = background.getPosition().y,
  758. childNode, distance, y, p, ny;
  759. for (var i = 0, len = childNodes.length; i < len; i++) {
  760. childNode = childNodes[i];
  761. p = childNode.getPosition();
  762. y = p.y;
  763. distance = by - y;
  764. ny = by + distance;
  765. childNode.setPosition(p.x, ny);
  766. if (typeof childNode.setScaleY === 'function') {
  767. if (!(childNode._disallowEvert === true))
  768. childNode.setScaleY(-1);
  769. }
  770. }
  771. },
  772. attr: function (key, value) {
  773. var _attrObj = this._attrObj || {};
  774. if (arguments.length === 1) {
  775. return _attrObj[key];
  776. }
  777. var childNodes = this.childNodes, childNode;
  778. _attrObj[key] = value;
  779. for (var i = 0; childNode = childNodes[i++];) {
  780. if (typeof childNode.a === 'function') {
  781. childNode.a(key, value);
  782. }
  783. }
  784. },
  785. a: function () {
  786. return this.attr.apply(this, arguments);
  787. }
  788. });
  789. }