Re: Some advice creating a graph class

From: Edward H. Fabrega (spiritualfields_at_wavecable.com)
Date: 02/20/05


Date: Sun, 20 Feb 2005 12:14:42 -0800


"rs" <removethis4spam.rastacey@nl.rogers.com> wrote in message
news:B_udnaD6CuV5LYXfRVn-iA@rogers.com...
>I am developing a program to draw a graph of database data using the
>OnPaint
> function in the View class.
> In the CView class I am grabbing the device context and then passing it to
> a
> function where I draw the actual graph by creating pens & brushes and
> using
> moveto/lineto functions etc.
>
> void CBView::OnPaint()
> {
> CPaintDC dc(this); // device context for painting
> DrawGraph(&dc);
> }
>
> This is working well but becoming quite large as a function and would
> think
> it is time to create a class to encapsulate the graph function.
> This seemed pretty straight forward until I started and realized it's not
> all that straight forward.
>
> Questions like what base class should this be derived from? How should the
> parameters be passed? etc.
>
> Any ideas, or tutorials or examples would be appreciated.
>
> Thanks.
>
>
>

Take a look at this. Are you trying to draw a grid like this?

http://members.aol.com/spiritualfields/main_screenshot.htm

That screen shot is of a CView drawn to reperesent a database. All of the
drawing takes place in the view. There is no way of keeping your OnPaint
small. It is a monumental task to draw and then populate the cells.
Especially if the "cell"s are really rectangles that you keep track of as
you draw the grid. If your only problem is that the function is big then you
have no problem. If you get more specific as to functionality, i.e. "how do
I keep track of the data?" "How do I scroll the window so that different
parts of the database are visible?" "How do I keep the column headers from
scrolling vertically" How do I keep the row headers from scrolling
horizontally?" How do I write into the cells from the database?" then I
might be able to help you, at least with the building of the grid. If you
are also building your database, then I might be able to help you there, as
well. Joe Newcomer's advice about letting OnPaint (I use OnDraw) worry about
drawing the grid is a good one, as it makes no sense to farm out painting
functionalilty to a function other than the one designed for painting.

Ed



Relevant Pages

  • Re: How do I create graph paper in Word or Excel?
    ... graph in a couple of minutes. ... Bring up the Draw menu by selecting View/Toolbars/Drawing. ... Ctrl key and drag a new line to the right one grid space. ... Deselect the Select Objects tool and add any titles you desire, ...
    (microsoft.public.word.drawing.graphics)
  • RE: How do I create graph paper in Word or Excel?
    ... How to create graph paper in Word ... Bring up the Draw menu by selecting View/Toolbars/Drawing. ... Ctrl key and drag a new line to the right one grid space. ... Deselect the Select Objects tool and add any titles you desire, ...
    (microsoft.public.word.drawing.graphics)
  • Re: Some advice creating a graph class
    ... I didn't realize I could use the dc in the view without passing it ... Are you trying to draw a grid like this? ... > That screen shot is of a CView drawn to reperesent a database. ...
    (microsoft.public.vc.mfc)
  • Re: Pre-draw part of JComponent
    ... > I have a class Graph that inherits JComponent. ... > graphs that all have exactly the same background grid. ... > graphics object when I redraw the component. ... Draw the grid into a BufferedImage. ...
    (comp.lang.java.gui)
  • ActiveFacts (was "ORM is the ...")
    ... how are contained in Terry Halpin's book "Information ... I'm a big fan of ORM2. ... I'm not a database wonk, but I play around a lot with graph- ... GRAph Theory in Ruby ...
    (comp.lang.ruby)