forked from CSE512-14W/fp-chaoyu-aniket-glnelson-anied
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow-controller.js
166 lines (141 loc) · 5.27 KB
/
flow-controller.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
var update_textbox = function(start){
d3.select("#textbox_timestart")
.attr("value", start);
d3.select("#textbox_timestop")
.attr("value", start + flow.duration);
};
var update_time_step = function(cur) {
current_time_step = cur;
d3.select("#controller g")
.transition()
.call(controller_brusher.extent([cur, cur+flow.duration]));
update_textbox(cur);
}
var graph_contoller = function(){
var controller_area = d3.select('#controller')
.attr('width', 600)
.attr('height', 60)
.style("display","block")
.style("margin","auto")
.style("width","600px");
// Add control buttons
controller_area.append("input")
.attr("type","button")
.attr("class","btn btn-default")
.attr("value", "Start")
.on("click", start);
controller_area.append("input")
.attr("type","button")
.attr("class","btn btn-default")
.attr("value", "Stop")
.on("click", stop);
controller_area.append("input")
.attr('id', 'textbox_timestart')
.style("width","40px") // was 50
.attr("value", "0");
// .on("click", function (d) {
// current_time_step = parseInt(d3.select('#textbox_timestart').attr('value'));
// });
controller_area.append("span")
.text(' to ');
controller_area.append("input")
.attr('id', 'textbox_timestop')
.style("width","40px") // was 50
.attr("value", "7");
// .on("click", time_update(0, 7));
controller_area.append("span")
.text(' ms');
var controller_height = 40;
var controller_width = 600;
var x = d3.scale.identity().domain([0, controller_width]);
var defaultExtent = [0,flow.duration];
var slidersvg = controller_area.append("svg")
.attr("width", controller_width)
.attr("height", controller_height);
//slidersvg.append("rect")
// .attr({
// width: controller_width,
// height: controller_height,
// class: 'controller-background'
// });
var controller_scale = d3.scale.linear()
.domain([0, 600])
.range([0, controller_width])
.nice();
var in_out_degree_range = [d3.min(total_degree, function(d) { return d; }),
d3.max(total_degree, function(d) { return d; })];
// y-axis scale
var yScale = d3.scale.linear()
.domain(in_out_degree_range)
.range([0, controller_height])
.nice();
// color scale
var cScale = d3.scale.log()
.domain(in_out_degree_range)
.range([30, 0]);
var barPadding = 1;
slidersvg.selectAll(".r")
.data(total_degree)
.enter()
.append("rect")
.attr({
x: function(d, i) { return i* (controller_width/total_degree.length);},
y: function(d) { return controller_height - yScale(d);},
width: controller_width / total_degree.length - barPadding,
height: function(d) { return yScale(d);},
fill: "#a8a8a8",
stroke: "#a8a8a8"
});
/*
* TODO user clicks on timeline while animation running
* timeline goes to that point in time immediately
* without having to press start again
*/
var brushed = function() {
var extent = brush.extent();
var start = Math.floor(extent[0])
update_textbox(start);
// was trying to get this to be instantly brushable
// wasn't working out well
//current_time_step = start;
//d3.select(this).transition() // i think not working bc of how initialized
// .call(brush.extent(target_extent));
};
var brushended = function() {
console.log("c brushended");
var extent = brush.extent();
var start = Math.floor(extent[0])
var end = Math.floor(extent[1])
flow.duration = Math.min(end - start, 50);
flow.duration = Math.max(flow.duration, 3);
console.log(flow.duration);
// flow.time_interval = flow.animation_duration / flow.duration;
var target_extent = [start, start + flow.duration];
current_time_step = start;
d3.select(this).transition()
.call(brush.extent(target_extent));
// was trying to get this to be instantly brushable
// wasn't working out well, need refactor drawing
// to make it work well I think
// so draw has interface draw(start,stop,loop_start,loop_end)
// that sets up interval etc
// update_time_step(current_time_step);
};
// TODO look at doc and see if different events
// for center (ie drag click)
// vs extent / duration drag clicks
var brush = d3.svg.brush()
.x(controller_scale)
.extent(defaultExtent)
.on("brush", brushed)
.on("brushend", brushended);
// TODO replace with avg in and out degree
// summary plot
var gBrush = slidersvg.append("g")
.attr("class", "brush")
.call(brush)
.call(brush.event);
gBrush.selectAll("rect")
.attr("height", controller_height)
return brush;
};