123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- (function($) {
-
- $.jqplot.CanvasAxisLabelRenderer = function(options) {
-
-
-
-
- this.angle = 0;
-
- this.axis;
-
-
- this.show = true;
-
-
- this.showLabel = true;
-
-
- this.label = '';
-
-
-
-
- this.fontFamily = '"Trebuchet MS", Arial, Helvetica, sans-serif';
-
-
- this.fontSize = '11pt';
-
-
- this.fontWeight = 'normal';
-
-
-
- this.fontStretch = 1.0;
-
-
- this.textColor = '#666666';
-
-
-
-
- this.enableFontSupport = true;
-
-
-
-
-
-
-
- this.pt2px = null;
-
- this._elem;
- this._ctx;
- this._plotWidth;
- this._plotHeight;
- this._plotDimensions = {height:null, width:null};
-
- $.extend(true, this, options);
-
- if (options.angle == null && this.axis != 'xaxis' && this.axis != 'x2axis') {
- this.angle = -90;
- }
-
- var ropts = {fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily};
- if (this.pt2px) {
- ropts.pt2px = this.pt2px;
- }
-
- if (this.enableFontSupport) {
- if ($.jqplot.support_canvas_text()) {
- this._textRenderer = new $.jqplot.CanvasFontRenderer(ropts);
- }
-
- else {
- this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
- }
- }
- else {
- this._textRenderer = new $.jqplot.CanvasTextRenderer(ropts);
- }
- };
-
- $.jqplot.CanvasAxisLabelRenderer.prototype.init = function(options) {
- $.extend(true, this, options);
- this._textRenderer.init({fontSize:this.fontSize, fontWeight:this.fontWeight, fontStretch:this.fontStretch, fillStyle:this.textColor, angle:this.getAngleRad(), fontFamily:this.fontFamily});
- };
-
-
-
-
- $.jqplot.CanvasAxisLabelRenderer.prototype.getWidth = function(ctx) {
- if (this._elem) {
- return this._elem.outerWidth(true);
- }
- else {
- var tr = this._textRenderer;
- var l = tr.getWidth(ctx);
- var h = tr.getHeight(ctx);
- var w = Math.abs(Math.sin(tr.angle)*h) + Math.abs(Math.cos(tr.angle)*l);
- return w;
- }
- };
-
-
- $.jqplot.CanvasAxisLabelRenderer.prototype.getHeight = function(ctx) {
- if (this._elem) {
- return this._elem.outerHeight(true);
- }
- else {
- var tr = this._textRenderer;
- var l = tr.getWidth(ctx);
- var h = tr.getHeight(ctx);
- var w = Math.abs(Math.cos(tr.angle)*h) + Math.abs(Math.sin(tr.angle)*l);
- return w;
- }
- };
-
- $.jqplot.CanvasAxisLabelRenderer.prototype.getAngleRad = function() {
- var a = this.angle * Math.PI/180;
- return a;
- };
-
- $.jqplot.CanvasAxisLabelRenderer.prototype.draw = function(ctx, plot) {
-
- if (this._elem) {
- if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
- window.G_vmlCanvasManager.uninitElement(this._elem.get(0));
- }
-
- this._elem.emptyForce();
- this._elem = null;
- }
-
-
- var elem = plot.canvasManager.getCanvas();
- this._textRenderer.setText(this.label, ctx);
- var w = this.getWidth(ctx);
- var h = this.getHeight(ctx);
- elem.width = w;
- elem.height = h;
- elem.style.width = w;
- elem.style.height = h;
-
- elem = plot.canvasManager.initCanvas(elem);
-
- this._elem = $(elem);
- this._elem.css({ position: 'absolute'});
- this._elem.addClass('jqplot-'+this.axis+'-label');
-
- elem = null;
- return this._elem;
- };
-
- $.jqplot.CanvasAxisLabelRenderer.prototype.pack = function() {
- this._textRenderer.draw(this._elem.get(0).getContext("2d"), this.label);
- };
-
- })(jQuery);
|