// Generated by CoffeeScript 1.4.0 (function() { var color_scale, height, subbar_on_mouseout, subbar_on_mouseover, vis, width, x; window.bar = {}; bar.dispatcher = d3.dispatch('focus', 'blur'); vis = null; width = null; height = null; x = d3.scale.linear(); color_scale = d3.scale.category10(); bar.init = function(v, w, h) { vis = v; width = w; height = h; return x.range([0, width]); }; bar.update = function(data) { var subbars; x.domain([0, d3.sum(data)]); subbars = vis.selectAll('.subbar').data(data); subbars.enter().append('rect').attr({ "class": 'subbar datapoint', fill: function(d, i) { return color_scale(i); }, y: 0, height: height }).on('mouseover', subbar_on_mouseover).on('mouseout', subbar_on_mouseout); subbars.attr({ x: function(d, i) { return x(d3.sum(data.slice(0, i))); }, width: function(d) { return x(d); } }); return subbars.exit().remove(); }; subbar_on_mouseover = function(d, i) { return bar.dispatcher.focus(i); }; subbar_on_mouseout = function(d, i) { return bar.dispatcher.blur(i); }; bar.focus = function(i) { return vis.select(".subbar:nth-of-type(" + (i + 1) + ")").classed('focus', true); }; bar.blur = function(i) { return vis.select(".subbar:nth-of-type(" + (i + 1) + ")").classed('focus', false); }; }).call(this);