Question

Tree Drawing in .NET (C#)

Asked by: Jazzle

Hi,
I need to dynamically draw (graphical) trees to represent simple prefix-notation maths sum, such as "+*xxx" [equal to (x*x)+x ], which would drawn as follows:
'+' at the root, '*' on the root's left branch (with an 'x' as both its leaves), and an 'x' on the root's right branch (a leaf).
(hope that makes sense, though hopefully it doesn't matter if it doesn't)

What I need is a plug-in that can draw these trees given just a string of the sum.
I assume I need free evaluation/demo software for the moment, because I only need to demonstrate the possibilities.
If there's some way of doing this using nothing extra that would be great, but I doubt it.

Any suggestions?  Thanks in advance...

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-01-07 at 04:47:26ID20843405
Tags

tree

,

draw

Topic

.NET

Participating Experts
2
Points
301
Comments
21

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Drawing
    Hello, Q. I want to draw many repetitive shapes (using a shape component called TManyShapes) on a canvas (I have am using TImage). Firstly, by using a PROCEDURE or FUNCTION how can I create many (alot of) shapes on that canvas (TImage) without having a conflict a similiar na...
  2. Drawing a tree in delphi?
    I need to draw a tree using delphi, I guess the best component available is Toutline?? Anyhow, I can draw nodes on this tree easily using Outline1.Insert(0,'a node'); But I can't seem to figure out how to draw a children for that node... ie how do i draw this (help me wit...
  3. Drawing Utility
    I developed a little drawing utility for shapes and lines. Problem is, once you draw a shape or line, and mouse-up, the next mouse down wipes everything away and starts over. Here is the code, so far; Controls Needed: Label1, Label2, Label3, Label4, Option1, Option2, Opt...
  4. Drawing Ellipses
    I can draw ellipses and other shapes. How do i tell if i have clicked on a ellipse.
  5. Drawing Binary Tree
    Well, how can we draw a binary tree for example in HTML (with nodes = rectangles or circles)

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: malharonePosted on 2004-01-07 at 09:18:56ID: 10063454

Is this for display purpose only or for parsing and then computing ?
Look into INORDER trees/graph structures.

 

by: JazzlePosted on 2004-01-07 at 09:28:33ID: 10063540

it's for display purposes only, and just one tree at a time.

 

by: malharonePosted on 2004-01-07 at 09:32:48ID: 10063572

first given any string .. you'd need to set your order of operation -- eg. operator predescence (i donno if that's the correct spelling)

So given
1+2*3+4/6

you'd have


+  1
    *  2
        3
    /   4
        6


is that right?

 

by: JazzlePosted on 2004-01-07 at 09:41:10ID: 10063646

in fact it's easier that than because the string would be in prefix notation:
e.g.  +xy  for x+y  and +*xyz for (x*y)+z

so,  +*xyz  would look like:

    +
   / \
  *   z
 / \
x   y

The real question is, how do I get the system to draw this?

 

by: malharonePosted on 2004-01-07 at 09:43:31ID: 10063663

well .. you can't really draw the real trees using the built in controls. you can create a control to owner draw this type of tree. but then you'd have to re-implement the "+" & "-" -- expand and collapse capabilities in addition to formatting .. etc.

so better stick to the Win Explorer format -- using Tree View.

 

by: JazzlePosted on 2004-01-07 at 09:54:32ID: 10063782

not really what i was after. and i don't need to expand or collapse branches.

i was hoping there would be a simple way to draw lines and single chars given an input string...
if i get desperate, i might have to do it with ascii!

 

by: malharonePosted on 2004-01-07 at 09:55:36ID: 10063796

then you're better off with ASCII ... but even with ASCII you dont have easy way of determining spacing between the elements.

 

by: JazzlePosted on 2004-01-07 at 09:59:18ID: 10063843

that's one of the biggies.

i hope someone knows of some software that could do it... (a graphical control of some sort.)

 

by: malharonePosted on 2004-01-07 at 10:03:21ID: 10063883

checkout: http://www.seanet.com/users/arsen/avltree.html
very neat .. and should give you idea for drawing trees. in .net to draw graphics ... use this
System.Drawing.Graphics g=this.CreateGraphics();
g.DrawLine(new System.Drawing.Pen(Color.Red),1,1,100,100);
g.<MANY DRAWING FUNCTIONS ... e.g. drawarc, drawrectangle, drawcircle, et.c..>

 

by: JazzlePosted on 2004-01-07 at 10:14:39ID: 10063998

have had a look at the page, and the applet - although i agree it is very neat, i need more of a solution in C# or a way to create a solution in MS VS2002/3.

 

by: farsightPosted on 2004-01-07 at 11:39:20ID: 10064810

There's a product that I had in mind (vaguely) because I remembered some graph layouts that impressed me.  I had to do some searching to find it.

I don't know how much work this would take to use for your application, but it would be sure to create a visually appealing result.  It does do automatic layout, though I don't know how closely that matches your application.  See the diagrams and explanation near the top of the second link.

Tom Sawyer products
http://www.tomsawyer.com/products.html
...
Graph Layout Toolkit  (C++) -- shows good diagrams of their technology
http://www.tomsawyer.com/glt/index.html
...
The Graph Editor Toolkit for the Microsoft Development Community (.NET)
http://www.tomsawyer.com/get/get-windows.html

Cool, huh?


--- --- ---
Other tools I found during my search.  These are not very on-target, but might still be useful.

MetaDraw
http://www.bennet-tec.com/btproducts/metadraw/metadraw.htm

AddFlow
http://www.lassalle.com/afnet.htm

RFFlow
http://www.rff.com/

Process Chart
http://www.processchart.com/

FlowChartX
http://mindfusion.org/download.html
http://mindfusion.org/gallery6.html

 

by: JazzlePosted on 2004-01-07 at 11:52:52ID: 10064918

from a quick look at these, some may prove useful.  i will get back to you all when i've had a better look at them.
thanks, and don't hesitate to suggest others. (the software must draw the tree for me, with very simple text input.)

 

by: farsightPosted on 2004-01-07 at 12:39:40ID: 10065292

(By the way, don't waste a lot of time on those "not on-target" links.  If they don't look right, just move on.)

Here's a couple more on-target that look very promising, though.

daVinci Presenter
http://www.b-novative.com/developer/dv30_doc/conc_lay.html
http://www.b-novative.com/developer/dv30_doc/term.html
(You could probably do simple text-processing to convert your input strings to their format.)
http://www.b-novative.com/developer/dv30_doc/term_exam.html
Brochure (with diagrams)
http://download.b-novative.com/daVinci_Presenter_Handout_Englisch.pdf

Graphlet, Graphscript
http://www.infosun.fmi.uni-passau.de/Graphlet/index.html

---
Great list of graph drawing tools (Some I've found, some new.)
http://i11www.informatik.uni-karlsruhe.de/algo/cosin/tools.html

---
You might find good info at http://graphdrawing.org
book list:
http://graphdrawing.org/literature/content.html

---
Another aside -- this one you'll probably find interesting.
For math notation, not graphs.

MathML .NET Control 1.0
http://www.dnzone.net/ShowDetail.asp?NewsId=185

---

Hmmmm ... getting a bit carried away here!

 

by: farsightPosted on 2004-01-07 at 12:42:28ID: 10065318

Ok, one more ...

Graphviz -- open source graph drawing software
http://www.research.att.com/~north/graphviz/

There seems to be a lot more available in Java, Unix, etc. rather than .NET.

 

by: JazzlePosted on 2004-01-07 at 14:28:15ID: 10066401

> There seems to be a lot more available in Java, Unix, etc. rather than .NET.
I do wish I could do it in Java, but have to use C++/C# for the speed. (Genetic Programming is the main task for my system)

 

by: JazzlePosted on 2004-01-07 at 14:32:40ID: 10066449

I will be back in a couple of days when I expect to dish out the points!

 

by: JazzlePosted on 2004-01-22 at 10:09:32ID: 10175998

anything further anyone?

 

by: farsightPosted on 2004-01-24 at 06:38:23ID: 10190975

Jazzle,
This is the last I'll have for this question, but feel free to contact me (via info in my profile).  I'm a bit interested in your project.   It would be cool if you could leave an update/status here sometime in the future -- particularly about the graphics/layout solution you finally implement, but also about the project in general.

I'm going to try using Netron (see below) for a project I'm just beginning.  Looks promising.  I just downloaded it, but haven't installed yet.

DRAWING
What have you determined about all the above posts for drawing solutions?  Anything at all interesting?
I'm pretty sure you'll need to write something yourself for your particular application.  You've got lots of choices for doing the graphics,m even just the System.Drawing namespace.  Perhaps that would be the "simple way to draw lines and single chars given an input string" you mentioned way up top.  If you do use System.Drawing you'll have to write-your-own layout code.

LAYOUT
If you need an algorithm to properly layout the tree, do a search on "layout algorithm" or "graph layout algorithm" or "tree layout algorithm".  Or you could come up with your algorithm for this simple case:  I guess every node would have 0, 1, or 2 children.  You could start with a simple, naive implementation, with one child a bit to the left, and the other a bit to the right.  That's result in overlap.  Then you can tweak and tune the algorithm to avoid overlap.  If you do the layout from the bottom upwards, each node should be able to look at the left-bound and right-bound of the left and right sub-trees, and determine how far left and right they need to be placed.

MORE DRAWING TOOLS

The Netron Project    (includes some? layout, free, beta, see license)
http://sourceforge.net/projects/netron/

GoDiagram for Microsoft .NET   ($$)
http://www.nwoods.com/GO/dotnet.htm
http://www.godotnetweb.com/samples/  (for the ASP.NET version)
The TreeApp and AutoLayout Demo samples may be close to what you need.


 

by: JazzlePosted on 2004-01-25 at 05:22:35ID: 10195007

thanks to farsight, and to malharone.
points split as appropriate.

 

by: JazzlePosted on 2005-03-29 at 02:33:23ID: 13651161

this is long overdue, but I thought I shold say what I did in the end.
I used that last suggestion, Northwoods, with a free educational license.

My diss is at http://www.jazzle.co.uk/GPGUI.pdf (1.74MB PDF )and contains some more info if you're interested.

 

by: farsightPosted on 2005-03-29 at 09:24:23ID: 13654312

Thanks for the feedback.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...