0

Is there a well documented way to draw an oriented graph or tree in the C# language, without using external libraries?

Hazel へいぜる
  • 2,751
  • 1
  • 12
  • 44

3 Answers3

0

you should be able use the System.Drawing namespace to draw and then just do the math and computational stuff yourself.

willz
  • 2,020
  • 3
  • 21
  • 24
  • Just because you mentioned it: What are common algorithms for positioning graph nodes and edges with less intersections as possible? Can you provide any names I could look up? I used a spring attraction/distraction method years ago... – fjdumont Sep 30 '11 at 10:08
  • 2
    Yes, spring layout is one common technique; another is known as 'Sugiyama'. GraphViz supports a couple of different techniques. There is no single algorithm that always does well. See e.g. http://stackoverflow.com/questions/2347748/planar-graph-layouts – reinierpost Oct 31 '11 at 10:32
0

Yes. You'll use the System.Drawing namespace (more info here). You'll want to create a virtual canvas large enough to handle your widest and tallest extents. These can be calculated by figuring the number of leaves in your tree (it is a bit more difficult with a graph) and then adding a spacing factor, etc.

It isn't a hard problem but it is tedious. It took me about a day several years ago. Sorry but I abandoned the interface as too clumsy and didn't keep the code.

Mark Brittingham
  • 28,545
  • 12
  • 80
  • 110
0

Yes, use the System.Drawing namespace, which contains drawing functions/classes.

Basically to draw, you do this:

Bitmap bmp = new Bitmap(width, height);
Image img = bmp;
Graphics g = Graphics.FromImage(img);

Then use g.FillRectangle , g.DrawLine, g.DrawString etc.

Remember that 0,0 is on top left though :)

Rafalon
  • 4,450
  • 2
  • 16
  • 30
Spikolynn
  • 4,067
  • 2
  • 37
  • 44