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

Make it possible to set the fill opacity by setting fill to a number

git-svn-id: https://flot.googlecode.com/svn/trunk@64 1e0a6537-2640-0410-bfb7-f154510ff394
parent 4b5dc00d
...@@ -348,10 +348,10 @@ Customizing the data series ...@@ -348,10 +348,10 @@ Customizing the data series
=========================== ===========================
lines, points, bars: { lines, points, bars: {
show: boolean, show: boolean
lineWidth: number, lineWidth: number
fill: boolean, fill: boolean or number
fillColor: color or null fillColor: color
} }
points: { points: {
...@@ -376,14 +376,19 @@ and Flot will happily draw each of them in turn, e.g. ...@@ -376,14 +376,19 @@ and Flot will happily draw each of them in turn, e.g.
points: { show: true, fill: false } points: { show: true, fill: false }
}; };
"lineWidth" is the thickness of the line or outline and "fill" is "lineWidth" is the thickness of the line or outline in pixels.
whether the shape should be filled. For lines, this produces area
graphs. If "fillColor" is null (default), the color for the data "fill" is whether the shape should be filled. For lines, this produces
series is used. area graphs. You can use "fillColor" to specify the color of the fill.
If "fillColor" evaluates to false (default for everything except
points), the fill color is auto-set to the color of the data series.
You can adjust the opacity of the fill by setting fill to a number
between 0 (fully transparent) and 1 (fully opaque).
Note that the options that take numbers works in units of pixels, but "barWidth" is the width of the bars in units of the x axis, contrary
"barWidth" is the width of the bars in units of the x axis (e.g. for to most other measures that are specified in pixels. For instance, for
time series it's in milliseconds). time series the unit is milliseconds so 24 * 60 * 60 * 1000 produces
bars with the width of a day.
The "colors" array specifies a default color theme to get colors for The "colors" array specifies a default color theme to get colors for
the data series from. You can specify as many colors as you like, like the data series from. You can specify as many colors as you like, like
......
...@@ -5,6 +5,9 @@ Added support for specifying the size of tick labels (axis.labelWidth, ...@@ -5,6 +5,9 @@ Added support for specifying the size of tick labels (axis.labelWidth,
axis.labelHeight). Useful for specifying a max label size to keep axis.labelHeight). Useful for specifying a max label size to keep
multiple plots aligned. multiple plots aligned.
The "fill" option can now be a number that specifies the opacity of
the fill.
Fixed a bug in calculating spacing around the plot (reported by Fixed a bug in calculating spacing around the plot (reported by
timothytoe). Fixed a bug in finding max values for all-negative data timothytoe). Fixed a bug in finding max values for all-negative data
sets. Prevent the possibility of eternal looping in tick calculations. sets. Prevent the possibility of eternal looping in tick calculations.
......
...@@ -784,7 +784,7 @@ ...@@ -784,7 +784,7 @@
ctx.translate(plotOffset.left, plotOffset.top); ctx.translate(plotOffset.left, plotOffset.top);
// draw background, if any // draw background, if any
if (options.grid.backgroundColor != null) { if (options.grid.backgroundColor) {
ctx.fillStyle = options.grid.backgroundColor; ctx.fillStyle = options.grid.backgroundColor;
ctx.fillRect(0, 0, plotWidth, plotHeight); ctx.fillRect(0, 0, plotWidth, plotHeight);
} }
...@@ -1141,11 +1141,9 @@ ...@@ -1141,11 +1141,9 @@
ctx.lineWidth = lw; ctx.lineWidth = lw;
ctx.strokeStyle = series.color; ctx.strokeStyle = series.color;
if (series.lines.fill) { setFillStyle(series.lines, series.color);
ctx.fillStyle = series.lines.fillColor != null ? series.lines.fillColor : parseColor(series.color).scale(null, null, null, 0.4).toString(); if (series.lines.fill)
plotLineArea(series.data, 0); plotLineArea(series.data, 0);
}
plotLine(series.data, 0); plotLine(series.data, 0);
ctx.restore(); ctx.restore();
} }
...@@ -1200,7 +1198,7 @@ ...@@ -1200,7 +1198,7 @@
ctx.lineWidth = series.points.lineWidth; ctx.lineWidth = series.points.lineWidth;
ctx.strokeStyle = series.color; ctx.strokeStyle = series.color;
ctx.fillStyle = series.points.fillColor != null ? series.points.fillColor : series.color; setFillStyle(series.points, series.color);
plotPoints(series.data, series.points.radius, series.points.fill); plotPoints(series.data, series.points.radius, series.points.fill);
ctx.restore(); ctx.restore();
} }
...@@ -1291,14 +1289,19 @@ ...@@ -1291,14 +1289,19 @@
ctx.lineWidth = lw; ctx.lineWidth = lw;
ctx.strokeStyle = series.color; ctx.strokeStyle = series.color;
if (series.bars.fill) { setFillStyle(series.bars, series.color);
ctx.fillStyle = series.bars.fillColor != null ? series.bars.fillColor : parseColor(series.color).scale(null, null, null, 0.4).toString();
}
plotBars(series.data, bw, 0, series.bars.fill); plotBars(series.data, bw, 0, series.bars.fill);
ctx.restore(); ctx.restore();
} }
function setFillStyle(obj, seriesColor) {
var fill = obj.fill;
if (fill) {
ctx.fillStyle = obj.fillColor ? obj.fillColor : parseColor(seriesColor).scale(null, null, null, typeof fill == "number" ? fill : 0.4).toString();
}
}
function insertLegend() { function insertLegend() {
target.find(".legend").remove(); target.find(".legend").remove();
...@@ -1352,7 +1355,7 @@ ...@@ -1352,7 +1355,7 @@
var c = options.legend.backgroundColor; var c = options.legend.backgroundColor;
if (c == null) { if (c == null) {
var tmp; var tmp;
if (options.grid.backgroundColor != null) if (options.grid.backgroundColor)
tmp = options.grid.backgroundColor; tmp = options.grid.backgroundColor;
else else
tmp = extractColor(legend); tmp = extractColor(legend);
......
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