index.html
<div id="vis"></div>
_.md
[ <a href="http://tributary.io/inlet/de93dc352da97129abbf">Launch: Tributary inlet</a> ] de93dc352da97129abbf by rickdg<br>
config.json
{"description":"Tributary inlet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"index.html":{"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,"ajax-caching":true}
inlet.js
d3.chart("CircleChart", {
initialize : function() {
this.xScale = d3.scale.linear();
this._width = this._width || this.base.attr("width") || 200;
this._height = this._height || this.base.attr("height") || 100;
this._radius = this._radius || 5;
var circleLayerBase = this.base.append("g")
.classed("circles", true);
this.layer("circles", circleLayerBase, {
dataBind: function(data) {
var chart = this.chart();
chart.xScale.domain([data[0], data[data.length-1]]);
return this.selectAll("circle")
.data(data);
},
insert: function() {
var chart = this.chart();
return this.append("circle")
.attr("r", chart.radius())
.attr("cy", chart.height()/2);
},
events: {
enter: function() {
var chart = this.chart();
return this.attr("cx", function(d) {
return chart.xScale(d)
});
}
}
});
},
width: function(newWidth) {
if (arguments.length === 0) {
return this._width;
}
this._width = newWidth;
this.base.attr("width", this._width);
this.xScale.range([this.radius(), this._width - this.radius()]);
return this;
},
height: function(newHeight) {
if (arguments.length === 0) {
return this._height;
}
this._height = newHeight;
this.base.attr("height", this._height);
return this;
},
radius: function(newRadius) {
if (arguments.length === 0) {
return this._radius;
}
this._radius = newRadius;
return this;
}
});
d3.chart("CircleChart").extend("HoverableCircleChart", {
initialize: function() {
this.layer("circles").on("enter", function() {
var chart = this.chart();
this.on("mouseover", function() {
var el = d3.select(this);
el.style("fill", "blue");
chart.trigger("brush", this);
}).on("mouseout", function() {
var el = d3.select(this);
el.style("fill", "");
});
});
}
});
var circleChart = d3.select("div#vis")
.append("svg")
.chart("HoverableCircleChart")
.width(200)
.height(50)
.radius(5);
circleChart.draw([1,4,6,9,12,13,30]);