// 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.VProgress = function (conf) { this.id = conf.id; this.canvas = document.getElementById(this.id); this.context = this.canvas.getContext('2d'); this.canvas.__object__ = this; this.min = RGraph.stringsToNumbers(conf.min); this.max = RGraph.stringsToNumbers(conf.max); this.value = RGraph.stringsToNumbers(conf.value); this.type = 'vprogress'; 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','blue','yellow','pink','cyan','black','white','gray'], colorsStrokeInner: '#999', colorsStrokeOuter: '#999', tickmarksOuter: true, tickmarksInner: false, tickmarksOuterCount: 0, tickmarksInnerCount: 0, tickmarksOuterColor: '#999', tickmarksInnerColor: '#999', marginLeft: 35, marginRight: 35, marginTop: 35, marginBottom: 35, marginInner: 0, //backgroundColor: 'Gradient(#ccc:#eee:#efefef)', backgroundColor: '#eee', shadow: false, shadowColor: 'rgba(0,0,0,0.5)', shadowBlur: 3, shadowOffsetx: 3, shadowOffsety: 3, title: '', titleBold: null, titleItalic: null, titleFont: null, titleSize: null, titleColor: null, titleHalign: null, titleValign: null, titleOffsetx: 0, titleOffsety: 0, titleSubtitle: '', titleSubtitleSize: null, titleSubtitleColor: '#aaa', titleSubtitleFont: null, titleSubtitleBold: null, titleSubtitleItalic: null, titleSubtitleOffsetx: 0, titleSubtitleOffsety: 0, titleSide: null, titleSideFont: null, titleSideSize: null, titleSideColor: null, titleSideBold: null, titleSideItalic: null, titleSideOffsetx: 0, titleSideOffsety: 0, textSize: 12, textColor: 'black', textFont: 'Arial, Verdana, sans-serif', textBold: false, textItalic: false, textAccessible: false, textAccessibleOverflow: 'visible', textAccessiblePointerevents: false, text: null, contextmenu: null, scaleDecimals: 0, scaleThousand: ',', scalePoint: '.', scaleUnitsPre: '', scaleUnitsPost: '', 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, annotatableColor: 'black', arrows: false, labelsInner: false, labelsInnerFont: null, labelsInnerSize: null, labelsInnerColor: null, labelsInnerBold: null, labelsInnerItalic: null, labelsInnerBackgroundFill: 'rgba(255,255,255,0.75)', labelsInnerBorder: true, labelsInnerBorderLinewidth: 1, labelsInnerBorderColor: '#ccc', labelsInnerDecimals: 0, labelsInnerUnitsPre: '', labelsInnerUnitsPost: '', labelsInnerScaleThousand: null, labelsInnerScalePoint: null, labelsInnerSpecific: null, labelsInnerOffsetx: 0, labelsInnerOffsety: 0, labelsCount: 10, labelsPosition: 'right', labelsOffsetx: 0, labelsOffsety: 0, labelsFont: null, labelsSize: null, labelsColor: null, labelsBold: null, labelsItalic: null, labelsSpecific: null, labelsSpecificFormattedDecimals: 0, labelsSpecificFormattedUnitsPre: '', labelsSpecificFormattedUnitsPost: '', labelsSpecificFormattedThousand: ',', labelsSpecificFormattedPoint: '.', adjustable: false, key: null, keyBackground: 'white', keyPosition: 'graph', keyHalign: 'right', keyShadow: false, keyShadowColor: '#666', keyShadowBlur: 3, keyShadowOffsetx: 2, keyShadowOffsety: 2, keyPositionGutterBoxed: false, keyPositionX: null, keyPositionY: null, keyColorShape: 'square', keyRounded: true, keyLinewidth: 1, keyColors: null, keyInteractive: false, keyInteractiveHighlightChartLinewidth: 2, keyInteractiveHighlightChartStroke: '#000', 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('[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) { var spacing = (this.canvas.height - this.marginTop - this.marginBottom) / properties.tickmarksInnerCount; this.context.lineWidth = 1; this.context.strokeStyle = properties.colorsStrokeInner; this.context.beginPath(); for (var y = this.marginTop; y 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 = function (shape) { if (properties.tooltipsHighlight) { if (typeof properties.highlightStyle === 'function') { (properties.highlightStyle)(shape); // Highlight all of the rects except this 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 function allows the VProgress to be adjustable. // UPDATE: Not any more // 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 = 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') { // Fire the onadjust event RGraph.fireCustomEvent(this, 'onadjust'); this.value = Number(value.toFixed(properties.scaleDecimals)); RGraph.redrawCanvas(this.canvas); } } }; // // Draws labelsSpecific // this.drawSpecificLabels = function () { var labels = properties.labelsSpecific; if (labels) { var halign = properties.labelsPosition === 'right' ? 'left' : 'right'; var step = this.height / (labels.length - 1); this.context.beginPath(); this.context.fillStyle = properties.textColor; for (var i=0; i this.max || value < this.min) { return null; } var barHeight = this.canvas.height - properties.marginTop - properties.marginBottom; var coord = ((value - this.min) / (this.max - this.min)) * barHeight; coord = this.canvas.height - coord - properties.marginBottom; 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.colors = RGraph.arrayClone(properties.colors, {structuredClone: false}); this.original_colors.tickmarksInnerColor = RGraph.arrayClone(properties.tickmarksInnerColor, {structuredClone: false}); this.original_colors.tickmarksOuterColor = RGraph.arrayClone(properties.tickmarksOuterColor, {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.backgroundColor = RGraph.arrayClone(properties.backgroundColor, {structuredClone: false}); } var colors = properties.colors; for (var i=0,len=colors.length; i