diff options
Diffstat (limited to 'js/dojo-1.7.2/dojox/drawing/annotations')
| -rw-r--r-- | js/dojo-1.7.2/dojox/drawing/annotations/Angle.js | 108 | ||||
| -rw-r--r-- | js/dojo-1.7.2/dojox/drawing/annotations/Arrow.js | 75 | ||||
| -rw-r--r-- | js/dojo-1.7.2/dojox/drawing/annotations/BoxShadow.js | 311 | ||||
| -rw-r--r-- | js/dojo-1.7.2/dojox/drawing/annotations/Label.js | 116 |
4 files changed, 610 insertions, 0 deletions
diff --git a/js/dojo-1.7.2/dojox/drawing/annotations/Angle.js b/js/dojo-1.7.2/dojox/drawing/annotations/Angle.js new file mode 100644 index 0000000..6f09f2a --- /dev/null +++ b/js/dojo-1.7.2/dojox/drawing/annotations/Angle.js @@ -0,0 +1,108 @@ +//>>built +// wrapped by build app +define("dojox/drawing/annotations/Angle", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.drawing.annotations.Angle"); + +dojox.drawing.annotations.Angle = dojox.drawing.util.oo.declare( + // summary: + // When initiated, an HTML box will hover near the Stencil, + // displaying it's angle while drawn or modified. Currently + // only works with Vector, Line, Arrow, and Axes. + // description: + // Annotation is positioned with dojox.drawing.util.positioning.angle + // That method should be overwritten for custom placement. + // Called internally. To initiaize: + // TODO: currently always on + // + function(/*Object*/options){ + // arguments: + // options: Object + // One key value: the stencil that called this. + // + this.stencil = options.stencil; + this.util = options.stencil.util; + this.mouse = options.stencil.mouse; + + this.stencil.connectMult([ + ["onDrag", this, "showAngle"], + ["onUp", this, "hideAngle"], + ["onTransformBegin", this, "showAngle"], + ["onTransform", this, "showAngle"], + ["onTransformEnd", this, "hideAngle"] + ]); + }, + { + type:"dojox.drawing.tools.custom", + angle:0, + + showAngle: function(){ + // summary: + // Called to display angle + // + if(!this.stencil.selected && this.stencil.created){ return; } + if(this.stencil.getRadius() < this.stencil.minimumSize){ + this.hideAngle(); + return; + } + var node = this.getAngleNode(); + var d = this.stencil.pointsToData(); + var pt = dojox.drawing.util.positioning.angle({x:d.x1,y:d.y1},{x:d.x2,y:d.y2}); + var sc = this.mouse.scrollOffset(); + var mx = this.stencil.getTransform(); + var dx = mx.dx / this.mouse.zoom; + var dy = mx.dy / this.mouse.zoom; + pt.x /= this.mouse.zoom; + pt.y /= this.mouse.zoom; + + // adding _offX & _offY since this is HTML + // and we are from the page corner, not + // the canvas corner + var x = this.stencil._offX + pt.x - sc.left + dx; + var y = this.stencil._offY + pt.y - sc.top + dy; + dojo.style(node, { + left: x + "px", + top: y + "px", + align:pt.align + }); + + var angle=this.stencil.getAngle(); + if(this.stencil.style.zAxis && this.stencil.shortType=="vector"){ + node.innerHTML = this.stencil.data.cosphi > 0 ? "out of" : "into"; + }else if(this.stencil.shortType=="line"){ + node.innerHTML = this.stencil.style.zAxis?"out of":Math.ceil(angle%180); + }else{ + node.innerHTML = Math.ceil(angle); + } + }, + + getAngleNode: function(){ + // summary: + // Gets or creates HTMLNode used for display + if(!this._angleNode){ + this._angleNode = dojo.create("span", null, dojo.body()); + dojo.addClass(this._angleNode, "textAnnotation"); + dojo.style(this._angleNode, "opacity", 1); + } + return this._angleNode; //HTMLNode + }, + + hideAngle: function(){ + // summary: + // Turns display off. + // + if(this._angleNode && dojo.style(this._angleNode, "opacity")>0.9){ + + dojo.fadeOut({node:this._angleNode, + duration:500, + onEnd: function(node){ + dojo.destroy(node); + } + }).play(); + this._angleNode = null; + } + + } + } + +); +}); diff --git a/js/dojo-1.7.2/dojox/drawing/annotations/Arrow.js b/js/dojo-1.7.2/dojox/drawing/annotations/Arrow.js new file mode 100644 index 0000000..d069aa0 --- /dev/null +++ b/js/dojo-1.7.2/dojox/drawing/annotations/Arrow.js @@ -0,0 +1,75 @@ +//>>built +// wrapped by build app +define("dojox/drawing/annotations/Arrow", ["dijit","dojo","dojox","dojo/require!dojox/drawing/stencil/Path"], function(dijit,dojo,dojox){ +dojo.provide("dojox.drawing.annotations.Arrow"); +dojo.require("dojox.drawing.stencil.Path"); + +dojox.drawing.annotations.Arrow = dojox.drawing.util.oo.declare( + // summary: + // An annotation called internally to put an arrowhead + // on ether end of a Line. Initiated in Arrow (and Vector) + // with the optional params: arrowStart and arrowEnd. Both + // default true for Axes. + // + dojox.drawing.stencil.Path, + function(/* dojox.__stencilArgs */options){ + // arguments: See stencil._Base + this.stencil.connectMult([ + [this.stencil, "select", this, "select"], + [this.stencil, "deselect", this, "deselect"], + [this.stencil, "render", this, "render"], + [this.stencil, "onDelete", this, "destroy"] + ]); + + this.connect("onBeforeRender", this, function(){ + var o = this.stencil.points[this.idx1]; + var c = this.stencil.points[this.idx2]; + if(this.stencil.getRadius() >= this.minimumSize){ + this.points = this.arrowHead(c.x, c.y, o.x, o.y, this.style); + }else{ + this.points = []; + } + }); + + }, + { + idx1:0, + idx2:1, + + subShape:true, + minimumSize:30, + //annotation:true, NOT! + + arrowHead: function(x1, y1, x2, y2, style){ + // summary: + // Creates data used to draw arrow head. + // + var obj = { + start:{ + x:x1, + y:y1 + }, + x:x2, + y:y2 + } + var angle = this.util.angle(obj); + + var lineLength = this.util.length(obj); + var al = style.arrows.length; + var aw = style.arrows.width/2; + if(lineLength<al){ + al = lineLength/2; + } + var p1 = this.util.pointOnCircle(x2, y2, -al, angle-aw); + var p2 = this.util.pointOnCircle(x2, y2, -al, angle+aw); + + return [ + {x:x2, y:y2}, + p1, + p2 + ]; + } + + } +); +}); diff --git a/js/dojo-1.7.2/dojox/drawing/annotations/BoxShadow.js b/js/dojo-1.7.2/dojox/drawing/annotations/BoxShadow.js new file mode 100644 index 0000000..be39725 --- /dev/null +++ b/js/dojo-1.7.2/dojox/drawing/annotations/BoxShadow.js @@ -0,0 +1,311 @@ +//>>built +// wrapped by build app +define("dojox/drawing/annotations/BoxShadow", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.drawing.annotations.BoxShadow"); + +dojox.drawing.annotations.BoxShadow = dojox.drawing.util.oo.declare( + // summary: + // Creates a box shadow under solid objects. Can change the + // shadow direction, color, size, and intensity. Can center + // the shadow and make it a Glow. + // description: + // This is a psuedo shadow, created by duplicating the + // original stencil and increasing the line weight while + // reducing the opacity. Therefore it will not work with + // text. Also won't look very good if the Stencil has no + // fill or is transparent. Can't do knockouts or inner + // shadows. Currently can't do paths - while doable, it + // will most likely choke IE into certain death. + // + function(/*Object*/options){ + this.stencil = options.stencil; + this.util = options.stencil.util; + this.mouse = options.stencil.mouse; + this.style = options.stencil.style; + + var shadowDefaults = { + // summary: + // When passing a shadow object into a stencil, that shadow + // object will be mixed in with these defaults. + // + // size: Number, mult: Number + // These two props work together. Both affect the size and quality + // of the shadow. size affects the actual size and mult affects the + // lineWidths that overlap to make the shadow. Generally you want a + // bigger 'size' than 'mult'. The defaults are good for a shadow, but + // you will want to increase them when making a glow. + // TODO: Make this more clear or use other properties. + size:6, + mult:4, + // alpha: Float + // Affects the alpha of the shadow. Because this is multiple shapes + // overlapped, you want much less than you may think. .1 is pretty + // dark and . is black. Higher numbers also give a sharper edge. + alpha:.05, + // place: String + // Tells the position of the shadow: + // B: bottom + // T: top + // L: left + // R: right + // C: center, or a glow + // Can be used in combinations such as BR, BL, L, T, etc. 'C' should + // be used by itself. + place:"BR", + // color: String + // The color of the shadow or glow. + color:"#646464" + } + + delete options.stencil; + this.options = dojo.mixin(shadowDefaults, options); + this.options.color = new dojo.Color(this.options.color) + this.options.color.a = this.options.alpha; + switch(this.stencil.shortType){ + case "image": + case "rect": + this.method = "createForRect"; break; + case "ellipse": + this.method = "createForEllipse"; break; + case "line": + this.method = "createForLine"; break; + case "path": + this.method = "createForPath"; break; + // path is a bit of a hassle. Plus I think in IE it would be + //slower than the political process. Maybe TODO. + case "vector": + this.method = "createForZArrow"; break; + default: + console.warn("A shadow cannot be made for Stencil type ", this.stencil.type); + } + + if(this.method){ + this.render(); + this.stencil.connectMult([ + [this.stencil, "onTransform", this, "onTransform"], + this.method=="createForZArrow"?[this.stencil, "render", this, "render"]:[this.stencil, "render", this, "onRender"], + [this.stencil, "onDelete", this, "destroy"] + ]); + } + }, + { + showing:true, + render: function(){ + if(this.container){ + this.container.removeShape(); + } + this.container = this.stencil.container.createGroup(); + this.container.moveToBack(); + + var o = this.options, + size = o.size, + mult = o.mult, + d = this.method == "createForPath" + ? this.stencil.points + : this.stencil.data, + r = d.r || 1, + p = o.place, + c = o.color; + + this[this.method](o, size, mult, d, r, p, c); + }, + + hide: function(){ + if(this.showing){ + this.showing = false; + this.container.removeShape(); + } + }, + + show: function(){ + if(!this.showing){ + this.showing = true; + this.stencil.container.add(this.container); + } + }, + + createForPath: function(o, size, mult, pts, r, p, c){ + var sh = size * mult / 4, + shy = /B/.test(p) ? sh : /T/.test(p) ? sh*-1 : 0, + shx = /R/.test(p) ? sh : /L/.test(p) ? sh*-1 : 0; + + var closePath = true; + + for(var i=1;i<=size;i++){ + var lineWidth = i * mult; + //var rect = this.container.createLine({x1:d.x1+shx, y1:d.y1+shy, x2:d.x2+shx, y2:d.y2+shy}) + // .setStroke({width:lineWidth, color:c, cap:"round"}) + + if(dojox.gfx.renderer=="svg"){ + var strAr = []; + dojo.forEach(pts, function(o, i){ + if(i==0){ + strAr.push("M " + (o.x+shx) +" "+ (o.y+shy)); + }else{ + var cmd = o.t || "L "; + strAr.push(cmd + (o.x+shx) +" "+ (o.y+shy)); // Z + undefined works here + } + }, this); + if(closePath){ + strAr.push("Z"); + } + this.container.createPath(strAr.join(", ")).setStroke({width:lineWidth, color:c, cap:"round"}) + + }else{ + // Leaving this code for VML. It seems slightly faster but times vary. + var pth = this.container.createPath({}).setStroke({width:lineWidth, color:c, cap:"round"}) + + dojo.forEach(this.points, function(o, i){ + if(i==0 || o.t=="M"){ + pth.moveTo(o.x+shx, o.y+shy); + }else if(o.t=="Z"){ + closePath && pth.closePath(); + }else{ + pth.lineTo(o.x+shx, o.y+shy); + } + }, this); + + closePath && pth.closePath(); + } + + + } + }, + + createForLine: function(o, size, mult, d, r, p, c){ + + var sh = size * mult / 4, + shy = /B/.test(p) ? sh : /T/.test(p) ? sh*-1 : 0, + shx = /R/.test(p) ? sh : /L/.test(p) ? sh*-1 : 0; + for(var i=1;i<=size;i++){ + var lineWidth = i * mult; + this.container.createLine({x1:d.x1+shx, y1:d.y1+shy, x2:d.x2+shx, y2:d.y2+shy}) + .setStroke({width:lineWidth, color:c, cap:"round"}) + } + }, + createForEllipse: function(o, size, mult, d, r, p, c){ + + var sh = size * mult / 8, + shy = /B/.test(p) ? sh : /T/.test(p) ? sh*-1 : 0, + shx = /R/.test(p) ? sh*.8 : /L/.test(p) ? sh*-.8 : 0; + + for(var i=1;i<=size;i++){ + var lineWidth = i * mult; + this.container.createEllipse({cx:d.cx+shx, cy:d.cy+shy, rx:d.rx-sh, ry:d.ry-sh, r:r}) + .setStroke({width:lineWidth, color:c}) + } + }, + + createForRect: function(o, size, mult, d, r, p, c){ + + var sh = size * mult / 2, + shy = /B/.test(p) ? sh : /T/.test(p) ? 0 : sh /2, + shx = /R/.test(p) ? sh : /L/.test(p) ? 0 : sh /2; + + for(var i=1;i<=size;i++){ + var lineWidth = i * mult; + this.container.createRect({x:d.x+shx, y:d.y+shy, width:d.width-sh, height:d.height-sh, r:r}) + .setStroke({width:lineWidth, color:c}) + } + }, + + arrowPoints: function(){ + // summary: + // Creates data used to draw arrow head. + // + var d = this.stencil.data; + var radius = this.stencil.getRadius(); + var angle = this.style.zAngle + 30; + + var pt = this.util.pointOnCircle(d.x1, d.y1, radius*.75, angle); + + var obj = { + start:{ + x:d.x1, + y:d.y1 + }, + x:pt.x, + y:pt.y + } + var angle = this.util.angle(obj); + var lineLength = this.util.length(obj); + var al = this.style.arrows.length; + var aw = this.style.arrows.width/3; + if(lineLength<al){ + al = lineLength/2; + } + + var p1 = this.util.pointOnCircle(obj.x, obj.y, -al, angle-aw); + var p2 = this.util.pointOnCircle(obj.x, obj.y, -al, angle+aw); + return [ + {x:obj.x, y:obj.y}, + p1, + p2 + ]; + }, + + createForZArrow: function(o, size, mult, pts, r, p, c){ + if(this.stencil.data.cosphi<1 || !this.stencil.points[0]){ return; } + var sh = size * mult / 4, + shy = /B/.test(p) ? sh : /T/.test(p) ? sh*-1 : 0, + shx = /R/.test(p) ? sh : /L/.test(p) ? sh*-1 : 0; + var closePath = true; + for(var i=1;i<=size;i++){ + var lineWidth = i * mult; + pts = this.arrowPoints(); + if(!pts){ return; } + if(dojox.gfx.renderer=="svg"){ + + var strAr = []; + dojo.forEach(pts, function(o, i){ + if(i==0){ + strAr.push("M " + (o.x+shx) +" "+ (o.y+shy)); + }else{ + var cmd = o.t || "L "; + strAr.push(cmd + (o.x+shx) +" "+ (o.y+shy)); // Z + undefined works here + } + }, this); + if(closePath){ + strAr.push("Z"); + } + + this.container.createPath(strAr.join(", ")).setStroke({width:lineWidth, color:c, cap:"round"}).setFill(c); + + }else{ + // Leaving this code for VML. It seems slightly faster but times vary. + var pth = this.container.createPath({}).setStroke({width:lineWidth, color:c, cap:"round"}) + + dojo.forEach(pts, function(o, i){ + if(i==0 || o.t=="M"){ + pth.moveTo(o.x+shx, o.y+shy); + }else if(o.t=="Z"){ + closePath && pth.closePath(); + }else{ + pth.lineTo(o.x+shx, o.y+shy); + } + }, this); + + closePath && pth.closePath(); + } + var sp = this.stencil.points; + this.container.createLine({x1:sp[0].x, y1:sp[0].y, x2:pts[0].x, y2:pts[0].y}) + .setStroke({width:lineWidth, color:c, cap:"round"}); + + } + }, + + + onTransform: function(){ + this.render(); + }, + onRender: function(){ + this.container.moveToBack(); + }, + destroy: function(){ + if(this.container){ + this.container.removeShape(); + } + } + } +); +}); diff --git a/js/dojo-1.7.2/dojox/drawing/annotations/Label.js b/js/dojo-1.7.2/dojox/drawing/annotations/Label.js new file mode 100644 index 0000000..22b9d32 --- /dev/null +++ b/js/dojo-1.7.2/dojox/drawing/annotations/Label.js @@ -0,0 +1,116 @@ +//>>built +// wrapped by build app +define("dojox/drawing/annotations/Label", ["dijit","dojo","dojox","dojo/require!dojox/drawing/stencil/Text"], function(dijit,dojo,dojox){ +dojo.provide("dojox.drawing.annotations.Label"); +dojo.require("dojox.drawing.stencil.Text"); + +dojox.drawing.annotations.Label = dojox.drawing.util.oo.declare( + // summary: + // An annotation called internally to label an Stencil. + // description: + // Annotation is positioned with dojox.drawing.util.positioning.label + // That method should be overwritten for custom placement. Or, + // add a 'setLabelCustom' method to the Stencil and it will be used. + // + dojox.drawing.stencil.Text, + function(/*Object*/options){ + // arguments: + // options: Object + // One key value: the stencil that called this. + // + this.master = options.stencil; + this.labelPosition = options.labelPosition || "BR"; // TL, TR, BR, BL, or function + if(dojo.isFunction(this.labelPosition)){ + this.setLabel = this.setLabelCustom; + } + this.setLabel(options.text || ""); + this.connect(this.master, "onTransform", this, "setLabel"); + this.connect(this.master, "destroy", this, "destroy"); + + if(this.style.labelSameColor){ + this.connect(this.master, "attr", this, "beforeAttr"); + } + },{ + _align:"start", + drawingType:"label", + + setLabelCustom: function(/* ? String */text){ + // summary: + // Attaches to custom positioning within a Stencil + // + var d = dojo.hitch(this.master, this.labelPosition)(); + this.setData({ + x:d.x, + y:d.y, + width:d.w || this.style.text.minWidth, + height:d.h || this._lineHeight + }); + + // is an event, not text, so keep the old label: + if(text && !text.split){ text = this.getText(); } + + this.render(this.typesetter(text)); + }, + + setLabel: function(/* String */text){ + // summary: + // Sets the text of the label. Not called directly. Should + // be called within Stencil. See stencil._Base + // + // onTransform will pass an object here + var x, y, box = this.master.getBounds(); + + if(/B/.test(this.labelPosition)){ + y = box.y2 - this._lineHeight; + }else{ + y = box.y1; + } + + if(/R/.test(this.labelPosition)){ + x = box.x2; + }else{ + y = box.y1; + this._align = "end"; + } + + if(!this.labelWidth || (text && text.split && text != this.getText())){ + this.setData({ + x:x, + y:y, + height:this._lineHeight, + width:this.style.text.minWidth + }); + + this.labelWidth = this.style.text.minWidth; + this.render(this.typesetter(text)); + + }else{ + + this.setData({ + x:x, + y:y, + height:this.data.height, + width:this.data.width + }); + + this.render(); + } + + }, + beforeAttr: function(key, value){ + if(value!==undefined){ + // make it an object + var k = key; key = {}; key[k] = value; + } + delete key.x; + delete key.y; + delete key.width; + delete key.height; + this.attr(key); + // FIXME: this.created should already be set, shouldn't it? + !this.created && this.render(); + } + } + +); +}); |
