forked from leebyron/streamgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVolatilitySort.java
More file actions
29 lines (24 loc) · 795 Bytes
/
Copy pathVolatilitySort.java
File metadata and controls
29 lines (24 loc) · 795 Bytes
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
import java.util.*;
/**
* VolatilitySort
* Sorts an array of layers by their volatility, placing the most volatile
* layers along the outsides of the graph, thus minimizing unneccessary
* distortion.
*
* First sort by volatility, then creates a 'top' and 'bottom' collection.
* Iterating through the sorted list of layers, place each layer in whichever
* collection has less total mass, arriving at an evenly weighted graph.
*
* @author Lee Byron
* @author Martin Wattenberg
*/
public class VolatilitySort extends LayerSort {
public String getName() {
return "Volatility Sorting, Evenly Weighted";
}
public Layer[] sort(Layer[] layers) {
// first sort by volatility
Arrays.sort(layers, new VolatilityComparator(true));
return orderToOutside(layers);
}
}