// Bar chart Module ///////////////////////////////// // Declare namespace d3.coolmodules = {}; // Declare component: (this outer function acts as the closure): d3.coolmodules.barChart = function module() { // Defaults values: var margin = {top: 10, right: 10, bottom: 20, left: 20}, width = 500, height = 300; function exports(_selection) { // create function to export _selection.each(function(_data) { // loop var test_data = _data.value; var rectW = (_data.row+2)*10, rectH = (_data.col+1)*10; // Select all bars and bind data: var bars = d3.select(this).selectAll(".bar") .data(test_data) .enter().append("rect"); //console.log(i+": "+JSON.stringify(_data.value)); // design svg elements bars.attr("class","bar") .attr({ 'width': rectH, 'x': function (d){ console.log(" log place1! "); return d.x * 10;}, 'y': function (d){ return d.y * 4;}, 'height': rectH*4}); console.log(" log place2! "); }); }// exports end // GETTERS AND SETTERS: exports.width = function(_x) { if (!arguments.length) return width; width = parseInt(_x); return this; }; exports.height = function(_x) { if (!arguments.length) return height; height = parseInt(_x); return this; }; return exports; };