Skip to content
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

fix datachart bug for single chart data #7020

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/js/components/DataChart/DataChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ const DataChart = forwardRef(
series.forEach(({ property, render }) => {
if (
!render &&
data.length > 1 &&
data.length >= 1 &&
Copy link
Collaborator

@jcfilben jcfilben Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data.length >= 1 &&
data.length > 1 &&

I think we should revert this change back. If we only have 1 data point we don't need the createDateFormat code

typeof data[0][property] === 'string'
) {
result[property] = createDateFormat(
Expand All @@ -547,7 +547,8 @@ const DataChart = forwardRef(
if (!property || (!horizontal && y) || (horizontal && !y)) {
if (render) return render(value);
} else {
const datum = data[axisValue];
// const datum = data[axisValue];
const datum = data[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change causes an issue with the axis labels. If we have the following code we end up with two xaxis labels that are the same value (Jun 23) coming from data[0].

const data = [
  { a: 1, b: 'one', c: 111111, d: '2020-06-24' },
  { a: 2, b: 'two', c: 222222, d: '2020-06-23' },
];

export const Simple = () => (
  <Box align="center" justify="start" pad="large">
    <DataChart
          data={data}
          series={['d', 'a']}
          axis={{
            x: { property: 'd' },
            y: { property: 'a' },
          }}
        />
  </Box>
);
Screen Shot 2023-11-20 at 12 32 56 PM

value = datum[property];
if (render) return render(value, datum, property);
}
Expand Down
10 changes: 8 additions & 2 deletions src/js/components/DataChart/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ export const createDateFormat = (firstValue, lastValue, full) => {
) {
const delta = Math.abs(endDate - startDate);
let options;
if (delta < 60000)
if (delta === 0)
// equal 0 - single data point
options = {
month: full ? 'short' : 'numeric',
day: 'numeric',
};
else if (delta < 60000)
Comment on lines +81 to +87
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (delta === 0)
// equal 0 - single data point
options = {
month: full ? 'short' : 'numeric',
day: 'numeric',
};
else if (delta < 60000)
if (delta < 60000)

Lets revert this change back, I don't think we need to adjust this

// less than 1 minute
options = full
? {
Expand All @@ -96,7 +102,7 @@ export const createDateFormat = (firstValue, lastValue, full) => {
else if (delta < 86400000)
// less than 1 day
options = { hour: 'numeric' };
else if (delta < 2592000000)
else if (delta < 2592000000 || delta === 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else if (delta < 2592000000 || delta === 0)
else if (delta < 2592000000)

Let's revert this change as well

// less than 30 days
options = {
month: full ? 'short' : 'numeric',
Expand Down