Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Created January 20, 2015 21:38
Show Gist options
  • Save ramnathv/c149a580479c5300e615 to your computer and use it in GitHub Desktop.
Save ramnathv/c149a580479c5300e615 to your computer and use it in GitHub Desktop.
Tributary inlet
{"description":"Tributary inlet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"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}
var data = [[4, 29], [9, 51], [10, 16], [70, 83]]
/*
var createAccessors = function(visExport) {
for (var n in visExport.opts) {
if (!visExport.opts.hasOwnProperty(n)) continue;
visExport[n] = (function(n) {
return function(v) {
return arguments.length ? (visExport.opts[n] = v, this) : visExport.opts[n];
}
})(n);
}
};
*/
var Chart = function module(){
var opts = {
w: 600,
h: 400,
margin: {top: 20, bottom: 20, left: 20, right: 20},
x: function(d, i){return d[0]},
y: function(d, i){return d[1]}
}
opts.W = opts.w - opts.margin.left - opts.margin.right
opts.H = opts.h - opts.margin.top - opts.margin.bottom
var xScale = d3.scale.linear().range([0, opts.W]),
yScale = d3.scale.linear().range([opts.H, 0])
function exports(selection){
selection.each(function(data){
opts.x.domain(d3.extent(data, function(d){return d[0]}))
opts.y.domain(d3.extent(data, function(d){return d[1]}))
var svg = d3.select(this)
.attr("width", opts.W)
.attr("heigth", opts.H)
.append("g")
.attr("transform", "translate(" + opts.margin.left + "," +
opts.margin.top + ","
)
var line = d3.svg.line()
.x(function(d, i){return xScale(d[0])})
.y(function(d, i){return yScale(d[1])})
svg.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line)
})
}
exports.opts = opts;
//createAccessors(exports, opts);
console.log(exports)
return exports;
}
Chart()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment