Skip to content

Commit

Permalink
Respect 'nodeIcons' props for overriding node icons
Browse files Browse the repository at this point in the history
updateIcon() function is deprecated
  • Loading branch information
jonnor committed Jun 26, 2017
1 parent daada31 commit 7a2ed4f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions examples/demo-full.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
var appState = {
graph: new fbpGraph.Graph(),
library: {},
iconOverrides: {},
theme: 'dark'
};

Expand Down Expand Up @@ -125,6 +126,7 @@
height: window.innerWidth,
graph: appState.graph,
library: appState.library,
nodeIcons: appState.iconOverrides,
onPanScale: renderNav,
}

Expand Down Expand Up @@ -166,13 +168,12 @@
// Simulate node icon updates
var iconKeys = Object.keys(TheGraph.FONT_AWESOME);
window.setInterval(function () {
if (!editor.graph) { return; }

var nodes = appState.graph.nodes;
if (nodes.length>0) {
var randomNodeId = nodes[Math.floor(Math.random()*nodes.length)].id;
var randomIcon = iconKeys[Math.floor(Math.random()*iconKeys.length)];
editor.updateIcon(randomNodeId, randomIcon);
appState.iconOverrides[randomNodeId] = randomIcon;
renderApp();
}
}, 1000);

Expand Down
2 changes: 2 additions & 0 deletions the-graph/the-graph-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ module.exports.register = function (context) {
width: null,
height: null,
readonly: false,
nodeIcons: {},
minZoom: 0.15,
maxZoom: 15.0,
offsetX: 0.0,
Expand Down Expand Up @@ -606,6 +607,7 @@ module.exports.register = function (context) {
scale: this.state.scale,
app: this,
library: this.props.library,
nodeIcons: this.props.nodeIcons,
onNodeSelection: this.props.onNodeSelection,
onEdgeSelection: this.props.onEdgeSelection,
showContext: this.showContext,
Expand Down
10 changes: 6 additions & 4 deletions the-graph/the-graph-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module.exports.register = function (context) {
app: null,
offsetX: 0,
offsetY: 0,
nodeIcons: {}, // allows overriding icon of a node
};
},
getInitialState: function() {
Expand All @@ -112,6 +113,7 @@ module.exports.register = function (context) {
},
componentWillReceiveProps: function(nextProps) {
this.subscribeGraph(this.props.graph, nextProps.graph);
this.markDirty();
},
subscribeGraph: function(previous, next) {
if (previous) {
Expand Down Expand Up @@ -394,9 +396,9 @@ module.exports.register = function (context) {
});
this.markDirty();
},
updatedIcons: {},
updateIcon: function (nodeId, icon) {
this.updatedIcons[nodeId] = icon;
// FIXME: deprecated function, to be removed
this.props.nodeIcons[nodeId] = icon;
this.markDirty();
},
dirty: false,
Expand Down Expand Up @@ -477,8 +479,8 @@ module.exports.register = function (context) {
}
var icon = "cog";
var iconsvg = "";
if (self.updatedIcons[key]) {
icon = self.updatedIcons[key];
if (self.props.nodeIcons[key]) {
icon = self.props.nodeIcons[key];
} else if (componentInfo && componentInfo.icon) {
icon = componentInfo.icon;
} else if (componentInfo && componentInfo.iconsvg) {
Expand Down

0 comments on commit 7a2ed4f

Please sign in to comment.