Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize nodes with JSX views #103

Merged
merged 11 commits into from
Sep 24, 2018
Merged
44 changes: 44 additions & 0 deletions sandbox/data/custom-node/CustomNode.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';

import './res/styles/custom-node.css';

const ICON_PATH = './data/custom-node/res/images/';

const ICON_TYPES = {
MAN: ICON_PATH + 'man.svg',
WOMAN: ICON_PATH + 'girl.svg',
CAR: ICON_PATH + 'car.svg',
BIKE: ICON_PATH + 'bike.svg'
};

/**
* Component that renders a person's name and gender, along with icons
* representing if they have a driver license for bike and / or car.
*/
function CustomNode({ person }) {
const isMale = person.gender === 'male';

return (
<div className={`flex-container person-node ${isMale ? 'male' : 'female'}`}>
<div className="name">{person.name}</div>

<div className="flex-container fill-space flex-container-row">
<div className="fill-space">
<div
className="icon"
style={{ backgroundImage: `url('${isMale ? ICON_TYPES.MAN : ICON_TYPES.WOMAN}')` }}
/>
</div>

<div className="icon-bar">
{person.hasBike && (
<div className="icon" style={{ backgroundImage: `url('${ICON_TYPES.BIKE}')` }} />
)}
{person.hasCar && <div className="icon" style={{ backgroundImage: `url('${ICON_TYPES.CAR}')` }} />}
</div>
</div>
</div>
);
}

export default CustomNode;
45 changes: 45 additions & 0 deletions sandbox/data/custom-node/custom-node.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import CustomNode from './CustomNode';

module.exports = {
automaticRearrangeAfterDropNode: false,
collapsible: false,
height: 400,
highlightDegree: 1,
highlightOpacity: 0.2,
linkHighlightBehavior: true,
maxZoom: 8,
minZoom: 0.1,
nodeHighlightBehavior: true,
panAndZoom: false,
staticGraph: false,
width: 800,
node: {
color: '#d3d3d3',
fontColor: 'black',
fontSize: 12,
fontWeight: 'normal',
highlightColor: 'red',
highlightFontSize: 12,
highlightFontWeight: 'bold',
highlightStrokeColor: 'SAME',
highlightStrokeWidth: 1.5,
labelProperty: 'name',
mouseCursor: 'pointer',
opacity: 1,
renderLabel: false,
size: 700,
strokeColor: 'none',
strokeWidth: 1.5,
svg: '',
symbolType: 'circle',
viewGenerator: node => <CustomNode person={node} />
},
link: {
color: '#d3d3d3',
opacity: 1,
semanticStrokeWidth: false,
strokeWidth: 4,
highlightColor: 'blue'
}
};
50 changes: 50 additions & 0 deletions sandbox/data/custom-node/custom-node.data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module.exports = {
links: [
{
source: 1,
target: 2
},
{
source: 1,
target: 3
},
{
source: 1,
target: 4
},
{
source: 3,
target: 4
}
],
nodes: [
{
id: 1,
name: 'Mary',
gender: 'female',
hasCar: false,
hasBike: false
},
{
id: 2,
name: 'Roy',
gender: 'male',
hasCar: false,
hasBike: true
},
{
id: 3,
name: 'Frank',
gender: 'male',
hasCar: true,
hasBike: true
},
{
id: 4,
name: 'Melanie',
gender: 'female',
hasCar: true,
hasBike: false
}
]
};
58 changes: 58 additions & 0 deletions sandbox/data/custom-node/res/images/bike.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions sandbox/data/custom-node/res/images/car.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions sandbox/data/custom-node/res/images/girl.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading