// 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 Segmented Donut chart constructor // RGraph.Segmented = function (conf) { var id = conf.id, canvas = document.getElementById(id), min = conf.min || 0, max = conf.max, value = conf.value; // id, min, max, value // Get the canvas and context objects 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 = 'segmented'; this.min = RGraph.stringsToNumbers(min); this.max = RGraph.stringsToNumbers(max); this.value = RGraph.stringsToNumbers(value); this.centerx = null; this.centery = null; this.radius = null; 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 // // If the value is zero set it to very // slightly more than zero so the meter // is drawn correctly. // // Likewise with the maximum value // if (this.value <= 0.0000001) { this.value = 0.0000001; } // Various config type stuff this.properties = { radius: null, centerx: null, centery: null, width: null, marginLeft: 15, marginRight: 15, marginTop: 15, marginBottom: 15, backgroundColor: 'black', colors: ['red','#ddd'], textFont: 'Arial, Verdana, sans-serif', textSize: null, textColor: 'gray', textBold: false, textItalic: false, textAccessible: false, textAccessibleOverflow: 'visible', textAccessiblePointerevents: false, text: null, labelsCenterFont: null, labelsCenterSize: null, labelsCenterColor: null, labelsCenterBold: null, labelsCenterItalic: null, labelsCenterUnitsPre: '', labelsCenterUnitsPost: '', labelsCenterDecimals: 0, labelsCenterPoint: '.', labelsCenterThousand: ',', labelsCenterSpecific: '', labelsCenterSpecificFormattedDecimals: 0, labelsCenterSpecificFormattedPoint: '.', labelsCenterSpecificFormattedThousand: ',', labelsCenterSpecificFormattedUnitsPre: '', labelsCenterSpecificFormattedUnitsPost: '', labelsCenterOffsetx: 0, labelsCenterOffsety: 0, radialsCount: 36, contextmenu: null, annotatable: false, annotatableColor: 'black', annotatableLinewidth: 1, adjustable: false, effectRoundrobinMultiplier: 1, 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 = [ 'radius', 'centerx', 'centery', 'width', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom', 'textSize', 'labelsCenterSize', 'labelsCenterOffsetx', 'labelsCenterOffsety', 'annotatableLinewidth', ]; // // 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('[SDONUT] 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 setter // 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' ) { 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 getter // // @param name string 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]; }; // // The function you call to draw 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