jqplot.canvasTextRenderer.js 24 KB

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