mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-01 06:30:26 +00:00
57 lines
18 KiB
JavaScript
57 lines
18 KiB
JavaScript
|
/**
|
||
|
* jqPlot
|
||
|
* Pure JavaScript plotting plugin using jQuery
|
||
|
*
|
||
|
* Version: 1.0.0r1095
|
||
|
*
|
||
|
* Copyright (c) 2009-2011 Chris Leonello
|
||
|
* jqPlot is currently available for use in all personal or commercial projects
|
||
|
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
||
|
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
||
|
* choose the license that best suits your project and use it accordingly.
|
||
|
*
|
||
|
* Although not required, the author would appreciate an email letting him
|
||
|
* know of any substantial use of jqPlot. You can reach the author at:
|
||
|
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
||
|
*
|
||
|
* If you are feeling kind and generous, consider supporting the project by
|
||
|
* making a donation at: http://www.jqplot.com/donate.php .
|
||
|
*
|
||
|
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
||
|
*
|
||
|
* version 2007.04.27
|
||
|
* author Ash Searle
|
||
|
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
||
|
* http://hexmen.com/js/sprintf.js
|
||
|
* The author (Ash Searle) has placed this code in the public domain:
|
||
|
* "This code is unrestricted: you are free to use it however you like."
|
||
|
*
|
||
|
* included jsDate library by Chris Leonello:
|
||
|
*
|
||
|
* Copyright (c) 2010-2011 Chris Leonello
|
||
|
*
|
||
|
* jsDate is currently available for use in all personal or commercial projects
|
||
|
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
||
|
* choose the license that best suits your project and use it accordingly.
|
||
|
*
|
||
|
* jsDate borrows many concepts and ideas from the Date Instance
|
||
|
* Methods by Ken Snyder along with some parts of Ken's actual code.
|
||
|
*
|
||
|
* Ken's origianl Date Instance Methods and copyright notice:
|
||
|
*
|
||
|
* Ken Snyder (ken d snyder at gmail dot com)
|
||
|
* 2008-09-10
|
||
|
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
|
||
|
* Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
|
||
|
*
|
||
|
* jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
|
||
|
* Larry has generously given permission to adapt his code for inclusion
|
||
|
* into jqPlot.
|
||
|
*
|
||
|
* Larry's original code can be found here:
|
||
|
*
|
||
|
* https://github.com/lsiden/export-jqplot-to-png
|
||
|
*
|
||
|
*
|
||
|
*/
|
||
|
(function(a){a.jqplot.CanvasTextRenderer=function(b){this.fontStyle="normal";this.fontVariant="normal";this.fontWeight="normal";this.fontSize="10px";this.fontFamily="sans-serif";this.fontStretch=1;this.fillStyle="#666666";this.angle=0;this.textAlign="start";this.textBaseline="alphabetic";this.text;this.width;this.height;this.pt2px=1.28;a.extend(true,this,b);this.normalizedFontSize=this.normalizeFontSize(this.fontSize);this.setHeight()};a.jqplot.CanvasTextRenderer.prototype.init=function(b){a.extend(true,this,b);this.normalizedFontSize=this.normalizeFontSize(this.fontSize);this.setHeight()};a.jqplot.CanvasTextRenderer.prototype.normalizeFontSize=function(b){b=String(b);var c=parseFloat(b);if(b.indexOf("px")>-1){return c/this.pt2px}else{if(b.indexOf("pt")>-1){return c}else{if(b.indexOf("em")>-1){return c*12}else{if(b.indexOf("%")>-1){return c*12/100}else{return c/this.pt2px}}}}};a.jqplot.CanvasTextRenderer.prototype.fontWeight2Float=function(b){if(Number(b)){return b/400}else{switch(b){case"normal":return 1;break;case"bold":return 1.75;break;case"bolder":return 2.25;break;case"lighter":return 0.75;break;default:return 1;break}}};a.jqplot.CanvasTextRenderer.prototype.getText=function(){return this.text};a.jqplot.CanvasTextRenderer.prototype.setText=function(c,b){this.text=c;this.setWidth(b);return this};a.jqplot.CanvasTextRenderer.prototype.getWidth=function(b){return this.width};a.jqplot.CanvasTextRenderer.prototype.setWidth=function(c,b){if(!b){this.width=this.measure(c,this.text)}else{this.width=b}return this};a.jqplot.CanvasTextRenderer.prototype.getHeight=function(b){return this.height};a.jqplot.CanvasTextRenderer.prototype.setHeight=function(b){if(!b){this.height=this.normalizedFontSize*this.pt2px}else{this.height=b}return this};a.jqplot.CanvasTextRenderer.prototype.letter=function(b){return this.letters[b]};a.jqplot.CanvasTextRenderer.prototype.ascent=function(){return this.normalizedFontSize};a.jqplot.CanvasTextRenderer.prototype.descent=function(){return 7*this.normalizedFontSize/25};a.jqplot.CanvasTextRenderer.prototype.measure=function(d,g){var f=0;var b=g.length;for(var e=0;e<b;e++){var h=this.letter(g.charAt(e));if(h){f+=h.width*this.normalizedFontSize/25*this.fontStretch}}return f};a.jqplot.CanvasTextRenderer.prototype.draw=function(s,n){var r=0;var o=this.height*0.72;var p=0;var l=n.length;var k=this.normalizedFontSize/25;s.save();var h,f;if((-Math.PI/2<=this.angle&&this.angle<=0)||(Math.PI*3/2<=this.angle&&this.angle<=Math.PI*2)){h=0;f=-Math.sin(this.angle)*this.width}else{if((0<this.angle&&this.angle<=Math.PI/2)||(-Math.PI*2<=this.angle&&this.angle<=-Math.PI*3/2)){h=Math.sin(this.angle)*this.height;f=0}else{if((-Math.PI<this.angle&&this.angle<-Math.PI/2)||(Math.PI<=this.angle&&this.angle<=Math.PI*3/2)){h=-Math.cos(this.angle)*this.width;f=-Math.sin(this.angle)*this.width-Math.cos(this.angle)*this.height}else{if((-Math.PI*3/2<this.angle&&this.angle<Math.PI)||(Math.PI/2<this.angle&&this.angle<Math.PI)){h=Math.sin(this.angle)*this.height-Math.cos(this.angle)*this.width;f=-Math.cos(this.angle)*this.height}}}}s.strokeStyle=this.fillStyle;s.fillStyle=this.fillStyle;s.translate(h,f);s.rotate(this.angle);s.lineCap="round";var t=(this.normalizedFontSize>30)?2:2+(30-this.normalizedFontSize)/20;s.lineWidth=t*k*this.fontWeight2Float(this.fontWeight);for(var g=0;g<l;g++){var m=this.letter(n.charAt(g));if(!m){continue}s.beginPath();var e=1;var b=0;for(var d=0;d<m.points.length;d++){var q=m.points[d];if(q[0]==-1&&q[1]==-1){e=1;continue}if(e){s.moveTo(r+q[0]*k*this.fontStretch,o-q[1]*k);e=false}else{s.lineTo(r+q[0]*k*this.fontStretch,o-q[1]*k)}}s.stroke();r+=m.width*k*this.fontStretch}s.restore();return p};a.jqplot.CanvasTextRenderer.prototype.letters={" ":{width:16,points:[]},"!":{width:10,points:[[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},'"':{width:16,points:[[4,21],[4,14],[-1,-1],[12,21],[12,14]]},"#":{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]]},"$":{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],[
|