forio / contour

Apache License 2.0
120 stars 21 forks source link

xAxis last tick disappear when rendered twice #220

Closed senluchen2015 closed 8 years ago

senluchen2015 commented 9 years ago

When a chart is rendered twice, depending on the data, the last tick might not appear. Currently, it seems that calling cartesian() again before all render() will solve the problem.

screen shot 2015-09-21 at 4 07 03 pm screen shot 2015-09-21 at 4 06 50 pm
drosen0 commented 9 years ago

In theory, you should be able to call render() a second time immediately, and I believe it does work in some browsers. I think in this case, d3 doesn't complete the transition when a second transition is started on the same element. There's a related issue with Contour tooltips not always fading out completely.

Instead of calling cartesian() a second time, which you're not really supposed to do, I'd bet calling setData(data) before the second render() would work as well. Other ways you could work around this are to organize your code so you render() only once, or delay the second render().

senluchen2015 commented 9 years ago

Trying the delays and setData didn't work. Further looking into this issue, I realized that the reason cartesian() works is because it reset the xScale to undefined. The actual issue comes from the "LinearScale" function "scale".

LinearScale.prototype = {
    init: function() {
        delete this._scale;
    },
    /*jshint eqnull:true*/
    scale: function(domain) {
    this._domain = domain ? this._getAxisDomain(domain) : this._getAxisDomain(this.data);
    if (!this._scale) {
        this._scale = d3.scale.linear().domain(this._domain);
        // this is currently missing in the else so that calling render the second time wont make the scale "nice"
        if (this.options.xAxis.min == null && this.options.xAxis.max == null) this._scale.nice();
    } else {
        this._scale.domain(this._domain);
    }
    this._setRange();
    return this._scale;
},

The missing "this._scale.nice()" in the else statement is causing the last "nice" tick to disappear. If we add "this._scale.nice()" to the else statement then the ticks won't disappear after rendering twice. Should we add this in?

drosen0 commented 9 years ago

Good find!

drosen0 commented 8 years ago

Fixed with #222.