From 51e14f6a27dbf2ab94a364f70e7f4813c113837d Mon Sep 17 00:00:00 2001 From: David Schnur Date: Tue, 12 Feb 2013 18:02:06 -0500 Subject: [PATCH 1/2] Added a 'reverse' sorted option. This orders the legend entries in reverse order of their series. --- jquery.flot.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jquery.flot.js b/jquery.flot.js index 7a0b04e..09d8fd0 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -2315,6 +2315,8 @@ Licensed under the MIT license. if (options.legend.sorted) { if ($.isFunction(options.legend.sorted)) { entries.sort(options.legend.sorted); + } else if (options.legend.sorted == "reverse") { + entries.reverse(); } else { var ascending = options.legend.sorted != "descending"; entries.sort(function(a, b) { From 6bbce44644e2f706b572490ea5152839baf9d35e Mon Sep 17 00:00:00 2001 From: David Schnur Date: Tue, 12 Feb 2013 18:03:23 -0500 Subject: [PATCH 2/2] Updated the API with the legend 'reverse' option. --- API.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/API.md b/API.md index 9c9199f..df0cf24 100644 --- a/API.md +++ b/API.md @@ -164,7 +164,7 @@ legend: { backgroundColor: null or color backgroundOpacity: number between 0 and 1 container: null or jQuery object/DOM element/jQuery expression - sorted: null/false, true, "ascending", "descending" or a comparator + sorted: null/false, true, "ascending", "descending", "reverse", or a comparator } ``` @@ -197,9 +197,10 @@ specify "container" as a jQuery object/expression to put the legend table into. The "position" and "margin" etc. options will then be ignored. Note that Flot will overwrite the contents of the container. -Legend entries appear in the same order as their series by default. To -sort them alphabetically, you can specify "sorted" as tue, "ascending" -or "descending", where true and "ascending" are equivalent. +Legend entries appear in the same order as their series by default. If "sorted" +is "reverse" then they appear in the opposite order from their series. To sort +them alphabetically, you can specify true, "ascending" or "descending", where +true and "ascending" are equivalent. You can also provide your own comparator function that accepts two objects with "label" and "color" properties, and returns zero if they