Skip to content

Commit c383945

Browse files
author
Allen Chang
committed
Merge pull request #162 from wafers/wt-animateGraph
Animate graphs
2 parents cfffa1e + a39b67a commit c383945

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

client/app/results/details.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function(Graph, ModulePass, $showdown, $scope, $rootScope, $stateParams, Search)
77
$scope.dlForm = {
88
barWidth: 5,
99
maPeriod: 100,
10-
startDate: moment().subtract(3, 'years').toDate(),
10+
startDate: moment('01 01 2009').toDate(),
1111
endDate: moment().toDate(),
1212
filter: 'all'
1313
}
@@ -37,7 +37,7 @@ function(Graph, ModulePass, $showdown, $scope, $rootScope, $stateParams, Search)
3737
// Draw the version graph
3838
var options = _.pick(this.dlForm, 'startDate', 'endDate');
3939
options['width'] = width;
40-
Graph.lineGraph(this.module, options);
40+
Graph.versionGraph(this.module, options);
4141
}
4242
else if(type === 'dependency'){
4343
// Draw the dependency graph

client/app/results/services.js

+35-10
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ angular.module('app')
365365
})(index);
366366
}
367367

368-
this.lineGraph = function(module, options){
368+
this.versionGraph = function(module, options){
369369
var width = options.width - margin.left - margin.right;
370370

371371
var dataStore = module.time;
@@ -479,11 +479,19 @@ angular.module('app')
479479
// Position circle at correct y-position
480480
.attr("cy", function(d){return height - d.majorVersion*100})
481481
// Size and color of circle based on update 'importance'
482-
.attr("r", function(d){return (d.majorVersion+1) > 0 ? (d.majorVersion+5) : 5})
482+
.attr("r", function(d){return 0})
483483
.attr("fill", function(d) {return '#'+colorScale(d.majorVersion)})
484484
.attr("opacity", 0.7)
485485
.on('mouseover', tip.show)
486486
.on('mouseout', tip.hide)
487+
488+
var transit = d3.select('#graph-container').select('svg')
489+
.selectAll('circle')
490+
.data(data)
491+
.transition()
492+
.duration(1000)
493+
.attr("r", function(d){return (d.majorVersion+1) > 0 ? (d.majorVersion+5) : 5})
494+
487495
}
488496

489497
// Render the download graph
@@ -584,15 +592,32 @@ angular.module('app')
584592
.enter().append("rect")
585593
.attr("class", "bar")
586594
.attr("x", function(d) { return x(dateFormat.parse(d.day)); })
587-
.attr("y", function(d) { return y(d.count); })
588-
.attr("height", function(d) { return height - y(d.count); })
595+
.attr("y", function(d) { return height; })
596+
.attr("height", function(d) { return 0 })
589597
.attr("width", options.barWidth)
590-
591-
chart.append('path')
592-
.attr("class", "moving-average")
593-
.attr('d', line(data))
594-
.attr('fill-opacity', 0)
595-
// });
598+
599+
var transit = d3.select('#graph-container').select('svg')
600+
.selectAll('rect')
601+
.data(data)
602+
.transition()
603+
.duration(1000)
604+
.attr("y", function(d) { return y(d.count); })
605+
.attr("height", function(d) { return height - y(d.count); })
606+
607+
setTimeout(function(){
608+
var path = chart.append('path')
609+
.attr("class", "moving-average")
610+
.attr('d', line(data))
611+
.attr('fill', 'none')
612+
613+
var totalLength = path.node().getTotalLength();
614+
615+
path.attr('stroke-dasharray', totalLength + ' ' + totalLength)
616+
.attr('stroke-dashoffset', totalLength)
617+
.transition()
618+
.duration(2000)
619+
.ease('linear')
620+
.attr('stroke-dashoffset', 0);}, 500)
596621

597622
function type(d) {
598623
d.count = +d.count; // coerce to number

0 commit comments

Comments
 (0)