Created
July 10, 2014 06:37
-
-
Save gordonhatusupy/73c279e8b207e9f8543c to your computer and use it in GitHub Desktop.
Removing static elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d3.json(path, function(data){ | |
var data_altb = d3.entries(data); | |
// console.log(data_alt) | |
// Complexity Mean | |
mean = d3.mean(data_altb, function(d){ return d.value.parameters.complexity }) | |
// Get complexity extent | |
var complexity_ext = d3.extent(data_altb, function(d){ | |
return parseInt(d.value.parameters.complexity * 100); | |
}) | |
// Get max min values for coolness | |
var coolness_ext = d3.extent(data_altb, function(d){ | |
return parseInt(d.value.coolness); | |
}) | |
// Setup scale for coolness | |
var coolness_val = d3.scale.linear() | |
.domain([coolness_ext[0], coolness_ext[1]]) | |
.range([0, 100]) | |
var coolness_val_opacity = d3.scale.linear() | |
.domain([coolness_ext[0], coolness_ext[1]]) | |
.range([0, 1]) | |
// Setup colorscale for coolness | |
var coolness_color = d3.scale.linear() | |
.domain([coolness_ext[0], coolness_ext[1]]) | |
.range(['#f000ff', '#00fff0']) | |
// Set up scales | |
var xScale = d3.scale.linear() | |
.domain([complexity_ext[0], complexity_ext[1]]) | |
.range([padding, w_alt - padding]); | |
var avg_complexity = d3.select('#bubble_plot_altb') | |
avg_complexity.append('g') | |
.attr('id', 'average_complexityb') | |
.append('rect') | |
.attr('x', xScale(mean * 100)) | |
.attr('y', 50) | |
.attr('fill', '#ffffff') | |
.attr('height', '100') | |
.attr('width', '1') | |
.attr('opacity', 0.5) | |
d3.select('#average_complexityb') | |
.append('text') | |
.text(' ' + 'Average complexity:' + ' ' + parseFloat(mean * 100).toFixed(2)) | |
.attr('x', xScale(mean * 100) + 10) | |
.attr('y', 55) | |
.attr('fill', '#fff') | |
.attr('font-size', '12px') | |
var groups = d3.select('#bubble_plot_altb') | |
.selectAll('g') | |
.data(data_altb) | |
groups.enter() | |
.append('g') | |
.attr('transform', function(d, i){ | |
return 'translate(' + xScale(d.value.parameters.complexity * 100) + ',0)'; | |
}) | |
.append('circle') | |
groups.selectAll('circle') | |
.attr('r', function(d){ | |
radius_val = Math.sqrt(coolness_val(d.value.coolness) / Math.PI) | |
return radius_val | |
}) | |
.attr('fill', function(d){ return coolness_color(d.value.coolness)}) | |
.attr('cy', 100) | |
.attr('opacity', function(d){ return coolness_val_opacity(d.value.coolness) }) | |
groups.exit() | |
.remove(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment