All Downloads are FREE. Search and download functionalities are using the official Maven repository.

report-resources.jqplot.1.0.8.plugins.jqplot.bubbleRenderer.js Maven / Gradle / Ivy

There is a newer version: 4.2.9
Show newest version
/**
 * jqPlot
 * Pure JavaScript plotting plugin using jQuery
 *
 * Version: 1.0.8
 * Revision: 1250
 *
 * Copyright (c) 2009-2013 Chris Leonello
 * jqPlot is currently available for use in all personal or commercial projects 
 * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL 
 * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can 
 * choose the license that best suits your project and use it accordingly. 
 *
 * Although not required, the author would appreciate an email letting him 
 * know of any substantial use of jqPlot.  You can reach the author at: 
 * chris at jqplot dot com or see http://www.jqplot.com/info.php .
 *
 * If you are feeling kind and generous, consider supporting the project by
 * making a donation at: http://www.jqplot.com/donate.php .
 *
 * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
 *
 *     version 2007.04.27
 *     author Ash Searle
 *     http://hexmen.com/blog/2007/03/printf-sprintf/
 *     http://hexmen.com/js/sprintf.js
 *     The author (Ash Searle) has placed this code in the public domain:
 *     "This code is unrestricted: you are free to use it however you like."
 * 
 */
(function($) {
    var arrayMax = function( array ){
        return Math.max.apply( Math, array );
    };
    var arrayMin = function( array ){
        return Math.min.apply( Math, array );
    };

    /**
     * Class: $.jqplot.BubbleRenderer
     * Plugin renderer to draw a bubble chart.  A Bubble chart has data points displayed as
     * colored circles with an optional text label inside.  To use
     * the bubble renderer, you must include the bubble renderer like:
     * 
     * > 
     * 
     * Data must be supplied in 
     * the form:
     * 
     * > [[x1, y1, r1, 
'); if (this.escapeHtml) { tel.text(t); } else { tel.html(t); } this.canvas._elem.append(tel); var h = $(tel).outerHeight(); var w = $(tel).outerWidth(); var top = gd[1] - 0.5*h; var left = gd[0] - 0.5*w; tel.css({top: top, left: left}); this.labels[idx] = $(tel); } } }; $.jqplot.DivCanvas = function() { $.jqplot.ElemContainer.call(this); this._ctx; }; $.jqplot.DivCanvas.prototype = new $.jqplot.ElemContainer(); $.jqplot.DivCanvas.prototype.constructor = $.jqplot.DivCanvas; $.jqplot.DivCanvas.prototype.createElement = function(offsets, clss, plotDimensions) { this._offsets = offsets; var klass = 'jqplot-DivCanvas'; if (clss != undefined) { klass = clss; } var elem; // if this canvas already has a dom element, don't make a new one. if (this._elem) { elem = this._elem.get(0); } else { elem = document.createElement('div'); } // if new plotDimensions supplied, use them. if (plotDimensions != undefined) { this._plotDimensions = plotDimensions; } var w = this._plotDimensions.width - this._offsets.left - this._offsets.right + 'px'; var h = this._plotDimensions.height - this._offsets.top - this._offsets.bottom + 'px'; this._elem = $(elem); this._elem.css({ position: 'absolute', width:w, height:h, left: this._offsets.left, top: this._offsets.top }); this._elem.addClass(klass); return this._elem; }; $.jqplot.DivCanvas.prototype.setContext = function() { this._ctx = { canvas:{ width:0, height:0 }, clearRect:function(){return null;} }; return this._ctx; }; $.jqplot.BubbleCanvas = function() { $.jqplot.ElemContainer.call(this); this._ctx; }; $.jqplot.BubbleCanvas.prototype = new $.jqplot.ElemContainer(); $.jqplot.BubbleCanvas.prototype.constructor = $.jqplot.BubbleCanvas; // initialize with the x,y pont of bubble center and the bubble radius. $.jqplot.BubbleCanvas.prototype.createElement = function(x, y, r) { var klass = 'jqplot-bubble-point'; var elem; // if this canvas already has a dom element, don't make a new one. if (this._elem) { elem = this._elem.get(0); } else { elem = document.createElement('canvas'); } elem.width = (r != null) ? 2*r : elem.width; elem.height = (r != null) ? 2*r : elem.height; this._elem = $(elem); var l = (x != null && r != null) ? x - r : this._elem.css('left'); var t = (y != null && r != null) ? y - r : this._elem.css('top'); this._elem.css({ position: 'absolute', left: l, top: t }); this._elem.addClass(klass); if ($.jqplot.use_excanvas) { window.G_vmlCanvasManager.init_(document); elem = window.G_vmlCanvasManager.initElement(elem); } return this._elem; }; $.jqplot.BubbleCanvas.prototype.draw = function(r, color, gradients, angle) { var ctx = this._ctx; // r = Math.floor(r*1.04); // var x = Math.round(ctx.canvas.width/2); // var y = Math.round(ctx.canvas.height/2); var x = ctx.canvas.width/2; var y = ctx.canvas.height/2; ctx.save(); if (gradients && !$.jqplot.use_excanvas) { r = r*1.04; var comps = $.jqplot.getColorComponents(color); var colorinner = 'rgba('+Math.round(comps[0]+0.8*(255-comps[0]))+', '+Math.round(comps[1]+0.8*(255-comps[1]))+', '+Math.round(comps[2]+0.8*(255-comps[2]))+', '+comps[3]+')'; var colorend = 'rgba('+comps[0]+', '+comps[1]+', '+comps[2]+', 0)'; // var rinner = Math.round(0.35 * r); // var xinner = Math.round(x - Math.cos(angle) * 0.33 * r); // var yinner = Math.round(y - Math.sin(angle) * 0.33 * r); var rinner = 0.35 * r; var xinner = x - Math.cos(angle) * 0.33 * r; var yinner = y - Math.sin(angle) * 0.33 * r; var radgrad = ctx.createRadialGradient(xinner, yinner, rinner, x, y, r); radgrad.addColorStop(0, colorinner); radgrad.addColorStop(0.93, color); radgrad.addColorStop(0.96, colorend); radgrad.addColorStop(1, colorend); // radgrad.addColorStop(.98, colorend); ctx.fillStyle = radgrad; ctx.fillRect(0,0, ctx.canvas.width, ctx.canvas.height); } else { ctx.fillStyle = color; ctx.strokeStyle = color; ctx.lineWidth = 1; ctx.beginPath(); var ang = 2*Math.PI; ctx.arc(x, y, r, 0, ang, 0); ctx.closePath(); ctx.fill(); } ctx.restore(); }; $.jqplot.BubbleCanvas.prototype.setContext = function() { this._ctx = this._elem.get(0).getContext("2d"); return this._ctx; }; $.jqplot.BubbleAxisRenderer = function() { $.jqplot.LinearAxisRenderer.call(this); }; $.jqplot.BubbleAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer(); $.jqplot.BubbleAxisRenderer.prototype.constructor = $.jqplot.BubbleAxisRenderer; // called with scope of axis object. $.jqplot.BubbleAxisRenderer.prototype.init = function(options){ $.extend(true, this, options); var db = this._dataBounds; var minsidx = 0, minpidx = 0, maxsidx = 0, maxpidx = 0, maxr = 0, minr = 0, minMaxRadius = 0, maxMaxRadius = 0, maxMult = 0, minMult = 0; // Go through all the series attached to this axis and find // the min/max bounds for this axis. for (var i=0; i db.max || db.max == null) { db.max = d[j][0]; maxsidx=i; maxpidx=j; maxr = d[j][2]; maxMaxRadius = s.maxRadius; maxMult = s.autoscaleMultiplier; } } else { if (d[j][1] < db.min || db.min == null) { db.min = d[j][1]; minsidx=i; minpidx=j; minr = d[j][2]; minMaxRadius = s.maxRadius; minMult = s.autoscaleMultiplier; } if (d[j][1] > db.max || db.max == null) { db.max = d[j][1]; maxsidx=i; maxpidx=j; maxr = d[j][2]; maxMaxRadius = s.maxRadius; maxMult = s.autoscaleMultiplier; } } } } var minRatio = minr/minMaxRadius; var maxRatio = maxr/maxMaxRadius; // need to estimate the effect of the radius on total axis span and adjust axis accordingly. var span = db.max - db.min; // var dim = (this.name == 'xaxis' || this.name == 'x2axis') ? this._plotDimensions.width : this._plotDimensions.height; var dim = Math.min(this._plotDimensions.width, this._plotDimensions.height); var minfact = minRatio * minMult/3 * span; var maxfact = maxRatio * maxMult/3 * span; db.max += maxfact; db.min -= minfact; }; function highlight (plot, sidx, pidx) { plot.plugins.bubbleRenderer.highlightLabelCanvas.empty(); var s = plot.series[sidx]; var canvas = plot.plugins.bubbleRenderer.highlightCanvas; var ctx = canvas._ctx; ctx.clearRect(0,0,ctx.canvas.width, ctx.canvas.height); s._highlightedPoint = pidx; plot.plugins.bubbleRenderer.highlightedSeriesIndex = sidx; var color = s.highlightColorGenerator.get(pidx); var x = s.gridData[pidx][0], y = s.gridData[pidx][1], r = s.gridData[pidx][2]; ctx.save(); ctx.fillStyle = color; ctx.strokeStyle = color; ctx.lineWidth = 1; ctx.beginPath(); ctx.arc(x, y, r, 0, 2*Math.PI, 0); ctx.closePath(); ctx.fill(); ctx.restore(); // bring label to front if (s.labels[pidx]) { plot.plugins.bubbleRenderer.highlightLabel = s.labels[pidx].clone(); plot.plugins.bubbleRenderer.highlightLabel.appendTo(plot.plugins.bubbleRenderer.highlightLabelCanvas); plot.plugins.bubbleRenderer.highlightLabel.addClass('jqplot-bubble-label-highlight'); } } function unhighlight (plot) { var canvas = plot.plugins.bubbleRenderer.highlightCanvas; var sidx = plot.plugins.bubbleRenderer.highlightedSeriesIndex; plot.plugins.bubbleRenderer.highlightLabelCanvas.empty(); canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height); for (var i=0; i
'); var top = this._gridPadding.top; var left = this._gridPadding.left; var width = this._plotDimensions.width - this._gridPadding.left - this._gridPadding.right; var height = this._plotDimensions.height - this._gridPadding.top - this._gridPadding.bottom; this.plugins.bubbleRenderer.highlightLabelCanvas.css({top:top, left:left, width:width+'px', height:height+'px'}); this.eventCanvas._elem.before(this.plugins.bubbleRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-bubbleRenderer-highlight-canvas', this._plotDimensions, this)); this.eventCanvas._elem.before(this.plugins.bubbleRenderer.highlightLabelCanvas); var hctx = this.plugins.bubbleRenderer.highlightCanvas.setContext(); } // setup default renderers for axes and legend so user doesn't have to // called with scope of plot function preInit(target, data, options) { options = options || {}; options.axesDefaults = options.axesDefaults || {}; options.seriesDefaults = options.seriesDefaults || {}; // only set these if there is a Bubble series var setopts = false; if (options.seriesDefaults.renderer == $.jqplot.BubbleRenderer) { setopts = true; } else if (options.series) { for (var i=0; i < options.series.length; i++) { if (options.series[i].renderer == $.jqplot.BubbleRenderer) { setopts = true; } } } if (setopts) { options.axesDefaults.renderer = $.jqplot.BubbleAxisRenderer; options.sortData = false; } } $.jqplot.preInitHooks.push(preInit); })(jQuery);



© 2015 - 2025 Weber Informatics LLC | Privacy Policy