Skip to content

Commit 803db6b

Browse files
Merge pull request #78 from OCNS/more_details_view_improvements
More details view improvements
2 parents 7a0f575 + ac10825 commit 803db6b

File tree

3 files changed

+75
-24
lines changed

3 files changed

+75
-24
lines changed

graph.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ const BUTTON_ROWS = [
6969
["forum", "issue tracker", "chat", "email"]
7070
];
7171

72-
function urlButton(type, url) {
72+
function urlButton(type, url, btnClass) {
7373
const button = document.createElement("button");
7474
let iconFile = BUTTON_ICONS[type];
7575
button.type = "button"
76-
button.classList.add('btn', 'btn-sm', 'm-1');
76+
button.classList.add('btn', 'm-1');
7777
let icon = `<img aria-hidden='true' focusable='false' class='icon' src='assets/${iconFile}'></img>`;
7878
button.innerHTML = icon + " " + type;
7979
if (url !== undefined) {
80-
button.classList.add('btn-info');
80+
button.classList.add(btnClass);
8181
button.onclick = function() {
8282
window.open(url, "_blank");
8383
}
@@ -92,6 +92,14 @@ function highlightNode(node) {
9292
if (node.id() == "simulators") {
9393
return;
9494
}
95+
// Swap out center/uncenter buttons
96+
const centerButton = document.getElementById("center_button");
97+
const uncenterButton = document.getElementById("uncenter_button");
98+
if (centerButton) {
99+
centerButton.classList.add("d-none");
100+
uncenterButton.classList.remove("d-none");
101+
}
102+
95103
// Ignore the meta node
96104
meta_node.deselect();
97105
meta_node.remove();
@@ -185,7 +193,7 @@ function highlightElement(event) {
185193
// Only unhilight node if double tapped on background
186194
// Single tap is too error prone
187195
if (event.type === "dbltap") {
188-
unhighlightNode(null);
196+
unhighlightNode(null, true);
189197
}
190198
else {
191199
console.log("No-op: single tap on background");
@@ -212,7 +220,15 @@ function highlightElement(event) {
212220
}
213221
}
214222

215-
function unhighlightNode(event) {
223+
function unhighlightNode(event, unselect) {
224+
// Swap out center/uncenter buttons
225+
const centerButton = document.getElementById("center_button");
226+
const uncenterButton = document.getElementById("uncenter_button");
227+
if (centerButton) {
228+
centerButton.classList.remove("d-none");
229+
uncenterButton.classList.add("d-none");
230+
}
231+
216232
// Ignore the meta node
217233
meta_node.restore();
218234
meta_node_edges.restore();
@@ -245,7 +261,9 @@ function unhighlightNode(event) {
245261
};
246262

247263
return_graph_to_init();
248-
showDetails(null, null);
264+
if (unselect) {
265+
showDetails(null, null);
266+
}
249267
}
250268

251269
function updateHighlights() {

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ <h5 class="offcanvas-title" id="filter_pane_label">Highlight simulators</h5>
6969
<!-- details pane -->
7070
<div class="col col-4 d-flex flex-column justify-content-between" style="height: 80vh; overflow: scroll" id="details">
7171
<div id="details_top" style="overflow-y: scroll; max-height: 80vh"></div>
72-
<div id="details_bottom"></div>
72+
<div id="details_bottom" class="border-top border-2"></div>
7373
</div>
7474
</div>
7575
</div>

index.js

+50-17
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,26 @@ function showDetails(data, connected) {
4242
let description = document.createElement("div");
4343
if (data["features"].includes("simulator")) {
4444
const quoted_sim = `[id='${data.id}']`;
45-
description.innerHTML = `<div class='d-flex justify-content-between align-items-center'>
45+
description.innerHTML = `<div class='d-flex justify-content-between align-items-center sticky-top border-bottom border-2' style='background-color: white;'>
4646
<h2>${data["full_name"]}</h2>
47-
<button class='btn btn-outline-primary align-middle' title='Center ${data["short_name"]} in the graph' onclick="highlightNode(cy.nodes('${quoted_sim.replace(/'/g, "\\'")}'));">
48-
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-bullseye" viewBox="0 0 16 16">
49-
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/>
50-
<path d="M8 13A5 5 0 1 1 8 3a5 5 0 0 1 0 10m0 1A6 6 0 1 0 8 2a6 6 0 0 0 0 12"/>
51-
<path d="M8 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6m0 1a4 4 0 1 0 0-8 4 4 0 0 0 0 8"/>
52-
<path d="M9.5 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0"/>
47+
<div id='center_button'>
48+
<button class='btn btn-outline-primary align-middle m-1 me-2' title='Center ${data["short_name"]} in the graph' onclick="highlightNode(cy.nodes('${quoted_sim.replace(/'/g, "\\'")}'));">
49+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-zoom-in" viewBox="0 0 16 16">
50+
<path fill-rule="evenodd" d="M6.5 12a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11M13 6.5a6.5 6.5 0 1 1-13 0 6.5 6.5 0 0 1 13 0"/>
51+
<path d="M10.344 11.742q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1 6.5 6.5 0 0 1-1.398 1.4z"/>
52+
<path fill-rule="evenodd" d="M6.5 3a.5.5 0 0 1 .5.5V6h2.5a.5.5 0 0 1 0 1H7v2.5a.5.5 0 0 1-1 0V7H3.5a.5.5 0 0 1 0-1H6V3.5a.5.5 0 0 1 .5-.5"/>
53+
</svg>
54+
</div>
55+
<div class="d-none" id='uncenter_button'>
56+
<button class='btn btn-outline-primary align-middle m-1 me-2' title='Go back to default view' onclick="unhighlightNode(null);">
57+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-zoom-out" viewBox="0 0 16 16">
58+
<path fill-rule="evenodd" d="M6.5 12a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11M13 6.5a6.5 6.5 0 1 1-13 0 6.5 6.5 0 0 1 13 0"/>
59+
<path d="M10.344 11.742q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1 6.5 6.5 0 0 1-1.398 1.4z"/>
60+
<path fill-rule="evenodd" d="M3 6.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5"/>
5361
</svg>
54-
</button>
5562
</div>`;
5663
} else {
57-
description.innerHTML = `<h2>${data["full_name"]}</h2>`;
64+
description.innerHTML = `<h2 class="sticky-top border-bottom border-2" style='background-color: white;'>${data["full_name"]}</h2>`;
5865
}
5966
description.innerHTML += "<p>" + data["description"] + "</p>";
6067
// Relations
@@ -103,20 +110,46 @@ function showDetails(data, connected) {
103110
link_heading.innerHTML = "Links";
104111
let tool_links = data["urls"];
105112
details_bottom.appendChild(link_heading);
113+
const flex_div = document.createElement("div");
114+
flex_div.classList.add("d-flex", "flex-wrap");
115+
const btnClasses = ["btn-primary", "btn-success", "btn-warning"];
106116
for (let row_idx=0; row_idx < BUTTON_ROWS.length; row_idx++) {
107-
let row = document.createElement("div");
108-
row.classList.add("row");
109117
// Go through elements in BUTTON_ROWS
110118
for (const button_type of BUTTON_ROWS[row_idx]) {
111-
let col = document.createElement("div");
112-
col.classList.add("col-auto");
113-
let button = urlButton(button_type, tool_links[button_type]);
114-
col.appendChild(button);
115-
row.appendChild(col);
119+
let button = urlButton(button_type, tool_links[button_type], btnClasses[row_idx]);
120+
flex_div.appendChild(button);
116121
}
117-
details_bottom.appendChild(row);
118122
}
123+
details_bottom.appendChild(flex_div);
124+
125+
// Back to simulators
126+
back_p = document.createElement("p");
127+
back_p.classList.add("mt-3");
128+
back_button = document.createElement("a");
129+
back_button.href = "#";
130+
back_button.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-counterclockwise" viewBox="0 0 16 16">
131+
<path fill-rule="evenodd" d="M8 3a5 5 0 1 1-4.546 2.914.5.5 0 0 0-.908-.417A6 6 0 1 0 8 2z"/>
132+
<path d="M8 4.466V.534a.25.25 0 0 0-.41-.192L5.23 2.308a.25.25 0 0 0 0 .384l2.36 1.966A.25.25 0 0 0 8 4.466"/>
133+
</svg>&nbsp;Back to simulators`;
134+
back_button.classList.add("btn", "btn-secondary");
135+
back_button.onclick = function() { cy.nodes(`[id = '${data.id}']`).unselect(); cy.nodes("#simulators").select(); unhighlightNode(); };
136+
back_p.appendChild(back_button);
137+
details_bottom.appendChild(back_p);
138+
// Edit footer
139+
edit_p = document.createElement("p");
140+
edit_p.classList.add("mt-3", "text-end");
141+
edit_link = document.createElement("a");
142+
edit_link.classList.add("link-secondary");
143+
edit_link.href = `${REPO_URL}/edit/${GIT_BRANCH}/${DATA_FOLDER}/${data["short_name"].replaceAll(" ", "-")}.yaml`;
144+
edit_link.innerHTML = "Edit this description on GitHub&nbsp;";
145+
edit_link.innerHTML += `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-github" viewBox="0 0 16 16">
146+
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27s1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8"/>
147+
</svg>`;
148+
edit_link.target = "_blank";
149+
edit_p.appendChild(edit_link);
150+
details_bottom.appendChild(edit_p);
119151
}
152+
120153
// hide filter pane
121154
const filterPane = new bootstrap.Offcanvas('#filter_pane');
122155
// FIXME: not quite sure what is going on here, but sometimes the internal state is incorrect

0 commit comments

Comments
 (0)