From 49cce02be913b5b35a350a3fc89359150e351e3a Mon Sep 17 00:00:00 2001 From: David Schnur Date: Thu, 7 Feb 2013 21:31:51 -0500 Subject: [PATCH 1/3] Add the plot function as a chainable property. Resolves #734 and #816. --- jquery.flot.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/jquery.flot.js b/jquery.flot.js index bbb6c68..7a0b04e 100644 --- a/jquery.flot.js +++ b/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); From aaa1cc7f84881addb5029e4ccf1e695eefd40403 Mon Sep 17 00:00:00 2001 From: David Schnur Date: Thu, 7 Feb 2013 21:33:08 -0500 Subject: [PATCH 2/3] Document the new plot chainable property. --- API.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/API.md b/API.md index bcf5d25..9c9199f 100644 --- a/API.md +++ b/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. From a787fa4e9c7768129b78c2ed2d67e8d7069fc4fd Mon Sep 17 00:00:00 2001 From: David Schnur Date: Sat, 9 Feb 2013 18:02:54 -0500 Subject: [PATCH 3/3] Updated credits for #953 chainable property. --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index ec8edbe..27a7a60 100644 --- a/NEWS.md +++ b/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,