Shopify/polaris-viz

Update the order of our data points

Closed this issue · 4 comments

Feature request summary

Update the order of our data points in Polaris Viz. The primary data point should always come first within a graph, tooltip and legend. The comparison should be secondary. The time frame for the x-axis should use the time frame that covers both data points.

Rationale

The comparison line in Polaris Viz is ordered first in the line series for our data viz and affects the order in our legends and tooltips. The primary line should come before the comparison.

Screen Shot 2022-10-25 at 11 35 40 AM

Because of this, when the data for today is viewed, the chart plots the x-axis time based on the comparison line (first in its series). This means you get the full scope of today's time. Whereas, if the primary line came first, the time in the x-axis only goes up to the current time of today.

image

In our report view, the primary line comes before the comparison, but it seems like there was a workaround to make sure the entire timeframe of the day gets plotted by adding zero values for the remainder of the time we haven't reached yet. This should not be the case as the data technically isn't at zero.

image

In addition to this, our bar charts also show the comparison bar before the primary bar. The primary data should always take precedence over the comparison and be ordered first. It's also confusing that the legend is showing the primary bar first.

image

cc @blboyle @mirualves @adamperron

🌟 Feature requests that are not yet planned will be closed. We then use the issue’s 👍 upvotes to track and set priorities. See the contribution guidelines for more information.

envex commented

Hello!

polaris-viz renders the data in the order it’s provided. If you want the comparison data to render after the other data, it needs to come last in the data array.

const DATA = [
  {
    name: 'Apr 1 – Apr 14, 2020',
    data: [
      {value: 333, key: '2020-04-01T12:00:00'},
    ],
  },
  {
    name: 'Previous month',
    data: [
      {value: 709, key: '2020-03-02T12:00:00'},
    ],
    isComparison: true,
  },
];

@envex

Let me know if you see this, but this is the issue that we were running into with the ordering of series.

https://codesandbox.io/s/agitated-tu-ygfn6n?file=/src/App.js

Screenshot Screen Shot 2022-10-26 at 2 51 02 PM

When the shorter-length series is first, the x-axis only goes to its length.

envex commented

Right, I see what you mean.

We currently don't account for data that has mismatched lengths of data points, so we'd have to check which has the longer series and use those for the labels.

envex commented

Fixed in #1411