diff --git a/dist/ReactGraph.js b/dist/ReactGraph.js index 57799811..600f00fb 100644 --- a/dist/ReactGraph.js +++ b/dist/ReactGraph.js @@ -33623,6 +33623,10 @@ connectionLineStyle: {} }; + var isFunction = function isFunction(obj) { + return !!(obj && obj.constructor && obj.call && obj.apply); + }; + var baseStyle = { position: 'absolute', zIndex: 5, @@ -33656,6 +33660,9 @@ height: state.height }; var scaleFactor = width / state.width; + var nodeColorFunc = isFunction(nodeColor) ? nodeColor : function () { + return nodeColor; + }; React.useEffect(function () { if (canvasNode) { var ctx = canvasNode.current.getContext('2d'); @@ -33668,7 +33675,7 @@ var transformY = state.transform[1]; var x = pos.x * state.transform[2] + transformX; var y = pos.y * state.transform[2] + transformY; - ctx.fillStyle = nodeColor; + ctx.fillStyle = nodeColorFunc(n); ctx.fillRect(x * scaleFactor, y * scaleFactor, n.__rg.width * scaleFactor * state.transform[2], n.__rg.height * scaleFactor * state.transform[2]); }); } diff --git a/example/SimpleGraph.js b/example/SimpleGraph.js index 94d6f178..bf11ebf2 100644 --- a/example/SimpleGraph.js +++ b/example/SimpleGraph.js @@ -165,6 +165,11 @@ class App extends PureComponent { > { + if (n.type === 'input') return 'blue' + if (n.type === 'output') return 'green' + return 'red'; + }} />