Skip to content

Commit

Permalink
Relocate/pin objects option menu
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Sep 30, 2023
1 parent cfc2a6d commit 6b72425
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 23 deletions.
53 changes: 35 additions & 18 deletions public/diagram/diagram.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@
width: 10rem;
}

.button {
border-radius: 2em;
background-color: var(--background-color-action);
color: var(--color-action);
padding: 0.6em 0.3em;
font-weight: 600;
position: absolute;
top: 10px;
right: 25px;
width: 10em;
height: 4em;
z-index: 10;
}

.row {
display: flex;
flex-direction: row;
Expand All @@ -39,25 +53,21 @@
width: 3em;
position: absolute;
right: 9.5em;
top: 6em;
align-self: flex-end;
}

.button {
border-radius: 2em;
background-color: var(--background-color-action);
color: var(--color-action);
padding: 0.6em 0.3em;
font-weight: 600;
position: absolute;
top: 10px;
right: 25px;
width: 10em;
height: 4em;
z-index: 10;
#img-mode {
top: 6em;
}

#img-pin {
top: 10em;
right: 9em;
width: 4em;
height: 2.75em;
}

#toggle {
.toggle {
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
Expand All @@ -66,15 +76,22 @@
border-radius: 30px;
background-color: var(--color-action);
position: absolute;
top: 6em;
right: 3em;
transition: all 0.5s ease-in;
cursor: pointer;
z-index: 10;
}

#toggle-mode {
top: 6em;
}

#toggle-pin {
top: 10em;
}

/* Making a dot switch inside the Toggle Button */
#toggle::before {
.toggle::before {
content: "";
width: 25px;
height: 25px;
Expand All @@ -88,12 +105,12 @@
}

/* Changing toggle button background when checked */
#toggle:checked {
.toggle:checked {
background-color: var(--background-color-action);
}

/* Changing dot switch color and moving to the right side when checked */
#toggle:checked::before {
.toggle:checked::before {
background: var(--color-action);
left: 32px;
}
17 changes: 15 additions & 2 deletions public/diagram/diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ function updateNodes(elements) {
layout.run()
}

function objectsPositionChanged() {
const newTitle = objectsKeepTheirPosition() ? 'ON -> objects will keep their positions' : 'OFF -> objects will be relocated to fit into the graph layout'
document.getElementById('toggle-pin').setAttribute('title', `Fix objects position: ${newTitle}`)
}

function objectsKeepTheirPosition() {
return document.getElementById('toggle-pin').checked
}

function reloadDiagram(elements) {
currentElements = [...elements]
changeElementsMode()
Expand All @@ -132,7 +141,7 @@ function reloadDiagram(elements) {

const newElements = elements.filter((element) => !cy.hasElementWithId(element.data.id))
if (newElements.length) {
const shouldUpdateLayout = cy.elements().length === 0
const shouldUpdateLayout = !objectsKeepTheirPosition() || cy.elements().length === 0
const addedNodes = cy.add(newElements)
if (shouldUpdateLayout) {
updateLayout()
Expand All @@ -156,6 +165,10 @@ function readyForLayoutElems(elements) {
}

function modeChanged() {
const toggleMode = document.getElementById('toggle-mode')
const newTitle = toggleMode.checked ? 'Dark mode ON' : 'Light Mode ON'
toggleMode.setAttribute('title', newTitle)

document.getElementById('main').style = `background-color: ${backgroundColor()}`
cy.elements().remove()
reloadDiagram(currentElements)
Expand All @@ -166,7 +179,7 @@ function backgroundColor() {
}

function isDarkMode() {
return document.getElementById('toggle').checked
return document.getElementById('toggle-mode').checked
}

function changeElementsMode() {
Expand Down
Binary file modified public/diagram/images/dark-mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/diagram/images/pin-objects.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions public/diagram/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
<button class="button" onclick="updateLayout()" title="Relocate the objects and their relationships in the diagram">ORGANIZE</button>
<!-- Modo Oscuro/Claro -->
<div class="row">
<img src="images/dark-mode.png" title="Dark/Light mode"/>
<input type="checkbox" id="toggle" title="Dark/Light mode" onchange="modeChanged()">
<img src="images/dark-mode.png" id="img-mode" title="Dark/Light mode"/>
<input type="checkbox" id="toggle-mode" class="toggle" onchange="modeChanged()">
</div>
<div class="row">
<img src="images/pin-objects.png" id="img-pin" title="Fix objects position"/>
<input type="checkbox" id="toggle-pin" class="toggle" onshow="objectsPositionChanged()" onchange="objectsPositionChanged()">
</div>
</div>
<script type="module">
Expand All @@ -46,7 +50,7 @@
initializeCytoscape(document.getElementById("cy"));

socket.on("initDiagram", function (options) {
document.getElementById('toggle').checked = options?.darkMode ?? false;
document.getElementById('toggle-mode').checked = options?.darkMode ?? false;
modeChanged();
});

Expand Down

0 comments on commit 6b72425

Please sign in to comment.