plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

bar base attribute doesn't work on date axis

Open cldougl opened this issue 7 years ago • 8 comments

Using the base attribute with date data creates an incorrect range and doesn't apply base correctly: https://codepen.io/plotly/pen/JpvajW

cldougl avatar Feb 21 '18 16:02 cldougl

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 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
  • Make a new attribute like end (what's the other end called if the start is base?) to use instead of y to use when you want to specify absolute values for both ends of the bar rather than base+delta

alexcjohnson avatar Feb 21 '18 16:02 alexcjohnson

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.

cldougl avatar Feb 21 '18 17:02 cldougl

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.

FrankWessels avatar May 25 '18 07:05 FrankWessels

y is supposed to be the size of the bar, and base is 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:

image

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:

image

but still doesn't look right.

etpinard avatar Dec 05 '18 16:12 etpinard

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?

alexcjohnson avatar Dec 05 '18 16:12 alexcjohnson

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 avatar Jun 11 '24 17:06 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: Image However, just commenting out the base the axis works again as expected, but of course is lacking a bar start date: Image

jpjsonic avatar Oct 23 '24 04:10 jpjsonic

@gvwilson Is it possible for us to re-open this issue?

jpjsonic avatar Nov 07 '24 14:11 jpjsonic