Skip to content

Commit 0add4f7

Browse files
committed
debounce window resize and fix row height
1 parent 0a371ee commit 0add4f7

File tree

6 files changed

+94
-7
lines changed

6 files changed

+94
-7
lines changed

css/style.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ body {
88
overflow-y: scroll;
99
}
1010

11+
svg, svg text {
12+
font-family: Nunito, futura, helvetica, arial, sans-serif;
13+
font-weight:600;
14+
}
1115
svg text {
1216
cursor: default;
1317
-webkit-user-select: none;
@@ -130,6 +134,14 @@ header > button:hover {
130134
left:0;
131135
}
132136

137+
#toggle-taxonomy {
138+
font-size:0.9em;
139+
text-decoration:underline;
140+
cursor:pointer;
141+
color:steelblue;
142+
float:right;
143+
}
144+
133145
#taxonomy > ul {
134146
list-style-type: none;
135147
padding:0;
@@ -205,7 +217,6 @@ header > button:hover {
205217
position:relative;
206218
}
207219
#main text {
208-
font-family: BrownPro, Brown, futura, helvetica, arial, sans-serif;
209220
text-anchor: middle;
210221
}
211222
.row-drag {

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<link href="https://fonts.googleapis.com/css?family=Nunito:400,600" rel="stylesheet">
67
<link href="css/style.css" rel="stylesheet">
78
</head>
89

js/components/link.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,52 @@ class Link {
450450
return slots;
451451
}
452452

453-
listenForEdit() {
454-
console.log('listening');
453+
listenForEdit(e) {
454+
console.log('listening', e.detail.text, e.detail.text.text());
455455
this.isEditing = true;
456456

457+
let bbox = e.detail.text.bbox();
458+
this.svg.addClass('editing');
459+
this.editingRect = this.svg.rect(bbox.width + 8, bbox.height + 4)
460+
.x(bbox.x - 4)
461+
.y(bbox.y - 2)
462+
.rx(2)
463+
.ry(2)
464+
.back();
465+
466+
// listenForEdit() {
467+
// this.isEditing = true;
468+
// let bbox = this.svgText.bbox();
469+
//
470+
// this.svg.addClass('editing');
471+
// this.editingRect = this.svg.rect(bbox.width + 8, bbox.height + 4)
472+
// .x(bbox.x - 4)
473+
// .y(bbox.y - 2)
474+
// .rx(2)
475+
// .ry(2)
476+
// .back();
477+
// }
478+
// stopEditing() {
479+
// this.isEditing = false;
480+
// this.svg.removeClass('editing');
481+
// this.editingRect.remove();
482+
// this.editingRect = null;
483+
// this.val = this.val.trim();
484+
// if (!this.val) {
485+
// this.remove();
486+
// }
487+
// else {
488+
// this.entity.calculateBox();
489+
// }
490+
// }
491+
457492
}
458493
stopEditing() {
459494
console.log('done');
460495
this.isEditing = false;
496+
this.svg.removeClass('editing');
497+
this.editingRect.remove();
498+
this.editingRect = null;
461499
}
462500

463501
getEndpoints() {

js/main.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ const Main = (function() {
8181

8282
// window event listeners
8383
// resize function
84-
window.onresize = function() {
84+
function resizeWindow() {
8585
body = document.body.getBoundingClientRect();
8686
links.forEach(l => l.hide());
8787
svg.width(body.width);
8888
rm.width(body.width);
89-
links.forEach(l => l.show());
89+
setSyntaxVisibility();
9090
}
91+
window.onresize = debounce(resizeWindow, 200);
92+
9193
document.getElementById('dataset').onchange = function(e) {
9294
if (this.selectedIndex > 0) {
9395
changeDataset(this.selectedIndex);
@@ -229,6 +231,29 @@ const Main = (function() {
229231
// private functions
230232
//--------------------------------
231233

234+
// from https://davidwalsh.name/javascript-debounce-function,
235+
// as taken from underscore
236+
237+
// Returns a function, that, as long as it continues to be invoked, will not
238+
// be triggered. The function will be called after it stops being called for
239+
// N milliseconds. If `immediate` is passed, trigger the function on the
240+
// leading edge, instead of the trailing.
241+
function debounce(func, wait, immediate) {
242+
var timeout;
243+
return function() {
244+
var context = this, args = arguments;
245+
var later = function() {
246+
timeout = null;
247+
if (!immediate) func.apply(context, args);
248+
};
249+
var callNow = immediate && !timeout;
250+
clearTimeout(timeout);
251+
timeout = setTimeout(later, wait);
252+
if (callNow) func.apply(context, args);
253+
};
254+
};
255+
256+
232257
/** options to set visibility of syntax tree
233258
*/
234259
function setSyntaxVisibility(bool) {

js/managers/labelmanager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const LabelManager = (function() {
2828

2929
function listenForEdit(e) {
3030
activeObject = e.detail.object;
31-
activeObject.listenForEdit();
31+
activeObject.listenForEdit(e);
3232
originalString = e.detail.object.val;
3333
string = null;
3434
};

js/managers/taxonomy.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ const Taxonomy = (function() {
100100
let keys = Object.keys(tagTypes);
101101

102102
// populate taxonomy
103-
div.innerHTML = '';
103+
div.innerHTML = '<span id="toggle-taxonomy">Filter unused labels</span>';
104+
104105
let ul = document.createElement('ul');
105106
div.appendChild(ul);
106107

@@ -188,6 +189,17 @@ const Taxonomy = (function() {
188189
this.tree.hierarchy.forEach(el => createLi(el, ul));
189190
jscolor.installByClassName('jscolor');
190191

192+
document.getElementById('toggle-taxonomy').onclick = function() {
193+
if (ul.className === 'filtered') {
194+
ul.className = '';
195+
this.innerHTML = 'Show all labels';
196+
}
197+
else {
198+
ul.className = 'filtered';
199+
this.innerHTML = 'Filter unused labels';
200+
}
201+
}
202+
191203
keys.forEach((tag, i) => {
192204
tagTypes[tag].forEach(word => updateColor(word, colors[i]));
193205
});

0 commit comments

Comments
 (0)