// o---------------------------------------------------------------------------o // | This file is part of the RGraph package - you can learn more at: | // | | // | https://www.rgraph.net | // | | // | RGraph is dual-licensed under the Open Source GPL license. This means | // | that it's free to use for any purpose. The GPL license does have | // | consequences on the license of the software that you include it in, | // | however. If this is not desirable, then there's an inexpensive commercial | // | license option available. See the RGraph website for more details. | // o---------------------------------------------------------------------------o RGraph = window.RGraph || {isrgraph:true,isRGraph:true,rgraph:true}; // // The progress bar constructor // RGraph.SemiCircularProgress = 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 = 'semicircularprogress'; 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 = { backgroundColor: 'transparent', backgroundGrid: false, backgroundGridMargin: 20, backgroundGridColor: '#eee', backgroundGridLinewidth: 1, backgroundGridCircles: true, backgroundGridRadials: true, backgroundGridRadialsCount: 10, backgroundFill: true, backgroundFillColor: null, colors: RGraph.getColors(), colorsStroke: 'transparent', linewidth: 1, marginLeft: 35, marginRight: 35, marginTop: 35, marginBottom: 35, radius: null, centerx: null, centery: null, width: null, anglesStart: Math.PI, anglesEnd: (2 * Math.PI), scaleVisible: false, scaleMin: null, scaleMax: null, // Defaults to the charts max value scaleDecimals: 0, scalePoint: '.', scaleThousand: ',', scaleFormatter: null, scaleUnitsPre: '', scaleUnitsPost: '', scaleLabelsCount: 10, scaleLabelsFont: null, scaleLabelsSize: null, scaleLabelsColor: null, scaleLabelsBold: null, scaleLabelsItalic: null, scaleLabelsOffsetr: 0, scaleLabelsOffsetx: 0, scaleLabelsOffsety: 0, shadow: false, shadowColor: 'rgba(220,220,220,1)', shadowBlur: 2, shadowOffsetx: 2, shadowOffsety: 2, labelsCenter: true, labelsCenterIndex: 0, labelsCenterFade: false, labelsCenterSize: 40, labelsCenterColor: null, labelsCenterBold: null, labelsCenterItalic: null, labelsCenterFont: null, labelsCenterValign: 'bottom', labelsCenterOffsetx: 0, labelsCenterOffsety: 0, labelsCenterThousand: ',', labelsCenterPoint: '.', labelsCenterDecimals: 0, labelsCenterUnitsPost: '', labelsCenterUnitsPre: '', labelsCenterSpecific: null, labelsMin: true, labelsMinColor: null, labelsMinFont: null, labelsMinBold: null, labelsMinSize: null, labelsMinItalic: null, labelsMinOffsetAngle: 0, labelsMinOffsetx: 0, labelsMinOffsety: 5, labelsMinThousand: ',', labelsMinPoint: '.', labelsMinDecimals: 0, labelsMinUnitsPost: '', labelsMinUnitsPre: '', labelsMinSpecific: null, labelsMax: true, labelsMaxColor: null, labelsMaxFont: null, labelsMaxBold: null, labelsMaxSize: null, labelsMaxItalic: null, labelsMaxOffsetAngle: 0, labelsMaxOffsetx: 0, labelsMaxOffsety: 5, labelsMaxThousand: ',', labelsMaxPoint: '.', labelsMaxDecimals: 0, labelsMaxUnitsPost: '', labelsMaxUnitsPre: '', labelsMaxSpecific: null, title: '', titleBold: true, 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, textSize: 12, textColor: 'black', textFont: 'Arial, Verdana, sans-serif', textBold: false, textItalic: false, textAccessible: false, textAccessibleOverflow: 'visible', textAccessiblePointerevents:false, text: null, contextmenu: null, tooltips: null, tooltipsEffect: 'slide', tooltipsOverride: null, tooltipsCssClass: 'RGraph_tooltip', tooltipsCss: null, tooltipsEvent: 'onclick', tooltipsHighlight: true, tooltipsPersistent: false, tooltipsHotspotXonly: false, tooltipsFormattedThousand: ',', tooltipsFormattedPoint: '.', tooltipsFormattedDecimals: 0, tooltipsFormattedUnitsPre: '', tooltipsFormattedUnitsPost: '', tooltipsFormattedKeyColors: null, tooltipsFormattedKeyColorsShape: 'square', tooltipsFormattedKeyColorsCss: null, tooltipsFormattedKeyLabels: [], tooltipsFormattedListType: 'ul', tooltipsFormattedListItems: null, tooltipsFormattedTableHeaders: null, tooltipsFormattedTableData: null, tooltipsPointer: true, tooltipsPointerCss: null, tooltipsPointerOffsetx: 0, tooltipsPointerOffsety: 0, tooltipsPositionStatic: true, tooltipsOffsetx: 0, tooltipsOffsety: 0, tooltipsHotspotIgnore: null, highlightStyle: null, highlightStroke: 'transparent', highlightFill: 'rgba(255,255,255,0.7)', highlightFade: true, annotatable: false, annotatableColor: 'black', annotatableLinewidth: 1, 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, keyInteractive: false, keyInteractiveHighlightChartStroke: 'rgba(0,0,0,0)', 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, adjustable: false, variant: 'default', clearto: 'transparent', events: {}, clip: null, responsive: null, scale: true, scaleFactor: 2, antialiasTranslate: false, style: [] }; // // These are the properties that get scaled up if the // scale option is enabled. // this.properties_scale = [ 'backgroundGridMargin', 'backgroundGridLinewidth', 'linewidth', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom', 'radius', 'centerx', 'centery', 'width', 'scaleLabelsSize', 'scaleLabelsOffsetr', 'scaleLabelsOffsetx', 'scaleLabelsOffsety', 'shadowBlur', 'shadowOffsetx', 'shadowOffsety', 'labelsCenterSize', 'labelsCenterOffsetx', 'labelsCenterOffsety', 'labelsMinSize', 'labelsMinOffsetx', 'labelsMinOffsety', 'labelsMaxSize', 'labelsMaxOffsetx', 'labelsMaxOffsety', 'titleSize', 'titleOffsetx', 'titleOffsety', 'titleSubtitleSize', 'titleSubtitleOffsetx', 'titleSubtitleOffsety', 'textSize', 'annotatableLinewidth', 'keyShadowBlur', 'keyShadowOffsetx', 'keyShadowOffsety', 'keyPositionMarginHSpace', 'keyPositionX', 'keyPositionY', 'keyLinewidth', 'keyLabelsSize', 'keyLabelsOffsetx', 'keyLabelsOffsety' ]; // // 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('[SEMICIRCULARPROGRESS] No canvas support'); return; } // Easy access to properties and the path function var properties = this.properties; this.path = RGraph.pathObjectFunction; // // "Decorate" the object with the generic effects if the effects library has been included // if (RGraph.Effects && typeof RGraph.Effects.decorate === 'function') { RGraph.Effects.decorate(this); } // Add the responsive method. This method resides in the common file. this.responsive = RGraph.responsive; // // A generic setter // // @param string name The name of the property to set or it can also be an object containing // object style configuration // this.set = function (name) { var value = typeof arguments[1] === 'undefined' ? null : arguments[1]; // Go through all of the properties and make sure // that they're using the correct capitalisation if (typeof name === 'string') { name = this.properties_lowercase_map[name.toLowerCase()] || name; } // backgroundBackdrop => backgroundFill // backgroundBackdropColor => backgroundFillColor if (name === 'backgroundBackdrop') name = 'backgroundFill'; if (name === 'backgroundBackdropColor') name = 'backgroundFillColor'; // Set the colorsParsed flag to false if the colors // property is being set if ( name === 'colors' || name === 'keyColors' || name === 'backgroundColor' || name === 'backgroundFill' || name === 'backgroundFillOpacity' ) { this.colorsParsed = false; } // the number of arguments is only one and it's an // object - parse it for configuration data and return. if (arguments.length === 1 && typeof arguments[0] === 'object') { for (i in arguments[0]) { if (typeof i === 'string') { this.set(i, arguments[0][i]); } } return this; } properties[name] = value; return this; }; // // A generic getter // // @param string name The name of the property to get // this.get = function (name) { // Go through all of the properties and make sure // that they're using the correct capitalisation name = this.properties_lowercase_map[name.toLowerCase()] || name; return properties[name]; }; // // Draws the progress bar // this.draw = function () { // MUST be the first thing that's done - but only // once!! RGraph.runOnce(`scale-up-the-canvas-once-in-the-draw-function-${this.id}-${this.uid}`, () => { // Note that we're in an arrow function so the // 'this' variable is OK to be used and refers // to the RGraph Line chart object. RGraph.scale(this); }); // // Fire the onbeforedraw event // RGraph.fireCustomEvent(this, 'onbeforedraw'); // // Add any CSS that has been specified to the document. // This is general CSS and does not necessarily have to // pertain to the canvas tag. It only gets added once // to the document no matter how many times this draw // function is called. // // Add the CSS to a