Commit 8a78e8f8 authored by olau@iola.dk's avatar olau@iola.dk

Added support for gradients, currently only used for the grid background

git-svn-id: https://flot.googlecode.com/svn/trunk@129 1e0a6537-2640-0410-bfb7-f154510ff394
parent c9429505
...@@ -472,7 +472,7 @@ Customizing the grid ...@@ -472,7 +472,7 @@ Customizing the grid
grid: { grid: {
color: color color: color
backgroundColor: color or null backgroundColor: color/gradient or null
tickColor: color tickColor: color
labelMargin: number labelMargin: number
markings: array of markings or (fn: axes -> array of markings) markings: array of markings or (fn: axes -> array of markings)
...@@ -484,13 +484,11 @@ Customizing the grid ...@@ -484,13 +484,11 @@ Customizing the grid
mouseActiveRadius: number mouseActiveRadius: number
} }
The grid is the thing with the axes and a number of ticks. "color" The grid is the thing with the axes and a number of ticks. "color" is
is the color of the grid itself whereas "backgroundColor" specifies the color of the grid itself whereas "backgroundColor" specifies the
the background color inside the grid area. The default value of null background color inside the grid area. The default value of null means
means that the background is transparent. You should only need to set that the background is transparent. You can also set a gradient, see
backgroundColor if you want the grid area to be a different color from the the gradient documentation below.
page color. Otherwise you might as well just set the background color
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. Note that you can style the tick between tick labels and the grid. Note that you can style the tick
...@@ -638,6 +636,24 @@ vertical crosshair that lets you trace the values on the x axis, "y" ...@@ -638,6 +636,24 @@ vertical crosshair that lets you trace the values on the x axis, "y"
enables a horizontal crosshair and "xy" enables them both. enables a horizontal crosshair and "xy" enables them both.
Specifying gradients
====================
A gradient is specified like this:
{ colors: [ color1, color2, ... ] }
For instance, you might specify a background on the grid going from
black to gray like this:
grid: {
backgroundColor: { colors: ["#000", "#999"] }
}
Flot currently only supports vertical gradients drawn from top to
bottom because that's what works with IE.
Plot Methods Plot Methods
------------ ------------
......
...@@ -25,8 +25,12 @@ Changes: ...@@ -25,8 +25,12 @@ Changes:
$.plot.formatDate(...) (suggestion by Matt Manela) and even $.plot.formatDate(...) (suggestion by Matt Manela) and even
replaced. replaced.
- Added "borderColor" option to the grid (patch from achamayou and - Added "borderColor" option to the grid (patch from Amaury Chamayoau
patch from Mike R. Williamson). and patch from Mike R. Williamson).
- Added support for gradient background for the grid, take a look at
the "setting options" example (based on patch from Amaury Chamayou,
issue 90).
Bug fixes: Bug fixes:
......
...@@ -53,7 +53,7 @@ $(function () { ...@@ -53,7 +53,7 @@ $(function () {
max: 2 max: 2
}, },
grid: { grid: {
backgroundColor: "#fffaff" backgroundColor: { colors: ["#fff", "#eee"] }
} }
}); });
}); });
......
...@@ -858,7 +858,7 @@ ...@@ -858,7 +858,7 @@
// draw background, if any // draw background, if any
if (options.grid.backgroundColor) { if (options.grid.backgroundColor) {
ctx.fillStyle = options.grid.backgroundColor; ctx.fillStyle = getColorOrGradient(options.grid.backgroundColor);
ctx.fillRect(0, 0, plotWidth, plotHeight); ctx.fillRect(0, 0, plotWidth, plotHeight);
} }
...@@ -1522,7 +1522,7 @@ ...@@ -1522,7 +1522,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) if (options.grid.backgroundColor && typeof options.grid.backgroundColor == "string")
tmp = options.grid.backgroundColor; tmp = options.grid.backgroundColor;
else else
tmp = extractColor(legend); tmp = extractColor(legend);
...@@ -2015,6 +2015,22 @@ ...@@ -2015,6 +2015,22 @@
return Math.abs(selection.second.x - selection.first.x) >= minSize && return Math.abs(selection.second.x - selection.first.x) >= minSize &&
Math.abs(selection.second.y - selection.first.y) >= minSize; Math.abs(selection.second.y - selection.first.y) >= minSize;
} }
function getColorOrGradient(spec) {
if (typeof spec == "string")
return spec;
else {
// assume this is a gradient spec; IE currently only
// supports a simple vertical gradient properly, so that's
// what we support too
var gradient = ctx.createLinearGradient(0, 0, 0, plotHeight);
for (var i = 0, l = spec.colors.length; i < l; ++i)
gradient.addColorStop(i / (l - 1), spec.colors[i]);
return gradient;
}
}
} }
$.plot = function(target, data, options) { $.plot = function(target, data, options) {
......
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