-
Notifications
You must be signed in to change notification settings - Fork 4
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
filtering/reconnecting #18
Changes from 3 commits
4cb2094
df53119
8cd129d
0ec7955
4e5f1a1
ccaeeca
022dece
b8fd996
35ce882
209d98a
01183ee
975cbc5
f19980f
4a7629f
5e221d6
849cfcf
89aabf9
490b773
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Link } from "../objects.js"; | ||
import { Toggle } from "./toggle.js"; | ||
|
||
export class Filter extends Toggle { | ||
constructor(id) { | ||
super(id); | ||
} | ||
|
||
toggle(criteriaFunction, parentLinks, childrenLinks, particles, drawAll) { | ||
if (this.isSliderActive) { | ||
const [newParentLinks, newChildrenLinks, newParticles] = reconnect( | ||
criteriaFunction, | ||
parentLinks, | ||
childrenLinks, | ||
particles | ||
); | ||
drawAll(newParentLinks, newChildrenLinks, newParticles); | ||
} else { | ||
drawAll(parentLinks, childrenLinks, particles); | ||
} | ||
} | ||
} | ||
|
||
function reconnect(criteriaFunction, parentLinks, childrenLinks, particles) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not entirely sure whether this is necessary yet, but just for the future; Can this be written in a way where there are no |
||
const newParentLinks = []; | ||
const newChildrenLinks = []; | ||
const filteredParticles = []; | ||
|
||
for (const particle of particles) { | ||
if (!criteriaFunction(particle)) { | ||
filteredParticles.push(null); | ||
|
||
const parentParticles = []; | ||
const childrenParticles = []; | ||
|
||
for (const parent of particle.parents) { | ||
if (criteriaFunction(particles[parent])) { | ||
parentParticles.push(parent); | ||
} | ||
} | ||
|
||
for (const child of particle.children) { | ||
if (criteriaFunction(particles[child])) { | ||
childrenParticles.push(child); | ||
} | ||
} | ||
|
||
for (const parent of parentParticles) { | ||
for (const child of childrenParticles) { | ||
const linkToParent = new Link(newParentLinks.length, parent, child); | ||
linkToParent.xShift = 3; | ||
const linkToChild = new Link(newChildrenLinks.length, parent, child); | ||
linkToChild.color = "#0A0"; | ||
linkToChild.xShift = -3; | ||
|
||
newParentLinks.push(linkToParent); | ||
newChildrenLinks.push(linkToChild); | ||
} | ||
} | ||
} else { | ||
filteredParticles.push(particle); | ||
|
||
for (const parentLinkId of particle.parentLinks) { | ||
const parentLink = parentLinks[parentLinkId]; | ||
const parent = particles[parentLink.from]; | ||
if (criteriaFunction(parent)) { | ||
newParentLinks.push(parentLink); | ||
} | ||
} | ||
|
||
for (const childrenLinkId of particle.childrenLinks) { | ||
const childrenLink = childrenLinks[childrenLinkId]; | ||
const child = particles[childrenLink.to]; | ||
if (criteriaFunction(child)) { | ||
newChildrenLinks.push(childrenLink); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return [newParentLinks, newChildrenLinks, filteredParticles]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// const slider = document.getElementById("show-pdg"); | ||
import { Toggle } from "./toggle.js"; | ||
|
||
export class PdgToggle extends Toggle { | ||
constructor(id) { | ||
super(id); | ||
} | ||
|
||
toggle(infoBoxes, redraw) { | ||
if (this.isSliderActive) { | ||
for (const infoBox of infoBoxes) { | ||
infoBox.updateTexImg(`${infoBox.pdg}`); | ||
} | ||
} else { | ||
for (const infoBox of infoBoxes) { | ||
infoBox.updateTexImg(infoBox.name); | ||
} | ||
} | ||
|
||
redraw(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,13 @@ | ||
const toggle = document.getElementById("toggle"); | ||
const slider = document.getElementsByClassName("slider")[0]; | ||
|
||
class Toggle { | ||
constructor() { | ||
export class Toggle { | ||
constructor(id) { | ||
this.isSliderActive = false; | ||
this.slider = document.getElementById(id); | ||
} | ||
|
||
init(infoBoxes, drawAll) { | ||
toggle.style.display = "flex"; | ||
|
||
slider.addEventListener("click", () => { | ||
init(callback) { | ||
this.slider.addEventListener("click", () => { | ||
this.isSliderActive = !this.isSliderActive; | ||
|
||
if (this.isSliderActive) { | ||
for (const infoBox of infoBoxes) { | ||
infoBox.updateTexImg(`${infoBox.pdg}`); | ||
} | ||
} else { | ||
for (const infoBox of infoBoxes) { | ||
infoBox.updateTexImg(infoBox.name); | ||
} | ||
} | ||
|
||
drawAll(); | ||
callback(); | ||
}); | ||
} | ||
} | ||
|
||
export default Toggle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stupid question from my side, where do these inputs come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry, these inputs come from main.js.