Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/packages/jqPlot.1.0.0/content/Scripts/jqPlot/plugins/jqplot.canvasTextRenderer.js @ 9617

Last change on this file since 9617 was 9617, checked in by pfleck, 11 years ago

#2063:
Started integrating Hive statistics into statistics web project.
Added jqPlot library for charting.

File size: 23.8 KB
Line 
1/**
2 * jqPlot
3 * Pure JavaScript plotting plugin using jQuery
4 *
5 * Version: 1.0.0b2_r1012
6 *
7 * Copyright (c) 2009-2011 Chris Leonello
8 * jqPlot is currently available for use in all personal or commercial projects
9 * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
10 * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
11 * choose the license that best suits your project and use it accordingly.
12 *
13 * Although not required, the author would appreciate an email letting him
14 * know of any substantial use of jqPlot.  You can reach the author at:
15 * chris at jqplot dot com or see http://www.jqplot.com/info.php .
16 *
17 * If you are feeling kind and generous, consider supporting the project by
18 * making a donation at: http://www.jqplot.com/donate.php .
19 *
20 * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
21 *
22 *     version 2007.04.27
23 *     author Ash Searle
24 *     http://hexmen.com/blog/2007/03/printf-sprintf/
25 *     http://hexmen.com/js/sprintf.js
26 *     The author (Ash Searle) has placed this code in the public domain:
27 *     "This code is unrestricted: you are free to use it however you like."
28 *
29 * included jsDate library by Chris Leonello:
30 *
31 * Copyright (c) 2010-2011 Chris Leonello
32 *
33 * jsDate is currently available for use in all personal or commercial projects
34 * under both the MIT and GPL version 2.0 licenses. This means that you can
35 * choose the license that best suits your project and use it accordingly.
36 *
37 * jsDate borrows many concepts and ideas from the Date Instance
38 * Methods by Ken Snyder along with some parts of Ken's actual code.
39 *
40 * Ken's origianl Date Instance Methods and copyright notice:
41 *
42 * Ken Snyder (ken d snyder at gmail dot com)
43 * 2008-09-10
44 * version 2.0.2 (http://kendsnyder.com/sandbox/date/)     
45 * Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
46 *
47 * jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
48 * Larry has generously given permission to adapt his code for inclusion
49 * into jqPlot.
50 *
51 * Larry's original code can be found here:
52 *
53 * https://github.com/lsiden/export-jqplot-to-png
54 *
55 *
56 */
57
58(function($) {   
59    // This code is a modified version of the canvastext.js code, copyright below:
60    //
61    // This code is released to the public domain by Jim Studt, 2007.
62    // He may keep some sort of up to date copy at http://www.federated.com/~jim/canvastext/
63    //
64    $.jqplot.CanvasTextRenderer = function(options){
65        this.fontStyle = 'normal';  // normal, italic, oblique [not implemented]
66        this.fontVariant = 'normal';    // normal, small caps [not implemented]
67        this.fontWeight = 'normal'; // normal, bold, bolder, lighter, 100 - 900
68        this.fontSize = '10px';
69        this.fontFamily = 'sans-serif';
70        this.fontStretch = 1.0;
71        this.fillStyle = '#666666';
72        this.angle = 0;
73        this.textAlign = 'start';
74        this.textBaseline = 'alphabetic';
75        this.text;
76        this.width;
77        this.height;
78        this.pt2px = 1.28;
79
80        $.extend(true, this, options);
81        this.normalizedFontSize = this.normalizeFontSize(this.fontSize);
82        this.setHeight();
83    };
84   
85    $.jqplot.CanvasTextRenderer.prototype.init = function(options) {
86        $.extend(true, this, options);
87        this.normalizedFontSize = this.normalizeFontSize(this.fontSize);
88        this.setHeight();
89    };
90   
91    // convert css spec into point size
92    // returns float
93    $.jqplot.CanvasTextRenderer.prototype.normalizeFontSize = function(sz) {
94        sz = String(sz);
95        var n = parseFloat(sz);
96        if (sz.indexOf('px') > -1) {
97            return n/this.pt2px;
98        }
99        else if (sz.indexOf('pt') > -1) {
100            return n;
101        }
102        else if (sz.indexOf('em') > -1) {
103            return n*12;
104        }
105        else if (sz.indexOf('%') > -1) {
106            return n*12/100;
107        }
108        // default to pixels;
109        else {
110            return n/this.pt2px;
111        }
112    };
113   
114   
115    $.jqplot.CanvasTextRenderer.prototype.fontWeight2Float = function(w) {
116        // w = normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
117        // return values adjusted for Hershey font.
118        if (Number(w)) {
119            return w/400;
120        }
121        else {
122            switch (w) {
123                case 'normal':
124                    return 1;
125                    break;
126                case 'bold':
127                    return 1.75;
128                    break;
129                case 'bolder':
130                    return 2.25;
131                    break;
132                case 'lighter':
133                    return 0.75;
134                    break;
135                default:
136                    return 1;
137                    break;
138             }   
139        }
140    };
141   
142    $.jqplot.CanvasTextRenderer.prototype.getText = function() {
143        return this.text;
144    };
145   
146    $.jqplot.CanvasTextRenderer.prototype.setText = function(t, ctx) {
147        this.text = t;
148        this.setWidth(ctx);
149        return this;
150    };
151   
152    $.jqplot.CanvasTextRenderer.prototype.getWidth = function(ctx) {
153        return this.width;
154    };
155   
156    $.jqplot.CanvasTextRenderer.prototype.setWidth = function(ctx, w) {
157        if (!w) {
158            this.width = this.measure(ctx, this.text);
159        }
160        else {
161            this.width = w;   
162        }
163        return this;
164    };
165   
166    // return height in pixels.
167    $.jqplot.CanvasTextRenderer.prototype.getHeight = function(ctx) {
168        return this.height;
169    };
170   
171    // w - height in pt
172    // set heigh in px
173    $.jqplot.CanvasTextRenderer.prototype.setHeight = function(w) {
174        if (!w) {
175            //height = this.fontSize /0.75;
176            this.height = this.normalizedFontSize * this.pt2px;
177        }
178        else {
179            this.height = w;   
180        }
181        return this;
182    };
183
184    $.jqplot.CanvasTextRenderer.prototype.letter = function (ch)
185    {
186        return this.letters[ch];
187    };
188
189    $.jqplot.CanvasTextRenderer.prototype.ascent = function()
190    {
191        return this.normalizedFontSize;
192    };
193
194    $.jqplot.CanvasTextRenderer.prototype.descent = function()
195    {
196        return 7.0*this.normalizedFontSize/25.0;
197    };
198
199    $.jqplot.CanvasTextRenderer.prototype.measure = function(ctx, str)
200    {
201        var total = 0;
202        var len = str.length;
203 
204        for (var i = 0; i < len; i++) {
205            var c = this.letter(str.charAt(i));
206            if (c) {
207                total += c.width * this.normalizedFontSize / 25.0 * this.fontStretch;
208            }
209        }
210        return total;
211    };
212
213    $.jqplot.CanvasTextRenderer.prototype.draw = function(ctx,str)
214    {
215        var x = 0;
216        // leave room at bottom for descenders.
217        var y = this.height*0.72;
218         var total = 0;
219         var len = str.length;
220         var mag = this.normalizedFontSize / 25.0;
221
222         ctx.save();
223         var tx, ty;
224         
225         // 1st quadrant
226         if ((-Math.PI/2 <= this.angle && this.angle <= 0) || (Math.PI*3/2 <= this.angle && this.angle <= Math.PI*2)) {
227             tx = 0;
228             ty = -Math.sin(this.angle) * this.width;
229         }
230         // 4th quadrant
231         else if ((0 < this.angle && this.angle <= Math.PI/2) || (-Math.PI*2 <= this.angle && this.angle <= -Math.PI*3/2)) {
232             tx = Math.sin(this.angle) * this.height;
233             ty = 0;
234         }
235         // 2nd quadrant
236         else if ((-Math.PI < this.angle && this.angle < -Math.PI/2) || (Math.PI <= this.angle && this.angle <= Math.PI*3/2)) {
237             tx = -Math.cos(this.angle) * this.width;
238             ty = -Math.sin(this.angle) * this.width - Math.cos(this.angle) * this.height;
239         }
240         // 3rd quadrant
241         else if ((-Math.PI*3/2 < this.angle && this.angle < Math.PI) || (Math.PI/2 < this.angle && this.angle < Math.PI)) {
242             tx = Math.sin(this.angle) * this.height - Math.cos(this.angle)*this.width;
243             ty = -Math.cos(this.angle) * this.height;
244         }
245         
246         ctx.strokeStyle = this.fillStyle;
247         ctx.fillStyle = this.fillStyle;
248         ctx.translate(tx, ty);
249         ctx.rotate(this.angle);
250         ctx.lineCap = "round";
251         // multiplier was 2.0
252         var fact = (this.normalizedFontSize > 30) ? 2.0 : 2 + (30 - this.normalizedFontSize)/20;
253         ctx.lineWidth = fact * mag * this.fontWeight2Float(this.fontWeight);
254         
255         for ( var i = 0; i < len; i++) {
256            var c = this.letter( str.charAt(i));
257            if ( !c) {
258                continue;
259            }
260
261            ctx.beginPath();
262
263            var penUp = 1;
264            var needStroke = 0;
265            for ( var j = 0; j < c.points.length; j++) {
266              var a = c.points[j];
267              if ( a[0] == -1 && a[1] == -1) {
268                  penUp = 1;
269                  continue;
270              }
271              if ( penUp) {
272                  ctx.moveTo( x + a[0]*mag*this.fontStretch, y - a[1]*mag);
273                  penUp = false;
274              } else {
275                  ctx.lineTo( x + a[0]*mag*this.fontStretch, y - a[1]*mag);
276              }
277            }
278            ctx.stroke();
279            x += c.width*mag*this.fontStretch;
280         }
281         ctx.restore();
282         return total;
283    };
284
285    $.jqplot.CanvasTextRenderer.prototype.letters = {
286         ' ': { width: 16, points: [] },
287         '!': { width: 10, points: [[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]] },
288         '"': { width: 16, points: [[4,21],[4,14],[-1,-1],[12,21],[12,14]] },
289         '#': { width: 21, points: [[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]] },
290         '$': { width: 20, points: [[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]] },
291         '%': { width: 24, points: [[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]] },
292         '&': { width: 26, points: [[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]] },
293         '\'': { width: 10, points: [[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]] },
294         '(': { width: 14, points: [[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]] },
295         ')': { width: 14, points: [[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]] },
296         '*': { width: 16, points: [[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]] },
297         '+': { width: 26, points: [[13,18],[13,0],[-1,-1],[4,9],[22,9]] },
298         ',': { width: 10, points: [[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]] },
299         '-': { width: 18, points: [[6,9],[12,9]] },
300         '.': { width: 10, points: [[5,2],[4,1],[5,0],[6,1],[5,2]] },
301         '/': { width: 22, points: [[20,25],[2,-7]] },
302         '0': { width: 20, points: [[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]] },
303         '1': { width: 20, points: [[6,17],[8,18],[11,21],[11,0]] },
304         '2': { width: 20, points: [[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]] },
305         '3': { width: 20, points: [[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]] },
306         '4': { width: 20, points: [[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]] },
307         '5': { width: 20, points: [[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]] },
308         '6': { width: 20, points: [[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]] },
309         '7': { width: 20, points: [[17,21],[7,0],[-1,-1],[3,21],[17,21]] },
310         '8': { width: 20, points: [[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]] },
311         '9': { width: 20, points: [[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]] },
312         ':': { width: 10, points: [[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]] },
313         ';': { width: 10, points: [[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]] },
314         '<': { width: 24, points: [[20,18],[4,9],[20,0]] },
315         '=': { width: 26, points: [[4,12],[22,12],[-1,-1],[4,6],[22,6]] },
316         '>': { width: 24, points: [[4,18],[20,9],[4,0]] },
317         '?': { width: 18, points: [[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]] },
318         '@': { width: 27, points: [[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]] },
319         'A': { width: 18, points: [[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]] },
320         'B': { width: 21, points: [[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]] },
321         'C': { width: 21, points: [[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]] },
322         'D': { width: 21, points: [[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]] },
323         'E': { width: 19, points: [[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]] },
324         'F': { width: 18, points: [[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]] },
325         'G': { width: 21, points: [[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]] },
326         'H': { width: 22, points: [[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]] },
327         'I': { width: 8, points: [[4,21],[4,0]] },
328         'J': { width: 16, points: [[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]] },
329         'K': { width: 21, points: [[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]] },
330         'L': { width: 17, points: [[4,21],[4,0],[-1,-1],[4,0],[16,0]] },
331         'M': { width: 24, points: [[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]] },
332         'N': { width: 22, points: [[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]] },
333         'O': { width: 22, points: [[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]] },
334         'P': { width: 21, points: [[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]] },
335         'Q': { width: 22, points: [[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]] },
336         'R': { width: 21, points: [[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]] },
337         'S': { width: 20, points: [[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]] },
338         'T': { width: 16, points: [[8,21],[8,0],[-1,-1],[1,21],[15,21]] },
339         'U': { width: 22, points: [[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]] },
340         'V': { width: 18, points: [[1,21],[9,0],[-1,-1],[17,21],[9,0]] },
341         'W': { width: 24, points: [[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]] },
342         'X': { width: 20, points: [[3,21],[17,0],[-1,-1],[17,21],[3,0]] },
343         'Y': { width: 18, points: [[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]] },
344         'Z': { width: 20, points: [[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]] },
345         '[': { width: 14, points: [[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]] },
346         '\\': { width: 14, points: [[0,21],[14,-3]] },
347         ']': { width: 14, points: [[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]] },
348         '^': { width: 16, points: [[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]] },
349         '_': { width: 16, points: [[0,-2],[16,-2]] },
350         '`': { width: 10, points: [[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]] },
351         'a': { width: 19, points: [[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
352         'b': { width: 19, points: [[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]] },
353         'c': { width: 18, points: [[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
354         'd': { width: 19, points: [[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
355         'e': { width: 18, points: [[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
356         'f': { width: 12, points: [[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]] },
357         'g': { width: 19, points: [[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
358         'h': { width: 19, points: [[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]] },
359         'i': { width: 8, points: [[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]] },
360         'j': { width: 10, points: [[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]] },
361         'k': { width: 17, points: [[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]] },
362         'l': { width: 8, points: [[4,21],[4,0]] },
363         'm': { width: 30, points: [[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]] },
364         'n': { width: 19, points: [[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]] },
365         'o': { width: 19, points: [[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]] },
366         'p': { width: 19, points: [[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]] },
367         'q': { width: 19, points: [[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]] },
368         'r': { width: 13, points: [[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]] },
369         's': { width: 17, points: [[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]] },
370         't': { width: 12, points: [[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]] },
371         'u': { width: 19, points: [[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]] },
372         'v': { width: 16, points: [[2,14],[8,0],[-1,-1],[14,14],[8,0]] },
373         'w': { width: 22, points: [[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]] },
374         'x': { width: 17, points: [[3,14],[14,0],[-1,-1],[14,14],[3,0]] },
375         'y': { width: 16, points: [[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]] },
376         'z': { width: 17, points: [[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]] },
377         '{': { width: 14, points: [[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]] },
378         '|': { width: 8, points: [[4,25],[4,-7]] },
379         '}': { width: 14, points: [[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]] },
380         '~': { width: 24, points: [[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]] }
381     };
382     
383    $.jqplot.CanvasFontRenderer = function(options) {
384        options = options || {};
385        if (!options.pt2px) {
386            options.pt2px = 1.5;
387        }
388        $.jqplot.CanvasTextRenderer.call(this, options);
389    };
390   
391    $.jqplot.CanvasFontRenderer.prototype = new $.jqplot.CanvasTextRenderer({});
392    $.jqplot.CanvasFontRenderer.prototype.constructor = $.jqplot.CanvasFontRenderer;
393
394    $.jqplot.CanvasFontRenderer.prototype.measure = function(ctx, str)
395    {
396        // var fstyle = this.fontStyle+' '+this.fontVariant+' '+this.fontWeight+' '+this.fontSize+' '+this.fontFamily;
397        var fstyle = this.fontSize+' '+this.fontFamily;
398        ctx.save();
399        ctx.font = fstyle;
400        var w = ctx.measureText(str).width;
401        ctx.restore();
402        return w;
403    };
404
405    $.jqplot.CanvasFontRenderer.prototype.draw = function(ctx, str)
406    {
407        var x = 0;
408        // leave room at bottom for descenders.
409        var y = this.height*0.72;
410        //var y = 12;
411
412         ctx.save();
413         var tx, ty;
414         
415         // 1st quadrant
416         if ((-Math.PI/2 <= this.angle && this.angle <= 0) || (Math.PI*3/2 <= this.angle && this.angle <= Math.PI*2)) {
417             tx = 0;
418             ty = -Math.sin(this.angle) * this.width;
419         }
420         // 4th quadrant
421         else if ((0 < this.angle && this.angle <= Math.PI/2) || (-Math.PI*2 <= this.angle && this.angle <= -Math.PI*3/2)) {
422             tx = Math.sin(this.angle) * this.height;
423             ty = 0;
424         }
425         // 2nd quadrant
426         else if ((-Math.PI < this.angle && this.angle < -Math.PI/2) || (Math.PI <= this.angle && this.angle <= Math.PI*3/2)) {
427             tx = -Math.cos(this.angle) * this.width;
428             ty = -Math.sin(this.angle) * this.width - Math.cos(this.angle) * this.height;
429         }
430         // 3rd quadrant
431         else if ((-Math.PI*3/2 < this.angle && this.angle < Math.PI) || (Math.PI/2 < this.angle && this.angle < Math.PI)) {
432             tx = Math.sin(this.angle) * this.height - Math.cos(this.angle)*this.width;
433             ty = -Math.cos(this.angle) * this.height;
434         }
435         ctx.strokeStyle = this.fillStyle;
436         ctx.fillStyle = this.fillStyle;
437        // var fstyle = this.fontStyle+' '+this.fontVariant+' '+this.fontWeight+' '+this.fontSize+' '+this.fontFamily;
438        var fstyle = this.fontSize+' '+this.fontFamily;
439         ctx.font = fstyle;
440         ctx.translate(tx, ty);
441         ctx.rotate(this.angle);
442         ctx.fillText(str, x, y);
443         // ctx.strokeText(str, x, y);
444
445         ctx.restore();
446    };
447   
448})(jQuery);
Note: See TracBrowser for help on using the repository browser.