Skip to content

Commit

Permalink
#29 BARS!
Browse files Browse the repository at this point in the history
  • Loading branch information
constanthatz committed Feb 27, 2015
1 parent a942a91 commit 300aa31
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
13 changes: 6 additions & 7 deletions seattle/seattle/static/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ function groupedbar() {
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");

var incidentNames = d3.keys(data[0]).filter(function(key) { return key !== "type"; });
var incidentNames = d3.keys(compare_data[0]).filter(function(key) { return key !== "types"; });

compare_data.forEach(function(d) {
d.incidents = incidentNames.map(function(name) { return {name: name, value: +d[name]}; });
});


x0.domain(compare_data.map(function(d) { return d.State; }));
x0.domain(compare_data.map(function(d) { return d.types; }));
x1.domain(incidentNames).rangeRoundBands([0, x0.rangeBand()]);
y.domain([0, d3.max(compare_data, function(d) { return d3.max(d.incidents, function(d) { return d.value; }); })]);

Expand All @@ -162,19 +162,18 @@ function groupedbar() {
.style("text-anchor", "end")
.text("Incidents/Year");

var type = svg.selectAll(".type")
var types = svg.selectAll(".types")
.data(compare_data)
.enter().append("g")
.attr("class", "g")
// .attr("transform", function(d) { return "translate(" + x0(d.type) + ",0)"; });
.attr("transform", function(d) { return "translate(" + x0(d.types) + ",0)"; });

type.selectAll("rect")
types.selectAll("rect")
.data(function(d) { return d.incidents; })
.enter().append("rect")
.attr("width", x1.rangeBand())
.attr("x", function(d) { return x1(d.name); })
// .attr("y", function(d) { return y(d.name); })
.attr("transform", "translate(0," + height/2 + ")" )
.attr("y", function(d) { return y(d.value); })
.attr("height", function(d) { return height - y(d.value); })
.style("fill", function(d) { return color(d.name); });
}
Expand Down
7 changes: 6 additions & 1 deletion seattle/seattle/templates/index.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@

<section id='visualization'>
<!-- <h2>Visualize</h2> -->
<div class='graph'></div>
<div class='graph'></div>
</section>

<section id='visualization'>
<!-- <h2>Visualize</h2> -->
<div class='groupedbar'></div>
</section>


<!-- <section id='overview' class='pvl'> -->
<!-- <h2>Overview</h2> -->
Expand Down
2 changes: 1 addition & 1 deletion seattle/seattle/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def line_plot_lat_long_ajax(request):
temp = Incidents_Model.percentage(output[i])
output_percentages[incident_types[i]] = temp['string']
output_count[incident_types[i]] = temp['year_count']
output_compare.append({'type': incident_types[i], 'prior': temp['prior_rate'], 'oneyear': temp['year_count']})
output_compare.append({'types': incident_types[i], 'prior': temp['prior_rate'], 'oneyear': temp['year_count']})
# print '{} count: {}'.format(incident_types[i], temp['year_count'])

# Generate data for graph
Expand Down

0 comments on commit 300aa31

Please sign in to comment.