-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVis2Main.js
196 lines (160 loc) · 4.39 KB
/
Vis2Main.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// this is the main file
function OnWindowLoaded()
{
// prepare main page (setting up splitter, docking, ...)
PrepareMainPage();
// initialize views
window.ViewManager.InitializeViews();
// update views
window.ViewManager.UpdateViews();
// get tree
var rTreeObject = window.TreeManager.GetTree(0);
// set reference tree
window.SelectionManager.SetReferenceTree(rTreeObject);
}
function PrepareMainPage()
{
$("#jqxSplitter2").jqxSplitter({
theme : 'darkblue',
orientation : 'horizontal',
panels : [ {
size : '210px'
}, {
size : '140px'
}, {
size : '500px'
} ]
});
$("#jqxSplitter").jqxSplitter({
theme : 'darkblue',
panels : [ {
size : '210px'
}, {
size : '800px'
} ]
});
$('#jqxSplitter').bind('resize', canvasSizeChanged);
$('#jqxSplitter2').bind('resize', canvasSizeChanged);
window.onresize = canvasSizeChanged;
// this class is a "model" in a ModelView-Pattern, used with knockout.js
// and stores information about the dynamically created windows
DynamicWindowsModel = function()
{
this.OpenViews = ko.observableArray([ {
treeID : 2,
windowIndex : 1
}, {
treeID : 2,
windowIndex : 2
} ]);
var self = this;
var nSections = 0;
var nWindows = 0;
var nWindowsCounter = 0;
var nMaxSections = 2;
// This method will handle the new added sections
function handleSection(el)
{
var id = 'knockout-section-' + nSections;
nSections += 1;
el.id = id;
$(el).appendTo($('#docking'));
$(el).css('width', '48%');
}
// This method will handle the new added windows
function handleWindow(el)
{
var nNewWindowIndex = nWindows + 1;
var id = 'knockout-window-' + (nNewWindowIndex);
var nSection = nWindowsCounter % nSections;
nWindows += 1;
nWindowsCounter += 1;
$(el).attr('id', id);
$(el).css('min-height', '300px');
// get tree index
var nTreeIndex = self.OpenViews()[nWindows - 1].treeID;
// set titlebar caption
$(el).children(".titlebar").append(
"Tree Comparison View (Tree " + (nTreeIndex + 1).toString()
+ ")");
$(el).children(".titlebar").append(
'<br><span id="measure-select-' + nNewWindowIndex
+ '"></span>');
// set id of <div class="content">
$(el).children(".content").attr('id',
'knockout-window-content-' + nWindows);
$(el).bind('closed', function(event)
{
window.ViewManager.OnCloseWindow(id);
});
$('#docking').jqxDocking('addWindow', id, 'default', nSection,
nWindows);
}
function getDOMElement(args)
{
for ( var i = 0; i < args.length; i += 1)
{
if (args[i].tagName && args[i].tagName.toUpperCase() === 'DIV')
{
return args[i];
}
}
return null;
}
// This method handles adding a new person (when the user click on the
// Add button)
this.addWindow = function(nTreeToCompare)
{
this.OpenViews.push({
treeID : nTreeToCompare,
windowIndex : nWindows,
});
return nWindows;
}
// This custom render takes care of adding new windows
this.buildWindow = function(element)
{
var el = getDOMElement(element);
if (nSections < nMaxSections)
{
handleSection(el);
handleWindow($(el).children('.knockout-window'));
}
else
{
handleWindow($(el).children('.knockout-window'));
$(el).remove();
}
}
this.closeWindow = function()
{
// decrement windows counter, necessary for placement of newly
// created windows
nWindowsCounter -= 1
assert(nWindows >= 0, "nWindows became negative");
}
};
window.DynamicWindowsModel = new DynamicWindowsModel();
// activate knockout.js, set Model
ko.applyBindings(window.DynamicWindowsModel);
$('#docking').jqxDocking({
theme : 'energyblue',
width : '700px',
panelsRoundedCorners : true
});
// close the dummy windows, which were added to make the sections working
// (they must be existing at the docking-construction-time)
$('#docking').jqxDocking('closeWindow', 'knockout-window-1');
$('#docking').jqxDocking('closeWindow', 'knockout-window-2');
}
// attach OnWindowLoadedEvent
window.addEventListener('load', OnWindowLoaded, false);
// create tree manager
window.TreeManager = new Vis2TreeManager("SampleTrees1.txt");
assert(window.TreeManager.GetNumTrees() > 0, "no trees loaded");
// create selection manager
window.SelectionManager = new Vis2SelectionManager();
// create color map
window.ColorMap = new Vis2ColorMap();
// create view manager
window.ViewManager = new Vis2ViewManager();