From f330b0c4ee1a7d9eaa89931b0c8de52e14a4501e Mon Sep 17 00:00:00 2001 From: moklick Date: Tue, 16 Jul 2019 12:33:05 +0200 Subject: [PATCH] feat(renderer): pass nodeTypes --- dist/ReactGraph.js | 5 ++++- example/SimpleGraph.js | 13 ++++++++++++- package.json | 4 +--- src/GraphView/index.js | 2 +- src/NodeRenderer/index.js | 17 ++++++++++++++++- src/index.js | 3 ++- 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/dist/ReactGraph.js b/dist/ReactGraph.js index f846b1a6..85ee547a 100644 --- a/dist/ReactGraph.js +++ b/dist/ReactGraph.js @@ -32218,7 +32218,10 @@ transform: "translate(".concat(position.x, "px,").concat(position.y, "px)") }, onClick: function onClick() { - return onNodeClick(data); + return onNodeClick({ + data: data, + position: position + }); } }, React__default.createElement(NodeComponent, props))); }; diff --git a/example/SimpleGraph.js b/example/SimpleGraph.js index 303978b0..3b68aee4 100644 --- a/example/SimpleGraph.js +++ b/example/SimpleGraph.js @@ -1,8 +1,14 @@ import React, { PureComponent } from 'react'; import Graph from '../src'; +import wrapNode from '../src/NodeRenderer/NodeTypes/wrapNode'; + // import Graph from '../dist/ReactGraph'; +const SpecialNode = wrapNode(({ data }) => +
I am Special!
{data.label}
+); + class App extends PureComponent { constructor() { super(); @@ -14,10 +20,12 @@ class App extends PureComponent { { data: { id: '3', label: 'This is a node' }, position: { x: 100, y: 200 }, style: { background: '#222', color: '#fff' } }, { data: { id: '4', label: 'nody nodes', type: 'output' }, position: { x: 50, y: 300 } }, { data: { id: '5', label: 'Another node', type: 'output' }, position: { x: 400, y: 300 } }, + { data: { id: '6', label: 'A label', type: 'special' }, position: { x: 400, y: 400 } }, { data: { source: '1', target: '2' } }, { data: { source: '2', target: '3' } }, { data: { source: '3', target: '4' } }, - { data: { source: '3', target: '5' } } + { data: { source: '3', target: '5' } }, + { data: { source: '5', target: '6' } } ] } } @@ -57,6 +65,9 @@ class App extends PureComponent { style={{ width: '100%', height: '100%' }} onLoad={graphInstance => this.onLoad(graphInstance)} onChange={(elements) => this.onChange(elements)} + nodeTypes={{ + special: SpecialNode + }} >