Re: [Jtreeview-users] Highlighting specific edges in JTV
Brought to you by:
alokito
|
From: Alok S. <al...@ca...> - 2007-02-20 18:16:19
|
Ah, it seems I misunderstood your question. Currently, there is no =20 way to represent relationships between pairs of nodes in java =20 treeview. I can think of two ways to do it: 1) The hard way to do it that would be in keeping with the java =20 treeview design would be to introduce some interface like HeaderInfo =20 that would capture the pairwise relationships on the nodes, add a =20 method to DataModel that makes it possible to retrieve the data =20 structure, and then modify the TreeDrawer to make use of it. You =20 would also have to introduce a new file format to keep track of =20 pairwise node relationships. 2) A much easier solution would be to add "LEFTCOLOR" and =20 "RIGHTCOLOR" columns to the GTR/ATR files, and then hack TreeColorer =20 and TreeDrawer to make use of those columns when "NODECOLOR" is not =20 present. You would also need to add two fields to TreeDrawerNode to =20 hold the left and right colors. If all three colors are present, you =20 could color the base of the node with NODECOLOR and the two branches =20 with the left and right. I would recommend #2, unless you plan on doing a lot with pairwise =20 node relationships, in which case #1 may pay off eventually. Let me =20 know if you plan to implement one of these, or something rather =20 different. #2 has the advantage that it could be implemented entirely =20= as a standalone plugin- just copy over the plugin/dendrogram source =20 tree and subclass TreeDrawerNode in the plugin, and use it when you =20 build the tree in TreeDrawer.setData(). If/when I adsorb it back into =20= the main source tree, I should be able to just overwrite the base =20 class with your TreeDrawerNode, and update the relevant classes in =20 plugin/dendrogram. Changing colors on the fly would work as described =20= in my previous email. -Alok On Feb 20, 2007, at 7:20 AM, Itamar Cohen wrote: > Hi Alok, > First of all, thanks for the quick response. As I understood from =20 > your response the only way to change colors is by changing the =20 > color of both edges coming out of the node (changing the color of =20 > A B C will change both the edges AB and AC). Is there a way to =20 > only change the color of one of them? > > Thanks, > Itamar Cohen > > CC: jtr...@li... > From: al...@ca... > Subject: Re: Highlighting specific edges in JTV > Date: Tue, 13 Feb 2007 15:21:28 -0800 > To: co...@ho... > > Hi Itamar, > > First of all, you should look at this example: > > http://jtreeview.sourceforge.net/examples/index.html#ex5 > > You can probably achieve the display that you want by actually hard-=20= > coding the colors in the GTR (gene tree) file. For example, > > NODEID LEFT RIGHT CORRELATION NODECOLOR > NODE1X GENE2268X GENE2269X 0.989404 #9900FF > > This indicates that the node named "NODE1X" which is formed by =20 > joining "GENE2268X" and "GENE2269X" should be colored "#9900FF" or =20 > bright purple. > > However, rather than preprocessing the GTR files and adding a =20 > column, you may want to add functionality to do this on the fly. =20 > The best way to do this is to write a plugin. I have written an =20 > example plugin that you should be able to read through as it is =20 > under 200 lines of code: > > https://sourceforge.net/docman/display_doc.php?=20 > docid=3D35149&group_id=3D84593 > > Your plugin shouldn't be too hard, depending on how exactly the =20 > coloring works. Here's one scheme that could work: > > 1) Write a class that extends PluginFactory. Look at the code for =20 > DataTableFactory from the example plugin to see how easy it can be. =20= > There are two ways you could make it work: > 1a) The selection of the file and coloring of the tree can happen =20 > within dialogs triggered by restorePlugin, which would then return =20 > null, or > 1b) restorePlugin returns a MainPanel that has a button that opens =20 > a file search dialog to locate the file with the color info, and a =20 > second button that loads it. > The advantage of 1b is that you can then have a list of common =20 > presets, if there are particular sorts of colorings you use often > > 2) Your write a method either in the PluginFactory or MainPanel =20 > that gets called with two parameters, 1) the name of the file with =20 > the coloring info, and 2) The viewFrame reference that was passed =20 > in to restorePlugin. It loads up the coloring info, and then calls =20 > viewFrame.getDataModel().getGtrHeaderInfo() to get the HeaderInfo =20 > representing the headers for the gene tree. > > 3) Call HeaderInfo.getHeaderIndex("NODECOLOR") to see if column =20 > exists, if not call HeaderInfo.addName("NODECOLOR", getNumHeaders=20 > ()), and check to make sure it returns true. > > 4) Traverse the gene tree headers to figure out which nodes to =20 > color what, and then call HeaderInfo.setHeader(nodeNumber, =20 > "NODECOLOR", "#9900FF"), with the appropriate node number and color =20= > of course. > > This may or may not work as planned... in particular, the updates =20 > from calling setHeader may not propagate all the way, as I don't =20 > have a plugin that works in quite this way yet. If you think it =20 > would be helpful, I could write up a quick test plugin that =20 > implements the above four steps and colors the nodes using a user-=20 > specified correlation threshold on the fly- i have been meaning to =20 > do this at some point anyways. > > I should also mention that you can get access to the state and data =20= > structures of the dendrogram (and in particular its in-memory tree =20 > of TreeDrawerNodes) by calling viewFrame.getMainPanelsByName=20 > ("Dendrogram"). it's straightforward, but a little more coding =20 > (although less coding than building your own tree of TreeDrawerNodes). > > All of the above only applies to the version of the code checked =20 > into CVS, there are a number of fixes made since the last =20 > release... in fact, I was planning to do a new release soon, since =20 > there are a few big problems in the last release. If there are any =20 > issues that need to be addressed for your plugin, it would be nice =20 > to do it before then. > > -Alok > > > On Feb 13, 2007, at 12:53 PM, Itamar Cohen wrote: > > Hi Alok, > > First of all, thanks for your response about height of subtrees, it =20= > was very helpful. We have a project now in which we are trying to =20 > highlight specific edges in a tree. I'm trying to alter the JTV =20 > code so it would read a list of node pairs and would show these =20 > edges in a different color. Could you suggest a simple way to =20 > enable this? > > Thanks, > Itamar > > Live Search: New search found Try it! > > > Find a local pizza place, movie theater, and more=85.then map the =20 > best route! Try it! |