// version: 2017-11-25 /** * o--------------------------------------------------------------------------------o * | This file is part of the RGraph package - you can learn more at: | * | | * | http://www.rgraph.net | * | | * | RGraph is licensed under the Open Source MIT license. That means that it's | * | totally free to use and there are no restrictions on what you can do with it! | * 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.value !== 'undefined' && typeof conf.id === 'string') { var id = conf.id, canvas = document.getElementById(id), min = conf.min, max = conf.max, value = conf.value, parseConfObjectForOptions = true; // Set this so the config is parsed (at the end of the constructor) } else { var id = conf, canvas = document.getElementById(id), min = arguments[1], max = arguments[2], value = arguments[3]; } this.id = id; this.canvas = canvas; this.context = this.canvas.getContext('2d'); this.canvas.__object__ = this; this.min = RGraph.stringsToNumbers(min); this.max = RGraph.stringsToNumbers(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': 'Gradient(#ccc:#eee:#efefef)', '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': 12, 'chart.text.color': 'black', 'chart.text.font': 'Segoe UI, Arial, Verdana, sans-serif', 'chart.text.accessible': true, 'chart.text.accessible.overflow': 'visible', 'chart.text.accessible.pointerevents': true, '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.labels.offsetx': 0, 'chart.labels.offsety': 0, '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, 'chart.clearto': 'rgba(0,0,0,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 0 ? prop['chart.scale.decimals'] : 0) + prop['chart.units.post'], 'valign':'bottom', 'halign':'center', 'tag': 'scale' }); } else { RG.text2(this, { 'font':font, 'size':size, 'x':this.gutterLeft + offsetx, 'y':ca.height - this.gutterBottom + 5 + offsety, 'text': prop['chart.units.pre'] + Number(this.min).toFixed(this.min > 0 ? prop['chart.scale.decimals'] : 0) + prop['chart.units.post'], 'valign':'top', 'halign':'center', 'tag': 'scale' }); } } }; /** * Returns the focused bar * * @param event e The event object */ this.getShape = this.getBar = function (e) { var mouseXY = RG.getMouseXY(e), mouseX = mouseXY[0], mouseY = mouseXY[1]; for (var i=0,len=this.coords.length; i (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) { var last = shape.index === this.coords.length - 1; if (typeof prop['chart.highlight.style'] === 'function') { (prop['chart.highlight.style'])(shape); } else { this.drawCurvedBar({ x: shape.x, y: shape.y, width: shape.width, height: shape.height, stroke: prop['chart.highlight.stroke'], fill: prop['chart.highlight.fill'] }); } }; /** * 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'], size = prop['chart.text.size'], valign = (prop['chart.labels.position'] == 'top' ? 'bottom' : 'top'), step = this.width / (labels.length - 1), offsetx = prop['chart.labels.offsetx'], offsety = prop['chart.labels.offsety'] co.beginPath(); co.fillStyle = prop['chart.text.color']; for (var i=0; i