Revize 8343da8f
Přidáno uživatelem Patrik Harag před více než 5 roky(ů)
sources/imiger-core/src/main/webapp/js/services/initialElimination.js | ||
---|---|---|
21 | 21 |
visibleComponentsCount - this._maxVisibleComponents); |
22 | 22 |
|
23 | 23 |
if (numberOfVerticesToGroup > 0) { |
24 |
if (!this._groupByTypes(visibleVertices)) { |
|
25 |
this._simpleGrouping(visibleVertices, numberOfVerticesToGroup); |
|
26 |
} |
|
24 |
this._groupByTypes(visibleVertices, numberOfVerticesToGroup); |
|
27 | 25 |
} |
28 | 26 |
} |
29 | 27 |
} |
30 | 28 |
|
31 |
_groupByTypes(visibleVertices) { |
|
29 |
_groupByTypes(visibleVertices, numberOfVerticesToGroup) {
|
|
32 | 30 |
let groups = new Map(); |
33 | 31 |
visibleVertices.forEach(vertex => { |
34 | 32 |
let entry = groups.get(vertex.archetype); |
... | ... | |
39 | 37 |
} |
40 | 38 |
}); |
41 | 39 |
|
42 |
if (groups.size > 2) {
|
|
40 |
if (groups.size > 0) {
|
|
43 | 41 |
// group by types |
44 |
groups.forEach((v, k) => { |
|
42 |
this._createGroupsWithCoupleOfVerticesLeftOut(visibleVertices, groups, numberOfVerticesToGroup); |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
_createGroupsWithCoupleOfVerticesLeftOut(visibleVertices, groups, numberOfVerticesToGroup) { |
|
47 |
let numberOfVertices = visibleVertices.length; |
|
48 |
let numberOfGroups = groups.size; |
|
49 |
let numberToLeftOut = numberOfVertices - numberOfVerticesToGroup - numberOfGroups; |
|
50 |
|
|
51 |
groups.forEach((vertices, k) => { |
|
52 |
let p = vertices.length / numberOfVertices; |
|
53 |
let numberToLeftOutInThisGroup = Math.floor(p * numberToLeftOut); |
|
54 |
let filtered = this._removeMostConnected(vertices, numberToLeftOutInThisGroup); |
|
55 |
|
|
56 |
if (filtered.length > 0) { |
|
45 | 57 |
let archetype = app.archetype.vertex[k]; |
46 | 58 |
let groupName = archetype.name; |
47 |
this._createGroup(v, groupName); |
|
48 |
}); |
|
49 |
return true; |
|
50 |
} else { |
|
51 |
// not enough vertex types (archetypes) |
|
52 |
return false; |
|
53 |
} |
|
59 |
let group = this._createGroup(filtered, groupName); |
|
60 |
this._circularLayout(group, vertices); |
|
61 |
} |
|
62 |
}); |
|
54 | 63 |
} |
55 | 64 |
|
56 |
_simpleGrouping(visibleVertices, numberOfVerticesToGroup) {
|
|
57 |
// just pack the first n vertices into a group
|
|
58 |
this._createGroup(visibleVertices.slice(0, numberOfVerticesToGroup), null);
|
|
65 |
_removeMostConnected(vertices, count) {
|
|
66 |
vertices.sort((a, b) => a.countEdges() - b.countEdges());
|
|
67 |
return vertices.slice(0, vertices.length - count);
|
|
59 | 68 |
} |
60 | 69 |
|
61 | 70 |
_createGroup(vertices, name) { |
... | ... | |
70 | 79 |
app.nodeList.push(group); |
71 | 80 |
app.groupList.push(group); |
72 | 81 |
app.viewportComponent.addNode(group); |
82 |
|
|
83 |
return group; |
|
84 |
} |
|
85 |
|
|
86 |
_circularLayout(group, vertices) { |
|
87 |
let center = group.position; |
|
88 |
|
|
89 |
let MIN_DISTANCE = 200; |
|
90 |
let MAX_DISTANCE = 400; |
|
91 |
let distance = MIN_DISTANCE |
|
92 |
+ (group.vertexList.length / this._maxVisibleComponents * (MAX_DISTANCE - MIN_DISTANCE)); |
|
93 |
|
|
94 |
vertices.forEach(v => { |
|
95 |
let angle = Math.random() * Math.PI * 2; |
|
96 |
let coordinates = new Coordinates( |
|
97 |
center.x + distance * Math.cos(angle) - (v.size.width / 2), |
|
98 |
center.y + distance * Math.sin(angle) |
|
99 |
); |
|
100 |
v.position = coordinates; |
|
101 |
v.move(coordinates); |
|
102 |
}); |
|
103 |
|
|
104 |
group.move(center); |
|
73 | 105 |
} |
106 |
|
|
74 | 107 |
} |
Také k dispozici: Unified diff
Improve initial elimination (refs #7468)