Skip to content

Commit

Permalink
fix: the nodes are rendered at their proper location every time (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoMercy235 committed Mar 22, 2020
1 parent fe9af8c commit 8843f4f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { SequenceModel } from '../../../../../../infrastructure/models/SequenceModel';
import { OptionModel } from '../../../../../../infrastructure/models/OptionModel';
import { StoryModel } from '../../../../../../infrastructure/models/StoryModel';
import { GRAPH_ID } from '../../../../../../shared/constants/graph';
import { GRAPH_ID, GRAPH_WAIT_FOR_GRAPH_STATE_CHANGE } from '../../../../../../shared/constants/graph';
import ActionsToolbarComponent from '../actions-toolbar/ActionsToolbarComponent';
import SaveGraphSequence from '../save-graph-sequence/SaveGraphSequence';
import SaveGraphOptions from '../save-graph-options/SaveGraphOptions';
Expand All @@ -34,9 +34,23 @@ class WriteStoryComponent extends Component {
sequence: undefined,
sourceDest: sourceDestInitialValues,
options: [],
graphState: { staticGraph: true },
};
graphRef = React.createRef();

componentDidMount () {
/**
* When using { staticGraphWithDragAndDrop: true }, the nodes get slightly rearranged
* if they are too tight. In order to avoid this, we're initially setting the graph to
* { staticGraph: true } so everything gets placed where it is supposed to stay
* and then we change the graph to { staticGraphWithDragAndDrop: true } to allow the
* user to move the nodes
*/
setTimeout(() => {
this.setState({ graphState: { staticGraphWithDragAndDrop: true } });
}, GRAPH_WAIT_FOR_GRAPH_STATE_CHANGE);
}

onSaveStory = () => {
console.log(getNewGraph(this.graphRef));
};
Expand Down Expand Up @@ -135,6 +149,7 @@ class WriteStoryComponent extends Component {
sequence,
sourceDest,
options,
graphState,
} = this.state;

const data = {
Expand Down Expand Up @@ -173,7 +188,7 @@ class WriteStoryComponent extends Component {
config={{
directed: true,
nodeHighlightBehavior: true,
staticGraphWithDragAndDrop: true,
...graphState,
node: {
labelProperty: 'name',
fontSize: 16,
Expand Down
2 changes: 2 additions & 0 deletions src/shared/constants/graph.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const GRAPH_ID = 'write-story-graph';
export const GRAPH_NODE_SIZE = 500;
export const GRAPH_SOURCE_DEST_PROPERTY = 'sourceDest';

export const GRAPH_WAIT_FOR_GRAPH_STATE_CHANGE = 1000;

0 comments on commit 8843f4f

Please sign in to comment.