I have, more or less, been struggling with this problem since
I first began programming with Delphi, back in 1996.
In Turbo Pascal for DOS, there was a SetViewPort procedure
that allowed us to define a plotting region outside of which
lines would be clipped off. No such thing seems to exist in
Delphi (ClipRect is a read-only property).
The way I have managed to circumvent this was to put two TImage
objects, one on top of the other:
- an underlying GraphImage which will hold the complete graph
(with titles, border, tick box, labels, axes, together with
the plot itself inside the viewport)
- a transparent overlying, but smaller, MathImage which will
hold only the plot inside the viewport.
The graphical elements inside MathImage will always be directly
superposed to their copy on the GraphImage.
Producing a graph usually involves:
- drawing a border or a tick box or just axes and writing
titles and labels on the GraphImage
- plotting the graph on the MathImage and, at the end of the
process, copying the result on the underlying GraphImage
- printing or saving the GraphImage to disk.
This works fine, except for a few problems:
a) issuing a MathImage.Update command produces flicker. This
is solely because of the underlying GraphImage, otherwise
it would not happen. Just hiding the GraphImage is even
enough to eliminate the flicker.
b) I have not found a way to put into a single component the
two TImage objects and their associated procedures. In
fact, I strongly suspect that this cannot be done unless
both are placed in a single container like a Panel.
c) a small experiment I have done showed that plotting on a
PaintBox would be about two times faster than plotting
on an Image. I nevertheless prefer working with images
since, contrary to a PaintBox, an Image covered by a
window will automatically redraw itself. This is a nice
feature especially when working with complex graphs.
Since I already have a few thousand lines of code referring to
GraphImage and MathImage, the best thing for me would be to
work with a single Image (this would be my GraphImage) and a
sub-region of it which could be referred to as my MathImage.
Is there a way to do this?
I would also appreciate any other suggestion. The graph units
I am working on will be used for most of my major projects so
I would really like to have a firm basis.