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 ...@@ -127,7 +127,7 @@ Customizing the legend
legend: { legend: {
show: boolean show: boolean
labelFormatter: null or (fn: string -> string) labelFormatter: null or (fn: string, series object -> string)
labelBoxBorderColor: color labelBoxBorderColor: color
noColumns: number noColumns: number
position: "ne" or "nw" or "se" or "sw" 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 ...@@ -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 function for "labelFormatter". Here's an example that makes them
clickable: clickable:
labelFormatter: function(label) { labelFormatter: function(label, series) {
return '<a href="' + label + '">' + label + '</a>'; // 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. "noColumns" is the number of columns to divide the legend table into.
......
...@@ -53,6 +53,8 @@ Changes: ...@@ -53,6 +53,8 @@ Changes:
points below that threshold will then get the color. Useful for points below that threshold will then get the color. Useful for
marking data below 0, for instance. 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: Bug fixes:
......
...@@ -1583,10 +1583,12 @@ ...@@ -1583,10 +1583,12 @@
if (!options.legend.show) if (!options.legend.show)
return; return;
var fragments = []; var fragments = [], rowStarted = false,
var rowStarted = false; lf = options.legend.labelFormatter, s, label;
for (i = 0; i < series.length; ++i) { for (i = 0; i < series.length; ++i) {
if (!series[i].label) s = series[i];
label = s.label;
if (!label)
continue; continue;
if (i % options.legend.noColumns == 0) { if (i % options.legend.noColumns == 0) {
...@@ -1596,12 +1598,11 @@ ...@@ -1596,12 +1598,11 @@
rowStarted = true; rowStarted = true;
} }
var label = series[i].label; if (lf)
if (options.legend.labelFormatter != null) label = lf(label, s);
label = options.legend.labelFormatter(label);
fragments.push( 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>'); '<td class="legendLabel">' + label + '</td>');
} }
if (rowStarted) 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