Skip to content

Commit

Permalink
Fix zoom stops working when DOT source is cleared
Browse files Browse the repository at this point in the history
Fixes #135.

The zoom functionality stores the original "graph0" <g> element and
applies zoom transforms to it, but that elements was removed when the
DOT source was cleared.

Instead of removing the whole svg, now only the graph elements below
the "graph0" <g> element are removed.
  • Loading branch information
magjac committed Apr 10, 2020
1 parent 4253f5c commit b3b7507
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions cypress/integration/browser_save_and_open.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ describe('Browser save and open', function() {

cy.savedGraphs().should('have.length', 0);

cy.canvasSvg().should('not.exist');
cy.nodes().should('have.length', 0);
cy.edges().should('have.length', 0);
})

it('The graph is renamed in browser local storage through the menu item Rename', function() {
Expand Down Expand Up @@ -968,7 +969,8 @@ describe('Browser save and open', function() {

// FIXME: Temporary workaround to ensure that the new SVG will be stored in localStorage
cy.clearDotSource();
cy.canvasGraph().should('not.exist');
cy.nodes().should('have.length', 0);
cy.edges().should('have.length', 0);

cy.clearAndRenderDotSource('digraph {Bob}');

Expand Down Expand Up @@ -1101,7 +1103,8 @@ describe('Browser save and open', function() {

// FIXME: Temporary workaround to ensure that the new SVG will be stored in localStorage
cy.clearDotSource();
cy.canvasGraph().should('not.exist');
cy.nodes().should('have.length', 0);
cy.edges().should('have.length', 0);

cy.clearAndRenderDotSource('digraph {Alice}');

Expand Down
3 changes: 2 additions & 1 deletion src/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Graph extends React.Component {
busy: false,
};
this.svg = d3_select(null);
this.graph0 = d3_select(null);
this.createGraph = this.createGraph.bind(this)
this.renderGraph = this.renderGraph.bind(this)
this.isDrawingEdge = false;
Expand Down Expand Up @@ -108,7 +109,7 @@ class Graph extends React.Component {
let fit = this.props.fit;
let engine = this.props.engine;
if (this.props.dotSrc.length === 0) {
this.svg.remove();
this.graph0.selectAll('*').remove();
this.svg = d3_select(null);
this.props.onError(null);
this.renderGraphReady = false;
Expand Down

0 comments on commit b3b7507

Please sign in to comment.