Web gl UI - creation of a tree sturcture

Please give me an algorithm to create the following tree structure and auto positioning of child nodes given a parent node and drawing it.

ps. the whole program will be appreciated :smiley: :smiley: :smiley: :smiley: