// o---------------------------------------------------------------------------------o // | This file is part of the RGraph package - you can learn more at: | // | | // | https://www.rgraph.net/license.html | // | | // | RGraph is dual-licensed under the Open Source GPL license. That means that it's | // | free to use and there are no restrictions on what you can use RGraph for! | // | If the GPL license does not suit you however, then there's an inexpensive | // | commercial license option available. See the URL above for more details. | // o---------------------------------------------------------------------------------o RGraph = window.RGraph || {isrgraph:true,isRGraph:true,rgraph:true}; RGraph.SVG = RGraph.SVG || {}; // Module pattern (function (win, doc, undefined) { RGraph.SVG.Funnel = function (conf) { // // A setter that the constructor uses (at the end) // to set all of the properties // // @param string name The name of the property to set // @param string value The value to set the property to // this.set = function (name, value) { if (arguments.length === 1 && typeof name === 'object') { for (i in arguments[0]) { if (typeof i === 'string') { name = ret.name; value = ret.value; this.set(name, value); } } } else { // Go through all of the properties and make sure // that they're using the correct capitalisation name = this.properties_lowercase_map[name.toLowerCase()] || name; var ret = RGraph.SVG.commonSetter({ object: this, name: name, value: value }); name = ret.name; value = ret.value; this.properties[name] = value; // If setting the colors, update the originalColors // property too if (name === 'colors') { this.originalColors = RGraph.SVG.arrayClone(value); this.colorsParsed = false; } } 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 this.properties[name]; }; // Convert strings to numbers conf.data = RGraph.SVG.stringsToNumbers(conf.data); //if (typeof conf.data === 'string') { // conf.data = conf.data.split(/,|\|/); //} //for (var i=0; i', this.svgAllGroup); // Draw the chart this.drawFunnel(); // Draw the background bars this.drawBackgroundBars(); // Draw the labels this.drawLabels(); // Draw the title and subtitle RGraph.SVG.drawTitle(this); // Draw the key if (typeof properties.key !== null && RGraph.SVG.drawKey) { RGraph.SVG.drawKey(this); } else if (!RGraph.SVG.isNull(properties.key)) { alert('The drawKey() function does not exist - have you forgotten to include the key library?'); } // Create the shadow definition if needed //if (properties.shadow) { // RGraph.SVG.setShadow({ // object: this, // offsetx: properties.shadowOffsetx, // offsety: properties.shadowOffsety, // blur: properties.shadowBlur, // color: properties.shadowColor, // id: 'dropShadow' // }); //} // Add the event listener that clears the highlight if // there is any. Must be MOUSEDOWN (ie before the click event) var obj = this; document.body.addEventListener('mousedown', function (e) { obj.hideHighlight(obj); }, false); // // Allow the addition of custom text via the // text: property. // RGraph.SVG.addCustomText(this); // // Fire the onfirstdraw event // if (this.firstDraw) { this.firstDraw = false; RGraph.SVG.fireCustomEvent(this, 'onfirstdraw'); } // Fire the draw event RGraph.SVG.fireCustomEvent(this, 'ondraw'); // // Install any inline responsive configuration. This // should be last in the draw function - even after // the draw events. // RGraph.SVG.installInlineResponsive(this); return this; }; // // New create() shortcut function // For example: // this.create('rect,x:0,y:0,width:100,height:100'[,parent]); // // @param str string The tag definition to parse and create // @param object The (optional) parent element // @return object The new tag // this.create = function (str) { var def = RGraph.SVG.create.parseStr(this, str); def.svg = this.svg; // By default the parent is the SVG tag - but if // requested then change it to the tag that has // been given if (arguments[1]) { def.parent = arguments[1]; } return RGraph.SVG.create(def); }; // // Draws the radar. // //@param opt object Options for the function (if any) // this.drawFunnel = function (opt) { // This is the center of the Funnel ONLY - not the whole chart var centerx = properties.marginLeft + (this.graphWidth / 2); // This first loop calculates the coordinates only - it DOES NOT // draw the Funnel on to the scene for (var i=0; i<(this.data.length - 1); ++i) { var value = this.data[i], nextValue = this.data[i+1], maxWidth = this.graphWidth, width = (value / this.max) * this.graphWidth, height = this.graphHeight / (this.data.length - 1), // The heights are equal nextWidth = (nextValue / this.max) * this.graphWidth, nextHeight = height; // The coordinates var x1 = centerx - (width / 2), y1 = properties.marginTop + (height * i), x2 = centerx + (width / 2), y2 = properties.marginTop + (height * i); x3 = centerx + (nextWidth / 2), y3 = properties.marginTop + (height * (i+1)), x4 = centerx - (nextWidth / 2), y4 = properties.marginTop + (height * (i+1)); // Store the coords this.coords.push({ x1: x1, y1: y1, x2: x2, y2: y2, x3: x3, y3: y3, x4: x4, y4: y4, widthTop: x2 - x1, widthBottom: x3 - x4, height: y3 - y2, object: this }); } // Now go thru the coods and draw the shapes for (var i=0,len=this.coords.length,sequentialIndex=0; i