Skip to content

Commit

Permalink
address #222
Browse files Browse the repository at this point in the history
  • Loading branch information
cj-dimaano committed May 24, 2017
1 parent 4d12066 commit f34079c
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions app/components/graph-editor/editor-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
* (except for events).
*/

// TODO: Make sure to not rely on this dependency long term.
// import { PLUGIN_DIRECTORY } from "../../services/plugin.service";
// import { remote } from "electron";
// const path = remote.require("path");

import { NUDGE, SELECTION_COLOR, STICKY_DELAY } from "./defaults";
import {
DrawableEvent,
Expand Down Expand Up @@ -268,6 +263,9 @@ export class EditorGraph {

// Update the drag point.
this.dragPoint = pt;

// Redraw the canvas.
this.draw();
}
}

Expand Down Expand Up @@ -328,6 +326,7 @@ export class EditorGraph {
* True if the hover object is set to anything; otherwise, false.
*/
updateHoverObject(pt?: point): boolean {
this.suspendDraw();

// Update the previous hover object.
if (this.hoverObject) {
Expand Down Expand Up @@ -437,7 +436,7 @@ export class EditorGraph {
else
this.hoverObject = null;

this.draw();
this.resumeDraw();
return this.hoverObject !== null;
}

Expand Down Expand Up @@ -471,7 +470,6 @@ export class EditorGraph {
this.dragObject.isDragging = true;
}
}
this.draw();
}

// Pick up the edge if one is being hovered.
Expand All @@ -481,6 +479,7 @@ export class EditorGraph {
const apt = (this.drawables
.get(hoverEdge.drawable.source) as EditorNode).anchor;
const isSrc = spt.x !== apt.x || spt.y !== apt.y;
this.updateHoverObject();
const edge = this.createDragEdge(
(isSrc ? hoverEdge.source : hoverEdge.destination),
isSrc,
Expand All @@ -498,17 +497,15 @@ export class EditorGraph {
else
edge.bindDestinationAnchor(pt);
}
this.hoverObject.isDragging = true;
this.moveEdge = this.hoverObject;
this.updateHoverObject();
hoverEdge.isDragging = true;
this.moveEdge = hoverEdge;
}

// Clear the drag object if the hover object is not a node or edge.
else if (this.dragObject) {
this.dragObject.isDragging = false;
this.dragObject = null;
this.updateHoverObject();
this.draw();
}
}

Expand Down Expand Up @@ -541,9 +538,6 @@ export class EditorGraph {
this._drawSelectionBox = () => {
this.g.drawSelectionBox(rect);
};

// Update the canvas.
this.draw();
}

/**
Expand All @@ -563,7 +557,7 @@ export class EditorGraph {
* Updates the collection of nodes being dragged.
*/
private updateDragNodes(dragNode: EditorNode, dpt: point) {
this.suspendDraw();
// this.suspendDraw();
const selectedNodes = [...this.drawable.selectedNodes];
if (dragNode.drawable.isSelected && selectedNodes.length > 0) {
for (const n of selectedNodes)
Expand All @@ -574,7 +568,7 @@ export class EditorGraph {
}
else
this.updateDragNode(dragNode, dpt);
this.resumeDraw();
// this.resumeDraw();
}

/**
Expand Down Expand Up @@ -682,7 +676,7 @@ export class EditorGraph {
this.moveEdge = null;
// Move or create the edge if it was dropped on a node.
if (hoverNode instanceof EditorNode) {
this.suspendDraw();
// this.suspendDraw();
// Get the source and destination nodes.
const src = dragEdge.source === HIDDEN_NODE ?
hoverNode :
Expand Down Expand Up @@ -721,7 +715,7 @@ export class EditorGraph {
);
this.updateSelected(drawable);
}
this.resumeDraw();
// this.resumeDraw();
}
// Update the original edge if one was being moved.
else if (like) {
Expand Down Expand Up @@ -795,7 +789,6 @@ export class EditorGraph {
this.unselected.add(e);
e.update(this.g);
d.addEventListener("change", this.onDrawablePropertyChanged);
this.draw();
}

/**
Expand All @@ -821,7 +814,6 @@ export class EditorGraph {
this.unselected.delete(e);
this.drawables.delete(d);
d.removeEventListener("change", this.onDrawablePropertyChanged);
this.draw();
}

/**
Expand Down Expand Up @@ -869,8 +861,10 @@ export class EditorGraph {
*/
private onCreated
= (evt: DrawableEvent<DrawableElement>) => {
this.suspendDraw();
for (const e of evt.detail.drawables)
this.registerDrawable(e[0]);
this.resumeDraw();
}

/**
Expand All @@ -881,9 +875,11 @@ export class EditorGraph {
*/
private onDeleted
= (evt: DrawableEvent<DrawableElement>) => {
this.suspendDraw();
for (const e of evt.detail.drawables) {
this.unregisterDrawable(e[0]);
}
this.resumeDraw();
}

/**
Expand All @@ -893,8 +889,10 @@ export class EditorGraph {
*/
private onMovedEdge
= (evt: MoveEdgeEvent) => {
this.suspendDraw();
this.unregisterDrawable(evt.detail.original);
this.registerDrawable(evt.detail.replacement);
this.resumeDraw();
}

/**
Expand Down

0 comments on commit f34079c

Please sign in to comment.