// 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 mixed conf This can either be an object that contains all of the configuration data * (the updated way of configuring the object) or it can be a string consisting of the * canvas ID * @param number The minimum value (if using the older configuration style) * @param number The maximum value (if using the older configuration style) * @param number The represented value (if using the older configuration style) */ RGraph.VProgress = function (conf) { /** * Allow for object config style */ if ( typeof conf === 'object' && typeof conf.min === 'number' && typeof conf.max === 'number' && typeof conf.id === 'string') { var parseConfObjectForOptions = true; // Set this so the config is parsed (at the end of the constructor) } else { var conf = { id: arguments[0], min: arguments[1], max: arguments[2], value: arguments[3] } } this.id = conf.id; this.canvas = document.getElementById(this.id); this.context = this.canvas.getContext('2d'); this.canvas.__object__ = this; this.min = conf.min; this.max = conf.max; this.value = RGraph.stringsToNumbers(conf.value); this.type = 'vprogress'; 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.zerostart':true, 'chart.tickmarks.color': '#999', 'chart.tickmarks.inner': false, '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.bold': true, 'chart.title.font': null, 'chart.title.size': null, 'chart.title.color': 'black', 'chart.title.side': null, 'chart.title.side.font': 'Arial', 'chart.title.side.size': 12, 'chart.title.side.color': 'black', 'chart.title.side.bold': true, '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.zoom.action': 'zoom', 'chart.arrows': false, 'chart.margin': 0, 'chart.resizable': false, 'chart.resize.handle.adjust': [0,0], 'chart.resize.handle.background': null, 'chart.label.inner': false, 'chart.labels.count': 10, 'chart.labels.position': 'right', 'chart.adjustable': false, 'chart.scale.decimals': 0, 'chart.scale.thousand': ',', 'chart.scale.point': '.', '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.color.shape': 'square', 'chart.key.rounded': true, 'chart.key.linewidth': 1, 'chart.key.colors': null, 'chart.key.interactive': false, 'chart.key.interactive.highlight.chart.stroke': '#000', '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.events.click': null, 'chart.events.mousemove': null, 'chart.border.inner': true } // Check for support if (!this.canvas) { alert('[PROGRESS] No canvas support'); return; } /** * Create the dollar objects so that functions can be added to them */ var linear_data = RGraph.arrayLinearize(this.value); for (var i=0; i 0) { co.fillStyle = prop['chart.title.color']; RG.Text2(this, {'font':prop['chart.title.font'] ? prop['chart.title.font'] : text_font, 'size':title_size, 'x':this.gutterLeft + ((ca.width - this.gutterLeft - this.gutterRight) / 2), 'y':this.gutterTop - 5, 'text':prop['chart.title'], 'valign':'bottom', 'halign':'center', 'bold': prop['chart.title.bold'], 'tag': 'title' }); } // Draw side title if (typeof(prop['chart.title.side']) == 'string') { co.fillStyle = prop['chart.title.side.color']; RG.Text2(this, {'font':prop['chart.title.side.font'], 'size':prop['chart.title.side.size'], 'x':prop['chart.labels.position'] == 'right' ? this.gutterLeft - 10 : (ca.width - this.gutterRight) + 10, 'y':this.gutterTop + (this.height / 2), 'text': prop['chart.title.side'], 'valign':'bottom', 'halign':'center', 'angle': prop['chart.labels.position'] == 'right' ? 270 : 90, 'bold': prop['chart.title.side.bold'], 'tag': 'title.side' }); } }; /** * Returns the focused bar * * @param event e The event object */ this.getShape = this.getBar = function (e) { var mouseCoords = RG.getMouseXY(e) for (var i=0,len=this.coords.length; i= left && mouseX <= (left + width) && mouseY >= top && mouseY <= (top + height) ) { var tooltip = 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 }; } } }; /** * 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 mouseCoords = RG.getMouseXY(e); var mouseX = mouseCoords[0]; var mouseY = mouseCoords[1]; var value = (this.height - (mouseY - this.gutterTop)) / this.height; value *= this.max - this.min; value += this.min; // Bounds checking if (value > this.max) value = this.max; if (value < this.min) value = this.min; 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 function allows the VProgress to be adjustable. * UPDATE: Not any more */ this.allowAdjusting = this.AllowAdjusting = function () {return;}; /** * 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') { // Fire the onadjust event RG.FireCustomEvent(this, 'onadjust'); this.value = Number(value.toFixed(prop['chart.scale.decimals'])); RG.RedrawCanvas(this.canvas); } } }; /** * 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 halign = prop['chart.labels.position'] == 'right' ? 'left' : 'right'; var step = this.height / (labels.length - 1); co.beginPath(); co.fillStyle = prop['chart.text.color']; for (var i=0; i