javascript - Transition on axis -- losing grid lines (ticksize), how to transition in correct order? -


i've got horizontal bar graph transition on x-axis. looks how want, almost.

sadly, red gridlines (ticksize(-h)) in back. need bring them front.

code here: http://bl.ocks.org/greencracker/1cb506e7375a2d825e24

i'm new transitions , suspect i'm calling in wrong order.

any suggestions on gridlines front and/or suggestions how dry code? not dry, i'm starting easy baby steps. key parts:

d3.csv("georgia_counties_vmt.csv", function(input) {     data = input;     data.foreach(function(d) { d.value = +d.value; });     data.foreach(function (d) {d.n1 = +d.n1; })     data.sort(function(a, b) { return b.value - a.value; });      x.domain([0, d3.max(data, function(d) { return d.value; })]);     y.domain(data.map(function(d) { return d.name; }));      initaxes(); // draws tiny axes transition proper size     change(); // calls redraw()  // skip some, then:   function redraw() {      // unrelated bar drawing stuff here:      //calls regular-size axes     svg.selectall("g.y_axis").call(yaxis)     svg.selectall("g.x_axis").call(xaxis)  }   function initaxes() // initializes axes range @ [0,1] {    var initxscale = d3.scale.linear()       .range([0, 1])       .domain([0, d3.max(data, function(d) { return d.value; })]);     var initxaxis = d3.svg.axis()       .scale(initxscale)       .ticksize(-h)       .orient("top");    svg.append("g")      .attr("class", "x_axis")      .call(initxaxis);      var inityscale = d3.scale.ordinal()    .rangebands([0, 1], 0.1)    .domain(data.map(function(d) { return d.name; }));   var inityaxis = d3.svg.axis()     .scale(inityscale)     .orient("left")     .ticksize(0);    svg.append("g")     .attr("class", "y_axis")     .call(inityaxis);   }  

this because missed initializing bars before initializing axis, can add init bars code before initaxes() , keep other codes no change.

d3.csv("georgia_counties_vmt.csv", function(input) {    ...   y.domain(data.map(function(d) { return d.name; }));    initbars(); // init bars before init axes   initaxes();   change();    }); // close d3.csv ...  ...  // new added function init bars function initbars() {   var bar = svg.selectall("g.bar")       .data(data)       .attr("class", "bar");    var barenter = bar.enter().append("g")     .attr("class", "bar")     .attr("transform", function (d) {return "translate(0," + (d.y0 = (y(d.name))) +")" ;});    barenter.append("rect")     .attr("width", 0)     .attr("height", y.rangeband()/2); } 

enter image description here


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -