Skip to content

Instantly share code, notes, and snippets.

@roundrobin
Created September 9, 2013 20:09
Show Gist options
  • Save roundrobin/6500819 to your computer and use it in GitHub Desktop.
Save roundrobin/6500819 to your computer and use it in GitHub Desktop.
RangePoints zickzack-layout
{"description":"RangePoints zickzack-layout","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/XwMhVzl.png"}
var nrOfEls = 16;
var columns = 4;
var height = 240;
var width = 420;
g.append("rect")
.attr({
width: width,
height: height,
fill: "#ddd"
});
var rangeOr = d3.range(nrOfEls);
var range = d3.range(Math.ceil(nrOfEls / columns));
var scaleOrdinal2 = d3.scale.ordinal().domain(rangeOr).rangePoints([0, height], 0.7);
var scaleOrdinal = d3.scale.ordinal().domain(range).rangePoints([0, height], 0.7);
var widthScale = d3.scale.ordinal().domain(d3.range(columns)).rangePoints([0, width], 0.7);
var color = "#133E8C";
var strokeColor = "#C88100";
var strokeWidth = 6;
var zIndex = 0;
var zIndex2 = 0;
var zIndex3 = 0;
var ySum = 0;
var selection = g.selectAll('.circleGroups')
.data(rangeOr)
.enter();
var circleGroup = selection.append("g")
.attr({
transform: function(d,i){
var x = 0;
var y = 0;
if(zIndex % columns === 0){
zIndex = 0;
}
zIndex++;
var x = widthScale(zIndex-1);
if(zIndex3 % columns === 0){
zIndex2++;
zIndex3 = 0;
}
zIndex3++;
var y = scaleOrdinal(zIndex2-1);
return "translate("+[x,y]+")";
},
"class": "group"
});
circleGroup.append("rect")
.attr({
width: 81,
height: 30,
fill: "#292C66"
});
selection.append("circle")
.attr({
r: Math.min(scaleOrdinal(0), widthScale(0)),
cx: function(d,i){
if(zIndex % columns === 0){
zIndex = 0;
}
zIndex++;
return widthScale(zIndex-1);
},
cy: function(d,i){
if(zIndex3 % columns === 0){
zIndex2++;
zIndex3 = 0;
}
zIndex3++;
return scaleOrdinal(zIndex2-1);
},
fill: color,
stroke: strokeColor,
"stroke-width": strokeWidth
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment