-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
479c227
commit c478758
Showing
10 changed files
with
150 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,59 @@ | ||
import { getContainer, getApp } from "./app.js"; | ||
import { getApp, getContainerSize, getContainer } from "./app.js"; | ||
|
||
const SPEED = 0.5; | ||
|
||
export const scrollTopLeft = () => { | ||
const container = getContainer(); | ||
const x = 0; | ||
const y = 0; | ||
|
||
container.x = x; | ||
container.y = y; | ||
|
||
return { x, y }; | ||
}; | ||
|
||
export const scrollTopCenter = () => { | ||
const container = getContainer(); | ||
const app = getApp(); | ||
const { width } = getContainerSize(); | ||
|
||
const screenWidth = app.renderer.width; | ||
const containerWidth = container.width; | ||
const containerWidth = width; | ||
|
||
const x = (screenWidth - containerWidth) / 2; | ||
const y = 0; | ||
container.x = x; | ||
container.y = y; | ||
|
||
return { x, y }; | ||
}; | ||
|
||
export const addScroll = (app) => { | ||
const container = getContainer(); | ||
const renderer = app.renderer; | ||
|
||
container.x = 0; | ||
container.y = 0; | ||
|
||
const screenWidth = renderer.width; | ||
const screenHeight = renderer.height; | ||
|
||
app.canvas.addEventListener("wheel", (e) => { | ||
if (e.shiftKey) { | ||
const deltaX = parseInt(e.deltaY * SPEED); | ||
const newXPosition = container.x - deltaX; | ||
const isXInBounds = | ||
newXPosition < 0 && | ||
newXPosition > screenWidth - getContainerSize().width; | ||
if (isXInBounds) { | ||
container.x = newXPosition; | ||
} | ||
} else { | ||
const deltaY = parseInt(e.deltaY * SPEED); | ||
|
||
const newYPosition = container.y - deltaY; | ||
|
||
const isYInBounds = | ||
newYPosition < 0 && | ||
newYPosition > screenHeight - getContainerSize().height; | ||
|
||
if (isYInBounds) { | ||
container.y = newYPosition; | ||
} | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
import { Toggle } from "./toggle.js"; | ||
export const togglePDG = async (objects) => { | ||
const collection = objects.datatypes["edm4hep::MCParticle"].collection; | ||
|
||
export class PdgToggle extends Toggle { | ||
constructor(id) { | ||
super(id); | ||
} | ||
const updatePDG = collection.map((object) => | ||
object.drawImage(`${object.name}`) | ||
); | ||
|
||
toggle(currentObjects, redraw) { | ||
const collection = | ||
currentObjects.datatypes["edm4hep::MCParticle"].collection; | ||
if (this.isSliderActive) { | ||
if (collection[0].PDG === undefined) return; | ||
for (const object of collection) { | ||
object.updateTexImg(`${object.PDG}`); | ||
} | ||
} else { | ||
if (collection[0].PDG === undefined) return; | ||
for (const object of collection) { | ||
object.updateTexImg(`${object.name}`); | ||
} | ||
} | ||
await Promise.all(updatePDG); | ||
}; | ||
|
||
redraw(); | ||
} | ||
} | ||
export const toggleId = async (objects) => { | ||
const collection = objects.datatypes["edm4hep::MCParticle"].collection; | ||
|
||
const updateId = collection.map((object) => | ||
object.drawImage(`${object.PDG}`) | ||
); | ||
|
||
await Promise.all(updateId); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
const prev = { | ||
function: null, | ||
}; | ||
|
||
export class Toggle { | ||
constructor(id) { | ||
this.isSliderActive = false; | ||
this.slider = document.getElementById(id); | ||
} | ||
|
||
init(callback) { | ||
this.slider.addEventListener("click", () => { | ||
init(activeFunction, inactiveFunction) { | ||
const newFunction = () => { | ||
this.isSliderActive = !this.isSliderActive; | ||
callback(); | ||
}); | ||
if (this.isSliderActive) { | ||
activeFunction(); | ||
} else { | ||
inactiveFunction(); | ||
} | ||
}; | ||
|
||
this.slider.removeEventListener("click", prev.function); | ||
this.slider.addEventListener("click", newFunction); | ||
prev.function = newFunction; | ||
} | ||
} |
Oops, something went wrong.