[ Launch Inlet ]
-
-
Save trtg/3895400 to your computer and use it in GitHub Desktop.
plotting bars in a zeo sleep graph with d3
This file contains hidden or 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
| {"endpoint":"","display":"svg","public":true,"require":[],"tab":"edit","display_percent":0.7,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01} |
This file contains hidden or 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
| var svg = d3.select("svg") | |
| var data1 = [4,4,2,3,3,3,2,2,2,1,1,1,4] | |
| var rects = svg.selectAll("rect") | |
| .data(data1) | |
| //var colorScale = d3.scale.category20(); | |
| //use zeo sleep graph colors | |
| //height also implicitly matches zeo | |
| var colorScale = d3.scale.ordinal() | |
| .domain([1,2,3,4]) | |
| .range([ | |
| "#00552A", | |
| "#99989B", | |
| "#29A639", | |
| "#D05827" | |
| ]) | |
| rects.enter() | |
| .append("rect") | |
| .attr({ | |
| width:21, | |
| height:function(d){ | |
| return d*20 | |
| }, | |
| y: function(d){return 97-d*20}, | |
| x:function(d,i){return i*22+115;}, | |
| fill: function(d,i){return colorScale(d);}, | |
| id: function(d,i){ | |
| return "rect"+i | |
| } | |
| }).on("mouseover",function(d,i){ | |
| d3.select("#rect"+i).attr({stroke:"#000"}) | |
| }).on("mouseout",function(d,i){ | |
| d3.select("#rect"+i).attr({stroke:"none"}) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment