Skip to content

Commit 3975fb1

Browse files
committed
adapt row height to syntax tree
1 parent ce35e02 commit 3975fb1

File tree

6 files changed

+198
-45
lines changed

6 files changed

+198
-45
lines changed

index.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,11 @@
3434
<div id="tooltip">
3535
</div>
3636
</div>
37-
<div id="graph">
38-
</div>
3937

40-
<script src="libs/d3.min.js"></script>
4138
<script src="libs/svg.js"></script>
4239
<script src="libs/svg.draggable.js"></script>
4340

44-
<script src="js/panel.js"></script>
41+
<script src="js/ymljson.js"></script>
4542
<script src="js/parser.js"></script>
4643
<script src="js/main.js"></script>
4744
<script src="js/managers/tooltip.js"></script>

js/components/row.js

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Row {
66
this.rw = 0;
77
this.words = [];
88
this.maxSlot = 0;
9-
this.paddingTop = 0;
9+
this.minSlot = 0;
1010

1111
// svg elements
1212
this.svg = null; // group
@@ -133,28 +133,9 @@ class Row {
133133
this.wordGroup.removeElement(word.svg);
134134
return word;
135135
}
136-
calculateMaxSlot() {
137-
// get max slot
138-
function fn(acc, anchor) {
139-
if (anchor.links.length === 0) {
140-
return Math.max(acc, anchor.slot);
141-
}
142-
return anchor.links.reduce(fn, 0);
143-
}
144-
this.maxSlot = this.words.reduce(fn, 0);
145-
}
146-
calculateMinSlot() {
147-
function fn(acc, anchor) {
148-
if (anchor.links.length === 0) {
149-
return Math.min(acc, anchor.slot);
150-
}
151-
return anchor.links.reduce(fn, 0);
152-
}
153-
this.minSlot = this.words.reduce(fn, 0);
154-
}
155136

156-
get ry2() { return this.ry + this.rh; }
137+
get ry2() { return this.ry + this.rh + 20 - this.minSlot * 15; }
157138
get minHeight() {
158-
return 90 + (this.maxSlot - this.paddingTop) * 15;
139+
return 60 + this.maxSlot * 15;
159140
}
160141
}

js/main.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const Main = (function() {
22
// classes
33
let parser;
4-
let panel;
54

65
// main svg element
76
let svg;
@@ -28,7 +27,6 @@ const Main = (function() {
2827

2928
tooltip = new Tooltip('tooltip', svg);
3029
parser = new Parser();
31-
panel = new Panel('graph');
3230
rm = new RowManager(svg);
3331
lm = new LabelManager(svg);
3432

@@ -71,9 +69,11 @@ const Main = (function() {
7169
function changeDataset(index = 1) {
7270
parser.readJson(`./data/data${index}.json`, function() {
7371
clear();
74-
[words, links, clusters] = buildWordsAndLinks();
75-
populateOptions();
76-
draw();
72+
ymlToJson.convert('taxonomy.yml.txt', function(taxonomy) {
73+
[words, links, clusters] = buildWordsAndLinks();
74+
populateOptions();
75+
draw();
76+
});
7777
});
7878
};
7979

js/managers/rowmanager.js

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ const RowManager = (function() {
88
}
99

1010
resizeAll() {
11-
_rows.forEach((row, i) => {
12-
row.calculateMaxSlot();
13-
row.calculateMinSlot();
14-
if (i > 0) {
15-
row.paddingTop = _rows[i - 1].minSlot;
16-
}
17-
let dy = row.minHeight - row.rh;
18-
if (dy > 0) { this.resizeRow(row.idx, dy); }
11+
_rows.forEach(row => {
12+
this.recalculateRowSlots(row);
13+
this.resizeRow(row.idx);
1914
});
2015
}
2116

22-
resizeRow(i, dy) {
17+
resizeRow(i, dy = 0) {
2318
let row = _rows[i];
2419
dy = Math.max(-row.rh + row.minHeight, dy);
2520
row.height(row.rh + dy);
2621
row.words.forEach(word => word.redrawLinks());
2722
for (let j = i + 1; j < _rows.length; ++j) {
28-
_rows[j].dy(dy);
23+
if (_rows[j - 1].ry2 + ROW_PADDING > _rows[j].ry + dy) {
24+
_rows[j].move(_rows[j - 1].ry2 + ROW_PADDING);
25+
}
26+
else {
27+
_rows[j].dy(dy);
28+
}
2929
_rows[j].words.forEach(word => word.redrawLinks());
3030
}
3131
_svg.height(this.lastRow.ry2 + ROW_PADDING + 20);
@@ -60,15 +60,23 @@ const RowManager = (function() {
6060

6161
addWordToRow(word, row, i, ignorePosition) {
6262
if (isNaN(i)) { i = row.words.length; }
63-
if (word.row && word.row !== row) { word.row.calculateMaxSlot(); }
63+
64+
// get word slots
65+
let slots = this.getSlotRange([0,0], word);
66+
if (word.row && word.row !== row &&
67+
(slots[0] === word.row.minSlot || word.row.maxSlot === slots[1])) {
68+
this.recalculateRowSlots(word.row);
69+
}
70+
if (row.minSlot > slots[0] || row.maxSlot < slots[1]) {
71+
if (row.minSlot > slots[0]) { row.minSlot = slots[0]; }
72+
if (row.maxSlot < slots[1]) { row.maxSlot = slots[1]; }
73+
this.resizeRow(row.idx);
74+
}
6475

6576
let overflow = row.addWord(word, i, ignorePosition);
6677
while (overflow < row.words.length) {
6778
this.moveWordDownARow(row.idx);
6879
}
69-
row.calculateMaxSlot();
70-
let dy = row.minHeight - row.rh;
71-
if (dy > 0) { this.resizeRow(row.idx, dy); }
7280
}
7381

7482
moveWordOnRow(word, dx) {
@@ -183,6 +191,19 @@ const RowManager = (function() {
183191
this.addWordToRow(_rows[index].removeLastWord(), nextRow, 0);
184192
}
185193

194+
getSlotRange(acc, anchor) {
195+
if (anchor.links.length === 0) {
196+
return [Math.min(acc[0], anchor.slot), Math.max(acc[1], anchor.slot)];
197+
}
198+
let a = anchor.links.reduce((acc, val) => this.getSlotRange(acc, val), [0, 0]);
199+
return [Math.min(acc[0], a[0]), Math.max(acc[1], a[1])];
200+
}
201+
202+
recalculateRowSlots(row) {
203+
[row.minSlot, row.maxSlot] = row.words
204+
.reduce((acc, val) => this.getSlotRange(acc, val), [0, 0]);
205+
}
206+
186207
get lastRow() { return _rows[_rows.length - 1]; }
187208
get rows() { return _rows; }
188209
}

js/ymljson.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// non-comprehensive function to convert yml file to json
2+
const ymlToJson = (function() {
3+
function convert(url, callback) {
4+
var xhr = new XMLHttpRequest();
5+
xhr.onreadystatechange = function() {
6+
if (xhr.readyState === 4 && xhr.status === 200) {
7+
let taxonomy = [];
8+
let arr = taxonomy;
9+
const text = xhr.responseText;
10+
const lines = text.split('\n');
11+
let depths = [];
12+
13+
lines.forEach(line => {
14+
let comment = line.indexOf('#');
15+
let lineStart = line.indexOf('-');
16+
if (lineStart < 0 || (comment >= 0 && comment < lineStart)) {
17+
return;
18+
}
19+
20+
line = ((comment >= 0) ? line.slice(lineStart + 1, comment) : line.slice(lineStart + 1)).trim();
21+
22+
while (depths.length > 0 && depths[depths.length - 1].i >= lineStart) {
23+
arr = depths.pop().arr;
24+
}
25+
if (depths.length === 0) { arr = taxonomy; }
26+
27+
if (line.endsWith(':')) {
28+
depths.push({ arr, i: lineStart });
29+
30+
let newArray = [];
31+
let child = {};
32+
child[line.slice(0, -1).trim()] = newArray;
33+
arr.push(child);
34+
arr = newArray;
35+
}
36+
else {
37+
arr.push(line);
38+
}
39+
});//end forEach
40+
if (callback) {
41+
callback(taxonomy);
42+
}
43+
}
44+
}
45+
xhr.open("GET", url);
46+
xhr.send();
47+
};
48+
49+
return {
50+
convert
51+
};
52+
})();

taxonomy.yml.txt

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
- Alias
2+
- ModificationTrigger
3+
- Site
4+
- Context:
5+
- Species
6+
- CellLine
7+
- Organ
8+
- CellType
9+
- Cellular_component
10+
- TissueType
11+
- ContextDirection
12+
- ContextLocation
13+
- ContextPossessive
14+
- Modification:
15+
- PTM
16+
- Mutant:
17+
- GenericMutant
18+
- SubstitutionMutant
19+
- DeletionMutant
20+
- DuplicationMutant
21+
- InsertionMutant
22+
- FrameshiftMutant
23+
- EventSite
24+
- Negation
25+
- PossibleController:
26+
- Event:
27+
- SimpleEvent:
28+
- Binding
29+
- Generic_event
30+
- Translocation
31+
- Amount:
32+
- IncreaseAmount:
33+
- Transcription
34+
- DecreaseAmount
35+
- AdditionEvent:
36+
- Acetylation
37+
- Farnesylation
38+
- Glycosylation
39+
- Hydrolysis
40+
- Hydroxylation
41+
- Methylation
42+
- Phosphorylation:
43+
- AutoPhosphorylation
44+
- Ribosylation
45+
- Sumoylation
46+
- Ubiquitination
47+
- RemovalEvent:
48+
- Deacetylation
49+
- Defarnesylation
50+
- Deglycosylation
51+
- Dehydrolysis
52+
- Dehydroxylation
53+
- Demethylation
54+
- Dephosphorylation
55+
- Deribosylation
56+
- Desumoylation
57+
- Deubiquitination
58+
- ComplexEvent:
59+
- Regulation:
60+
- Positive_regulation
61+
- Negative_regulation
62+
- ActivationEvent:
63+
- Positive_activation
64+
- Negative_activation
65+
- Entity:
66+
# Any BioEntity may appear as the controlled in an Activation
67+
- BioEntity:
68+
- BioProcess # ex. "apoptosis"
69+
- BioChemicalEntity:
70+
- Generic_entity
71+
- Simple_chemical
72+
- Equivalable: #TODO: Better name
73+
- Family
74+
- MacroMolecule:
75+
- Protein
76+
- Gene_or_gene_product
77+
- Complex
78+
- GENE
79+
# a preliminary taxonomy for assembly (precedence relations)
80+
- Precedence:
81+
# for pairs that are directly (immediately) connected
82+
# difficult to know from odin rules alone, but not impossible
83+
- DirectConnection
84+
# for pairs that are indirectly (not immediately) connected
85+
- IndirectConnection
86+
# Between-sentence precedence
87+
- BetweenSentence:
88+
- TimexAfter
89+
- TimexBefore
90+
- SentenceInitialEvent
91+
- InterAfter
92+
- InterBefore
93+
# tense and aspect detection
94+
- TAM:
95+
- Aux
96+
- Tense:
97+
- PastTense
98+
- PresentTense
99+
- FutureTense
100+
- Aspect:
101+
- Perfective
102+
- Progressive

0 commit comments

Comments
 (0)