Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added the plot function as a chainable property. #953

Merged
merged 3 commits into from

1 participant

@dnschnur
Owner

This implements a long-standing enhancement of being able to create a plot like this:

$("#placeholder").plot(data, options);

This form supports standard jQuery chaining, making it quite convenient when the placeholder is the result of a stream of jQuery calls, or when additional calls need to be made after the plot is created.

The disadvantage of this form is that it provides no way to return the plot object. This isn't a big deal, though, since users can easily retrieve it via the 'plot' data key, like this:

var plot = $("#placeholder").plot(data, options).data("plot");
@dnschnur dnschnur was assigned
@dnschnur dnschnur merged commit 410dd7d into flot:master
@dnschnur dnschnur deleted the dnschnur:jquery-chainable branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 8, 2013
  1. @dnschnur
  2. @dnschnur
Commits on Feb 9, 2013
  1. @dnschnur
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 0 deletions.
  1. +8 −0 API.md
  2. +3 −0  NEWS.md
  3. +10 −0 jquery.flot.js
View
8 API.md
@@ -15,6 +15,14 @@ don't use for anything else. Make sure you check any fancy styling
you apply to the div, e.g. background images have been reported to be a
problem on IE 7.
+The plot function can also be used as a jQuery chainable property. This form
+naturally can't return the plot object directly, but you can still access it
+via the 'plot' data key, like this:
+
+```js
+var plot = $("#placeholder").plot(data, options).data("plot");
+```
+
The format of the data is documented below, as is the available
options. The plot object returned from the call has some methods you
can call. These are documented separately below.
View
3  NEWS.md
@@ -104,6 +104,9 @@ The base and overlay canvas are now using the CSS classes "flot-base" and
- Added a new option called 'zero' to bars and filled lines series, to control
whether the y-axis minimum is scaled to fit the data or set to zero.
+ - The plot function is now also a jQuery chainable property.
+ (patch by David Schnur, issues #734 and #816, pull request #953)
+
### Bug fixes ###
- Fix problem with null values and pie plugin. (patch by gcruxifix,
View
10 jquery.flot.js
@@ -2681,6 +2681,8 @@ Licensed under the MIT license.
}
}
+ // Add the plot function to the top level of the jQuery object
+
$.plot = function(placeholder, data, options) {
//var t0 = new Date();
var plot = new Plot($(placeholder), data, options, $.plot.plugins);
@@ -2692,6 +2694,14 @@ Licensed under the MIT license.
$.plot.plugins = [];
+ // Also add the plot function as a chainable property
+
+ $.fn.plot = function(data, options) {
+ return this.each(function() {
+ $.plot(this, data, options);
+ });
+ }
+
// round to nearby lower multiple of base
function floorInBase(n, base) {
return base * Math.floor(n / base);
Something went wrong with that request. Please try again.