Skip to content

Commit

Permalink
Merge pull request #57 from magjac/visual-feedback-while-rendering-graph
Browse files Browse the repository at this point in the history
Visual feedback while rendering graph
  • Loading branch information
magjac committed Sep 19, 2018
2 parents 09175a3 + 53aaeae commit f90cf8d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 19 deletions.
47 changes: 40 additions & 7 deletions src/Graph.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Fade from '@material-ui/core/Fade';
import CircularProgress from '@material-ui/core/CircularProgress';
import { select as d3_select} from 'd3-selection';
import { selectAll as d3_selectAll} from 'd3-selection';
import { transition as d3_transition} from 'd3-transition';
Expand All @@ -18,6 +20,11 @@ const styles = {
flex: {
flexGrow: 1,
},
progress: {
position: 'absolute',
top: 'calc(64px + 2 * 12px + 2px)',
left: 'calc(100vw - 2 * 12px - 2 * 12px)',
},
};

function isNumeric(n) {
Expand All @@ -27,7 +34,9 @@ function isNumeric(n) {
class Graph extends React.Component {
constructor(props) {
super(props);
this.state = {};
this.state = {
busy: false,
};
this.createGraph = this.createGraph.bind(this)
this.renderGraph = this.renderGraph.bind(this)
this.isDrawingEdge = false;
Expand Down Expand Up @@ -65,6 +74,7 @@ class Graph extends React.Component {
let line = errorMessage.replace(/.*error in line ([0-9]*) .*\n/, '$1');
this.props.onError({message: errorMessage, line: line});
this.rendering = false;
this.setState({busy: false});
if (this.pendingUpdate) {
this.pendingUpdate = false;
this.render();
Expand Down Expand Up @@ -126,6 +136,7 @@ class Graph extends React.Component {
return;
}
this.rendering = true;
this.setState({busy: true});
this.graphviz
.width(width)
.height(height)
Expand All @@ -149,6 +160,7 @@ class Graph extends React.Component {
this.dotGraph = this.prelDotGraph;
this.addEventHandlers();
this.rendering = false;
this.setState({busy: false});
if (!this.renderGraphReady) {
this.renderGraphReady = true;
this.setZoomScale(1, true);
Expand Down Expand Up @@ -714,12 +726,33 @@ class Graph extends React.Component {
}

render() {
return <div
ref={div => this.div = d3_select(div)}
onDragOver={this.handleNodeShapeDragOver}
onDrop={this.handleNodeShapeDrop.bind(this)}
>
</div>;
const { classes } = this.props;
return (
<React.Fragment>
<div
ref={div => this.div = d3_select(div)}
onDragOver={this.handleNodeShapeDragOver}
onDrop={this.handleNodeShapeDrop.bind(this)}
>
</div>
{this.state.busy && (
<Fade
in={true}
style={{
transitionDelay: '800ms',
}}
unmountOnExit
>
<CircularProgress
className={classes.progress}
color="secondary"
size={20}
thickness={4.5}
/>
</Fade>
)}
</React.Fragment>
);
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,54 +249,54 @@ class Index extends React.Component {
}

handleNodeStyleChange = (style) => {
this.setPersistentState(prevState => ({
this.setPersistentState(state => ({
defaultNodeAttributes: {
...prevState.defaultNodeAttributes,
...state.defaultNodeAttributes,
style: style,
},
}));
}

handleNodeColorChange = (color) => {
this.setPersistentState(prevState => ({
this.setPersistentState(state => ({
defaultNodeAttributes: {
...prevState.defaultNodeAttributes,
...state.defaultNodeAttributes,
color: color,
},
}));
}

handleNodeFillColorChange = (color) => {
this.setPersistentState(prevState => ({
this.setPersistentState(state => ({
defaultNodeAttributes: {
...prevState.defaultNodeAttributes,
...state.defaultNodeAttributes,
fillcolor: color,
},
}));
}

handleEdgeStyleChange = (style) => {
this.setPersistentState(prevState => ({
this.setPersistentState(state => ({
defaultEdgeAttributes: {
...prevState.defaultEdgeAttributes,
...state.defaultEdgeAttributes,
style: style,
},
}));
}

handleEdgeColorChange = (color) => {
this.setPersistentState(prevState => ({
this.setPersistentState(state => ({
defaultEdgeAttributes: {
...prevState.defaultEdgeAttributes,
...state.defaultEdgeAttributes,
color: color,
},
}));
}

handleEdgeFillColorChange = (color) => {
this.setPersistentState(prevState => ({
this.setPersistentState(state => ({
defaultEdgeAttributes: {
...prevState.defaultEdgeAttributes,
...state.defaultEdgeAttributes,
fillcolor: color,
},
}));
Expand Down

0 comments on commit f90cf8d

Please sign in to comment.