Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made a highlighted background of labels. #15

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions www/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,82 @@ window.addEventListener('load', async () => {
for (const node of nodes) {
await makeSparqlAndUpdateStore(node.id, 'delete', 'boundary');
await makeSparqlAndUpdateStore(node.id, 'delete', 'insideBoundary');
node.classList.remove('insideBoundary', 'boundary', 'inCommissioningPackage');
node.classList.remove('insideBoundary', 'boundary');
removeCommissionHighlight(node);
}
});

async function handleNodeClick(node, event) {
// ctrl + left click - select or deselect nodes as insideBoundary
if (event.ctrlKey) {
if (node.classList.contains('insideBoundary')) {
node.classList.remove('insideBoundary', 'inCommissioningPackage');
node.classList.remove('insideBoundary');
removeCommissionHighlight(node);
await makeSparqlAndUpdateStore(node.id, 'delete', 'insideBoundary');
} else {
node.classList.add('insideBoundary');
await makeSparqlAndUpdateStore(node.id, 'insert', 'insideBoundary');
if (node.classList.contains('boundary')) {
node.classList.remove('boundary', 'inCommissioningPackage');
node.classList.remove('boundary');
removeCommissionHighlight(node);
await makeSparqlAndUpdateStore(node.id, 'delete', 'boundary');
}
}
// left click - select or deselect nodes as boundary
} else {
if (node.classList.contains('boundary')) {
node.classList.remove('boundary', 'inCommissioningPackage');
node.classList.remove('boundary');
removeCommissionHighlight(node);
await makeSparqlAndUpdateStore(node.id, 'delete', 'boundary');
} else {
node.classList.add('boundary');
await makeSparqlAndUpdateStore(node.id, 'insert', 'boundary');
if (node.classList.contains('insideBoundary')) {
node.classList.remove('insideBoundary', 'inCommissioningPackage');
node.classList.remove('insideBoundary');
removeCommissionHighlight(node);
await makeSparqlAndUpdateStore(node.id, 'delete', 'insideBoundary');
}
}
}
}

function createHighlightBox(node) {
var highlightRects = node.querySelectorAll('.commissionHighlight');
if (highlightRects.length !== 0)
return;
var bbox = node.getBBox();

// Create a new rect element
var highlightRect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
highlightRect.setAttribute('x', bbox.x);
highlightRect.setAttribute('y', bbox.y);
highlightRect.setAttribute('width', bbox.width);
highlightRect.setAttribute('height', bbox.height);
highlightRect.setAttribute('fill', 'yellow'); // Highlight color
highlightRect.setAttribute('fill-opacity', '0.2'); // Semi-transparent
highlightRect.setAttribute('class', 'commissionHighlight');
node.appendChild(highlightRect);
}

function addCommissionHighlight(node){
createHighlightBox(node);
}

function removeCommissionHighlight(node) {
var highlightRects = node.querySelectorAll('.commissionHighlight');
highlightRects.forEach(rect => rect.remove());
}

async function updateInCommissioningPackage() {
if (checkOnlyInsideBoundary()) { return ;}
let query = 'SELECT ?node WHERE{?node a data:insideBoundary .}';
let result = await queryTripleStore(query);
let nodeIds = parseNodeIds(result);
nodes.forEach(node => {
if (nodeIds.includes(node.id) && !node.classList.contains('boundary') && !node.classList.contains('insideBoundary')) {
node.classList.add('inCommissioningPackage');
addCommissionHighlight(node);
} else {
node.classList.remove('inCommissioningPackage');
removeCommissionHighlight(node);
}
});
}
Expand Down