// 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 // // This is a library of a few functions that make it easier to do // effects like fade-ins or eaxpansion. // // // Initialise the various objects // RGraph = window.RGraph || {isrgraph:true,isRGraph:true,rgraph:true}; RGraph.SVG = RGraph.SVG || {}; RGraph.SVG.FX = RGraph.SVG.FX || {}; // Module pattern (function (win, doc, undefined) { // // This functions adds the generic effects to thechart object // // @param object obj The chart object // RGraph.SVG.FX.decorate = function (obj) { for (i in RGraph.SVG.FX) { if (typeof RGraph.SVG.FX[i] === 'function') { obj[i] = RGraph.SVG.FX[i]; } } }; // // fadeIn // // This function simply uses the CSS opacity property - initially set to zero and // increasing to 1 over the period of 0.5 second // RGraph.SVG.FX.fadein = function () { // This function gets added to the chart object - so the this // variable is the chart object var obj = this, opt = arguments[0] || {}, frames = opt.frames || 90, duration = (frames / 60) * 1000, frame = 0, callback = opt.callback || function () {}; // Initially the opacity should be zero obj.svg.style.opacity = 0; // Draw the chart RGraph.SVG.redraw(this.svg); // Now fade the chart in for (var i=1; i<=frames; ++i) { (function (index) { setTimeout(function () { obj.svg.style.opacity = (index / frames); if (index >= frames) { callback(obj); } }, (index / frames) * duration); })(i) } return this; }; // // fadeOut // // This function is a reversal of the above function - fading out instead of in // RGraph.SVG.FX.fadeout = function () { // This function gets added to the chart object - so the this // variable is the chart object var obj = this, opt = arguments[0] || {}, frames = opt.frames || 90, duration = (frames / 60) * 1000, frame = 0, callback = opt.callback || function () {}; //RGraph.SVG.redraw() // Now fade the chart out for (var i=1; i<=frames; ++i) { (function (index) { setTimeout(function () { obj.svg.style.opacity = 1 - (index / frames); if (index >= frames) { callback(obj); } }, (index / frames) * duration); })(i) } return this; }; // // fadeSlideIn // // This function fades the canvas in in a sliding motion // RGraph.SVG.FX.fadeslidein = function () { // This function gets added to the chart object - so the this // variable is the chart object var obj = this, opt = arguments[0] || {}, frames = opt.frames || 90, frame = 0, pc = -20, step = (120 - pc) / frames, color = opt.color || 'white', width = this.container.offsetWidth, height = this.container.offsetHeight, callback = opt.callback || function () {}; // Draw the chart RGraph.SVG.redraw(this.svg); // Create the cover jQuery('
').css({ background: 'linear-gradient(135deg, rgba(255,255,255,0) ' + pc + '%, ' + color + ' ' + (pc + 20) + '%)', width: width + 'px', height: height + 'px', top: 0, left: 0, position: 'absolute' }).appendTo(jQuery(this.container)); function iterator () { if (pc < 120) { jQuery('div#rgraph_fadeslide_cover_' + obj.id).css({ background: 'linear-gradient(135deg, rgba(255,255,255,0) ' + pc + '%, ' + color + ' ' + (pc + 20) + '%)' }); pc += step; RGraph.SVG.FX.update(iterator); } else { jQuery('div#rgraph_fadeslide_cover_' + obj.id).remove(); callback(obj); } } iterator(); return this; }; // // fadeSlideOut // // Fades the canvas out in a sliding motion. This function gets added // to the chart object - so the this variable is the chart object // RGraph.SVG.FX.fadeslideout = function () { var obj = this, opt = arguments[0] || {}, frames = opt.frames || 90, frame = 0, pc = -20, step = (120 - pc) / frames, canvasXY = RGraph.SVG.getSVGXY(obj.svg), color = opt.color || 'white', width = this.container.offsetWidth, height = this.container.offsetHeight, callback = opt.callback || function () {}; // Draw the chart //RGraph.SVG.redraw(this.svg); // Create the cover jQuery('
').css({ background: 'linear-gradient(135deg, ' + color + ' ' + pc + '%, rgba(255,255,255,0) ' + (pc + 20) + '%)', width: width + 'px', height: height + 'px', top: 0, left: 0, position: 'absolute' }).appendTo(jQuery(obj.svg.parentNode)); function iterator () { if (pc < 120) { jQuery('div#rgraph_fadeslide_cover_' + obj.id).css({ background: 'linear-gradient(135deg, ' + color + ' ' + pc + '%, rgba(255,255,255,0) ' + (pc + 20) + '%)' }); pc += step; RGraph.SVG.FX.update(iterator); } else { RGraph.SVG.clear(obj.svg); jQuery('div#rgraph_fadeslide_cover_' + obj.id).remove(); callback(obj); } } iterator(); return this; }; // // fadeCircularIn // // This function uses radial CSS gradients to cover the canvas with a radial fade in effect // (from the center outwards) // RGraph.SVG.FX.fadecircularinoutwards = function () { // This function gets added to the chart object - so the 'this' // variable is the chart object var obj = this, opt = arguments[0] || {}, frames = opt.frames || 90, frame = 1, radius = 0, svgXY = RGraph.SVG.getSVGXY(obj.svg), color = opt.color || 'white', callback = opt.callback || function () {}; // Draw the chart RGraph.SVG.redraw(this.svg); // Create the cover jQuery('
').css({ background: 'radial-gradient(rgba(255,255,255,0) 0%, ' + color + ' ' + radius + '%)', width: this.container.offsetWidth + 'px', height: this.container.offsetHeight + 'px', top: 0, left: 0, position: 'absolute' }).appendTo(jQuery(obj.svg.parentNode)); function iterator () { if (frame < frames) { jQuery('div#rgraph_fadecircularinoutwards_cover_' + obj.id).css({ background: 'radial-gradient(rgba(255,255,255,0) ' + ((frame++ / frames) * 100) + '%, ' + color + ' ' + ((frame++ / frames) * 150) + '%)' }); RGraph.SVG.FX.update(iterator); } else { jQuery('div#rgraph_fadecircularinoutwards_cover_' + obj.id).remove(); callback(obj); } } iterator(); return this; }; // // fadecircularoutoutwards // // This function uses radial CSS gradients to cover the canvas with a radial fade out effect // (from the center outwards) // RGraph.SVG.FX.fadecircularoutoutwards = function () { // This function gets added to the chart object - so the this // variable is the chart object var obj = this, opt = arguments[0] || {}, frames = opt.frames || 90, frame = 0, width = this.container.offsetWidth, height = this.container.offsetHeight, canvasXY = RGraph.SVG.getSVGXY(obj.svg), color = opt.color || 'white', callback = opt.callback || function () {}; // Draw the chart //RGraph.SVG.redraw(this.svg); // Create the cover jQuery('
').css({ background: 'radial-gradient(rgba(255,255,255,0) 0%, transparent 0%)', width: width + 'px', height: height + 'px', top: 0, left: 0, position: 'absolute' }).appendTo(jQuery(obj.svg.parentNode)); function iterator () { if (frame < frames) { jQuery('div#rgraph_fadeslide_cover_' + obj.id).css({ background: 'radial-gradient(' + color + ' ' + ((frame++ / frames) * 100) + '%, rgba(255,255,255,0) ' + ((frame++ / frames) * 150) + '%)' }); RGraph.SVG.FX.update(iterator); } else { RGraph.SVG.clear(obj.svg); jQuery('div#rgraph_fadeslide_cover_' + obj.id).remove(); callback(obj); } } iterator(); return this; }; // // fadeCircularInInwards // // This function gets added to the chart object - so the 'this' // variable is the chart object // RGraph.SVG.FX.fadecircularininwards = function () { var obj = this, opt = arguments[0] || {}, frames = opt.frames || 90, frame = 0, radius = Math.max( obj.container.offsetWidth, obj.container.offsetHeight ), color = opt.color || 'white', callback = opt.callback || function () {}; // Draw the chart RGraph.SVG.redraw(this.svg); // Create the cover jQuery('
').css({ background: 'radial-gradient(rgba(255,255,255,0) 100%, rgba(255,255,255,0) 0%)', width: this.container.offsetWidth + 'px', height: this.container.offsetHeight + 'px', top: 0, left: 0, position: 'absolute' }).appendTo(jQuery(obj.svg.parentNode)); function iterator () { if (frame < frames) { jQuery('div#rgraph_fadeslide_cover_' + obj.id).css({ background: 'radial-gradient(' + color + ' ' + (( (frames - frame++) / frames) * 100) + '%, rgba(255,255,255,0) ' + (( (frames - frame++) / frames) * 120) + '%)' }); RGraph.SVG.FX.update(iterator); } else { jQuery('div#rgraph_fadeslide_cover_' + obj.id).remove(); callback(obj); } } iterator(); return this; }; // // fadecircularoutinwards // // This function gets added to the chart object - so the this // variable is the chart object // RGraph.SVG.FX.fadecircularoutinwards = function () { var obj = this, opt = arguments[0] || {}, frames = opt.frames || 90, frame = 0, radius = Math.max( this.container.offsetWidth, this.container.offsetHeight ), color = opt.color || 'white', callback = opt.callback || function () {}; // Draw the chart //RGraph.SVG.redraw(this.svg); // Create the cover jQuery('
').css({ background: 'radial-gradient(rgba(255,255,255,0) 0%, rgba(255,255,255,0) 0%)', width: this.container.offsetWidth + 'px', height: this.container.offsetHeight + 'px', top: 0, left: 0, position: 'absolute' }).appendTo(jQuery(obj.svg.parentNode)); function iterator () { if (frame < frames) { jQuery('div#rgraph_fadeslide_cover_' + obj.id).css({ background: 'radial-gradient(rgba(255,255,255,0) ' + (( (frames - frame++) / frames) * 100) + '%, ' + color + ' ' + (( (frames - frame++) / frames) * 120) + '%)' }); RGraph.SVG.FX.update(iterator); } else { RGraph.SVG.clear(obj.svg); jQuery('div#rgraph_fadeslide_cover_' + obj.id).remove(); callback(obj); } } iterator(); return this; }; // // Reveal // // With this effect the chart is slowly revealed from the centre outwards. This // function gets added to the chart object - so the 'this' variable is the chart // object // // @param object Options for the effect. You can give frames here // @param function An optional callback function // RGraph.SVG.FX.reveal = function () { var obj = this, opt = arguments[0] || {} color = opt.color || 'white', frames = opt.frames || 90, duration = (frames / 60) * 1000, callback = opt.callback || function () {} var divs = [ ['rgraph_reveal_left_' + this.id, 0, 0, this.container.offsetWidth / 2, this.container.offsetHeight], ['rgraph_reveal_right_' + this.id,(this.container.offsetWidth / 2),0,(this.container.offsetWidth / 2),this.container.offsetHeight], ['rgraph_reveal_top_' + this.id,0,0,this.container.offsetWidth,(this.container.offsetHeight / 2)], ['rgraph_reveal_bottom_' + this.id,0,(this.container.offsetHeight / 2),this.container.offsetWidth,(this.container.offsetHeight / 2)] ]; for (var i=0,len=divs.length; i