// 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 chart constructor. This function sets up the object. It takes the ID (the HTML attribute) of the canvas as the // first argument and the data as the second. If you need to change this, you can. // RGraph.Thermometer = function (conf) { this.id = conf.id; this.canvas = document.getElementById(this.id); this.context = this.canvas.getContext ? this.canvas.getContext('2d') : null; this.canvas.__object__ = this; this.uid = RGraph.createUID(); this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.createUID(); this.colorsParsed = false; this.type = 'thermometer'; this.isRGraph = true; this.isrgraph = true; this.rgraph = true; this.min = RGraph.stringsToNumbers(conf.min); this.max = RGraph.stringsToNumbers(conf.max); this.value = RGraph.stringsToNumbers(conf.value); this.graphArea = []; this.currentValue = null; 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 = { linewidth: 1, backgroundColor: 'white', colorsStroke: '#666', colors: RGraph.getColors(), marginLeft: 35, marginRight: 35, marginTop: 35, marginBottom: 35, tickmarksSize: 2, tickmarksCount: 0, textColor: 'black', textFont: 'Arial, Verdana, sans-serif', textSize: 12, textBold: false, textItalic: false, textAccessible: false, textAccessibleOverflow: 'visible', textAccessiblePointerevents:false, text: null, scaleVisible: false, scaleUnitsPre: '', scaleUnitsPost: '', scaleDecimals: 0, scaleThousand: ',', scalePoint: '.', title: '', titleFont: null, titleSize: null, titleColor: null, titleBold: true, titleItalic: 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: '', titleSideBold: null, titleSideFont: null, titleSideSize: null, titleSideColor: null, titleSideItalic: null, titleSideOffsetx: 0, titleSideOffsety: 0, shadow: false, shadowOffsetx: 0, shadowOffsety: 0, shadowBlur: 15, shadowColor: '#ddd', contextmenu: null, adjustable: false, labelsValue: true, labelsValueColor: null, labelsValueFont: null, labelsValueSize: null, labelsValueBold: null, labelsValueItalic: null, labelsValueDecimals: null, labelsValueThousand: null, labelsValuePoint: null, labelsValueUnitsPre: null, labelsValueUnitsPost: null, labelsValueOffsetx: 0, labelsValueOffsety: 0, labelsCount: 5, labelsDecimals: null, labelsUnitsPre: null, labelsUnitsPost: null, labelsPoint: null, labelsThousand: null, labelsColor: null, labelsFont: null, labelsSize: null, labelsBold: null, labelsItalic: null, labelsOffsetx: 0, labelsOffsety: 0, annotatable: false, annotatableColor: 'black', annotatableLinewidth: 1, tooltips: null, tooltipsHighlight: true, tooltipsEffect: 'slide', tooltipsEvent: 'click', tooltipsCssClass: 'RGraph_tooltip', tooltipsCss: null, tooltipsPersistent: false, 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, highlightStroke: 'transparent', highlightFill: 'rgba(255,255,255,0.7)', highlightFade: true, clearto: 'transparent', bulbBottomRadiusAdjust: 0, bulbBottomRadius: null, 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 = [ 'linewidth', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom', 'marginInner', 'shadowBlur', 'shadowOffsetx', 'shadowOffsety', 'titleSize', 'titleOffsetx', 'titleOffsety', 'titleSubtitleSize', 'titleSubtitleOffsetx', 'titleSubtitleOffsety', 'titleSideSize', 'titleSideOffsetx', 'titleSideOffsety', 'textSize', 'highlightLinewidth', 'labelsInnerSize', 'labelsInnerBorderLinewidth', 'labelsInnerOffsetx', 'labelsInnerOffsety', 'labelsOffsetx', 'labelsOffsety', 'labelsSize', 'labelsValueSize', 'labelsValueOffsetx', 'labelsValueOffsety', 'keyShadowBlur', 'keyShadowOffsetx', 'keyShadowOffsety', 'keyPositionX', 'keyPositionY', 'keyLinewidth', 'keyInteractiveHighlightChartLinewidth', '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; } } // // A simple check that the browser has canvas support // if (!this.canvas) { alert('[THERMOMETER] No canvas support'); return; } // // The thermometer can only have one data point so only this.$0 needs to be created // this.$0 = {}; // 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') { 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]; }; // // Draws the thermometer // 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 custom RGraph onbeforedraw event (which should be fired before the chart is drawn) 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