// 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 line chart constructor // RGraph.Gauge = 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 ? this.canvas.getContext("2d", {alpha: (typeof id === 'object' && id.alpha === false) ? false : true}) : null; this.canvas.__object__ = this; this.type = 'gauge'; this.min = RGraph.stringsToNumbers(min); this.max = RGraph.stringsToNumbers(max); this.value = RGraph.stringsToNumbers(value); 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.coordsText = []; this.original_colors = []; this.firstDraw = true; // After the first draw this will be false this.stopAnimationRequested = false;// Used to control the animations // // Range checking. // // As of 4.63, it now saves the original value // this.valueOriginal = this.value; if (typeof this.value === 'object') { for (var i=0; i this.max) this.value[i] = max; if (this.value[i] < this.min) this.value[i] = min; } } else { if (this.value > this.max) this.value = max; if (this.value < this.min) this.value = min; } // Coniguration properties this.properties = { anglesStart: null, anglesEnd: null, centerx: null, centery: null, radius: null, marginLeft: 35, marginRight: 35, marginTop: 35, marginBottom: 35, borderWidth: 10, textFont: 'Arial, Verdana, sans-serif', textSize: 12, textColor: '#666', textBold: false, textItalic: false, textAccessible: false, textAccessibleOverflow: 'visible', textAccessiblePointerevents: false, text: null, titleTop: '', titleTopFont: null, titleTopSize: 16, titleTopColor: 'black', titleTopBold: true, titleTopItalic: null, titleTopPos: null, titleTopOffsetx: 0, titleTopOffsety: 0, titleTopSubtitle: null, titleTopSubtitleFont: null, titleTopSubtitleSize: null, titleTopSubtitleColor: '#666', titleTopSubtitleBold: null, titleTopSubtitleItalic: null, titleTopSubtitlePos: null, titleTopSubtitleOffsetx: 0, titleTopSubtitleOffsety: 0, titleBottom: '', titleBottomFont: null, titleBottomSize: null, titleBottomColor: null, titleBottomBold: null, titleBottomItalic: null, titleBottomPos: null, titleBottomOffsetx: 0, titleBottomOffsety: 0, backgroundColor: 'white', backgroundGradient: false, scaleDecimals: 0, scalePoint: '.', scaleThousand: ',', scaleUnitsPre: '', scaleUnitsPost: '', labelsCount: 5, labelsCentered: false, labelsOffsetRadius: 0, labelsOffsetAngle: 0, labelsOffsetx: 0, labelsOffsety: 0, labelsSpecific: null, labelsSpecificFormattedDecimals: 0, labelsSpecificFormattedPoint: '.', labelsSpecificFormattedThousand: ',', labelsSpecificFormattedUnitsPre: '', labelsSpecificFormattedUnitsPost: '', labelsFont: null, labelsSize: null, labelsColor: null, labelsBold: null, labelsItalic: null, labelsValue: false, labelsValueYPos: 0.5, labelsValueUnitsPre: '', labelsValueUnitsPost: '', labelsValueBounding: true, labelsValueBoundingFill: 'white', labelsValueBoundingStroke: 'black', labelsValueFont: null, labelsValueSize: null, labelsValueColor: null, labelsValueItalic: null, labelsValueBold: null, labelsValueDecimals: null, labelsValuePoint: null, labelsValueThousand: null, colorsRedStart: 0.9 * this.max, colorsRedColor: '#dc3912', colorsRedWidth: 5, colorsYellowColor: '#ff9900', colorsYellowWidth: 5, colorsGreenEnd: 0.7 * this.max, colorsGreenColor: 'transparent', colorsGreenWidth: 5, colorsRanges: null, needleSize: null, needleTail: false, needleColors: ['#D5604D', 'red', 'green', 'yellow'], needleType: 'triangle', needleWidth: 7, borderOuter: '#ccc', borderInner: '#f1f1f1', borderOutline: 'black', borderGradient: false, centerpinColor: 'black', centerpinGradient: false, centerpinRadius: null, tickmarksSmall: 25, tickmarksSmallColor: 'black', tickmarksMedium: 0, tickmarksMediumColor: 'black', tickmarksLarge: 5, tickmarksLargeColor: 'black', adjustable: false, annotatable: false, annotatableLinewidth: 1, annotatableColor: 'black', shadow: false, shadowColor: 'gray', shadowOffsetx: 0, shadowOffsety: 0, shadowBlur: 15, 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 = [ 'centerx', 'centery', 'radius', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom', 'borderWidth', 'textSize', 'titleTopSize', 'titleTopOffsetx', 'titleTopOffsety', 'titleTopSubtitleSize', 'titleTopSubtitleOffsetx', 'titleTopSubtitleOffsety', 'titleBottomSize', 'titleBottomOffsetx', 'titleBottomOffsety', 'labelsOffsetRadius', 'labelsOffsetx', 'labelsOffsety', 'labelsSize', 'labelsValueSize', 'colorsRedWidth', 'colorsYellowWidth', 'colorsGreenWidth', 'needleSize', 'needleWidth', 'centerpinRadius', 'annotatableLinewidth', 'shadowOffsetx', 'shadowOffsety', 'shadowBlur' ]; // // 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; } } // 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; // // An all encompassing accessor // // @param string name The name of the property // @param mixed value The value of the property // 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; } // Set the colorsParsed flag to false if the colors // property is being set if ( name === 'colors' || name === 'backgroundColor' || name === 'colorsRedColor' || name === 'colorsYellowColor' || name === 'colorsGreenColor' || name === 'borderInner' || name === 'borderOuter' || name === 'colorsRanges' || name === 'needleColors' ) { 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; }; // // An all encompassing accessor // // @param string name The name of the property // 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]; }; // // The function you call to draw the line chart // // @param bool An optional bool used internally to ditinguish whether the // line chart is being called by the bar chart // 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