Commit 74661de1 authored by olau@iola.dk's avatar olau@iola.dk

Added second parameter to labelFormatter for legend

git-svn-id: https://flot.googlecode.com/svn/trunk@140 1e0a6537-2640-0410-bfb7-f154510ff394
parent f6b08328
......@@ -127,7 +127,7 @@ Customizing the legend
legend: {
show: boolean
labelFormatter: null or (fn: string -> string)
labelFormatter: null or (fn: string, series object -> string)
labelBoxBorderColor: color
noColumns: number
position: "ne" or "nw" or "se" or "sw"
......@@ -143,8 +143,9 @@ 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 '<a href="' + label + '">' + label + '</a>';
labelFormatter: function(label, series) {
// series is the series object for the label
return '<a href="#' + label + '">' + label + '</a>';
}
"noColumns" is the number of columns to divide the legend table into.
......
......@@ -53,6 +53,8 @@ Changes:
points below that threshold will then get the color. Useful for
marking data below 0, for instance.
- The legend labelFormatter now passes the series in addition to just
the label (suggestion by Vincent Lemeltier).
Bug fixes:
......
......@@ -1583,10 +1583,12 @@
if (!options.legend.show)
return;
var fragments = [];
var rowStarted = false;
var fragments = [], rowStarted = false,
lf = options.legend.labelFormatter, s, label;
for (i = 0; i < series.length; ++i) {
if (!series[i].label)
s = series[i];
label = s.label;
if (!label)
continue;
if (i % options.legend.noColumns == 0) {
......@@ -1596,12 +1598,11 @@
rowStarted = true;
}
var label = series[i].label;
if (options.legend.labelFormatter != null)
label = options.legend.labelFormatter(label);
if (lf)
label = lf(label, s);
fragments.push(
'<td class="legendColorBox"><div style="border:1px solid ' + options.legend.labelBoxBorderColor + ';padding:1px"><div style="width:4px;height:0;border:5px solid ' + series[i].color + ';overflow:hidden"></div></div></td>' +
'<td class="legendColorBox"><div style="border:1px solid ' + options.legend.labelBoxBorderColor + ';padding:1px"><div style="width:4px;height:0;border:5px solid ' + s.color + ';overflow:hidden"></div></div></td>' +
'<td class="legendLabel">' + label + '</td>');
}
if (rowStarted)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment