// version: 2014-06-26 /** * o--------------------------------------------------------------------------------o * | This file is part of the RGraph package. RGraph is Free Software, licensed | * | under the MIT license - so it's free to use for all purposes. If you want to | * | donate to help keep the project going then you can do so here: | * | | * | http://www.rgraph.net/donate | * 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 (id, data) { var tmp = RGraph.getCanvasTag(id); // Get the canvas and context objects this.id = tmp[0]; this.canvas = tmp[1]; this.canvas.__object__ = this; this.context = this.canvas.getContext ? this.canvas.getContext("2d", {alpha: (typeof id === 'object' && id.alpha === false) ? false : true}) : null; this.max = 0; this.coords = []; this.data = []; 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 /** * Compatibility with older browsers */ //RGraph.OldBrowserCompat(this.context); // 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.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)' } // 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 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 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 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 0) { angle = -1 * prop['chart.text.angle']; valign = 'center'; halign = 'right'; yPos += 10; } for (i=0; i= 2) { if (prop['chart.line.dash'] && typeof co.setLineDash === 'function') { co.setLineDash(prop['chart.line.dash']); } co.lineCap = 'round'; co.lineJoin = 'round'; co.lineWidth = this.getLineWidth(i);// i is the index of the set of coordinates co.strokeStyle = prop['chart.line.colors'][i]; co.beginPath(); var prevY = null; var currY = null; for (var j=0,len=this.coords[i].length; j 0) prevY = this.coords[i][j - 1][1]; currY = yPos; if (j == 0 || RG.is_null(prevY) || RG.is_null(currY)) { co.moveTo(xPos, yPos); } else { // Stepped? var stepped = prop['chart.line.stepped']; if ( (typeof stepped == 'boolean' && stepped) || (typeof stepped == 'object' && stepped[i]) ) { co.lineTo(this.coords[i][j][0], this.coords[i][j - 1][1]); } co.lineTo(xPos, yPos); } } co.stroke(); /** * Set the linedash back to the default */ if (prop['chart.line.dash'] && typeof co.setLineDash === 'function') { co.setLineDash([1,0]); } } /** * Set the linewidth back to 1 */ co.lineWidth = 1; }; /** * Returns the linewidth * * @param number i The index of the "line" (/set of coordinates) */ this.getLineWidth = this.GetLineWidth = function (i) { var linewidth = prop['chart.line.linewidth']; if (typeof linewidth == 'number') { return linewidth; } else if (typeof linewidth == 'object') { if (linewidth[i]) { return linewidth[i]; } else { return linewidth[0]; } alert('[SCATTER] Error! chart.linewidth should be a single number or an array of one or more numbers'); } }; /** * Draws vertical bars. Line chart doesn't use a horizontal scale, hence this function * is not common */ this.drawVBars = this.DrawVBars = function () { var vbars = prop['chart.background.vbars']; var graphWidth = ca.width - this.gutterLeft - this.gutterRight; if (vbars) { var xmax = prop['chart.xmax']; var xmin = prop['chart.xmin']; for (var i=0,len=vbars.length; i 0) { var i=0; for (var set=0; set= (x - offset) && mouseY <= (y + offset) && mouseY >= (y - offset)) { var tooltip = RG.parseTooltipText(this.data[set][i][3], 0); var index_adjusted = i; for (var ds=(set-1); ds >=0; --ds) { index_adjusted += this.data[ds].length; } return { 0: this, 1: x, 2: y, 3: set, 4: i, 5: this.data[set][i][3], 'object': this, 'x': x, 'y': y, 'dataset': set, 'index': i, 'tooltip': tooltip, 'index_adjusted': index_adjusted }; } } else if (RG.is_null(y)) { // Nothing to see here } else { var mark = this.data[set][i]; /** * Determine the width */ var width = prop['chart.boxplot.width']; if (typeof(mark[1][7]) == 'number') { width = mark[1][7]; } if ( typeof(x) == 'object' && mouseX > x[0] && mouseX < x[1] && mouseY < y[1] && mouseY > y[3] ) { var tooltip = RG.parseTooltipText(this.data[set][i][3], 0); return { 0: this, 1: x[0], 2: x[1] - x[0], 3: y[1], 4: y[3] - y[1], 5: set, 6: i, 7: this.data[set][i][3], 'object': this, 'x': x[0], 'y': y[1], 'width': x[1] - x[0], 'height': y[3] - y[1], 'dataset': set, 'index': i, 'tooltip': tooltip }; } } } } }; /** * Draws the above line labels */ this.drawAboveLabels = this.DrawAboveLabels = function () { var size = prop['chart.labels.above.size']; var font = prop['chart.text.font']; var units_pre = prop['chart.units.pre']; var units_post = prop['chart.units.post']; for (var set=0,len=this.coords.length; set (ca.height - this.gutterBottom) || mouseX < this.gutterLeft || mouseX > (ca.width - this.gutterRight) ) { return null; } if (prop['chart.xaxispos'] == 'center') { var value = (((this.grapharea / 2) - (mouseY - this.gutterTop)) / this.grapharea) * (this.max - this.min) value *= 2; // Account for each side of the X axis if (value >= 0) { value += this.min if (prop['chart.ylabels.invert']) { value -= this.min; value = this.max - value; } } else { value -= this.min; if (prop['chart.ylabels.invert']) { value += this.min; value = this.max + value; value *= -1; } } } else { var value = ((this.grapharea - (mouseY - this.gutterTop)) / this.grapharea) * (this.max - this.min) value += this.min; if (prop['chart.ylabels.invert']) { value -= this.min; value = this.max - value; } } return value; }; /** * When you click on the chart, this method can return the X value at that point. * * @param mixed arg This can either be an event object or the X coordinate * @param number If specifying the X coord as the first arg then this should be the Y coord */ this.getXValue = function (arg) { if (arg.length == 2) { var mouseX = arg[0]; var mouseY = arg[1]; } else { var mouseXY = RG.getMouseXY(arg); var mouseX = mouseXY[0]; var mouseY = mouseXY[1]; } var obj = this; if ( mouseY < this.gutterTop || mouseY > (ca.height - this.gutterBottom) || mouseX < this.gutterLeft || mouseX > (ca.width - this.gutterRight) ) { return null; } var width = (ca.width - this.gutterLeft - this.gutterRight); var value = ((mouseX - this.gutterLeft) / width) * (prop['chart.xmax'] - prop['chart.xmin']) value += prop['chart.xmin']; return value; }; /** * Each object type has its own Highlight() function which highlights the appropriate shape * * @param object shape The shape to highlight */ this.highlight = this.Highlight = function (shape) { // Boxplot highlight if (shape['height']) { RG.Highlight.Rect(this, shape); // Point highlight } else { RG.Highlight.Point(this, shape); } }; /** * The getObjectByXY() worker method. Don't call this call: * * RG.ObjectRegistry.getObjectByXY(e) * * @param object e The event object */ this.getObjectByXY = function (e) { var mouseXY = RG.getMouseXY(e); if ( mouseXY[0] > (this.gutterLeft - 3) && mouseXY[0] < (ca.width - this.gutterRight + 3) && mouseXY[1] > (this.gutterTop - 3) && mouseXY[1] < ((ca.height - this.gutterBottom) + 3) ) { return this; } }; /** * This function can be used when the canvas is clicked on (or similar - depending on the event) * to retrieve the relevant X coordinate for a particular value. * * @param int value The value to get the X coordinate for */ this.getXCoord = function (value) { if (typeof value != 'number' && typeof value != 'string') { return null; } // Allow for date strings to be passed if (typeof value === 'string') { value = RG.parseDate(value); } var xmin = prop['chart.xmin']; var xmax = prop['chart.xmax']; var x; if (value < xmin) return null; if (value > xmax) return null; var gutterRight = this.gutterRight; var gutterLeft = this.gutterLeft; if (prop['chart.yaxispos'] == 'right') { x = ((value - xmin) / (xmax - xmin)) * (ca.width - gutterLeft - gutterRight); x = (ca.width - gutterRight - x); } else { x = ((value - xmin) / (xmax - xmin)) * (ca.width - gutterLeft - gutterRight); x = x + gutterLeft; } return x; }; /** * This function positions a tooltip when it is displayed * * @param obj object The chart object * @param int x The X coordinate specified for the tooltip * @param int y The Y coordinate specified for the tooltip * @param objec tooltip The tooltips DIV element */ this.positionTooltip = function (obj, x, y, tooltip, idx) { var shape = RG.Registry.Get('chart.tooltip.shape'); var dataset = shape['dataset']; var index = shape['index']; var coordX = obj.coords[dataset][index][0] var coordY = obj.coords[dataset][index][1] var canvasXY = RG.getCanvasXY(obj.canvas); var gutterLeft = obj.gutterLeft; var gutterTop = obj.gutterTop; var width = tooltip.offsetWidth; var height = tooltip.offsetHeight; tooltip.style.left = 0; tooltip.style.top = 0; // Is the coord a boxplot var isBoxplot = typeof(coordY) == 'object' ? true : false; // Show any overflow (ie the arrow) tooltip.style.overflow = ''; // Create the arrow var img = new Image(); img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAFCAYAAACjKgd3AAAARUlEQVQYV2NkQAN79+797+RkhC4M5+/bd47B2dmZEVkBCgcmgcsgbAaA9GA1BCSBbhAuA/AagmwQPgMIGgIzCD0M0AMMAEFVIAa6UQgcAAAAAElFTkSuQmCC'; img.style.position = 'absolute'; img.id = '__rgraph_tooltip_pointer__'; img.style.top = (tooltip.offsetHeight - 2) + 'px'; tooltip.appendChild(img); // Reposition the tooltip if at the edges: // LEFT edge ////////////////////////////////////////////////////////////////// if ((canvasXY[0] + (coordX[0] || coordX) - (width / 2)) < 10) { if (isBoxplot) { tooltip.style.left = canvasXY[0] + coordX[0] + ((coordX[1] - coordX[0]) / 2) - (width * 0.1) + 'px'; tooltip.style.top = canvasXY[1] + coordY[2] - height - 5 + 'px'; img.style.left = ((width * 0.1) - 8.5) + 'px'; } else { tooltip.style.left = (canvasXY[0] + coordX - (width * 0.1)) + 'px'; tooltip.style.top = canvasXY[1] + coordY - height - 9 + 'px'; img.style.left = ((width * 0.1) - 8.5) + 'px'; } // RIGHT edge ////////////////////////////////////////////////////////////////// } else if ((canvasXY[0] + (coordX[0] || coordX) + (width / 2)) > doc.body.offsetWidth) { if (isBoxplot) { tooltip.style.left = canvasXY[0] + coordX[0] + ((coordX[1] - coordX[0]) / 2) - (width * 0.9) + 'px'; tooltip.style.top = canvasXY[1] + coordY[2] - height - 5 + 'px'; img.style.left = ((width * 0.9) - 8.5) + 'px'; } else { tooltip.style.left = (canvasXY[0] + coordX - (width * 0.9)) + 'px'; tooltip.style.top = canvasXY[1] + coordY - height - 9 + 'px'; img.style.left = ((width * 0.9) - 8.5) + 'px'; } // Default positioning - CENTERED ////////////////////////////////////////////////////////////////// } else { if (isBoxplot) { tooltip.style.left = canvasXY[0] + coordX[0] + ((coordX[1] - coordX[0]) / 2) - (width / 2) + 'px'; tooltip.style.top = canvasXY[1] + coordY[2] - height - 5 + 'px'; img.style.left = ((width * 0.5) - 8.5) + 'px'; } else { tooltip.style.left = (canvasXY[0] + coordX - (width * 0.5)) + 'px'; tooltip.style.top = canvasXY[1] + coordY - height - 9 + 'px'; img.style.left = ((width * 0.5) - 8.5) + 'px'; } } }; /** * Returns the applicable Y COORDINATE when given a Y value * * @param int value The value to use * @return int The appropriate Y coordinate */ this.getYCoord = this.getYCoordFromValue = function (value) { if (typeof(value) != 'number') { return null; } var invert = prop['chart.ylabels.invert']; var xaxispos = prop['chart.xaxispos']; var graphHeight = ca.height - this.gutterTop - this.gutterBottom; var halfGraphHeight = graphHeight / 2; var ymax = this.max; var ymin = prop['chart.ymin']; var coord = 0; if (value > ymax || (prop['chart.xaxispos'] == 'bottom' && value < ymin) || (prop['chart.xaxispos'] == 'center' && ((value > 0 && value < ymin) || (value < 0 && value > (-1 * ymin))))) { return null; } /** * This calculates scale values if the X axis is in the center */ if (xaxispos == 'center') { coord = ((Math.abs(value) - ymin) / (ymax - ymin)) * halfGraphHeight; if (invert) { coord = halfGraphHeight - coord; } if (value < 0) { coord += this.gutterTop; coord += halfGraphHeight; } else { coord = halfGraphHeight - coord; coord += this.gutterTop; } /** * And this calculates scale values when the X axis is at the bottom */ } else { coord = ((value - ymin) / (ymax - ymin)) * graphHeight; if (invert) { coord = graphHeight - coord; } // Invert the coordinate because the Y scale starts at the top coord = graphHeight - coord; // And add on the top gutter coord = this.gutterTop + coord; } return coord; }; /** * A helper class that helps facilitatesbubble charts */ RG.Scatter.Bubble = function (scatter, min, max, width, data) { this.scatter = scatter; this.min = min; this.max = max; this.width = width; this.data = data; /** * A setter for the Bubble chart class - it just acts as a "passthru" to the Scatter object */ this.set = this.Set = function (name, value) { this.scatter.Set(name, value); return this; }; /** * A getter for the Bubble chart class - it just acts as a "passthru" to the Scatter object */ this.get = this.Get = function (name) { this.scatter.Get(name); }; /** * Tha Bubble chart draw function */ this.draw = this.Draw = function () { var bubble_min = this.min; var bubble_max = this.max; var bubble_data = this.data; var bubble_max_width = this.width; // This custom ondraw event listener draws the bubbles this.scatter.ondraw = function (obj) { // Loop through all the points (first dataset) for (var i=0; i