Skip to content

Commit 5a811a0

Browse files
committed
basic search bar for word/label
1 parent 420528d commit 5a811a0

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ svg text {
6161
display:block;
6262
cursor:pointer;
6363
}
64+
#search-minimap {
65+
display:block;
66+
width:100px;
67+
}
6468
#minimap {
6569
pointer-events:none;
6670
position:fixed;

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
<div id="minimap" class="noselect">
2626
<a id="toggle-minimap">hide>></a>
27+
<input type="text" id="search-minimap">
2728
<canvas>
2829
</canvas>
2930
</div>

js/GraphLayout.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ const GraphLayout = (function() {
203203
// -------- in progress
204204
// test case : Pos_reg --> graft "outside"
205205
// test case : Promotes --> graft "inside"
206+
// test case : Ubiquitination --> graft left
206207
// test case : Phosphorylation --> two
207208
/* let graftLeftOfRoot = data.anchor.x < this.data[index].root.x;
208209

js/minimap.js

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ const Minimap = (function() {
1212
const PADDING = 3;
1313
const COLOR = {
1414
word: '#888',
15-
untagged: '#aaa',
15+
untagged: '#bbb',
1616
selected: 'crimson',
17-
link: 'cyan'
17+
link: 'magenta',
18+
highlight: 'cyan',
19+
unhighlight: '#666'
1820
}
1921

2022
function update() {
@@ -35,10 +37,20 @@ const Minimap = (function() {
3537

3638
row.words.forEach(function(word) {
3739
// choose color
38-
ctx.fillStyle = word.tag ? COLOR.word : COLOR.untagged;
39-
if (word.isSelected) {
40+
if (searchTerm) {
41+
if (word.val.toLowerCase().includes(searchTerm) || (word.tag && word.tag.toLowerCase().includes(searchTerm))) {
42+
ctx.fillStyle = COLOR.highlight;
43+
}
44+
else {
45+
ctx.fillStyle = COLOR.untagged;
46+
}
47+
}
48+
else if (word.isSelected) {
4049
ctx.fillStyle = COLOR.selected;
4150
}
51+
else {
52+
ctx.fillStyle = word.tag ? COLOR.word : COLOR.untagged;
53+
}
4254

4355
// add word rectangle
4456
ctx.fillRect(word.underneathRect.x() * r, (slots[i] - 1) * RECT_HEIGHT + i * PADDING, word.underneathRect.width() * r,RECT_HEIGHT + PADDING / 3);
@@ -57,9 +69,15 @@ const Minimap = (function() {
5769
let y = (slots[minRow - 1] || 0) + rows[minRow].maxSlots - link.h;
5870

5971
// choose color
60-
ctx.fillStyle = COLOR.link;
61-
62-
if (!link.isSelected && link.style) {
72+
if (searchTerm) {
73+
if (link.textStr.toLowerCase().includes(searchTerm)) {
74+
ctx.fillStyle = COLOR.highlight;
75+
}
76+
else {
77+
ctx.fillStyle = COLOR.unhighlight;
78+
}
79+
}
80+
else if (!link.isSelected && link.style) {
6381
if (link.style.stroke instanceof LinearGradient) {
6482
let x = (maxRow > minRow) ? 0 : link.linesLeftX[0];
6583
let gradient = ctx.createLinearGradient(x * r,0,width * r,0);
@@ -71,6 +89,9 @@ const Minimap = (function() {
7189
ctx.fillStyle = link.style.stroke;
7290
}
7391
}
92+
else {
93+
ctx.fillStyle = COLOR.link;
94+
}
7495
ctx.fillRect(link.linesLeftX[0] * r, y * RECT_HEIGHT + minRow * PADDING, width * r, RECT_HEIGHT);
7596

7697
// draw links spanning multiple rows
@@ -107,9 +128,11 @@ const Minimap = (function() {
107128
}
108129

109130
// drag events
131+
let dragStart = null;
110132
let drag = 0;
111133
let mousedown = false;
112134
function onmousedown(e) {
135+
dragStart = e;
113136
drag = e.y;
114137
mousedown = true;
115138
}
@@ -119,15 +142,22 @@ const Minimap = (function() {
119142
drag = e.y;
120143
}
121144
}
122-
function onmouseup() {
123-
mousedown = false;
124-
}
125145

126146
let clicked = false;
127147
let click = 0;
128-
function onclick(e) {
129-
clicked = true;
130-
click = e.offsetY / e.target.getBoundingClientRect().height;
148+
function onmouseup(e) {
149+
if (mousedown) {
150+
if (Math.abs(e.x - dragStart.x) < 2 && Math.abs(e.y - dragStart.y) < 2) {
151+
clicked = true;
152+
click = e.offsetY / e.target.getBoundingClientRect().height;
153+
}
154+
mousedown = false;
155+
}
156+
}
157+
158+
let searchTerm = null;
159+
function search() {
160+
searchTerm = this.value.trim().toLowerCase() || null;
131161
}
132162

133163
class Minimap {
@@ -148,11 +178,14 @@ const Minimap = (function() {
148178

149179
// swipe minimap to scroll page
150180
view.onmousedown = onmousedown;
151-
view.onclick = onclick;
152181
document.addEventListener('mousemove', onmousemove);
153182
document.addEventListener('mouseup', onmouseup);
154183
document.addEventListener('mouseleave', onmouseup);
155184

185+
// add search functionality
186+
document.getElementById('search-minimap').onchange = search;
187+
document.getElementById('search-minimap').onkeyup = search;
188+
156189
h = view.height;
157190
w = view.width;
158191
ctx = view.getContext('2d');

0 commit comments

Comments
 (0)