blob: 6df61add89bfd96614c3fb5ad0e876e7337709b7 [file] [log] [blame]
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
Varun Patila24bd3e2020-11-24 10:08:33 +05303 * Copyright (c) 2020, Regents of the University of California
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -07004 * 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
Yingdi Yueb692ac2015-02-10 18:46:18 -080015namespace chronochat {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070016
17using std::vector;
18using std::map;
19
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070020void
Yingdi Yu0b0a7362014-08-05 16:31:30 -070021OneLevelTreeLayout::setOneLevelLayout(vector<Coordinate>& childNodesCo)
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070022{
23 if (childNodesCo.empty())
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070024 return;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070025
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070026 double y = getLevelDistance();
27 double sd = getSiblingDistance();
28 int n = childNodesCo.size();
29 double x = - (n - 1) * sd / 2;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070030 for (int i = 0; i < n; i++) {
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070031 childNodesCo[i].x = x;
32 childNodesCo[i].y = y;
33 x += sd;
34 }
35}
36
37void
38MultipleLevelTreeLayout::setMultipleLevelTreeLayout(TrustTreeNodeList& nodeList)
39{
Yingdi Yu0b0a7362014-08-05 16:31:30 -070040 if (nodeList.empty())
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070041 return;
42
43 double ld = getLevelDistance();
44 double sd = getSiblingDistance();
45
Yingdi Yu0b0a7362014-08-05 16:31:30 -070046 map<int, double> layerSpan;
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070047
Yingdi Yu0b0a7362014-08-05 16:31:30 -070048 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 Yuf4aaa8b2014-03-10 11:24:31 -070054
Yingdi Yu0b0a7362014-08-05 16:31:30 -070055 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 Yuf4aaa8b2014-03-10 11:24:31 -070060
Yingdi Yu0b0a7362014-08-05 16:31:30 -070061 for (TrustTreeNodeList::iterator it = nodeList.begin(); it != nodeList.end(); it++) {
62 (*it)->x -= layerSpan[(*it)->level()];
63 }
Yingdi Yuf4aaa8b2014-03-10 11:24:31 -070064}
Yingdi Yu0b0a7362014-08-05 16:31:30 -070065
Yingdi Yueb692ac2015-02-10 18:46:18 -080066} // namespace chronochat