#include #include "TreeMap.h" LAYOUTPLUGIN(TreeMap,"Tree Map (Shneiderman)","David Auber","01/12/1999","ok","0","1"); using namespace std; void TreeMap::dfsPlacement(node n, int depth, double x, double y, double width, double height, bool direction, STL_EXT_NS::hash_map &value) { //Affecte la valeur du noeud courant layoutProxy->setNodeValue(n,Coord(x+(double)width/2,y+(double)height/2,depth)); size->setNodeValue(n,Size(width,height,1)); if (superGraph->outdeg(n)==0) return; //Calcul la somme des valeurs des fils. double tmpSomme=value[n]; x+=width*1/20; y+=height*1/20; width-=width/10; height-=height/10; double delta; double newX=x,newY=y; double newWidth=width,newHeight=height; Iterator *itN=superGraph->getOutNodes(n); //interpolation horizontale if (direction) { delta=width/tmpSomme; for (;itN->hasNext();) { node itn=itN->next(); newWidth=delta*value[itn]; dfsPlacement(itn,depth+4,newX,newY,newWidth,newHeight,false,value); newX+=delta*value[itn]; } } else { //interpolation vertical for (;itN->hasNext();) { node itn=itN->next(); delta=height/tmpSomme; newHeight=delta*value[itn]; dfsPlacement(itn,depth+4,newX,newY,newWidth,newHeight,true,value); newY+=delta*value[itn]; } }delete itN; } TreeMap::TreeMap(PropertyContext *context):Layout(context){} TreeMap::~TreeMap() {} double TreeMap::initVal(node n, STL_EXT_NS::hash_map &value) { if (superGraph->outdeg(n)==0) { if (!(value[n]=metric->getNodeValue(n)>0)) value[n]=1; return value[n]; } double sum=0; Iterator *itN=superGraph->getOutNodes(n); for (;itN->hasNext();) { node itn=itN->next(); sum+=initVal(itn,value); } delete itN; value[n]=sum; return sum; } bool TreeMap::run() { metric=getProxy(superGraph,"viewMetric"); size=getLocalProxy(superGraph,"viewSize"); STL_EXT_NS::hash_map value(superGraph->numberOfNodes()); Iterator *itN=superGraph->getNodes(); for (;itN->hasNext();) { node itn=itN->next(); if (superGraph->indeg(itn)==0) { initVal(itn,value); dfsPlacement(itn,1,0,0,1024,1024,true,value); break; } } delete itN; return true; } bool TreeMap::check(string &erreurMsg) { if (superGraph->isTree()) { erreurMsg=""; return true; } else { erreurMsg="The Graph must be a Tree"; return false; } } void TreeMap::reset() {}