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: old x axis labels were not destroyed during data update if parsing was set to false or an object with custom axis keys #9601

Closed
wants to merge 8 commits into from

Conversation

CatchABus
Copy link
Contributor

@CatchABus CatchABus commented Aug 30, 2021

When parsing was set to false or an object with xAxisKey or yAxisKey, there were issues if chart data was updated more than once.
Apparently, old x labels were not destroyed, resulting in merging old and new x labels.
This PR destroys old x labels every time data is updated, provided that chart has parsing set to false or an object with custom keys.

According to docs: https://www.chartjs.org/docs/next/general/data-structures.html, labels should only be set manually when importing primitive data so this does not break any kind of labels list set on chart initialization.

Fixes #9599

@CatchABus CatchABus marked this pull request as draft August 30, 2021 11:54
@CatchABus CatchABus closed this Aug 30, 2021
@CatchABus CatchABus reopened this Aug 30, 2021
@CatchABus CatchABus marked this pull request as ready for review August 30, 2021 16:20
@etimberg
Copy link
Member

etimberg commented Sep 2, 2021

Would definitely be good to have a test for this

@etimberg
Copy link
Member

Looks like this needs a rebase and the test being added.

@etimberg
Copy link
Member

Closing as stale

@etimberg etimberg closed this Oct 24, 2021
@CatchABus
Copy link
Contributor Author

CatchABus commented Oct 24, 2021

@etimberg I was too busy with my work these days but I was planning to update this one.
Is there any possibility of reopening this PR?

@etimberg
Copy link
Member

Yup, not a problem 😄

@@ -249,6 +249,69 @@ describe('Chart.DatasetController', function() {
expect(parsedYValues).toEqual([20, 30]);
});

it('should synchronize labels array with X values when chart existing dataset is updated and parsing is off', function() {
Copy link
Member

Choose a reason for hiding this comment

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

Does this case work properly when parsing is on, or should this fix actually apply in that case too?

Copy link
Contributor Author

@CatchABus CatchABus Nov 7, 2021

Choose a reason for hiding this comment

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

The bug occurs when parsing is off or has provided keys, that's why I target those 2 cases.

Copy link
Contributor Author

@CatchABus CatchABus Nov 7, 2021

Choose a reason for hiding this comment

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

@kurkle I totally missed this one but it seems issue occurs with parsing set to true as well.
Do you think I should add a 3rd test or maybe change test description to ...when parsing has no provided keys?

UPDATED: My bad. Not setting parsing inside tests defaults to false so I got confused. It seems bug does really NOT occur when parsing is set to true.

Copy link
Contributor Author

@CatchABus CatchABus Nov 7, 2021

Choose a reason for hiding this comment

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

After few more tests, it seems I get different results for parsing: true now and this case needs to be covered.
I'm not sure if there is any cache mechanism, but unit tests suddenly failed after few more attempts.
I marked PR as draft until I resolve this.

@CatchABus
Copy link
Contributor Author

@etimberg I added 2 new tests for this case. I made use of meta.iScale inside tests which I'm not sure if it's appropriate.
Please let me know if further improvements are needed.

@CatchABus CatchABus marked this pull request as draft November 7, 2021 21:45
@kurkle
Copy link
Member

kurkle commented Nov 29, 2021

Sorry @dimitrisrk for hijacking your fix, but we are getting eager to publish 3.6.1

@CatchABus
Copy link
Contributor Author

Sorry @dimitrisrk for hijacking your fix, but we are getting eager to publish 3.6.1

I'm the one who should apologize for my delay. It appears my approach did not cover all cases so I hit a dead end.
I'm glad that someone else will take care of this. Closing this PR in favor of #9921 . :)

@CatchABus CatchABus closed this Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: chart labels are not updated properly if parsing object data
3 participants