// version: 2014-08-16 /** * 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 progress bar constructor * * @param int id The ID of the canvas tag * @param int value The indicated value of the meter. * @param int max The end value (the upper most) of the meter */ RGraph.HProgress = function (conf) { /** * Allow for object config style */ if ( typeof conf === 'object' && typeof conf.min === 'number' && typeof conf.max === 'number' && typeof conf.value !== 'undefined' && typeof conf.id === 'string') { var id = conf.id var canvas = document.getElementById(id); var min = conf.min; var max = conf.max; var value = conf.value; var parseConfObjectForOptions = true; // Set this so the config is parsed (at the end of the constructor) } else { var id = conf; var canvas = document.getElementById(id); var min = arguments[1]; var max = arguments[2]; var value = arguments[3]; } this.id = id; this.canvas = canvas; this.context = this.canvas.getContext('2d'); this.canvas.__object__ = this; this.min = min; this.max = max; this.value = RGraph.stringsToNumbers(value); this.type = 'hprogress'; this.coords = []; this.isRGraph = true; this.currentValue = null; 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); this.properties = { 'chart.colors': ['Gradient(white:#0c0)','Gradient(white:red)','Gradient(white:green)','yellow','pink','cyan','black','white','gray'], 'chart.strokestyle.inner': '#999', 'chart.strokestyle.outer': '#999', 'chart.tickmarks': true, 'chart.tickmarks.color': '#999', 'chart.tickmarks.inner': false, 'chart.tickmarks.zerostart':true, 'chart.gutter.left': 25, 'chart.gutter.right': 25, 'chart.gutter.top': 25, 'chart.gutter.bottom': 25, 'chart.numticks': 10, 'chart.numticks.inner': 50, 'chart.background.color': '#eee', 'chart.shadow': false, 'chart.shadow.color': 'rgba(0,0,0,0.5)', 'chart.shadow.blur': 3, 'chart.shadow.offsetx': 3, 'chart.shadow.offsety': 3, 'chart.title': '', 'chart.title.background': null, 'chart.title.bold': true, 'chart.title.font': null, 'chart.title.x': null, 'chart.title.y': null, 'chart.title.halign': null, 'chart.title.valign': null, 'chart.text.size': 10, 'chart.text.color': 'black', 'chart.text.font': 'Arial', 'chart.contextmenu': null, 'chart.units.pre': '', 'chart.units.post': '', 'chart.tooltips': null, 'chart.tooltips.effect': 'fade', 'chart.tooltips.css.class': 'RGraph_tooltip', 'chart.tooltips.highlight': true, 'chart.tooltips.event': 'onclick', 'chart.highlight.stroke': 'rgba(0,0,0,0)', 'chart.highlight.fill': 'rgba(255,255,255,0.7)', 'chart.annotatable': false, 'chart.annotate.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.arrows': false, 'chart.margin': 0, 'chart.resizable': false, 'chart.resize.handle.adjust':[0,0], 'chart.resize.handle.background':null, 'chart.labels.specific': null, 'chart.labels.count': 10, 'chart.adjustable': false, 'chart.scale.decimals': 0, 'chart.scale.point': '.', 'chart.scale.thousand': ',', 'chart.key': null, 'chart.key.background': 'white', 'chart.key.position': 'gutter', '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.color.shape': 'square', 'chart.key.rounded': true, 'chart.key.linewidth': 1, 'chart.key.colors': null, 'chart.key.color.shape': 'square', 'chart.key.interactive': false, 'chart.key.interactive.highlight.chart.stroke': 'black', 'chart.key.interactive.highlight.chart.fill': 'rgba(255,255,255,0.7)', 'chart.key.interactive.highlight.label': 'rgba(255,0,0,0.2)', 'chart.key.text.color': 'black', 'chart.labels.position': 'bottom', 'chart.events.mousemove': null, 'chart.events.click': null, 'chart.border.inner': true } // Check for support if (!this.canvas) { alert('[HPROGRESS] No canvas support'); return; } /** * Create the dollar objects so that functions can be added to them */ var linear_data = RGraph.array_linearize(value); for (var i=0; i= left && mouseX <= (left + width) && mouseY >= top && mouseY <= (top + height) ) { var tooltip = RG.parseTooltipText(prop['chart.tooltips'], idx); return { 0: this, 1: left, 2: top, 3: width, 4: height, 5: idx, 'object':this, 'x':left, 'y':top, 'width': width, 'height': height, 'index': idx, 'tooltip': tooltip } } } }; /** * This function returns the value that the mouse is positioned at, regardless of * the actual indicated value. * * @param object e The event object */ this.getValue = function (e) { var mouseXY = RG.getMouseXY(e); var value = (mouseXY[0] - this.gutterLeft) / this.width; value *= this.max - this.min; value += this.min; if (mouseXY[0] < this.gutterLeft) { value = this.min; } if (mouseXY[0] > (ca.width - this.gutterRight) ) { value = this.max } 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) { // Add the new highlight RG.Highlight.Rect(this, shape); }; /** * The getObjectByXY() worker method. Don't call this call: * * RGraph.ObjectRegistry.getObjectByXY(e) * * @param object e The event object */ this.getObjectByXY = function (e) { var mouseXY = RG.getMouseXY(e); if ( mouseXY[0] > this.gutterLeft && mouseXY[0] < (ca.width - this.gutterRight) && mouseXY[1] > this.gutterTop && mouseXY[1] < (ca.height - this.gutterBottom) ) { return this; } }; /** * This method handles the adjusting calculation for when the mouse is moved * * @param object e The event object */ this.adjusting_mousemove = this.Adjusting_mousemove = function (e) { /** * Handle adjusting for the HProgress */ if (prop['chart.adjustable'] && RG.Registry.Get('chart.adjusting') && RG.Registry.Get('chart.adjusting').uid == this.uid) { var mouseXY = RG.getMouseXY(e); var value = this.getValue(e); if (typeof(value) == 'number') { this.value = Number(value.toFixed(prop['chart.scale.decimals'])); RG.redrawCanvas(ca); // Fire the onadjust event RG.fireCustomEvent(this, 'onadjust'); } } }; /** * Draws chart.labels.specific */ this.drawSpecificLabels = this.DrawSpecificLabels = function () { var labels = prop['chart.labels.specific']; if (labels) { var font = prop['chart.text.font']; var size = prop['chart.text.size']; var valign = (prop['chart.labels.position'] == 'top' ? 'bottom' : 'top'); var step = this.width / (labels.length - 1); co.beginPath(); co.fillStyle = prop['chart.text.color']; for (var i=0; i