TreeView's Dendrogram for any data?

  • sylvara

    sylvara - 2008-04-09

    Greetings -
    I have been tasked to implement a clustering algorithm to analyze some data.  I must also present the results of this clustering in the form of a dendrogram.  In searching the web for pre-existing Java tools to help with this, I came across TreeView.  I have looked through the documentation, and I am still unsure whether or not it is possible to incorporate just the Dendrogram components of the TreeView code into my code for the data I am analyzing.
    Is this possible?  If so, where should I start?

    • Alok Saldanha

      Alok Saldanha - 2008-04-11

      First of all, let me suggest that your program output a .CDT file that you then view with java treeview. It is not as nice a user experience, but it will greatly reduce developer time.

      If you want to incorporate parts of java treeview into another program, most likely you will need to rewrite it somewhat. I actually have two classes that do tree drawing, the LeftTreeDrawer for the gene tree, and the InvertedTreeDrawer for the ArrayTrees.  All of the actual drawing is triggered by calls similar to

                          xScaleEq, yScaleEq,
                          destRect, selectedNode, false);

      Where drawer is an instance of either LeftTreeDrawer or InvertedTreeDrawer, offscreen graphics is a standard Graphics object, xScaleEq and yScaleEq are LinearTransformation objects that describe how the x and y axis are to be scaled, and destRect is a Rectangle describing where in the offscreenGraphics to draw, and selectedNode is a TreeDrawerNode representing the root node of the subtree to be drawn.

      If you want to use the tree drawers, you will need to build a tree of TreeDrawerNodes, which are defined by the following

          private double corr = 0.0;
          private double ind = -1;
          private TreeDrawerNode parent = null;
          private TreeDrawerNode left = null;
          private TreeDrawerNode right = null;
          private String id = null;
          private Color color =;

      corr and ind determine height from base of tree and position on the tree respectively. The corr should go from 0 to 1, and the ind should be between 0 and n where n is the number of nodes in the tree. You can compensate for other mappings by changing the LinearTransformations appropriately.

      If you decided not to use the classes after all, you can still take a look at the paintSubtree function (or more directly, the NodeDrawer.draw function) - most likely, you will need to write something similar in your own tree drawer class.

      Good luck!

    • sylvara

      sylvara - 2008-04-16

      Thank you!  I am currently looking for a very rapid way to prototype a potential use we might have for clustering.  In other words, I want instant gratification! :)  However, I will keep this in mind if we end up using clustering techniques and need to draw dendrograms.

      • Alok Saldanha

        Alok Saldanha - 2008-04-16

        If you want instant gratification, stop writing code and cluster using cluster 3.0

        then view with java treeview. Or, if cluster 3.0 does not cluster the way you want, then fix it or write a quick python script to do whatever you had in mind.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks