diff --git a/js/filters/collections/mcparticle.js b/js/filters/collections/mcparticle.js index 5bdeac2..f0b4ca7 100644 --- a/js/filters/collections/mcparticle.js +++ b/js/filters/collections/mcparticle.js @@ -118,6 +118,16 @@ export function initMCParticleFilters(parentContainer, viewObjects) { const { simStatus, generatorStatus, collectionNames } = checkboxes; + let areSimStatusChecked = false; + + simStatus.forEach((checkbox) => { + const { checked } = checkbox.getValues(); + + if (checked) { + areSimStatusChecked = true; + } + }); + const someSimStatusCheckbox = objectSatisfiesCheckbox( object, simStatus, @@ -129,7 +139,11 @@ export function initMCParticleFilters(parentContainer, viewObjects) { collectionNames, ]); - return someSimStatusCheckbox && normalCheckboxes; + if (areSimStatusChecked) { + return someSimStatusCheckbox && normalCheckboxes; + } else { + return normalCheckboxes; + } }; return criteriaFunction; diff --git a/js/filters/collections/recoparticle.js b/js/filters/collections/recoparticle.js index 1c2a75c..0e503ee 100644 --- a/js/filters/collections/recoparticle.js +++ b/js/filters/collections/recoparticle.js @@ -7,7 +7,7 @@ import { addCollectionTitle, collectionFilterContainer, } from "../components/lib.js"; -import { RangeComponent } from "../components/range.js"; +import { magnitudeRangeLogic, RangeComponent } from "../components/range.js"; import { rangeLogic } from "../components/range.js"; function renderRecoParticleFilters(viewObjects) { @@ -19,12 +19,14 @@ function renderRecoParticleFilters(viewObjects) { const charge = new RangeComponent("charge", "charge", "e"); const momentum = new RangeComponent("momentum", "momentum", "GeV"); - const range = [energy, charge, momentum]; + const range = [energy, charge]; range.forEach((rangeFilter) => { container.appendChild(rangeFilter.render()); }); + container.appendChild(momentum.render()); + const [collectionNamesContainer, collectionCheckboxes] = buildCollectionCheckboxes( viewObjects.datatypes["edm4hep::ReconstructedParticle"].collection @@ -37,13 +39,14 @@ function renderRecoParticleFilters(viewObjects) { filters: { range, collectionCheckboxes, + momentum, }, }; } export function initRecoParticleFilters(parentContainer, viewObjects) { const { container, filters } = renderRecoParticleFilters(viewObjects); - const { range, collectionCheckboxes } = filters; + const { range, collectionCheckboxes, momentum } = filters; parentContainer.appendChild(container); @@ -56,6 +59,11 @@ export function initRecoParticleFilters(parentContainer, viewObjects) { } } + const { min, max } = momentum.getValues(); + if (!magnitudeRangeLogic(min, max, object, "momentum")) { + return false; + } + if ( !objectSatisfiesCheckbox( object, diff --git a/js/filters/components/checkbox.js b/js/filters/components/checkbox.js index fdb72b6..afbf414 100644 --- a/js/filters/components/checkbox.js +++ b/js/filters/components/checkbox.js @@ -65,22 +65,10 @@ export function objectSatisfiesCheckbox( property, logicFunction ) { - const checkedBoxes = []; - for (const checkbox of checkboxes) { const { checked, value } = checkbox.getValues(); - if (checked) { - checkedBoxes.push(value); - } - } - - if (checkedBoxes.length === 0) { - return true; - } - - for (const checked of checkedBoxes) { - if (logicFunction(checked, object, property)) { + if (checked && logicFunction(value, object, property)) { return true; } } diff --git a/js/filters/components/common.js b/js/filters/components/common.js index 5b101e2..a4af841 100644 --- a/js/filters/components/common.js +++ b/js/filters/components/common.js @@ -45,14 +45,12 @@ export function buildCollectionCheckboxes(collection) { selectAll.addEventListener("click", () => { checkboxes.forEach((checkbox) => { checkbox.checked(true); - checkbox.checkbox.dispatchEvent(new Event("change")); }); }); clearAll.addEventListener("click", () => { checkboxes.forEach((checkbox) => { checkbox.checked(false); - checkbox.checkbox.dispatchEvent(new Event("change")); }); }); diff --git a/js/filters/filter.js b/js/filters/filter.js index fa86fe7..263fa5f 100644 --- a/js/filters/filter.js +++ b/js/filters/filter.js @@ -1,5 +1,7 @@ import { setScroll, setScrollBarsPosition } from "../draw/scroll.js"; import { copyObject } from "../lib/copy.js"; +import { checkEmptyObject } from "../lib/empty-object.js"; +import { showMessage } from "../lib/messages.js"; import { initClusterFilters } from "./collections/cluster.js"; import { initMCParticleFilters } from "./collections/mcparticle.js"; import { initParticleIdFilters } from "./collections/particleid.js"; @@ -39,6 +41,34 @@ const filters = { reset: null, }; +const filterOptionsChanged = (initialValues) => { + const allCheckboxes = document.getElementsByClassName( + "filter-input-checkbox" + ); + + for (let i = 0; i < allCheckboxes.length; i++) { + const checked = allCheckboxes[i].checked; + const initialValue = initialValues.checkboxes[i]; + + if (checked !== initialValue) { + return true; + } + } + + const allInputs = document.getElementsByClassName("filter-input-range"); + + for (let i = 0; i < allInputs.length; i++) { + const input = allInputs[i].value; + const initialInput = initialValues.range[i]; + + if (input !== initialInput) { + return true; + } + } + + return false; +}; + export function initFilters( { viewObjects, viewCurrentObjects }, collections, @@ -47,7 +77,10 @@ export function initFilters( ) { const criteriaFunctions = {}; - let someInputChanged = false; + const initialValues = { + range: [], + checkboxes: [], + }; const resetFiltersContent = () => { const content = document.getElementById("filters-content"); @@ -76,27 +109,32 @@ export function initFilters( "filter-input-checkbox" ); + initialValues.checkboxes = []; + for (const input of allCheckboxes) { - input.addEventListener("change", () => { - someInputChanged = true; - }); + const checked = input.checked; + initialValues.checkboxes.push(checked); } const allInputs = document.getElementsByClassName("filter-input-range"); + initialValues.range = []; + for (const input of allInputs) { - input.addEventListener("input", () => { - someInputChanged = true; - }); + const value = input.value; + initialValues.range.push(value); } }; resetFiltersContent(); filters.apply = async () => { - if (!someInputChanged) { + const filtersChanged = filterOptionsChanged(initialValues); + + if (!filtersChanged) { return; } + const filterOutValue = document.getElementById("invert-filter").checked; const ids = filterOut( viewObjects, @@ -104,6 +142,14 @@ export function initFilters( criteriaFunctions, filterOutValue ); + + const isEmpty = checkEmptyObject(viewCurrentObjects); + + if (isEmpty) { + showMessage("No objects satisfy the filter options"); + return; + } + reconnectFunction(viewCurrentObjects, ids); await render(viewCurrentObjects); const { x, y } = filterScroll();