From 24a296fef91c25967bcb5ad651133f5bae7066b0 Mon Sep 17 00:00:00 2001 From: moklick Date: Mon, 5 Aug 2019 18:04:37 +0200 Subject: [PATCH] feat(minimap): node color func --- dist/ReactGraph.js | 9 +++++++- example/SimpleGraph.js | 5 +++++ example/build/example.e31bb0bc.js | 31 +++++++++++++++++++++++---- example/build/example.e31bb0bc.js.map | 2 +- example/build/index.js | 2 +- example/build/index.js.map | 2 +- src/Plugins/MiniMap/index.js | 5 ++++- src/utils.js | 1 + 8 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 src/utils.js 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'; + }} />