-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy patharrow.js
67 lines (59 loc) · 2.06 KB
/
arrow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(function() {
'use strict';
/*
* The arrow feature is a convienient way to visually draw attention to a portion
* of a chart by pointing an arrow at it.
*
* @name arrow
*/
d4.feature('arrow', function(name) {
return {
accessors: {
classes: 'line',
tipSize: 6,
x1: function() {
return this.x(0);
},
x2: function() {
return this.x(this.width);
},
y1: function() {
return this.y(0);
},
y2: function() {
return this.y(this.height);
}
},
render: function(scope, data, selection) {
var defs = this.container.select('defs');
d4.appendOnce(defs, 'marker#' + name + '-end')
.attr('viewBox', '0 0 10 10')
.attr('refX', 10)
.attr('refY', 5)
.attr('markerWidth', d4.functor(scope.accessors.tipSize).bind(this))
.attr('markerHeight', d4.functor(scope.accessors.tipSize).bind(this))
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 0 0 L 10 5 L 0 10 z');
d4.appendOnce(defs, 'marker#' + name + '-start')
.attr('viewBox', '0 0 10 10')
.attr('refX', 10)
.attr('refY', 5)
.attr('markerWidth', d4.functor(scope.accessors.tipSize).bind(this)())
.attr('markerHeight', d4.functor(scope.accessors.tipSize).bind(this))
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 0 0 L 10 5 L 0 10 z');
d4.appendOnce(selection, 'g.' + name);
var arrow = d4.appendOnce(this.container.select('.' + name), 'line')
.attr('class', d4.functor(scope.accessors.classes).bind(this))
.attr('x1', d4.functor(scope.accessors.x1).bind(this))
.attr('x2', d4.functor(scope.accessors.x2).bind(this))
.attr('y1', d4.functor(scope.accessors.y1).bind(this))
.attr('y2', d4.functor(scope.accessors.y2).bind(this))
.attr('marker-end', 'url(#' + name + '-end)');
return arrow;
}
};
});
}).call(this);