-
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
Fixes bug #5289: Bars do not appear at correct X axis position when specified in {x, y} format #5298
Conversation
src/core/core.controller.js
Outdated
return result; | ||
}, | ||
/** | ||
* return the y data of the label, if no this label, return null |
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.
The spacing is a bit off on the doc for this comment and the next one.
They should probably be more like the first method doc you have like:
/**
*
This one is missing a space:
/**
*
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.
The missing space is added now in all the places.
src/core/core.controller.js
Outdated
break; | ||
} | ||
if (labelArray.indexOf(item.x) > -1) { | ||
result = true; |
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.
just return true
here. you don't need the result
var and can return false
as the last line
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.
Changed as you required.
src/core/core.controller.js
Outdated
formatDataset: function(dataArray) { | ||
var labels = this.chart.data.labels; | ||
var tmp = dataArray.slice(0); | ||
var labelLen = labels.length; |
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.
there's no need to create a variable for this value since it's only used once. same with dataLen
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 have removed the labelLen
and dataLen
variables since they are used only once.
src/core/core.controller.js
Outdated
return y; | ||
}, | ||
/** | ||
* find if the data in datasets is existed in the labels |
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.
"is existed" -> "exists"
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.
Fixed.
src/core/core.controller.js
Outdated
} | ||
}, | ||
/** | ||
* format the data list if the data is missing some points in the datasets. |
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.
The first letter of a method doc is typically capitalized. Same below
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.
Capitalized all the first letter of the method doc.
src/core/core.controller.js
Outdated
* @param {array} dataArray the data in the datasets. | ||
* @return {number} the y data according to the label | ||
*/ | ||
getY: function(label, dataArray) { |
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.
this can be put with the other functions (line 25-68) since it doesn't use any class members
src/core/core.controller.js
Outdated
* @param {array} labelArray the label in the labels array | ||
* @return {boolean} the match result, true is included | ||
*/ | ||
dataInLabel: function(dataArray, labelArray) { |
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.
this can be put with the other functions (line 25-68) since it doesn't use any class members
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 have put these two functions on the other place.
src/core/core.controller.js
Outdated
* @param {array} dataArray array to format | ||
* @return {array} the formated array | ||
*/ | ||
formatDataset: function(dataArray) { |
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.
private functions should be prefixed with _
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.
The prefixed is added.
Pls check.
src/core/core.controller.js
Outdated
for (var i = 0; i < dataArray.length; i++) { | ||
var item = dataArray[i]; | ||
if (item.x === label) { | ||
y = item.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.
you can just return item.y
here, which will be less code and more efficient. then remove the y
variable and return null
at the end if you didn't hit this
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.
The code is changed as you required.
if (item === null || item === undefined || item.x === undefined) { | ||
break; | ||
} | ||
if (labelArray.indexOf(item.x) > -1) { |
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.
this will return true if a single item matches. is that what you want?
if you want to see if all items match then you could return false if < 0 here and return true at the end of the function
*/ | ||
_formatDataset: function(dataArray) { | ||
var labels = this.chart.data.labels; | ||
var tmp = dataArray.slice(0); |
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.
there's no reason to create tmp
here as a copy of dataArray
. the only actions taken on it are read-only. just use dataArray
directly and remove tmp
_formatDataset: function(dataArray) { | ||
var labels = this.chart.data.labels; | ||
var tmp = dataArray.slice(0); | ||
var result = dataArray; |
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.
this is where you should make the defensive copy. don't modify the input to the function. instead do var result = dataArray.slice(0); // create copy of input
@wmzhong don't forget there are some comments on this PR |
@wmzhong a quick reminder that there are some outstanding comments on this PR |
@wmzhong a reminder to take another look at this PR when you get a chance |
That would be a shame. But when the first review takes three months interest might have shifted 😔 |
if (match && dataArray.length < labels.length) { | ||
for (var i = 0; i < labels.length; i++) { | ||
var label = labels[i]; | ||
result[i] = {x: label, y: getY(label, tmp)}; |
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 you need to check if it's a horizontal or vertical chart here and can't just assume that the label will be on the x-axis
And getY
should probably be called getValue
and also do the same check
Yeah, can definitely understand that the long review cycles are frustrating. We'd love help reviewing PRs if you're able to go through the pending PRs and help review. To be clear, if we close any PR due to inactivity, it's always welcome to be re-opened in the future when the feedback is ready to be addressed. The main reason for closing inactive PRs is to help make it clear which PRs need reviews so that we can more efficiently get through them and try to cut down the review cycle |
@wmzhong I really appreciate the contribution and I would like to see it make its way in, but it has been quite some time without a response. I'm going to close this PR for now, but please do update it and let us know when you do so that we can reopen it and finish getting it reviewed and merged. Sorry once again for the delay on the original review |
Fix #5289 by formatting the data if missing some points.