// o---------------------------------------------------------------------------------o // | This file is part of the RGraph package - you can learn more at: | // | | // | https://www.rgraph.net/license.html | // | | // | RGraph is dual-licensed under the Open Source GPL license. That means that it's | // | free to use and there are no restrictions on what you can use RGraph for! | // | If the GPL license does not suit you however, then there's an inexpensive | // | commercial license option available. See the URL above for more details. | // o---------------------------------------------------------------------------------o RGraph = window.RGraph || {isrgraph:true,isRGraph:true,rgraph:true}; // The progress bar constructor RGraph.HProgress = function (conf) { var id = conf.id, canvas = document.getElementById(id), min = conf.min, max = conf.max, value = conf.value; 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.isRGraph = true; this.isrgraph = true; this.rgraph = true; this.currentValue = null; this.uid = RGraph.createUID(); this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.createUID(); this.colorsParsed = false; this.coords = []; this.coordsText = []; this.original_colors = []; this.firstDraw = true; // After the first draw this will be false this.stopAnimationRequested = false;// Used to control the animations this.properties = { colors: ['#0c0','red','green','yellow','pink','cyan','black','white','gray'], colorsStrokeInner: '#999', colorsStrokeOuter: '#999', tickmarksColor: '#999', tickmarksInnerCount: 0, tickmarksOuterCount: 0, backgroundColor: 'Gradient(#ccc:#eee:#efefef)', //backgroundColor: '#eee', marginLeft: 35, marginRight: 35, marginTop: 35, marginBottom: 35, shadow: false, shadowColor: 'rgba(0,0,0,0.5)', shadowBlur: 3, shadowOffsetx: 3, shadowOffsety: 3, title: '', titleX: null, titleY: null, titleHalign: null, titleValign: null, titleFont: null, titleSize: null, titleColor: null, titleBold: null, titleItalic: null, titleOffsetx: 0, titleOffsety: 0, titleSubtitle: '', titleSubtitleSize: null, titleSubtitleColor: '#aaa', titleSubtitleFont: null, titleSubtitleBold: null, titleSubtitleItalic: null, titleSubtitleOffsetx: 0, titleSubtitleOffsety: 0, textSize: 12, textColor: 'black', textFont: 'Arial, Verdana, sans-serif', textBold: false, textItalic: false, textAccessible: false, textAccessibleOverflow: 'visible', textAccessiblePointerevents: false, text: null, contextmenu: null, scaleUnitsPre: '', scaleUnitsPost: '', scaleDecimals: 0, scalePoint: '.', scaleThousand: ',', adjustable: false, tooltips: null, tooltipsEffect: 'slide', tooltipsCssClass: 'RGraph_tooltip', tooltipsCss: null, tooltipsHighlight: true, tooltipsEvent: 'onclick', tooltipsFormattedThousand: ',', tooltipsFormattedPoint: '.', tooltipsFormattedDecimals: 0, tooltipsFormattedUnitsPre: '', tooltipsFormattedUnitsPost: '', tooltipsFormattedKeyColors: null, tooltipsFormattedKeyColorsShape: 'square', tooltipsFormattedKeyLabels: [], tooltipsFormattedListType: 'ul', tooltipsFormattedListItems: null, tooltipsFormattedTableHeaders: null, tooltipsFormattedTableData: null, tooltipsPointer: true, tooltipsPointerOffsetx: 0, tooltipsPointerOffsety: 0, tooltipsPositionStatic: true, tooltipsHotspotIgnore: null, highlightLinewidth: 1, highlightStroke: 'rgba(0,0,0,0)', highlightFill: 'rgba(255,255,255,0.7)', annotatable: false, annotateColor: 'black', arrows: false, marginInner: 0, labelsPosition: 'bottom', labelsSpecific: null, labelsSpecificFormattedDecimals: 0, labelsSpecificFormattedPoint: '.', labelsSpecificFormattedThousand: ',', labelsSpecificFormattedUnitsPre: '', labelsSpecificFormattedUnitsPost: '', labelsCount: 10, labelsOffsetx: 0, labelsOffsety: 0, labelsFont: null, labelsSize: null, labelsColor: null, labelsBold: null, labelsItalic: null, labelsInner: false, labelsInnerFont: null, labelsInnerSize: null, labelsInnerColor: null, labelsInnerBold: null, labelsInnerItalic: null, labelsInnerOffsetx: 0, labelsInnerOffsety: 0, labelsInnerDecimals: 0, labelsInnerBackgroundFill: 'rgba(255,255,255,0.7)', labelsInnerBorder: true, labelsInnerBorderLinewidth: 1, labelsInnerBorderColor: '#ccc', labelsInnerScalePoint: null, labelsInnerScaleThousand: null, labelsInnerUnitsPre: '', labelsInnerUnitsPost: '', labelsInnerSpecific: null, key: null, keyBackground: 'white', keyPosition: 'margin', keyHalign: 'right', keyShadow: false, keyShadowColor: '#666', keyShadowBlur: 3, keyShadowOffsetx: 2, keyShadowOffsety: 2, keyPositionMarginBoxed: false, keyPositionMarginHSpace: 0, keyPositionX: null, keyPositionY: null, keyColorShape: 'square', keyRounded: true, keyLinewidth: 1, keyColors: null, keyColorShape: 'square', keyInteractive: false, keyInteractiveHighlightChartLinewidth: 2, keyInteractiveHighlightChartStroke: 'black', keyInteractiveHighlightChartFill: 'rgba(255,255,255,0.7)', keyInteractiveHighlightLabel: 'rgba(255,0,0,0.2)', keyLabelsColor: null, keyLabelsFont: null, keyLabelsSize: null, keyLabelsBold: null, keyLabelsItalic: null, keyLabelsOffsetx: 0, keyLabelsOffsety: 0, keyFormattedDecimals: 0, keyFormattedPoint: '.', keyFormattedThousand: ',', keyFormattedUnitsPre: '', keyFormattedUnitsPost: '', keyFormattedValueSpecific: null, keyFormattedItemsCount: null, borderInner: true, corners: 'square', // Can also be round cornersRoundRadius: 10, clearto: 'rgba(0,0,0,0)' } // // Add the reverse look-up table for property names // so that property names can be specified in any case. // this.properties_lowercase_map = []; for (var i in this.properties) { if (typeof i === 'string') { this.properties_lowercase_map[i.toLowerCase()] = i; } } // 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.arrayLinearize(value); for (var i=0; i 0) { var spacing = (this.canvas.width - this.marginLeft - this.marginRight) / properties.tickmarksInnerCount; this.context.lineWidth = 1; this.context.strokeStyle = properties.colorsStrokeOuter; this.context.beginPath(); for (var x = this.marginLeft; x 0) { this.context.beginPath(); // This is used by the label function below this.tickInterval = this.width / properties.tickmarksOuterCount; var start = 0; if (properties.labelsPosition === 'top') { for (var i=this.marginLeft + start; i<=(this.width + this.marginLeft + 0.1); i+=this.tickInterval) { this.context.moveTo(Math.round(i), this.marginTop); this.context.lineTo(Math.round(i), this.marginTop - 4); } } else { for (var i=this.marginLeft + start; i<=(this.width + this.marginLeft + 0.1); i+=this.tickInterval) { this.context.moveTo(Math.round(i), this.marginTop + this.height); this.context.lineTo(Math.round(i), this.marginTop + this.height + 4); } } this.context.stroke(); } }; // // The function that draws the labels // this.drawLabels = function () { if (!RGraph.isNull(properties.labelsSpecific)) { return this.drawSpecificLabels(); } if (properties.labelsCount === 0) { return; } this.context.fillStyle = properties.textColor; var xPoints = [], yPoints = [], bold = properties.textBold, italic = properties.textItalic, color = properties.textColor, font = properties.textFont, size = properties.textSize, offsetx = properties.labelsOffsetx, offsety = properties.labelsOffsety; for (i=0,len=this.scale2.labels.length; i (this.canvas.width - this.marginRight) ) { 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) { var isLast = shape.index === this.coords.length - 1; if (!properties.tooltipsHighlight) { return; } // Call a function to highlight the chart if (typeof properties.highlightStyle === 'function') { (properties.highlightStyle)(shape); // Highlight all of the rects except the selected one - essentially an inverted highlight } else if (typeof properties.highlightStyle === 'string' && properties.highlightStyle === 'invert') { for (var i=0; i this.marginLeft && mouseXY[0] < (this.canvas.width - this.marginRight) && mouseXY[1] > this.marginTop && mouseXY[1] < (this.canvas.height - this.marginBottom) ) { 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 (properties.adjustable && RGraph.Registry.get('adjusting') && RGraph.Registry.get('adjusting').uid == this.uid) { var mouseXY = RGraph.getMouseXY(e); var value = this.getValue(e); if (typeof value === 'number') { this.value = Number(value.toFixed(properties.scaleDecimals)); RGraph.redrawCanvas(this.canvas); // Fire the onadjust event RGraph.fireCustomEvent(this, 'onadjust'); } } }; // // Draws labelsSpecific // this.drawSpecificLabels = function () { // // If the xaxisLabels option is a string then turn it // into an array. // if (properties.labelsSpecific && properties.labelsSpecific.length) { if (typeof properties.labelsSpecific === 'string') { properties.labelsSpecific = RGraph.arrayPad({ array: [], length: properties.labelsCount, value: properties.labelsSpecific }); } // Label substitution // for (var i=0; i this.max) { return null; } var barWidth = this.canvas.width - this.marginLeft - this.marginRight; var coord = ((value - min) / (this.max - min)) * barWidth; coord = this.marginLeft + coord; return coord; }; // // This returns true/false as to whether the cursor is over the chart area. // The cursor does not necessarily have to be over the bar itself. // this.overChartArea = function (e) { var mouseXY = RGraph.getMouseXY(e); var mouseX = mouseXY[0]; var mouseY = mouseXY[1]; if ( mouseX >= this.marginLeft && mouseX <= (this.canvas.width - this.marginRight) && mouseY >= this.marginTop && mouseY <= (this.canvas.height - this.marginBottom) ) { return true; } return false; }; // // // this.parseColors = function () { // Save the original colors so that they can be restored when the canvas is reset if (this.original_colors.length === 0) { this.original_colors.backgroundColor = RGraph.arrayClone(properties.backgroundColor, {structuredClone: false}); this.original_colors.colors = RGraph.arrayClone(properties.colors, {structuredClone: false}); this.original_colors.tickmarksColor = RGraph.arrayClone(properties.tickmarksColor, {structuredClone: false}); this.original_colors.colorsStrokeInner = RGraph.arrayClone(properties.colorsStrokeInner, {structuredClone: false}); this.original_colors.colorsStrokeOuter = RGraph.arrayClone(properties.colorsStrokeOuter, {structuredClone: false}); this.original_colors.highlightFill = RGraph.arrayClone(properties.highlightFill, {structuredClone: false}); this.original_colors.highlightStroke = RGraph.arrayClone(properties.highlightStroke, {structuredClone: false}); this.original_colors.highlightColor = RGraph.arrayClone(properties.highlightColor, {structuredClone: false}); } var colors = properties.colors; for (var i=0; i