Hi Damien,
Yes, it is possible to customise the links more. For this, you will have to modify the velocity template d3graph/templates/d3graph.vhtml. This is an Apache Velocity template that generates the html code for the webpage. The part that you need to edit is actually generating a Javascript table which is the data model for the graph. In the browser, having loaded up the graph page, if you just view the source, you'll find a large Javascript table in a script tag. It's essentially a list of nodes and links. This data is then passed on to create the visual representation. By changing what's included in this table you can make the visualisation include or exclude only certain things.
So what we need to do is modify the velocity template so that only the desired nodes and links get put in that Javascript data structure. First, to remove the instance-class relationships, you can just remove this section in the code. For me this starts on line 166, but it might be slightly different for you as our files might not be exactly identical at this point.
- Code: Select all
#* *##if($topicMap.getTopics().size > 0 && $doneAssocs.size() > 0)
#* *#,
#* *##end
#* *##set( $ntopics = $listmaker.make() )
#* *##set( $j = 0)
#* *##foreach ( $topic in $topics )
#* *##set($temp = $ntopics.add($topic))
#* *##set( $j = $j + 1)
#* *##if($j == $n)
#* *##break
#* *##end
#* *##end
#* *##foreach( $topic in $ntopics )
#* *##set( $types = $topic.getTypes() )
#* *##foreach( $type in $types )
#* *##if($topicHashMap.get($type.getID()) && $topicHashMap.get($topic.getID()))
#* *##if($i > 0)
#* *#,
#* *##end
#* *#{
#* *#"source" : $topicHashMap.get($type.getID()),
#* *#"target" : $topicHashMap.get($topic.getID()),
#* *#"class" : "type",
#* *#"id" : "link$i"
#* *#}
#* *##set($i = $i + 1)
#* *##end
#* *##end
#* *##end
Then, if you want to remove some topics completely, you need to make modifications to the $topics array. This is constructed at the start of the script section, for me, starting at line 48. You could add any kind of if clauses here to limit what kind of topics are included. For example, you could do something like #if( $topic.isOfType( $someOtherTopic) ) . The very first line of the template demonstrates how to get $someOtherTopic with a subject identifier. Look for the $topics.add( ) lines, putting the if statement around those should restrict what topics get included. Note that these are inside #set statements due to limitations in the velocity language.
You can similarly affect what associations are included. The links section of the javascript data structure is generated starting at line 134. Here you could add an if statement based on $assoc.getType() and only include certain types of association, for example.
More complicated modifications are possible too. You just need to change the code to only include the things you want visualised.
A couple of notes about the Velocity template language, in case you are not familiar with it. It's much like most other template languages. By default, everything gets output verbatim. Then you can include various control logic statements with a hash sign #. For example #if( something) ... #end . Then only if something is true, the thing between the if and end gets output. Variables begin with a dollar sign and can be used pretty freely both in # statements and anywhere else. You'll also see a lot of comments in the file. Two hash mark the rest of the line as comment and #* and *# are used to comment everything between the two. Pretty much all whitespace is commented in the file to avoid it going into the source file. This is not absolutely necessary but it avoids having long stretches of whitespace in the final generated html, admittedly at the cost of making the template less readable. A user guide for Velocity, with more information, can be found here
http://velocity.apache.org/engine/devel/user-guide.html .
Olli