From 4ee1e04e19c739d16a641b1fa224e8f320ad55db Mon Sep 17 00:00:00 2001 From: David Schnur Date: Wed, 25 Apr 2012 10:36:56 -0400 Subject: [PATCH] Added processOffset and drawBackground hooks --- API.txt | 27 +++++++++++++++++++++++---- jquery.flot.js | 10 ++++++++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/API.txt b/API.txt index 61d2f34..f25110f 100644 --- a/API.txt +++ b/API.txt @@ -919,8 +919,8 @@ can call: - pointOffset({ x: xpos, y: ypos }) Returns the calculated offset of the data point at (x, y) in data - space within the placeholder div. If you are working with multiple axes, you - can specify the x and y axis references, e.g. + space within the placeholder div. If you are working with multiple + axes, you can specify the x and y axis references, e.g. o = pointOffset({ x: xpos, y: ypos, xaxis: 2, yaxis: 3 }) // o.left and o.top now contains the offset within the div @@ -1114,6 +1114,25 @@ hooks in the plugins bundled with Flot. doesn't check it or do any normalization on it afterwards. + - processOffset [phase 4] + + function(plot, offset) + + Called after Flot has initialized the plot's offset, but before it + draws any axes or plot elements. This hook is useful for customizing + the margins between the grid and the edge of the canvas. "offset" is + an object with attributes "top", "bottom", "left" and "right", + corresponding to the margins on the four sides of the plot. + + + - drawBackground [phase 5] + + function(plot, canvascontext) + + Called before all other drawing operations. Used to draw backgrounds + or other custom elements before the plot or axes have been draw. + + - drawSeries [phase 5] function(plot, canvascontext, series) @@ -1121,8 +1140,8 @@ hooks in the plugins bundled with Flot. Hook for custom drawing of a single series. Called just before the standard drawing routine has been called in the loop that draws each series. - - + + - draw [phase 5] function(plot, canvascontext) diff --git a/jquery.flot.js b/jquery.flot.js index 0db9fe1..e75a9ce 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -152,6 +152,8 @@ processOptions: [], processRawData: [], processDatapoints: [], + processOffset: [], + drawBackground: [], drawSeries: [], draw: [], bindEvents: [], @@ -1024,7 +1026,9 @@ // init plot offset for (var a in plotOffset) plotOffset[a] = showGrid ? options.grid.borderWidth : 0; - + + executeHooks(hooks.processOffset, [plotOffset]); + // init axes $.each(axes, function (_, axis) { axis.show = axis.options.show; @@ -1035,7 +1039,7 @@ setRange(axis); }); - + if (showGrid) { // determine from the placeholder the font size ~ height of font ~ 1 em var fontDefaults = { @@ -1441,6 +1445,8 @@ function draw() { ctx.clearRect(0, 0, canvasWidth, canvasHeight); + executeHooks(hooks.drawBackground, [ctx]); + var grid = options.grid; // draw background, if any