gui: Display the trust tree
Change-Id: Id48227b0f2e903905d7c8eb9795d038d6562794c
diff --git a/src/tree-layout.cpp b/src/tree-layout.cpp
new file mode 100644
index 0000000..7fba509
--- /dev/null
+++ b/src/tree-layout.cpp
@@ -0,0 +1,71 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ * Yingdi Yu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
+#include "tree-layout.h"
+
+#include <iostream>
+
+void
+OneLevelTreeLayout::setOneLevelLayout(std::vector<Coordinate> &childNodesCo)
+{
+ if (childNodesCo.empty())
+ {
+ return;
+ }
+ double y = getLevelDistance();
+ double sd = getSiblingDistance();
+ int n = childNodesCo.size();
+ double x = - (n - 1) * sd / 2;
+ for (int i = 0; i < n; i++)
+ {
+ childNodesCo[i].x = x;
+ childNodesCo[i].y = y;
+ x += sd;
+ }
+}
+
+void
+MultipleLevelTreeLayout::setMultipleLevelTreeLayout(TrustTreeNodeList& nodeList)
+{
+ if(nodeList.empty())
+ return;
+
+ double ld = getLevelDistance();
+ double sd = getSiblingDistance();
+
+ std::map<int, double> layerSpan;
+
+ TrustTreeNodeList::iterator it = nodeList.begin();
+ TrustTreeNodeList::iterator end = nodeList.end();
+ for(; it != end; it++)
+ {
+ int layer = (*it)->level();
+ (*it)->y = layer * ld;
+ (*it)->x = layerSpan[layer];
+ layerSpan[layer] += sd;
+ }
+
+ std::map<int, double>::iterator layerIt = layerSpan.begin();
+ std::map<int, double>::iterator layerEnd = layerSpan.end();
+ for(; layerIt != layerEnd; layerIt++)
+ {
+ double shift = (layerIt->second - sd) / 2;
+ layerIt->second = shift;
+ }
+
+ it = nodeList.begin();
+ end = nodeList.end();
+ for(; it != end; it++)
+ {
+ (*it)->x -= layerSpan[(*it)->level()];
+ }
+}