Skip to content

Commit 469eca4

Browse files
committed
add morpheme example
1 parent 3d28e1f commit 469eca4

File tree

10 files changed

+195
-286
lines changed

10 files changed

+195
-286
lines changed

css/style.css

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,19 @@ header > button:hover {
179179
}
180180

181181
body > #tree-svg {
182-
box-shadow: 0 0 1em #aaa;
182+
border-top: 1px solid #ccc;
183+
/*box-shadow: 0 0 1em #aaa;*/
183184
background:hsl(5,5%,98%);
184185
position:fixed;
185186
bottom:0;
186187
font-size:14px;
187-
height:250px;
188+
height:200px;
189+
width:100%;
188190
max-height:40vh;
189191
}
190-
body > #tree-svg.hidden {
192+
body { margin-bottom:200px; }
193+
body.tree-closed { margin-bottom: 0; }
194+
body.tree-closed > #tree-svg {
191195
display:none;
192196
}
193197
body > #tree-svg #tree-close {
@@ -215,6 +219,7 @@ body > #tree-svg #tree-close {
215219
font-weight: 400;
216220
color:#444;
217221
display:none;
222+
z-index:100;
218223
}
219224
#tooltip.active {
220225
display:block;

data/data6.json

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"eventData": {
3+
"comments": [],
4+
"entities": [
5+
[
6+
"T1",
7+
"BOUND",
8+
[[
9+
"0",
10+
"2"
11+
]]
12+
],
13+
[
14+
"T2",
15+
"FREE",
16+
[[
17+
"3",
18+
"7"
19+
]]
20+
],
21+
[
22+
"T3",
23+
"BOUND",
24+
[[
25+
"8",
26+
"12"
27+
]]
28+
]
29+
],
30+
"attributes": [],
31+
"text": "un lock able",
32+
"relations": [
33+
[
34+
"R1",
35+
"unlock",
36+
[
37+
[
38+
"Controlled",
39+
"T1"
40+
],
41+
[
42+
"Controller",
43+
"T2"
44+
]
45+
]
46+
],
47+
[
48+
"R2",
49+
"unlockable",
50+
[
51+
[
52+
"Controlled",
53+
"R1"
54+
],
55+
[
56+
"Controller",
57+
"T3"
58+
]
59+
]
60+
]
61+
],
62+
"triggers": [],
63+
"events": []
64+
},
65+
"syntaxData": {
66+
"comments": [],
67+
"entities": [
68+
[
69+
"T1",
70+
"",
71+
[[
72+
"0",
73+
"2"
74+
]]
75+
],
76+
[
77+
"T2",
78+
"",
79+
[[
80+
"3",
81+
"7"
82+
]]
83+
],
84+
[
85+
"T3",
86+
"",
87+
[[
88+
"8",
89+
"12"
90+
]]
91+
]
92+
],
93+
"attributes": [],
94+
"text": "un lock able",
95+
"relations": [],
96+
"triggers": [],
97+
"events": []
98+
}
99+
}

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<option>paragraph</option>
1818
<option>passage1</option>
1919
<option>passage2</option>
20+
<option>morpheme</option>
2021
</select>
2122
<button id="taxonomy-toggle">Taxonomy</button>
2223
<button id="options-toggle">Options</button>

js/components/link.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ class Link {
494494
}
495495
text(str) {
496496
if (this.editingText) {
497+
if (str === undefined) { return this.editingText; }
497498
this.editingText.text(str);
498499
}
499500
}

js/components/tag.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class WordTag {
4848
}
4949
}
5050
text(val) {
51+
if (val === undefined) { return this.svgText; }
5152
this.val = val;
5253
this.svgText.text(this.val);
5354
this.ww = this.svgText.length();

js/main.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,20 @@ const Main = (function() {
3939
tree = new TreeLayout('#tree', svg);
4040

4141
// load and render initial dataset by default
42-
changeDataset(2);
42+
changeDataset(6);
4343

4444
// svg event listeners
4545
svg.on('row-resize', function(e) {
4646
lm.stopEditing();
4747
rm.resizeRow(e.detail.object.idx, e.detail.y);
4848
});
4949

50+
svg.on('label-updated', function(e) {
51+
// TODO: so so incomplete
52+
let color = tm.getColor(e.detail.label, e.detail.object);
53+
e.detail.object.node.style.fill = color;
54+
});
55+
5056
svg.on('word-move-start', function() {
5157
if (!options.showLinksOnMove && options.showSyntax) {
5258
setSyntaxVisibility(false);
@@ -65,6 +71,11 @@ const Main = (function() {
6571
}
6672
});
6773

74+
svg.on('tag-remove', function(e) {
75+
e.detail.object.remove();
76+
tm.remove(e.detail.object);
77+
});
78+
6879
svg.on('row-recalculate-slots', function(e) {
6980
links.forEach(link => {
7081
link.resetSlotRecalculation();
@@ -76,7 +87,7 @@ const Main = (function() {
7687
});
7788

7889
svg.on('build-tree', function(e) {
79-
tree.svg.classed('hidden', false);
90+
document.body.classList.remove('tree-closed');
8091
if (tree.isInModal) {
8192
setActiveTab('tree');
8293
}
@@ -300,6 +311,7 @@ const Main = (function() {
300311
w.setSyntaxId(token.id);
301312
return w;
302313
});
314+
console.log('words',words);
303315
const clusters = [];
304316

305317
[].concat(parser.data.entities, parser.data.triggers).forEach(el => {
@@ -324,6 +336,7 @@ const Main = (function() {
324336
let anchor;
325337
switch (argument.id.charAt(0)) {
326338
case 'E':
339+
case 'R':
327340
anchor = links.find(link => link.eventId === argument.id);
328341
break;
329342
case 'T':

js/managers/labelmanager.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const LabelManager = (function() {
2+
let _svg;
23
let activeObject = null;
34
let string = null;
45
let originalString = null;
@@ -20,6 +21,7 @@ const LabelManager = (function() {
2021
class LabelManager {
2122
constructor(svg) {
2223
// listeners for label handling
24+
_svg = svg;
2325
svg.on('tag-edit', listenForEdit);
2426
svg.on('link-label-edit', listenForEdit);
2527
this.stopEditing = stopEditing;
@@ -35,7 +37,10 @@ const LabelManager = (function() {
3537

3638
function stopEditing() {
3739
if (activeObject && activeObject.isEditing) {
38-
// if (!string) { updateString(originalString); }
40+
let text = activeObject.text();
41+
if (text && !(activeObject instanceof Link)) {
42+
_svg.fire('label-updated', { object: text, label: text.text() });
43+
}
3944
activeObject.stopEditing();
4045
activeObject = null;
4146
originalString = string = null;

js/managers/taxonomy.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Taxonomy = (function() {
1414
'#a6761d',
1515
'#7f7f7f'
1616
];
17+
let tagTypes = {};
1718

1819
function updateColor(word, color) {
1920
if (word instanceof Word) {
@@ -29,28 +30,27 @@ const Taxonomy = (function() {
2930
class Taxonomy {
3031
constructor(id) {
3132
this.tree = {};
32-
this.tagTypes = {};
3333
div = document.getElementById('taxonomy');
3434
}
3535

3636
buildTagTypes(words) {
37-
this.tagTypes = {};
37+
tagTypes = {};
3838
words.forEach(word => {
3939
if (word.tag) {
40-
if (this.tagTypes[word.tag.val]) {
41-
this.tagTypes[word.tag.val].push(word);
40+
if (tagTypes[word.tag.val]) {
41+
tagTypes[word.tag.val].push(word);
4242
}
4343
else {
44-
this.tagTypes[word.tag.val] = [word];
44+
tagTypes[word.tag.val] = [word];
4545
}
4646
}
4747
if (word.clusters.length > 0) {
4848
word.clusters.forEach(cluster => {
49-
if (this.tagTypes[cluster.val]) {
50-
this.tagTypes[cluster.val].push(cluster);
49+
if (tagTypes[cluster.val]) {
50+
tagTypes[cluster.val].push(cluster);
5151
}
5252
else {
53-
this.tagTypes[cluster.val] = [cluster];
53+
tagTypes[cluster.val] = [cluster];
5454
}
5555
});
5656
}
@@ -96,7 +96,6 @@ const Taxonomy = (function() {
9696
}
9797

9898
populateTaxonomy() {
99-
let tagTypes = this.tagTypes;
10099
let keys = Object.keys(tagTypes);
101100

102101
// populate taxonomy
@@ -204,6 +203,35 @@ const Taxonomy = (function() {
204203
tagTypes[tag].forEach(word => updateColor(word, colors[i]));
205204
});
206205
}
206+
207+
remove(object) {
208+
// TODO: fix the fuck out of this
209+
return;
210+
let tag = object.val;
211+
let entity = object.entity;
212+
if (tagTypes[tag]) {
213+
let i = tagTypes[tag].indexOf(entity);
214+
if (i > -1) {
215+
tagTypes[tag].splice(i, 1);
216+
if (tagTypes[tag].length < 1) {
217+
delete tagTypes[tag];
218+
}
219+
}
220+
}
221+
}
222+
223+
getColor(label, object) {
224+
//FIXME: fix me the fuck up
225+
return;
226+
let keys = Object.keys(tagTypes);
227+
if (tagTypes[label]) {
228+
return colors[keys.indexOf(label)];
229+
}
230+
else {
231+
tagTypes[label] = object;
232+
return colors[keys.length] || 'black';
233+
}
234+
}
207235
}
208236
return Taxonomy;
209237
})();

js/managers/tooltip.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,12 @@ const Tooltip = (function() {
7777
switch (e.target.id) {
7878
// tag management events
7979
case 'menu--remove-tag':
80-
if (activeObject instanceof Word && activeObject.tag) {
81-
activeObject.tag.remove();
82-
}
83-
else {
84-
activeObject.remove();
85-
}
80+
let tag1 = (activeObject instanceof Word && activeObject.tag) ? activeObject.tag : activeObject;
81+
_svg.fire('tag-remove', { object: tag1 });
8682
break;
8783
case 'menu--add-tag':
88-
let tag = activeObject.setTag('?');
89-
_svg.fire('tag-edit', { object: tag });
84+
let tag2 = activeObject.setTag('?');
85+
_svg.fire('tag-edit', { object: tag2 });
9086
break;
9187
case 'menu--edit-tag':
9288
_svg.fire('tag-edit', { object: activeObject.tag });

0 commit comments

Comments
 (0)