rgraph-rails 5.00 → 6.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/publish-geml.yaml +46 -0
  3. data/.gitignore +1 -0
  4. data/README.md +4 -5
  5. data/lib/rgraph-rails/version.rb +1 -1
  6. data/rgraph-rails.gemspec +4 -4
  7. data/vendor/assets/javascripts/RGraph.activity.js +1691 -0
  8. data/vendor/assets/javascripts/RGraph.bar.js +4253 -236
  9. data/vendor/assets/javascripts/RGraph.bipolar.js +3958 -162
  10. data/vendor/assets/javascripts/RGraph.common.annotate.js +414 -35
  11. data/vendor/assets/javascripts/RGraph.common.context.js +635 -30
  12. data/vendor/assets/javascripts/RGraph.common.core.js +10485 -419
  13. data/vendor/assets/javascripts/RGraph.common.csv.js +508 -27
  14. data/vendor/assets/javascripts/RGraph.common.dynamic.js +1693 -90
  15. data/vendor/assets/javascripts/RGraph.common.effects.js +1629 -89
  16. data/vendor/assets/javascripts/RGraph.common.key.js +1003 -53
  17. data/vendor/assets/javascripts/RGraph.common.moment.js +5670 -0
  18. data/vendor/assets/javascripts/RGraph.common.sheets.js +541 -31
  19. data/vendor/assets/javascripts/RGraph.common.sheets.php +351 -0
  20. data/vendor/assets/javascripts/RGraph.common.starburst.js +382 -0
  21. data/vendor/assets/javascripts/RGraph.common.table.js +386 -0
  22. data/vendor/assets/javascripts/RGraph.common.tooltips.js +1433 -32
  23. data/vendor/assets/javascripts/RGraph.drawing.background.js +660 -35
  24. data/vendor/assets/javascripts/RGraph.drawing.circle.js +618 -34
  25. data/vendor/assets/javascripts/RGraph.drawing.image.js +857 -52
  26. data/vendor/assets/javascripts/RGraph.drawing.line.js +712 -0
  27. data/vendor/assets/javascripts/RGraph.drawing.marker1.js +760 -38
  28. data/vendor/assets/javascripts/RGraph.drawing.marker2.js +740 -37
  29. data/vendor/assets/javascripts/RGraph.drawing.marker3.js +573 -36
  30. data/vendor/assets/javascripts/RGraph.drawing.poly.js +667 -36
  31. data/vendor/assets/javascripts/RGraph.drawing.rect.js +638 -34
  32. data/vendor/assets/javascripts/RGraph.drawing.text.js +672 -37
  33. data/vendor/assets/javascripts/RGraph.drawing.xaxis.js +653 -52
  34. data/vendor/assets/javascripts/RGraph.drawing.yaxis.js +714 -51
  35. data/vendor/assets/javascripts/RGraph.fuel.js +1149 -59
  36. data/vendor/assets/javascripts/RGraph.funnel.js +1277 -56
  37. data/vendor/assets/javascripts/RGraph.gantt.js +1646 -82
  38. data/vendor/assets/javascripts/RGraph.gauge.js +1773 -89
  39. data/vendor/assets/javascripts/RGraph.hbar.js +3869 -159
  40. data/vendor/assets/javascripts/RGraph.horseshoe.js +970 -0
  41. data/vendor/assets/javascripts/RGraph.hprogress.js +1829 -81
  42. data/vendor/assets/javascripts/RGraph.line.js +5293 -244
  43. data/vendor/assets/javascripts/RGraph.meter.js +1570 -77
  44. data/vendor/assets/javascripts/RGraph.modaldialog.js +300 -19
  45. data/vendor/assets/javascripts/RGraph.odo.js +1553 -68
  46. data/vendor/assets/javascripts/RGraph.pie.js +3273 -129
  47. data/vendor/assets/javascripts/RGraph.radar.js +2333 -108
  48. data/vendor/assets/javascripts/RGraph.rose.js +2685 -114
  49. data/vendor/assets/javascripts/RGraph.rscatter.js +1920 -80
  50. data/vendor/assets/javascripts/RGraph.scatter.js +4215 -171
  51. data/vendor/assets/javascripts/RGraph.segmented.js +1006 -0
  52. data/vendor/assets/javascripts/RGraph.semicircularprogress.js +1980 -59
  53. data/vendor/assets/javascripts/RGraph.svg.activity.js +1696 -0
  54. data/vendor/assets/javascripts/RGraph.svg.bar.js +2575 -77
  55. data/vendor/assets/javascripts/RGraph.svg.bipolar.js +3533 -106
  56. data/vendor/assets/javascripts/RGraph.svg.common.ajax.js +240 -21
  57. data/vendor/assets/javascripts/RGraph.svg.common.core.js +7105 -299
  58. data/vendor/assets/javascripts/RGraph.svg.common.csv.js +408 -28
  59. data/vendor/assets/javascripts/RGraph.svg.common.fx.js +1291 -68
  60. data/vendor/assets/javascripts/RGraph.svg.common.key.js +451 -20
  61. data/vendor/assets/javascripts/RGraph.svg.common.sheets.js +543 -31
  62. data/vendor/assets/javascripts/RGraph.svg.common.table.js +391 -0
  63. data/vendor/assets/javascripts/RGraph.svg.common.tooltips.js +1072 -23
  64. data/vendor/assets/javascripts/RGraph.svg.funnel.js +1151 -32
  65. data/vendor/assets/javascripts/RGraph.svg.gauge.js +1429 -34
  66. data/vendor/assets/javascripts/RGraph.svg.hbar.js +2692 -65
  67. data/vendor/assets/javascripts/RGraph.svg.horseshoe.js +969 -0
  68. data/vendor/assets/javascripts/RGraph.svg.line.js +2855 -86
  69. data/vendor/assets/javascripts/RGraph.svg.pie.js +1630 -58
  70. data/vendor/assets/javascripts/RGraph.svg.radar.js +1772 -58
  71. data/vendor/assets/javascripts/RGraph.svg.rose.js +2419 -83
  72. data/vendor/assets/javascripts/RGraph.svg.scatter.js +2280 -65
  73. data/vendor/assets/javascripts/RGraph.svg.segmented.js +930 -0
  74. data/vendor/assets/javascripts/RGraph.svg.semicircularprogress.js +1612 -29
  75. data/vendor/assets/javascripts/RGraph.svg.waterfall.js +1525 -50
  76. data/vendor/assets/javascripts/RGraph.thermometer.js +1411 -64
  77. data/vendor/assets/javascripts/RGraph.vprogress.js +1915 -81
  78. data/vendor/assets/javascripts/RGraph.waterfall.js +1896 -89
  79. data/vendor/assets/javascripts/financial-data.js +1067 -0
  80. metadata +37 -16
  81. data/.travis.yml +0 -11
  82. data/vendor/assets/javascripts/RGraph.common.deprecated.js +0 -35
  83. data/vendor/assets/javascripts/RGraph.common.resizing.js +0 -38
  84. data/vendor/assets/javascripts/RGraph.common.zoom.js +0 -15
  85. data/vendor/assets/javascripts/RGraph.cornergauge.js +0 -71
@@ -1,65 +1,1412 @@
1
+ 'version:2023-09-16 (6.14)';
2
+ //
3
+ // o--------------------------------------------------------------------------------o
4
+ // | This file is part of the RGraph package - you can learn more at: |
5
+ // | |
6
+ // | https://www.rgraph.net |
7
+ // | |
8
+ // | RGraph is licensed under the Open Source MIT license. That means that it's |
9
+ // | totally free to use and there are no restrictions on what you can do with it! |
10
+ // o--------------------------------------------------------------------------------o
1
11
 
2
- RGraph=window.RGraph||{isRGraph:true};RGraph.Thermometer=function(conf)
3
- {if(typeof conf==='object'&&typeof conf.id==='string'){var parseConfObjectForOptions=true;}else{var conf={id:arguments[0],min:arguments[1],max:arguments[2],value:arguments[3]}}
4
- this.id=conf.id;this.canvas=document.getElementById(this.id);this.context=this.canvas.getContext?this.canvas.getContext('2d'):null;this.canvas.__object__=this;this.uid=RGraph.CreateUID();this.canvas.uid=this.canvas.uid?this.canvas.uid:RGraph.CreateUID();this.colorsParsed=false;this.type='thermometer';this.isRGraph=true;this.min=RGraph.stringsToNumbers(conf.min);this.max=RGraph.stringsToNumbers(conf.max);this.value=RGraph.stringsToNumbers(conf.value);this.coords=[];this.graphArea=[];this.currentValue=null;this.coordsText=[];this.original_colors=[];this.firstDraw=true;this.propertyNameAliases={};this.properties={'chart.linewidth':1,'chart.background.color':'white','chart.colors.stroke':'black','chart.colors':['Gradient(#c00:red:#f66:#fcc)'],'chart.margin.left':25,'chart.margin.right':25,'chart.margin.top':25,'chart.margin.bottom':25,'chart.tickmarks.size':2,'chart.tickmarks.count':10,'chart.text.color':'black','chart.text.font':'Arial, Verdana, sans-serif','chart.text.size':12,'chart.text.bold':false,'chart.text.italic':false,'chart.text.accessible':true,'chart.text.accessible.overflow':'visible','chart.text.accessible.pointerevents':false,'chart.scale.visible':false,'chart.scale.units.pre':'','chart.scale.units.post':'','chart.scale.decimals':0,'chart.scale.thousand':',','chart.scale.point':'.','chart.title':'','chart.title.font':null,'chart.title.size':null,'chart.title.color':null,'chart.title.bold':null,'chart.title.italic':null,'chart.title.side':'','chart.title.side.bold':null,'chart.title.side.font':null,'chart.title.side.size':null,'chart.title.side.color':null,'chart.title.side.italic':null,'chart.shadow':true,'chart.shadow.offsetx':0,'chart.shadow.offsety':0,'chart.shadow.blur':15,'chart.shadow.color':'#ddd','chart.resizable':false,'chart.resizable.handle.background':null,'chart.contextmenu':null,'chart.adjustable':false,'chart.labels.value':true,'chart.labels.value.color':null,'chart.labels.value.font':null,'chart.labels.value.size':null,'chart.labels.value.bold':null,'chart.labels.value.italic':null,'chart.labels.value.decimals':null,'chart.labels.value.thousand':null,'chart.labels.value.point':null,'chart.labels.value.units.pre':null,'chart.labels.value.units.post':null,'chart.labels.count':5,'chart.labels.decimals':null,'chart.labels.units.pre':null,'chart.labels.units.post':null,'chart.labels.point':null,'chart.labels.thousand':null,'chart.labels.color':null,'chart.labels.font':null,'chart.labels.size':null,'chart.labels.bold':null,'chart.labels.italic':null,'chart.annotatable':false,'chart.annotatable.color':'black','chart.annotatable.linewidth':1,'chart.tooltips':null,'chart.tooltips.highlight':true,'chart.tooltips.effect':'fade','chart.tooltips.event':'onclick','chart.highlight.stroke':'rgba(0,0,0,0)','chart.highlight.fill':'rgba(255,255,255,0.7)','chart.clearto':'rgba(0,0,0,0)','chart.bulb.bottom.radius.adjust':0,'chart.bulb.bottom.radius':null}
5
- if(!this.canvas){alert('[THERMOMETER] No canvas support');return;}
6
- this.$0={};if(!this.canvas.__rgraph_aa_translated__){this.context.translate(0.5,0.5);this.canvas.__rgraph_aa_translated__=true;}
7
- var RG=RGraph,ca=this.canvas,co=ca.getContext('2d'),prop=this.properties,pa2=RG.path2,win=window,doc=document,ma=Math
8
- if(RG.Effects&&typeof RG.Effects.decorate==='function'){RG.Effects.decorate(this);}
9
- this.set=this.Set=function(name)
10
- {var value=typeof arguments[1]==='undefined'?null:arguments[1];if(arguments.length===1&&typeof name==='object'){RG.parseObjectStyleConfig(this,name);return this;}
11
- if(name.substr(0,6)!='chart.'){name='chart.'+name;}
12
- while(name.match(/([A-Z])/)){name=name.replace(/([A-Z])/,'.'+RegExp.$1.toLowerCase());}
13
- if(name=='chart.ylabels.count'){name='chart.labels.count';}
14
- prop[name.toLowerCase()]=value;return this;};this.get=this.Get=function(name)
15
- {if(name.substr(0,6)!='chart.'){name='chart.'+name;}
16
- while(name.match(/([A-Z])/)){name=name.replace(/([A-Z])/,'.'+RegExp.$1.toLowerCase());}
17
- return prop[name];};this.draw=this.Draw=function()
18
- {RG.fireCustomEvent(this,'onbeforedraw');this.value=ma.min(this.max,this.value);this.value=ma.max(this.min,this.value);if(!this.colorsParsed){this.parseColors();this.colorsParsed=true;}
19
- this.currentValue=this.value;this.coordsText=[];this.marginLeft=prop['chart.margin.left'];this.marginRight=prop['chart.margin.right'];this.marginTop=prop['chart.margin.top'];this.marginBottom=prop['chart.margin.bottom'];this.scale2=RG.getScale2(this,{'scale.max':this.max,'scale.min':this.min,'scale.strict':true,'scale.thousand':prop['chart.scale.thousand'],'scale.point':prop['chart.scale.point'],'scale.decimals':prop['chart.scale.decimals'],'ylabels.count':prop['chart.labels.count'],'scale.round':prop['chart.scale.round'],'scale.units.pre':prop['chart.scale.units.pre'],'scale.units.post':prop['chart.scale.units.post']});this.x=this.marginLeft;this.width=ca.width-this.marginLeft-this.marginRight;this.y=this.marginTop+(this.width/2);this.halfWidth=this.width/2;this.bulbTopCenterx=this.marginLeft+(this.width/2);this.bulbTopCentery=this.marginTop+(this.width/2);this.bulbTopRadius=this.width/2;this.bulbBottomCenterx=this.marginLeft+(this.width/2);this.bulbBottomRadius=typeof prop['chart.bulb.bottom.radius']==='number'?prop['chart.bulb.bottom.radius']:this.width*0.75+prop['chart.bulb.bottom.radius.adjust'];this.bulbBottomCentery=ca.height-this.marginBottom-this.bulbBottomRadius;this.scaleTopY=this.bulbTopCentery;this.scaleBottomY=this.bulbBottomCentery-this.bulbBottomRadius;this.scaleHeight=this.scaleBottomY-this.scaleTopY;this.height=this.getYCoord(this.min)-this.getYCoord(this.value);this.coords[0]=[this.x,this.getYCoord(this.value),this.width,this.height];this.drawBackground();this.drawBar();this.drawTickMarks();this.drawLabels();if(prop['chart.title']){this.drawTitle();}
20
- if(prop['chart.title.side']){this.drawSideTitle();}
21
- if(prop['chart.resizable']){RG.allowResizing(this);}
22
- if(prop['chart.contextmenu']){RG.showContext(this);}
23
- RG.installEventListeners(this);if(this.firstDraw){this.firstDraw=false;RG.fireCustomEvent(this,'onfirstdraw');this.firstDrawFunc();}
24
- RG.fireCustomEvent(this,'ondraw');return this;};this.drawBackground=this.DrawBackground=function()
25
- {if(prop['chart.shadow']){RG.setShadow(this,prop['chart.shadow.color'],prop['chart.shadow.offsetx'],prop['chart.shadow.offsety'],prop['chart.shadow.blur']);}
26
- this.pathBackground();co.strokeStyle=prop['chart.colors.stroke'];co.fillStyle=prop['chart.background.color'];co.lineWidth=1+prop['chart.linewidth'];co.stroke();co.fill();co.lineWidth=1;};this.drawBar=this.DrawBar=function()
27
- {this.pathBar();pa2(co,'f %',prop['chart.colors'][0]);};this.pathBar=function()
28
- {var barHeight=this.coords[0][3],y=(this.coords[0][1]+this.coords[0][3])-barHeight
29
- RG.noShadow(this);pa2(co,'b r % % % % a % % % 0 6.28 false',this.coords[0][0],y,this.coords[0][2],this.bulbBottomCentery-y,this.bulbBottomCenterx,this.bulbBottomCentery,this.bulbBottomRadius);};this.pathBackground=function()
30
- {pa2(this.context,'b r % % % % a % % % 0 6.28 false m % % a % % % 0 6.28 false',this.x,this.scaleTopY,this.coords[0][2],this.bulbBottomCentery-this.scaleTopY,this.bulbTopCenterx,this.bulbTopCentery,this.bulbTopRadius,this.bulbBottomCenterx,this.bulbBottomCentery,this.bulbBottomCenterx,this.bulbBottomCentery,this.bulbBottomRadius);};this.drawTickMarks=this.DrawTickMarks=function()
31
- {if(prop['chart.numticks']){var ticksize=prop['chart.tickmarks.size'];co.strokeStyle=prop['chart.colors.stroke'];co.lineWidth=prop['chart.linewidth']/2;co.beginPath();for(var i=0;i<=prop['chart.tickmarks.count'];++i){var y=this.scaleBottomY-((this.scaleHeight/prop['chart.tickmarks.count'])*i);co.moveTo(this.marginLeft,ma.round(y));co.lineTo(this.marginLeft+ticksize,ma.round(y));co.moveTo(ca.width-this.marginRight,ma.round(y));co.lineTo(ca.width-this.marginRight-ticksize,ma.round(y));}
32
- co.stroke();co.lineWidth=1;}};this.drawLabels=this.DrawLabels=function()
33
- {if(prop['chart.labels.value']){var text=prop['chart.scale.visible']?RG.numberFormat({object:this,number:this.value.toFixed(typeof prop['chart.labels.value.decimals']==='number'?prop['chart.labels.value.decimals']:prop['chart.scale.decimals']),unitspre:typeof prop['chart.labels.value.units.pre']==='string'?prop['chart.labels.value.units.pre']:prop['chart.scale.units.pre'],unitspost:typeof prop['chart.labels.value.units.post']==='string'?prop['chart.labels.value.units.post']:prop['chart.scale.units.post'],point:typeof prop['chart.labels.value.point']==='string'?prop['chart.labels.value.point']:prop['chart.scale.point'],thousand:typeof prop['chart.labels.value.thousand']==='string'?prop['chart.labels.value.thousand']:prop['chart.scale.thousand']}):RG.numberFormat({object:this,number:this.value.toFixed(typeof prop['chart.labels.value.decimals']==='number'?prop['chart.labels.value.decimals']:prop['chart.scale.decimals']),unitspre:typeof prop['chart.labels.value.units.pre']==='string'?prop['chart.labels.value.units.pre']:prop['chart.scale.units.pre'],unitspost:typeof prop['chart.labels.value.units.post']==='string'?prop['chart.labels.value.units.post']:prop['chart.scale.units.post'],point:typeof prop['chart.labels.value.point']==='string'?prop['chart.labels.value.point']:prop['chart.scale.point'],thousand:typeof prop['chart.labels.value.thousand']==='string'?prop['chart.labels.value.thousand']:prop['chart.scale.thousand']});var textConf=RG.getTextConf({object:this,prefix:'chart.labels.value'});RG.text2(this,{font:textConf.font,size:textConf.size,color:textConf.color,bold:textConf.bold,italic:textConf.italic,x:this.coords[0][0]+(this.coords[0][2]/2),y:this.coords[0][1]+7,text:text,valign:'top',halign:'center',bounding:true,boundingFill:'white',tag:'labels.value'});}
34
- if(prop['chart.scale.visible']){this.drawScale();}};this.drawTitle=this.DrawTitle=function()
35
- {var textConf=RG.getTextConf({object:this,prefix:'chart.title'});RG.text2(this,{font:textConf.font,size:textConf.size,color:textConf.color,bold:textConf.bold,italic:textConf.italic,x:this.marginLeft+(this.width/2),y:this.marginTop-3,text:String(prop['chart.title']),valign:'bottom',halign:'center',bold:true,tag:'title'});};this.drawSideTitle=this.DrawSideTitle=function()
36
- {var textConf=RG.getTextConf({object:this,prefix:'chart.title.side'});co.fillStyle=prop['chart.text.color'];RG.text2(this,{font:textConf.font,size:textConf.size,color:textConf.color,bold:textConf.bold,italic:textConf.italic,x:this.marginLeft-3,y:(this.scaleHeight/2)+this.marginTop+this.bulbTopRadius,text:String(prop['chart.title.side']),valign:'bottom',halign:'center',angle:270,tag:'title.side',accessible:false});};this.drawScale=this.DrawScale=function()
37
- {co.fillStyle=prop['chart.text.color'];var units_pre=prop['chart.scale.units.pre'],units_post=prop['chart.scale.units.post'],decimals=typeof prop['chart.labels.decimals']==='number'?prop['chart.labels.decimals']:prop['chart.scale.decimals'],numLabels=prop['chart.labels.count'],step=(this.max-this.min)/numLabels;for(var i=1;i<=numLabels;++i){var x=ca.width-this.marginRight+(prop['chart.linewidth']/2),y=ca.height-this.marginBottom-(2*this.bulbBottomRadius)-((this.scaleHeight/numLabels)*i),text=RG.numberFormat({object:this,number:String((this.min+(i*step)).toFixed(decimals)),unitspre:typeof prop['chart.labels.units.pre']==='string'?prop['chart.labels.units.pre']:prop['chart.scale.units.pre'],unitspost:typeof prop['chart.labels.units.post']==='string'?prop['chart.labels.units.post']:prop['chart.scale.units.post'],point:typeof prop['chart.labels.point']==='string'?prop['chart.labels.point']:prop['chart.scale.point'],thousand:typeof prop['chart.labels.thousand']==='string'?prop['chart.labels.thousand']:prop['chart.scale.thousand']});var textConf=RG.getTextConf({object:this,prefix:'chart.labels'});RG.text2(this,{font:textConf.font,size:textConf.size,color:textConf.color,bold:textConf.bold,italic:textConf.italic,x:x+6,y:y,text:text,valign:'center',tag:'scale'});}
38
- RG.text2(this,{font:textConf.font,size:textConf.size,color:textConf.color,bold:textConf.bold,italic:textConf.italic,x:x+6,y:this.bulbBottomCentery-this.bulbBottomRadius,text:RG.numberFormat({object:this,number:this.min.toFixed(decimals),unitspre:typeof prop['chart.labels.units.pre']==='string'?prop['chart.labels.units.pre']:prop['chart.scale.units.pre'],unitspost:typeof prop['chart.labels.units.post']==='string'?prop['chart.labels.units.post']:prop['chart.scale.units.post'],point:typeof prop['chart.labels.point']==='string'?prop['chart.labels.point']:prop['chart.scale.point'],thousand:typeof prop['chart.labels.thousand']==='string'?prop['chart.labels.thousand']:prop['chart.scale.thousand']}),valign:'center',tag:'scale'});};this.getShape=this.getBar=function(e)
39
- {var mouseXY=RG.getMouseXY(e),mouseX=mouseXY[0],mouseY=mouseXY[1];for(var i=0;i<this.coords.length;i++){var coords=this.coords[i],left=coords[0],top=coords[1],width=coords[2],height=coords[3];this.pathBar();if(co.isPointInPath(mouseX,mouseY)){var tooltip=RG.parseTooltipText?RG.parseTooltipText(prop['chart.tooltips'],i):'';return{0:this,object:this,1:left,x:left,2:top,y:top,3:width,width:width,4:height,height:height,5:i,index:i,tooltip:tooltip};}}
40
- return null;};this.getValue=function(arg)
41
- {if(arg.length===2){var mouseX=arg[0],mouseY=arg[1];}else{var mouseXY=RG.getMouseXY(arg),mouseX=mouseXY[0],mouseY=mouseXY[1];}
42
- var value=(this.scaleHeight-(mouseY-this.scaleTopY))/this.scaleHeight;value*=(this.max-this.min);value+=this.min;value=ma.max(value,this.min);value=ma.min(value,this.max);return value;};this.highlight=this.Highlight=function(shape)
43
- {if(prop['chart.tooltips.highlight']){if(typeof prop['chart.highlight.style']==='function'){(prop['chart.highlight.style'])(shape);return;}
44
- this.pathBar();pa2(co,'s % f %',prop['chart.highlight.stroke'],prop['chart.highlight.fill']);}};this.getObjectByXY=function(e)
45
- {var mouseXY=RG.getMouseXY(e),mouseX=mouseXY[0],mouseY=mouseXY[1]
46
- this.pathBackground();if(co.isPointInPath(mouseX,mouseY)){return this;}};this.adjusting_mousemove=this.Adjusting_mousemove=function(e)
47
- {if(prop['chart.adjustable']&&RG.Registry.get('chart.adjusting')&&RG.Registry.get('chart.adjusting').uid==this.uid){var mouseXY=RG.getMouseXY(e),value=this.getValue(e);if(typeof(value)=='number'){RG.fireCustomEvent(this,'onadjust');this.value=Number(value.toFixed(prop['chart.scale.decimals']));RG.redrawCanvas(ca);}}};this.getYCoord=function(value)
48
- {if(value>this.max||value<this.min){return null;}
49
- var y=ma.abs(value-this.min)/ma.abs(this.max-this.min)
50
- y=y*(this.scaleBottomY-this.scaleTopY);return this.scaleBottomY-y;};this.overChartArea=function(e)
51
- {var mouseXY=RG.getMouseXY(e),mouseX=mouseXY[0],mouseY=mouseXY[1];this.pathBackground();return co.isPointInPath(mouseX,mouseY);};this.parseColors=function()
52
- {if(this.original_colors.length===0){this.original_colors['chart.colors']=RG.arrayClone(prop['chart.colors']);}
53
- var colors=prop['chart.colors'];for(var i=0;i<colors.length;++i){colors[i]=this.parseSingleColorForGradient(colors[i]);}};this.reset=function()
54
- {};this.parseSingleColorForGradient=function(color)
55
- {if(!color){return color;}
56
- if(typeof color==='string'&&color.match(/^gradient\((.*)\)$/i)){if(color.match(/^gradient\(({.*})\)$/i)){return RGraph.parseJSONGradient({object:this,def:RegExp.$1});}
57
- var parts=RegExp.$1.split(':');var grad=co.createLinearGradient(prop['chart.margin.left'],0,ca.width-prop['chart.margin.right'],0);var diff=1/(parts.length-1);grad.addColorStop(0,RG.trim(parts[0]));for(var j=1;j<parts.length;++j){grad.addColorStop(j*diff,RG.trim(parts[j]));}}
58
- return grad?grad:color;};this.on=function(type,func)
59
- {if(type.substr(0,2)!=='on'){type='on'+type;}
60
- if(typeof this[type]!=='function'){this[type]=func;}else{RG.addCustomEventListener(this,type,func);}
61
- return this;};this.firstDrawFunc=function()
62
- {};this.grow=function()
63
- {var obj=this,callback=arguments[1]||function(){},opt=arguments[0]||{},frames=opt.frames?opt.frames:30,origValue=Number(obj.currentValue),newValue=obj.value;newValue=ma.min(newValue,this.max);newValue=ma.max(newValue,this.min);var diff=newValue-origValue,step=(diff/frames),frame=0;function iterate()
64
- {obj.value=(step*frame)+origValue;RG.clear(obj.canvas);RG.redrawCanvas(obj.canvas);if(frame<frames){frame++;RG.Effects.updateCanvas(iterate);}else{callback(obj);}}
65
- iterate();return this;};RG.register(this);if(parseConfObjectForOptions){RG.parseObjectStyleConfig(this,conf.options);}};
12
+ RGraph = window.RGraph || {isrgraph:true,isRGraph:true,rgraph:true};
13
+
14
+ // The chart constructor. This function sets up the object. It takes the ID (the HTML attribute) of the canvas as the
15
+ // first argument and the data as the second. If you need to change this, you can.
16
+ //
17
+ RGraph.Thermometer = function (conf)
18
+ {
19
+ this.id = conf.id;
20
+ this.canvas = document.getElementById(this.id);
21
+ this.context = this.canvas.getContext ? this.canvas.getContext('2d') : null;
22
+ this.canvas.__object__ = this;
23
+ this.uid = RGraph.createUID();
24
+ this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.createUID();
25
+ this.colorsParsed = false;
26
+ this.type = 'thermometer';
27
+ this.isRGraph = true;
28
+ this.isrgraph = true;
29
+ this.rgraph = true;
30
+ this.min = RGraph.stringsToNumbers(conf.min);
31
+ this.max = RGraph.stringsToNumbers(conf.max);
32
+ this.value = RGraph.stringsToNumbers(conf.value);
33
+ this.coords = [];
34
+ this.graphArea = [];
35
+ this.currentValue = null;
36
+ this.coordsText = [];
37
+ this.original_colors = [];
38
+ this.firstDraw = true; // After the first draw this will be false
39
+ this.stopAnimationRequested = false;// Used to control the animations
40
+
41
+
42
+ this.properties =
43
+ {
44
+ linewidth: 1,
45
+
46
+ backgroundColor: 'white',
47
+
48
+ colorsStroke: 'black',
49
+ colors: ['red'],
50
+
51
+ marginLeft: 35,
52
+ marginRight: 35,
53
+ marginTop: 35,
54
+ marginBottom: 35,
55
+
56
+ tickmarksSize: 2,
57
+ tickmarksCount: 10,
58
+
59
+ textColor: 'black',
60
+ textFont: 'Arial, Verdana, sans-serif',
61
+ textSize: 12,
62
+ textBold: false,
63
+ textItalic: false,
64
+ textAccessible: false,
65
+ textAccessibleOverflow: 'visible',
66
+ textAccessiblePointerevents:false,
67
+ text: null,
68
+
69
+ scaleVisible: false,
70
+ scaleUnitsPre: '',
71
+ scaleUnitsPost: '',
72
+ scaleDecimals: 0,
73
+ scaleThousand: ',',
74
+ scalePoint: '.',
75
+
76
+ title: '',
77
+ titleFont: null,
78
+ titleSize: null,
79
+ titleColor: null,
80
+ titleBold: null,
81
+ titleItalic: null,
82
+ titleHalign: null,
83
+ titleValign: null,
84
+ titleOffsetx: 0,
85
+ titleOffsety: 0,
86
+ titleSubtitle: '',
87
+ titleSubtitleSize: null,
88
+ titleSubtitleColor: '#aaa',
89
+ titleSubtitleFont: null,
90
+ titleSubtitleBold: null,
91
+ titleSubtitleItalic: null,
92
+ titleSubtitleOffsetx: 0,
93
+ titleSubtitleOffsety: 0,
94
+ titleSide: '',
95
+ titleSideBold: null,
96
+ titleSideFont: null,
97
+ titleSideSize: null,
98
+ titleSideColor: null,
99
+ titleSideItalic: null,
100
+ titleSideOffsetx: 0,
101
+ titleSideOffsety: 0,
102
+
103
+ shadow: true,
104
+ shadowOffsetx: 0,
105
+ shadowOffsety: 0,
106
+ shadowBlur: 15,
107
+ shadowColor: '#ddd',
108
+
109
+ resizable: false,
110
+ resizableHandleBackground: null,
111
+
112
+ contextmenu: null,
113
+
114
+ adjustable: false,
115
+
116
+ labelsValue: true,
117
+ labelsValueColor: null,
118
+ labelsValueFont: null,
119
+ labelsValueSize: null,
120
+ labelsValueBold: null,
121
+ labelsValueItalic: null,
122
+ labelsValueDecimals: null,
123
+ labelsValueThousand: null,
124
+ labelsValuePoint: null,
125
+ labelsValueUnitsPre: null,
126
+ labelsValueUnitsPost: null,
127
+ labelsValueOffsetx: 0,
128
+ labelsValueOffsety: 0,
129
+
130
+ labelsCount: 5,
131
+ labelsDecimals: null,
132
+ labelsUnitsPre: null,
133
+ labelsUnitsPost: null,
134
+ labelsPoint: null,
135
+ labelsThousand: null,
136
+ labelsColor: null,
137
+ labelsFont: null,
138
+ labelsSize: null,
139
+ labelsBold: null,
140
+ labelsItalic: null,
141
+ labelsOffsetx: 0,
142
+ labelsOffsety: 0,
143
+
144
+ annotatable: false,
145
+ annotatableColor: 'black',
146
+ annotatableLinewidth: 1,
147
+
148
+ tooltips: null,
149
+ tooltipsHighlight: true,
150
+ tooltipsEffect: 'slide',
151
+ tooltipsEvent: 'click',
152
+ tooltipsCssClass: 'RGraph_tooltip',
153
+ tooltipsCss: null,
154
+ tooltipsFormattedThousand: ',',
155
+ tooltipsFormattedPoint: '.',
156
+ tooltipsFormattedDecimals: 0,
157
+ tooltipsFormattedUnitsPre: '',
158
+ tooltipsFormattedUnitsPost: '',
159
+ tooltipsFormattedKeyColors: null,
160
+ tooltipsFormattedKeyColorsShape: 'square',
161
+ tooltipsFormattedKeyLabels: [],
162
+ tooltipsFormattedListType: 'ul',
163
+ tooltipsFormattedListItems: null,
164
+ tooltipsFormattedTableHeaders: null,
165
+ tooltipsFormattedTableData: null,
166
+ tooltipsPointer: true,
167
+ tooltipsPointerOffsetx: 0,
168
+ tooltipsPointerOffsety: 0,
169
+ tooltipsPositionStatic: true,
170
+ tooltipsHotspotIgnore: null,
171
+
172
+ highlightStroke: 'rgba(0,0,0,0)',
173
+ highlightFill: 'rgba(255,255,255,0.7)',
174
+
175
+ clearto: 'rgba(0,0,0,0)',
176
+
177
+ bulbBottomRadiusAdjust: 0,
178
+ bulbBottomRadius: null
179
+ }
180
+
181
+
182
+
183
+ //
184
+ // A simple check that the browser has canvas support
185
+ //
186
+ if (!this.canvas) {
187
+ alert('[THERMOMETER] No canvas support');
188
+ return;
189
+ }
190
+
191
+ //
192
+ // The thermometer can only have one data point so only this.$0 needs to be created
193
+ //
194
+ this.$0 = {};
195
+
196
+ // Easy access to properties and the path function
197
+ var properties = this.properties;
198
+ this.path = RGraph.pathObjectFunction;
199
+
200
+ //
201
+ // "Decorate" the object with the generic effects if the effects library has been included
202
+ //
203
+ if (RGraph.Effects && typeof RGraph.Effects.decorate === 'function') {
204
+ RGraph.Effects.decorate(this);
205
+ }
206
+
207
+
208
+
209
+ // Add the responsive method. This method resides in the common file.
210
+ this.responsive = RGraph.responsive;
211
+
212
+
213
+ //
214
+ // A setter.
215
+ this.set = function (name)
216
+ {
217
+ var value = typeof arguments[1] === 'undefined' ? null : arguments[1];
218
+
219
+ // the number of arguments is only one and it's an
220
+ // object - parse it for configuration data and return.
221
+ if (arguments.length === 1 && typeof arguments[0] === 'object') {
222
+ for (i in arguments[0]) {
223
+ if (typeof i === 'string') {
224
+ this.set(i, arguments[0][i]);
225
+ }
226
+ }
227
+
228
+ return this;
229
+ }
230
+
231
+ properties[name] = value;
232
+
233
+ return this;
234
+ };
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+ //
244
+ // A getter.
245
+ //
246
+ // @param name string The name of the property to get
247
+ //
248
+ this.get = function (name)
249
+ {
250
+ return properties[name];
251
+ };
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+ //
261
+ // Draws the thermometer
262
+ //
263
+ this.draw = function ()
264
+ {
265
+ // Fire the custom RGraph onbeforedraw event (which should be fired before the chart is drawn)
266
+ RGraph.fireCustomEvent(this, 'onbeforedraw');
267
+
268
+
269
+
270
+ // Translate half a pixel for antialiasing purposes - but only if it hasn't been
271
+ // done already
272
+ //
273
+ // MUST be the first thing done!
274
+ //
275
+ if (!this.canvas.__rgraph_aa_translated__) {
276
+ this.context.translate(0.5,0.5);
277
+
278
+ this.canvas.__rgraph_aa_translated__ = true;
279
+ }
280
+
281
+
282
+ // Max/min boundary constraints
283
+ this.value = Math.min(this.max, this.value);
284
+ this.value = Math.max(this.min, this.value);
285
+
286
+ //
287
+ // Parse the colors. This allows for simple gradient syntax
288
+ //
289
+ if (!this.colorsParsed) {
290
+ this.parseColors();
291
+
292
+ // Don't want to do this again
293
+ this.colorsParsed = true;
294
+ }
295
+
296
+ //
297
+ // Set the current value
298
+ //
299
+ this.currentValue = this.value;
300
+
301
+
302
+
303
+ //
304
+ // Stop this growing uncontrollably
305
+ //
306
+ this.coordsText = [];
307
+
308
+
309
+
310
+ //
311
+ // Make the margins easy to access
312
+ //
313
+ this.marginLeft = properties.marginLeft;
314
+ this.marginRight = properties.marginRight;
315
+ this.marginTop = properties.marginTop;
316
+ this.marginBottom = properties.marginBottom;
317
+
318
+
319
+ // Get the scale
320
+ this.scale2 = RGraph.getScale({object: this, options: {
321
+ 'scale.max': this.max,
322
+ 'scale.min': this.min,
323
+ 'scale.strict': true,
324
+ 'scale.thousand': properties.scaleThousand,
325
+ 'scale.point': properties.scalePoint,
326
+ 'scale.decimals': properties.scaleDecimals,
327
+ 'ylabels.count': properties.labelsCount,
328
+ 'scale.round': properties.scaleRound,
329
+ 'scale.units.pre': properties.scaleUnitsPre,
330
+ 'scale.units.post': properties.scaleUnitsPost
331
+ }});
332
+
333
+
334
+
335
+ // Work out the coordinates and positions
336
+
337
+ this.x = this.marginLeft;
338
+ this.width = this.canvas.width - this.marginLeft - this.marginRight;
339
+ this.y = this.marginTop + (this.width / 2);
340
+
341
+
342
+ this.halfWidth = this.width / 2;
343
+
344
+ this.bulbTopCenterx = this.marginLeft + (this.width / 2);
345
+ this.bulbTopCentery = this.marginTop + (this.width / 2);
346
+ this.bulbTopRadius = this.width / 2;
347
+ this.bulbBottomCenterx = this.marginLeft + (this.width / 2);
348
+ this.bulbBottomRadius = typeof properties.bulbBottomRadius === 'number' ? properties.bulbBottomRadius : this.width * 0.75 + properties.bulbBottomRadiusAdjust;
349
+ this.bulbBottomCentery = this.canvas.height - this.marginBottom - this.bulbBottomRadius;
350
+
351
+ this.scaleTopY = this.bulbTopCentery;
352
+ this.scaleBottomY = this.bulbBottomCentery - this.bulbBottomRadius;
353
+ this.scaleHeight = this.scaleBottomY - this.scaleTopY;
354
+
355
+ this.height = this.getYCoord(this.min) - this.getYCoord(this.value);
356
+
357
+ this.coords[0] = [
358
+ this.x,
359
+ this.getYCoord(this.value),
360
+ this.width,
361
+ this.height
362
+ ];
363
+
364
+ // Draw the background
365
+ this.drawBackground();
366
+
367
+ // Draw the bar that represents the value
368
+ this.drawBar();
369
+
370
+
371
+ // Draw the tickmarks
372
+ this.drawTickMarks();
373
+
374
+ //
375
+ // Draw the label
376
+ //
377
+ this.drawLabels();
378
+
379
+
380
+
381
+ //
382
+ // Draw the title
383
+ //
384
+ if (properties.title) {
385
+ this.drawTitle();
386
+ }
387
+
388
+ //
389
+ // Draw the side title
390
+ //
391
+ if (properties.titleSide) {
392
+ this.drawSideTitle();
393
+ }
394
+
395
+
396
+
397
+
398
+ //
399
+ // Setup the context menu if required
400
+ //
401
+ if (properties.contextmenu) {
402
+ RGraph.showContext(this);
403
+ }
404
+
405
+
406
+
407
+
408
+ //
409
+ // Add custom text thats specified
410
+ //
411
+ RGraph.addCustomText(this);
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+ //
423
+ // This installs the event listeners
424
+ //
425
+ RGraph.installEventListeners(this);
426
+
427
+
428
+ //
429
+ // Fire the onfirstdraw event
430
+ //
431
+ if (this.firstDraw) {
432
+ this.firstDraw = false;
433
+ RGraph.fireCustomEvent(this, 'onfirstdraw');
434
+ this.firstDrawFunc();
435
+ }
436
+
437
+
438
+
439
+ //
440
+ // Fire the custom RGraph draw event (which should be fired when you have drawn the chart)
441
+ //
442
+ RGraph.fireCustomEvent(this, 'ondraw');
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+ //
454
+ // Install any inline responsive configuration. This
455
+ // should be last in the draw function - even after
456
+ // the draw events.
457
+ //
458
+ RGraph.installInlineResponsive(this);
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+ return this;
468
+ };
469
+
470
+
471
+
472
+
473
+
474
+
475
+
476
+
477
+ //
478
+ // Draws the thermometer
479
+ //
480
+ this.drawBackground = function ()
481
+ {
482
+ if (properties.shadow) {
483
+ RGraph.setShadow(
484
+ this,
485
+ properties.shadowColor,
486
+ properties.shadowOffsetx,
487
+ properties.shadowOffsety,
488
+ properties.shadowBlur
489
+ );
490
+ }
491
+
492
+ // Draw the outline and background
493
+ this.pathBackground();
494
+
495
+ this.context.strokeStyle = properties.colorsStroke;
496
+ this.context.fillStyle = properties.backgroundColor;
497
+ this.context.lineWidth = 1 + properties.linewidth;
498
+
499
+ this.context.stroke();
500
+ this.context.fill();
501
+
502
+ this.context.lineWidth = 1;
503
+ };
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+ //
513
+ // This draws the bar that indicates the value of the thermometer. It makes use
514
+ // of the .pathBar() function.
515
+ //
516
+ this.drawBar = function ()
517
+ {
518
+ this.pathBar();
519
+
520
+ this.path('f %', properties.colors[0]);
521
+ };
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+ //
531
+ // This function draws the path that indicates the specified value. It
532
+ // doesn't stroke or fill the path.
533
+ //
534
+ this.pathBar = function ()
535
+ {
536
+ var barHeight = this.coords[0][3],
537
+ y = (this.coords[0][1] + this.coords[0][3]) - barHeight
538
+
539
+ RGraph.noShadow(this);
540
+
541
+ // Draw the bar that indicates the value
542
+ this.path(
543
+ 'b ss transparent r % % % % m % % a % % % 0 6.28 false',
544
+ this.coords[0][0], y, this.coords[0][2], this.bulbBottomCentery - y,
545
+ this.bulbBottomCenterx + this.bulbBottomRadius, this.bulbBottomCentery,
546
+ this.bulbBottomCenterx, this.bulbBottomCentery, this.bulbBottomRadius
547
+ );
548
+ };
549
+
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+ //
558
+ // This function draws the path that indicates that encompasses the
559
+ // background. It's used by the overChartArea() function.
560
+ //
561
+ this.pathBackground = function ()
562
+ {
563
+ this.path(
564
+ 'b r % % % % a % % % 3.1415927 6.28 false m % % a % % % 0 6.2830 false c',
565
+ this.x,this.scaleTopY,this.coords[0][2],this.bulbBottomCentery - this.scaleTopY,
566
+ this.bulbTopCenterx,this.bulbTopCentery,this.bulbTopRadius,
567
+ this.bulbBottomCenterx,this.bulbBottomCentery,
568
+ this.bulbBottomCenterx,this.bulbBottomCentery,this.bulbBottomRadius
569
+ );
570
+ };
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+ //
580
+ // Draws the tickmarks of the thermometer
581
+ //
582
+ this.drawTickMarks = function ()
583
+ {
584
+ if (properties.tickmarksCount) {
585
+
586
+ var ticksize = properties.tickmarksSize;
587
+
588
+ this.context.strokeStyle = properties.colorsStroke;
589
+ this.context.lineWidth = properties.linewidth / 2;
590
+
591
+ // Left hand side tickmarks
592
+ this.context.beginPath();
593
+ for (var i=0; i<=properties.tickmarksCount; ++i) {
594
+
595
+ var y = this.scaleBottomY - ((this.scaleHeight / properties.tickmarksCount) * i);
596
+
597
+ this.context.moveTo(this.marginLeft, Math.round(y));
598
+ this.context.lineTo(this.marginLeft + ticksize, Math.round(y));
599
+
600
+ // Right hand side tickmarks
601
+ this.context.moveTo(this.canvas.width - this.marginRight, Math.round(y));
602
+ this.context.lineTo(this.canvas.width - this.marginRight - ticksize, Math.round(y));
603
+ }
604
+ this.context.stroke();
605
+
606
+ this.context.lineWidth = 1;
607
+ }
608
+ };
609
+
610
+
611
+
612
+
613
+
614
+
615
+
616
+
617
+ //
618
+ // Draws the labels of the thermometer. Now (4th August 2011) draws
619
+ // the scale too
620
+ //
621
+ this.drawLabels = function ()
622
+ {
623
+ //
624
+ // This draws draws the label that sits at the top of the chart
625
+ //
626
+ if (properties.labelsValue) {
627
+
628
+ // Weird...
629
+ var text = properties.scaleVisible ?
630
+ RGraph.numberFormat({
631
+ object: this,
632
+ number: this.value.toFixed(typeof properties.labelsValueDecimals === 'number' ? properties.labelsValueDecimals : properties.scaleDecimals),
633
+ unitspre: typeof properties.labelsValueUnitsPre === 'string' ? properties.labelsValueUnitsPre : properties.scaleUnitsPre,
634
+ unitspost: typeof properties.labelsValueUnitsPost === 'string' ? properties.labelsValueUnitsPost : properties.scaleUnitsPost,
635
+ point: typeof properties.labelsValuePoint === 'string' ? properties.labelsValuePoint : properties.scalePoint,
636
+ thousand: typeof properties.labelsValueThousand === 'string' ? properties.labelsValueThousand : properties.scaleThousand
637
+ })
638
+ :
639
+ RGraph.numberFormat({
640
+ object: this,
641
+ number: this.value.toFixed(typeof properties.labelsValueDecimals === 'number' ? properties.labelsValueDecimals : properties.scaleDecimals),
642
+ unitspre: typeof properties.labelsValueUnitsPre === 'string' ? properties.labelsValueUnitsPre : properties.scaleUnitsPre,
643
+ unitspost: typeof properties.labelsValueUnitsPost === 'string' ? properties.labelsValueUnitsPost : properties.scaleUnitsPost,
644
+ point: typeof properties.labelsValuePoint === 'string' ? properties.labelsValuePoint : properties.scalePoint,
645
+ thousand: typeof properties.labelsValueThousand === 'string' ? properties.labelsValueThousand : properties.scaleThousand
646
+ });
647
+
648
+ var textConf = RGraph.getTextConf({
649
+ object: this,
650
+ prefix: 'labelsValue'
651
+ });
652
+
653
+ RGraph.text({
654
+
655
+ object: this,
656
+
657
+ font: textConf.font,
658
+ size: textConf.size,
659
+ color: textConf.color,
660
+ bold: textConf.bold,
661
+ italic: textConf.italic,
662
+
663
+ x: this.coords[0][0] + (this.coords[0][2] / 2) + properties.labelsValueOffsetx,
664
+ y: this.coords[0][1] + 7 + properties.labelsValueOffsety,
665
+
666
+ text: text,
667
+
668
+ valign: 'top',
669
+ halign: 'center',
670
+
671
+ bounding: true,
672
+ boundingFill:'white',
673
+
674
+ tag: 'labels.value'
675
+ });
676
+ }
677
+
678
+
679
+ //
680
+ // Draw the scale if requested
681
+ //
682
+ if (properties.scaleVisible) {
683
+ this.drawScale();
684
+ }
685
+ };
686
+
687
+
688
+
689
+
690
+
691
+
692
+
693
+
694
+ //
695
+ // Draws the title
696
+ //
697
+ this.drawTitle = function ()
698
+ {
699
+ RGraph.drawTitle(this);
700
+ };
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+ //
710
+ // Draws the title
711
+ //
712
+ this.drawSideTitle = function ()
713
+ {
714
+ var textConf = RGraph.getTextConf({
715
+ object: this,
716
+ prefix: 'titleSide'
717
+ });
718
+
719
+ var x = this.marginLeft - 3;
720
+ var y = (this.scaleHeight / 2) + this.marginTop + this.bulbTopRadius;
721
+
722
+ // Add any use specified offset
723
+ if (typeof properties.titleSideOffsetx === 'number') x += properties.titleSideOffsetx;
724
+ if (typeof properties.titleSideOffsety === 'number') y += properties.titleSideOffsety;
725
+
726
+ this.context.fillStyle = properties.textColor;
727
+ RGraph.text({
728
+
729
+ object: this,
730
+
731
+ font: textConf.font,
732
+ size: textConf.size,
733
+ color: textConf.color,
734
+ bold: textConf.bold,
735
+ italic: textConf.italic,
736
+
737
+ x: x,
738
+ y: y,
739
+
740
+ text: String(properties.titleSide),
741
+
742
+ valign: 'bottom',
743
+ halign: 'center',
744
+
745
+ angle: 270,
746
+ tag: 'title.side',
747
+ accessible: false
748
+ });
749
+ };
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+ //
759
+ // Draw the scale if requested
760
+ //
761
+ this.drawScale = function ()
762
+ {
763
+ this.context.fillStyle = properties.textColor;
764
+
765
+ var units_pre = properties.scaleUnitsPre,
766
+ units_post = properties.scaleUnitsPost,
767
+ decimals = typeof properties.labelsDecimals === 'number' ? properties.labelsDecimals : properties.scaleDecimals,
768
+ numLabels = properties.labelsCount,
769
+ step = (this.max - this.min) / numLabels;
770
+
771
+ for (var i=1; i<=numLabels; ++i) {
772
+
773
+ var x = this.canvas.width - this.marginRight + (properties.linewidth / 2),
774
+ y = this.canvas.height - this.marginBottom - (2 * this.bulbBottomRadius) - ((this.scaleHeight / numLabels) * i),
775
+ text = RGraph.numberFormat({
776
+ object: this,
777
+ number: String((this.min + (i * step)).toFixed(decimals)),
778
+ unitspre: typeof properties.labelsUnitsPre === 'string' ? properties.labelsUnitsPre : properties.scaleUnitsPre,
779
+ unitspost: typeof properties.labelsUnitsPost === 'string' ? properties.labelsUnitsPost : properties.scaleUnitsPost,
780
+ point: typeof properties.labelsPoint === 'string' ? properties.labelsPoint : properties.scalePoint,
781
+ thousand: typeof properties.labelsThousand === 'string' ? properties.labelsThousand : properties.scaleThousand
782
+ });
783
+
784
+ var textConf = RGraph.getTextConf({
785
+ object: this,
786
+ prefix: 'labels'
787
+ });
788
+
789
+ RGraph.text({
790
+
791
+ object: this,
792
+
793
+ font: textConf.font,
794
+ size: textConf.size,
795
+ color: textConf.color,
796
+ bold: textConf.bold,
797
+ italic: textConf.italic,
798
+
799
+ x: x + 5 + properties.labelsOffsetx,
800
+ y: y + properties.labelsOffsety,
801
+
802
+ text: text,
803
+ valign: 'center',
804
+ tag: 'scale'
805
+ });
806
+ }
807
+
808
+ // Draw zero
809
+ RGraph.text({
810
+
811
+ object: this,
812
+
813
+ font: textConf.font,
814
+ size: textConf.size,
815
+ color: textConf.color,
816
+ bold: textConf.bold,
817
+ italic: textConf.italic,
818
+
819
+ x: x + 6 + properties.labelsOffsetx,
820
+ y: this.bulbBottomCentery - this.bulbBottomRadius + properties.labelsOffsety,
821
+ text: RGraph.numberFormat({
822
+ object: this,
823
+ number: this.min.toFixed(decimals),
824
+ unitspre: typeof properties.labelsUnitsPre === 'string' ? properties.labelsUnitsPre : properties.scaleUnitsPre,
825
+ unitspost: typeof properties.labelsUnitsPost === 'string' ? properties.labelsUnitsPost : properties.scaleUnitsPost,
826
+ point: typeof properties.labelsPoint === 'string' ? properties.labelsPoint : properties.scalePoint,
827
+ thousand: typeof properties.labelsThousand === 'string' ? properties.labelsThousand : properties.scaleThousand
828
+ }),
829
+ valign: 'center',
830
+ tag: 'scale'
831
+ });
832
+ };
833
+
834
+
835
+
836
+
837
+
838
+
839
+
840
+
841
+ //
842
+ // Returns the focused/clicked bar
843
+ //
844
+ // @param event e The event object
845
+ //
846
+ this.getShape = function (e)
847
+ {
848
+ var mouseXY = RGraph.getMouseXY(e),
849
+ mouseX = mouseXY[0],
850
+ mouseY = mouseXY[1];
851
+
852
+ for (var i=0; i<this.coords.length; i++) {
853
+
854
+ if (RGraph.tooltipsHotspotIgnore(this, i)) {
855
+ continue;
856
+ }
857
+
858
+ var coords = this.coords[i],
859
+ left = coords[0],
860
+ top = coords[1],
861
+ width = coords[2],
862
+ height = coords[3];
863
+
864
+ this.pathBar();
865
+
866
+ if (this.context.isPointInPath(mouseX, mouseY)) {
867
+
868
+ var tooltip = RGraph.parseTooltipText ? RGraph.parseTooltipText(properties.tooltips, i) : '';
869
+
870
+ return {
871
+ object: this,
872
+ x: left,
873
+ y: top,
874
+ width: width,
875
+ height: height,
876
+ index: 0,
877
+ dataset: 0,
878
+ sequentialIndex: 0,
879
+ tooltip: typeof tooltip === 'string' ? tooltip : null
880
+ };
881
+ }
882
+ }
883
+
884
+ return null;
885
+ };
886
+
887
+
888
+
889
+
890
+
891
+
892
+
893
+
894
+ //
895
+ // This function returns the value that the mouse is positioned t, regardless of
896
+ // the actual indicated value.
897
+ //
898
+ // @param object e The event object (or it can also be an two element array containing the X/Y coords)
899
+ //
900
+ this.getValue = function (arg)
901
+ {
902
+ if (arg.length === 2) {
903
+ var mouseX = arg[0],
904
+ mouseY = arg[1];
905
+ } else {
906
+ var mouseXY = RGraph.getMouseXY(arg),
907
+ mouseX = mouseXY[0],
908
+ mouseY = mouseXY[1];
909
+ }
910
+
911
+ var value = (this.scaleHeight - (mouseY - this.scaleTopY)) / this.scaleHeight;
912
+ value *= (this.max - this.min);
913
+ value += this.min;
914
+
915
+ value = Math.max(value, this.min);
916
+ value = Math.min(value, this.max);
917
+
918
+ return value;
919
+ };
920
+
921
+
922
+
923
+
924
+
925
+
926
+
927
+
928
+ //
929
+ // Each object type has its own Highlight() function which highlights the appropriate shape
930
+ //
931
+ // @param object shape The shape to highlight
932
+ //
933
+ this.highlight = function (shape)
934
+ {
935
+ if (properties.tooltipsHighlight) {
936
+
937
+ if (typeof properties.highlightStyle === 'function') {
938
+ (properties.highlightStyle)(shape);
939
+ return;
940
+ }
941
+
942
+ this.pathBar();
943
+
944
+ this.path(
945
+ 's % f %',
946
+ properties.highlightStroke, properties.highlightFill
947
+ );
948
+ }
949
+ };
950
+
951
+
952
+
953
+
954
+
955
+
956
+
957
+
958
+ //
959
+ // The getObjectByXY() worker method. Don't call this - call:
960
+ //
961
+ // RGraph.ObjectRegistry.getObjectByXY(e)
962
+ //
963
+ // @param object e The event object
964
+ //
965
+ this.getObjectByXY = function (e)
966
+ {
967
+ var mouseXY = RGraph.getMouseXY(e),
968
+ mouseX = mouseXY[0],
969
+ mouseY = mouseXY[1]
970
+
971
+ // Draw the background shape (don't stroke or fill it)
972
+ this.pathBackground();
973
+
974
+ if (this.context.isPointInPath(mouseX, mouseY)) {
975
+ return this;
976
+ }
977
+ };
978
+
979
+
980
+
981
+
982
+
983
+
984
+
985
+
986
+ //
987
+ // This method handles the adjusting calculation for when the mouse is moved
988
+ //
989
+ // @param object e The event object
990
+ //
991
+ this.adjusting_mousemove = function (e)
992
+ {
993
+ //
994
+ // Handle adjusting for the Thermometer
995
+ //
996
+ if (properties.adjustable && RGraph.Registry.get('adjusting') && RGraph.Registry.get('adjusting').uid == this.uid) {
997
+
998
+ var mouseXY = RGraph.getMouseXY(e),
999
+ value = this.getValue(e);
1000
+
1001
+ if (typeof value == 'number') {
1002
+
1003
+ // Fire the onadjust event
1004
+ RGraph.fireCustomEvent(this, 'onadjust');
1005
+
1006
+ this.value = Number(value.toFixed(properties.scaleDecimals));
1007
+
1008
+ RGraph.redrawCanvas(this.canvas);
1009
+ }
1010
+ }
1011
+ };
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
1018
+
1019
+
1020
+ //
1021
+ // Returns the appropriate Y coord for a value
1022
+ //
1023
+ // @param number value The value to return the coord for
1024
+ //
1025
+ this.getYCoord = function (value)
1026
+ {
1027
+ if (value > this.max || value < this.min) {
1028
+ return null;
1029
+ }
1030
+
1031
+ var y = Math.abs(value - this.min) / Math.abs(this.max - this.min)
1032
+ y = y * (this.scaleBottomY - this.scaleTopY);
1033
+
1034
+
1035
+ return this.scaleBottomY - y;
1036
+ };
1037
+
1038
+
1039
+
1040
+
1041
+
1042
+
1043
+
1044
+
1045
+ //
1046
+ // This returns true/false as to whether the cursor is over the chart area.
1047
+ // The cursor does not necessarily have to be over the bar itself.
1048
+ //
1049
+ this.overChartArea = function (e)
1050
+ {
1051
+ var mouseXY = RGraph.getMouseXY(e),
1052
+ mouseX = mouseXY[0],
1053
+ mouseY = mouseXY[1];
1054
+
1055
+ this.pathBackground();
1056
+
1057
+ return this.context.isPointInPath(mouseX, mouseY);
1058
+ };
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+ //
1068
+ // This allows for easy specification of gradients
1069
+ //
1070
+ this.parseColors = function ()
1071
+ {
1072
+ // Save the original colors so that they can be restored when the canvas is reset
1073
+ if (this.original_colors.length === 0) {
1074
+ this.original_colors.colors = RGraph.arrayClone(properties.colors);
1075
+ }
1076
+
1077
+
1078
+
1079
+
1080
+
1081
+ var colors = properties.colors;
1082
+
1083
+ for (var i=0; i<colors.length; ++i) {
1084
+ colors[i] = this.parseSingleColorForGradient(colors[i]);
1085
+ }
1086
+ };
1087
+
1088
+
1089
+
1090
+
1091
+
1092
+
1093
+
1094
+
1095
+ //
1096
+ // Use this function to reset the object to the post-constructor state. Eg reset colors if
1097
+ // need be etc
1098
+ //
1099
+ this.reset = function ()
1100
+ {
1101
+ };
1102
+
1103
+
1104
+
1105
+
1106
+
1107
+
1108
+
1109
+
1110
+ //
1111
+ // This parses a single color value
1112
+ //
1113
+ this.parseSingleColorForGradient = function (color)
1114
+ {
1115
+ if (!color) {
1116
+ return color;
1117
+ }
1118
+
1119
+ if (typeof color === 'string' && color.match(/^gradient\((.*)\)$/i)) {
1120
+
1121
+ // Allow for JSON gradients
1122
+ if (color.match(/^gradient\(({.*})\)$/i)) {
1123
+ return RGraph.parseJSONGradient({
1124
+ object: this,
1125
+ def: RegExp.$1
1126
+ });
1127
+ }
1128
+
1129
+ var parts = RegExp.$1.split(':');
1130
+
1131
+ // Create the gradient
1132
+ var grad = this.context.createLinearGradient(
1133
+ properties.marginLeft,
1134
+ 0,
1135
+ this.canvas.width - properties.marginRight,
1136
+ 0
1137
+ );
1138
+
1139
+ var diff = 1 / (parts.length - 1);
1140
+
1141
+ grad.addColorStop(0, RGraph.trim(parts[0]));
1142
+
1143
+ for (var j=1; j<parts.length; ++j) {
1144
+ grad.addColorStop(j * diff, RGraph.trim(parts[j]));
1145
+ }
1146
+ }
1147
+
1148
+ return grad ? grad : color;
1149
+ };
1150
+
1151
+
1152
+
1153
+
1154
+
1155
+
1156
+
1157
+
1158
+ //
1159
+ // Using a function to add events makes it easier to facilitate method chaining
1160
+ //
1161
+ // @param string type The type of even to add
1162
+ // @param function func
1163
+ //
1164
+ this.on = function (type, func)
1165
+ {
1166
+ if (type.substr(0,2) !== 'on') {
1167
+ type = 'on' + type;
1168
+ }
1169
+
1170
+ if (typeof this[type] !== 'function') {
1171
+ this[type] = func;
1172
+ } else {
1173
+ RGraph.addCustomEventListener(this, type, func);
1174
+ }
1175
+
1176
+ return this;
1177
+ };
1178
+
1179
+
1180
+
1181
+
1182
+
1183
+
1184
+
1185
+
1186
+ //
1187
+ // Used in chaining. Runs a function there and then - not waiting for
1188
+ // the events to fire (eg the onbeforedraw event)
1189
+ //
1190
+ // @param function func The function to execute
1191
+ //
1192
+ this.exec = function (func)
1193
+ {
1194
+ func(this);
1195
+
1196
+ return this;
1197
+ };
1198
+
1199
+
1200
+
1201
+
1202
+
1203
+
1204
+
1205
+
1206
+ //
1207
+ // This function runs once only
1208
+ // (put at the end of the file (before any effects))
1209
+ //
1210
+ this.firstDrawFunc = function ()
1211
+ {
1212
+ };
1213
+
1214
+
1215
+
1216
+
1217
+
1218
+
1219
+
1220
+
1221
+ //
1222
+ // Gauge Grow
1223
+ //
1224
+ // This effect gradually increases the represented value
1225
+ //
1226
+ // @param object obj The chart object
1227
+ // @param Not used - pass null
1228
+ // @param function An optional callback function
1229
+ //
1230
+ this.grow = function ()
1231
+ {
1232
+ // Cancel any stop request if one is pending
1233
+ this.cancelStopAnimation();
1234
+
1235
+ var obj = this,
1236
+ callback = arguments[1] || function () {},
1237
+ opt = arguments[0] || {},
1238
+ frames = opt.frames ? opt.frames : 30,
1239
+ origValue = Number(obj.currentValue),
1240
+ newValue = obj.value;
1241
+
1242
+ newValue = Math.min(newValue, this.max);
1243
+ newValue = Math.max(newValue, this.min);
1244
+
1245
+ var diff = newValue - origValue,
1246
+ step = (diff / frames),
1247
+ frame = 0;
1248
+
1249
+
1250
+ function iterate ()
1251
+ {
1252
+ if (obj.stopAnimationRequested) {
1253
+
1254
+ // Reset the flag
1255
+ obj.stopAnimationRequested = false;
1256
+
1257
+ return;
1258
+ }
1259
+
1260
+ // Set the new value
1261
+ obj.value = (step * frame) + origValue;
1262
+
1263
+ RGraph.clear(obj.canvas);
1264
+ RGraph.redrawCanvas(obj.canvas);
1265
+
1266
+ if (frame < frames) {
1267
+ frame++;
1268
+ RGraph.Effects.updateCanvas(iterate);
1269
+ } else {
1270
+ callback(obj);
1271
+ }
1272
+ }
1273
+
1274
+ iterate();
1275
+
1276
+ return this;
1277
+ };
1278
+
1279
+
1280
+
1281
+
1282
+
1283
+
1284
+
1285
+
1286
+ //
1287
+ // Couple of functions that allow you to control the
1288
+ // animation effect
1289
+ //
1290
+ this.stopAnimation = function ()
1291
+ {
1292
+ this.stopAnimationRequested = true;
1293
+ };
1294
+
1295
+ this.cancelStopAnimation = function ()
1296
+ {
1297
+ this.stopAnimationRequested = false;
1298
+ };
1299
+
1300
+
1301
+
1302
+
1303
+
1304
+
1305
+
1306
+
1307
+ //
1308
+ // A worker function that handles Bar chart specific tooltip substitutions
1309
+ //
1310
+ this.tooltipSubstitutions = function (opt)
1311
+ {
1312
+ return {
1313
+ index: 0,
1314
+ dataset: 0,
1315
+ sequentialIndex: 0,
1316
+ value: this.value,
1317
+ values: [this.value]
1318
+ };
1319
+ };
1320
+
1321
+
1322
+
1323
+
1324
+
1325
+
1326
+
1327
+
1328
+ //
1329
+ // A worker function that returns the correct color/label/value
1330
+ //
1331
+ // @param object specific The indexes that are applicable
1332
+ // @param number index The appropriate index
1333
+ //
1334
+ this.tooltipsFormattedCustom = function (specific, index)
1335
+ {
1336
+ var color = (properties.tooltipsFormattedKeyColors && properties.tooltipsFormattedKeyColors[0]) ? properties.tooltipsFormattedKeyColors[0] : properties.colors[0];
1337
+ var label = (properties.tooltipsFormattedKeyLabels && properties.tooltipsFormattedKeyLabels[0]) ? properties.tooltipsFormattedKeyLabels[0] : '';
1338
+
1339
+ return {
1340
+ label: label,
1341
+ color: color
1342
+ };
1343
+ };
1344
+
1345
+
1346
+
1347
+
1348
+
1349
+
1350
+
1351
+
1352
+ //
1353
+ // This allows for static tooltip positioning
1354
+ //
1355
+ this.positionTooltipStatic = function (args)
1356
+ {
1357
+ var obj = args.object,
1358
+ e = args.event,
1359
+ tooltip = args.tooltip,
1360
+ index = args.index,
1361
+ canvasXY = RGraph.getCanvasXY(obj.canvas)
1362
+ coords = this.coords[args.index];
1363
+
1364
+ // Position the tooltip in the X direction
1365
+ args.tooltip.style.left = (
1366
+ canvasXY[0] // The X coordinate of the canvas
1367
+ + coords[0] // The X coordinate of the point on the chart
1368
+ + (coords[2] / 2) // Add half of the width of the bar
1369
+ - (tooltip.offsetWidth / 2) // Subtract half of the tooltip width
1370
+ + obj.properties.tooltipsOffsetx // Add any user defined offset
1371
+ ) + 'px';
1372
+
1373
+ args.tooltip.style.top = (
1374
+ canvasXY[1] // The Y coordinate of the canvas
1375
+ + coords[1] // The Y coordinate of the bar on the chart
1376
+ - tooltip.offsetHeight // The height of the tooltip
1377
+ - 10 // An arbitrary amount
1378
+ + obj.properties.tooltipsOffsety // Add any user defined offset
1379
+ ) + 'px';
1380
+
1381
+ // If the top of the tooltip is off the top of the page
1382
+ // then move the tooltip down
1383
+ if(parseFloat(args.tooltip.style.top) < 0) {
1384
+ args.tooltip.style.top = parseFloat(args.tooltip.style.top) + (coords[3] / 2) + 5 + 'px';
1385
+ }
1386
+ };
1387
+
1388
+
1389
+
1390
+
1391
+
1392
+
1393
+
1394
+
1395
+ //
1396
+ // Now, because canvases can support multiple charts, canvases must always be registered
1397
+ //
1398
+ RGraph.register(this);
1399
+
1400
+
1401
+
1402
+
1403
+
1404
+
1405
+
1406
+
1407
+ //
1408
+ // This is the 'end' of the constructor so if the first argument
1409
+ // contains configuration data - handle that.
1410
+ //
1411
+ RGraph.parseObjectStyleConfig(this, conf.options);
1412
+ };