/** * 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 RGraph license. For all kinds of business | * | purposes there is a small one-time licensing fee to pay and for non | * | commercial purposes it is free to use. You can read the full license here: | * | | * | http://www.rgraph.net/license | * o------------------------------------------------------------------------------o */ if (typeof(RGraph) == 'undefined') RGraph = {}; /** * 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 (id, value, max) { this.id = id; this.max = max; this.value = value; this.canvas = document.getElementById(typeof id === 'object' ? id.id : id); this.context = this.canvas.getContext('2d'); this.canvas.__object__ = this; 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 = []; /** * Compatibility with older browsers */ RGraph.OldBrowserCompat(this.context); this.properties = { 'chart.min': 0, '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 } /** * Allow for new style method of passing arguments to the constructor */ if (arguments.length == 4) { this.min = arguments[1]; this.max = arguments[2]; this.value = arguments[3]; this.properties['chart.min'] = arguments[1]; } else if (arguments.length == 3) { this.min = 0; this.max = arguments[2]; this.value = arguments[1]; this.properties['chart.min'] = 0; } // 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 - prop['chart.min']; value += prop['chart.min']; if (mouseXY[0] < this.gutterLeft) { value = prop['chart.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 = 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 = 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.Redraw(); } } } /** * Draws chart.labels.specific */ 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