// 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.Line = function (conf) { var id = conf.id, canvas = document.getElementById(id), data = conf.data; this.id = id; this.canvas = canvas; this.context = this.canvas.getContext('2d'); this.canvas.__object__ = this; this.type = 'line'; this.max = 0; this.coords = []; this.coords2 = []; this.coords.key = []; this.coordsText = []; this.coordsSpline = []; this.coordsAxes = {xaxis: [], yaxis: []}; this.coordsTrendline = []; this.hasnegativevalues = false; this.isRGraph = true; this.isrgraph = true; this.rgraph = true; this.uid = RGraph.createUID(); this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.createUID(); this.colorsParsed = false; this.original_colors = []; this.firstDraw = true; // After the first draw this will be false this.stopAnimationRequested = false;// Used to control the animations this.growEffectMultiplier = 1; // Used by the Grow effect // Configuration default values this.properties = { backgroundBarsCount: null, backgroundBarsColor1: 'transparent', backgroundBarsColor2: 'transparent', backgroundGrid: true, backgroundGridLinewidth: 1, backgroundGridHsize: 25, backgroundGridVsize: 25, backgroundGridColor: '#eee', backgroundGridVlines: false, backgroundGridHlines: true, backgroundGridBorder: false, backgroundGridAutofit: true, backgroundGridAutofitAlign: true, backgroundGridHlinesCount: 5, backgroundGridVlinesCount: null, backgroundGridDashed: false, backgroundGridDotted: false, backgroundGridDashArray: null, backgroundHbars: null, backgroundImage: null, backgroundImageStretch: true, backgroundImageX: null, backgroundImageY: null, backgroundImageW: null, backgroundImageH: null, backgroundImageAlign: null, backgroundColor: null, backgroundBorder: false, backgroundBorderLinewidth: 1, backgroundBorderColor: '#aaa', backgroundBorderDashed: false, backgroundBorderDotted: false, backgroundBorderDashArray: null, xaxis: false, xaxisLinewidth: 1, xaxisColor: 'black', xaxisTickmarks: true, xaxisTickmarksLength: 3, xaxisTickmarksLastLeft: null, xaxisTickmarksLastRight: null, xaxisTickmarksCount: null, xaxisLabels: null, xaxisLabelsFormattedDecimals: 0, xaxisLabelsFormattedPoint: '.', xaxisLabelsFormattedThousand: ',', xaxisLabelsFormattedUnitsPre: '', xaxisLabelsFormattedUnitsPost: '', xaxisLabelsSize: null, xaxisLabelsFont: null, xaxisLabelsItalic: null, xaxisLabelsBold: null, xaxisLabelsColor: null, xaxisLabelsOffsetx: 0, xaxisLabelsOffsety: 0, xaxisLabelsHalign: null, xaxisLabelsValign: null, xaxisLabelsPosition: 'edge', xaxisLabelsSpecificAlign:'left', xaxisPosition: 'bottom', xaxisLabelsAngle: 0, xaxisTitle: '', xaxisTitleBold: null, xaxisTitleSize: null, xaxisTitleFont: null, xaxisTitleColor: null, xaxisTitleItalic: null, xaxisTitlePos: null, xaxisTitleOffsetx: 0, xaxisTitleOffsety: 0, xaxisTitleX: null, xaxisTitleY: null, xaxisTitleHalign: 'center', xaxisTitleValign: 'top', yaxis: false, yaxisLinewidth: 1, yaxisColor: 'black', yaxisTickmarks: true, yaxisTickmarksCount: null, yaxisTickmarksLastTop: null, yaxisTickmarksLastBottom: null, yaxisTickmarksLength: 3, yaxisScale: true, yaxisScaleMin: 0, yaxisScaleMax: null, yaxisScaleUnitsPre: '', yaxisScaleUnitsPost: '', yaxisScaleDecimals: 0, yaxisScalePoint: '.', yaxisScaleThousand: ',', yaxisScaleRound: false, yaxisScaleFormatter: null, yaxisScaleInvert: false, yaxisLabelsSpecific: null, yaxisLabelsCount: 5, yaxisLabelsOffsetx: 0, yaxisLabelsOffsety: 0, yaxisLabelsHalign: null, yaxisLabelsValign: null, yaxisLabelsFont: null, yaxisLabelsSize: null, yaxisLabelsColor: null, yaxisLabelsBold: null, yaxisLabelsItalic: null, yaxisLabelsPosition: 'edge', yaxisPosition: 'left', yaxisTitle: '', yaxisTitleBold: null, yaxisTitleSize: null, yaxisTitleFont: null, yaxisTitleColor: null, yaxisTitleItalic: null, yaxisTitlePos: null, yaxisTitleX: null, yaxisTitleY: null, yaxisTitleOffsetx: 0, yaxisTitleOffsety: 0, yaxisTitleHalign: null, yaxisTitleValign: null, yaxisTitleAccessible: null, labelsAbove: false, labelsAboveDecimals: 0, labelsAboveSize: null, labelsAboveColor: null, labelsAboveFont: null, labelsAboveBold: null, labelsAboveItalic: null, labelsAboveBackground: 'rgba(255,255,255,0.7)', labelsAboveBorder: false, labelsAboveUnitsPre: '', labelsAboveUnitsPost: '', labelsAboveSpecific: null, labelsAboveOffsetx: 0, labelsAboveOffsety: 0, labelsAboveFormatter: null, linewidth: 3.001, linecap: 'round', linejoin: 'round', colors: RGraph.getColors(), tickmarksStyle: 'none', tickmarksLinewidth: null, tickmarksSize: 3, tickmarksColor: null, tickmarksStyleDotStroke: 'white', tickmarksStyleDotFill: null, tickmarksStyleDotLinewidth: 3, tickmarksStyleImage: null, tickmarksStyleImageHalign: 'center', tickmarksStyleImageValign: 'center', tickmarksStyleImageOffsetx: 0, tickmarksStyleImageOffsety: 0, marginLeft: 35, marginRight: 35, marginTop: 35, marginBottom: 35, marginInner: 0, filledColors: null, textBold: false, textItalic: false, textSize: 12, textColor: 'black', textFont: "Arial, Verdana, sans-serif", textAccessible: false, textAccessibleOverflow: 'visible', textAccessiblePointerevents:false, text: null, title: '', titleFont: null, titleSize: null, titleColor: null, titleBold: true, titleItalic: null, titleX: null, titleY: null, titleHalign: null, titleValign: null, titleOffsetx: 0, titleOffsety: 0, titleSubtitle: '', titleSubtitleSize: null, titleSubtitleColor: '#aaa', titleSubtitleFont: null, titleSubtitleBold: null, titleSubtitleItalic: null, titleSubtitleOffsetx: 0, titleSubtitleOffsety: 0, shadow: false, shadowOffsetx: 2, shadowOffsety: 2, shadowBlur: 3, shadowColor: 'rgba(128,128,128,0.5)', tooltips: null, tooltipsHotspotXonly: false, tooltipsHotspotSize: 5, tooltipsHotspotIgnore: null, tooltipsEffect: 'slide', tooltipsCssClass: 'RGraph_tooltip', tooltipsCss: null, tooltipsEvent: 'onmousemove', tooltipsHighlight: true, tooltipsPersistent: false, tooltipsCoordsPage: false, tooltipsFormattedThousand: ',', tooltipsFormattedPoint: '.', tooltipsFormattedDecimals: 0, tooltipsFormattedUnitsPre: '', tooltipsFormattedUnitsPost: '', tooltipsFormattedKeyColors: null, tooltipsFormattedKeyColorsShape: 'square', tooltipsFormattedKeyLabels: [], tooltipsFormattedListType: 'ul', tooltipsFormattedListItems: null, tooltipsFormattedTableHeaders: null, tooltipsFormattedTableData: null, tooltipsDataset: null, tooltipsDatasetEvent: 'click', tooltipsPointer: true, tooltipsPointerOffsetx: 0, tooltipsPointerOffsety: 0, tooltipsPositionStatic: true, highlightStyle: null, highlightStroke: 'gray', highlightFill: 'rgba(255,255,255,0.5)', highlightPointRadius: 2, highlightFade: true, highlightDataset: false, highlightDatasetStroke: 'rgba(0,0,0,0.25)', highlightDatasetFill: 'rgba(255,255,255,0.75)', highlightDatasetLinewidth: 10, highlightDatasetStrokeAlpha: 1, highlightDatasetFillAlpha: 1, highlightDatasetFillUseColors: false, highlightDatasetStrokeUseColors: false, highlightDatasetDotted: false, highlightDatasetDashed: false, highlightDatasetDashArray: null, highlightDatasetExclude: null, highlightDatasetCallback: null, highlightDatasetEvent: 'click', stepped: false, key: null, keyBackground: 'white', keyPosition: 'graph', keyHalign: null, 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(255,0,0,0.3)', keyInteractiveHighlightLabel: 'rgba(255,0,0,0.2)', keyLabelsFont: null, keyLabelsSize: null, keyLabelsColor: null, keyLabelsBold: null, keyLabelsItalic: null, keyLabelsOffsetx: 0, keyLabelsOffsety: 0, keyFormattedDecimals: 0, keyFormattedPoint: '.', keyFormattedThousand: ',', keyFormattedUnitsPre: '', keyFormattedUnitsPost: '', keyFormattedValueSpecific: null, keyFormattedItemsCount: null, contextmenu: null, crosshairs: false, crosshairsColor: '#333', crosshairsLinewidth: 1, crosshairsHline: true, crosshairsVline: true, crosshairsSnapToScale: false, annotatable: false, annotatableColor: 'black', annotatableLinewidth: 1, filled: false, filledRange: false, filledRangeThreshold: null, filledRangeThresholdColors: ['red', 'green'], filledAccumulative: true, variant: null, axesAbove: false, backdrop: false, backdropSize: 30, backdropAlpha: 0.2, adjustable: false, adjustableOnly: null, adjustableXonly: false, redraw: true, outofbounds: false, outofboundsClip: false, animationFactor: 1, animationUnfoldX: false, animationUnfoldY: true, animationUnfoldInitial: 2, animationTraceClip: 1, animationTraceCenter: false, spline: false, lineVisible: [], errorbars: false, errorbarsColor: 'black', errorbarsCapped: true, errorbarsCappedWidth: 12, errorbarsLinewidth: 1, combinedEffect: null, combinedEffectOptions: null, combinedEffectCallback: null, clearto: 'transparent', dotted: false, dashed: false, trendline: false, trendlineColors: ['#666'], trendlineLinewidth: 1, trendlineMargin: 25, trendlineDashed: false, trendlineDotted: false, trendlineDashArray: null, trendlineClip: true, nullBridge: false, nullBridgeLinewidth: null, nullBridgeColors: null, // Can be null, a string or an object nullBridgeDashArray: [5,5], labelsAngled: false, labelsAngledSpecific: null, labelsAngledAccessible: null, labelsAngledFont: null, labelsAngledColor: null, labelsAngledSize: null, labelsAngledBold: null, labelsAngledItalic: null, labelsAngledUpFont: null, labelsAngledUpColor: null, labelsAngledUpSize: null, labelsAngledUpBold: null, labelsAngledUpItalic: null, labelsAngledDownFont: null, labelsAngledDownColor: null, labelsAngledDownSize: null, labelsAngledDownBold: null, labelsAngledDownItalic: null, labelsAngledLevelFont: null, labelsAngledLevelColor: null, labelsAngledLevelSize: null, labelsAngledLevelBold: null, labelsAngledILeveltalic:null, lines: null, // Used to show an average line indicator (for example) 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 = [ 'backgroundGridLinewidth', 'backgroundGridHsize', 'backgroundGridVsize', 'backgroundGridDashArray', 'backgroundImageX', 'backgroundImageY', 'backgroundImageW', 'backgroundImageH', 'backgroundBorderLinewidth', 'backgroundBorderDashArray', 'xaxisLinewidth', 'xaxisTickmarksLength', 'xaxisLabelsSize', 'xaxisLabelsOffsetx', 'xaxisLabelsOffsety', 'xaxisTitleSize', 'xaxisTitleOffsetx', 'xaxisTitleOffsety', 'xaxisTitleX', 'xaxisTitleY', 'yaxisLinewidth', 'yaxisTickmarksLength', 'yaxisLabelsOffsetx', 'yaxisLabelsOffsety', 'yaxisLabelsSize', 'yaxisTitleSize', 'yaxisTitleX', 'yaxisTitleY', 'yaxisTitleOffsetx', 'yaxisTitleOffsety', 'labelsAboveSize', 'labelsAboveOffsetx', 'labelsAboveOffsety', 'linewidth', 'tickmarksLinewidth', 'tickmarksSize', 'tickmarksStyleDotLinewidth', 'tickmarksStyleImageOffsetx', 'tickmarksStyleImageOffsety', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom', 'marginInner', 'textSize', 'titleSize', 'titleX', 'titleY', 'titleOffsetx', 'titleOffsety', 'titleSubtitleSize', 'titleSubtitleOffsetx', 'titleSubtitleOffsety', 'shadowOffsetx', 'shadowOffsety', 'shadowBlur', 'tooltipsHotspotSize', 'highlightPointRadius', 'highlightDatasetLinewidth', 'keyShadowBlur', 'keyShadowOffsetx', 'keyShadowOffsety', 'keyPositionMarginHSpace', 'keyPositionX', 'keyPositionY', 'keyLinewidth', 'keyLabelsSize', 'crosshairsLinewidth', 'annotatableLinewidth', 'backdropSize', 'errorbarsCappedWidth', 'errorbarsLinewidth', 'trendlineLinewidth', 'trendlineMargin', 'trendlineDashArray', 'nullBridgeLinewidth', 'nullBridgeDashArray', 'labelsAngledSize', 'labelsAngledUpSize', 'labelsAngledDownSize', 'labelsAngledLevelSize' ]; // // 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; } } // Convert strings to numbers this.original_data = RGraph.stringsToNumbers(conf.data); // // Store the original data. This also allows for giving arguments as one big array. // if (typeof this.original_data[0] === 'number' || RGraph.isNullish(this.original_data[0])) { this.original_data = [RGraph.arrayClone(this.original_data)]; } // Some of the animations actually modify the // .original_data array so we need to keep a // copy of the unmodified, unmodified data. this // variable is used to access that data in those // effects (eg the wave effect). this.unmodified_data = RGraph.arrayClone(this.original_data); // Check for support if (!this.canvas) { alert('[LINE] Fatal error: no canvas support'); return; } // // Store the data here as one big array // this.data_arr = RGraph.arrayLinearize(this.original_data); for (var i=0; i { // Note that were 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