Skip to content

Commit db3d64d

Browse files
committed
Add a search box to the model viewer
Refs pombase/pombase-gocam#108
1 parent e6d068b commit db3d64d

File tree

1 file changed

+71
-4
lines changed

1 file changed

+71
-4
lines changed

gocam_view/templates/gocam_view/index.html

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
margin-left: 0.3em;
7070
}
7171
#cy-panel {
72+
margin-top: 2.5em;
7273
width: 0.1em;
7374
flex: 0 0 auto;
7475
{% if full_or_widget == 'widget' %}
@@ -78,6 +79,9 @@
7879
width: 20em;
7980
{% endif %}
8081
}
82+
#search-input {
83+
font-size: 105%;
84+
}
8185
#cy-panel-contents {
8286
display: block;
8387
}
@@ -86,7 +90,7 @@
8690
flex: 0 0 auto;
8791
}
8892
#node-details {
89-
padding: 2em 0 0 0.2em;
93+
padding: 0.2em 0 0 0.2em;
9094
{% if full_or_widget == 'widget' %}
9195
height: 200px;
9296
{% endif %}
@@ -233,6 +237,10 @@
233237

234238
delete elements['models'];
235239

240+
const isSmallJoin = models.length <= 10;
241+
242+
const nodes = elements['nodes'];
243+
236244
const geneInfoMap = elements['gene_info_map'];
237245
delete elements['gene_info_map'];
238246

@@ -246,7 +254,7 @@
246254
let seenParentIds = new Set();
247255

248256

249-
elements['nodes'].map(node => {
257+
nodes.map(node => {
250258
if (node.data.parent) {
251259
seenParentIds.add(node.data.parent);
252260
}
@@ -606,7 +614,15 @@
606614
'corner-radius': "10",
607615
'padding': "10px",
608616
'content': "data(title)",
609-
'border-width': '2px',
617+
'border-width': function(el) {
618+
let width = 2;
619+
if (isSelected(el)) {
620+
width = 6;
621+
width += models.length / 8;
622+
}
623+
return width;
624+
},
625+
610626
'border-color': '#555',
611627
};
612628

@@ -974,7 +990,7 @@
974990
}
975991
}
976992

977-
elements['nodes'].map(node => {
993+
nodes.map(node => {
978994
if (node.data.enabler_id &&
979995
rawHighlightGeneIds.length == 1 &&
980996
rawHighlightGeneIds[0] == node.data.enabler_id.replace(/.*:/, '')) {
@@ -1000,12 +1016,58 @@
10001016
updateDetails();
10011017
});
10021018

1019+
const searchBoxDiv = document.getElementById('search-box');
1020+
window.showSearch = function() {
1021+
if (searchBoxDiv.style.display == 'none') {
1022+
searchBoxDiv.style.display = 'block';
1023+
} else {
1024+
searchBoxDiv.style.display = 'none';
1025+
}
1026+
}
1027+
1028+
const doSearch = (searchText) => {
1029+
for (const node of nodes) {
1030+
if (isSmallJoin &&
1031+
(node.data.enabler_label &&
1032+
node.data.enabler_label.toLowerCase().includes(searchText) ||
1033+
node.data.enabler_id &&
1034+
node.data.enabler_id.toLowerCase().includes(searchText) ||
1035+
node.data.label &&
1036+
node.data.label.toLowerCase().includes(searchText) ||
1037+
node.data.node_id &&
1038+
node.data.node_id.toLowerCase().includes(searchText)) ||
1039+
node.data.type == 'model' &&
1040+
(node.data.label.includes(searchText) ||
1041+
node.data.id == 'gomodel:' + searchText)) {
1042+
currentData = node.data;
1043+
cy.getElementById(node.data.id).select();
1044+
break;
1045+
}
1046+
}
1047+
updateDetails();
1048+
};
1049+
1050+
const searchInput = document.getElementById('search-input');
1051+
searchInput.addEventListener("input", (e) => {
1052+
const searchText = e.target.value.trim().toLowerCase();
1053+
cy.$().unselect();
1054+
currentData = undefined;
1055+
if (searchText.length >= 2) {
1056+
doSearch(searchText);
1057+
}
1058+
});
1059+
10031060
});
10041061
</script>
10051062

10061063
<div id="cy-container">
10071064
<div id="cy"></div>
10081065
<div id="panel-buttons">
1066+
{% if full_or_widget == 'full' %}
1067+
<button id="show-search" title="Search" onclick="showSearch()">
1068+
<img width="16px" height="16px" src='data:image/svg+xml;charset=utf-8,<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg fill="%23000000" height="10mm" width="10mm" viewBox="0 0 500 500" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> <g> <path d="M483.4,454.444l-121.3-121.4c28.7-35.2,46-80,46-128.9c0-112.5-91.5-204.1-204.1-204.1S0,91.644,0,204.144 s91.5,204,204.1,204c48.8,0,93.7-17.3,128.9-46l121.3,121.3c8.3,8.3,20.9,8.3,29.2,0S491.8,462.744,483.4,454.444z M40.7,204.144 c0-90.1,73.2-163.3,163.3-163.3s163.4,73.3,163.4,163.4s-73.3,163.4-163.4,163.4S40.7,294.244,40.7,204.144z"/> </g> </svg>'/>
1069+
</button>
1070+
{% endif %}
10091071
<button id="zoom-out" title="Zoom out" onclick="modelZoomOut()">
10101072
{% if full_or_widget == 'widget' %}
10111073
-
@@ -1029,6 +1091,11 @@
10291091
<button id="save-svg-button" target="_blank" onclick="window.open(getSvgUrl(), '_blank')">View as SVG</button>
10301092
</div>
10311093
<div id="cy-panel">
1094+
{% if full_or_widget == 'full' %}
1095+
<div id="search-box" style="display: none">
1096+
<input id="search-input" placeholder="Search ..."/>
1097+
</div>
1098+
{% endif %}
10321099
<div id="cy-panel-contents">
10331100
<div id="node-details">
10341101

0 commit comments

Comments
 (0)