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

Visualization of MCParticle + RecoParticle #43

Merged
merged 20 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bea1ab5
feat: fix loading and prepare objects to be placed on canvas by algor…
brauliorivas Jun 24, 2024
7714291
feat: fix loading and prepare objects to be placed on canvas by algor…
brauliorivas Jun 24, 2024
c252b87
Merge branch 'feat/mc-reco-view' of github.com:brauliorivas/dmx into …
brauliorivas Jun 24, 2024
8f6f45d
add more links and begin with random positions
brauliorivas Jun 25, 2024
b66f72d
feat: fix loading and prepare objects to be placed on canvas by algor…
brauliorivas Jun 24, 2024
cd887e5
add more links and begin with random positions
brauliorivas Jun 25, 2024
94088a8
Merge branch 'feat/mc-reco-view' of github.com:brauliorivas/dmx into …
brauliorivas Jun 25, 2024
67db9c2
feat: fix loading and prepare objects to be placed on canvas by algor…
brauliorivas Jun 24, 2024
34c8c0c
add more links and begin with random positions
brauliorivas Jun 25, 2024
ac1632e
fix filtering with new logic and test
brauliorivas Jun 26, 2024
e8affde
fix conflict
brauliorivas Jun 26, 2024
b236c65
Merge branch 'feat/contact-modal' into feat/mc-reco-view
brauliorivas Jun 26, 2024
b030b93
give enough space on limits
brauliorivas Jun 26, 2024
8c0135c
Merge branch 'feat/contact-modal' into feat/mc-reco-view
brauliorivas Jun 26, 2024
6022e7d
visualize recoparticles in a tree like structure
brauliorivas Jun 27, 2024
ea0b7a6
Merge branch 'main' into feat/mc-reco-view
brauliorivas Jun 29, 2024
322759f
build 3 views for visualizations
brauliorivas Jun 30, 2024
1229aac
add proper name for views
brauliorivas Jun 30, 2024
16288eb
add back filters (temporary solution)
brauliorivas Jun 30, 2024
0dc5988
fix pdg toggle for mcparticle tree view
brauliorivas Jul 1, 2024
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
41 changes: 41 additions & 0 deletions css/views.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#available-views {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: flex-start;
align-items: center;
padding: 8px;
}

.view-button {
background-color: #f1f1f1;
border: 1px solid #000;
border-radius: 5px;
padding: 8px;
margin: 8px;
cursor: pointer;
height: fit-content;
}

#views {
display: none;
flex-direction: column;
position: fixed;
top: 25%;
left: 10px;
width: fit-content;
height: 50%;
background-color: #e1e1e1;
padding: 15px;
border: 1px solid #000;
border-radius: 5px;
}

#view-selector {
display: flex;
flex-direction: column;
justify-content: flex-start;
overflow-y: auto;
overflow-x: hidden;
width: fit-content;
}
11 changes: 10 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<link rel="stylesheet" href="css/event.css">
<link rel="stylesheet" href="css/information.css">
<link rel="stylesheet" href="css/contact.css">
<link rel="stylesheet" href="css/views.css">
</head>

<body>
Expand All @@ -41,6 +42,8 @@
<label class="mr-10" for="event-number">Select event number:</label>
<select name="event-number" id="event-number"></select>
</div>
<div id="available-views">
</div>
<br>
<div class="align-right">
<button id="visualize-button">Visualize</button>
Expand Down Expand Up @@ -147,12 +150,18 @@
</div>
</div>

<div id="views">
<p>Select a view:</p>
<div id="view-selector"></div>
</div>

<canvas id="canvas" width="100vw" height="100vh"></canvas>

<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js" type="text/javascript"></script>
<script type="module" src="js/main.js"></script>
<script type="module" src="js/menu/filter/filter.js"></script>
<script type="module" src="js/information.js"></script>
<script type="module" src="js/views/views.js"></script>
<script type="module" src="js/menu/filter/filter.js"></script>
</body>

</html>
45 changes: 28 additions & 17 deletions js/draw.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
import { canvas, ctx } from "./main.js";

export function drawAll(ctx, loadedObjects) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
function draw(objects) {
const datatypes = objects.datatypes;
const associations = objects.associations;

for (const elements of Object.values(loadedObjects)) {
for (const collection of Object.values(associations)) {
for (const association of collection) {
association.draw(ctx);
}
}

for (const elements of Object.values(datatypes)) {
const { collection, oneToMany, oneToOne } = elements;

for (const links of Object.values(oneToMany)) {
for (const link of links) link.draw(ctx);
for (const link of links) {
link.draw(ctx);
}
}

for (const link of Object.values(oneToOne)) link.draw(ctx);
for (const links of Object.values(oneToOne)) {
for (const link of links) {
link.draw(ctx);
}
}

for (const object of collection) object.draw(ctx);
for (const object of collection) {
object.draw(ctx);
}
}
}

export function drawAll(loadedObjects) {
ctx.clearRect(0, 0, canvas.width, canvas.height);

draw(loadedObjects);
}

export function drawVisible(visibleObjects) {
const boundigClientRect = canvas.getBoundingClientRect();
ctx.clearRect(
Expand All @@ -25,15 +46,5 @@ export function drawVisible(visibleObjects) {
window.innerHeight
);

for (const elements of Object.values(visibleObjects)) {
const { collection, oneToMany, oneToOne } = elements;

for (const links of Object.values(oneToMany)) {
for (const link of links) link.draw(ctx);
}

for (const link of Object.values(oneToOne)) link.draw(ctx);

for (const object of collection) object.draw(ctx);
}
draw(visibleObjects);
}
73 changes: 73 additions & 0 deletions js/event-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { loadObjects } from "./types/load.js";
import { copyObject } from "./lib/copy.js";
import { canvas, jsonData, selectedObjectTypes } from "./main.js";
import { objectTypes } from "./types/objects.js";
import { drawCurrentView, saveScrollLocation } from "./views/views.js";

const eventNumber = document.getElementById("selected-event");
const previousEvent = document.getElementById("previous-event");
const nextEvent = document.getElementById("next-event");

const currentEvent = {};

const eventCollection = {};
const currentObjects = {};

function updateEventNumber() {
if (eventNumber.firstChild) {
eventNumber.removeChild(eventNumber.firstChild);
}
eventNumber.appendChild(
document.createTextNode(`Event: ${currentEvent.event}`)
);
}

function loadSelectedEvent() {
if (eventCollection[currentEvent.event] === undefined) {
const objects = loadObjects(
jsonData.data,
currentEvent.event,
selectedObjectTypes.types
);

eventCollection[currentEvent.event] = objects;

for (const [key, value] of Object.entries(
eventCollection[currentEvent.event].datatypes
)) {
const classType = objectTypes[key];
const collection = value.collection;
classType.setup(collection, canvas);
}
copyObject(objects, currentObjects);
} else {
copyObject(eventCollection[currentEvent.event], currentObjects);
}
}

export function renderEvent(eventNumber) {
saveScrollLocation();
currentEvent.event = eventNumber;
loadSelectedEvent();
updateEventNumber();
drawCurrentView();
}

previousEvent.addEventListener("click", () => {
const newEventNum = `${parseInt(currentEvent.event) - 1}`;
renderEvent(newEventNum);
});
nextEvent.addEventListener("click", () => {
const newEventNum = `${parseInt(currentEvent.event) + 1}`;
renderEvent(newEventNum);
});
eventNumber.addEventListener("click", () => {
const eventSelectorMenu = document.getElementById("event-selector-menu");
if (eventSelectorMenu.style.display === "flex") {
eventSelectorMenu.style.display = "none";
} else {
eventSelectorMenu.style.display = "flex";
}
});

export { currentObjects, currentEvent };
46 changes: 33 additions & 13 deletions js/events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { canvas, ctx } from "./main.js";
import { canvas } from "./main.js";
import { drawAll, drawVisible } from "./draw.js";

const mouseDown = function (event, visibleObjects, dragTools) {
Expand All @@ -10,7 +10,7 @@ const mouseDown = function (event, visibleObjects, dragTools) {
dragTools.prevMouseX = mouseX;
dragTools.prevMouseY = mouseY;

for (const { collection } of Object.values(visibleObjects)) {
for (const { collection } of Object.values(visibleObjects.datatypes)) {
for (const object of collection) {
if (object.isHere(mouseX, mouseY)) {
dragTools.draggedObject = object;
Expand All @@ -30,7 +30,7 @@ const mouseUp = function (event, currentObjects, dragTools) {
dragTools.isDragging = false;

// console.time("drawAll");
drawAll(ctx, currentObjects);
drawAll(currentObjects);
// console.timeEnd("drawAll");
};

Expand All @@ -47,7 +47,6 @@ const mouseMove = function (event, visibleObjects, dragTools) {
if (!dragTools.isDragging) {
return;
}
event.preventDefault();

const boundigClientRect = canvas.getBoundingClientRect();
const mouseX = parseInt(event.clientX - boundigClientRect.x);
Expand All @@ -60,9 +59,7 @@ const mouseMove = function (event, visibleObjects, dragTools) {
draggedObject.x += dx;
draggedObject.y += dy;

// console.time("drawVisible");
drawVisible(visibleObjects);
// console.timeEnd("drawVisible");

dragTools.prevMouseX = mouseX;
dragTools.prevMouseY = mouseY;
Expand All @@ -71,10 +68,14 @@ const mouseMove = function (event, visibleObjects, dragTools) {
const getVisible = function (loadedObjects, visibleObjects) {
const boundigClientRect = canvas.getBoundingClientRect();

for (const [objectType, elements] of Object.entries(loadedObjects)) {
visibleObjects.datatypes = {};
visibleObjects.associations = {};
for (const [objectType, elements] of Object.entries(
loadedObjects.datatypes ?? {}
)) {
const { collection, oneToMany, oneToOne } = elements;

visibleObjects[objectType] = {
visibleObjects.datatypes[objectType] = {
collection: [],
oneToMany: {},
oneToOne: {},
Expand All @@ -89,12 +90,12 @@ const getVisible = function (loadedObjects, visibleObjects) {
window.innerHeight
)
) {
visibleObjects[objectType].collection.push(object);
visibleObjects.datatypes[objectType].collection.push(object);
}
}

for (const [name, links] of Object.entries(oneToMany)) {
visibleObjects[objectType].oneToMany[name] = [];
visibleObjects.datatypes[objectType].oneToMany[name] = [];

for (const link of links) {
if (
Expand All @@ -105,13 +106,13 @@ const getVisible = function (loadedObjects, visibleObjects) {
window.innerHeight
)
) {
visibleObjects[objectType].oneToMany[name].push(link);
visibleObjects.datatypes[objectType].oneToMany[name].push(link);
}
}
}

for (const [name, links] of Object.entries(oneToOne)) {
visibleObjects[objectType].oneToOne[name] = null;
visibleObjects.datatypes[objectType].oneToOne[name] = [];

for (const link of links) {
if (
Expand All @@ -122,11 +123,30 @@ const getVisible = function (loadedObjects, visibleObjects) {
window.innerHeight
)
) {
visibleObjects[objectType].oneToOne[name] = link;
visibleObjects.datatypes[objectType].oneToOne[name].push(link);
}
}
}
}

for (const [name, links] of Object.entries(
loadedObjects.associations ?? {}
)) {
visibleObjects.associations[name] = [];

for (const link of links) {
if (
link.isVisible(
0 - boundigClientRect.x,
0 - boundigClientRect.y,
window.innerWidth,
window.innerHeight
)
) {
visibleObjects.associations[name].push(link);
}
}
}
};

const onScroll = function (currentObjects, visibleObjects) {
Expand Down
47 changes: 47 additions & 0 deletions js/filter/mcparticle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { PdgToggle } from "../menu/show-pdg.js";
import {
bits,
genStatus,
renderRangeParameters,
parametersRange,
renderGenSim,
start,
getWidthFilterContent,
} from "../menu/filter/filter.js";
import { drawAll } from "../draw.js";

const filter = document.getElementById("filter");
const filters = document.getElementById("filters");
const manipulationTools = document.getElementsByClassName("manipulation-tool");

export function setupMCParticleFilter(
viewObjects,
viewCurrentObjects,
viewVisibleObjects
) {
for (const tool of manipulationTools) {
tool.style.display = "flex";
}
const mcObjects =
viewCurrentObjects.datatypes["edm4hep::MCParticle"].collection;
genStatus.reset();
mcObjects.forEach((mcObject) => {
genStatus.add(mcObject.generatorStatus);
});
genStatus.setCheckBoxes();
filters.replaceChildren();

renderRangeParameters(parametersRange);
renderGenSim(bits, genStatus);

const width = getWidthFilterContent();
filter.style.width = width;
const pdgToggle = new PdgToggle("show-pdg");
pdgToggle.init(() => {
pdgToggle.toggle(viewCurrentObjects, () => {
drawAll(viewCurrentObjects);
});
});

start(viewObjects, viewCurrentObjects, viewVisibleObjects);
}
Loading
Loading