| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
(function($) { |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
$.jqplot.CanvasAxisTickRenderer = function(options) { |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
this.mark = 'outside'; |
| 51 |
|
| 52 |
|
| 53 |
this.showMark = true; |
| 54 |
|
| 55 |
|
| 56 |
this.showGridline = true; |
| 57 |
|
| 58 |
|
| 59 |
this.isMinorTick = false; |
| 60 |
|
| 61 |
|
| 62 |
this.angle = 0; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
this.markSize = 4; |
| 67 |
|
| 68 |
|
| 69 |
this.show = true; |
| 70 |
|
| 71 |
|
| 72 |
this.showLabel = true; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
this.labelPosition = 'auto'; |
| 78 |
this.label = ''; |
| 79 |
this.value = null; |
| 80 |
this._styles = {}; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
this.formatter = $.jqplot.DefaultTickFormatter; |
| 85 |
|
| 86 |
|
| 87 |
this.formatString = ''; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
this.prefix = ''; |
| 92 |
|
| 93 |
|
| 94 |
this.fontFamily = '"Trebuchet MS", Arial, Helvetica, sans-serif'; |
| 95 |
|
| 96 |
|
| 97 |
this.fontSize = '10pt'; |
| 98 |
|
| 99 |
|
| 100 |
this.fontWeight = 'normal'; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
this.fontStretch = 1.0; |
| 105 |
|
| 106 |
|
| 107 |
this.textColor = '#666666'; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
this.enableFontSupport = true; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
this.pt2px = null; |
| 121 |
|
| 122 |
this._elem; |
| 123 |
this._ctx; |
| 124 |
this._plotWidth; |
| 125 |
this._plotHeight; |
| 126 |
this._plotDimensions = {height:null, width:null}; |
| 127 |
|
| 128 |
$.extend(true, this, options); |
| 129 |
|
| 130 |
var ropts = {fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily}; |
| 131 |
if (this.pt2px) { |
| 132 |
ropts.pt2px = this.pt2px; |
| 133 |
} |
| 134 |
|
| 135 |
if (this.enableFontSupport) { |
| 136 |
if ($.jqplot.support_canvas_text()) { |
| 137 |
this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts); |
| 138 |
} |
| 139 |
|
| 140 |
else { |
| 141 |
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts); |
| 142 |
} |
| 143 |
} |
| 144 |
else { |
| 145 |
this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts); |
| 146 |
} |
| 147 |
}; |
| 148 |
|
| 149 |
$.jqplot.CanvasAxisTickRenderer.prototype.init = function(options) { |
| 150 |
$.extend(true, this, options); |
| 151 |
this._textRenderer.init({fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily}); |
| 152 |
}; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
$.jqplot.CanvasAxisTickRenderer.prototype.getWidth = function(ctx) { |
| 158 |
if (this._elem) { |
| 159 |
return this._elem.outerWidth(true); |
| 160 |
} |
| 161 |
else { |
| 162 |
var tr = this._textRenderer; |
| 163 |
var l = tr.getWidth(ctx); |
| 164 |
var h = tr.getHeight(ctx); |
| 165 |
var w = Math.abs(Math.sin(tr.angle)*h) + Math.abs(Math.cos(tr.angle)*l); |
| 166 |
return w; |
| 167 |
} |
| 168 |
}; |
| 169 |
|
| 170 |
|
| 171 |
$.jqplot.CanvasAxisTickRenderer.prototype.getHeight = function(ctx) { |
| 172 |
if (this._elem) { |
| 173 |
return this._elem.outerHeight(true); |
| 174 |
} |
| 175 |
else { |
| 176 |
var tr = this._textRenderer; |
| 177 |
var l = tr.getWidth(ctx); |
| 178 |
var h = tr.getHeight(ctx); |
| 179 |
var w = Math.abs(Math.cos(tr.angle)*h) + Math.abs(Math.sin(tr.angle)*l); |
| 180 |
return w; |
| 181 |
} |
| 182 |
}; |
| 183 |
|
| 184 |
|
| 185 |
$.jqplot.CanvasAxisTickRenderer.prototype.getTop = function(ctx) { |
| 186 |
if (this._elem) { |
| 187 |
return this._elem.position().top; |
| 188 |
} |
| 189 |
else { |
| 190 |
return null; |
| 191 |
} |
| 192 |
}; |
| 193 |
|
| 194 |
$.jqplot.CanvasAxisTickRenderer.prototype.getAngleRad = function() { |
| 195 |
var a = this.angle * Math.PI/180; |
| 196 |
return a; |
| 197 |
}; |
| 198 |
|
| 199 |
|
| 200 |
$.jqplot.CanvasAxisTickRenderer.prototype.setTick = function(value, axisName, isMinor) { |
| 201 |
this.value = value; |
| 202 |
if (isMinor) { |
| 203 |
this.isMinorTick = true; |
| 204 |
} |
| 205 |
return this; |
| 206 |
}; |
| 207 |
|
| 208 |
$.jqplot.CanvasAxisTickRenderer.prototype.draw = function(ctx, plot) { |
| 209 |
if (!this.label) { |
| 210 |
this.label = this.prefix + this.formatter(this.formatString, this.value); |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
if (this._elem) { |
| 215 |
if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) { |
| 216 |
window.G_vmlCanvasManager.uninitElement(this._elem.get(0)); |
| 217 |
} |
| 218 |
|
| 219 |
this._elem.emptyForce(); |
| 220 |
this._elem = null; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
var elem = plot.canvasManager.getCanvas(); |
| 227 |
|
| 228 |
this._textRenderer.setText(this.label, ctx); |
| 229 |
var w = this.getWidth(ctx); |
| 230 |
var h = this.getHeight(ctx); |
| 231 |
|
| 232 |
elem.width = w; |
| 233 |
elem.height = h; |
| 234 |
elem.style.width = w; |
| 235 |
elem.style.height = h; |
| 236 |
elem.style.textAlign = 'left'; |
| 237 |
elem.style.position = 'absolute'; |
| 238 |
|
| 239 |
elem = plot.canvasManager.initCanvas(elem); |
| 240 |
|
| 241 |
this._elem = $(elem); |
| 242 |
this._elem.css(this._styles); |
| 243 |
this._elem.addClass('jqplot-'+this.axis+'-tick'); |
| 244 |
|
| 245 |
elem = null; |
| 246 |
return this._elem; |
| 247 |
}; |
| 248 |
|
| 249 |
$.jqplot.CanvasAxisTickRenderer.prototype.pack = function() { |
| 250 |
this._textRenderer.draw(this._elem.get(0).getContext("2d"), this.label); |
| 251 |
}; |
| 252 |
|
| 253 |
})(jQuery); |