-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathd3Grid.js
80 lines (70 loc) · 2.16 KB
/
d3Grid.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
68
69
70
71
72
73
74
75
76
77
78
79
80
(function() {
'use strict';
angular.module('app.directives')
.directive('d3Grid', ['d3', function(d3) {
return {
restrict: 'EA',
scope: {
data: '='
},
link: function(scope, iElement, iAttrs) {
// console.log(scope.data);
var margin = {
top: 20,
right: 100,
bottom: 30,
left: 100
},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var xScale = d3.scale.linear()
.domain([0, d3.max(scope.data, function(d) {
return d.x;
})])
.range([0, width]);
var yScale = d3.scale.linear()
.domain([0, d3.max(scope.data, function(d) {
return d.y;
})])
.range([height, 0]);
console.log(xScale(1))
console.log(yScale(1))
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.innerTickSize(-height)
.outerTickSize(0)
.tickPadding(10);
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left")
.innerTickSize(-width)
.outerTickSize(0)
.tickPadding(10);
var line = d3.svg.line()
.x(function(d) {
return xScale(d.x);
})
.y(function(d) {
return yScale(d.y);
});
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
svg.append("path")
.data([scope.data])
.attr("class", "line")
.attr("d", line);
}
};
}]);
}());