Skip to content

Commit fcf221c

Browse files
committed
load words from json
1 parent 5a0cf8d commit fcf221c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

index.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
<body>
6363

6464
<div id="header">
65-
<select>
65+
<button id="random">random graph</button>
66+
<select id="dataset">
6667
<option>-- select dataset --</option>
6768
<option>data1</option>
6869
<option>data2</option>
@@ -173,26 +174,24 @@
173174
if (this.selectedIndex > 0) {
174175
parser.readJson(`./data/data${this.selectedIndex}.json`, function() {
175176
console.log(parser);
176-
resetDrawing();
177+
var words = parser.tokens.map((token, i) => new Word(token, i));
178+
resetDrawing(words, []);
177179
});
178180
}
179181
};
180182

181183
function resetDrawing(words, links) {
182184
draw.clear();
183185
rowGroup = draw.group();
184-
[groupAllElements, linkG, textG, arrowG].forEach(group => {
185-
if (group) { group.clear(); }
186-
group = undefined;
187-
});
186+
groupAllElements = linkG = textG = arrowG = undefined;
188187
dragElem = null;
189188
isDragging = false;
190189
rowOffsetX = 0;
191190
rowOffsetWord = null;
192191
prevX = -1;
193192

194193
rows = [];
195-
wordObjs = words || createTestWords(4, 10, 10);
194+
wordObjs = words || createTestWords(5, 6, 10);
196195
linkObjs = links || createTestMultiLinks(1);
197196
drawWords(wordObjs);
198197
drawLinks(linkObjs);
@@ -206,7 +205,8 @@
206205
}
207206

208207
document.addEventListener('keydown', handleKeyDown, false);
209-
document.querySelector('select').onchange = changeDataset;
208+
document.getElementById('random').onclick = resetDrawing.bind(this, null, null);
209+
document.getElementById('dataset').onchange = changeDataset;
210210
window.onresize = _.debounce(resize, 300);
211211

212212
};

0 commit comments

Comments
 (0)