Simple-charts icon indicating copy to clipboard operation
Simple-charts copied to clipboard

Automatically dropping x axis

Open giacomobg opened this issue 3 years ago • 1 comments

I came across unexpected behaviour in the Line template, I had an axis that did not start at 0 and the x axis moved off the chart and out of the margin as a result.

I found it was caused by this code

//create x axis, if y axis doesn't start at 0 drop x axis accordingly

svg.append('g')   
  .attr('class', 'x axis')  
  .attr('transform', function(d){
    if(yDomain[0] != 0){
      return 'translate(0,' + (height + 30) + ')'
        } else {
          return 'translate(0,' + height  + ')'
        }
      })
  .call(xAxis);`

As you can see the axis gets moved downwards by 30 pixels if the x scale does not start at 0. Is there a time when this functionality is necessary? It was not in my case and I feel like it will cause more unexpected bugs than help? Can always add a variable to the config if we want to make it easy to move the x axis down by a certain number of pixels.

giacomobg avatar Apr 15 '21 14:04 giacomobg