UNPKG

node-red-contrib-smartnode-hook

Version:

this project is dependenced by the node-red-contrib-smartnode for some IoT display function

1,179 lines (953 loc) 119 kB
// version: 2014-11-15 /** * o--------------------------------------------------------------------------------o * | This file is part of the RGraph package - you can learn more at: | * | | * | http://www.rgraph.net | * | | * | This package is licensed under the Creative Commons BY-NC license. That means | * | that for non-commercial purposes it's free to use and for business use there's | * | a 99 GBP per-company fee to pay. You can read the full license here: | * | | * | http://www.rgraph.net/license | * o--------------------------------------------------------------------------------o */ RGraph = window.RGraph || {isRGraph: true}; /** * The scatter graph constructor * * @param object canvas The cxanvas object * @param array data The chart data */ RGraph.Scatter = function (conf) { /** * Allow for object config style */ if ( typeof conf === 'object' && typeof conf.data === 'object' && typeof conf.id === 'string') { var parseConfObjectForOptions = true; // Set this so the config is parsed (at the end of the constructor) this.data = new Array(conf.data.length); // Store the data set(s) this.data = RGraph.arrayClone(conf.data); // Account for just one dataset being given if (typeof conf.data === 'object' && typeof conf.data[0] === 'object' && (typeof conf.data[0][0] === 'number' || typeof conf.data[0][0] === 'string')) { var tmp = RGraph.arrayClone(conf.data); conf.data = new Array(); conf.data[0] = RGraph.arrayClone(tmp); this.data = RGraph.arrayClone(conf.data); } } else { var conf = {id: conf}; conf.data = arguments[1]; this.data = []; // Handle multiple datasets being given as one argument if (arguments[1][0] && arguments[1][0][0] && typeof arguments[1][0][0] == 'object') { // Store the data set(s) for (var i=0; i<arguments[1].length; ++i) { this.data[i] = RGraph.arrayClone(arguments[1][i]); } // Handle multiple data sets being supplied as seperate arguments } else { // Store the data set(s) for (var i=1; i<arguments.length; ++i) { this.data[i - 1] = RGraph.arrayClone(arguments[i]); } } } this.id = conf.id; this.canvas = document.getElementById(this.id); this.canvas.__object__ = this; this.context = this.canvas.getContext ? this.canvas.getContext('2d') : null; this.max = 0; this.coords = []; this.type = 'scatter'; this.isRGraph = true; this.uid = RGraph.CreateUID(); this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.CreateUID(); this.colorsParsed = false; this.coordsText = []; this.original_colors = []; this.firstDraw = true; // After the first draw this will be false // Handle multiple datasets being given as one argument //if (arguments[1][0] && arguments[1][0][0] && typeof(arguments[1][0][0]) == 'object') { // // Store the data set(s) // for (var i=0; i<arguments[1].length; ++i) { // this.data[i] = arguments[1][i]; // } // Handle multiple data sets being supplied as seperate arguments //} else { // Store the data set(s) //for (var i=1; i<arguments.length; ++i) { // this.data[i - 1] = arguments[i]; //} //} // Various config properties this.properties = { 'chart.background.barcolor1': 'rgba(0,0,0,0)', 'chart.background.barcolor2': 'rgba(0,0,0,0)', 'chart.background.grid': true, 'chart.background.grid.width': 1, 'chart.background.grid.color': '#ddd', 'chart.background.grid.hsize': 20, 'chart.background.grid.vsize': 20, 'chart.background.hbars': null, 'chart.background.vbars': null, 'chart.background.grid.vlines': true, 'chart.background.grid.hlines': true, 'chart.background.grid.border': true, 'chart.background.grid.autofit':true, 'chart.background.grid.autofit.numhlines': 5, 'chart.background.grid.autofit.numvlines': 20, 'chart.background.image': null, 'chart.background.image.stretch': true, 'chart.background.image.x': null, 'chart.background.image.y': null, 'chart.background.image.w': null, 'chart.background.image.h': null, 'chart.background.image.align': null, 'chart.background.color': null, 'chart.text.size': 10, 'chart.text.angle': 0, 'chart.text.color': 'black', 'chart.text.font': 'Arial', 'chart.tooltips': [], // Default must be an empty array 'chart.tooltips.effect': 'fade', 'chart.tooltips.event': 'onmousemove', 'chart.tooltips.hotspot': 3, 'chart.tooltips.css.class': 'RGraph_tooltip', 'chart.tooltips.highlight': true, 'chart.tooltips.coords.page': false, 'chart.units.pre': '', 'chart.units.post': '', 'chart.numyticks': 10, 'chart.tickmarks': 'cross', 'chart.tickmarks.image.halign': 'center', 'chart.tickmarks.image.valign': 'center', 'chart.tickmarks.image.offsetx': 0, 'chart.tickmarks.image.offsety': 0, 'chart.ticksize': 5, 'chart.numxticks': true, 'chart.xaxis': true, 'chart.gutter.left': 25, 'chart.gutter.right': 25, 'chart.gutter.top': 25, 'chart.gutter.bottom': 25, 'chart.xmin': 0, 'chart.xmax': 0, 'chart.ymax': null, 'chart.ymin': 0, 'chart.scale.decimals': null, 'chart.scale.point': '.', 'chart.scale.thousand': ',', 'chart.title': '', 'chart.title.background': null, 'chart.title.hpos': null, 'chart.title.vpos': null, 'chart.title.bold': true, 'chart.title.font': null, 'chart.title.xaxis': '', 'chart.title.xaxis.bold': true, 'chart.title.xaxis.size': null, 'chart.title.xaxis.font': null, 'chart.title.yaxis': '', 'chart.title.yaxis.bold': true, 'chart.title.yaxis.size': null, 'chart.title.yaxis.font': null, 'chart.title.yaxis.color': null, 'chart.title.xaxis.pos': null, 'chart.title.yaxis.pos': null, 'chart.title.yaxis.x': null, 'chart.title.yaxis.y': null, 'chart.title.xaxis.x': null, 'chart.title.xaxis.y': null, 'chart.title.x': null, 'chart.title.y': null, 'chart.title.halign': null, 'chart.title.valign': null, 'chart.labels': [], 'chart.labels.ingraph': null, 'chart.labels.above': false, 'chart.labels.above.size': 8, 'chart.labels.above.decimals': 0, 'chart.ylabels': true, 'chart.ylabels.count': 5, 'chart.ylabels.invert': false, 'chart.ylabels.specific': null, 'chart.ylabels.inside': false, 'chart.contextmenu': null, 'chart.defaultcolor': 'black', 'chart.xaxispos': 'bottom', 'chart.yaxispos': 'left', 'chart.crosshairs': false, 'chart.crosshairs.color': '#333', 'chart.crosshairs.linewidth': 1, 'chart.crosshairs.coords': false, 'chart.crosshairs.coords.fixed':true, 'chart.crosshairs.coords.fadeout':false, 'chart.crosshairs.coords.labels.x': 'X', 'chart.crosshairs.coords.labels.y': 'Y', 'chart.crosshairs.hline': true, 'chart.crosshairs.vline': true, 'chart.annotatable': false, 'chart.annotate.color': 'black', 'chart.line': false, 'chart.line.linewidth': 1, 'chart.line.colors': ['green', 'red'], 'chart.line.shadow.color': 'rgba(0,0,0,0)', 'chart.line.shadow.blur': 2, 'chart.line.shadow.offsetx': 3, 'chart.line.shadow.offsety': 3, 'chart.line.stepped': false, 'chart.line.visible': true, 'chart.noaxes': false, 'chart.noyaxis': false, 'chart.key': null, 'chart.key.background': 'white', 'chart.key.position': 'graph', 'chart.key.halign': 'right', 'chart.key.shadow': false, 'chart.key.shadow.color': '#666', 'chart.key.shadow.blur': 3, 'chart.key.shadow.offsetx': 2, 'chart.key.shadow.offsety': 2, 'chart.key.position.gutter.boxed': false, 'chart.key.position.x': null, 'chart.key.position.y': null, 'chart.key.interactive': false, 'chart.key.interactive.highlight.chart.fill': 'rgba(255,0,0,0.9)', 'chart.key.interactive.highlight.label': 'rgba(255,0,0,0.2)', 'chart.key.color.shape': 'square', 'chart.key.rounded': true, 'chart.key.linewidth': 1, 'chart.key.colors': null, 'chart.key.text.color': 'black', 'chart.axis.color': 'black', 'chart.zoom.factor': 1.5, 'chart.zoom.fade.in': true, 'chart.zoom.fade.out': true, 'chart.zoom.hdir': 'right', 'chart.zoom.vdir': 'down', 'chart.zoom.frames': 25, 'chart.zoom.delay': 16.666, 'chart.zoom.shadow': true, 'chart.zoom.background': true, 'chart.zoom.action': 'zoom', 'chart.boxplot.width': 1, 'chart.boxplot.capped': true, 'chart.resizable': false, 'chart.resize.handle.background': null, 'chart.xmin': 0, 'chart.labels.specific.align': 'left', 'chart.xscale': false, 'chart.xscale.units.pre': '', 'chart.xscale.units.post': '', 'chart.xscale.numlabels': 10, 'chart.xscale.formatter': null, 'chart.xscale.decimals': 0, 'chart.xscale.thousand': ',', 'chart.xscale.point': '.', 'chart.noendxtick': false, 'chart.noendytick': true, 'chart.events.mousemove': null, 'chart.events.click': null, 'chart.highlight.stroke': 'rgba(0,0,0,0)', 'chart.highlight.fill': 'rgba(255,255,255,0.7)' } /** * This allows the data points to be given as dates as well as numbers. Formats supported by RGraph.parseDate() are accepted. */ for (var i=0; i<this.data.length; ++i) { for (var j=0; j<this.data[i].length; ++j) { if (this.data[i][j] && typeof(this.data[i][j][0]) == 'string') { this.data[i][j][0] = RGraph.parseDate(this.data[i][j][0]); } } } /** * Now make the data_arr array - all the data as one big array */ this.data_arr = []; for (var i=0; i<this.data.length; ++i) { for (var j=0; j<this.data[i].length; ++j) { this.data_arr.push(this.data[i][j]); } } // Create the $ objects so that they can be used for (var i=0; i<this.data_arr.length; ++i) { this['$' + i] = {} } // Check for support if (!this.canvas) { alert('[SCATTER] No canvas support'); return; } /** * Translate half a pixel for antialiasing purposes - but only if it hasn't beeen * done already */ if (!this.canvas.__rgraph_aa_translated__) { this.context.translate(0.5,0.5); this.canvas.__rgraph_aa_translated__ = true; } // Short variable names var RG = RGraph; var ca = this.canvas; var co = ca.getContext('2d'); var prop = this.properties; var jq = jQuery; var pa = RG.Path; var win = window; var doc = document; var ma = Math; /** * "Decorate" the object with the generic effects if the effects library has been included */ if (RG.Effects && typeof RG.Effects.decorate === 'function') { RG.Effects.decorate(this); } /** * A simple setter * * @param string name The name of the property to set * @param string value The value of the property */ this.set = this.Set = function (name) { var value = typeof arguments[1] === 'undefined' ? null : arguments[1]; /** * the number of arguments is only one and it's an * object - parse it for configuration data and return. */ if (arguments.length === 1 && typeof name === 'object') { RG.parseObjectStyleConfig(this, name); return this; } /** * This should be done first - prepend the propertyy name with "chart." if necessary */ if (name.substr(0,6) != 'chart.') { name = 'chart.' + name; } /** * BC for chart.xticks */ if (name == 'chart.xticks') { name == 'chart.numxticks'; } /** * This is here because the key expects a name of "chart.colors" */ if (name == 'chart.line.colors') { prop['chart.colors'] = value; } /** * Allow compatibility with older property names */ if (name == 'chart.tooltip.hotspot') { name = 'chart.tooltips.hotspot'; } /** * chart.yaxispos should be left or right */ if (name == 'chart.yaxispos' && value != 'left' && value != 'right') { alert("[SCATTER] chart.yaxispos should be left or right. You've set it to: '" + value + "' Changing it to left"); value = 'left'; } /** * Check for xaxispos */ if (name == 'chart.xaxispos' ) { if (value != 'bottom' && value != 'center') { alert('[SCATTER] (' + this.id + ') chart.xaxispos should be center or bottom. Tried to set it to: ' + value + ' Changing it to center'); value = 'center'; } } prop[name.toLowerCase()] = value; return this; }; /** * A simple getter * * @param string name The name of the property to set */ this.get = this.Get = function (name) { /** * This should be done first - prepend the property name with "chart." if necessary */ if (name.substr(0,6) != 'chart.') { name = 'chart.' + name; } return prop[name]; }; /** * The function you call to draw the line chart */ this.draw = this.Draw = function () { // MUST be the first thing done! if (typeof prop['chart.background.image'] === 'string') { RG.DrawBackgroundImage(this); } /** * Fire the onbeforedraw event */ RG.FireCustomEvent(this, 'onbeforedraw'); /** * Parse the colors. This allows for simple gradient syntax */ if (!this.colorsParsed) { this.parseColors(); // Don't want to do this again this.colorsParsed = true; } /** * Stop this growing uncontrollably */ this.coordsText = []; /** * This is new in May 2011 and facilitates indiviual gutter settings, * eg chart.gutter.left */ this.gutterLeft = prop['chart.gutter.left']; this.gutterRight = prop['chart.gutter.right']; this.gutterTop = prop['chart.gutter.top']; this.gutterBottom = prop['chart.gutter.bottom']; // Go through all the data points and see if a tooltip has been given this.hasTooltips = false; var overHotspot = false; // Reset the coords array this.coords = []; /** * This facilitates the xmax, xmin and X values being dates */ if (typeof(prop['chart.xmin']) == 'string') prop['chart.xmin'] = RG.parseDate(prop['chart.xmin']); if (typeof(prop['chart.xmax']) == 'string') prop['chart.xmax'] = RG.parseDate(prop['chart.xmax']); /** * Look for tooltips and populate chart.tooltips * * NB 26/01/2011 Updated so that chart.tooltips is ALWAYS populated */ if (!RGraph.ISOLD) { this.Set('chart.tooltips', []); for (var i=0,len=this.data.length; i<len; i+=1) { for (var j =0,len2=this.data[i].length;j<len2; j+=1) { if (this.data[i][j] && this.data[i][j][3]) { prop['chart.tooltips'].push(this.data[i][j][3]); this.hasTooltips = true; } else { prop['chart.tooltips'].push(null); } } } } // Reset the maximum value this.max = 0; // Work out the maximum Y value //if (prop['chart.ymax'] && prop['chart.ymax'] > 0) { if (typeof prop['chart.ymax'] === 'number') { this.max = prop['chart.ymax']; this.min = prop['chart.ymin'] ? prop['chart.ymin'] : 0; this.scale2 = RG.getScale2(this, { 'max':this.max, 'min':this.min, 'strict':true, 'scale.thousand':prop['chart.scale.thousand'], 'scale.point':prop['chart.scale.point'], 'scale.decimals':prop['chart.scale.decimals'], 'ylabels.count':prop['chart.ylabels.count'], 'scale.round':prop['chart.scale.round'], 'units.pre': prop['chart.units.pre'], 'units.post': prop['chart.units.post'] }); this.max = this.scale2.max; this.min = this.scale2.min; var decimals = prop['chart.scale.decimals']; } else { var i = 0; var j = 0; for (i=0,len=this.data.length; i<len; i+=1) { for (j=0,len2=this.data[i].length; j<len2; j+=1) { if (this.data[i][j][1] != null) { this.max = Math.max(this.max, typeof(this.data[i][j][1]) == 'object' ? RG.array_max(this.data[i][j][1]) : Math.abs(this.data[i][j][1])); } } } this.min = prop['chart.ymin'] ? prop['chart.ymin'] : 0; this.scale2 = RG.getScale2(this, { 'max':this.max, 'min':this.min, 'scale.thousand':prop['chart.scale.thousand'], 'scale.point':prop['chart.scale.point'], 'scale.decimals':prop['chart.scale.decimals'], 'ylabels.count':prop['chart.ylabels.count'], 'scale.round':prop['chart.scale.round'], 'units.pre': prop['chart.units.pre'], 'units.post': prop['chart.units.post'] }); this.max = this.scale2.max; this.min = this.scale2.min; } this.grapharea = ca.height - this.gutterTop - this.gutterBottom; // Progressively Draw the chart RG.background.Draw(this); /** * Draw any horizontal bars that have been specified */ if (prop['chart.background.hbars'] && prop['chart.background.hbars'].length) { RG.DrawBars(this); } /** * Draw any vertical bars that have been specified */ if (prop['chart.background.vbars'] && prop['chart.background.vbars'].length) { this.DrawVBars(); } if (!prop['chart.noaxes']) { this.DrawAxes(); } this.DrawLabels(); i = 0; for(i=0; i<this.data.length; ++i) { this.DrawMarks(i); // Set the shadow co.shadowColor = prop['chart.line.shadow.color']; co.shadowOffsetX = prop['chart.line.shadow.offsetx']; co.shadowOffsetY = prop['chart.line.shadow.offsety']; co.shadowBlur = prop['chart.line.shadow.blur']; this.DrawLine(i); // Turn the shadow off RG.NoShadow(this); } if (prop['chart.line']) { for (var i=0,len=this.data.length;i<len; i+=1) { this.DrawMarks(i); // Call this again so the tickmarks appear over the line } } /** * Setup the context menu if required */ if (prop['chart.contextmenu']) { RG.ShowContext(this); } /** * Draw the key if necessary */ if (prop['chart.key'] && prop['chart.key'].length) { RG.DrawKey(this, prop['chart.key'], prop['chart.line.colors']); } /** * Draw " above" labels if enabled */ if (prop['chart.labels.above']) { this.DrawAboveLabels(); } /** * Draw the "in graph" labels, using the member function, NOT the shared function in RGraph.common.core.js */ this.DrawInGraphLabels(this); /** * This function enables resizing */ if (prop['chart.resizable']) { RG.AllowResizing(this); } /** * This installs the event listeners */ RG.InstallEventListeners(this); /** * Fire the onfirstdraw event */ if (this.firstDraw) { RG.fireCustomEvent(this, 'onfirstdraw'); this.firstDraw = false; this.firstDrawFunc(); } /** * Fire the RGraph ondraw event */ RG.FireCustomEvent(this, 'ondraw'); return this; } /** * Draws the axes of the scatter graph */ this.drawAxes = this.DrawAxes = function () { var graphHeight = ca.height - this.gutterTop - this.gutterBottom; co.beginPath(); co.strokeStyle = prop['chart.axis.color']; co.lineWidth = (prop['chart.axis.linewidth'] || 1) + 0.001; // Strange Chrome bug // Draw the Y axis if (prop['chart.noyaxis'] == false) { if (prop['chart.yaxispos'] == 'left') { co.moveTo(this.gutterLeft, this.gutterTop); co.lineTo(this.gutterLeft, ca.height - this.gutterBottom); } else { co.moveTo(ca.width - this.gutterRight, this.gutterTop); co.lineTo(ca.width - this.gutterRight, ca.height - this.gutterBottom); } } // Draw the X axis if (prop['chart.xaxis']) { if (prop['chart.xaxispos'] == 'center') { co.moveTo(this.gutterLeft, Math.round(this.gutterTop + ((ca.height - this.gutterTop - this.gutterBottom) / 2))); co.lineTo(ca.width - this.gutterRight, Math.round(this.gutterTop + ((ca.height - this.gutterTop - this.gutterBottom) / 2))); } else { co.moveTo(this.gutterLeft, ca.height - this.gutterBottom); co.lineTo(ca.width - this.gutterRight, ca.height - this.gutterBottom); } } // Draw the Y tickmarks if (prop['chart.noyaxis'] == false) { var numyticks = prop['chart.numyticks']; //for (y=this.gutterTop; y < ca.height - this.gutterBottom + (prop['chart.xaxispos'] == 'center' ? 1 : 0) ; y+=(graphHeight / numyticks)) { for (i=0; i<numyticks; ++i) { var y = ((ca.height - this.gutterTop - this.gutterBottom) / numyticks) * i; y = y + this.gutterTop; if (prop['chart.xaxispos'] == 'center' && i == (numyticks / 2)) { continue; } if (prop['chart.yaxispos'] == 'left') { co.moveTo(this.gutterLeft, Math.round(y)); co.lineTo(this.gutterLeft - 3, Math.round(y)); } else { co.moveTo(ca.width - this.gutterRight +3, Math.round(y)); co.lineTo(ca.width - this.gutterRight, Math.round(y)); } } /** * Draw the end Y tickmark if the X axis is in the centre */ if (prop['chart.numyticks'] > 0) { if (prop['chart.xaxispos'] == 'center' && prop['chart.yaxispos'] == 'left') { co.moveTo(this.gutterLeft, Math.round(ca.height - this.gutterBottom)); co.lineTo(this.gutterLeft - 3, Math.round(ca.height - this.gutterBottom)); } else if (prop['chart.xaxispos'] == 'center') { co.moveTo(ca.width - this.gutterRight + 3, Math.round(ca.height - this.gutterBottom)); co.lineTo(ca.width - this.gutterRight, Math.round(ca.height - this.gutterBottom)); } } /** * Draw an extra tick if the X axis isn't being shown */ if (prop['chart.xaxis'] == false && prop['chart.yaxispos'] == 'left') { co.moveTo(this.gutterLeft, Math.round(ca.height - this.gutterBottom)); co.lineTo(this.gutterLeft - 3, Math.round(ca.height - this.gutterBottom)); } else if (prop['chart.xaxis'] == false && prop['chart.yaxispos'] == 'right') { co.moveTo(ca.width - this.gutterRight, Math.round(ca.height - this.gutterBottom)); co.lineTo(ca.width - this.gutterRight + 3, Math.round(ca.height - this.gutterBottom)); } } /** * Draw the X tickmarks */ if (prop['chart.numxticks'] > 0 && prop['chart.xaxis']) { var x = 0; var y = (prop['chart.xaxispos'] == 'center') ? this.gutterTop + (this.grapharea / 2) : (ca.height - this.gutterBottom); this.xTickGap = (prop['chart.labels'] && prop['chart.labels'].length) ? ((ca.width - this.gutterLeft - this.gutterRight ) / prop['chart.labels'].length) : (ca.width - this.gutterLeft - this.gutterRight) / 10; /** * This allows the number of X tickmarks to be specified */ if (typeof(prop['chart.numxticks']) == 'number') { this.xTickGap = (ca.width - this.gutterLeft - this.gutterRight) / prop['chart.numxticks']; } for (x=(this.gutterLeft + (prop['chart.yaxispos'] == 'left' && prop['chart.noyaxis'] == false ? this.xTickGap : 0) ); x <= (ca.width - this.gutterRight - (prop['chart.yaxispos'] == 'left' || prop['chart.noyaxis'] == true ? -1 : 1)); x += this.xTickGap) { if (prop['chart.yaxispos'] == 'left' && prop['chart.noendxtick'] == true && x == (ca.width - this.gutterRight) ) { continue; } else if (prop['chart.yaxispos'] == 'right' && prop['chart.noendxtick'] == true && x == this.gutterLeft) { continue; } co.moveTo(Math.round(x), y - (prop['chart.xaxispos'] == 'center' ? 3 : 0)); co.lineTo(Math.round(x), y + 3); } } co.stroke(); /** * Reset the linewidth back to one */ co.lineWidth = 1; }; /** * Draws the labels on the scatter graph */ this.drawLabels = this.DrawLabels = function () { co.fillStyle = prop['chart.text.color']; var font = prop['chart.text.font']; var xMin = prop['chart.xmin']; var xMax = prop['chart.xmax']; var yMax = this.scale2.max; var yMin = prop['chart.ymin'] ? prop['chart.ymin'] : 0; var text_size = prop['chart.text.size']; var units_pre = prop['chart.units.pre']; var units_post = prop['chart.units.post']; var numYLabels = prop['chart.ylabels.count']; var invert = prop['chart.ylabels.invert']; var inside = prop['chart.ylabels.inside']; var context = co; var canvas = ca; var boxed = false; this.halfTextHeight = text_size / 2; this.halfGraphHeight = (ca.height - this.gutterTop - this.gutterBottom) / 2; /** * Draw the Y yaxis labels, be it at the top or center */ if (prop['chart.ylabels']) { var xPos = prop['chart.yaxispos'] == 'left' ? this.gutterLeft - 5 : ca.width - this.gutterRight + 5; var align = prop['chart.yaxispos'] == 'right' ? 'left' : 'right'; /** * Now change the two things above if chart.ylabels.inside is specified */ if (inside) { if (prop['chart.yaxispos'] == 'left') { xPos = prop['chart.gutter.left'] + 5; align = 'left'; boxed = true; } else { xPos = ca.width - prop['chart.gutter.right'] - 5; align = 'right'; boxed = true; } } if (prop['chart.xaxispos'] == 'center') { /** * Specific Y labels */ if (typeof(prop['chart.ylabels.specific']) == 'object' && prop['chart.ylabels.specific'] != null && prop['chart.ylabels.specific'].length) { var labels = prop['chart.ylabels.specific']; if (prop['chart.ymin'] > 0) { labels = []; for (var i=0; i<(prop['chart.ylabels.specific'].length - 1); ++i) { labels.push(prop['chart.ylabels.specific'][i]); } } for (var i=0; i<labels.length; ++i) { var y = this.gutterTop + (i * (this.grapharea / (labels.length * 2) ) ); RG.Text2(this, {'font':font, 'size':text_size, 'x':xPos, 'y':y, 'text':labels[i], 'valign':'center', 'halign':align, 'bounding':boxed, 'tag': 'labels.specific' }); } var reversed_labels = RG.array_reverse(labels); for (var i=0; i<reversed_labels.length; ++i) { var y = this.gutterTop + (this.grapharea / 2) + ((i+1) * (this.grapharea / (labels.length * 2) ) ); RG.Text2(this, {'font':font, 'size':text_size, 'x':xPos, 'y':y, 'text':reversed_labels[i], 'valign':'center', 'halign':align, 'bounding':boxed, 'tag': 'labels.specific' }); } /** * Draw the center label if chart.ymin is specified */ if (prop['chart.ymin'] != 0) { RG.Text2(this, {'font':font, 'size':text_size, 'x':xPos, 'y':(this.grapharea / 2) + this.gutterTop, 'text':prop['chart.ylabels.specific'][prop['chart.ylabels.specific'].length - 1], 'valign':'center', 'halign':align, 'bounding':boxed, 'tag': 'labels.specific' }); } } if (!prop['chart.ylabels.specific'] && typeof numYLabels == 'number') { /** * Draw the top half */ for (var i=0,len=this.scale2.labels.length; i<len; i+=1) { //var value = ((this.max - this.min)/ numYLabels) * (i+1); //value = (invert ? this.max - value : value); //if (!invert) value += this.min; //value = value.toFixed(prop['chart.scale.decimals']); if (!invert) { RG.Text2(this, {'font':font, 'size': text_size, 'x': xPos, 'y': this.gutterTop + this.halfGraphHeight - (((i + 1)/numYLabels) * this.halfGraphHeight), 'valign': 'center', 'halign':align, 'bounding': boxed, 'boundingFill': 'white', 'text': this.scale2.labels[i], 'tag': 'scale' }); } else { RG.Text2(this, {'font':font, 'size': text_size, 'x': xPos, 'y': this.gutterTop + this.halfGraphHeight - ((i/numYLabels) * this.halfGraphHeight), 'valign': 'center', 'halign':align, 'bounding': boxed, 'boundingFill': 'white', 'text': this.scale2.labels[this.scale2.labels.length - (i + 1)], 'tag': 'scale' }); } } /** * Draw the bottom half */ for (var i=0,len=this.scale2.labels.length; i<len; i+=1) { //var value = (((this.max - this.min)/ numYLabels) * i) + this.min; // value = (invert ? value : this.max - (value - this.min)).toFixed(prop['chart.scale.decimals']); if (!invert) { RG.Text2(this, {'font':font, 'size': text_size, 'x': xPos, 'y': this.gutterTop + this.halfGraphHeight + this.halfGraphHeight - ((i/numYLabels) * this.halfGraphHeight), 'valign': 'center', 'halign':align, 'bounding': boxed, 'boundingFill': 'white', 'text': '-' + this.scale2.labels[len - (i+1)], 'tag': 'scale' }); } else { // This ensures that the center label isn't drawn twice if (i == (len - 1)&& invert) { continue; } RG.Text2(this, {'font':font, 'size': text_size, 'x': xPos, 'y': this.gutterTop + this.halfGraphHeight + this.halfGraphHeight - (((i + 1)/numYLabels) * this.halfGraphHeight), 'valign': 'center', 'halign':align, 'bounding': boxed, 'boundingFill': 'white', 'text': '-' + this.scale2.labels[i], 'tag': 'scale' }); } } // If ymin is specified draw that if (!invert && yMin > 0) { RG.Text2(this, {'font':font, 'size': text_size, 'x': xPos, 'y': this.gutterTop + this.halfGraphHeight, 'valign': 'center', 'halign':align, 'bounding': boxed, 'boundingFill': 'white', 'text': RG.number_format(this, yMin.toFixed(prop['chart.scale.decimals']), units_pre, units_post), 'tag': 'scale' }); } if (invert) { RG.Text2(this, {'font':font, 'size': text_size, 'x': xPos, 'y': this.gutterTop, 'valign': 'center', 'halign':align, 'bounding': boxed, 'boundingFill': 'white', 'text': RG.number_format(this, yMin.toFixed(prop['chart.scale.decimals']), units_pre, units_post), 'tag': 'scale' }); RG.Text2(this, {'font':font, 'size': text_size, 'x': xPos, 'y': this.gutterTop + (this.halfGraphHeight * 2), 'valign': 'center', 'halign':align, 'bounding': boxed, 'boundingFill': 'white', 'text': '-' + RG.number_format(this, yMin.toFixed(prop['chart.scale.decimals']), units_pre, units_post), 'tag': 'scale' }); } } // X axis at the bottom } else { var xPos = prop['chart.yaxispos'] == 'left' ? this.gutterLeft - 5 : ca.width - this.gutterRight + 5; var align = prop['chart.yaxispos'] == 'right' ? 'left' : 'right'; if (inside) { if (prop['chart.yaxispos'] == 'left') { xPos = prop['chart.gutter.left'] + 5; align = 'left'; boxed = true; } else { xPos = ca.width - obj.gutterRight - 5; align = 'right'; boxed = true; } } /** * Specific Y labels */ if (typeof prop['chart.ylabels.specific'] == 'object' && prop['chart.ylabels.specific']) { var labels = prop['chart.ylabels.specific']; // Lose the last label if (prop['chart.ymin'] > 9999) { labels = []; for (var i=0; i<(prop['chart.ylabels.specific'].length - 1); ++i) { labels.push(prop['chart.ylabels.specific'][i]); } } for (var i=0,len=labels.length; i<len; i+=1) { var y = this.gutterTop + (i * (this.grapharea / (len - 1)) ); RG.Text2(this, {'font':font, 'size':text_size, 'x':xPos, 'y':y, 'text':labels[i], 'halign':align, 'valign':'center', 'bounding':boxed, 'tag': 'scale' }); } /** * X axis at the bottom */ } else { if (typeof(numYLabels) == 'number') { if (invert) { for (var i=0; i<numYLabels; ++i) { //var value = ((this.max - this.min)/ numYLabels) * i; // value = value.toFixed(prop['chart.scale.decimals']); var interval = (ca.height - this.gutterTop - this.gutterBottom) / numYLabels; RG.Text2(this, {'font':font, 'size': text_size, 'x': xPos, 'y': this.gutterTop + ((i+1) * interval), 'valign': 'center', 'halign':align, 'bounding': boxed, 'boundingFill': 'white', 'text': this.scale2.labels[i], 'tag': 'scale' }); } // No X axis being shown and there's no ymin. If ymin IS set its added further down if (!prop['chart.xaxis'] && !prop['chart.ymin']) { RG.Text2(this, {'font':font, 'size': text_size,