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