PROBLEM: I recently had a need to draw dynamic, alternate background shading in
the space *behind* the grid, yet at a point in the plotting process when the
grid parameters & series data had already been defined.
ISSUE: the 'draw' hook executes only after both the grid and series data have
been drawn. this can become a problem for IE, since compositing still isnt
available in excanvas, and anything drawn using this hook will be placed on top
of the grid & series graphics (this is not always the desired result).
SOLUTION: the ideal solution would be to either move the call to the draw hook
a few lines up, or create a new 'pre-grid-draw' hook that fires before the grid
is drawn, yet once the grid has been defined & series data have been processed.
i.e., in the draw function...
function draw(){
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
var grid = options.grid;
executeHooks(hooks.draw,[ctx]); /*hook is now here*/
if (grid.show && ! grid.aboveData)drawGrid();
for (var i = 0;i < series.length; ++ i)drawSeries(series[i]);
/*executeHooks(hooks.draw,[ctx]); hook was previously here*/
if (grid.show && grid.aboveData)drawGrid();
}
here's an example of my implementation
http://www.changosurf.com/dev/test/
the above plot wasn't previously possible in IE; the plot background shading
would completely mask the plot graphics (even when using the draw hook in its
original form), and compositing was impossible in IE. it was possible to mimic
in other browsers by using canvas tag's 'globalCompositeOperation' setting and
by using flot's unmodified 'draw' hook.
Since this plot shading deals with sunrise&sunset times, the shading intervals
are dynamic, so the shade drawing routine depends on the grid & data series
being setup beforehand in order to properly determine where to draw the day &
night shades; the earlier hooks (those before the 'draw' hook) also won't work,
since neither the grid nor series data have been setup yet.
Original issue reported on code.google.com by changos...@gmail.com on 23 Aug 2010 at 7:43
Original issue reported on code.google.com by
changos...@gmail.com
on 23 Aug 2010 at 7:43