blob: d2c4d2cba110fd672db91904e5cd81fdbc8b8879 [file] [log] [blame]
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -07001/* -*- 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 Yu0b0a7362014-08-05 16:31:30 -070013#include "tree-layout.hpp"
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070014#include <iostream>
15
Yingdi Yu0b0a7362014-08-05 16:31:30 -070016namespace chronos {
17
18using std::vector;
19using std::map;
20
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070021void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070022OneLevelTreeLayout::setOneLevelLayout(vector<Coordinate>& childNodesCo)
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070023{
24 if (childNodesCo.empty())
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070025 return;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070026
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070027 double y = getLevelDistance();
28 double sd = getSiblingDistance();
29 int n = childNodesCo.size();
30 double x = - (n - 1) * sd / 2;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070031 for (int i = 0; i < n; i++) {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070032 childNodesCo[i].x = x;
33 childNodesCo[i].y = y;
34 x += sd;
35 }
36}
37
38void
39MultipleLevelTreeLayout::setMultipleLevelTreeLayout(TrustTreeNodeList& nodeList)
40{
Yingdi Yu0b0a7362014-08-05 16:31:30 -070041 if (nodeList.empty())
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070042 return;
43
44 double ld = getLevelDistance();
45 double sd = getSiblingDistance();
46
Yingdi Yu0b0a7362014-08-05 16:31:30 -070047 map<int, double> layerSpan;
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070048
Yingdi Yu0b0a7362014-08-05 16:31:30 -070049 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 Yuf4aaa8b2014-03-10 11:24:31 -070055
Yingdi Yu0b0a7362014-08-05 16:31:30 -070056 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 Yuf4aaa8b2014-03-10 11:24:31 -070061
Yingdi Yu0b0a7362014-08-05 16:31:30 -070062 for (TrustTreeNodeList::iterator it = nodeList.begin(); it != nodeList.end(); it++) {
63 (*it)->x -= layerSpan[(*it)->level()];
64 }
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070065}
Yingdi Yu0b0a7362014-08-05 16:31:30 -070066
67} // namespace chronos