jtextor / dagitty

Graphical analysis of structural causal models / graphical causal models.
GNU General Public License v2.0
282 stars 46 forks source link

hi, i have a question about the node's position? #5

Closed joostshao closed 8 years ago

joostshao commented 8 years ago

hi, i have a question about the node's position? Look the meta data like this below.

{
    e: "0  1  0  0  0  0  0  0  0  0  0  0  0  0\n"+
       "0  0  0  0  0  0  0  0  0  0  0  0  0  0\n"+
       "1  0  0  0  0  0  0  0  0  0  0  0  0  0\n"+
       "1  0  0  0  0  0  0  0  0  0  0  0  0  0\n"+
       "0  1  1  0  0  0  1  0  0  0  0  0  0  1\n"+
       "0  1  1  0  1  0  1  0  0  0  0  0  0  1\n"+
       "0  1  0  0  0  0  0  0  0  0  0  0  0  0\n"+
       "1  1  1  1  1  1  1  0  0  0  1  1  1  1\n"+
       "1  1  1  1  1  1  1  1  0  0  1  1  1  1\n"+
       "1  1  1  1  1  1  1  1  0  0  1  1  1  1\n"+
       "1  1  0  0  1  1  1  0  0  0  0  1  0  1\n"+
       "1  1  1  0  1  1  1  0  0  0  0  0  1  0\n"+
       "0  1  1  0  1  1  1  0  0  0  0  0  0  1\n"+
       "0  1  0  0  0  0  0  0  0  0  0  0  0  0",

    v: "ToothLoss E @-1.677,2.421\n"+
"Mortality O @1.900,2.360\n"+
"Periodontitis 1 @-0.335,1.703\n"+
"Caries 1 @-1.879,-1.875\n"+
"Diabetes 1 @-0.888,0.322\n"+
"Obesity 1 @-0.904,-1.340\n"+
"Hypertension 1 @1.780,-0.157\n"+
"Psychosocial 1 @-0.088,0.266\n"+
"Age 1 @-0.039,-1.762\n"+
"Sex 1 @-0.844,-3.340\n"+
"Alcohol 1 @0.054,-3.594\n"+
"Smoking 1 @0.772,0.379\n"+
"Sport 1 @0.914,-3.396\n"+
"Lipids 1 @2.026,-1.650",

    l: "Polzer et al., 2012"
},

how to calculte the nodes's positions(x,y) as the Matrix like this? the important thing is to visuliazation.

jtextor commented 8 years ago

I am not quite sure I am getting you, but are you asking how to convert the node coordinates such as given (e.g. @-1.879,-1.875) into screen coordinates?

If so, basically dagitty computes the bounding box of the screen coordinates, adds padding, and then maps that to the bounding box of the drawing window. Relevant code is in GraphLayouter.js (function layoutCalcBounds) and GraphGUI_View.js (function initializeCoordinateSystem).

The new dagitty syntax (based on GraphViz) also allows specifying the bounding box explicitly like so:

dag { graph [bb="0,0,100,100"]

x [pos="50,50"] y [pos="20,20"]

x -> y }

The example you're quoting still uses the old syntax, I had no time yet to convert them all over.

joostshao commented 8 years ago

hi, although you didn't understand what i mean, but thank you !

first: convert node coordinates to the browser, it is already you implimented.

but what i ask is that(maybe some diffcult): how to generate the node coordinates from the matrix.

for example:

"0  1   1\n"+
"0  0  1\n"+
 "1  1  0\n"+

how to get the coordinates(x, y values) from the 3 dimensions matrix?

gra

the image showed is only 3 nodes, but if there have 20 nodes, how to make every node's coordinates rational to show a clean and streakiness images ?

jtextor commented 8 years ago

I see. The problem you are describing is called "Graph Drawing" (https://en.wikipedia.org/wiki/Graph_drawing). This is indeed by no means an easy problem and hundreds of algorithms have been to solve it. There's also a dedicated software called "graphviz" for doing that. Dagitty only implements one graph drawing algorithm called "force directed" or "spring" (https://en.wikipedia.org/wiki/Force-directed_graph_drawing), see class GraphLayouter.js. This is what dagitty uses to automatically generate node coordinates.

I am closing this issue since it is not directly related to dagitty.

joostshao commented 8 years ago

thank you , i get you meaning.