Commit ab264f6e authored by olau@iola.dk's avatar olau@iola.dk

legend.margin can now specify horizontal and vertical margins

git-svn-id: https://flot.googlecode.com/svn/trunk@131 1e0a6537-2640-0410-bfb7-f154510ff394
parent da43cef6
...@@ -130,9 +130,9 @@ Customizing the legend ...@@ -130,9 +130,9 @@ Customizing the legend
labelBoxBorderColor: color labelBoxBorderColor: color
noColumns: number noColumns: number
position: "ne" or "nw" or "se" or "sw" position: "ne" or "nw" or "se" or "sw"
margin: number of pixels margin: number of pixels or [x margin, y margin]
backgroundColor: null or color backgroundColor: null or color
backgroundOpacity: number in 0.0 - 1.0 backgroundOpacity: number between 0 and 1
container: null or jQuery object/DOM element/jQuery expression container: null or jQuery object/DOM element/jQuery expression
} }
...@@ -149,14 +149,16 @@ clickable: ...@@ -149,14 +149,16 @@ clickable:
"noColumns" is the number of columns to divide the legend table into. "noColumns" is the number of columns to divide the legend table into.
"position" specifies the overall placement of the legend within the "position" specifies the overall placement of the legend within the
plot (top-right, top-left, etc.) and margin the distance to the plot plot (top-right, top-left, etc.) and margin the distance to the plot
edge. "backgroundColor" and "backgroundOpacity" specifies the edge (this can be either a number or an array of two numbers like [x,
y]). "backgroundColor" and "backgroundOpacity" specifies the
background. The default is a partly transparent auto-detected background. The default is a partly transparent auto-detected
background. background.
If you want the legend to appear somewhere else in the DOM, you can 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. specify "container" as a jQuery object/expression to put the legend
The "position" and "margin" etc. options will then be ignored. Note table into. The "position" and "margin" etc. options will then be
that it will overwrite the contents of the container. ignored. Note that Flot will overwrite the contents of the container.
Most of the above settings do not apply
......
...@@ -35,6 +35,9 @@ Changes: ...@@ -35,6 +35,9 @@ Changes:
- Added a "plotunselected" event which is triggered when the selection - Added a "plotunselected" event which is triggered when the selection
is removed, see "selection" example (suggestion by Meda Ugo); is removed, see "selection" example (suggestion by Meda Ugo);
- The option legend.margin can now specify horizontal and vertical
margins independently (suggestion by someone who's annoyed).
Bug fixes: Bug fixes:
......
...@@ -1504,16 +1504,19 @@ ...@@ -1504,16 +1504,19 @@
if (options.legend.container != null) if (options.legend.container != null)
$(options.legend.container).html(table); $(options.legend.container).html(table);
else { else {
var pos = ""; var pos = "",
var p = options.legend.position, m = options.legend.margin; p = options.legend.position,
m = options.legend.margin;
if (m[0] == null)
m = [m, m];
if (p.charAt(0) == "n") if (p.charAt(0) == "n")
pos += 'top:' + (m + plotOffset.top) + 'px;'; pos += 'top:' + (m[1] + plotOffset.top) + 'px;';
else if (p.charAt(0) == "s") else if (p.charAt(0) == "s")
pos += 'bottom:' + (m + plotOffset.bottom) + 'px;'; pos += 'bottom:' + (m[1] + plotOffset.bottom) + 'px;';
if (p.charAt(1) == "e") if (p.charAt(1) == "e")
pos += 'right:' + (m + plotOffset.right) + 'px;'; pos += 'right:' + (m[0] + plotOffset.right) + 'px;';
else if (p.charAt(1) == "w") else if (p.charAt(1) == "w")
pos += 'left:' + (m + plotOffset.left) + 'px;'; pos += 'left:' + (m[0] + plotOffset.left) + 'px;';
var legend = $('<div class="legend">' + table.replace('style="', 'style="position:absolute;' + pos +';') + '</div>').appendTo(target); var legend = $('<div class="legend">' + table.replace('style="', 'style="position:absolute;' + pos +';') + '</div>').appendTo(target);
if (options.legend.backgroundOpacity != 0.0) { if (options.legend.backgroundOpacity != 0.0) {
// put in the transparent background // put in the transparent background
......
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