3 d3.custom.barChart = function module() {
9 }, width = 500, height = 500, gap = 0, ease = 'cubic-in-out';
10 var svg, duration = 500;
12 var dispatch = d3.dispatch('customHover');
13 function exports(_selection) {
15 .each(function(_data) {
17 var chartW = width - margin.left - margin.right, chartH = height
18 - margin.top - margin.bottom;
20 var x1 = d3.scale.ordinal().domain(
21 _data.map(function(d, i) {
23 })).rangeRoundBands([ 0, chartW ], .1);
25 var y1 = d3.scale.linear().domain(
26 [ 0, d3.max(_data, function(d, i) {
28 }) ]).range([ chartH, 0 ]);
30 var xAxis = d3.svg.axis().scale(x1).orient('bottom');
32 var yAxis = d3.svg.axis().scale(y1).orient('left');
34 var barW = chartW / _data.length;
37 svg = d3.select(this).append('svg').classed('chart',
39 var container = svg.append('g').classed(
40 'container-group', true);
41 container.append('g').classed('chart-group', true);
43 .classed('x-axis-group axis', true);
45 .classed('y-axis-group axis', true);
48 svg.transition().duration(duration).attr({
52 svg.select('.container-group').attr(
54 transform : 'translate(' + margin.left + ','
58 svg.select('.x-axis-group.axis').transition().duration(
59 duration).ease(ease).attr({
60 transform : 'translate(0,' + (chartH) + ')'
63 svg.select('.y-axis-group.axis').transition().duration(
64 duration).ease(ease).call(yAxis);
66 var gapSize = x1.rangeBand() / 100 * gap;
67 var barW = x1.rangeBand() - gapSize;
68 var bars = svg.select('.chart-group').selectAll('.bar')
70 bars.enter().append('rect').classed('bar', true).attr({
76 height : function(d, i) {
77 return chartH - y1(d);
79 }).on('mouseover', dispatch.customHover);
80 bars.transition().duration(duration).ease(ease).attr({
83 return x1(i) + gapSize / 2;
88 height : function(d, i) {
89 return chartH - y1(d);
92 bars.exit().transition().style({
100 exports.width = function(_x) {
101 if (!arguments.length)
103 width = parseInt(_x);
106 exports.height = function(_x) {
107 if (!arguments.length)
109 height = parseInt(_x);
113 exports.gap = function(_x) {
114 if (!arguments.length)
119 exports.ease = function(_x) {
120 if (!arguments.length)
125 d3.rebind(exports, dispatch, 'on');