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 = {
* Knowledge space graph editor. Allows easy editing of the graph structure.
*/
export class Editor extends React.PureComponent<any, stateTypes> {
private graphContainer: React.RefObject<HTMLDivElement>;
private rendererRef: React.RefObject<GraphRenderer2D>;
constructor(props: any) {
......@@ -85,7 +84,7 @@ export class Editor extends React.PureComponent<any, stateTypes> {
this.keyReleased(e.key);
});
this.graphContainer = React.createRef();
this.rendererRef = React.createRef();
listAllSpaces().then((spaces) => this.setState({ spaces: spaces }));
......@@ -144,6 +143,11 @@ export class Editor extends React.PureComponent<any, stateTypes> {
console.log("Starting to load new graph ...");
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
const graph = new DynamicGraph();
graph.fromSerializedObject(data);
......@@ -225,14 +229,11 @@ export class Editor extends React.PureComponent<any, stateTypes> {
<SpaceManager />
{this.state.graph && (
<div id="content">
<div
id="force-graph-renderer"
ref={this.graphContainer}
>
<div id="force-graph-renderer">
<SelectLayer
nodes={this.state.graph.nodes}
screen2GraphCoords={
this.rendererRef
this.rendererRef.current
? this.rendererRef.current
.screen2GraphCoords
: undefined
......
......@@ -49,6 +49,7 @@ export class GraphRenderer2D extends React.PureComponent<
this.screen2GraphCoords = this.screen2GraphCoords.bind(this);
this.handleNodeCanvasObject = this.handleNodeCanvasObject.bind(this);
this.handleLinkCanvasObject = this.handleLinkCanvasObject.bind(this);
this.allowForceSimulation = this.allowForceSimulation.bind(this);
document.addEventListener("keydown", (e) => {
this.keys[e.key] = true;
......@@ -71,6 +72,10 @@ export class GraphRenderer2D extends React.PureComponent<
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.
*/
......
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