Skip to content

Restyling a date axis with timestamp data changes axis type to numeric #2144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jdugge opened this issue Nov 6, 2017 · 8 comments
Closed
Labels
regression this used to work

Comments

@jdugge
Copy link
Contributor

jdugge commented Nov 6, 2017

Starting with Plotly.js 1.31.0, restyling a plot using timestamps instead of date strings turns the axis from a date axis to a numeric axis, even if the original data was in the same format, as can be seen in this codepen. In 1.30.0, this didn't happen.

var trace1 = {
  x: [1509583143188, 1510187943188], 
  y: [1, 2]
};

var data = [ trace1];

var layout = {
  title:'Line and Scatter Plot',
  xaxis: { type: 'date'}
};

Plotly.newPlot('myDiv', data, layout);

// Restyling with the same data turns the axis from date to numeric type
Plotly.restyle('myDiv', {x: [[1509441408043, 1510046208043]], y: [[1, 2]]})
@jdugge jdugge changed the title Restyling a date axis with timestamp data Restyling a date axis with timestamp data changes axis type to numeric Nov 6, 2017
@etpinard
Copy link
Contributor

Side-effect of #1999, thanks for the report.

@etpinard etpinard added the regression this used to work label Nov 13, 2017
@jdugge
Copy link
Contributor Author

jdugge commented Jan 23, 2018

I'd like to take a shot at fixing this behaviour, but I'm not sure where the best place to tackle this would be.

  • Somehow check in the clearAxisTypes function whether the axis type was set by the user. This seems like a good place to do it, because there's alread a check for whether the axis type is log, from which we infer that the axis type must have been manually set. I don't know how to check whether an axis type was manually set, though.
  • When manually setting an axis when calling newPlot, relayout or update, the clearAxisTypes flag in in the trace attributes could be removed. However, I think the the trace attributes are global to all traces of the same type, so it wouldn't be possible to have the axis type fixed for traces on only one axis.
  • Provide a mechanism for overriding the clearAxisTypes behaviour when calling restyle. This doesn't feel right, though, because it doesn't reinstate the old behaviour and because the restyle function doesn't take any parameters that could be used for this.

@etpinard
Copy link
Contributor

I think the cleanest way to fix this would be to wait for ax.autotype proposed in #2234

But since this ticket signals a regression, perhaps we should try to make a quick (albeit temporary) fix. In this case, your first bullet point seems like the best solution.

@s31tz
Copy link

s31tz commented Jul 2, 2020

I want to update timeseries data and observe the same problem in v1.54.5. Is there a workaround?

@s31tz
Copy link

s31tz commented Jul 3, 2020

I found a workaround: deleteTraces() + addTraces() instead of restyle(). Downside: The trace must be completely defined.

@nikita-zamaraev-loginom
Copy link

nikita-zamaraev-loginom commented Sep 13, 2021

When clearing the data of the first trace, the display breaks. codepen.io#Plotly.js axis.type discard error

js source code
var trace1 = {
    name: "trace1",
    x: [new Date('2020-10-04'), new Date('2021-11-04'), new Date('2023-12-04')],
    y: [90, 40, 60],
    type: 'scatter'
};

var trace2 = {
    name: "trace2",
    x: [new Date('2020-10-04'), new Date('2021-11-04'), new Date('2023-12-04')],
    y: [80, 50, 40],
    type: 'scatter'
};

var layout = {
    showlegend: true,
    xaxis: {
        type: "date" // Explicitly
    }
};

Plotly.newPlot('myDiv', [trace1, trace2], layout);

setTimeout(function () { 
    // Then I want to leave the legend1. But hide the trace1
    Plotly.restyle('myDiv', { x: [[null]], y: [[null]] }, [0]); // this doesn't work
    //Plotly.restyle('myDiv', { x: [[null]], y: [[null]] }, [1]); // it works
}, 2000);

@gvwilson
Copy link
Contributor

Hi - this issue has been sitting for a while, so as part of our effort to tidy up our public repositories I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our stack. Cheers - @gvwilson

@bparsons5
Copy link

Unfortunately, I am still getting this exact issue. plotly.js v2.35.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression this used to work
Projects
None yet
Development

No branches or pull requests

6 participants