-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
isObject returns false given Date object #4538
Comments
That's the expected behavior |
Ok. I can't change the code in #4533 as suggested then. Originally:
Suggested to change to:
Which won't work since |
I suggested that actually (in if (helpers.isObject(rawValue)) {
if (me.isHorizontal()) {
if (rawValue.x !== undefined) {
return me.getRightValue(rawValue.x);
}
} else if (rawValue.y !== undefined) {
return me.getRightValue(rawValue.y);
}
}
return rawValue; |
I was referring to the comment in #4533 (comment) |
And in getRightValue: function(rawValue) {
if (helpers.isObject(rawValue) && rawValue.t !== undefined) {
return this.getRightValue(rawValue.t);
}
return Chart.Scale.prototype.getRightValue.call(this, rawValue);
} which could even be simpler: getRightValue: function(rawValue) {
if (rawValue && rawValue.t !== undefined) {
return this.getRightValue(rawValue.t);
}
return Chart.Scale.prototype.getRightValue.call(this, rawValue);
} |
Actually, you don't even need to test if |
What about the check for date types? I don't think I can use exactly the code above since it doesn't have that check?
|
Why you need to test it since what you want is |
If you really want to check Date and moment, then this should work: getRightValue: function(rawValue) {
if ((rawValue instanceof Date) || (rawValue instanceof moment)) {
return rawValue;
}
if (rawValue && rawValue.t !== undefined) {
return this.getRightValue(rawValue.t);
}
return Chart.Scale.prototype.getRightValue.call(this, rawValue);
} |
And I think you can even replace the |
yeah, I guess you're right. I probably don't really need to check Date and moment. I figured there was some need to since the code was doing that originally, but as far as I can tell it's not required |
@benmccann after reading again the original implementation, I think my version is not fully correct: it should return // core.scale.js
getRightValue: function(rawValue) {
if (typeof(rawValue) === 'number' && isFinite(rawValue)) {
return rawValue;
}
if (rawValue) {
if (me.isHorizontal()) {
if (rawValue.x !== undefined) {
return me.getRightValue(rawValue.x);
}
} else if (rawValue.y !== undefined) {
return me.getRightValue(rawValue.y);
}
}
return NaN;
},
// scale.time.js
getRightValue: function(rawValue) {
if ((rawValue instanceof Date) || (rawValue instanceof moment)) {
return rawValue;
}
if (rawValue && rawValue.t !== undefined) {
return this.getRightValue(rawValue.t);
}
return Chart.Scale.prototype.getRightValue.call(this, rawValue);
} Simpler and more predictable code (more readable as well since it becomes obvious that a "right value" is a finite number (and a Date / moment for the time scale). |
That causes the tests to fail. I think we're spending quite a lot of time optimizing a little section of code without fixing any issues people have actually run into or adding any functionality. Should we just call it a day on this one? |
To get it to work I would need to change it to:
I'll go ahead and do that |
Any idea where a string is expected as the result of @etimberg do you know what this method is really supposed to do? |
https://github.com/chartjs/Chart.js/blob/master/src/helpers/helpers.core.js#L51
What is
isObject
supposed to return given aDate
?The method has the code:
This will return
false
if passed a date because you'll get[object Date]
The text was updated successfully, but these errors were encountered: