Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 9 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 10 | * Yingdi Yu <yingdi@cs.ucla.edu> |
| 11 | */ |
| 12 | |
| 13 | #include "tree-layout.h" |
| 14 | |
| 15 | #include <iostream> |
| 16 | |
| 17 | void |
| 18 | OneLevelTreeLayout::setOneLevelLayout(std::vector<Coordinate> &childNodesCo) |
| 19 | { |
| 20 | if (childNodesCo.empty()) |
| 21 | { |
| 22 | return; |
| 23 | } |
| 24 | double y = getLevelDistance(); |
| 25 | double sd = getSiblingDistance(); |
| 26 | int n = childNodesCo.size(); |
| 27 | double x = - (n - 1) * sd / 2; |
| 28 | for (int i = 0; i < n; i++) |
| 29 | { |
| 30 | childNodesCo[i].x = x; |
| 31 | childNodesCo[i].y = y; |
| 32 | x += sd; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | void |
| 37 | MultipleLevelTreeLayout::setMultipleLevelTreeLayout(TrustTreeNodeList& nodeList) |
| 38 | { |
| 39 | if(nodeList.empty()) |
| 40 | return; |
| 41 | |
| 42 | double ld = getLevelDistance(); |
| 43 | double sd = getSiblingDistance(); |
| 44 | |
| 45 | std::map<int, double> layerSpan; |
| 46 | |
| 47 | TrustTreeNodeList::iterator it = nodeList.begin(); |
| 48 | TrustTreeNodeList::iterator end = nodeList.end(); |
| 49 | for(; it != end; it++) |
| 50 | { |
| 51 | int layer = (*it)->level(); |
| 52 | (*it)->y = layer * ld; |
| 53 | (*it)->x = layerSpan[layer]; |
| 54 | layerSpan[layer] += sd; |
| 55 | } |
| 56 | |
| 57 | std::map<int, double>::iterator layerIt = layerSpan.begin(); |
| 58 | std::map<int, double>::iterator layerEnd = layerSpan.end(); |
| 59 | for(; layerIt != layerEnd; layerIt++) |
| 60 | { |
| 61 | double shift = (layerIt->second - sd) / 2; |
| 62 | layerIt->second = shift; |
| 63 | } |
| 64 | |
| 65 | it = nodeList.begin(); |
| 66 | end = nodeList.end(); |
| 67 | for(; it != end; it++) |
| 68 | { |
| 69 | (*it)->x -= layerSpan[(*it)->level()]; |
| 70 | } |
| 71 | } |