D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
michalskop
Full window
Github gist
Inner circles seem bigger than outer rings (experiment)
<!DOCTYPE html> <meta charset="utf-8"> <style> body { font: 10px sans-serif; } .axis path, .axis line { fill: none; stroke: #000; shape-rendering: crispEdges; } .x.axis path { display: none; } .line { fill: none; stroke: #bbb; stroke-width: 1px; } .line.active { stroke-width: 5px; stroke: #444 } .group-2 { fill: none; stroke: #aac; stroke-width: 1px; } .group-2.active { stroke-width: 5px; stroke: #335; } .zeroline { fill: none; stroke: red; stroke-width: 3px; } .point { fill: white; stroke: #222; } .point.active { fill: #222; } .average { fill: orange; stroke: orange; fill-opacity: .6; stroke-width: 1.5px; stroke-opacity: 1; } .average.active { fill-opacity: 1; } .stimuli { fill: white; stroke: #000; } .stimuli.active { stroke: green; } </style> <body> <h1>How we perceive smaller the areas of the (colourful) rings than of their inner (white) circles</h1> <div id="chart"></div> <script src="https://d3js.org/d3.v3.js"></script> <script> var realvalues = {S: 0.075, A: 0.359, D: 0.676, F: 0.984} var averages = {S: 0, A: 0, D: 0, F: 0} var margin = {top: 20, right: 20, bottom: 30, left: 50}, width = 960 - margin.left - margin.right, height = 400 - margin.top - margin.bottom; var x = d3.scale.linear() .range([0, width]) .domain([0,1]); var y = d3.scale.linear() .range([height, 0]) .domain([-0.5,0.7]); var xAxis = d3.svg.axis() .scale(x) .orient("bottom"); var yAxis = d3.svg.axis() .scale(y) .orient("left"); var svg = d3.select("#chart").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + height + ")") .call(xAxis) .append("text") .attr("x", x(1)) .attr("dx", ".71em") .style("text-anchor", "end") .text("Real values of percentage of colour"); svg.append("g") .attr("class", "y axis") .call(yAxis) .append("text") .attr("transform", "rotate(-90)") .attr("y", 6) .attr("dy", ".71em") .style("text-anchor", "end") .text("Errors of Estimates"); var line = d3.svg.line() .x( function(d) { return d[0]; }) .y(function(d) { return d[1]; }); zeroline = Array([x(0),y(0)],[x(1),y(0)]); svg.append("path") .datum(zeroline) .attr("class", "zeroline") .attr("d", line) stimuli = function(rate) { R = 30; irate = 1-rate; q = R*(1-Math.sqrt(irate)) r = R - q/2; return Array(r,q); } d3.csv("ex1.csv", function(error, data) { /*data.forEach(function(d) { d.S = +d.S d.A = +d.A; });*/ //realvalues.forEach(function(realval,index) { points = Array(); data.forEach(function(d) { rdata = Array(); for (i in realvalues) { xx = realvalues[i] + Math.random()/50-0.01; yy = +d[i]/100-realvalues[i]; rdata.push([x(xx),y(yy)]); points.push([xx,yy]); averages[i] += yy; } svg.append("path") .datum(rdata) .attr("class", function() {if (d.group == "2") return "group-2"; else return "line"}) .attr("d", line) .attr("title",d.name) .on("mouseover", function() { d3.select(this) .classed("active", true ) // should then accept fill from CSS }) .on("mouseout", function() { d3.select(this) .classed("active", false) }); }); svg.selectAll('circle') .data(points) .enter().append('circle') .attr("cx", function(d) {return x(d[0]) }) .attr("cy", function(d) {return y(d[1]) }) .attr("r", 3) .attr("class", "point") .attr("title",function(d) {return "Error of colour estimate: " + Math.round(d[1]*1000)/10 + "% (percentage points)"}) .on("mouseover", function() { d3.select(this) .classed("active", true ) }) .on("mouseout", function() { d3.select(this) .classed("active", false) }); for(i in averages) { svg.append('circle') .attr("cx", x(realvalues[i])) .attr("cy", y(averages[i]/points.length*4)) .attr("r", 10) .attr("class","average") .attr("title","Average of error of colour estimate: " + (Math.round(averages[i]/points.length*4*1000)/10) + "% (percentage points)") .on("mouseover", function() { d3.select(this) .classed("active", true ) }) .on("mouseout", function() { d3.select(this) .classed("active", false) }); st = stimuli(realvalues[i]); svg.append('circle') .attr("cx", x(realvalues[i])) .attr("cy", y(0.5)) .attr("r",st[0]) .attr("stroke-width",st[1]) .attr("class","stimuli") .attr("title","Real percentage of colour: " + (Math.round(realvalues[i]*1000)/10) + "%") .on("mouseover", function() { d3.select(this) .classed("active", true ) }) .on("mouseout", function() { d3.select(this) .classed("active", false) }); } }); </script> <p>Estimates of <strong>percentage of colour in the 4 circles above</strong> (i.e., number of black pixels vs. number of black and white pixels). Experiment on 45 university students.</p> <p>The values on x-axis are slightly randomly moved, so the overlapted points may be visible.</p> </p>(<em>One group was asked about the percentage of black, the other about white - no significant difference</em>)</p> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-8592359-13', 'ocks.org'); ga('send', 'pageview'); </script> </body>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js