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

Load particles according to edm4hep #36

Merged
merged 39 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3cfbb4c
create initial types of collections defined in gsoc
brauliorivas May 29, 2024
186024e
loading function to check if types are correctly working
brauliorivas May 31, 2024
fbfb0ea
test suite for loadParticles and buildLoader
brauliorivas May 31, 2024
c7b270c
change example data for RecoParticle test
brauliorivas May 31, 2024
170de18
Merge branch 'main' into new-types
brauliorivas May 31, 2024
27d03ec
check if previews work
brauliorivas May 31, 2024
0a52737
small change
brauliorivas May 31, 2024
02392eb
another small change
brauliorivas May 31, 2024
13978a4
remove unnecessary exclamation mark
brauliorivas Jun 2, 2024
5f48b1d
eliminate try catch
brauliorivas Jun 3, 2024
00bb203
add version check + dynamic load of object
brauliorivas Jun 3, 2024
83a9bbd
update tests
brauliorivas Jun 3, 2024
3e64c41
types for RecoParticle relations including 1:1 and 1:many
brauliorivas Jun 4, 2024
f7a14c5
add links for types
brauliorivas Jun 5, 2024
904cd51
test for loading functions
brauliorivas Jun 6, 2024
ba9630c
test reconstruction
brauliorivas Jun 6, 2024
69f3fd6
remove a few things
brauliorivas Jun 7, 2024
a1afbfe
extract up-to-date types from edm4hep
brauliorivas Jun 9, 2024
1715a04
Merge branch 'new-types' into dynamic-types
brauliorivas Jun 9, 2024
cc58efa
load particles according to edm4hep.yaml definition
brauliorivas Jun 9, 2024
49d5e6e
improvements (advised) and create test a better test suite
brauliorivas Jun 10, 2024
0e30a99
add documentation to update-on-demand for dmx
brauliorivas Jun 11, 2024
1ff80b6
renaming from particle -> object
brauliorivas Jun 11, 2024
9ba9506
drop types for datatypes
brauliorivas Jun 11, 2024
57348db
correct file naming
brauliorivas Jun 11, 2024
c2b0742
typo in MODEl.md
brauliorivas Jun 12, 2024
c0c7387
Merge branch 'main' into dynamic-types
brauliorivas Jun 12, 2024
8e83913
Merge branch 'dynamic-types' of github.com:brauliorivas/dmx into dyna…
brauliorivas Jun 12, 2024
8e82181
[WIP] setup loading to later draw MCParticles
brauliorivas Jun 13, 2024
27ba065
fix typos in MODEL.md
brauliorivas Jun 13, 2024
e82ba4c
implement @tmadlener random color generator
brauliorivas Jun 13, 2024
9c0ee0a
minimal drawing for MCParticle
brauliorivas Jun 13, 2024
cd53b06
good working drawing
brauliorivas Jun 13, 2024
aeb04e2
dmx works with new loading functionality
brauliorivas Jun 13, 2024
fc45409
dmx completely using new loading function
brauliorivas Jun 14, 2024
bb0bc73
remove old files + fix filter function + fix lib
brauliorivas Jun 14, 2024
26597ee
new loading is done. [WIP] new test suite
brauliorivas Jun 14, 2024
0c1538b
add very basic tests for new loading logic
brauliorivas Jun 15, 2024
c37b2f3
check for correct object loading and links when reading a json file f…
brauliorivas Jun 17, 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
60 changes: 24 additions & 36 deletions js/draw.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,39 @@
import { canvas, ctx } from "./main.js";

export function drawAll(ctx, currentParticles) {
const { parentLinks, childrenLinks, infoBoxes } = currentParticles;

export function drawAll(ctx, loadedObjects) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// console.time("drawParentLinks");
for (const link of parentLinks) {
link.draw(ctx, infoBoxes);
}
// console.timeEnd("drawParentLinks");
// console.time("drawChildrenLinks");
for (const link of childrenLinks) {
link.draw(ctx, infoBoxes);
}
// console.timeEnd("drawChildrenLinks");
// console.time("drawBoxes");
for (const infoBox of infoBoxes) {
if (infoBox !== null) infoBox.draw(ctx);
}
// console.timeEnd("drawBoxes");
}

export function drawVisible(currentParticles, visibleParticles) {
const {
infoBoxes: visibleBoxes,
parentLinks: visibleParentLinks,
childrenLinks: visibleChildrenLinks,
} = visibleParticles;
for (const elements of Object.values(loadedObjects)) {
const { collection, oneToMany, oneToOne } = elements;

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

const { parentLinks, childrenLinks, infoBoxes } = currentParticles;
for (const link of Object.values(oneToOne)) link.draw(ctx);

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

export function drawVisible(visibleObjects) {
const boundigClientRect = canvas.getBoundingClientRect();
ctx.clearRect(
0 - boundigClientRect.x,
0 - boundigClientRect.y,
window.innerWidth,
window.innerHeight
);
for (const linkId of visibleParentLinks) {
if (parentLinks[linkId] !== undefined)
parentLinks[linkId].draw(ctx, infoBoxes);
}
for (const linkId of visibleChildrenLinks) {
if (childrenLinks[linkId] !== undefined)
childrenLinks[linkId].draw(ctx, infoBoxes);
}
for (const boxId of visibleBoxes) {
infoBoxes[boxId].draw(ctx);

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);
}
}
147 changes: 68 additions & 79 deletions js/events.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { canvas, ctx } from "./main.js";
import { drawAll, drawVisible } from "./draw.js";

const mouseDown = function (
event,
currentParticles,
visibleParticles,
dragTools
) {
const mouseDown = function (event, visibleObjects, dragTools) {
event.preventDefault();
const boundigClientRect = canvas.getBoundingClientRect();
const mouseX = parseInt(event.clientX - boundigClientRect.x);
Expand All @@ -15,18 +10,18 @@ const mouseDown = function (
dragTools.prevMouseX = mouseX;
dragTools.prevMouseY = mouseY;

const infoBoxes = currentParticles.infoBoxes;
const visibleBoxes = visibleParticles.infoBoxes;
for (let i = visibleBoxes.length - 1; i >= 0; i--) {
if (infoBoxes[visibleBoxes[i]].isHere(mouseX, mouseY)) {
dragTools.draggedInfoBox = visibleBoxes[i];
dragTools.isDragging = true;
return;
for (const { collection } of Object.values(visibleObjects)) {
for (const object of collection) {
if (object.isHere(mouseX, mouseY)) {
dragTools.draggedObject = object;
dragTools.isDragging = true;
return;
}
}
}
};

const mouseUp = function (event, particlesHandler, dragTools) {
const mouseUp = function (event, currentObjects, dragTools) {
if (!dragTools.isDragging) {
return;
}
Expand All @@ -35,7 +30,7 @@ const mouseUp = function (event, particlesHandler, dragTools) {
dragTools.isDragging = false;

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

Expand All @@ -48,12 +43,7 @@ const mouseOut = function (event, dragTools) {
dragTools.isDragging = false;
};

const mouseMove = function (
event,
currentParticles,
visibleParticles,
dragTools
) {
const mouseMove = function (event, visibleObjects, dragTools) {
if (!dragTools.isDragging) {
return;
}
Expand All @@ -66,82 +56,81 @@ const mouseMove = function (
const dx = mouseX - dragTools.prevMouseX;
const dy = mouseY - dragTools.prevMouseY;

const infoBox = currentParticles.infoBoxes[dragTools.draggedInfoBox];
infoBox.x += dx;
infoBox.y += dy;
const draggedObject = dragTools.draggedObject;
draggedObject.x += dx;
draggedObject.y += dy;

// console.time("drawVisible");
drawVisible(currentParticles, visibleParticles);
drawVisible(visibleObjects);
// console.timeEnd("drawVisible");

dragTools.prevMouseX = mouseX;
dragTools.prevMouseY = mouseY;
};

const getVisible = function (currentParticles, visibleParticles) {
const getVisible = function (loadedObjects, visibleObjects) {
const boundigClientRect = canvas.getBoundingClientRect();

const { infoBoxes, parentLinks, childrenLinks } = currentParticles;

const visibleBoxes = [];
const visibleParentLinks = [];
const visibleChildrenLinks = [];

for (const box of infoBoxes) {
if (box === null) continue;
if (
box.isVisible(
0 - boundigClientRect.x,
0 - boundigClientRect.y,
window.innerWidth,
window.innerHeight
)
) {
visibleBoxes.push(box.id);
for (const [objectType, elements] of Object.entries(loadedObjects)) {
const { collection, oneToMany, oneToOne } = elements;

visibleObjects[objectType] = {
collection: [],
oneToMany: {},
oneToOne: {},
};

for (const object of collection) {
if (
object.isVisible(
0 - boundigClientRect.x,
0 - boundigClientRect.y,
window.innerWidth,
window.innerHeight
)
) {
visibleObjects[objectType].collection.push(object);
}
}
}

for (const link of parentLinks) {
if (
link.isVisible(
0 - boundigClientRect.x,
0 - boundigClientRect.y,
window.innerWidth,
window.innerHeight,
infoBoxes
)
) {
visibleParentLinks.push(link.id);
for (const [name, links] of Object.entries(oneToMany)) {
visibleObjects[objectType].oneToMany[name] = [];

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

for (const link of childrenLinks) {
if (
link.isVisible(
0 - boundigClientRect.x,
0 - boundigClientRect.y,
window.innerWidth,
window.innerHeight,
infoBoxes
)
) {
visibleChildrenLinks.push(link.id);
for (const [name, links] of Object.entries(oneToOne)) {
visibleObjects[objectType].oneToOne[name] = null;

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

/*
console.log("Visible boxes: ", visibleBoxes);
console.log("Visible parentLinks: ", visibleParentLinks);
console.log("Visible childrenLinks: ", visibleChildrenLinks);
*/

visibleParticles.infoBoxes = visibleBoxes;
visibleParticles.parentLinks = visibleParentLinks;
visibleParticles.childrenLinks = visibleChildrenLinks;
};

const onScroll = function (currentParticles, visibleParticles) {
getVisible(currentParticles, visibleParticles);
const onScroll = function (currentObjects, visibleObjects) {
getVisible(currentObjects, visibleObjects);
};

export { mouseDown, mouseUp, mouseOut, mouseMove, getVisible, onScroll };
25 changes: 25 additions & 0 deletions js/lib/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export function copyObject(objToCopy, updatedObject) {
for (const [key, value] of Object.entries(objToCopy)) {
updatedObject[key] = value;
}
}

export function emptyCopyObject(objToCopy, updatedObject) {
for (const [objectType, elements] of Object.entries(objToCopy)) {
const { _, oneToMany, oneToOne } = elements;

updatedObject[objectType] = {
collection: [],
oneToMany: {},
oneToOne: {},
};

for (const name in oneToMany) {
updatedObject[objectType].oneToMany[name] = [];
}

for (const name in oneToOne) {
updatedObject[objectType].oneToOne[name] = null;
}
}
}
13 changes: 13 additions & 0 deletions js/lib/getName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { mappings } from "../../data/particles.js";

export function getName(pdg) {
const particle = mappings[pdg];

if (particle !== undefined) {
console.log("Name: " + particle);
return particle;
}

console.log("PDG: " + pdg.toString());
return "PDG: " + pdg.toString();
}
Loading
Loading