// version: 2017-11-25 /** * o--------------------------------------------------------------------------------o * | This file is part of the RGraph package - you can learn more at: | * | | * | http://www.rgraph.net | * | | * | RGraph is licensed under the Open Source MIT license. That means that it's | * | totally free to use and there are no restrictions on what you can do with it! | * o--------------------------------------------------------------------------------o */ RGraph = window.RGraph || {isRGraph: true}; /** * The bar chart constructor * * @param object canvas The canvas object * @param array data The chart data */ RGraph.Funnel = function (conf) { /** * Allow for object config style */ if ( typeof conf === 'object' && typeof conf.data === 'object' && typeof conf.id === 'string') { var id = conf.id var canvas = document.getElementById(id); var data = conf.data; var parseConfObjectForOptions = true; // Set this so the config is parsed (at the end of the constructor) } else { var id = conf; var canvas = document.getElementById(id); var data = arguments[1]; } 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 = 'funnel'; this.coords = []; this.isRGraph = true; this.uid = RGraph.CreateUID(); this.canvas.uid = this.canvas.uid ? this.canvas.uid : RGraph.CreateUID(); this.coordsText = []; this.original_colors = []; this.firstDraw = true; // After the first draw this will be false // Check for support if (!this.canvas) { alert('[FUNNEL] No canvas support'); return; } /** * The funnel charts properties */ this.properties = { 'chart.strokestyle': 'rgba(0,0,0,0)', 'chart.gutter.left': 25, 'chart.gutter.right': 25, 'chart.gutter.top': 25, 'chart.gutter.bottom': 25, 'chart.labels': null, 'chart.labels.sticks': false, 'chart.labels.x': null, 'chart.title': '', 'chart.title.background': null, 'chart.title.hpos': null, 'chart.title.vpos': null, 'chart.title.bold': true, 'chart.title.font': null, 'chart.title.x': null, 'chart.title.y': null, 'chart.title.halign': null, 'chart.title.valign': null, 'chart.colors': [ 'Gradient(white:red)', 'Gradient(white:green)', 'Gradient(white:gray)', 'Gradient(white:blue)', 'Gradient(white:black)', 'Gradient(white:gray)', 'Gradient(white:pink)', 'Gradient(white:blue)', 'Gradient(white:yellow)', 'Gradient(white:green)', 'Gradient(white:red)' ], 'chart.text.size': 12, 'chart.text.boxed': true, 'chart.text.halign': 'left', 'chart.text.color': 'black', 'chart.text.font': 'Segoe UI, Arial, Verdana, sans-serif', 'chart.text.accessible': true, 'chart.text.accessible.overflow': 'visible', 'chart.text.accessible.pointerevents': true, 'chart.contextmenu': null, 'chart.shadow': false, 'chart.shadow.color': '#666', 'chart.shadow.blur': 3, 'chart.shadow.offsetx': 3, 'chart.shadow.offsety': 3, 'chart.key': null, 'chart.key.background': 'white', 'chart.key.position': 'graph', 'chart.key.halign': 'right', 'chart.key.shadow': false, 'chart.key.shadow.color': '#666', 'chart.key.shadow.blur': 3, 'chart.key.shadow.offsetx': 2, 'chart.key.shadow.offsety': 2, 'chart.key.position.gutter.boxed': false, 'chart.key.position.x': null, 'chart.key.position.y': null, 'chart.key.color.shape': 'square', 'chart.key.rounded': true, 'chart.key.linewidth': 1, 'chart.key.colors': null, 'chart.key.interactive': false, 'chart.key.interactive.highlight.chart.stroke': 'black', 'chart.key.interactive.highlight.chart.fill': 'rgba(255,255,255,0.7)', 'chart.key.interactive.highlight.label': 'rgba(255,0,0,0.2)', 'chart.key.text.color': 'black', 'chart.tooltips': null, 'chart.tooltips.effect': 'fade', 'chart.tooltips.css.class': 'RGraph_tooltip', 'chart.tooltips.event': 'onclick', 'chart.highlight.stroke': 'rgba(0,0,0,0)', 'chart.highlight.fill': 'rgba(255,255,255,0.7)', 'chart.tooltips.highlight': true, 'chart.annotatable': false, 'chart.annotate.color': 'black', 'chart.zoom.factor': 1.5, 'chart.zoom.fade.in': true, 'chart.zoom.fade.out': true, 'chart.zoom.factor': 1.5, 'chart.zoom.fade.in': true, 'chart.zoom.fade.out': true, 'chart.zoom.hdir': 'right', 'chart.zoom.vdir': 'down', 'chart.zoom.frames': 25, 'chart.zoom.delay': 16.666, 'chart.zoom.shadow': true, 'chart.zoom.background': true, 'chart.zoom.action': 'zoom', 'chart.resizable': false, 'chart.events.click': null, 'chart.events.mousemove': null, 'chart.clearto': 'rgba(0,0,0,0)' } // Store the data for (var i=0; i 0) { var font = prop['chart.text.font']; var size = prop['chart.text.size']; var color = prop['chart.text.color']; var labels = prop['chart.labels']; var halign = prop['chart.text.halign'] == 'left' ? 'left' : 'center'; var bgcolor = prop['chart.text.boxed'] ? 'white' : null; if (typeof prop['chart.labels.x'] == 'number') { var x = prop['chart.labels.x']; } else { var x = halign == 'left' ? (this.gutterLeft - 15) : ((ca.width - this.gutterLeft - this.gutterRight) / 2) + this.gutterLeft; } for (var j=0; j prop['chart.gutter.left'] && mouseXY[0] < (ca.width - prop['chart.gutter.right']) && mouseXY[1] > prop['chart.gutter.top'] && mouseXY[1] < (ca.height - prop['chart.gutter.bottom']) ) { return this; } }; /** * This function positions a tooltip when it is displayed * * @param obj object The chart object * @param int x The X coordinate specified for the tooltip * @param int y The Y coordinate specified for the tooltip * @param objec tooltip The tooltips DIV element * this.positionTooltip = function (obj, x, y, tooltip, idx) { var coords = obj.coords[tooltip.__index__]; var x1 = coords[0]; var y1 = coords[1]; var x2 = coords[2]; var y2 = coords[3]; var x3 = coords[4]; var y3 = coords[5]; var x4 = coords[6]; var y4 = coords[7]; var coordW = x2 - x1; var coordX = x1 + (coordW / 2); var canvasXY = RG.getCanvasXY(ca); var mouseXY = RG.getMouseXY(window.event); var gutterLeft = prop['chart.gutter.left']; var gutterTop = prop['chart.gutter.top']; var width = tooltip.offsetWidth; var height = tooltip.offsetHeight; // Set the top position tooltip.style.left = 0; tooltip.style.top = window.event.pageY - height - 5 + 'px'; // By default any overflow is hidden tooltip.style.overflow = ''; // Reposition the tooltip if at the edges: // LEFT edge if (canvasXY[0] + mouseXY[0] - (width / 2) < 0) { tooltip.style.left = canvasXY[0] + mouseXY[0] - (width * 0.1) + 'px'; // RIGHT edge } else if (canvasXY[0] + mouseXY[0] + (width / 2) > doc.body.offsetWidth) { tooltip.style.left = canvasXY[0] + mouseXY[0] - (width * 0.9) + 'px'; // Default positioning - CENTERED } else { tooltip.style.left = canvasXY[0] + mouseXY[0] - (width / 2) + 'px'; } };*/ /** * This allows for easy specification of gradients */ this.parseColors = function () { // Save the original colors so that they can be restored when the canvas is reset if (this.original_colors.length === 0) { this.original_colors['chart.colors'] = RG.array_clone(prop['chart.colors']); this.original_colors['chart.key.colors'] = RG.array_clone(prop['chart.key.colors']); this.original_colors['chart.highlight.fill'] = RG.array_clone(prop['chart.highlight.fill']); this.original_colors['chart.highlight.stroke'] = RG.array_clone(prop['chart.highlight.stroke']); this.original_colors['chart.strokestyle'] = RG.array_clone(prop['chart.strokestyle']); } var colors = prop['chart.colors']; for (var i=0; i