Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from sarbull/patch-9
Browse files Browse the repository at this point in the history
Fix clearGraph method on new empty data
  • Loading branch information
Ljupcho Palashevski authored Nov 12, 2020
2 parents 3a6f3ad + b485adf commit 453b80f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
13 changes: 10 additions & 3 deletions src/asset-lineage/asset-lineage-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class AssetLineageView extends mixinBehaviors([ItemViewBehavior], PolymerElement
.pop();
}

if (!['condensedNode', 'subProcess'].includes(_selectedNode.group)) {
if (!['condensedNode', 'subProcess', 'Process'].includes(_selectedNode.group)) {
this.selectedNode = _selectedNode;

this.$.tokenAjaxDetails.url = `/api/assets/${nodeId}`;
Expand Down Expand Up @@ -246,7 +246,7 @@ class AssetLineageView extends mixinBehaviors([ItemViewBehavior], PolymerElement
}

_graphDataChanged(data) {
if (data.edges.length === 0 || data.nodes.length === 0) {
if (data === null || data.nodes.length === 0) {
this.dispatchEvent(new CustomEvent('show-modal', {
bubbles: true,
composed: true,
Expand All @@ -257,7 +257,14 @@ class AssetLineageView extends mixinBehaviors([ItemViewBehavior], PolymerElement
}));
}

this._updateHappiGraph(data);
if (data !== null) {
this._updateHappiGraph(data);
} else {
this._updateHappiGraph({
nodes: [],
edges: []
});
}
}

_ultimateSource(guid, includeProcesses) {
Expand Down
35 changes: 23 additions & 12 deletions src/common/happi-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ class HappiGraph extends PolymerElement {
}

_graphDataUpdate(newData, oldData) {
if (newData.nodes.length > 0) {
this.clearGraph();
this.clearGraph();

if (newData.nodes.length > 0) {
let mappedNodes = this.mapped(newData);
let finalNodes = [];
let orderedNodes = {};
Expand All @@ -274,6 +274,10 @@ class HappiGraph extends PolymerElement {
}
}

if(newData.nodes.length === 1) {
orderedNodes = this.mapped(newData);
}

Object.keys(orderedNodes).forEach(k => {
finalNodes.push(orderedNodes[k]);
});
Expand All @@ -284,8 +288,8 @@ class HappiGraph extends PolymerElement {
nodes: finalNodes.map(n => {
let result = {
...n,
fx: n.x * 350, // TODO: calculate these coordinates so that
fy: n.y * 350, // all nodes are centered
fx: n.x ? n.x * 350 : 0, // TODO: calculate these coordinates so that
fy: n.y ? n.y * 350 : 0, // all nodes are centered
width: this.getNodeWidth(n.properties.length),
height: this.getNodeHeight(n.properties.length)
};
Expand Down Expand Up @@ -322,16 +326,23 @@ class HappiGraph extends PolymerElement {
}

clearGraph() {
this.graph = {
nodes: [],
links: []
};
if (this.svg) {
this.graph = {
nodes: [],
links: [],
graphDirection: ''
};

this.nodes = [];
this.links = [];
this.nodes = [];
this.links = [];

this.updateForces();
this.update();
this.simulation = d3.forceSimulation();

this.fitContent();
this.initializeForces();
this.updateForces();
this.update();
}
}

connectedCallback() {
Expand Down

0 comments on commit 453b80f

Please sign in to comment.