Skip to content

Commit f90cf8d

Browse files
authored
Merge pull request #57 from magjac/visual-feedback-while-rendering-graph
Visual feedback while rendering graph
2 parents 09175a3 + 53aaeae commit f90cf8d

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

src/Graph.js

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { withStyles } from '@material-ui/core/styles';
4+
import Fade from '@material-ui/core/Fade';
5+
import CircularProgress from '@material-ui/core/CircularProgress';
46
import { select as d3_select} from 'd3-selection';
57
import { selectAll as d3_selectAll} from 'd3-selection';
68
import { transition as d3_transition} from 'd3-transition';
@@ -18,6 +20,11 @@ const styles = {
1820
flex: {
1921
flexGrow: 1,
2022
},
23+
progress: {
24+
position: 'absolute',
25+
top: 'calc(64px + 2 * 12px + 2px)',
26+
left: 'calc(100vw - 2 * 12px - 2 * 12px)',
27+
},
2128
};
2229

2330
function isNumeric(n) {
@@ -27,7 +34,9 @@ function isNumeric(n) {
2734
class Graph extends React.Component {
2835
constructor(props) {
2936
super(props);
30-
this.state = {};
37+
this.state = {
38+
busy: false,
39+
};
3140
this.createGraph = this.createGraph.bind(this)
3241
this.renderGraph = this.renderGraph.bind(this)
3342
this.isDrawingEdge = false;
@@ -65,6 +74,7 @@ class Graph extends React.Component {
6574
let line = errorMessage.replace(/.*error in line ([0-9]*) .*\n/, '$1');
6675
this.props.onError({message: errorMessage, line: line});
6776
this.rendering = false;
77+
this.setState({busy: false});
6878
if (this.pendingUpdate) {
6979
this.pendingUpdate = false;
7080
this.render();
@@ -126,6 +136,7 @@ class Graph extends React.Component {
126136
return;
127137
}
128138
this.rendering = true;
139+
this.setState({busy: true});
129140
this.graphviz
130141
.width(width)
131142
.height(height)
@@ -149,6 +160,7 @@ class Graph extends React.Component {
149160
this.dotGraph = this.prelDotGraph;
150161
this.addEventHandlers();
151162
this.rendering = false;
163+
this.setState({busy: false});
152164
if (!this.renderGraphReady) {
153165
this.renderGraphReady = true;
154166
this.setZoomScale(1, true);
@@ -714,12 +726,33 @@ class Graph extends React.Component {
714726
}
715727

716728
render() {
717-
return <div
718-
ref={div => this.div = d3_select(div)}
719-
onDragOver={this.handleNodeShapeDragOver}
720-
onDrop={this.handleNodeShapeDrop.bind(this)}
721-
>
722-
</div>;
729+
const { classes } = this.props;
730+
return (
731+
<React.Fragment>
732+
<div
733+
ref={div => this.div = d3_select(div)}
734+
onDragOver={this.handleNodeShapeDragOver}
735+
onDrop={this.handleNodeShapeDrop.bind(this)}
736+
>
737+
</div>
738+
{this.state.busy && (
739+
<Fade
740+
in={true}
741+
style={{
742+
transitionDelay: '800ms',
743+
}}
744+
unmountOnExit
745+
>
746+
<CircularProgress
747+
className={classes.progress}
748+
color="secondary"
749+
size={20}
750+
thickness={4.5}
751+
/>
752+
</Fade>
753+
)}
754+
</React.Fragment>
755+
);
723756
}
724757
}
725758

src/pages/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,54 +249,54 @@ class Index extends React.Component {
249249
}
250250

251251
handleNodeStyleChange = (style) => {
252-
this.setPersistentState(prevState => ({
252+
this.setPersistentState(state => ({
253253
defaultNodeAttributes: {
254-
...prevState.defaultNodeAttributes,
254+
...state.defaultNodeAttributes,
255255
style: style,
256256
},
257257
}));
258258
}
259259

260260
handleNodeColorChange = (color) => {
261-
this.setPersistentState(prevState => ({
261+
this.setPersistentState(state => ({
262262
defaultNodeAttributes: {
263-
...prevState.defaultNodeAttributes,
263+
...state.defaultNodeAttributes,
264264
color: color,
265265
},
266266
}));
267267
}
268268

269269
handleNodeFillColorChange = (color) => {
270-
this.setPersistentState(prevState => ({
270+
this.setPersistentState(state => ({
271271
defaultNodeAttributes: {
272-
...prevState.defaultNodeAttributes,
272+
...state.defaultNodeAttributes,
273273
fillcolor: color,
274274
},
275275
}));
276276
}
277277

278278
handleEdgeStyleChange = (style) => {
279-
this.setPersistentState(prevState => ({
279+
this.setPersistentState(state => ({
280280
defaultEdgeAttributes: {
281-
...prevState.defaultEdgeAttributes,
281+
...state.defaultEdgeAttributes,
282282
style: style,
283283
},
284284
}));
285285
}
286286

287287
handleEdgeColorChange = (color) => {
288-
this.setPersistentState(prevState => ({
288+
this.setPersistentState(state => ({
289289
defaultEdgeAttributes: {
290-
...prevState.defaultEdgeAttributes,
290+
...state.defaultEdgeAttributes,
291291
color: color,
292292
},
293293
}));
294294
}
295295

296296
handleEdgeFillColorChange = (color) => {
297-
this.setPersistentState(prevState => ({
297+
this.setPersistentState(state => ({
298298
defaultEdgeAttributes: {
299-
...prevState.defaultEdgeAttributes,
299+
...state.defaultEdgeAttributes,
300300
fillcolor: color,
301301
},
302302
}));

0 commit comments

Comments
 (0)