rr.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. ht.lib = ht.lib || {};
  2. if (!ht.lib['rr']) {
  3. ht.lib['rr'] = function (x, y, width, height, angle, localVarObj, localDynamicVar, nodename) {
  4. _ratio = GD.getRatioWithRotation(0, ratio);
  5. ht.lib['rr'].superClass.constructor.apply(this);
  6. this.localVarObj = localVarObj;
  7. this.localDynamicVar = localDynamicVar;
  8. this.childNodes = [];
  9. this._styleObject = {};
  10. this._originWidth = 31*_ratio.ratioX;
  11. this._originHeight = 33*_ratio.ratioY;
  12. this._baseClass = "ht.lib.rr";
  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_rrNode0type = 'oval';
  37. var Lib_rrNode0 = new ht.Node(),
  38. Lib_rrNode0BorderWidth = 2*2;
  39. if (Lib_rrNode0type === 'arc') {
  40. Lib_rrNode0BorderWidth *= 2;
  41. }
  42. Lib_rrNode0.setImage(GD.getRectJSON(30*_ratio.ratioX, 30*_ratio.ratioY, Lib_rrNode0type, '@arcFrom@', '@arcTo@', '@arcClose@'));
  43. Lib_rrNode0.setPosition(15*ratio.ratioX, 15*ratio.ratioY);
  44. Lib_rrNode0.setSize(30*_ratio.ratioX, 30*_ratio.ratioY);
  45. Lib_rrNode0.s({
  46. 'pixelPerfect':true
  47. /*@AddPara@*/
  48. });
  49. Lib_rrNode0.a('node.width', 30*_ratio.ratioX);
  50. Lib_rrNode0.a('node.height', 30*_ratio.ratioY);
  51. Lib_rrNode0.a('node.type', Lib_rrNode0type);
  52. Lib_rrNode0.a('node.rect', [0, 0, 30*_ratio.ratioX, 30*_ratio.ratioY]);
  53. Lib_rrNode0.a('node.background', 'rgba(255,255,255,0.003921569)');
  54. Lib_rrNode0.a('node.gradientcolor', '');
  55. Lib_rrNode0.a('node.gradient', '');
  56. Lib_rrNode0.a('node.borderwidth', Lib_rrNode0BorderWidth);
  57. Lib_rrNode0.a('node.color', 'rgba(255,128,0,1)');
  58. Lib_rrNode0.a('node.fillrect', [0,0,0,0]);
  59. Lib_rrNode0.a('node.fillbackcolor', 'rgba(0,0,0,0)');
  60. Lib_rrNode0.a('node.fillgradientcolor', 'rgba(0,0,0,0)');
  61. Lib_rrNode0.a('node.fillgradient', '');
  62. if (Lib_rrNode0type !== 'rect') {
  63. Lib_rrNode0.a('node.arcFrom', parseFloat('@arcFrom@'));
  64. Lib_rrNode0.a('node.arcTo', parseFloat('@arcTo@'));
  65. Lib_rrNode0.a('node.arcClose', '@arcClose@' === 'true' ? true : false);
  66. }
  67. if (Lib_rrNode0type === 'arc') {
  68. Lib_rrNode0.a('node.arcOval', true);
  69. }
  70. Lib_rrNode0.setRotation(0*Math.PI/180);
  71. Lib_rrNode0.borderWidth = Lib_rrNode0BorderWidth;
  72. Lib_rrNode0.borderFillwidth = Lib_rrNode0BorderWidth;
  73. dataModel.add(Lib_rrNode0);
  74. Lib_rrNode0._nodename = 'Lib_rrNode0'
  75. Lib_rrNode0._nodeType = 'rect';
  76. zoomNodeList.push({
  77. node: Lib_rrNode0,
  78. attr: 'node.borderwidth'
  79. });
  80. (function (node, _img) {
  81. var setWidth = node.setWidth,
  82. setHeight = node.setHeight;
  83. node.setWidth = function (width) {
  84. if (width === this.getWidth()) return ;
  85. var height = this.getHeight();
  86. this.a('node.width', width);
  87. this.a('node.rect', [0,0,width, height]);
  88. setWidth.apply(this, arguments);
  89. }
  90. node.setHeight = function (height) {
  91. if (height === this.getHeight()) return ;
  92. var width = this.getWidth();
  93. this.a('node.height', height);
  94. this.a('node.rect', [0,0,width, height]);
  95. setHeight.apply(this, arguments);
  96. }
  97. })(Lib_rrNode0, Lib_rrNode0.getImage());var Lib_rrNode1points=[5, 5,25, 5],
  98. Lib_rrNode1rect=ht.Default.unionPoint([{x:5,y:5},{x:25,y:5}]),
  99. Lib_rrNode1compspts=[];
  100. _ratio = GD.getRatioWithRotation(0, ratio);
  101. var _startratio = GD.getRatioWithRotation(3.14159265358979, ratio),
  102. _endratio = GD.getRatioWithRotation(0, ratio);
  103. for(var i=0;i<Lib_rrNode1points.length;i++){
  104. if(i%2==0){
  105. Lib_rrNode1compspts.push(Lib_rrNode1points[i]-Lib_rrNode1rect.x);
  106. }else{
  107. Lib_rrNode1compspts.push(Lib_rrNode1points[i]-Lib_rrNode1rect.y);
  108. }
  109. }
  110. var Lib_rrNode1ptslength=Lib_rrNode1compspts.length;
  111. if (Lib_rrNode1rect.height === 0) {
  112. Lib_rrNode1compspts[0] -= 0;
  113. Lib_rrNode1compspts[Lib_rrNode1ptslength-2] += 0;
  114. } else if (Lib_rrNode1rect.width === 0){
  115. Lib_rrNode1compspts[1] -= 0;
  116. Lib_rrNode1compspts[Lib_rrNode1ptslength-1] += 0;
  117. } else {
  118. Lib_rrNode1compspts[0] -= 0;
  119. Lib_rrNode1compspts[1] -= 0;
  120. Lib_rrNode1compspts[Lib_rrNode1ptslength-2] += 0;
  121. Lib_rrNode1compspts[Lib_rrNode1ptslength-1] += 0;
  122. }
  123. Lib_rrNode1 = new ht.Node();
  124. Lib_rrNode1.borderWidth = 2;
  125. Lib_rrNode1rect.width = Lib_rrNode1rect.width === 0 ? 0.0001 : Lib_rrNode1rect.width;
  126. Lib_rrNode1rect.height = Lib_rrNode1rect.height === 0 ? 0.0001 : Lib_rrNode1rect.height;
  127. var Lib_rrNode1endCompspts = [Lib_rrNode1compspts[Lib_rrNode1ptslength-2],Lib_rrNode1compspts[Lib_rrNode1ptslength-1],0,0];
  128. var Lib_rrNode1startCompspts = [Lib_rrNode1compspts[0],Lib_rrNode1compspts[1],0,0];
  129. Lib_rrNode1.setImage(GD.getPolyLineJSON());
  130. Lib_rrNode1.setPosition(Lib_rrNode1rect.x+Lib_rrNode1rect.width/2,Lib_rrNode1rect.y+Lib_rrNode1rect.height/2);
  131. Lib_rrNode1.setSize(Lib_rrNode1rect.width,Lib_rrNode1rect.height);
  132. Lib_rrNode1.setStyle("opacity",1);
  133. Lib_rrNode1.s({'pixelPerfect':true});
  134. Lib_rrNode1borderwidth=2;
  135. Lib_rrNode1.setRotation(0);
  136. dataModel.add(Lib_rrNode1);
  137. Lib_rrNode1.a('node.points',Lib_rrNode1compspts);
  138. Lib_rrNode1.a('node.segments',[1,2]);
  139. Lib_rrNode1.a('node.color','rgba(255,128,0,1)');
  140. Lib_rrNode1.a('node.borderPattern',getDashStyle("@borderPattern@"));
  141. Lib_rrNode1.a('node.borderColor','rgba(255,128,0,1)');
  142. Lib_rrNode1.a('node.background','rgba(255,128,0,1)');
  143. Lib_rrNode1.a('node.gradient','');
  144. Lib_rrNode1.a('node.gradientcolor','rgba(255,128,0,1)');
  145. Lib_rrNode1.a('node.endCompspts',Lib_rrNode1endCompspts);
  146. Lib_rrNode1.a('node.startCompspts',Lib_rrNode1startCompspts);
  147. (function (node, img, compspts, endCompspts, startCompspts) {
  148. var position = node.getPosition(),
  149. w = node.getWidth()*_ratio.ratioX,
  150. h = node.getHeight()*_ratio.ratioY;
  151. function resetPoints(rx, ry) {
  152. for (var i = 0, len = compspts.length; i < len; i++) {
  153. if (i%2 === 0) {
  154. compspts[i]*=rx;
  155. } else {
  156. compspts[i]*=ry;
  157. }
  158. }
  159. endCompspts[0] = compspts[compspts.length-2];
  160. endCompspts[1] = compspts[compspts.length-1];
  161. endCompspts[2] *= rx;
  162. endCompspts[3] *= ry;
  163. node.a('node.offsetEndY', -(endCompspts[3]*0.5));
  164. node.a('node.offsetEndX', -(endCompspts[2]*0.5));
  165. startCompspts[0] = compspts[0];
  166. startCompspts[1] = compspts[1];
  167. startCompspts[2] *= rx;
  168. startCompspts[3] *= ry;
  169. node.a('node.offsetStartY', -(startCompspts[3]*0.5));
  170. node.a('node.offsetStartX', -(startCompspts[2]*0.5));
  171. node.a('node.endRotation', GD.calcRotationByStartAndEnd(compspts[i-4], compspts[i-3], compspts[i-2], compspts[i-1]));
  172. node.a('node.startRotation', GD.calcRotationByStartAndEnd(compspts[0], compspts[1], compspts[2], compspts[3]) + Math.PI);
  173. }
  174. node.setSize(w, h);
  175. node.setPosition(position.x * ratio.ratioX, position.y * ratio.ratioY);
  176. node.a('node.width', w);
  177. node.a('node.height', h);
  178. resetPoints(_ratio.ratioX, _ratio.ratioY);
  179. node.borderWidth = 2;
  180. node.a('node.borderwidth',node.borderWidth);
  181. node._nodename = 'Lib_rrNode1';
  182. node._nodeType = 'line';
  183. zoomNodeList.push({
  184. node: node,
  185. attr: 'node.borderwidth'
  186. });
  187. var setWidth = node.setWidth,
  188. setHeight = node.setHeight,
  189. timer, rx = 1, ry = 1;
  190. node.setWidth = function (width) {
  191. var _width = this.getWidth();
  192. rx = width / _width;
  193. node.a('node.width', width);
  194. setWidth.apply(this, arguments);
  195. resetPoints(rx, 1);
  196. }
  197. node.setHeight = function (height) {
  198. var _height = this.getHeight();
  199. ry = height / _height;
  200. node.a('node.height', height);
  201. setHeight.apply(this, arguments);
  202. resetPoints(1, ry);
  203. }
  204. })(Lib_rrNode1, Lib_rrNode1.getImage(), Lib_rrNode1compspts, Lib_rrNode1endCompspts, Lib_rrNode1startCompspts);
  205. var Lib_rrNode2points=[0, 15,30, 15],
  206. Lib_rrNode2rect=ht.Default.unionPoint([{x:0,y:15},{x:30,y:15}]),
  207. Lib_rrNode2compspts=[];
  208. _ratio = GD.getRatioWithRotation(0, ratio);
  209. var _startratio = GD.getRatioWithRotation(3.14159265358979, ratio),
  210. _endratio = GD.getRatioWithRotation(0, ratio);
  211. for(var i=0;i<Lib_rrNode2points.length;i++){
  212. if(i%2==0){
  213. Lib_rrNode2compspts.push(Lib_rrNode2points[i]-Lib_rrNode2rect.x);
  214. }else{
  215. Lib_rrNode2compspts.push(Lib_rrNode2points[i]-Lib_rrNode2rect.y);
  216. }
  217. }
  218. var Lib_rrNode2ptslength=Lib_rrNode2compspts.length;
  219. if (Lib_rrNode2rect.height === 0) {
  220. Lib_rrNode2compspts[0] -= 0;
  221. Lib_rrNode2compspts[Lib_rrNode2ptslength-2] += 0;
  222. } else if (Lib_rrNode2rect.width === 0){
  223. Lib_rrNode2compspts[1] -= 0;
  224. Lib_rrNode2compspts[Lib_rrNode2ptslength-1] += 0;
  225. } else {
  226. Lib_rrNode2compspts[0] -= 0;
  227. Lib_rrNode2compspts[1] -= 0;
  228. Lib_rrNode2compspts[Lib_rrNode2ptslength-2] += 0;
  229. Lib_rrNode2compspts[Lib_rrNode2ptslength-1] += 0;
  230. }
  231. Lib_rrNode2 = new ht.Node();
  232. Lib_rrNode2.borderWidth = 2;
  233. Lib_rrNode2rect.width = Lib_rrNode2rect.width === 0 ? 0.0001 : Lib_rrNode2rect.width;
  234. Lib_rrNode2rect.height = Lib_rrNode2rect.height === 0 ? 0.0001 : Lib_rrNode2rect.height;
  235. var Lib_rrNode2endCompspts = [Lib_rrNode2compspts[Lib_rrNode2ptslength-2],Lib_rrNode2compspts[Lib_rrNode2ptslength-1],0,0];
  236. var Lib_rrNode2startCompspts = [Lib_rrNode2compspts[0],Lib_rrNode2compspts[1],0,0];
  237. Lib_rrNode2.setImage(GD.getPolyLineJSON());
  238. Lib_rrNode2.setPosition(Lib_rrNode2rect.x+Lib_rrNode2rect.width/2,Lib_rrNode2rect.y+Lib_rrNode2rect.height/2);
  239. Lib_rrNode2.setSize(Lib_rrNode2rect.width,Lib_rrNode2rect.height);
  240. Lib_rrNode2.setStyle("opacity",1);
  241. Lib_rrNode2.s({'pixelPerfect':true});
  242. Lib_rrNode2borderwidth=2;
  243. Lib_rrNode2.setRotation(0);
  244. dataModel.add(Lib_rrNode2);
  245. Lib_rrNode2.a('node.points',Lib_rrNode2compspts);
  246. Lib_rrNode2.a('node.segments',[1,2]);
  247. Lib_rrNode2.a('node.color','rgba(255,128,0,1)');
  248. Lib_rrNode2.a('node.borderPattern',getDashStyle("@borderPattern@"));
  249. Lib_rrNode2.a('node.borderColor','rgba(255,128,0,1)');
  250. Lib_rrNode2.a('node.background','rgba(255,128,0,1)');
  251. Lib_rrNode2.a('node.gradient','');
  252. Lib_rrNode2.a('node.gradientcolor','rgba(255,128,0,1)');
  253. Lib_rrNode2.a('node.endCompspts',Lib_rrNode2endCompspts);
  254. Lib_rrNode2.a('node.startCompspts',Lib_rrNode2startCompspts);
  255. (function (node, img, compspts, endCompspts, startCompspts) {
  256. var position = node.getPosition(),
  257. w = node.getWidth()*_ratio.ratioX,
  258. h = node.getHeight()*_ratio.ratioY;
  259. function resetPoints(rx, ry) {
  260. for (var i = 0, len = compspts.length; i < len; i++) {
  261. if (i%2 === 0) {
  262. compspts[i]*=rx;
  263. } else {
  264. compspts[i]*=ry;
  265. }
  266. }
  267. endCompspts[0] = compspts[compspts.length-2];
  268. endCompspts[1] = compspts[compspts.length-1];
  269. endCompspts[2] *= rx;
  270. endCompspts[3] *= ry;
  271. node.a('node.offsetEndY', -(endCompspts[3]*0.5));
  272. node.a('node.offsetEndX', -(endCompspts[2]*0.5));
  273. startCompspts[0] = compspts[0];
  274. startCompspts[1] = compspts[1];
  275. startCompspts[2] *= rx;
  276. startCompspts[3] *= ry;
  277. node.a('node.offsetStartY', -(startCompspts[3]*0.5));
  278. node.a('node.offsetStartX', -(startCompspts[2]*0.5));
  279. node.a('node.endRotation', GD.calcRotationByStartAndEnd(compspts[i-4], compspts[i-3], compspts[i-2], compspts[i-1]));
  280. node.a('node.startRotation', GD.calcRotationByStartAndEnd(compspts[0], compspts[1], compspts[2], compspts[3]) + Math.PI);
  281. }
  282. node.setSize(w, h);
  283. node.setPosition(position.x * ratio.ratioX, position.y * ratio.ratioY);
  284. node.a('node.width', w);
  285. node.a('node.height', h);
  286. resetPoints(_ratio.ratioX, _ratio.ratioY);
  287. node.borderWidth = 2;
  288. node.a('node.borderwidth',node.borderWidth);
  289. node._nodename = 'Lib_rrNode2';
  290. node._nodeType = 'line';
  291. zoomNodeList.push({
  292. node: node,
  293. attr: 'node.borderwidth'
  294. });
  295. var setWidth = node.setWidth,
  296. setHeight = node.setHeight,
  297. timer, rx = 1, ry = 1;
  298. node.setWidth = function (width) {
  299. var _width = this.getWidth();
  300. rx = width / _width;
  301. node.a('node.width', width);
  302. setWidth.apply(this, arguments);
  303. resetPoints(rx, 1);
  304. }
  305. node.setHeight = function (height) {
  306. var _height = this.getHeight();
  307. ry = height / _height;
  308. node.a('node.height', height);
  309. setHeight.apply(this, arguments);
  310. resetPoints(1, ry);
  311. }
  312. })(Lib_rrNode2, Lib_rrNode2.getImage(), Lib_rrNode2compspts, Lib_rrNode2endCompspts, Lib_rrNode2startCompspts);
  313. var Lib_rrNode3points=[3, 10,28, 10],
  314. Lib_rrNode3rect=ht.Default.unionPoint([{x:3,y:10},{x:28,y:10}]),
  315. Lib_rrNode3compspts=[];
  316. _ratio = GD.getRatioWithRotation(0, ratio);
  317. var _startratio = GD.getRatioWithRotation(3.14159265358979, ratio),
  318. _endratio = GD.getRatioWithRotation(0, ratio);
  319. for(var i=0;i<Lib_rrNode3points.length;i++){
  320. if(i%2==0){
  321. Lib_rrNode3compspts.push(Lib_rrNode3points[i]-Lib_rrNode3rect.x);
  322. }else{
  323. Lib_rrNode3compspts.push(Lib_rrNode3points[i]-Lib_rrNode3rect.y);
  324. }
  325. }
  326. var Lib_rrNode3ptslength=Lib_rrNode3compspts.length;
  327. if (Lib_rrNode3rect.height === 0) {
  328. Lib_rrNode3compspts[0] -= 0;
  329. Lib_rrNode3compspts[Lib_rrNode3ptslength-2] += 0;
  330. } else if (Lib_rrNode3rect.width === 0){
  331. Lib_rrNode3compspts[1] -= 0;
  332. Lib_rrNode3compspts[Lib_rrNode3ptslength-1] += 0;
  333. } else {
  334. Lib_rrNode3compspts[0] -= 0;
  335. Lib_rrNode3compspts[1] -= 0;
  336. Lib_rrNode3compspts[Lib_rrNode3ptslength-2] += 0;
  337. Lib_rrNode3compspts[Lib_rrNode3ptslength-1] += 0;
  338. }
  339. Lib_rrNode3 = new ht.Node();
  340. Lib_rrNode3.borderWidth = 2;
  341. Lib_rrNode3rect.width = Lib_rrNode3rect.width === 0 ? 0.0001 : Lib_rrNode3rect.width;
  342. Lib_rrNode3rect.height = Lib_rrNode3rect.height === 0 ? 0.0001 : Lib_rrNode3rect.height;
  343. var Lib_rrNode3endCompspts = [Lib_rrNode3compspts[Lib_rrNode3ptslength-2],Lib_rrNode3compspts[Lib_rrNode3ptslength-1],0,0];
  344. var Lib_rrNode3startCompspts = [Lib_rrNode3compspts[0],Lib_rrNode3compspts[1],0,0];
  345. Lib_rrNode3.setImage(GD.getPolyLineJSON());
  346. Lib_rrNode3.setPosition(Lib_rrNode3rect.x+Lib_rrNode3rect.width/2,Lib_rrNode3rect.y+Lib_rrNode3rect.height/2);
  347. Lib_rrNode3.setSize(Lib_rrNode3rect.width,Lib_rrNode3rect.height);
  348. Lib_rrNode3.setStyle("opacity",1);
  349. Lib_rrNode3.s({'pixelPerfect':true});
  350. Lib_rrNode3borderwidth=2;
  351. Lib_rrNode3.setRotation(0);
  352. dataModel.add(Lib_rrNode3);
  353. Lib_rrNode3.a('node.points',Lib_rrNode3compspts);
  354. Lib_rrNode3.a('node.segments',[1,2]);
  355. Lib_rrNode3.a('node.color','rgba(255,128,0,1)');
  356. Lib_rrNode3.a('node.borderPattern',getDashStyle("@borderPattern@"));
  357. Lib_rrNode3.a('node.borderColor','rgba(255,128,0,1)');
  358. Lib_rrNode3.a('node.background','rgba(255,128,0,1)');
  359. Lib_rrNode3.a('node.gradient','');
  360. Lib_rrNode3.a('node.gradientcolor','rgba(255,128,0,1)');
  361. Lib_rrNode3.a('node.endCompspts',Lib_rrNode3endCompspts);
  362. Lib_rrNode3.a('node.startCompspts',Lib_rrNode3startCompspts);
  363. (function (node, img, compspts, endCompspts, startCompspts) {
  364. var position = node.getPosition(),
  365. w = node.getWidth()*_ratio.ratioX,
  366. h = node.getHeight()*_ratio.ratioY;
  367. function resetPoints(rx, ry) {
  368. for (var i = 0, len = compspts.length; i < len; i++) {
  369. if (i%2 === 0) {
  370. compspts[i]*=rx;
  371. } else {
  372. compspts[i]*=ry;
  373. }
  374. }
  375. endCompspts[0] = compspts[compspts.length-2];
  376. endCompspts[1] = compspts[compspts.length-1];
  377. endCompspts[2] *= rx;
  378. endCompspts[3] *= ry;
  379. node.a('node.offsetEndY', -(endCompspts[3]*0.5));
  380. node.a('node.offsetEndX', -(endCompspts[2]*0.5));
  381. startCompspts[0] = compspts[0];
  382. startCompspts[1] = compspts[1];
  383. startCompspts[2] *= rx;
  384. startCompspts[3] *= ry;
  385. node.a('node.offsetStartY', -(startCompspts[3]*0.5));
  386. node.a('node.offsetStartX', -(startCompspts[2]*0.5));
  387. node.a('node.endRotation', GD.calcRotationByStartAndEnd(compspts[i-4], compspts[i-3], compspts[i-2], compspts[i-1]));
  388. node.a('node.startRotation', GD.calcRotationByStartAndEnd(compspts[0], compspts[1], compspts[2], compspts[3]) + Math.PI);
  389. }
  390. node.setSize(w, h);
  391. node.setPosition(position.x * ratio.ratioX, position.y * ratio.ratioY);
  392. node.a('node.width', w);
  393. node.a('node.height', h);
  394. resetPoints(_ratio.ratioX, _ratio.ratioY);
  395. node.borderWidth = 2;
  396. node.a('node.borderwidth',node.borderWidth);
  397. node._nodename = 'Lib_rrNode3';
  398. node._nodeType = 'line';
  399. zoomNodeList.push({
  400. node: node,
  401. attr: 'node.borderwidth'
  402. });
  403. var setWidth = node.setWidth,
  404. setHeight = node.setHeight,
  405. timer, rx = 1, ry = 1;
  406. node.setWidth = function (width) {
  407. var _width = this.getWidth();
  408. rx = width / _width;
  409. node.a('node.width', width);
  410. setWidth.apply(this, arguments);
  411. resetPoints(rx, 1);
  412. }
  413. node.setHeight = function (height) {
  414. var _height = this.getHeight();
  415. ry = height / _height;
  416. node.a('node.height', height);
  417. setHeight.apply(this, arguments);
  418. resetPoints(1, ry);
  419. }
  420. })(Lib_rrNode3, Lib_rrNode3.getImage(), Lib_rrNode3compspts, Lib_rrNode3endCompspts, Lib_rrNode3startCompspts);
  421. var Lib_rrNode4points=[16, 13,16, 33],
  422. Lib_rrNode4rect=ht.Default.unionPoint([{x:16,y:13},{x:16,y:33}]),
  423. Lib_rrNode4compspts=[];
  424. _ratio = GD.getRatioWithRotation(0, ratio);
  425. var _startratio = GD.getRatioWithRotation(4.71238898038469, ratio),
  426. _endratio = GD.getRatioWithRotation(7.85398163397448, ratio);
  427. for(var i=0;i<Lib_rrNode4points.length;i++){
  428. if(i%2==0){
  429. Lib_rrNode4compspts.push(Lib_rrNode4points[i]-Lib_rrNode4rect.x);
  430. }else{
  431. Lib_rrNode4compspts.push(Lib_rrNode4points[i]-Lib_rrNode4rect.y);
  432. }
  433. }
  434. var Lib_rrNode4ptslength=Lib_rrNode4compspts.length;
  435. if (Lib_rrNode4rect.height === 0) {
  436. Lib_rrNode4compspts[0] -= 0;
  437. Lib_rrNode4compspts[Lib_rrNode4ptslength-2] += 0;
  438. } else if (Lib_rrNode4rect.width === 0){
  439. Lib_rrNode4compspts[1] -= 0;
  440. Lib_rrNode4compspts[Lib_rrNode4ptslength-1] += 0;
  441. } else {
  442. Lib_rrNode4compspts[0] -= 0;
  443. Lib_rrNode4compspts[1] -= 0;
  444. Lib_rrNode4compspts[Lib_rrNode4ptslength-2] += 0;
  445. Lib_rrNode4compspts[Lib_rrNode4ptslength-1] += 0;
  446. }
  447. Lib_rrNode4 = new ht.Node();
  448. Lib_rrNode4.borderWidth = 2;
  449. Lib_rrNode4rect.width = Lib_rrNode4rect.width === 0 ? 0.0001 : Lib_rrNode4rect.width;
  450. Lib_rrNode4rect.height = Lib_rrNode4rect.height === 0 ? 0.0001 : Lib_rrNode4rect.height;
  451. var Lib_rrNode4endCompspts = [Lib_rrNode4compspts[Lib_rrNode4ptslength-2],Lib_rrNode4compspts[Lib_rrNode4ptslength-1],0,0];
  452. var Lib_rrNode4startCompspts = [Lib_rrNode4compspts[0],Lib_rrNode4compspts[1],0,0];
  453. Lib_rrNode4.setImage(GD.getPolyLineJSON());
  454. Lib_rrNode4.setPosition(Lib_rrNode4rect.x+Lib_rrNode4rect.width/2,Lib_rrNode4rect.y+Lib_rrNode4rect.height/2);
  455. Lib_rrNode4.setSize(Lib_rrNode4rect.width,Lib_rrNode4rect.height);
  456. Lib_rrNode4.setStyle("opacity",1);
  457. Lib_rrNode4.s({'pixelPerfect':true});
  458. Lib_rrNode4borderwidth=2;
  459. Lib_rrNode4.setRotation(0);
  460. dataModel.add(Lib_rrNode4);
  461. Lib_rrNode4.a('node.points',Lib_rrNode4compspts);
  462. Lib_rrNode4.a('node.segments',[1,2]);
  463. Lib_rrNode4.a('node.color','rgba(255,128,0,1)');
  464. Lib_rrNode4.a('node.borderPattern',getDashStyle("@borderPattern@"));
  465. Lib_rrNode4.a('node.borderColor','rgba(255,128,0,1)');
  466. Lib_rrNode4.a('node.background','rgba(255,128,0,1)');
  467. Lib_rrNode4.a('node.gradient','');
  468. Lib_rrNode4.a('node.gradientcolor','rgba(255,128,0,1)');
  469. Lib_rrNode4.a('node.endCompspts',Lib_rrNode4endCompspts);
  470. Lib_rrNode4.a('node.startCompspts',Lib_rrNode4startCompspts);
  471. (function (node, img, compspts, endCompspts, startCompspts) {
  472. var position = node.getPosition(),
  473. w = node.getWidth()*_ratio.ratioX,
  474. h = node.getHeight()*_ratio.ratioY;
  475. function resetPoints(rx, ry) {
  476. for (var i = 0, len = compspts.length; i < len; i++) {
  477. if (i%2 === 0) {
  478. compspts[i]*=rx;
  479. } else {
  480. compspts[i]*=ry;
  481. }
  482. }
  483. endCompspts[0] = compspts[compspts.length-2];
  484. endCompspts[1] = compspts[compspts.length-1];
  485. endCompspts[2] *= rx;
  486. endCompspts[3] *= ry;
  487. node.a('node.offsetEndY', -(endCompspts[3]*0.5));
  488. node.a('node.offsetEndX', -(endCompspts[2]*0.5));
  489. startCompspts[0] = compspts[0];
  490. startCompspts[1] = compspts[1];
  491. startCompspts[2] *= rx;
  492. startCompspts[3] *= ry;
  493. node.a('node.offsetStartY', -(startCompspts[3]*0.5));
  494. node.a('node.offsetStartX', -(startCompspts[2]*0.5));
  495. node.a('node.endRotation', GD.calcRotationByStartAndEnd(compspts[i-4], compspts[i-3], compspts[i-2], compspts[i-1]));
  496. node.a('node.startRotation', GD.calcRotationByStartAndEnd(compspts[0], compspts[1], compspts[2], compspts[3]) + Math.PI);
  497. }
  498. node.setSize(w, h);
  499. node.setPosition(position.x * ratio.ratioX, position.y * ratio.ratioY);
  500. node.a('node.width', w);
  501. node.a('node.height', h);
  502. resetPoints(_ratio.ratioX, _ratio.ratioY);
  503. node.borderWidth = 2;
  504. node.a('node.borderwidth',node.borderWidth);
  505. node._nodename = 'Lib_rrNode4';
  506. node._nodeType = 'line';
  507. zoomNodeList.push({
  508. node: node,
  509. attr: 'node.borderwidth'
  510. });
  511. var setWidth = node.setWidth,
  512. setHeight = node.setHeight,
  513. timer, rx = 1, ry = 1;
  514. node.setWidth = function (width) {
  515. var _width = this.getWidth();
  516. rx = width / _width;
  517. node.a('node.width', width);
  518. setWidth.apply(this, arguments);
  519. resetPoints(rx, 1);
  520. }
  521. node.setHeight = function (height) {
  522. var _height = this.getHeight();
  523. ry = height / _height;
  524. node.a('node.height', height);
  525. setHeight.apply(this, arguments);
  526. resetPoints(1, ry);
  527. }
  528. })(Lib_rrNode4, Lib_rrNode4.getImage(), Lib_rrNode4compspts, Lib_rrNode4endCompspts, Lib_rrNode4startCompspts);
  529. /*@GraphList@*/
  530. /*@PageInit@*/
  531. var localVarObj = this.localVarObj;
  532. var localDynamicVarObj = this.localDynamicVar();
  533. this['Lib_rrNode0'] = Lib_rrNode0;
  534. Lib_rrNode0.__parentLib = nodename;
  535. Lib_rrNode0.__parent = this;
  536. this.childNodes.push(Lib_rrNode0);
  537. this['Lib_rrNode1'] = Lib_rrNode1;
  538. Lib_rrNode1.__parentLib = nodename;
  539. Lib_rrNode1.__parent = this;
  540. this.childNodes.push(Lib_rrNode1);
  541. this['Lib_rrNode2'] = Lib_rrNode2;
  542. Lib_rrNode2.__parentLib = nodename;
  543. Lib_rrNode2.__parent = this;
  544. this.childNodes.push(Lib_rrNode2);
  545. this['Lib_rrNode3'] = Lib_rrNode3;
  546. Lib_rrNode3.__parentLib = nodename;
  547. Lib_rrNode3.__parent = this;
  548. this.childNodes.push(Lib_rrNode3);
  549. this['Lib_rrNode4'] = Lib_rrNode4;
  550. Lib_rrNode4.__parentLib = nodename;
  551. Lib_rrNode4.__parent = this;
  552. this.childNodes.push(Lib_rrNode4);
  553. /*@ControlContextMenu@*/
  554. /*@Declare@*/
  555. this.init(x, y, width, height, angle);
  556. };
  557. ht.Default.def('ht.lib.rr', Object, {
  558. refresh10ms: function () {
  559. var localVarObj = this.localVarObj;
  560. var localDynamicVarObj = this.localDynamicVar();
  561. var Lib_rrNode0= this.Lib_rrNode0;
  562. var Lib_rrNode1= this.Lib_rrNode1;
  563. var Lib_rrNode2= this.Lib_rrNode2;
  564. var Lib_rrNode3= this.Lib_rrNode3;
  565. var Lib_rrNode4= this.Lib_rrNode4;
  566. /*@refresh10ms@*/
  567. },
  568. refresh100ms: function () {
  569. var localVarObj = this.localVarObj;
  570. var localDynamicVarObj = this.localDynamicVar();
  571. var Lib_rrNode0= this.Lib_rrNode0;
  572. var Lib_rrNode1= this.Lib_rrNode1;
  573. var Lib_rrNode2= this.Lib_rrNode2;
  574. var Lib_rrNode3= this.Lib_rrNode3;
  575. var Lib_rrNode4= this.Lib_rrNode4;
  576. /*@refresh100ms@*/
  577. },
  578. refresh500ms: function () {
  579. var localVarObj = this.localVarObj;
  580. var localDynamicVarObj = this.localDynamicVar();
  581. var Lib_rrNode0= this.Lib_rrNode0;
  582. var Lib_rrNode1= this.Lib_rrNode1;
  583. var Lib_rrNode2= this.Lib_rrNode2;
  584. var Lib_rrNode3= this.Lib_rrNode3;
  585. var Lib_rrNode4= this.Lib_rrNode4;
  586. /*@refresh500ms@*/
  587. },
  588. refresh1s: function () {
  589. var Counter1s = arguments[0] || 0;
  590. var localVarObj = this.localVarObj;
  591. var localDynamicVarObj = this.localDynamicVar();
  592. var Lib_rrNode0= this.Lib_rrNode0;
  593. var Lib_rrNode1= this.Lib_rrNode1;
  594. var Lib_rrNode2= this.Lib_rrNode2;
  595. var Lib_rrNode3= this.Lib_rrNode3;
  596. var Lib_rrNode4= this.Lib_rrNode4;
  597. /*@refresh1s@*/
  598. },
  599. refresh5s: function () {
  600. var localVarObj = this.localVarObj;
  601. var localDynamicVarObj = this.localDynamicVar();
  602. var Lib_rrNode0= this.Lib_rrNode0;
  603. var Lib_rrNode1= this.Lib_rrNode1;
  604. var Lib_rrNode2= this.Lib_rrNode2;
  605. var Lib_rrNode3= this.Lib_rrNode3;
  606. var Lib_rrNode4= this.Lib_rrNode4;
  607. /*@refresh5s@*/
  608. },
  609. /*@PageDynamic@*/
  610. onEvent: function (e, data, type, origin, offset, objMouseOn, ctm) {
  611. var localVarObj = this.localVarObj;
  612. var localDynamicVarObj = this.localDynamicVar();
  613. var Lib_rrNode0= this.Lib_rrNode0;
  614. var Lib_rrNode1= this.Lib_rrNode1;
  615. var Lib_rrNode2= this.Lib_rrNode2;
  616. var Lib_rrNode3= this.Lib_rrNode3;
  617. var Lib_rrNode4= this.Lib_rrNode4;
  618. if (type === 'click') {
  619. /*@EvnentClicked@*/
  620. } else if (type === 'mousedown') {
  621. mouseX=e.clientX;
  622. mouseY=e.clientY;
  623. /*@EvnentMouseDown@*/
  624. } else if (type === 'mouseup') {
  625. /*@EvnentMouseUp@*/
  626. } else if (type === 'mousemove') {
  627. var mouseX, mouseY, position, zoom;
  628. position=origin.getLogicalPoint(e);
  629. zoom = graphView.getZoom();
  630. if (origin === graphView) {
  631. mouseX= position.x + origin.tx();
  632. mouseY = position.y + origin.ty();
  633. } else {
  634. offset = offset || {x: 0, y: 0};
  635. mouseX = position.x / zoom + offset.x + origin.tx();
  636. mouseY = position.y / zoom + offset.y + origin.ty();
  637. }
  638. /*@EvnentMouseLeave@*/
  639. /*@EvnentMouseOver@*/
  640. } else if (type === 'keydown') {
  641. /*@EvnentKeyDown@*/
  642. } else if (type === 'contextmenu') {
  643. /*@Declare@*/
  644. /*@SetNodeContextMenu@*/
  645. /*@SetPageContextMenu@*/
  646. }
  647. /*@LibEvent@*/
  648. },
  649. getBaseClass: function () {
  650. return this._baseClass;
  651. },
  652. getWidth: function () {
  653. return this._width;
  654. },
  655. getHeight: function () {
  656. return this._height;
  657. },
  658. getSize: function () {
  659. return {
  660. width: this._width,
  661. height: this._height
  662. }
  663. },
  664. setWidth: function (width) {
  665. if (width === undefined || width === null || width != width) {
  666. return ;
  667. }
  668. var originWidth = this._width;
  669. var ratio = width / originWidth;
  670. var childNodes = this.childNodes, childNode, p, op = this.getPosition(), w, cw, ox, rotation = this.getRotation();
  671. for (var i = 0, len = childNodes.length; i < len; i++) {
  672. childNode = childNodes[i];
  673. p = childNode.getPosition();
  674. cw = childNode.getWidth();
  675. w = cw >=2 ? cw * ratio : cw;
  676. childNode.setWidth(w);
  677. ox = op.x + (p.x - op.x) * ratio;
  678. childNode.setPosition(ox, p.y);
  679. rotation = GD.calcRotation(rotation);
  680. if (rotation === 0 || rotation === Math.PI) {
  681. // 图元未旋转
  682. ox = op.x + (p.x - op.x)*ratio;
  683. childNode.setPosition(ox, p.y);
  684. } else if (rotation === 90 * Math.PI / 180) {
  685. // 图元旋转以后
  686. ox = op.y + (p.y - op.y)*ratio;
  687. childNode.setPosition(p.x, ox);
  688. }
  689. }
  690. this._width = width;
  691. this._originWidth = width;
  692. this._ratioX = ratio;
  693. return this;
  694. },
  695. setHeight: function (height) {
  696. if (height === undefined || height === null || height != height) {
  697. return ;
  698. }
  699. var originHeight = this._height;
  700. var ratio = height / originHeight;
  701. var childNodes = this.childNodes, childNode, p, op = this.getPosition(), h, ch, oy, rotation = this.getRotation();
  702. for (var i = 0, len = childNodes.length; i < len; i++) {
  703. childNode = childNodes[i];
  704. p = childNode.getPosition();
  705. ch = childNode.getHeight();
  706. h = ch >=2 ? ch * ratio : ch;
  707. childNode.setHeight(h);
  708. rotation = GD.calcRotation(rotation);
  709. if (rotation === 0 || rotation === Math.PI) {
  710. // 图元未旋转
  711. oy = op.y + (p.y - op.y)*ratio;
  712. childNode.setPosition(p.x, oy);
  713. } else if (rotation === 90 * Math.PI / 180) {
  714. // 图元旋转以后
  715. oy = op.x + (p.x - op.x)*ratio;
  716. childNode.setPosition(oy, p.y);
  717. }
  718. }
  719. this._height = height;
  720. this._originHeight = height;
  721. this._ratioY = ratio;
  722. return this;
  723. },
  724. setSize: function (size) {
  725. // var args = Array.prototype.slice.call(arguments, 0);
  726. // var height, width;
  727. // if (args.length === 0) {
  728. // return ;
  729. // }else if (args.length === 1) {
  730. // height = args[0].height;
  731. // width = args[0].width;
  732. // } else {
  733. // width = args[0];
  734. // height = args[1];
  735. // }
  736. // var wh = GD.getRatioWithRotation(angle, wid)
  737. // this.setHeight(height);
  738. // this.setWidth(width);
  739. // return this;
  740. var args = Array.prototype.slice.call(arguments, 0);
  741. var height, width;
  742. if (args.length === 0) {
  743. return ;
  744. }else if (args.length === 1) {
  745. height = args[0].height;
  746. width = args[0].width;
  747. angle = 0;
  748. } else if (args.length === 2) {
  749. if (typeof args[0] === 'object') {
  750. width = args[0].width;
  751. height = args[0].height;
  752. angle = args[1] || 0;
  753. } else {
  754. width = args[0];
  755. height = args[1];
  756. angle = 0;
  757. }
  758. } else if (args.length === 3) {
  759. width = args[0];
  760. height = args[1];
  761. angle = args[2] || 0;
  762. }
  763. var wh = GD.getRatioWithRotation(0, width, height);
  764. this.setHeight(wh.ratioY);
  765. this.setWidth(wh.ratioX);
  766. return this;
  767. },
  768. getPosition: function () {
  769. return {
  770. x: this._x,
  771. y: this._y
  772. }
  773. },
  774. setPosition: function () {
  775. var args = Array.prototype.slice.call(arguments, 0), x, y;
  776. if (args.length === 0) {
  777. return this;
  778. } else if (args.length === 1) {
  779. if (typeof args[0] != 'object') {
  780. return this;
  781. }
  782. x = args[0].x;
  783. y = args[0].y;
  784. } else {
  785. x = args[0];
  786. y = args[1];
  787. }
  788. if ((x !== 0 && !x) || (y !== 0 && !y)) {
  789. return this;
  790. }
  791. // var childNodes = this.childNodes, offset, childNode, p;
  792. // for (var i = 0, len = childNodes.length; i < len; i++) {
  793. // childNode = childNodes[i];
  794. // p = childNode.getPosition();
  795. // childNode.setPosition(x - (this._x-p.x)*this._ratioX, y - (this._y-p.y)*this._ratioY);
  796. // }
  797. // this._x = x;
  798. // this._y = y;
  799. // return this;
  800. var childNodes, childNode, background, offset = {}, op, cp;
  801. childNodes = this.childNodes;
  802. background = this._background;
  803. op = background.getPosition();
  804. offset.x = x - op.x;
  805. offset.y = y - op.y;
  806. for (var i = 0, len = childNodes.length; i < len; i++) {
  807. childNode = childNodes[i];
  808. cp = childNode.getPosition();
  809. childNode.setPosition(cp.x + offset.x, cp.y + offset.y);
  810. }
  811. this._x = x;
  812. this._y = y;
  813. this._position = {x: x, y: y};
  814. return this;
  815. },
  816. getStyle: function (key) {
  817. if (!key) {
  818. return undefined;
  819. }
  820. return this._styleObject[key];
  821. },
  822. setStyle: function (key, value, force) {
  823. var childNodes = this.childNodes, childNode;
  824. for (var i = 0, len = childNodes.length; i < len; i++) {
  825. childNode = childNodes[i];
  826. if (key === '2d.visible') {
  827. if (value === graphView.isVisible(childNode)) {
  828. continue;
  829. }
  830. if (!value) {
  831. childNode._savedIsVisible = graphView.isVisible(childNode);
  832. childNode.s({
  833. '2d.visible': false
  834. })
  835. } else {
  836. childNode.s({
  837. '2d.visible': childNode._savedIsVisible
  838. })
  839. }
  840. continue;
  841. }
  842. childNode.s({
  843. key: value
  844. });
  845. }
  846. this._styleObject[key] = value;
  847. return this;
  848. },
  849. calcSize: function () {
  850. var background = this._background;
  851. var position = background.getPosition(),
  852. width = background.getWidth(),
  853. height = background.getHeight();
  854. this._width = width;
  855. this._height = height;
  856. this._x = position.x;
  857. this._y = position.y;
  858. this._position = {
  859. x: this._x,
  860. y: this._y
  861. }
  862. return this;
  863. return this;
  864. },
  865. s: function (styleObj, force) {
  866. var args = Array.prototype.slice.call(arguments, 0);
  867. var styleObj;
  868. if (args.length === 0) {
  869. return this;
  870. } else if (args.length === 1) {
  871. styleObj = args[0];
  872. } else {
  873. this.setStyle(args[0], args[1]);
  874. return this;
  875. }
  876. for (var key in styleObj) {
  877. if (!styleObj.hasOwnProperty(key)) {
  878. continue;
  879. }
  880. this.setStyle(key, styleObj[key], force);
  881. }
  882. return this;
  883. },
  884. init: function (x, y, width, height, angle) {
  885. var that = this;
  886. this.calcSize();
  887. (function (width, height, angle) {
  888. // that.setSize(width, height, angle);
  889. // var wh = GD.getRatioWithRotation(angle, width, height);
  890. // width = wh.ratioX;
  891. // height = wh.ratioY;
  892. var originHeight = that._height;
  893. var originWidth = that._width;
  894. var ratioY = height / originHeight;
  895. var ratioX = width / originWidth;
  896. var childNodes = that.childNodes,
  897. childNode,p, op = that.getPosition(), h, ch, oy, w, cw, ox, name, borderRatio, borderWidth;
  898. for (var i = 0, len = childNodes.length; i < len; i++) {
  899. childNode = childNodes[i];
  900. p = childNode.getPosition();
  901. childNode.originHeight = childNode.originHeight || childNode.getHeight();
  902. ch = childNode.getHeight();
  903. cw = childNode.getWidth();
  904. if (ch > 2) {
  905. h = ch * ratioY;
  906. childNode.setHeight(h);
  907. }
  908. if (cw > 2) {
  909. w = cw * ratioX;
  910. childNode.setWidth(w);
  911. }
  912. borderRatio = (ratioX + ratioY)*0.5;
  913. if (childNode._nodeType === 'line') { // 如果是线,
  914. if (childNode.getWidth() > childNode.getHeight()) {
  915. borderRatio = ratioX;
  916. } else {
  917. borderRatio = ratioY;
  918. }
  919. }
  920. name = childNode._nodename;
  921. // if (childNode.borderWidth && name && ch > 2 && cw > 2) {
  922. // borderWidth = childNode.borderWidth / borderRatio;
  923. // if (borderWidth > ch*0.5 || borderWidth > cw *0.5) {
  924. // // borderWidth = childNode.borderWidth;
  925. // }
  926. // childNode.borderWidth = borderWidth;
  927. // childNode.a(name + '.borderwidth', borderWidth);
  928. // }
  929. }
  930. that._height = height;
  931. that._originHeight = height;
  932. that._ratioY = ratioY;
  933. that._width = width;
  934. that._originWidth = width;
  935. that._ratioX = ratioX;
  936. })(width, height, angle);
  937. that._x = width / 2;
  938. that._y = height / 2;
  939. that._rotation = 0;
  940. // that.setPosition(x, y);
  941. (function (x, y) {
  942. var childNodes = that.childNodes, offset, childNode;
  943. var w2 = that.getWidth() / 2, h2 = that.getHeight()/2;
  944. for (var i = 0, len = childNodes.length; i < len; i++) {
  945. childNode = childNodes[i];
  946. offset = childNode.getPosition();
  947. childNode.setPosition(x + offset.x * that._ratioX - w2, y + offset.y * that._ratioY - h2);
  948. }
  949. that._x = x;
  950. that._y = y;
  951. })(x, y);
  952. // setTimeout(that.addEVent, 1000);
  953. },
  954. setRotation: function (angle) {
  955. var that = this, _angle = that.getRotation();
  956. if (angle!==0 && !angle || angle === _angle) {
  957. return this;
  958. }
  959. var childNodes = this.childNodes, childNode, p = this.getPosition(), px = p.x, py = p.y;
  960. for (var i = 0, len = childNodes.length; i < len; i++) {
  961. childNode = childNodes[i];
  962. var x = childNode.getPosition().x - px;
  963. var y = childNode.getPosition().y - py;
  964. childNode.setPosition(Math.cos(angle-_angle) * x - Math.sin(angle-_angle) * y + px, Math.cos(angle-_angle) * y + Math.sin(angle-_angle) * x + py);
  965. childNode.setRotation(angle);
  966. }
  967. this._rotation = angle;
  968. return this;
  969. },
  970. getRotation: function () {
  971. return this._rotation;
  972. },
  973. setScale: function (sx, sy) {
  974. var that = this,
  975. childNodes = this.childNodes,
  976. childNode;
  977. if (sx === undefined || sx === null) return ;
  978. if (sy === undefined || sy === null) {
  979. sy = sx;
  980. }
  981. for (var i = 0, len = childNodes.length; i < len; i++) {
  982. childNode = childNodes[i];
  983. if (typeof childNode.setScale === 'function') {
  984. childNode.setScale(sx, sy);
  985. }
  986. }
  987. },
  988. getScale: function () {
  989. return this._background.getScale();
  990. },
  991. setScaleX: function (sx) {
  992. if (sx === undefined || sx === null) return;
  993. var that = this,
  994. childNodes = this.childNodes,
  995. childNode;
  996. for (var i = 0, len = childNodes.length; i < len; i++) {
  997. childNode = childNodes[i];
  998. if (typeof childNode.setScaleX === 'function') {
  999. childNode.setScaleX(sx);
  1000. }
  1001. }
  1002. },
  1003. setScaleY: function (sy) {
  1004. if (sy === undefined || sy === null) return;
  1005. var that = this,
  1006. childNodes = this.childNodes,
  1007. childNode;
  1008. for (var i = 0, len = childNodes.length; i < len; i++) {
  1009. childNode = childNodes[i];
  1010. if (typeof childNode.setScaleY === 'function') {
  1011. childNode.setScaleY(sy);
  1012. }
  1013. }
  1014. },
  1015. getScaleX: function () {
  1016. return this._background.getScaleX();
  1017. },
  1018. getScaleY: function () {
  1019. return this._background.getScaleY();
  1020. },
  1021. evert: function () {
  1022. var that = this,
  1023. childNodes = this.childNodes,
  1024. background = this._background,
  1025. bp = background.getPosition(),
  1026. bx = bp.x,
  1027. by = bp.y,
  1028. childNode, distanceX, distanceY, x, y, p, nx, ny;
  1029. for (var i = 0, len = childNodes.length; i < len; i++) {
  1030. childNode = childNodes[i];
  1031. p = childNode.getPosition();
  1032. x = p.x;
  1033. y = p.y;
  1034. distanceX = bx - x;
  1035. distanceY = by - y;
  1036. nx = bx + distanceX;
  1037. ny = by + distanceY;
  1038. childNode.setPosition(nx, ny);
  1039. if (typeof childNode.setScale === 'function') {
  1040. if (!(childNode._disallowEvert === true))
  1041. childNode.setScale(-1, -1);
  1042. }
  1043. }
  1044. },
  1045. evertX: function () {
  1046. var that = this,
  1047. childNodes = this.childNodes,
  1048. background = this._background,
  1049. bx = background.getPosition().x,
  1050. childNode, distance, x, p, nx;
  1051. for (var i = 0, len = childNodes.length; i < len; i++) {
  1052. childNode = childNodes[i];
  1053. p = childNode.getPosition();
  1054. x = p.x;
  1055. distance = bx - x;
  1056. nx = bx + distance;
  1057. childNode.setPosition(nx, p.y);
  1058. if (typeof childNode.setScaleX === 'function') {
  1059. if (!(childNode._disallowEvert === true))
  1060. childNode.setScaleX(-1);
  1061. }
  1062. }
  1063. },
  1064. evertY: function () {
  1065. var that = this,
  1066. childNodes = this.childNodes,
  1067. background = this._background,
  1068. by = background.getPosition().y,
  1069. childNode, distance, y, p, ny;
  1070. for (var i = 0, len = childNodes.length; i < len; i++) {
  1071. childNode = childNodes[i];
  1072. p = childNode.getPosition();
  1073. y = p.y;
  1074. distance = by - y;
  1075. ny = by + distance;
  1076. childNode.setPosition(p.x, ny);
  1077. if (typeof childNode.setScaleY === 'function') {
  1078. if (!(childNode._disallowEvert === true))
  1079. childNode.setScaleY(-1);
  1080. }
  1081. }
  1082. },
  1083. attr: function (key, value) {
  1084. var _attrObj = this._attrObj || {};
  1085. if (arguments.length === 1) {
  1086. return _attrObj[key];
  1087. }
  1088. var childNodes = this.childNodes, childNode;
  1089. _attrObj[key] = value;
  1090. for (var i = 0; childNode = childNodes[i++];) {
  1091. if (typeof childNode.a === 'function') {
  1092. childNode.a(key, value);
  1093. }
  1094. }
  1095. },
  1096. a: function () {
  1097. return this.attr.apply(this, arguments);
  1098. }
  1099. });
  1100. }