From c81f0af709ed9d11a867410bc46bce878b4bc001 Mon Sep 17 00:00:00 2001 From: "olau@iola.dk" Date: Fri, 7 Dec 2007 10:05:55 +0000 Subject: [PATCH] Added labelFormatter option git-svn-id: https://flot.googlecode.com/svn/trunk@22 1e0a6537-2640-0410-bfb7-f154510ff394 --- API.txt | 33 ++++++++++++++++++++++----------- NEWS.txt | 3 +++ jquery.flot.js | 7 ++++++- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/API.txt b/API.txt index fc203f4..ab4a0cc 100644 --- a/API.txt +++ b/API.txt @@ -94,8 +94,9 @@ Customizing the legend legend: { show: boolean, - noColumns: number, + labelFormatter: null or (fn: string -> string), labelBoxBorderColor: color, + noColumns: number, position: "ne" or "nw" or "se" or "sw", margin: number of pixels, backgroundColor: null or color, @@ -104,23 +105,33 @@ Customizing the legend } The legend is generated as a table with the data series labels and -small label boxes with the color of the series. "noColumns" is the -number of columns to divide the legend table into. "position" -specifies the overall placement of the legend within the plot -(top-right, top-left, etc.) and margin the distance to the plot edge. -"backgroundColor" and "backgroundOpacity" specifies the background. -The default is a partly transparent auto-detected background. +small label boxes with the color of the series. If you want to format +the labels in some way, e.g. make them to links, you can pass in a +function for "labelFormatter". Here's an example that makes them +clickable: + + labelFormatter: function(label) { + return '' + label + ''; + } + +"noColumns" is the number of columns to divide the legend table into. +"position" specifies the overall placement of the legend within the +plot (top-right, top-left, etc.) and margin the distance to the plot +edge. "backgroundColor" and "backgroundOpacity" specifies the +background. The default is a partly transparent auto-detected +background. + +If you want the legend to appear somewhere else in the DOM, you can +specify "container" as a jQuery object to put the legend table into. +The "position" and "margin" etc. options will then be ignored. -If you want the legend to appear somewhere else, you can specify -"container" as a jQuery object to put the legend table in. The -"position" and "margin" etc. will then be ignored. Customizing the axes ==================== xaxis, yaxis: { - ticks: null or ticks array, + ticks: null or ticks array or (fn: range -> ticks array), noTicks: number, tickFormatter: fn: number -> string, tickDecimals: null or number, diff --git a/NEWS.txt b/NEWS.txt index 3208a58..1d0735b 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -10,6 +10,9 @@ The ticks options can now be a callback function that takes one parameter, an object with the attributes min and max. The function should return a ticks array. +Added labelFormatter option in legend, useful for turning the legend +labels into links. + Fixed a couple of bugs. The API should now be fully documented. diff --git a/jquery.flot.js b/jquery.flot.js index 5b01c94..c2625e0 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -18,6 +18,7 @@ legend: { show: true, noColumns: 1, // number of colums in legend table + labelFormatter: null, // fn: string -> string labelBoxBorderColor: "#ccc", // border color for the little label boxes container: null, // container (as jQuery object) to put legend in, null means default on top of graph position: "ne", // position of default legend container within plot @@ -954,10 +955,14 @@ fragments.push(''); rowStarted = true; } + + var label = series[i].label; + if (options.legend.labelFormatter != null) + label = options.legend.labelFormatter(label); fragments.push( '
' + - '' + series[i].label + ''); + '' + label + ''); } if (rowStarted) fragments.push('');