Skip to content

Commit

Permalink
latest plywood
Browse files Browse the repository at this point in the history
  • Loading branch information
vogievetsky committed Nov 11, 2015
1 parent 60fe38c commit 8ee25bc
Show file tree
Hide file tree
Showing 2 changed files with 1,395 additions and 849 deletions.
29 changes: 16 additions & 13 deletions plywood.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
return "translate(" + x + "," + y + ")";
}

var dayQuarters = ['midnight - 6am', '6am - noon', 'noon - 6pm', '6pm - midnight']
var timeOfDayLabels = ['midnight - 6am', '6am - noon', 'noon - 6pm', '6pm - midnight']

var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
Expand Down Expand Up @@ -85,22 +85,25 @@
upgradeTime(flatData, 'time');


var stateByDayQuarter = $('wiki')
var stateByTimeOfDay = $('wiki')
.filter('$regionName != null')
.split('$regionName', 'State')
.apply('Edits', '$wiki.count()')
.sort('$Edits', 'descending')
.limit(5)
.apply('DayQuarters',
$('wiki').split('$dayQuarter', 'DayQuarter')
.apply('TimesOfDay',
$('wiki').split('$dayQuarter', 'TimeOfDay')
.apply('Edits', '$wiki.count()')
.sort('$DayQuarter', 'ascending')
.sort('$TimeOfDay', 'ascending')
)


stateByDayQuarter.compute({ wiki: Dataset.fromJS(flatData) }).then(function(dataset) {
stateByTimeOfDay.compute({ wiki: Dataset.fromJS(flatData) }).then(function(dataset) {
var data = dataset.toJS();

// Let's have a look at what we have here.
console.log(JSON.stringify(data, null, 2));

var hours = [0, 1, 2, 3];

x0.domain(data.map(function(d) { return d.State; }));
Expand All @@ -109,7 +112,7 @@
y.domain([
0,
d3.max(data, function(d) {
return d3.max(d.DayQuarters, function(d) { return d.Edits; });
return d3.max(d.TimesOfDay, function(d) { return d.Edits; });
})
]);

Expand Down Expand Up @@ -140,17 +143,17 @@
states.exit().remove();

// Within each <g> make a <rect> for the hours
var hoursOfDay = states.selectAll(".day-quarter")
.data(function(d) { return d.DayQuarters; }); // Split on day quarter
var hoursOfDay = states.selectAll(".time-of-day")
.data(function(d) { return d.TimesOfDay; }); // Split on day quarter

hoursOfDay.enter().append("rect").attr('class', 'day-quarter');
hoursOfDay.enter().append("rect").attr('class', 'time-of-day');

hoursOfDay
.attr("width", x1.rangeBand())
.attr("x", function(d) { return x1(d.DayQuarter); })
.attr("x", function(d) { return x1(d.TimeOfDay); })
.attr("y", function(d) { return y(d.Edits); })
.attr("height", function(d) { return height - y(d.Edits); })
.style("fill", function(d) { return color(d.DayQuarter); });
.style("fill", function(d) { return color(d.TimeOfDay); });

hoursOfDay.exit().remove();

Expand All @@ -172,7 +175,7 @@
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return dayQuarters[d]; });
.text(function(d) { return timeOfDayLabels[d]; });

}).done();
});
Expand Down
Loading

0 comments on commit 8ee25bc

Please sign in to comment.