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

Setting correct decimated values when below threshold #8883

Merged
merged 4 commits into from Apr 12, 2021

Conversation

Nico-DF
Copy link
Contributor

@Nico-DF Nico-DF commented Apr 12, 2021

Not a critical bug, but as one of the primary objectives of #8843 was to have real points when the graph allows it (especially when zooming), the correct data must be set when below the resolution threshold.

Currently, (when using zoom), if the scale contains fewer data than threshold, the algorithm will exit (not doing any decimation), and will then use the last _decimated data instead of data in the current range/the raw data if the dataset was small enough.

This commit aims to fix that.

@kurkle
Copy link
Member

kurkle commented Apr 12, 2021

I think it would be better to clear the decimated data in this case, because you'd expect the result to be same as it would be with the same amount of data originally, right?

@Nico-DF
Copy link
Contributor Author

Nico-DF commented Apr 12, 2021

Indeed, it makes sense, even if there is 1M+ data, given the current scale, if it is below threshold, it does not matter as the range will only display a fraction of it.
Was too focused on the current scope

In that case, I then need to also reset the data function and clear _data/_decimated? That would make sense

@kurkle
Copy link
Member

kurkle commented Apr 12, 2021

I think cleanDecimatedData(chart); does what is needed.

Edit: It does that for all datasets, I think it might be good to split the per dataset part out of that, or duplicate it, because in this case you'd want to process only the current dataset

@Nico-DF
Copy link
Contributor Author

Nico-DF commented Apr 12, 2021

Yep, on it

@Nico-DF
Copy link
Contributor Author

Nico-DF commented Apr 12, 2021

Btw, feel free to squash when accepting (or I can do it on my side if you want) if you deem the PR acceptable

@kurkle
Copy link
Member

kurkle commented Apr 12, 2021

You probably missed my edit on my last comment. I realized the clearDecimatedData function clears all datasets but in this case you'd want to clear the current one only, right?

We squash by default when merging, so no worries on that.

@Nico-DF
Copy link
Contributor Author

Nico-DF commented Apr 12, 2021

Whoopsie, didn't saw the edit, will do a simple refactor

kurkle
kurkle previously approved these changes Apr 12, 2021
Copy link
Member

@kurkle kurkle left a comment

Choose a reason for hiding this comment

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

Not sure if the change in the order is needed, but I don't think it makes any difference either in any (real) scenario.

@kurkle
Copy link
Member

kurkle commented Apr 12, 2021

Filename Size Change
dist/chart.esm.js 68.8 kB +14 B (0%)
dist/chart.js 87.5 kB +18 B (0%)
dist/chart.min.js 62.4 kB +15 B (0%)

@Nico-DF
Copy link
Contributor Author

Nico-DF commented Apr 12, 2021

Indeed, order was changed by my first commit where I relied on _decimated, now that I clean it, the inversion is not needed and will needlessly perform an allocation in some cases.

Want me to reorder?

(Btw, sry for the spam and back&forth)

@kurkle
Copy link
Member

kurkle commented Apr 12, 2021

Want me to reorder?

Its usually better to avoid unneeded changes. So if its not too much trouble, yes please :)

(Btw, sry for the spam and back&forth)

Does not bother me, I like it when things move and don't stall for long periods :)

@kurkle
Copy link
Member

kurkle commented Apr 12, 2021

Saves a byte too!

Filename Size Change
dist/chart.esm.js 68.8 kB +13 B (0%)
dist/chart.js 87.5 kB +17 B (0%)
dist/chart.min.js 62.4 kB +15 B (0%)

@kurkle kurkle requested a review from etimberg April 12, 2021 08:49
@etimberg etimberg merged commit 5a27de3 into chartjs:master Apr 12, 2021
@etimberg etimberg added this to the Version 3.2 milestone Apr 12, 2021
@Nico-DF Nico-DF deleted the bugfix/decimationThreshold branch April 12, 2021 13:47
@kurkle kurkle modified the milestones: Version 3.2, Version 3.1.1 Apr 17, 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.

None yet

3 participants