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 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 13 | #include "tree-layout.hpp" |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 14 | #include <iostream> |
| 15 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame^] | 16 | namespace chronochat { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 17 | |
| 18 | using std::vector; |
| 19 | using std::map; |
| 20 | |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 21 | void |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 22 | OneLevelTreeLayout::setOneLevelLayout(vector<Coordinate>& childNodesCo) |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 23 | { |
| 24 | if (childNodesCo.empty()) |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 25 | return; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 26 | |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 27 | double y = getLevelDistance(); |
| 28 | double sd = getSiblingDistance(); |
| 29 | int n = childNodesCo.size(); |
| 30 | double x = - (n - 1) * sd / 2; |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 31 | for (int i = 0; i < n; i++) { |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 32 | childNodesCo[i].x = x; |
| 33 | childNodesCo[i].y = y; |
| 34 | x += sd; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | void |
| 39 | MultipleLevelTreeLayout::setMultipleLevelTreeLayout(TrustTreeNodeList& nodeList) |
| 40 | { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 41 | if (nodeList.empty()) |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 42 | return; |
| 43 | |
| 44 | double ld = getLevelDistance(); |
| 45 | double sd = getSiblingDistance(); |
| 46 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 47 | map<int, double> layerSpan; |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 48 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 49 | for (TrustTreeNodeList::iterator it = nodeList.begin(); it != nodeList.end(); it++) { |
| 50 | int layer = (*it)->level(); |
| 51 | (*it)->y = layer * ld; |
| 52 | (*it)->x = layerSpan[layer]; |
| 53 | layerSpan[layer] += sd; |
| 54 | } |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 55 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 56 | for (map<int, double>::iterator layerIt = layerSpan.begin(); |
| 57 | layerIt != layerSpan.end(); layerIt++) { |
| 58 | double shift = (layerIt->second - sd) / 2; |
| 59 | layerIt->second = shift; |
| 60 | } |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 61 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 62 | for (TrustTreeNodeList::iterator it = nodeList.begin(); it != nodeList.end(); it++) { |
| 63 | (*it)->x -= layerSpan[(*it)->level()]; |
| 64 | } |
Yingdi Yu | f4aaa8b | 2014-03-10 11:24:31 -0700 | [diff] [blame] | 65 | } |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 66 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame^] | 67 | } // namespace chronochat |