forked from leebyron/streamgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinimizedWiggleLayout.java
34 lines (30 loc) · 960 Bytes
/
MinimizedWiggleLayout.java
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
/**
* MinimizedWiggleLayout
* Minimizes the sum of squares of the layer slopes at each value
*
* We present this as a reasonable alternative to the Stream Graph for
* real-time use. While it has some drawbacks compared to StreamLayout, it is
* much faster to execute and is reasonable for real-time applications.
*
* @author Lee Byron
* @author Martin Wattenberg
*/
public class MinimizedWiggleLayout extends LayerLayout {
public String getName() {
return "Minimized Wiggle Layout";
}
public void layout(Layer[] layers) {
int n = layers[0].size.length;
int m = layers.length;
float[] baseline = new float[n];
// Set shape of baseline values.
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
baseline[i] += (m - j - 0.5) * layers[j].size[i];
}
baseline[i] /= m;
}
// Put layers on top of the baseline.
stackOnBaseline(layers, baseline);
}
}