root / trunk / web / dojo / dojox / charting / action2d / Tooltip.js @ 13
History | View | Annotate | Download (5.96 KB)
| 1 | 9 | andrej.cim | /*
|
|---|---|---|---|
| 2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
| 3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
| 4 | see: http://dojotoolkit.org/license for details
|
||
| 5 | */
|
||
| 6 | |||
| 7 | |||
| 8 | if(!dojo._hasResource["dojox.charting.action2d.Tooltip"]){ |
||
| 9 | dojo._hasResource["dojox.charting.action2d.Tooltip"]=true; |
||
| 10 | dojo.provide("dojox.charting.action2d.Tooltip");
|
||
| 11 | dojo.require("dojox.charting.action2d.Base");
|
||
| 12 | dojo.require("dojox.gfx.matrix");
|
||
| 13 | dojo.require("dijit.Tooltip");
|
||
| 14 | dojo.require("dojox.lang.functional");
|
||
| 15 | dojo.require("dojox.lang.functional.scan");
|
||
| 16 | dojo.require("dojox.lang.functional.fold");
|
||
| 17 | (function(){
|
||
| 18 | var _1=function(o){ |
||
| 19 | var t=o.run&&o.run.data&&o.run.data[o.index];
|
||
| 20 | if(t&&typeof t!="number"&&(t.tooltip||t.text)){ |
||
| 21 | return t.tooltip||t.text;
|
||
| 22 | } |
||
| 23 | if(o.element=="candlestick"){ |
||
| 24 | return "<table cellpadding=\"1\" cellspacing=\"0\" border=\"0\" style=\"font-size:0.9em;\">"+"<tr><td>Open:</td><td align=\"right\"><strong>"+o.data.open+"</strong></td></tr>"+"<tr><td>High:</td><td align=\"right\"><strong>"+o.data.high+"</strong></td></tr>"+"<tr><td>Low:</td><td align=\"right\"><strong>"+o.data.low+"</strong></td></tr>"+"<tr><td>Close:</td><td align=\"right\"><strong>"+o.data.close+"</strong></td></tr>"+(o.data.mid!==undefined?"<tr><td>Mid:</td><td align=\"right\"><strong>"+o.data.mid+"</strong></td></tr>":"")+"</table>"; |
||
| 25 | } |
||
| 26 | return o.element=="bar"?o.x:o.y; |
||
| 27 | }; |
||
| 28 | var df=dojox.lang.functional,m=dojox.gfx.matrix,_2=Math.PI/4,_3=Math.PI/2; |
||
| 29 | dojo.declare("dojox.charting.action2d.Tooltip",dojox.charting.action2d.Base,{defaultParams:{text:_1},optionalParams:{},constructor:function(_4,_5,_6){ |
||
| 30 | this.text=_6&&_6.text?_6.text:_1;
|
||
| 31 | this.connect();
|
||
| 32 | },process:function(o){ |
||
| 33 | if(o.type==="onplotreset"||o.type==="onmouseout"){ |
||
| 34 | _7(this.aroundRect);
|
||
| 35 | this.aroundRect=null; |
||
| 36 | return;
|
||
| 37 | } |
||
| 38 | if(!o.shape||o.type!=="onmouseover"){ |
||
| 39 | return;
|
||
| 40 | } |
||
| 41 | var _8={type:"rect"},_9=["after","before"]; |
||
| 42 | switch(o.element){
|
||
| 43 | case "marker": |
||
| 44 | _8.x=o.cx; |
||
| 45 | _8.y=o.cy; |
||
| 46 | _8.width=_8.height=1;
|
||
| 47 | break;
|
||
| 48 | case "circle": |
||
| 49 | _8.x=o.cx-o.cr; |
||
| 50 | _8.y=o.cy-o.cr; |
||
| 51 | _8.width=_8.height=2*o.cr;
|
||
| 52 | break;
|
||
| 53 | case "column": |
||
| 54 | _9=["above","below"]; |
||
| 55 | case "bar": |
||
| 56 | _8=dojo.clone(o.shape.getShape()); |
||
| 57 | break;
|
||
| 58 | case "candlestick": |
||
| 59 | _8.x=o.x; |
||
| 60 | _8.y=o.y; |
||
| 61 | _8.width=o.width; |
||
| 62 | _8.height=o.height; |
||
| 63 | break;
|
||
| 64 | default:
|
||
| 65 | if(!this.angles){ |
||
| 66 | if(typeof o.run.data[0]=="number"){ |
||
| 67 | this.angles=df.map(df.scanl(o.run.data,"+",0),"* 2 * Math.PI / this",df.foldl(o.run.data,"+",0)); |
||
| 68 | }else{
|
||
| 69 | this.angles=df.map(df.scanl(o.run.data,"a + b.y",0),"* 2 * Math.PI / this",df.foldl(o.run.data,"a + b.y",0)); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | var _a=m._degToRad(o.plot.opt.startAngle),_b=(this.angles[o.index]+this.angles[o.index+1])/2+_a; |
||
| 73 | _8.x=o.cx+o.cr*Math.cos(_b); |
||
| 74 | _8.y=o.cy+o.cr*Math.sin(_b); |
||
| 75 | _8.width=_8.height=1;
|
||
| 76 | if(_b<_2){
|
||
| 77 | }else{
|
||
| 78 | if(_b<_3+_2){
|
||
| 79 | _9=["below","above"]; |
||
| 80 | }else{
|
||
| 81 | if(_b<Math.PI+_2){
|
||
| 82 | _9=["before","after"]; |
||
| 83 | }else{
|
||
| 84 | if(_b<2*Math.PI-_2){ |
||
| 85 | _9=["above","below"]; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | break;
|
||
| 91 | } |
||
| 92 | var lt=dojo.coords(this.chart.node,true); |
||
| 93 | _8.x+=lt.x; |
||
| 94 | _8.y+=lt.y; |
||
| 95 | _8.x=Math.round(_8.x); |
||
| 96 | _8.y=Math.round(_8.y); |
||
| 97 | _8.width=Math.ceil(_8.width); |
||
| 98 | _8.height=Math.ceil(_8.height); |
||
| 99 | this.aroundRect=_8;
|
||
| 100 | _c(this.text(o),this.aroundRect,_9,"center"); |
||
| 101 | }}); |
||
| 102 | var _d=dojo.declare(dijit._MasterTooltip,{show:function(_e,_f,_10,_11){ |
||
| 103 | if(this.aroundNode&&this.aroundNode===_f){ |
||
| 104 | return;
|
||
| 105 | } |
||
| 106 | if(this.fadeOut.status()=="playing"){ |
||
| 107 | this._onDeck=arguments; |
||
| 108 | return;
|
||
| 109 | } |
||
| 110 | this.containerNode.innerHTML=_e;
|
||
| 111 | this.domNode.style.top=(this.domNode.offsetTop+1)+"px"; |
||
| 112 | if(!this.connectorNode){ |
||
| 113 | this.connectorNode=dojo.query(".dijitTooltipConnector",this.domNode)[0]; |
||
| 114 | } |
||
| 115 | var _12=dojo.coords(this.connectorNode); |
||
| 116 | this.arrowWidth=_12.w,this.arrowHeight=_12.h; |
||
| 117 | this.place=(_11&&_11=="center")?this.placeChartingTooltip:dijit.placeOnScreenAroundElement,this.place(this.domNode,_f,dijit.getPopupAroundAlignment((_10&&_10.length)?_10:dijit.Tooltip.defaultPosition,this.isLeftToRight()),dojo.hitch(this,"orient")); |
||
| 118 | dojo.style(this.domNode,"opacity",0); |
||
| 119 | this.fadeIn.play();
|
||
| 120 | this.isShowingNow=true; |
||
| 121 | this.aroundNode=_f;
|
||
| 122 | },placeChartingTooltip:function(_13,_14,_15,_16){ |
||
| 123 | return this._placeOnScreenAroundRect(_13,_14.x,_14.y,_14.width,_14.height,_15,_16); |
||
| 124 | },_placeOnScreenAroundRect:function(_17,x,y,_18,_19,_1a,_1b){ |
||
| 125 | var _1c=[];
|
||
| 126 | for(var _1d in _1a){ |
||
| 127 | _1c.push({aroundCorner:_1d,corner:_1a[_1d],pos:{x:x+(_1d.charAt(1)=="L"?0:_18),y:y+(_1d.charAt(0)=="T"?0:_19),w:_18,h:_19}});
|
||
| 128 | } |
||
| 129 | return this._place(_17,_1c,_1b); |
||
| 130 | },_place:function(_1e,_1f,_20){ |
||
| 131 | var _21=dijit.getViewport();
|
||
| 132 | if(!_1e.parentNode||String(_1e.parentNode.tagName).toLowerCase()!="body"){ |
||
| 133 | dojo.body().appendChild(_1e); |
||
| 134 | } |
||
| 135 | var _22=null; |
||
| 136 | var _23=null,_24=null; |
||
| 137 | dojo.some(_1f,function(_25){
|
||
| 138 | var _26=_25.corner;
|
||
| 139 | var _27=_25.aroundCorner;
|
||
| 140 | var pos=_25.pos;
|
||
| 141 | if(_20){
|
||
| 142 | _20(_1e,_25.aroundCorner,_26); |
||
| 143 | } |
||
| 144 | var _28=_1e.style;
|
||
| 145 | var _29=_28.display;
|
||
| 146 | var _2a=_28.visibility;
|
||
| 147 | _28.visibility="hidden";
|
||
| 148 | _28.display="";
|
||
| 149 | var mb=dojo.marginBox(_1e);
|
||
| 150 | _28.display=_29; |
||
| 151 | _28.visibility=_2a; |
||
| 152 | var _2b,_2c,_2d,_2e,_2f,_30,_31;
|
||
| 153 | _23=null,_24=null; |
||
| 154 | if(_27.charAt(0)==_26.charAt(0)){ |
||
| 155 | _2b=(_26.charAt(1)=="L"?pos.x:Math.max(_21.l,pos.x-mb.w)),_2c=(_26.charAt(0)=="T"?(pos.y+pos.h/2-mb.h/2):(pos.y-pos.h/2-mb.h/2)),_2d=(_26.charAt(1)=="L"?Math.min(_21.l+_21.w,_2b+mb.w):pos.x),_2e=_2c+mb.h,_2f=_2d-_2b,_30=_2e-_2c,_31=(mb.w-_2f)+(mb.h-_30); |
||
| 156 | _24=(mb.h-this.arrowHeight)/2; |
||
| 157 | }else{
|
||
| 158 | _2b=(_26.charAt(1)=="L"?(pos.x+pos.w/2-mb.w/2):(pos.x-pos.w/2-mb.w/2)),_2c=(_26.charAt(0)=="T"?pos.y:Math.max(_21.t,pos.y-mb.h)),_2d=_2b+mb.w,_2e=(_26.charAt(0)=="T"?Math.min(_21.t+_21.h,_2c+mb.h):pos.y),_2f=_2d-_2b,_30=_2e-_2c,_31=(mb.w-_2f)+(mb.h-_30); |
||
| 159 | _23=(mb.w-this.arrowWidth)/2; |
||
| 160 | } |
||
| 161 | if(_22==null||_31<_22.overflow){ |
||
| 162 | _22={corner:_26,aroundCorner:_25.aroundCorner,x:_2b,y:_2c,w:_2f,h:_30,overflow:_31};
|
||
| 163 | } |
||
| 164 | return !_31;
|
||
| 165 | },this);
|
||
| 166 | _1e.style.left=_22.x+"px";
|
||
| 167 | _1e.style.top=_22.y+"px";
|
||
| 168 | this.connectorNode.style.top=""; |
||
| 169 | this.connectorNode.style.left=""; |
||
| 170 | if(_24){
|
||
| 171 | this.connectorNode.style.top=_24+"px"; |
||
| 172 | } |
||
| 173 | if(_23){
|
||
| 174 | this.connectorNode.style.left=_23+"px"; |
||
| 175 | } |
||
| 176 | if(_22.overflow&&_20){
|
||
| 177 | _20(_1e,_22.aroundCorner,_22.corner); |
||
| 178 | } |
||
| 179 | return _22;
|
||
| 180 | }}); |
||
| 181 | var _32=null; |
||
| 182 | function _c(_33,_34,_35,_36){ |
||
| 183 | if(!_32){
|
||
| 184 | _32=new _d();
|
||
| 185 | } |
||
| 186 | return _32.show(_33,_34,_35,_36);
|
||
| 187 | }; |
||
| 188 | function _7(_37){ |
||
| 189 | if(!_32){
|
||
| 190 | _32=new _d();
|
||
| 191 | } |
||
| 192 | return _32.hide(_37);
|
||
| 193 | }; |
||
| 194 | })(); |
||
| 195 | } |