| 1 |
define(["dijit/Tooltip", "dojo/_base/lang", "dojo/_base/declare", "dojo/_base/window", "dojo/_base/connect", "dojo/dom-style", |
| 2 |
"./PlotAction", "dojox/gfx/matrix", "dojo/has", "dojo/has!dojo-bidi?../bidi/action2d/Tooltip", |
| 3 |
"dojox/lang/functional", "dojox/lang/functional/scan", "dojox/lang/functional/fold"], |
| 4 |
function(DijitTooltip, lang, declare, win, hub, domStyle, PlotAction, m, has, BidiTooltip, df){ |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
var DEFAULT_TEXT = function(o, plot){ |
| 24 |
var t = o.run && o.run.data && o.run.data[o.index]; |
| 25 |
if(t && typeof t != "number" && (t.tooltip || t.text)){ |
| 26 |
return t.tooltip || t.text; |
| 27 |
} |
| 28 |
if(plot.tooltipFunc){ |
| 29 |
return plot.tooltipFunc(o); |
| 30 |
}else{ |
| 31 |
return o.y; |
| 32 |
} |
| 33 |
}; |
| 34 |
|
| 35 |
var pi4 = Math.PI / 4, pi2 = Math.PI / 2; |
| 36 |
|
| 37 |
var Tooltip = declare(has("dojo-bidi")? "dojox.charting.action2d.NonBidiTooltip" : "dojox.charting.action2d.Tooltip", PlotAction, { |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
defaultParams: { |
| 43 |
text: DEFAULT_TEXT, |
| 44 |
mouseOver: true, |
| 45 |
defaultPosition: ["after-centered", "before-centered"] |
| 46 |
}, |
| 47 |
optionalParams: {}, |
| 48 |
|
| 49 |
constructor: function(chart, plot, kwArgs){ |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
this.text = kwArgs && kwArgs.text ? kwArgs.text : DEFAULT_TEXT; |
| 59 |
this.mouseOver = kwArgs && kwArgs.mouseOver != undefined ? kwArgs.mouseOver : true; |
| 60 |
this.defaultPosition = kwArgs && kwArgs.defaultPosition != undefined ? kwArgs.defaultPosition : ["after-centered", "before-centered"]; |
| 61 |
this.connect(); |
| 62 |
}, |
| 63 |
|
| 64 |
process: function(o){ |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
if(o.type === "onplotreset" || o.type === "onmouseout"){ |
| 70 |
DijitTooltip.hide(this.aroundRect); |
| 71 |
this.aroundRect = null; |
| 72 |
if(o.type === "onplotreset"){ |
| 73 |
delete this.angles; |
| 74 |
} |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
if(!o.shape || (this.mouseOver && o.type !== "onmouseover") || (!this.mouseOver && o.type !== "onclick")){ return; } |
| 79 |
|
| 80 |
|
| 81 |
var aroundRect = {type: "rect"}, position = this.defaultPosition; |
| 82 |
switch(o.element){ |
| 83 |
case "marker": |
| 84 |
aroundRect.x = o.cx; |
| 85 |
aroundRect.y = o.cy; |
| 86 |
aroundRect.w = aroundRect.h = 1; |
| 87 |
break; |
| 88 |
case "circle": |
| 89 |
aroundRect.x = o.cx - o.cr; |
| 90 |
aroundRect.y = o.cy - o.cr; |
| 91 |
aroundRect.w = aroundRect.h = 2 * o.cr; |
| 92 |
break; |
| 93 |
case "spider_circle": |
| 94 |
aroundRect.x = o.cx; |
| 95 |
aroundRect.y = o.cy ; |
| 96 |
aroundRect.w = aroundRect.h = 1; |
| 97 |
break; |
| 98 |
case "spider_plot": |
| 99 |
return; |
| 100 |
case "column": |
| 101 |
position = ["above-centered", "below-centered"]; |
| 102 |
|
| 103 |
case "bar": |
| 104 |
aroundRect = lang.clone(o.shape.getShape()); |
| 105 |
aroundRect.w = aroundRect.width; |
| 106 |
aroundRect.h = aroundRect.height; |
| 107 |
break; |
| 108 |
case "candlestick": |
| 109 |
aroundRect.x = o.x; |
| 110 |
aroundRect.y = o.y; |
| 111 |
aroundRect.w = o.width; |
| 112 |
aroundRect.h = o.height; |
| 113 |
break; |
| 114 |
default: |
| 115 |
|
| 116 |
if(!this.angles){ |
| 117 |
|
| 118 |
var filteredRun = typeof o.run.data[0] == "number" ? |
| 119 |
df.map(o.run.data, "x ? Math.max(x, 0) : 0") : df.map(o.run.data, "x ? Math.max(x.y, 0) : 0"); |
| 120 |
this.angles = df.map(df.scanl(filteredRun, "+", 0), |
| 121 |
"* 2 * Math.PI / this", df.foldl(filteredRun, "+", 0)); |
| 122 |
} |
| 123 |
var startAngle = m._degToRad(o.plot.opt.startAngle), |
| 124 |
angle = (this.angles[o.index] + this.angles[o.index + 1]) / 2 + startAngle; |
| 125 |
aroundRect.x = o.cx + o.cr * Math.cos(angle); |
| 126 |
aroundRect.y = o.cy + o.cr * Math.sin(angle); |
| 127 |
aroundRect.w = aroundRect.h = 1; |
| 128 |
|
| 129 |
if(startAngle && (angle < 0 || angle > 2 * Math.PI)){ |
| 130 |
angle = Math.abs(2 * Math.PI - Math.abs(angle)); |
| 131 |
} |
| 132 |
|
| 133 |
if(angle < pi4){ |
| 134 |
|
| 135 |
}else if(angle < pi2 + pi4){ |
| 136 |
position = ["below-centered", "above-centered"]; |
| 137 |
}else if(angle < Math.PI + pi4){ |
| 138 |
position = ["before-centered", "after-centered"]; |
| 139 |
}else if(angle < 2 * Math.PI - pi4){ |
| 140 |
position = ["above-centered", "below-centered"]; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
break; |
| 148 |
} |
| 149 |
if(has("dojo-bidi")){ |
| 150 |
this._recheckPosition(o,aroundRect,position); |
| 151 |
} |
| 152 |
|
| 153 |
var lt = this.chart.getCoords(); |
| 154 |
aroundRect.x += lt.x; |
| 155 |
aroundRect.y += lt.y; |
| 156 |
aroundRect.x = Math.round(aroundRect.x); |
| 157 |
aroundRect.y = Math.round(aroundRect.y); |
| 158 |
aroundRect.w = Math.ceil(aroundRect.w); |
| 159 |
aroundRect.h = Math.ceil(aroundRect.h); |
| 160 |
this.aroundRect = aroundRect; |
| 161 |
|
| 162 |
var tooltipText = this.text(o, this.plot); |
| 163 |
if(tooltipText){ |
| 164 |
DijitTooltip.show(this._format(tooltipText), this.aroundRect, position); |
| 165 |
} |
| 166 |
if(!this.mouseOver){ |
| 167 |
this._handle = hub.connect(win.doc, "onclick", this, "onClick"); |
| 168 |
} |
| 169 |
}, |
| 170 |
onClick: function(){ |
| 171 |
this.process({ type: "onmouseout"}); |
| 172 |
}, |
| 173 |
_recheckPosition: function(obj,rect,position){ |
| 174 |
}, |
| 175 |
_format: function(tooltipText){ |
| 176 |
return tooltipText; |
| 177 |
} |
| 178 |
}); |
| 179 |
return has("dojo-bidi")? declare("dojox.charting.action2d.Tooltip", [Tooltip, BidiTooltip]) : Tooltip; |
| 180 |
}); |