Skip to content

Commit cb38cf5

Browse files
committed
Simplify examples
1 parent 46c5149 commit cb38cf5

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

example/highlight/index.html

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,19 @@
3535
});
3636
};
3737

38-
_paintNode = (node, ctx) => {
38+
_paintRing = (node, ctx) => {
3939
const { NODE_R } = HighlightGraph;
40-
const { highlightNodes } = this.state;
41-
42-
if (highlightNodes.indexOf(node) !== -1) { // add ring
43-
ctx.beginPath();
44-
ctx.arc(node.x, node.y, NODE_R * 1.4, 0, 2 * Math.PI, false);
45-
ctx.fillStyle = 'red';
46-
ctx.fill();
47-
}
4840

41+
// add ring just for highlighted nodes
4942
ctx.beginPath();
50-
ctx.arc(node.x, node.y, NODE_R, 0, 2 * Math.PI, false);
51-
ctx.fillStyle = 'midnightblue';
43+
ctx.arc(node.x, node.y, NODE_R * 1.4, 0, 2 * Math.PI, false);
44+
ctx.fillStyle = 'red';
5245
ctx.fill();
5346
};
5447

5548
render() {
5649
const { NODE_R } = HighlightGraph;
57-
const { data, highlightLink } = this.state;
50+
const { data, highlightNodes, highlightLink } = this.state;
5851

5952
return <ForceGraph2D
6053
ref={el => { this.fg = el; }}
@@ -63,7 +56,8 @@
6356
linkWidth={link => link === highlightLink ? 5 : 1}
6457
linkDirectionalParticles={4}
6558
linkDirectionalParticleWidth={link => link === highlightLink ? 4 : 0}
66-
nodeCanvasObject={this._paintNode}
59+
nodeCanvasObjectMode={node => highlightNodes.indexOf(node) !== -1 ? 'before' : undefined}
60+
nodeCanvasObject={this._paintRing}
6761
onNodeHover={this._handleNodeHover}
6862
onLinkHover={this._handleLinkHover}
6963
/>;

example/text-links/index-3d.html

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,21 @@
2222
graphData={data}
2323
nodeLabel="id"
2424
nodeAutoColorBy="group"
25+
linkThreeObjectExtend={true}
2526
linkThreeObject={link => {
26-
// create line object
27-
const lineObj = new THREE.Line(
28-
new THREE.BufferGeometry(),
29-
new THREE.MeshLambertMaterial({
30-
color: '#f0f0f0',
31-
transparent: true,
32-
opacity: 0.2
33-
})
34-
);
35-
36-
// add text sprite as child
27+
// extend link with text sprite
3728
const sprite = new SpriteText(`${link.source} > ${link.target}`);
3829
sprite.color = 'lightgrey';
3930
sprite.textHeight = 1.5;
40-
lineObj.add(sprite);
41-
42-
return lineObj;
31+
return sprite;
4332
}}
44-
linkPositionUpdate={(obj, { start, end }) => {
33+
linkPositionUpdate={(sprite, { start, end }) => {
4534
const middlePos = Object.assign(...['x', 'y', 'z'].map(c => ({
4635
[c]: start[c] + (end[c] - start[c]) / 2 // calc middle point
4736
})));
4837

49-
const textSprite = obj.children[0];
50-
51-
// Position link text
52-
Object.assign(textSprite.position, middlePos);
38+
// Position sprite
39+
Object.assign(sprite.position, middlePos);
5340
}}
5441
/>,
5542
document.getElementById('graph')

0 commit comments

Comments
 (0)