-
Notifications
You must be signed in to change notification settings - Fork 46
/
grid.js
65 lines (56 loc) · 1.68 KB
/
grid.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
(function() {
'use strict';
/*
* This feature allows you to specify a grid over a portion or the entire chart area.
*
* @name grid
*/
d4.feature('grid', function(name) {
var xAxis = d3.svg.axis();
var yAxis = d3.svg.axis();
return {
accessors: {
formatXAxis: function(xAxis) {
return xAxis.orient('bottom');
},
formatYAxis: function(yAxis) {
return yAxis.orient('left');
}
},
proxies: [{
target: xAxis,
prefix: 'x'
}, {
target: yAxis,
prefix: 'y'
}],
render: function(scope, data, selection) {
xAxis.scale(this.x);
yAxis.scale(this.y);
var formattedXAxis = d4.functor(scope.accessors.formatXAxis).bind(this)(xAxis);
var formattedYAxis = d4.functor(scope.accessors.formatYAxis).bind(this)(yAxis);
var grid = d4.appendOnce(selection, 'g.grid.border.' + name);
var gridBg = d4.appendOnce(grid, 'rect');
var gridX = d4.appendOnce(grid, 'g.x.grid.' + name);
var gridY = d4.appendOnce(grid, 'g.y.grid.' + name);
gridBg
.attr('transform', 'translate(0,0)')
.attr('x', 0)
.attr('y', 0)
.attr('width', this.width)
.attr('height', this.height);
gridX
.attr('transform', 'translate(0,' + this.height + ')')
.call(formattedXAxis
.tickSize(-this.height, 0, 0)
.tickFormat(''));
gridY
.attr('transform', 'translate(0,0)')
.call(formattedYAxis
.tickSize(-this.width, 0, 0)
.tickFormat(''));
return grid;
}
};
});
}).call(this);