bar base attribute doesn't work on date axis
Using the base attribute with date data creates an incorrect range and doesn't apply base correctly: https://codepen.io/plotly/pen/JpvajW
Hmm yeah, we definitely shouldn't do what we're doing now (which it appears is converting to ms since 1970 and adding that on to the base date) but I don't think what you're expecting is consistent with how base works on other axis types. y is supposed to be the size of the bar, and base is where it starts. I suppose we could do either or both of:
- Allow specifying
yin milliseconds, and usebaseto determine the axis type - this almost works right now with explicit axis type, though it seems we make a timezone error - see https://codepen.io/alexcjohnson/pen/eVrPyr - Make a new attribute like
end(what's the other end called if the start isbase?) to use instead ofyto use when you want to specify absolute values for both ends of the bar rather than base+delta
got it -- you're right, I was expecting y to be treated as an 'end' rather than a 'delta'. In that case I think:
Allow specifying y in milliseconds, and use base to determine the axis type - this almost works right now with explicit axis type, though it seems we make a timezone error - see https://codepen.io/alexcjohnson/pen/eVrPyr
is a good method to document.
For the second option of adding an attribute, it might be an option to add a mode instead of a new array attribute where ymode: 'delta' | 'end'. This option would be useful for users creating gantt type charts.
Here another example of a problem caused by this issue:
https://codepen.io/etpinard/pen/MGdRKq?editors=1010
Might be helpful when solving? Note that when not specifying the xaxis type in this example, the graph is the same for everyone, no matter the timezone.
yis supposed to be the size of the bar, andbaseis where it starts.
On a similar topic, what should base do on category size axes? Right now,
Plotly.newPlot('graph', [{
type: 'bar',
x: ['a', 'b', 'c'],
base: -0.5
}])
it is completely off:
swapping d2c for d2l_noadd for category (and multicategory) axes here:
https://github.com/plotly/plotly.js/blob/7bb5daaaa118537ca01464d12cdbcef6f9cc764a/src/traces/bar/cross_trace_calc.js#L131
and
https://github.com/plotly/plotly.js/blob/7bb5daaaa118537ca01464d12cdbcef6f9cc764a/src/traces/bar/cross_trace_calc.js#L142
gives "better" results:

but still doesn't look right.
but still doesn't look right.
What would be "right"? Is there a use case here or should we just prohibit base+(multi)category during supplyDefaults?
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
@gvwilson I think this is still a pretty significant issue that's worth looking at. Fixing this unlocks really powerful charts like Gantt plots. Here's an example of a Gantt plot that I was trying to make:
const projectsData = [
{ project: "Website Speed", start_date: "2024-02-14", finish_date: "2024-03-07" },
{ project: "Database Migration", start_date: "2024-02-22", finish_date: "2024-03-05" },
{ project: "Bug Fix", start_date: "2024-02-12", finish_date: "2024-02-18" }
];
const trace = {
type: 'bar',
x: projectsData.map(d => d.finish_date),
y: projectsData.map(d => d.project),
orientation: 'h',
base: projectsData.map(d => d.start_date)
};
const layout = {
title: {
text: 'Project Duration Gantt Chart<br><sub>Visualizing the duration of each project over time</sub>',
},
xaxis: {
type: 'date',
},
yaxis: {
margin: {
l: 130
}
};
Plotly.newPlot('chart', [trace], layout);
If you leave the base in the chart you get really odd benavior on the xaxis just as everyone has said above:
However, just commenting out the base the axis works again as expected, but of course is lacking a bar start date:
@gvwilson Is it possible for us to re-open this issue?
