// 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 pie chart constructor // RGraph.Pie = function (conf) { var id = conf.id, canvas = document.getElementById(id), data = conf.data; // 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.total = 0; this.subTotal = 0; this.angles = []; this.data = data; this.originalData = RGraph.arrayClone(data); this.properties = []; this.type = 'pie'; this.isRGraph = true; this.isrgraph = true; this.rgraph = true; this.coords = []; this.coords.key = []; this.coordsSticks = []; this.coordsText = []; 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.exploding = null; this.stopAnimationRequested = false;// Used to control the animations this.waveRadiusMultiplier = RGraph.arrayFill([], this.data.length, 1); // // Convert strings to numbers // this.data = RGraph.stringsToNumbers(this.data); this.properties = { centerxAdjust: 0, centeryAdjust: 0, colors: RGraph.getColors(), colorsStroke: 'transparent', linewidth: 3, labels: [], labelsFormattedDecimals: 0, labelsFormattedPoint: '.', labelsFormattedThousand: ',', labelsFormattedUnitsPre: '', labelsFormattedUnitsPost: '', labelsFont: null, labelsSize: null, labelsColor: null, labelsBold: null, labelsItalic: null, labelsRadiusOffset: 0, labelsSticks: false, labelsSticksLength: 7, labelsSticksColors: null, labelsSticksLinewidth: 1, labelsSticksHlength: 5, labelsList: true, labelsListLeftOffsetx: 0, labelsListLeftOffsety: 0, labelsListRightOffsetx: 0, labelsListRightOffsety: 0, labelsListSticksAngled: false, labelsListSticksOffset: 30, labelsIngraph: null, labelsIngraphColor: null, labelsIngraphFont: null, labelsIngraphSize: null, labelsIngraphBold: null, labelsIngraphItalic: null, labelsIngraphBounding: true, labelsIngraphBoundingFill: 'white', labelsIngraphBoundingStroke: 'transparent', labelsIngraphSpecific: null, labelsIngraphSpecificFormattedDecimals: 0, labelsIngraphSpecificFormattedPoint: '.', labelsIngraphSpecificFormattedThousand: ',', labelsIngraphSpecificFormattedUnitsPre: '', labelsIngraphSpecificFormattedUnitsPost: '', labelsIngraphUnitsPre: '', labelsIngraphUnitsPost: '', labelsIngraphPoint: '.', labelsIngraphThousand: ',', labelsIngraphDecimals: 0, labelsIngraphRadius: null, labelsIngraphRadiusOffset: 0, labelsIngraphUndrawn: null, labelsIngraphUndrawnAsLabels: null, labelsIngraphUndrawnAlwaysShow: false, labelsCenter: null, labelsCenterSize: 26, labelsCenterFont: null, labelsCenterColor: null, labelsCenterItalic: null, labelsCenterBold: null, labelsCenterOffsetx: 0, labelsCenterOffsety: 0, labelsInside: null, labelsInsideColor: null, labelsInsideSize: null, labelsInsideFont: null, labelsInsideBold: null, labelsInsideItalic: null, labelsInsideDecimals: 0, labelsInsidePoint: '.', labelsInsideThousand: ',', labelsInsideUnitsPre: '', labelsInsideUnitsPost: '', labelsInsideOffsetr: 0, labelsInsideHalign: 'auto', labelsInsideBounding: false, labelsInsideBoundingFill: 'rgba(255,255,255,0.75)', labelsInsideBoundingStroke: 'transparent', labelsInsideSpecific: null, labelsInsideSpecificFormattedDecimals: 0, labelsInsideSpecificFormattedPoint: '.', labelsInsideSpecificFormattedThousand: ',', labelsInsideSpecificFormattedUnitsPre: '', labelsInsideSpecificFormattedUnitsPost: '', marginLeft: 35, marginRight: 35, marginTop: 35, marginBottom: 35, title: '', titleBold: true, titleFont: null, titleSize: null, titleColor: null, 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, shadowColor: '#aaa', shadowOffsetx: 0, shadowOffsety: 0, shadowBlur: 15, textBold: false, textItalic: false, textSize: 12, textColor: 'black', textFont: 'Arial, Verdana, sans-serif', textAccessible: false, textAccessibleOverflow: 'visible', textAccessiblePointerevents: false, text: null, contextmenu: null, tooltips: [], tooltipsEvent: 'onclick', tooltipsEffect: 'slide', tooltipsCssClass: 'RGraph_tooltip', tooltipsCss: null, tooltipsHighlight: true, 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, highlightStyle: '2d', highlightStyleTwodFill: 'rgba(255,255,255,0.7)', highlightStyleTwodStroke: 'transparent', highlightStyleTwodLinewidth: 2, highlightStyleOutlineWidth: null, highlightFade: true, centerx: null, centery: null, radius: null, border: false, borderColor: 'rgba(255,255,255,0.5)', key: null, keyBackground: 'white', keyPosition: 'graph', keyHalign: 'right', keyValign: null, keyShadow: false, keyShadowColor: '#666', keyShadowBlur: 3, keyShadowOffsetx: 2, keyShadowOffsety: 2, keyPositionGutterBoxed: false, keyPositionMarginHSpace: 10, keyPositionX: null, keyPositionY: null, keyColorShape: 'square', keyRounded: true, keyLinewidth: 1, keyColors: null, keyInteractive: false, keyInteractiveHighlightChartLinewidth: 2, keyInteractiveHighlightChartStroke: 'black', 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, annotatable: false, annotatableColor: 'black', annotatableLinewidth: 1, variant: 'pie', variantDonutWidth: null, variantThreedDepth: 20, exploded: [], effectRoundrobinMultiplier: 1, centerpin: null, centerpinFill: 'gray', centerpinStroke: 'white', origin: 0 - (Math.PI / 2), clearto: 'transparent', eventsEnabled: true, clip: null, responsive: null, events: {}, clip: 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 = [ 'centerxAdjust', 'centeryAdjust', 'linewidth', 'labelsSize', 'labelsRadiusOffset', 'labelsSticksLength', 'labelsSticksLinewidth', 'labelsSticksHlength', 'labelsListLeftOffsetx', 'labelsListLeftOffsety', 'labelsListRightOffsetx', 'labelsListRightOffsety', 'labelsListSticksOffset', 'labelsIngraphSize', 'labelsIngraphRadius', 'labelsIngraphRadiusOffset', 'labelsIngraphUndrawn', 'labelsIngraphUndrawnAsLabels', 'labelsIngraphUndrawnAlwaysShow', 'labelsCenterSize', 'labelsCenterOffsetx', 'labelsCenterOffsety', 'labelsInsideSize', 'labelsInsideOffsetr', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom', 'titleSize', 'titleX', 'titleY', 'titleOffsetx', 'titleOffsety', 'titleSubtitleSize', 'titleSubtitleOffsetx', 'titleSubtitleOffsety', 'shadowOffsetx', 'shadowOffsety', 'shadowBlur', 'textSize', 'highlightStyleTwodLinewidth', 'highlightStyleOutlineWidth', 'centerx', 'centery', 'radius', 'keyShadowBlur', 'keyShadowOffsetx', 'keyShadowOffsety', 'keyPositionX', 'keyPositionY', 'keyPositionMarginHSpace', 'keyLinewidth', 'keyInteractiveHighlightChartLinewidth', 'keyLabelsSize', 'keyLabelsOffsetx', 'keyLabelsOffsety', 'variantDonutWidth', 'variantThreedDepth', 'exploded' ]; // // 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; } } // // Calculate the total // for (var i=0,len=data.length; i { // 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