generated from allen-cell-animated/github-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/second module #175
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
Draft
meganrm
wants to merge
12
commits into
main
Choose a base branch
from
feature/second-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a922926
added two different complexes
meganrm 9860a97
use complex 1
meganrm 537c3ab
add second module content
meganrm 325205e
change in visibility and progression control
meganrm def84b7
changes to data for new simulation
meganrm 68776c9
new colors and conc
meganrm d0f0297
make page update in ui
meganrm 4584de7
changes to copy
meganrm c183cd9
fix typo
meganrm 775276f
go to next module
meganrm 51f715f
functional changes
meganrm 7d901d9
fix update errror
meganrm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import { | |
| AgentName, | ||
| CurrentConcentration, | ||
| InputConcentration, | ||
| LayoutType, | ||
| Module, | ||
| ProductName, | ||
| ScatterTrace, | ||
|
|
@@ -22,7 +23,7 @@ import LeftPanel from "./components/main-layout/LeftPanel"; | |
| import RightPanel from "./components/main-layout/RightPanel"; | ||
| import ReactionDisplay from "./components/main-layout/ReactionDisplay"; | ||
| import ContentPanelTimer from "./components/main-layout/ContentPanelTimer"; | ||
| import content, { moduleNames } from "./content"; | ||
| import content, { FIRST_PAGE, moduleNames } from "./content"; | ||
| import { | ||
| PROMPT_TO_ADJUST_B, | ||
| DEFAULT_VIEWPORT_SIZE, | ||
|
|
@@ -48,10 +49,8 @@ import LiveSimulationData from "./simulation/LiveSimulationData"; | |
| import { PLOT_COLORS } from "./components/plots/constants"; | ||
| import useModule from "./hooks/useModule"; | ||
|
|
||
| const ADJUSTABLE_AGENT = AgentName.B; | ||
|
|
||
| function App() { | ||
| const [page, setPage] = useState(1); | ||
| const [page, setPage] = useState(FIRST_PAGE); | ||
| const [time, setTime] = useState(0); | ||
| const [isPlaying, setIsPlaying] = useState(false); | ||
| const [trajectoryStatus, setTrajectoryStatus] = useState( | ||
|
|
@@ -86,12 +85,18 @@ function App() { | |
| const [timeFactor, setTimeFactor] = useState( | ||
| LiveSimulationData.INITIAL_TIME_FACTOR | ||
| ); | ||
| const [viewportSize, setViewportSize] = useState(DEFAULT_VIEWPORT_SIZE); | ||
| const [viewportWidth, setViewportWidth] = useState( | ||
| DEFAULT_VIEWPORT_SIZE.width | ||
| ); | ||
| const [viewportHeight, setViewportHeight] = useState( | ||
| DEFAULT_VIEWPORT_SIZE.height | ||
| ); | ||
|
|
||
| /** | ||
| * Analysis state | ||
| * used to create plots and feedback | ||
| */ | ||
| const [trajectoryPlotData, setTrajectoryPlotData] = | ||
| const [preComputedTrajectoryPlotData, setPreComputedTrajectoryPlotData] = | ||
| useState<ScatterTrace[]>(); | ||
| const [liveConcentration, setLiveConcentration] = | ||
| useState<CurrentConcentration>({ | ||
|
|
@@ -161,21 +166,22 @@ function App() { | |
| if (!trajectory) { | ||
| return null; | ||
| } | ||
| const longestAxis = Math.max(viewportSize.width, viewportSize.height); | ||
| const longestAxis = Math.max(viewportWidth, viewportHeight); | ||
| return new BindingSimulator(trajectory, longestAxis / 3); | ||
| }, [currentModule, viewportSize, simulationData]); | ||
| }, [viewportWidth, viewportHeight, simulationData, currentModule]); | ||
|
|
||
| const preComputedPlotDataManager = useMemo(() => { | ||
| if (!trajectoryPlotData) { | ||
| if (!preComputedTrajectoryPlotData) { | ||
| return null; | ||
| } | ||
| return new PreComputedPlotData(trajectoryPlotData); | ||
| }, [trajectoryPlotData]); | ||
| return new PreComputedPlotData(preComputedTrajectoryPlotData); | ||
| }, [preComputedTrajectoryPlotData]); | ||
|
|
||
| useEffect(() => { | ||
| if (!clientSimulator) { | ||
| return; | ||
| } | ||
|
|
||
| simulariumController.changeFile( | ||
| { | ||
| clientSimulator: clientSimulator, | ||
|
|
@@ -244,6 +250,7 @@ function App() { | |
| uniqMeasuredConcentrations.length >= 3 | ||
| ); | ||
| }, [hasAValueAboveKd, hasAValueBelowKd, uniqMeasuredConcentrations]); | ||
|
|
||
| const handleNewInputConcentration = useCallback( | ||
| (name: string, value: number) => { | ||
| if (value === 0) { | ||
|
|
@@ -261,6 +268,7 @@ function App() { | |
| name as keyof typeof LiveSimulationData.AVAILABLE_AGENTS; | ||
| const agentId = LiveSimulationData.AVAILABLE_AGENTS[agentName].id; | ||
| clientSimulator.changeConcentration(agentId, value); | ||
|
|
||
| simulariumController.gotoTime(time + 1); | ||
| resetCurrentRunAnalysisState(); | ||
| }, | ||
|
|
@@ -281,14 +289,20 @@ function App() { | |
| [AgentName.B]: | ||
| LiveSimulationData.INITIAL_CONCENTRATIONS[AgentName.B], | ||
| }); | ||
| // advances time | ||
| handleNewInputConcentration( | ||
| ADJUSTABLE_AGENT, | ||
| LiveSimulationData.ADJUSTABLE_AGENT_MAP[currentModule], | ||
| LiveSimulationData.INITIAL_CONCENTRATIONS[AgentName.B] | ||
| ); | ||
| setIsPlaying(false); | ||
| clearAllAnalysisState(); | ||
| setTimeFactor(LiveSimulationData.INITIAL_TIME_FACTOR); | ||
| }, [clearAllAnalysisState, handleNewInputConcentration, productName]); | ||
| }, [ | ||
| clearAllAnalysisState, | ||
| handleNewInputConcentration, | ||
| productName, | ||
| currentModule, | ||
| ]); | ||
| // Special events in page navigation | ||
| // usePageNumber takes a page number, a conditional and a callback | ||
|
|
||
|
|
@@ -299,7 +313,10 @@ function App() { | |
| // clicked the home button | ||
| usePageNumber( | ||
| page, | ||
| (page) => page === 1 && currentProductConcentrationArray.length > 1, | ||
| (page) => | ||
| page === 1 && | ||
| currentModule === 1 && | ||
| currentProductConcentrationArray.length > 1, | ||
|
Comment on lines
+316
to
+319
Contributor
Author
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.
|
||
| () => { | ||
| totalReset(); | ||
| } | ||
|
|
@@ -313,17 +330,35 @@ function App() { | |
| isPlaying && | ||
| recordedInputConcentration.length > 0 && | ||
| recordedInputConcentration[0] !== | ||
| inputConcentration[ADJUSTABLE_AGENT], | ||
| inputConcentration[ | ||
| LiveSimulationData.ADJUSTABLE_AGENT_MAP[currentModule] | ||
| ], | ||
| () => { | ||
| setPage(page + 1); | ||
| } | ||
| ); | ||
|
|
||
| // handle trajectory changes based on content changes | ||
| useEffect(() => { | ||
| const currentPage = content[currentModule][page]; | ||
| const nextPage = content[currentModule][page + 1]; | ||
| if (!nextPage?.trajectoryUrl && !currentPage.trajectoryUrl) { | ||
| if (trajectoryStatus === TrajectoryStatus.LOADED) { | ||
| simulariumController.clearFile(); | ||
| setTrajectoryStatus(TrajectoryStatus.INITIAL); | ||
| } | ||
| if ( | ||
| currentPage.layout === LayoutType.LiveSimulation && | ||
| simulariumController.getFile() !== LIVE_SIMULATION_NAME | ||
| ) { | ||
| setTrajectoryName(LIVE_SIMULATION_NAME); | ||
| } | ||
| } | ||
|
|
||
| if (!nextPage) { | ||
| return; | ||
| } | ||
| // if the next page has a trajectory, load it | ||
| const url = nextPage.trajectoryUrl; | ||
| if (trajectoryStatus === TrajectoryStatus.INITIAL && url) { | ||
| const changeTrajectory = async () => { | ||
|
|
@@ -334,7 +369,7 @@ function App() { | |
| await fetch3DTrajectory( | ||
| url, | ||
| simulariumController, | ||
| setTrajectoryPlotData | ||
| setPreComputedTrajectoryPlotData | ||
| ); | ||
| setTrajectoryStatus(TrajectoryStatus.LOADED); | ||
| }; | ||
|
|
@@ -349,15 +384,14 @@ function App() { | |
| totalReset, | ||
| ]); | ||
|
|
||
| usePageNumber( | ||
| page, | ||
| (page) => page === finalPageNumber, | ||
| () => { | ||
| if (simulariumController.getFile()) { | ||
| simulariumController.clearFile(); | ||
| } | ||
| useEffect(() => { | ||
| const { section } = content[currentModule][page]; | ||
| if (section === Section.Experiment) { | ||
| setTimeFactor(LiveSimulationData.DEFAULT_TIME_FACTOR); | ||
| } else if (section === Section.Introduction) { | ||
| setTimeFactor(LiveSimulationData.INITIAL_TIME_FACTOR); | ||
| } | ||
| ); | ||
| }, [currentModule, page]); | ||
|
|
||
| const addProductionTrace = (previousConcentration: number) => { | ||
| const traces = productOverTimeTraces; | ||
|
|
@@ -376,7 +410,6 @@ function App() { | |
| const handleStartExperiment = () => { | ||
| simulariumController.pause(); | ||
| totalReset(); | ||
| setTimeFactor(LiveSimulationData.DEFAULT_TIME_FACTOR); | ||
| setPage(page + 1); | ||
| }; | ||
|
|
||
|
|
@@ -386,12 +419,7 @@ function App() { | |
| // 2d trajectory | ||
| // switch to orthographic camera | ||
| simulariumController.setCameraType(true); | ||
| const { section } = content[currentModule][page]; | ||
| if (section === Section.Experiment) { | ||
| setTimeFactor(LiveSimulationData.DEFAULT_TIME_FACTOR); | ||
| } else { | ||
| setTimeFactor(LiveSimulationData.INITIAL_TIME_FACTOR); | ||
| } | ||
| setPreComputedTrajectoryPlotData(undefined); | ||
| setFinalTime(-1); | ||
| } else { | ||
| // 3d trajectory | ||
|
|
@@ -407,14 +435,14 @@ function App() { | |
| const handleTimeChange = (timeData: TimeData) => { | ||
| const { time } = timeData; | ||
| setTime(time); | ||
| console.log("new time", time); | ||
| // can't use isLastFrame here because the time is not updated | ||
| // in state yet | ||
| if (finalTime > 0 && time >= finalTime - timeFactor && isPlaying) { | ||
| setIsPlaying(false); | ||
| } | ||
| let concentrations: CurrentConcentration = {}; | ||
| let previousData = currentProductConcentrationArray; | ||
|
|
||
| if (preComputedPlotDataManager) { | ||
| if (timeData.time === 0) { | ||
| // for the 3D trajectory, | ||
|
|
@@ -482,16 +510,19 @@ function App() { | |
| setEquilibriumFeedbackTimeout("Not yet!"); | ||
| return false; | ||
| } | ||
| const adjustableAgentName = | ||
| LiveSimulationData.ADJUSTABLE_AGENT_MAP[currentModule]; | ||
| // this will always be defined for the current run, but since there are | ||
| // different agents in each module, typescript fears it will be undefined | ||
| const currentInputConcentration = inputConcentration[ADJUSTABLE_AGENT]; | ||
| const currentInputConcentration = | ||
| inputConcentration[adjustableAgentName]; | ||
| if (currentInputConcentration === undefined) { | ||
| return false; | ||
| } | ||
| const concentrations = | ||
| clientSimulator.getCurrentConcentrations(productName); | ||
| const productConcentration = concentrations[productName]; | ||
| const reactantConcentration = concentrations[ADJUSTABLE_AGENT]; | ||
| const reactantConcentration = concentrations[adjustableAgentName]; | ||
|
|
||
| const currentTime = indexToTime( | ||
| currentProductConcentrationArray.length, | ||
|
|
@@ -538,32 +569,45 @@ function App() { | |
|
|
||
| const { totalMainContentPages } = useModule(currentModule); | ||
| const lastPageOfExperiment = page === totalMainContentPages; | ||
|
|
||
| const adjustableAgentName = | ||
| LiveSimulationData.ADJUSTABLE_AGENT_MAP[currentModule]; | ||
| return ( | ||
| <> | ||
| <div className="app"> | ||
| <SimulariumContext.Provider | ||
| value={{ | ||
| trajectoryName, | ||
| productName, | ||
| adjustableAgentName, | ||
| fixedAgentStartingConcentration: | ||
| inputConcentration[AgentName.A] || 0, | ||
| currentProductionConcentration: | ||
| liveConcentration[productName] || 0, | ||
| maxConcentration: | ||
| simulationData.getMaxConcentration(currentModule), | ||
| handleStartExperiment, | ||
| section: content[currentModule][page].section, | ||
| moduleLength: content[currentModule].length, | ||
| module: currentModule, | ||
| getAgentColor: simulationData.getAgentColor, | ||
| isPlaying, | ||
| setIsPlaying, | ||
| simulariumController, | ||
| handleTimeChange, | ||
| page, | ||
| setPage, | ||
| setCurrentModule, | ||
| timeFactor, | ||
| timeUnit: simulationData.timeUnit, | ||
| handleTrajectoryChange, | ||
| viewportSize, | ||
| setViewportSize, | ||
| viewportSize: { | ||
| width: viewportWidth, | ||
| height: viewportHeight, | ||
| }, | ||
| setViewportSize: ({ width, height }) => { | ||
| setViewportWidth(width); | ||
| setViewportHeight(height); | ||
| }, | ||
| recordedConcentrations: recordedInputConcentration, | ||
| }} | ||
| > | ||
|
|
@@ -611,7 +655,7 @@ function App() { | |
| unbindingEventsOverTime={ | ||
| unBindingEventsOverTime | ||
| } | ||
| adjustableAgent={ADJUSTABLE_AGENT} | ||
| adjustableAgent={adjustableAgentName} | ||
| /> | ||
| } | ||
| centerPanel={ | ||
|
|
@@ -636,7 +680,7 @@ function App() { | |
| handleRecordEquilibrium | ||
| } | ||
| currentAdjustableAgentConcentration={ | ||
| inputConcentration[ADJUSTABLE_AGENT] || 0 | ||
| inputConcentration[adjustableAgentName] || 0 | ||
| } | ||
| equilibriumData={{ | ||
| inputConcentrations: | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.