Skip to content

Commit 3ba7f28

Browse files
Revamp resize plugin to reuse the plot object and disconnect its
resize event properly git-svn-id: https://flot.googlecode.com/svn/trunk@318 1e0a6537-2640-0410-bfb7-f154510ff394
1 parent 4e02781 commit 3ba7f28

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

NEWS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Changes:
8181
types (sponsored by Utility Data Corporation).
8282
- Resize plugin for automatically redrawing when the placeholder
8383
changes size, e.g. on window resizes (sponsored by Novus Partners).
84+
A resize() method has been added to plot object facilitate this.
8485
- Support Infinity/-Infinity for plotting asymptotes by hacking it
8586
into +/-Number.MAX_VALUE (reported by rabaea.mircea).
8687
- Support for restricting navigate plugin to not pan/zoom an axis (based

jquery.flot.resize.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,32 @@ plots, you can just fix the size of their placeholders.
2323

2424

2525
(function ($) {
26-
var redrawing = 0;
2726
var options = { }; // no options
2827

2928
function init(plot) {
29+
function onResize() {
30+
var placeholder = plot.getPlaceholder();
31+
32+
// somebody might have hidden us and we can't plot
33+
// when we don't have the dimensions
34+
if (placeholder.width() == 0 || placeholder.height() == 0)
35+
return;
36+
37+
plot.resize();
38+
plot.setupGrid();
39+
plot.draw();
40+
}
41+
3042
function bindEvents(plot, eventHolder) {
31-
if (!redrawing)
32-
plot.getPlaceholder().resize(onResize);
33-
34-
function onResize() {
35-
var placeholder = plot.getPlaceholder();
36-
37-
// somebody might have hidden us and we can't plot
38-
// when we don't have the dimensions
39-
if (placeholder.width() == 0 || placeholder.height() == 0)
40-
return;
41-
42-
++redrawing;
43-
$.plot(placeholder, plot.getData(), plot.getOptions());
44-
--redrawing;
45-
}
43+
plot.getPlaceholder().resize(onResize);
44+
}
45+
46+
function shutdown(plot, eventHolder) {
47+
plot.getPlaceholder().unbind("resize", onResize);
4648
}
4749

4850
plot.hooks.bindEvents.push(bindEvents);
51+
plot.hooks.shutdown.push(shutdown);
4952
}
5053

5154
$.plot.plugins.push({

0 commit comments

Comments
 (0)