1345.js 29 KB

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