-
Notifications
You must be signed in to change notification settings - Fork 4
/
layout_rectangularLayout.f.js.html
96 lines (66 loc) · 3.7 KB
/
layout_rectangularLayout.f.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: layout/rectangularLayout.f.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: layout/rectangularLayout.f.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import {mean} from "d3";
import {makeEdges, makeVertexFromNode} from "./layoutHelpers";
/** @module layout */
export function rectangularVertices(tree){
let currentY=0;
const vertices=[];
const traverse = function(node,siblingPositions=[]){
const myChildrenPositions=[];
if(node.children){
for(const child of node.children){
traverse(child,myChildrenPositions);
}
siblingPositions.push(mean(myChildrenPositions));
const vertex = {...makeVertexFromNode(node),
y:mean(myChildrenPositions),
x:node.divergence};
vertices.push(vertex);
}else{
currentY+=1;
siblingPositions.push(currentY);
const vertex = {...makeVertexFromNode(node), y:currentY, x:node.divergence};
vertices.push(vertex);
}
};
traverse(tree.rootNode);
//slow!
return vertices;
}
const layoutFactory=makeVertices=>tree=>{
const vertices = makeVertices(tree);
const edges = makeEdges(vertices);
return {vertices,edges}
};
export const rectangularLayout = layoutFactory(rectangularVertices);</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-bauble.html">bauble</a></li><li><a href="module-figtree.html">figtree</a></li><li><a href="module-layout.html">layout</a></li><li><a href="module-tree.html">tree</a></li></ul><h3>Classes</h3><ul><li><a href="Axis.html">Axis</a></li><li><a href="BaubleManager.html">BaubleManager</a></li><li><a href="CircleBauble.html">CircleBauble</a></li><li><a href="Decoration.html">Decoration</a></li><li><a href="Label.html">Label</a></li><li><a href="Legend.html">Legend</a></li><li><a href="module-bauble.Bauble.html">Bauble</a></li><li><a href="module-figtree.FigTree.html">FigTree</a></li><li><a href="module-tree.Tree.html">Tree</a></li><li><a href="module-tree-Node.html">Node</a></li><li><a href="ScaleBar.html">ScaleBar</a></li></ul><h3>Global</h3><ul><li><a href="global.html#branch">branch</a></li><li><a href="global.html#branchLabel">branchLabel</a></li><li><a href="global.html#branchPathGenerator">branchPathGenerator</a></li><li><a href="global.html#circle">circle</a></li><li><a href="global.html#dateToDecimal">dateToDecimal</a></li><li><a href="global.html#decimalToDate">decimalToDate</a></li><li><a href="global.html#internalNodeLabel">internalNodeLabel</a></li><li><a href="global.html#label">label</a></li><li><a href="global.html#leapYear">leapYear</a></li><li><a href="global.html#legend">legend</a></li><li><a href="global.html#scaleBar">scaleBar</a></li><li><a href="global.html#tipLabel">tipLabel</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Wed Mar 18 2020 15:21:17 GMT+0000 (Greenwich Mean Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>