Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically draw an organization chart?

Users of my program are organized hierarchically. Each user is a node in a tree, and the only other type of node is the department node. Each node has one and only one parent (possibly the root node).

I generated a DOT file to be used by the graphviz suite, but the resulting picture is unusable because it's too wide. I don't know if this program can be tuned to suit my needs, because I have a flat hierarchy with lots of sibling nodes, so maybe I need a program specifically designed for this (or write my own). I tried the unflatten tool, but without success.

This is the test dot file - note that my program often uses 10x this data...

like image 986
Raffaele Avatar asked Jan 24 '12 08:01

Raffaele


1 Answers

Based on your comment, here's a quick test using other layout algorithms than dot. Since you said circle, I tried with circo and twopi.

I had to make some slight changes to the test script:

  • add some colors/shape/style/font
  • style user and department nodes differently
  • insert a newline between the name and the function of the users

Putting the long department names on two lines would probably help, too.

digraph G {
overlap=false;
splines=true;
root="node0";

node[colorscheme=paired12, fontsize=11];
node0 [shape=house, label="Organizzazione", style="filled", fillcolor=3, color="4", fontsize=20, height=2,
 fontname="Times New Roman Bold"];

node[shape=doubleoctagon, style=filled, fillcolor=7, color=8, width=3];
node24 [label="C3 TERREMOTO"];
node28 [label="E POLIZIA URBANA E PROTEZIONE CIVILE"];
node14 [label="D1 SERVIZI SCOLASTICI"];
node35 [label="30: PROTOCOLLO ADMIN "];
node18 [label="B ECONOMICO E FINANZIARIO"];
node22 [label="C ASSETTO E TERRITORIO"];
node41 [label="A9 UFFICIO PUBBLICAZIONI"];
node38 [label="C1 TECNICO"];
node31 [label="A AFFARI GENERALI"];
node12 [label="A4 ANAGRAFE E STATO CIVILE"];
node20 [label="B1 TRIBUTI"];
node16 [label="A5 ELETTORALE E LEVA"];
node40 [label="31: PUBBLICAZIONI ALBO UTENTE "];
node26 [label="C2a TECNICO"];
node9 [label="A3 UFFICIO PROTOCOLLO CENTRALE"];

node[shape=box, style=filled, fillcolor="1", color="2", width=2];
node0 -> node24;
node0 -> node28;
node7 [label="14: ROCCO MARINACCIO\nVISUALIZZATORE"];
node0 -> node7;
node25 [label="27: FRANCESCO MARINO "];
node26 -> node25;
node39 [label="5: CIRO D'EMILIO\nPROTOCOLLATORE"];
node20 -> node39;
node4 [label="15: FRANCESCO PAZIENZA\nVISUALIZZATORE"];
node0 -> node4;
node3 [label="18: ADRIANA NATALE\nVISUALIZZATRICE"];
node0 -> node3;
node42 [label="4: MICHELE ROGATO\nRESP DI REPARTO"];
node18 -> node42;
node29 [label="29: FRANCESCO NOTA "];
node28 -> node29;
node0 -> node14;
node10 [label="12: STEFANO IEFFA "];
node0 -> node10;
node13 [label="20: ANTONIO MARINO "];
node14 -> node13;
node30 [label="3: PATRIZIA PLATANO\nPROTOCOLLATRICE"];
node31 -> node30;
node1 [label="19: PATRIZIA PLATANO "];
node0 -> node1;
node37 [label="6: GIUSEPPE CEGLIA\nRESP. DI REPARTO"];
node38 -> node37;
node0 -> node35;
node0 -> node18;
node23 [label="26: PASQUALE RUSSO "];
node24 -> node23;
node2 [label="17: MICHELE BICCARINO\nVISUALIZZATORE"];
node0 -> node2;
node0 -> node22;
node0 -> node41;
node11 [label="21: GIUSEPPE DI FLUMERI "];
node12 -> node11;
node43 [label="9: ROBERTO CAMPANELLA "];
node0 -> node43;
node0 -> node38;
node0 -> node31;
node0 -> node12;
node0 -> node20;
node17 [label="23: MICHELE IPPOLITO "];
node18 -> node17;
node6 [label="13: ALESSANDRO CAPANO "];
node0 -> node6;
node19 [label="24: SALVATORE DOTO "];
node20 -> node19;
node15 [label="22: BENVENUTA REA "];
node16 -> node15;
node27 [label="28: ANTONIO CAMPANELLA "];
node28 -> node27;
node8 [label="11: PASQUALE PALUMBO "];
node9 -> node8;
node5 [label="16: PAOLO PIETRO TROCCOLA\nVISUALIZZATORE"];
node0 -> node5;
node0 -> node16;
node21 [label="25: RAFFAELA COFANO "];
node22 -> node21;
node41 -> node40;
node32 [label="2: MARIA CRISTINA ANELLI\nVISUALIZZATRICE"];
node0 -> node32;
node0 -> node26;
node33 [label="10: VINCENZO BOTTICELLI "];
node0 -> node33;
node0 -> node9;
node36 [label="7: ANTONIETTA STRAZZELLA\nRESP. DI REPARTO"];
node22 -> node36;
node34 [label="1: AMBROGIO MASCIA\nAmministratore di sistema"];
node9 -> node34;
node44 [label="8: MARIANO LAUDISI\nVISUALIZZATORE"];
node0 -> node44;
}

You'll probably have to open the images and look at them in the original size.

Twopi layout:

graphviz output - twopi

Circo layout:

graphviz output - circo

The circo layout could probably be more appropriate if you have department linked to departments, or a lot of users in one department.

like image 53
marapet Avatar answered Sep 20 '22 10:09

marapet