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

[ Line Chart ] Line chart does not handle datapoints created with the Number constructor #3124

Closed
MatthieuRivaud opened this issue Aug 10, 2016 · 3 comments

Comments

@MatthieuRivaud
Copy link
Contributor

MatthieuRivaud commented Aug 10, 2016

Data points created with the Number constructor (ex: new Number(...)) : typeof (new Number()) yields "object", thus Chart.controllers.line.updateElement and Chart.Scale.getRightValue treat those values as { x: ..., y: ... } objects and skip them (because x and y are undefined).

If I hack those functions to consider ... instanceof Number the same as typeof ... === 'number', the data points are correctly displayed.

Should we try to handle this kind of (edge?) case ? Other chart types do seem to accept Number objects (tested a radar chart).

@etimberg
Copy link
Member

I think we should gracefully handle this case. I'm not sure why anyone would create a number using new Number but since it's valid JS we should at least try and support it if it is easy.

One thing we may also want to test is using Typed arrays for the data to the chart. I don't think we do any specific to check that the data array is an array (isArray will return false for a typed array) but we should add a test to prevent any regressions.

@MatthieuRivaud
Copy link
Contributor Author

Re: new Number() : I encountered the case with code that handled number sanitation on string representations of given numbers, and passed that to the Number constructor. (Javascript code generated from XSL). I replaced the call by just Number(...) (which gives a typeof = 'number' instead of an object).

Re: Typed arrays : I don't know if we have to specifically handle TypedArray data objects (as in transforming them into real arrays), but it could be nice to be able to take any typed array view as data. Most of the Array methods are also available on typed array views (or can be called with Array.prototype.XXX.apply), so it should be possible to work on typed arrays (as long as we don't try to add or delete items). With well-chosen helpers, it may not be too much of a pain.

Even though, it might be better to just ask for an Array object, or forcefully convert to Array from the start to avoid strange regressions. I don't really see a use case with so much data that copying into another array would be a no go.

@MatthieuRivaud MatthieuRivaud changed the title [ Line Chart ] Line chart does not handle datapoints created with then Number constructor [ Line Chart ] Line chart does not handle datapoints created with the Number constructor Aug 11, 2016
@simonbrunel simonbrunel added this to the Version 2.8 milestone Nov 29, 2018
@simonbrunel
Copy link
Member

simonbrunel commented Nov 29, 2018

Should be fixed by #5752.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants