1/* Flot plugin for automatically redrawing plots as the placeholder resizes. 2 3Copyright (c) 2007-2014 IOLA and Ole Laursen. 4Licensed under the MIT license. 5 6It works by listening for changes on the placeholder div (through the jQuery 7resize event plugin) - if the size changes, it will redraw the plot. 8 9There are no options. If you need to disable the plugin for some plots, you 10can just fix the size of their placeholders. 11 12*/ 13 14/* Inline dependency: 15 * jQuery resize event - v1.1 - 3/14/2010 16 * http://benalman.com/projects/jquery-resize-plugin/ 17 * 18 * Copyright (c) 2010 "Cowboy" Ben Alman 19 * Dual licensed under the MIT and GPL licenses. 20 * http://benalman.com/about/license/ 21 */ 22(function($,e,t){"$:nomunge";var i=[],n=$.resize=$.extend($.resize,{}),a,r=false,s="setTimeout",u="resize",m=u+"-special-event",o="pendingDelay",l="activeDelay",f="throttleWindow";n[o]=200;n[l]=20;n[f]=true;$.event.special[u]={setup:function(){if(!n[f]&&this[s]){return false}var e=$(this);i.push(this);e.data(m,{w:e.width(),h:e.height()});if(i.length===1){a=t;h()}},teardown:function(){if(!n[f]&&this[s]){return false}var e=$(this);for(var t=i.length-1;t>=0;t--){if(i[t]==this){i.splice(t,1);break}}e.removeData(m);if(!i.length){if(r){cancelAnimationFrame(a)}else{clearTimeout(a)}a=null}},add:function(e){if(!n[f]&&this[s]){return false}var i;function a(e,n,a){var r=$(this),s=r.data(m)||{};s.w=n!==t?n:r.width();s.h=a!==t?a:r.height();i.apply(this,arguments)}if($.isFunction(e)){i=e;return a}else{i=e.handler;e.handler=a}}};function h(t){if(r===true){r=t||1}for(var s=i.length-1;s>=0;s--){var l=$(i[s]);if(l[0]==e||l.is(":visible")){var f=l.width(),c=l.height(),d=l.data(m);if(d&&(f!==d.w||c!==d.h)){l.trigger(u,[d.w=f,d.h=c]);r=t||true}}else{d=l.data(m);d.w=0;d.h=0}}if(a!==null){if(r&&(t==null||t-r<1e3)){a=e.requestAnimationFrame(h)}else{a=setTimeout(h,n[o]);r=false}}}if(!e.requestAnimationFrame){e.requestAnimationFrame=function(){return e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(t,i){return e.setTimeout(function(){t((new Date).getTime())},n[l])}}()}if(!e.cancelAnimationFrame){e.cancelAnimationFrame=function(){return e.webkitCancelRequestAnimationFrame||e.mozCancelRequestAnimationFrame||e.oCancelRequestAnimationFrame||e.msCancelRequestAnimationFrame||clearTimeout}()}})(jQuery,this); 23 24(function ($) { 25 var options = { }; // no options 26 27 function init(plot) { 28 function onResize() { 29 var placeholder = plot.getPlaceholder(); 30 31 // somebody might have hidden us and we can't plot 32 // when we don't have the dimensions 33 if (placeholder.width() == 0 || placeholder.height() == 0) 34 return; 35 36 plot.resize(); 37 plot.setupGrid(); 38 plot.draw(); 39 } 40 41 function bindEvents(plot, eventHolder) { 42 plot.getPlaceholder().resize(onResize); 43 } 44 45 function shutdown(plot, eventHolder) { 46 plot.getPlaceholder().unbind("resize", onResize); 47 } 48 49 plot.hooks.bindEvents.push(bindEvents); 50 plot.hooks.shutdown.push(shutdown); 51 } 52 53 $.plot.plugins.push({ 54 init: init, 55 options: options, 56 name: 'resize', 57 version: '1.0' 58 }); 59})(jQuery); 60