Skip to content

Commit

Permalink
Revamp resize plugin to reuse the plot object and disconnect its
Browse files Browse the repository at this point in the history
resize event properly


git-svn-id: https://flot.googlecode.com/svn/trunk@318 1e0a6537-2640-0410-bfb7-f154510ff394
  • Loading branch information
olau@iola.dk committed Mar 17, 2011
1 parent 4e02781 commit 3ba7f28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions NEWS.txt
Expand Up @@ -81,6 +81,7 @@ Changes:
types (sponsored by Utility Data Corporation).
- Resize plugin for automatically redrawing when the placeholder
changes size, e.g. on window resizes (sponsored by Novus Partners).
A resize() method has been added to plot object facilitate this.
- Support Infinity/-Infinity for plotting asymptotes by hacking it
into +/-Number.MAX_VALUE (reported by rabaea.mircea).
- Support for restricting navigate plugin to not pan/zoom an axis (based
Expand Down
35 changes: 19 additions & 16 deletions jquery.flot.resize.js
Expand Up @@ -23,29 +23,32 @@ plots, you can just fix the size of their placeholders.


(function ($) {
var redrawing = 0;
var options = { }; // no options

function init(plot) {
function onResize() {
var placeholder = plot.getPlaceholder();

// somebody might have hidden us and we can't plot
// when we don't have the dimensions
if (placeholder.width() == 0 || placeholder.height() == 0)
return;

plot.resize();
plot.setupGrid();
plot.draw();
}

function bindEvents(plot, eventHolder) {
if (!redrawing)
plot.getPlaceholder().resize(onResize);

function onResize() {
var placeholder = plot.getPlaceholder();

// somebody might have hidden us and we can't plot
// when we don't have the dimensions
if (placeholder.width() == 0 || placeholder.height() == 0)
return;

++redrawing;
$.plot(placeholder, plot.getData(), plot.getOptions());
--redrawing;
}
plot.getPlaceholder().resize(onResize);
}

function shutdown(plot, eventHolder) {
plot.getPlaceholder().unbind("resize", onResize);
}

plot.hooks.bindEvents.push(bindEvents);
plot.hooks.shutdown.push(shutdown);
}

$.plot.plugins.push({
Expand Down

0 comments on commit 3ba7f28

Please sign in to comment.