-
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
Allow specifying the time axis via t attribute #4533
Conversation
src/scales/scale.time.js
Outdated
* Allow x-axis to be accessed via x or t attribute | ||
*/ | ||
getRightValue: function(rawValue) { | ||
if (typeof(rawValue) === 'object') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helpers.isObject(value)
seems a better choice since typeof null === 'object'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to revert this change. See #4538
src/scales/scale.time.js
Outdated
*/ | ||
getRightValue: function(rawValue) { | ||
if (typeof(rawValue) === 'object') { | ||
if ((rawValue instanceof Date) || rawValue.isValid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess .isValid
verifies if rawValue
is a moment object? if so, can we explicitly check for it (rawValue instance moment
) instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. We do this same check in core.scale.js. I'm not sure I want to change it to rawValue instance moment
because then we'd be introducing a dependency on moment in core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that core.scale.js
should not depend of moment, but I realize that we should remove these checks from getRightValue
in core.scale.js
and keep only: object ? horizontal ? value.x : value.y
. There is no reason to have them in the base class, it's time scale specific and this new override is the way to go.
Since there is already a dependency of moment in scale.time.js
, I prefer an explicit check which is more robust and readable (I'm also changing it in parseTime
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And to be correct, it should be something like that in core.scale.js
:
var me = this;
// ...
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;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call on moving the date handling from core to time. I've done that. I didn't make the other changes. partially because helpers.isObject
seems bugged. #4538
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helpers.isObject
doesn't handle Date as an object. I'm still thinking that my previous comment is valid: only handle defined object.x
and object.y
else return rawValue
. If rawValue
is a date, then it works as before, no need for a special case. Also, it should not call me.getRightValue
if rawValue
doesn't define x
(or y
) properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/scales/scale.time.js
Outdated
if ((rawValue instanceof Date) || rawValue.isValid) { | ||
return rawValue; | ||
} | ||
return this.getRightValue(this.isHorizontal() ? (!helpers.isNullOrUndef(rawValue.t) ? rawValue.t : rawValue.x) : rawValue.y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should fallback to x/y only if t === undefined
. Also t
should be considered for vertical scale:
this.getRightValue(helpers.valueOrDefault(rawValue.t, this.isHorizontal() ? rawValue.x : rawValue.y));
src/scales/scale.time.js
Outdated
if ((rawValue instanceof Date) || rawValue.isValid) { | ||
return rawValue; | ||
} | ||
return this.getRightValue(this.isHorizontal() ? (!helpers.isNullOrUndef(rawValue.t) ? rawValue.t : rawValue.x) : rawValue.y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also fallback to the base implementation for x/y:
// ...
if (rawValue.t !== undefined) {
return this.getRightValue(rawValue.t);
}
// ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
db43cb4
to
436f268
Compare
81d9276
to
889c56a
Compare
For time series charts it may make more sense to specify the horizontal axis using the variable `t`. This change will make it much easier to use the time scale with the financial chart, which takes in the data points `{t, o, h, l, c}`.
For time series charts it may make more sense to specify the horizontal axis using the variable `t`. This change will make it much easier to use the time scale with the financial chart, which takes in the data points `{t, o, h, l, c}`.
For time series charts it may make more sense to specify the horizontal axis using the variable
t
This change will make it much easier to use the time scale with the financial chart, which takes in the data points
{ t, o, h, l, c }