Skip to content

Commit

Permalink
Tree simulation running or not status now persists across clusters (p…
Browse files Browse the repository at this point in the history
…ausing simulation in one cluster pauses in all).
  • Loading branch information
Nyckoka committed Jul 3, 2023
1 parent 0d53133 commit c85a83b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
interface TreeViewSettingsCardProps {
loadingGraph: boolean

simulationRunning: boolean

onPauseAnimation: () => void
onRestartAnimation: () => void

Expand Down Expand Up @@ -46,6 +48,8 @@ export function TreeViewSettingsCard(
{
loadingGraph,

simulationRunning,

onPauseAnimation,
onRestartAnimation,

Expand All @@ -70,7 +74,7 @@ export function TreeViewSettingsCard(
onPrint
}: TreeViewSettingsCardProps
) {
const [animationRunning, setAnimationRunning] = useState(true)
const [animationRunning, setAnimationRunning] = useState(simulationRunning)
const [transformationsOpen, setTransformationsOpen] = useState(false)

return <Box sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export default function ForceDirectedLayout() {
<TreeViewSettingsCard
loadingGraph={loadingGraph}

simulationRunning={simulationConfig.simulationRunning}

onPauseAnimation={pauseAnimation}
onRestartAnimation={restartAnimation}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export function useForceDirectedLayout() {

return {
canvasRef,
graphRef,
loadingGraph,
treeView: cascadingInfoTreeView,

Expand All @@ -116,8 +117,14 @@ export function useForceDirectedLayout() {
numClusters,
selectedCluster,
setSelectedCluster,
pauseAnimation: () => graphRef.current?.pause(),
restartAnimation: () => graphRef.current?.restart(),
pauseAnimation: () => {
simulationConfig.setSimulationRunning(false)
graphRef.current?.pause()
},
restartAnimation: () => {
simulationConfig.setSimulationRunning(true)
graphRef.current?.restart()
},

resetSimulationFilters: () => {
// TODO: reset filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export function useGraph(projectId: string, datasetId: string, treeViewId: strin
await graphRef.current!.setData(nodes, links)
graphRef.current?.renderNodeLabels(graphTransformationsConfig.nodeLabel)
graphRef.current?.renderLinkLabels(graphTransformationsConfig.linkLabel)
if(!simulationConfig.simulationRunning) {
graphRef.current?.pause()
}

console.log("finished loading graph")
setLoadingGraph(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface SimulationConfig {
friction: number;
repulsionTheta: number;
decay: number;
simulationRunning: boolean;

setLinkSpring: (value: number) => void;
setLinkDistance: (value: number) => void;
Expand All @@ -21,6 +22,7 @@ export interface SimulationConfig {
setRepulsion: (value: number) => void;
setRepulsionTheta: (value: number) => void;
setDecay: (value: number) => void;
setSimulationRunning: (value: boolean) => void;

resetAll: () => void;
}
Expand All @@ -43,6 +45,8 @@ export function useSimulationConfig(
const [repulsionTheta, setRepulsionTheta] = useState(graphRef.current?.config.simulation.repulsionTheta ?? defaultConfig.simulation!.repulsionTheta!)
const [decay, setDecay] = useState(graphRef.current?.config.simulation.decay ?? defaultConfig.simulation!.decay!)

const [simulationRunning, setSimulationRunning] = useState(graphRef.current?.isSimulationRunning ?? true)

useEffect(() => {
if (loadingGraph)
return
Expand All @@ -54,6 +58,8 @@ export function useSimulationConfig(
setFriction(graphRef.current?.config.simulation.friction ?? defaultConfig.simulation!.friction!)
setRepulsionTheta(graphRef.current?.config.simulation.repulsionTheta ?? defaultConfig.simulation!.repulsionTheta!)
setDecay(graphRef.current?.config.simulation.decay ?? defaultConfig.simulation!.decay!)
setSimulationRunning(graphRef.current?.isSimulationRunning ?? true)

}, [loadingGraph])

return {
Expand All @@ -64,6 +70,7 @@ export function useSimulationConfig(
friction,
repulsionTheta,
decay,
simulationRunning,

setLinkSpring: (value: number) => {
setLinkSpring(value)
Expand Down Expand Up @@ -93,6 +100,9 @@ export function useSimulationConfig(
setDecay(value)
graphRef.current?.setConfig({simulation: {decay: value}})
},
setSimulationRunning: (value: boolean) => {
setSimulationRunning(value)
},

resetAll: () => {
setLinkSpring(defaultConfig.simulation!.linkSpring!)
Expand Down

0 comments on commit c85a83b

Please sign in to comment.