Skip to content

Commit 7d91ebb

Browse files
Arrows on links add
1 parent 232e1c6 commit 7d91ebb

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iknow-entity-browser",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "Visualizer for iKnow entities",
55
"main": "gulpfile.babel.js",
66
"scripts": {

src/static/index.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@
1515
<i id="undoButton" class="ui icon-undo"></i>
1616
<i id="redoButton" class="ui icon-redo"></i>
1717
</div>
18-
<svg id="graph"></svg>
18+
<svg id="graph">
19+
<defs>
20+
<marker id="svgLineArrow-related" markerWidth="10" markerHeight="10" refX="7" refY="3" orient="auto" markerUnits="strokeWidth">
21+
<path d="M0,0 L0,6 L9,3 z" fill="#ffb840"/>
22+
</marker>
23+
<marker id="svgLineArrow-similar" markerWidth="10" markerHeight="10" refX="7" refY="3" orient="auto" markerUnits="strokeWidth">
24+
<path d="M0,0 L0,6 L9,3 z" fill="#7ca1ff"/>
25+
</marker>
26+
<marker id="svgLineArrow-other" markerWidth="10" markerHeight="10" refX="7" refY="3" orient="auto" markerUnits="strokeWidth">
27+
<path d="M0,0 L0,6 L9,3 z" fill="#f00"/>
28+
</marker>
29+
</defs>
30+
</svg>
1931
<div id="table">
2032
<i id="tableToggle" class="ui icon-list"></i>
2133
<div id="rightTopIcons">

src/static/js/graph/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,19 @@ function newSimulation () {
6666
.on("tick", ticked);
6767
}
6868

69+
const ARROW_FWD = 2;
70+
6971
function ticked () {
7072
if (!link)
7173
return;
7274
link
73-
.attr("x1", d => d.source.x)
74-
.attr("y1", d => d.source.y)
75-
.attr("x2", d => d.target.x)
76-
.attr("y2", d => d.target.y);
75+
.attr("x1", d => {
76+
d.dir = Math.atan2(d.target.y - d.source.y, d.target.x - d.source.x);
77+
return d.source.x + Math.cos(d.dir) * d.source.radius;
78+
})
79+
.attr("y1", d => d.source.y + Math.sin(d.dir) * d.source.radius)
80+
.attr("x2", d => d.target.x - Math.cos(d.dir) * (d.target.radius + ARROW_FWD))
81+
.attr("y2", d => d.target.y - Math.sin(d.dir) *(d.target.radius + ARROW_FWD));
7782
node
7883
.attr("transform", (d) => `translate(${ d.x },${ d.y })`)
7984
}
@@ -206,7 +211,8 @@ export function update (g = lastGraph, reset = false) {
206211
: d.type === "related"
207212
? "related"
208213
: "other"
209-
);
214+
)
215+
.attr("marker-end", d => `url(#svgLineArrow-${ d.type })`);
210216
link = linkEnter.merge(link);
211217

212218
node = nodes.selectAll(".node").data(graph.nodes, function (d) { return this._id || d.id; });

0 commit comments

Comments
 (0)