Skip to content

Commit b797293

Browse files
Merge pull request #24 from MatinGhanbari/main
Add search box
2 parents 8338530 + 181c939 commit b797293

File tree

1 file changed

+89
-7
lines changed

1 file changed

+89
-7
lines changed

visualization/index.html

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,55 @@
7474
-moz-user-select: none;
7575
-ms-user-select: none;
7676
user-select: none;
77+
}.search-box-container{
78+
position: fixed;
79+
direction: rtl;
80+
display: flex;
81+
justify-content: center;
82+
top: 5px;
83+
width: 90%;
84+
margin: 5%;
85+
margin-top: 0;
86+
height: 50px;
87+
z-index: 1;
88+
}.search-box{
89+
width: 250px;
90+
height: 35px;
91+
padding: 10px;
92+
margin-top: 0;
93+
background: rgba(255, 255, 255, 0.1);
94+
border: 2px solid rgba(0, 0, 0, 0.163);
95+
backdrop-filter: blur(10px);
96+
-webkit-backdrop-filter: blur(10px);
97+
z-index: 1;
98+
transition: all 0.3s ease;
99+
}.search-item{
100+
width: 250px;
101+
height: 35px;
102+
padding: 10px;
103+
background: rgba(255, 255, 255, 0.675);
104+
backdrop-filter: blur(10px);
105+
-webkit-backdrop-filter: blur(10px);
106+
z-index: 1;
107+
transition: all 0.3s ease;
108+
}.search-item:hover{
109+
background: rgba(76, 76, 76, 0.675);
110+
transition: all 0.5 ease;
77111
}
78112
</style>
79113
</head>
80114
<body>
81-
<div
82-
class="graph_wrapper ibm-plex-sans-arabic-thin no-select"
83-
id="graph"
84-
></div>
85-
<div class="dialog ibm-plex-sans-arabic-regular" id="nodePropertiesDialog">
115+
<div class="graph_wrapper no-select" id="graph"></div>
116+
<div class="search-box-container no-select flex" id="search-box">
117+
<div id="searchDropdown" class="dropdown-content">
118+
<input type="text" id="serach-input" class="search-box"
119+
onfocusout="closeSearch();"
120+
onkeyup="searchStation()"
121+
onfocus="closeDialog();searchStation()"
122+
placeholder="نام ایستگاه را جستجو کنید ..."></div>
123+
</div>
124+
</div>
125+
<div class="dialog" id="nodePropertiesDialog">
86126
<div class="dialog-header">
87127
<span id="dialogTitle">اطلاعات ایستگاه</span>
88128
<button id="closeDialogBtn">X</button>
@@ -114,9 +154,21 @@
114154
);
115155
const stations = await response.json();
116156

157+
const searchDropdown = document.getElementById("searchDropdown");
158+
117159
// add nodes and relationships based on the graph data
118160
for (let station in stations) {
119161
graph.addNode(station, stations[station]);
162+
163+
var span = document.createElement('span');
164+
span.style.display="none"
165+
span.classList.add("search-item");
166+
span.innerHTML = stations[station].translations.fa;
167+
span.addEventListener("mousedown", function (e) {
168+
RenderNodeProperties({data:stations[station]});
169+
});
170+
searchDropdown.appendChild(span);
171+
120172
for (let relationship of stations[station].relations) {
121173
graph.addLink(station, relationship);
122174
}
@@ -207,8 +259,35 @@
207259
});
208260
renderer.run();
209261
};
262+
263+
264+
function closeSearch() {
265+
const items = document.querySelectorAll(".search-item");
266+
for (let i = 0; i < items.length; i++) {
267+
items[i].style.display = "none";
268+
}
269+
}
270+
271+
function searchStation() {
272+
closeDialog();
273+
const serachInput = document.getElementById("serach-input");
274+
const filter = serachInput.value.toUpperCase();
275+
const items = document.querySelectorAll(".search-item");
276+
277+
for (let i = 0; i < items.length; i++) {
278+
txtValue = items[i].textContent || a[i].innerText;
279+
if(filter==""){
280+
items[i].style.display = "none";
281+
}else if (txtValue.toUpperCase().indexOf(filter) > -1) {
282+
items[i].style.display = "block";
283+
} else {
284+
items[i].style.display = "none";
285+
}
286+
}
287+
}
210288

211289
function RenderNodeProperties(node) {
290+
closeSearch();
212291
const dialog = document.getElementById("nodePropertiesDialog");
213292
const nodeNameElement = document.getElementById("nodeName");
214293
const nodeAddressElement = document.getElementById("nodeAddress");
@@ -233,8 +312,11 @@
233312
closeButton.onclick = function () {
234313
dialog.style.display = "none";
235314
};
236-
nodeAddressElement.addEventListener("click", handleAddressClick);
237-
nodeAddressElement.addEventListener("touchstart", handleAddressClick);
315+
}
316+
317+
function closeDialog() {
318+
const dialog = document.getElementById("nodePropertiesDialog");
319+
dialog.style.display = "none";
238320
}
239321

240322
init();

0 commit comments

Comments
 (0)