-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlearn_angular.html
149 lines (137 loc) · 4.38 KB
/
learn_angular.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<html lang="en">
<head>
<title>Alpha-Viz</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="lib/bootstrap/css/bootstrap.min.css">
<!-- add script tags to include all the .js file -->
<script src="lib/d3/d3.min.js" charset="utf-8"></script>
<script src="lib/angular/angular.min.js"></script>
<style>
/*add custom style css*/
input[type="range"]{
width: 15%;
}
</style>
</head>
<body ng-app="myApp" ng-init="charts=[[8, 3, 7],[2, 5, 9],[6, 2, 3]]; ourRangeValue=50; progs=[20, 30, 50]; dynamic_chart=[10, 20, 30]">
<input type="text" ng-model="person"></input>
hello {{person}}!
<hello-world></hello-world>
<p>------------------------------------</p>
<donut-chart data="chart" ng-repeat="chart in charts"></donut-chart>
<p>------------------------------------</p>
<div ng-controller="HelloController">
<input type="range" ng-model="ourRangeValue">
<input type="range" ng-model="ourRangeValue">
</div>
<p>------------------------------------</p>
<div ng-repeat="prog in progs">
<input type="range" ng-model="prog">
<progress-bar progress="prog"></progress-bar>
</input>
</div>
<p>------------------------------------</p>
<input type="range" ng-model="dynamic_chart[0]">
<br>
<input type="range" ng-model="dynamic_chart[1]">
<br>
<input type="range" ng-model="dynamic_chart[2]">
<donut-chart data="dynamic_chart"></donut-chart>
<script>
// module to hold all the directives
var myApp = angular.module('myApp', [])
// create helloWorld directive
myApp.directive('helloWorld', function() {
function link(scope, element, attr) {
element.text("hello world!")
}
return {
link: link,
restrict: 'E'
}
})
// create donut char directive
myApp.directive('donutChart', function() {
function link(scope, element, attr) {
// Donut Chart
var color = d3.scale.category10() // 10 categories of color
var data = scope.data // isolated scope to allow different data
var width = 300
var height = 300
var min = Math.min(width, height)
var svg = d3.select(element[0]).append('svg')
.attr('width', width)
.attr('height', height)
var pie = d3.layout.pie().sort(null) // null to disable sorting
var arc = d3.svg.arc()
.outerRadius(min / 2 * 0.9)
.innerRadius(min / 2 * 0.5)
var g = svg.append('g') // for group SVGs, center the donut chart
.attr('transform', 'translate(' + width / 2 + ',' + height / 2 + ')') // w/2 as x, h/2 as y
var arcs = g.selectAll('path').data(pie(data))
.enter().append('path')
.attr('fill', function(d, i) { return color(i) })
.style('stroke', 'white')
// .attr('d', arc) need to comment and modify dynamicly
// add $watch to dynamic update
scope.$watch('data', function(data) {
console.log("an element within `data` changed!")
console.log(data)
arcs.data(pie(data)).attr('d', arc);
}, true)
}
return {
link: link,
restrict: 'E',
scope: { data: '=' }
}
})
// create a HelloController
myApp.controller('HelloController', function($scope){
$scope.ourRangeValue = 50;
})
// create progress bar directives
myApp.directive('progressBar', function() {
function link (scope, element, attr) {
var w = 300
var h = 30
var svg = d3.select(element[0]).append('svg')
.attr('width', w)
.attr('height', h)
.style('border', '1px solid black')
// inner bar 'rect'
var rect = svg.append('rect').style('fill', 'blue')
scope.$watch('progress', function(progress) {
rect.attr({x: 0, y: 0, width: w * progress / 100, height: h })
})
}
return {
link: link,
restrict: 'E',
scope: { progress: '=' }
}
})
</script>
<!-- add div tags to set region -->
<script>
// your d3.js code
// configure page layout
// load data
// var file = "./data/daily_2014_clean.csv"
// var columns = "year,month,day,entity,avgASenti,avgImpSc".split(',')
// var metricOne = "avgASenti"
// var metricTwo = "avgImpSc"
// d3.csv(file, function(error, data) {
// // error check
// if(error) {
// console.warn(error);
// return;
// }
// // use data
// console.log(data.length)
// })
// perform functions
</script>
</body>
</html>