Skip to content
Snippets Groups Projects
Commit 68af56a1 authored by Matthias Konitzny's avatar Matthias Konitzny :fire:
Browse files

Fixed a bug which caused the simulation to not reheat on space change.

parent ac80b943
No related branches found
No related tags found
No related merge requests found
...@@ -63,7 +63,6 @@ type stateTypes = { ...@@ -63,7 +63,6 @@ type stateTypes = {
* Knowledge space graph editor. Allows easy editing of the graph structure. * Knowledge space graph editor. Allows easy editing of the graph structure.
*/ */
export class Editor extends React.PureComponent<any, stateTypes> { export class Editor extends React.PureComponent<any, stateTypes> {
private graphContainer: React.RefObject<HTMLDivElement>;
private rendererRef: React.RefObject<GraphRenderer2D>; private rendererRef: React.RefObject<GraphRenderer2D>;
constructor(props: any) { constructor(props: any) {
...@@ -85,7 +84,7 @@ export class Editor extends React.PureComponent<any, stateTypes> { ...@@ -85,7 +84,7 @@ export class Editor extends React.PureComponent<any, stateTypes> {
this.keyReleased(e.key); this.keyReleased(e.key);
}); });
this.graphContainer = React.createRef(); this.rendererRef = React.createRef();
listAllSpaces().then((spaces) => this.setState({ spaces: spaces })); listAllSpaces().then((spaces) => this.setState({ spaces: spaces }));
...@@ -144,6 +143,11 @@ export class Editor extends React.PureComponent<any, stateTypes> { ...@@ -144,6 +143,11 @@ export class Editor extends React.PureComponent<any, stateTypes> {
console.log("Starting to load new graph ..."); console.log("Starting to load new graph ...");
console.log(data); console.log(data);
// Allow a single phase of force simulation when loading the graph.
if (this.rendererRef.current != undefined) {
this.rendererRef.current.allowForceSimulation();
}
// Create graph // Create graph
const graph = new DynamicGraph(); const graph = new DynamicGraph();
graph.fromSerializedObject(data); graph.fromSerializedObject(data);
...@@ -225,14 +229,11 @@ export class Editor extends React.PureComponent<any, stateTypes> { ...@@ -225,14 +229,11 @@ export class Editor extends React.PureComponent<any, stateTypes> {
<SpaceManager /> <SpaceManager />
{this.state.graph && ( {this.state.graph && (
<div id="content"> <div id="content">
<div <div id="force-graph-renderer">
id="force-graph-renderer"
ref={this.graphContainer}
>
<SelectLayer <SelectLayer
nodes={this.state.graph.nodes} nodes={this.state.graph.nodes}
screen2GraphCoords={ screen2GraphCoords={
this.rendererRef this.rendererRef.current
? this.rendererRef.current ? this.rendererRef.current
.screen2GraphCoords .screen2GraphCoords
: undefined : undefined
......
...@@ -49,6 +49,7 @@ export class GraphRenderer2D extends React.PureComponent< ...@@ -49,6 +49,7 @@ export class GraphRenderer2D extends React.PureComponent<
this.screen2GraphCoords = this.screen2GraphCoords.bind(this); this.screen2GraphCoords = this.screen2GraphCoords.bind(this);
this.handleNodeCanvasObject = this.handleNodeCanvasObject.bind(this); this.handleNodeCanvasObject = this.handleNodeCanvasObject.bind(this);
this.handleLinkCanvasObject = this.handleLinkCanvasObject.bind(this); this.handleLinkCanvasObject = this.handleLinkCanvasObject.bind(this);
this.allowForceSimulation = this.allowForceSimulation.bind(this);
document.addEventListener("keydown", (e) => { document.addEventListener("keydown", (e) => {
this.keys[e.key] = true; this.keys[e.key] = true;
...@@ -71,6 +72,10 @@ export class GraphRenderer2D extends React.PureComponent< ...@@ -71,6 +72,10 @@ export class GraphRenderer2D extends React.PureComponent<
this.forceGraph = React.createRef(); this.forceGraph = React.createRef();
} }
public allowForceSimulation() {
this.warmupTicks = this.defaultWarmupTicks;
}
/** /**
* Deletes all nodes currently selected. Handles store points accordingly of the number of deleted nodes. * Deletes all nodes currently selected. Handles store points accordingly of the number of deleted nodes.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment