ht.lib = ht.lib || {}; if (!ht.lib['细线竖短紫']) { ht.lib['细线竖短紫'] = function (x, y, width, height, angle, localVarObj, localDynamicVar, nodename) { _ratio = GD.getRatioWithRotation(0, ratio); ht.lib['细线竖短紫'].superClass.constructor.apply(this); this.localVarObj = localVarObj; this.localDynamicVar = localDynamicVar; this.childNodes = []; this._styleObject = {}; this._originWidth = 1*_ratio.ratioX; this._originHeight = 7*_ratio.ratioY; this._baseClass = "ht.lib.细线竖短紫"; this._background = new ht.Node(); this._background.setWidth(this._originWidth); this._background.setHeight(this._originHeight); this._background.setPosition(this._originWidth/2, this._originHeight/2); this._background.setImage({ width: width, height: height, clip: true, comps: [ { type: 'rect', background: 'rgba(0,255,0,0)', rect: [0,0,width, height] } ] }); this._background.__parentLib = nodename; this._background.isLibBackground = true; this.childNodes.push(this._background); dataModel.add(this._background); /*@PageBackgroundInit@*/ /*@PageBeforeInit@*/ var Lib_细线竖短紫Node0points=[0, 0,0, 7], Lib_细线竖短紫Node0rect=ht.Default.unionPoint([{x:0,y:0},{x:0,y:7}]), Lib_细线竖短紫Node0compspts=[]; _ratio = GD.getRatioWithRotation(0, ratio); var _startratio = GD.getRatioWithRotation(4.71238898038469, ratio), _endratio = GD.getRatioWithRotation(7.85398163397448, ratio); for(var i=0;i=2 ? cw * ratio : cw; childNode.setWidth(w); ox = op.x + (p.x - op.x) * ratio; childNode.setPosition(ox, p.y); rotation = GD.calcRotation(rotation); if (rotation === 0 || rotation === Math.PI) { // 图元未旋转 ox = op.x + (p.x - op.x)*ratio; childNode.setPosition(ox, p.y); } else if (rotation === 90 * Math.PI / 180) { // 图元旋转以后 ox = op.y + (p.y - op.y)*ratio; childNode.setPosition(p.x, ox); } } this._width = width; this._originWidth = width; this._ratioX = ratio; return this; }, setHeight: function (height) { if (height === undefined || height === null || height != height) { return ; } var originHeight = this._height; var ratio = height / originHeight; var childNodes = this.childNodes, childNode, p, op = this.getPosition(), h, ch, oy, rotation = this.getRotation(); for (var i = 0, len = childNodes.length; i < len; i++) { childNode = childNodes[i]; p = childNode.getPosition(); ch = childNode.getHeight(); h = ch >=2 ? ch * ratio : ch; childNode.setHeight(h); rotation = GD.calcRotation(rotation); if (rotation === 0 || rotation === Math.PI) { // 图元未旋转 oy = op.y + (p.y - op.y)*ratio; childNode.setPosition(p.x, oy); } else if (rotation === 90 * Math.PI / 180) { // 图元旋转以后 oy = op.x + (p.x - op.x)*ratio; childNode.setPosition(oy, p.y); } } this._height = height; this._originHeight = height; this._ratioY = ratio; return this; }, setSize: function (size) { // var args = Array.prototype.slice.call(arguments, 0); // var height, width; // if (args.length === 0) { // return ; // }else if (args.length === 1) { // height = args[0].height; // width = args[0].width; // } else { // width = args[0]; // height = args[1]; // } // var wh = GD.getRatioWithRotation(angle, wid) // this.setHeight(height); // this.setWidth(width); // return this; var args = Array.prototype.slice.call(arguments, 0); var height, width; if (args.length === 0) { return ; }else if (args.length === 1) { height = args[0].height; width = args[0].width; angle = 0; } else if (args.length === 2) { if (typeof args[0] === 'object') { width = args[0].width; height = args[0].height; angle = args[1] || 0; } else { width = args[0]; height = args[1]; angle = 0; } } else if (args.length === 3) { width = args[0]; height = args[1]; angle = args[2] || 0; } var wh = GD.getRatioWithRotation(0, width, height); this.setHeight(wh.ratioY); this.setWidth(wh.ratioX); return this; }, getPosition: function () { return { x: this._x, y: this._y } }, setPosition: function () { var args = Array.prototype.slice.call(arguments, 0), x, y; if (args.length === 0) { return this; } else if (args.length === 1) { if (typeof args[0] != 'object') { return this; } x = args[0].x; y = args[0].y; } else { x = args[0]; y = args[1]; } if ((x !== 0 && !x) || (y !== 0 && !y)) { return this; } // var childNodes = this.childNodes, offset, childNode, p; // for (var i = 0, len = childNodes.length; i < len; i++) { // childNode = childNodes[i]; // p = childNode.getPosition(); // childNode.setPosition(x - (this._x-p.x)*this._ratioX, y - (this._y-p.y)*this._ratioY); // } // this._x = x; // this._y = y; // return this; var childNodes, childNode, background, offset = {}, op, cp; childNodes = this.childNodes; background = this._background; op = background.getPosition(); offset.x = x - op.x; offset.y = y - op.y; for (var i = 0, len = childNodes.length; i < len; i++) { childNode = childNodes[i]; cp = childNode.getPosition(); childNode.setPosition(cp.x + offset.x, cp.y + offset.y); } this._x = x; this._y = y; this._position = {x: x, y: y}; return this; }, getStyle: function (key) { if (!key) { return undefined; } return this._styleObject[key]; }, setStyle: function (key, value, force) { var childNodes = this.childNodes, childNode; for (var i = 0, len = childNodes.length; i < len; i++) { childNode = childNodes[i]; if (key === '2d.visible') { if (value === graphView.isVisible(childNode)) { continue; } if (!value) { childNode._savedIsVisible = graphView.isVisible(childNode); childNode.s({ '2d.visible': false }) } else { childNode.s({ '2d.visible': childNode._savedIsVisible }) } continue; } childNode.s({ key: value }); } this._styleObject[key] = value; return this; }, calcSize: function () { var background = this._background; var position = background.getPosition(), width = background.getWidth(), height = background.getHeight(); this._width = width; this._height = height; this._x = position.x; this._y = position.y; this._position = { x: this._x, y: this._y } return this; return this; }, s: function (styleObj, force) { var args = Array.prototype.slice.call(arguments, 0); var styleObj; if (args.length === 0) { return this; } else if (args.length === 1) { styleObj = args[0]; } else { this.setStyle(args[0], args[1]); return this; } for (var key in styleObj) { if (!styleObj.hasOwnProperty(key)) { continue; } this.setStyle(key, styleObj[key], force); } return this; }, init: function (x, y, width, height, angle) { var that = this; this.calcSize(); (function (width, height, angle) { // that.setSize(width, height, angle); // var wh = GD.getRatioWithRotation(angle, width, height); // width = wh.ratioX; // height = wh.ratioY; var originHeight = that._height; var originWidth = that._width; var ratioY = height / originHeight; var ratioX = width / originWidth; var childNodes = that.childNodes, childNode,p, op = that.getPosition(), h, ch, oy, w, cw, ox, name, borderRatio, borderWidth; for (var i = 0, len = childNodes.length; i < len; i++) { childNode = childNodes[i]; p = childNode.getPosition(); childNode.originHeight = childNode.originHeight || childNode.getHeight(); ch = childNode.getHeight(); cw = childNode.getWidth(); if (ch > 2) { h = ch * ratioY; childNode.setHeight(h); } if (cw > 2) { w = cw * ratioX; childNode.setWidth(w); } borderRatio = (ratioX + ratioY)*0.5; if (childNode._nodeType === 'line') { // 如果是线, if (childNode.getWidth() > childNode.getHeight()) { borderRatio = ratioX; } else { borderRatio = ratioY; } } name = childNode._nodename; // if (childNode.borderWidth && name && ch > 2 && cw > 2) { // borderWidth = childNode.borderWidth / borderRatio; // if (borderWidth > ch*0.5 || borderWidth > cw *0.5) { // // borderWidth = childNode.borderWidth; // } // childNode.borderWidth = borderWidth; // childNode.a(name + '.borderwidth', borderWidth); // } } that._height = height; that._originHeight = height; that._ratioY = ratioY; that._width = width; that._originWidth = width; that._ratioX = ratioX; })(width, height, angle); that._x = width / 2; that._y = height / 2; that._rotation = 0; // that.setPosition(x, y); (function (x, y) { var childNodes = that.childNodes, offset, childNode; var w2 = that.getWidth() / 2, h2 = that.getHeight()/2; for (var i = 0, len = childNodes.length; i < len; i++) { childNode = childNodes[i]; offset = childNode.getPosition(); childNode.setPosition(x + offset.x * that._ratioX - w2, y + offset.y * that._ratioY - h2); } that._x = x; that._y = y; })(x, y); // setTimeout(that.addEVent, 1000); }, setRotation: function (angle) { var that = this, _angle = that.getRotation(); if (angle!==0 && !angle || angle === _angle) { return this; } var childNodes = this.childNodes, childNode, p = this.getPosition(), px = p.x, py = p.y; for (var i = 0, len = childNodes.length; i < len; i++) { childNode = childNodes[i]; var x = childNode.getPosition().x - px; var y = childNode.getPosition().y - py; childNode.setPosition(Math.cos(angle-_angle) * x - Math.sin(angle-_angle) * y + px, Math.cos(angle-_angle) * y + Math.sin(angle-_angle) * x + py); childNode.setRotation(angle); } this._rotation = angle; return this; }, getRotation: function () { return this._rotation; }, setScale: function (sx, sy) { var that = this, childNodes = this.childNodes, childNode; if (sx === undefined || sx === null) return ; if (sy === undefined || sy === null) { sy = sx; } for (var i = 0, len = childNodes.length; i < len; i++) { childNode = childNodes[i]; if (typeof childNode.setScale === 'function') { childNode.setScale(sx, sy); } } }, getScale: function () { return this._background.getScale(); }, setScaleX: function (sx) { if (sx === undefined || sx === null) return; var that = this, childNodes = this.childNodes, childNode; for (var i = 0, len = childNodes.length; i < len; i++) { childNode = childNodes[i]; if (typeof childNode.setScaleX === 'function') { childNode.setScaleX(sx); } } }, setScaleY: function (sy) { if (sy === undefined || sy === null) return; var that = this, childNodes = this.childNodes, childNode; for (var i = 0, len = childNodes.length; i < len; i++) { childNode = childNodes[i]; if (typeof childNode.setScaleY === 'function') { childNode.setScaleY(sy); } } }, getScaleX: function () { return this._background.getScaleX(); }, getScaleY: function () { return this._background.getScaleY(); }, evert: function () { var that = this, childNodes = this.childNodes, background = this._background, bp = background.getPosition(), bx = bp.x, by = bp.y, childNode, distanceX, distanceY, x, y, p, nx, ny; for (var i = 0, len = childNodes.length; i < len; i++) { childNode = childNodes[i]; p = childNode.getPosition(); x = p.x; y = p.y; distanceX = bx - x; distanceY = by - y; nx = bx + distanceX; ny = by + distanceY; childNode.setPosition(nx, ny); if (typeof childNode.setScale === 'function') { if (!(childNode._disallowEvert === true)) childNode.setScale(-1, -1); } } }, evertX: function () { var that = this, childNodes = this.childNodes, background = this._background, bx = background.getPosition().x, childNode, distance, x, p, nx; for (var i = 0, len = childNodes.length; i < len; i++) { childNode = childNodes[i]; p = childNode.getPosition(); x = p.x; distance = bx - x; nx = bx + distance; childNode.setPosition(nx, p.y); if (typeof childNode.setScaleX === 'function') { if (!(childNode._disallowEvert === true)) childNode.setScaleX(-1); } } }, evertY: function () { var that = this, childNodes = this.childNodes, background = this._background, by = background.getPosition().y, childNode, distance, y, p, ny; for (var i = 0, len = childNodes.length; i < len; i++) { childNode = childNodes[i]; p = childNode.getPosition(); y = p.y; distance = by - y; ny = by + distance; childNode.setPosition(p.x, ny); if (typeof childNode.setScaleY === 'function') { if (!(childNode._disallowEvert === true)) childNode.setScaleY(-1); } } }, attr: function (key, value) { var _attrObj = this._attrObj || {}; if (arguments.length === 1) { return _attrObj[key]; } var childNodes = this.childNodes, childNode; _attrObj[key] = value; for (var i = 0; childNode = childNodes[i++];) { if (typeof childNode.a === 'function') { childNode.a(key, value); } } }, a: function () { return this.attr.apply(this, arguments); } }); }