-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlegend.js
More file actions
226 lines (206 loc) · 8.62 KB
/
legend.js
File metadata and controls
226 lines (206 loc) · 8.62 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
var Legend = Class.create( {
/*
* Class responsible for keeping track of disorders on canvas and their properties.
* This information is graphically displayed in a 'Legend' box
*/
initialize: function() {
this._disorders = new Hash({});
this._evaluations = {};
this._disorderColors = new Hash({});
this._legendBox = new Element('div', {'class' : 'legend-box', id: 'legend-box'});
editor.workspace.insert(this._legendBox);
this._legendBox.setOpacity(0);
var legendTitle= new Element('h2', {'class' : 'legend-title'}).update('Key');
this._legendBox.insert(legendTitle);
this._disorderList = new Element('ul', {'class' : 'disorder-list'});
this._legendBox.insert(this._disorderList);
Element.observe(this._legendBox, 'mouseover', function() {
$$('.menu-box').invoke('setOpacity', .5);
});
Element.observe(this._legendBox, 'mouseout', function() {
$$('.menu-box').invoke('setOpacity', 1);
});
},
/*
* Returns an object of disorder ID's mapped to Disorder objects.
*/
getDisorders: function() {
return this._disorders;
},
/*
* Replaces the disorder Hash with the Hash passed in the parameter, and updates
* the graphical 'Legend' to represent the new information
*
* @param hash is a Hash object that has disorder IDs as keys and Disorder objects as values
*/
setDisorders: function(hash) {
this._disorders = hash;
},
/*
* Returns an object of evaluation ID's mapped to the evaluation properties.
*/
getEvaluations: function() {
return this._evaluations;
},
/*
* Replaces the evaluation map with the map passed in the parameter, and updates
* the graphical 'Legend' to represent the new information
*
* @param map is an object formatted as follows { E1 : {conclusion: '+', result: '(36n/18n)', numAEvaluations: 4}}
*/
setEvaluations: function(map) {
this._evaluations = map;
//TODO: this.buildLegend
},
/*
* Returns the Disorder object with the given disorder ID.
*
* @param disorderID the id number for the disorder, taken from the OMIM database
*/
getDisorder: function(disorderID) {
return this.getDisorders().get(disorderID);
},
/*
* Replaces the Disorder object with the given disorder ID.
*
* @param disorderID the id number for the disorder, taken from the OMIM database
* @param disorder a Disorder object
*/
setDisorder: function(disorderID, disorder) {
this.getDisorders().set(disorderID, disorder);
},
/*
* Registers an occurrence of a disorder. If disorder hasn't been documented yet,
* designates a color for it.
*
* @param disorder an object with fields 'id' and 'value', where id is the id number
* for the disorder, taken from the OMIM database, and 'value' is the name of the disorder.
* eg. {id: 33244, value: 'Down Syndrome'}
*/
addCase: function(disorder, node) {
if (!this.containsDisorder(disorder['id'])) {
this.setDisorder(disorder['id'], new Disorder(disorder['id'], disorder['value'], null, []));
var color = this.getDisorder(disorder['id']).getColor();
this.addUsedColor(disorder['id'], color);
var listElement = this.generateDisorderElement(disorder['id'], disorder['value'], color);
this._disorderList.insert(listElement);
}
(new Effect.Opacity('legend-box', { from: 0, to:.9, duration: 0.5 }));
this.getDisorder(disorder['id']).addAffectedNode(node);
this._displayCasesForDisorder(disorder['id']);
},
/*
* Removes an occurrence of a disorder if there are any. Removes the disorder
* from the 'Legend' box if this disorder is not registered in any individual.
*
* @param disorder an object with fields 'id' and 'value', where id is the id number
* for the disorder, taken from the OMIM database, and 'value' is the name of the disorder.
* eg. {id: 33244, value: 'Down Syndrome'}
*/
removeCase: function(disorder, node) {
var wasntEmpty = this.getDisorders().keys().length > 0;
if (this.containsDisorder(disorder['id'])) {
this.getDisorder(disorder['id']).removeAffectedNode(node);
if(this.getDisorder(disorder['id']).getNumAffected() < 1) {
var removeFromLegend = function() {$('disorder-' + disorder['id']).remove()};
this.getDisorders().unset(disorder['id']);
if(this.getDisorders().keys().length == 0) {
new Effect.Opacity('legend-box', { from:.9, to:0, duration: 0.5, afterFinish: removeFromLegend});
}
else {
removeFromLegend();
}
}
}
this._displayCasesForDisorder(disorder['id']);
},
/**
* Update the displayed number of affected cases for for a disorder in the legend UI.
*
* @param disorderID the identifier of the disorder to update
*/
_displayCasesForDisorder : function(disorderID) {
var label = this._legendBox.down('li#disorder-' + disorderID + ' .disorder-cases');
if (label) {
var cases = this.getDisorder(disorderID).getNumAffected();
label.update(cases + " case" + ((cases - 1) && "s" || ""));
}
},
/*
* Returns true if the disorder with the given ID is registered in the Legend
*
* @param disorderID the id number for the disorder, taken from the OMIM database
*/
containsDisorder: function(disorderID) {
return this.getDisorders().keys().indexOf(disorderID) > -1;
},
/*
* Adds color to the list of colors used in the Legend
*
* @param color is a string representing a CSS color e.g. 'blue' or '#DADADA'
*/
addUsedColor: function(disorderID, color) {
this.getDisorderColors().set(disorderID, color);
document.fire('disorder:color', {'id' : disorderID, color: color});
},
/**
* Retrieve the color associated to a specific disorder
*
* @param disorderID the identifier of the disorder
* @return the color for that disorder, as a string #rrggbb, or undefined if the disorder is not registered
*/
getDisorderColor: function(disorderID) {
return this._disorderColors.get(disorderID);
},
getDisorderColors: function() {
return this._disorderColors;
},
/**
* Generate the element that will display information about the given disorder in the legend
*
* @param id the (internal) identifier of the disorder
* @param name the human-readable disorder name
* @param color the color associated with the disorder, displayed on affected nodes in the pedigree
* @return a 'li' element to be insert in the legend's list
*/
generateDisorderElement: function(id, name, color) {
var item = new Element('li', {'class' : 'disorder', 'id' : 'disorder-' + id}).update(new Element('span', {'class' : 'disorder-name'}).update(name));
var bubble = new Element('span', {'class' : 'disorder-color'});
bubble.style.backgroundColor = color;
item.insert({'top' : bubble});
var countLabel = new Element('span', {'class' : 'disorder-cases'});
var countLabelContainer = new Element('span', {'class' : 'disorder-cases-container'}).insert("(").insert(countLabel).insert(")");
item.insert(" ").insert(countLabelContainer);
var me = this;
Element.observe(item, 'mouseover', function() {
//item.setStyle({'text-decoration':'underline', 'cursor' : 'default'});
item.down('.disorder-name').setStyle({'background': color, 'cursor' : 'default'});
me.getDisorder(id).getAffectedNodes().each(function(node) {
node.getGraphics().highlight();
});
});
Element.observe(item, 'mouseout', function() {
//item.setStyle({'text-decoration':'none'});
item.down('.disorder-name').setStyle({'background':'', 'cursor' : 'default'});
me.getDisorder(id).getAffectedNodes().each(function(node) {
node.getGraphics().unHighlight();
});
});
new Draggable(item, {
revert: true,
reverteffect: function(segment) {
// Reset the in-line style.
segment.setStyle({
height: '',
left: '',
position: '',
top: '',
zIndex: '',
width: ''
});
},
ghosting: true
});
return item;
}
});