Commit 78de0447 authored by olau@iola.dk's avatar olau@iola.dk

Added support for customizing the border width, change gridLabel to tickLabel...

Added support for customizing the border width, change gridLabel to tickLabel and mention it in the API

git-svn-id: https://flot.googlecode.com/svn/trunk@54 1e0a6537-2640-0410-bfb7-f154510ff394
parent cba14862
...@@ -169,7 +169,7 @@ be chosen based on the minimum/maximum data values. ...@@ -169,7 +169,7 @@ be chosen based on the minimum/maximum data values.
The "autoscaleMargin" is a bit esoteric: it's the fraction of margin The "autoscaleMargin" is a bit esoteric: it's the fraction of margin
that the scaling algorithm will add to avoid that the outermost points that the scaling algorithm will add to avoid that the outermost points
ends up on the grid outline. Note that this margin is only applied ends up on the grid border. Note that this margin is only applied
when a min or max value is not explicitly set. If a margin is when a min or max value is not explicitly set. If a margin is
specified, the plot will furthermore extend the axis end-point to the specified, the plot will furthermore extend the axis end-point to the
nearest whole tick. The default value is "null" for the x axis and nearest whole tick. The default value is "null" for the x axis and
...@@ -401,6 +401,7 @@ Customizing the grid ...@@ -401,6 +401,7 @@ Customizing the grid
labelMargin: number labelMargin: number
coloredAreas: array of areas or (fn: plot area -> array of areas) coloredAreas: array of areas or (fn: plot area -> array of areas)
coloredAreasColor: color coloredAreasColor: color
borderWidth: number
clickable: boolean clickable: boolean
} }
...@@ -413,8 +414,10 @@ page color. Otherwise you might as well just set the background color ...@@ -413,8 +414,10 @@ page color. Otherwise you might as well just set the background color
of the page with CSS. of the page with CSS.
"tickColor" is the color of the ticks and "labelMargin" is the spacing "tickColor" is the color of the ticks and "labelMargin" is the spacing
between tick labels and the grid. between tick labels and the grid. Note that you can style the tick
labels with CSS, e.g. to change the color. They have class "tickLabel".
"borderWidth" is the width of the border around the plot. Set it to 0
to disable the border.
"coloredAreas" is an array of areas that will be drawn on top of the "coloredAreas" is an array of areas that will be drawn on top of the
background. You can either specify an array of objects with { x1, y1, background. You can either specify an array of objects with { x1, y1,
......
...@@ -28,14 +28,16 @@ parameters, the second parameter is an optional object with ...@@ -28,14 +28,16 @@ parameters, the second parameter is an optional object with
information about the axis. It has min, max, tickDecimals, tickSize. information about the axis. It has min, max, tickDecimals, tickSize.
Added support for segmented lines (based on patch from Michael Added support for segmented lines (based on patch from Michael
MacDonald) and for ignoring null values (suggestion from Nick MacDonald) and for ignoring null and bad values (suggestion from Nick
Konidaris). Konidaris and joshwaihi).
Added support for changing the border width (joebno and safoo).
Label colors can be changed via CSS by selecting the tickLabel class.
Fixed a bug in handling single-item bar series (reported by Emil Fixed a bug in handling single-item bar series (reported by Emil
Filipov). Fixed erratic behaviour when interacting with the plot Filipov). Fixed erratic behaviour when interacting with the plot
with IE 7 (reported by Lau Bech Lauritzen). Prevent IE/Safari text with IE 7 (reported by Lau Bech Lauritzen). Prevent IE/Safari text
selection when selecting stuff on the canvas. The data is now selection when selecting stuff on the canvas.
implicitly converted to
......
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
backgroundColor: null, // null for transparent, else color backgroundColor: null, // null for transparent, else color
tickColor: "#dddddd", // color used for the ticks tickColor: "#dddddd", // color used for the ticks
labelMargin: 3, // in pixels labelMargin: 3, // in pixels
borderWidth: 2,
clickable: null, clickable: null,
coloredAreas: null, // array of { x1, y1, x2, y2 } or fn: plot area -> areas coloredAreas: null, // array of { x1, y1, x2, y2 } or fn: plot area -> areas
coloredAreasColor: "#f4f4f4" coloredAreasColor: "#f4f4f4"
...@@ -604,7 +605,7 @@ ...@@ -604,7 +605,7 @@
} }
// measure it // measure it
var dummyDiv = $('<div style="position:absolute;top:-10000px;font-size:smaller" class="gridLabel">' + max_label + '</div>').appendTo(target); var dummyDiv = $('<div style="position:absolute;top:-10000px;font-size:smaller" class="tickLabel">' + max_label + '</div>').appendTo(target);
labelMaxWidth = dummyDiv.width(); labelMaxWidth = dummyDiv.width();
labelMaxHeight = dummyDiv.height(); labelMaxHeight = dummyDiv.height();
dummyDiv.remove(); dummyDiv.remove();
...@@ -721,12 +722,14 @@ ...@@ -721,12 +722,14 @@
} }
ctx.stroke(); ctx.stroke();
// draw outline if (options.grid.borderWidth) {
ctx.lineWidth = 2; // draw border
ctx.strokeStyle = options.grid.color; ctx.lineWidth = options.grid.borderWidth;
ctx.lineJoin = "round"; ctx.strokeStyle = options.grid.color;
ctx.strokeRect(0, 0, plotWidth, plotHeight); ctx.lineJoin = "round";
ctx.restore(); ctx.strokeRect(0, 0, plotWidth, plotHeight);
ctx.restore();
}
} }
function drawLabels() { function drawLabels() {
...@@ -743,7 +746,7 @@ ...@@ -743,7 +746,7 @@
tick = xaxis.ticks[i]; tick = xaxis.ticks[i];
if (!tick.label || tick.v < xaxis.min || tick.v > xaxis.max) if (!tick.label || tick.v < xaxis.min || tick.v > xaxis.max)
continue; continue;
html += '<div style="position:absolute;top:' + (plotOffset.top + plotHeight + options.grid.labelMargin) + 'px;left:' + (plotOffset.left + tHoz(tick.v) - xBoxWidth/2) + 'px;width:' + xBoxWidth + 'px;text-align:center" class="gridLabel">' + tick.label + "</div>"; html += '<div style="position:absolute;top:' + (plotOffset.top + plotHeight + options.grid.labelMargin) + 'px;left:' + (plotOffset.left + tHoz(tick.v) - xBoxWidth/2) + 'px;width:' + xBoxWidth + 'px;text-align:center" class="tickLabel">' + tick.label + "</div>";
} }
// do the y-axis // do the y-axis
...@@ -751,7 +754,7 @@ ...@@ -751,7 +754,7 @@
tick = yaxis.ticks[i]; tick = yaxis.ticks[i];
if (!tick.label || tick.v < yaxis.min || tick.v > yaxis.max) if (!tick.label || tick.v < yaxis.min || tick.v > yaxis.max)
continue; continue;
html += '<div style="position:absolute;top:' + (plotOffset.top + tVert(tick.v) - labelMaxHeight/2) + 'px;left:0;width:' + labelMaxWidth + 'px;text-align:right" class="gridLabel">' + tick.label + "</div>"; html += '<div style="position:absolute;top:' + (plotOffset.top + tVert(tick.v) - labelMaxHeight/2) + 'px;left:0;width:' + labelMaxWidth + 'px;text-align:right" class="tickLabel">' + tick.label + "</div>";
} }
html += '</div>'; html += '</div>';
......
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