forked from equinor/webviz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor parameter matrix module (equinor#609)
Co-authored-by: Hans Kallekleiv <[email protected]>
- Loading branch information
1 parent
de630c7
commit d7ac146
Showing
14 changed files
with
392 additions
and
282 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
...end/src/modules/ParameterDistributionMatrix/components/ParameterDistributionPlot/index.ts
This file was deleted.
Oops, something went wrong.
10 changes: 6 additions & 4 deletions
10
frontend/src/modules/ParameterDistributionMatrix/loadModule.tsx
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,12 +1,14 @@ | ||
import { ModuleRegistry } from "@framework/ModuleRegistry"; | ||
|
||
import { Settings } from "./settings"; | ||
import { MODULE_NAME } from "./registerModule"; | ||
import { Settings } from "./settings/settings"; | ||
import { Interface, interfaceInitialization } from "./settingsToViewInterface"; | ||
import { State } from "./state"; | ||
import { View } from "./view"; | ||
import { View } from "./view/view"; | ||
|
||
const defaultState: State = { ensembleSetParameterIdents: [] }; | ||
const defaultState: State = {}; | ||
|
||
const module = ModuleRegistry.initModule<State>("ParameterDistributionMatrix", defaultState); | ||
const module = ModuleRegistry.initModule<State, Interface>(MODULE_NAME, defaultState, {}, interfaceInitialization); | ||
|
||
module.viewFC = View; | ||
module.settingsFC = Settings; |
8 changes: 0 additions & 8 deletions
8
frontend/src/modules/ParameterDistributionMatrix/registerModule.ts
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
frontend/src/modules/ParameterDistributionMatrix/registerModule.tsx
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ModuleRegistry } from "@framework/ModuleRegistry"; | ||
|
||
import { Interface } from "./settingsToViewInterface"; | ||
import { State } from "./state"; | ||
|
||
export const MODULE_NAME = "ParameterDistributionMatrix"; | ||
ModuleRegistry.registerModule<State, Interface>({ | ||
moduleName: MODULE_NAME, | ||
defaultTitle: "Parameter Distribution Matrix", | ||
}); |
185 changes: 0 additions & 185 deletions
185
frontend/src/modules/ParameterDistributionMatrix/settings.tsx
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
frontend/src/modules/ParameterDistributionMatrix/settings/atoms/baseAtoms.ts
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { EnsembleIdent } from "@framework/EnsembleIdent"; | ||
import { ParameterIdent } from "@framework/EnsembleParameters"; | ||
import { atomWithCompare } from "@framework/utils/atomUtils"; | ||
|
||
import { atom } from "jotai"; | ||
|
||
function areEnsembleIdentListsEqual(a: EnsembleIdent[], b: EnsembleIdent[]) { | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
for (let i = 0; i < a.length; i++) { | ||
if (!a[i].equals(b[i])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
export const userSelectedEnsembleIdentsAtom = atomWithCompare<EnsembleIdent[]>([], areEnsembleIdentListsEqual); | ||
export const userSelectedParameterIdentsAtom = atom<ParameterIdent[]>([]); | ||
export const showConstantParametersAtom = atom<boolean>(false); |
73 changes: 73 additions & 0 deletions
73
frontend/src/modules/ParameterDistributionMatrix/settings/atoms/derivedAtoms.ts
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { ParameterIdent, ParameterType } from "@framework/EnsembleParameters"; | ||
import { EnsembleSetAtom } from "@framework/GlobalAtoms"; | ||
|
||
import { atom } from "jotai"; | ||
|
||
import { | ||
showConstantParametersAtom, | ||
userSelectedEnsembleIdentsAtom, | ||
userSelectedParameterIdentsAtom, | ||
} from "./baseAtoms"; | ||
|
||
export const selectedEnsembleIdentsAtom = atom((get) => { | ||
const ensembleSet = get(EnsembleSetAtom); | ||
const userSelectedEnsembleIdents = get(userSelectedEnsembleIdentsAtom); | ||
|
||
let computedEnsembleIdents = userSelectedEnsembleIdents.filter((el) => ensembleSet.hasEnsemble(el)); | ||
if (computedEnsembleIdents.length === 0 && ensembleSet.getEnsembleArr().length > 0) { | ||
computedEnsembleIdents = [ensembleSet.getEnsembleArr()[0].getIdent()]; | ||
} | ||
|
||
return computedEnsembleIdents; | ||
}); | ||
|
||
export const intersectedParameterIdentsAtom = atom((get) => { | ||
const ensembleSet = get(EnsembleSetAtom); | ||
const selectedEnsembleIdents = get(selectedEnsembleIdentsAtom); | ||
const showConstantParameters = get(showConstantParametersAtom); | ||
|
||
if (selectedEnsembleIdents.length === 0) return []; | ||
|
||
// Find set of parameter idents per ensemble | ||
const ensembleParameterSets: Set<ParameterIdent>[] = []; | ||
|
||
for (const ensembleIdent of selectedEnsembleIdents) { | ||
const ensemble = ensembleSet.findEnsemble(ensembleIdent); | ||
if (!ensemble) continue; | ||
|
||
const parameters = ensemble | ||
.getParameters() | ||
.getParameterArr() | ||
.filter( | ||
(parameter) => | ||
(showConstantParameters || !parameter.isConstant) && parameter.type === ParameterType.CONTINUOUS | ||
); | ||
const identArr: ParameterIdent[] = []; | ||
for (const parameter of parameters) { | ||
identArr.push(new ParameterIdent(parameter.name, parameter.groupName)); | ||
} | ||
const parameterIdents = new Set(identArr); | ||
if (parameterIdents.size > 0) { | ||
ensembleParameterSets.push(parameterIdents); | ||
} | ||
} | ||
|
||
if (ensembleParameterSets.length === 0) return []; | ||
|
||
// Intersection of parameters across ensembles | ||
const intersectedParameterIdents = ensembleParameterSets.reduce((acc, set) => { | ||
if (acc === null) return set; | ||
return new Set([...acc].filter((ident1) => [...set].some((ident2) => ident1.equals(ident2)))); | ||
}, ensembleParameterSets[0] || new Set()); | ||
|
||
return Array.from(intersectedParameterIdents).sort((a, b) => a.toString().localeCompare(b.toString())); | ||
}); | ||
|
||
export const selectedParameterIdentsAtom = atom((get) => { | ||
const intersectedParameterIdents = get(intersectedParameterIdentsAtom); | ||
const userSelectedParameterIdents = get(userSelectedParameterIdentsAtom); | ||
|
||
return userSelectedParameterIdents.filter((ident) => | ||
intersectedParameterIdents.some((intersectIdent) => intersectIdent.equals(ident)) | ||
); | ||
}); |
Oops, something went wrong.