ShiboBrady / flot

Automatically exported from code.google.com/p/flot
MIT License
0 stars 0 forks source link

Add preprocessOffset and preDraw hooks #639

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, I'm using flot (0.7) about 2 weeks and see it's very flexible with plugins.
To enhance it's flexibility I suggest to add 2 hooks:
1) preprocessOffset(plot, offset) - for preparing initial offset, this will 
allow to have chart caption, padding, margin or whatever needed to be added on 
the canvas area. I've added this hook call in setupGrid() function of flot, 
right after string with initializing:
   plotOffset.left = plotOffset.right = plotOffset.top = plotOffset.bottom = 0;
++ executeHooks(hooks.preprocessOffset, [plotOffset]);

I'm using this hook in my plugins (see attached).

2) preDraw(plot, ctx) - this hook will help to draw on the canvas before flot. 
I'm using it for drawing chart borders and background. I've placed this hook 
call in draw() function right after clearing canvas call:
   ctx.clearRect(0, 0, canvasWidth, canvasHeight);
++ executeHooks(hooks.preDraw, [ctx]);

Attached files are:
1) jquery.flot.chart.js - this plugin for chart background and borders (used 
preprocessOffset and preDraw hooks);
2) jquery.flot.caption.js - this plugin for chart caption (used 
preprocessOffset hook);

To use them both first should be included jquery.flot.chart.js, then 
jquery.flot.caption.js, because caption offset depends on chart borders, margin 
and padding.

Original issue reported on code.google.com by milke...@gmail.com on 25 Nov 2011 at 11:31

Attachments:

GoogleCodeExporter commented 8 years ago
oops... attached dev version, remove console.log in jquery.flot.chart.js before 
using

Original comment by milke...@gmail.com on 25 Nov 2011 at 12:03

GoogleCodeExporter commented 8 years ago
The master branch now has two new hooks called 'processOffset' and 
'drawBackground', corresponding almost exactly to the 'preprocessOffset' and 
'preDraw' hooks that you suggested.  The names are slightly different, for 
better consistency with the existing hook names.

There is also a new grid option called 'margin' that allows one to specify a 
margin around the plot, either as a single value or individual 
top/bottom/left/right values.  While the same can be done with the 
processOffset hook, an option makes more sense for end-users who simply want to 
set the value on plot creation.  The hook is intended for plugins, where there 
may be multiple plugins each adjusting the margin to make room for their output.

Original comment by dnsch...@gmail.com on 30 Apr 2012 at 4:30

GoogleCodeExporter commented 8 years ago
Issue 508 has been merged into this issue.

Original comment by dnsch...@gmail.com on 30 Apr 2012 at 5:47

GoogleCodeExporter commented 8 years ago
Issue 400 has been merged into this issue.

Original comment by dnsch...@gmail.com on 30 Apr 2012 at 5:52