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

Fixes bug #5289: Bars do not appear at correct X axis position when specified in {x, y} format #5298

Closed
wants to merge 8 commits into from

Conversation

tfwww
Copy link
Contributor

@tfwww tfwww commented Feb 24, 2018

Fix #5289 by formatting the data if missing some points.

@tfwww tfwww changed the title Fixes Bars do not appear at correct X axis position when specified in {x, y} format #5289 Fixes bug #5289: Bars do not appear at correct X axis position when specified in {x, y} format Feb 24, 2018
return result;
},
/**
* return the y data of the label, if no this label, return null
Copy link
Contributor

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:

/**
*

Copy link
Contributor Author

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.

break;
}
if (labelArray.indexOf(item.x) > -1) {
result = true;
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed as you required.

formatDataset: function(dataArray) {
var labels = this.chart.data.labels;
var tmp = dataArray.slice(0);
var labelLen = labels.length;
Copy link
Contributor

@benmccann benmccann May 20, 2018

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

Copy link
Contributor Author

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.

return y;
},
/**
* find if the data in datasets is existed in the labels
Copy link
Contributor

Choose a reason for hiding this comment

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

"is existed" -> "exists"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

}
},
/**
* format the data list if the data is missing some points in the datasets.
Copy link
Contributor

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

Copy link
Contributor Author

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.

* @param {array} dataArray the data in the datasets.
* @return {number} the y data according to the label
*/
getY: function(label, dataArray) {
Copy link
Contributor

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

* @param {array} labelArray the label in the labels array
* @return {boolean} the match result, true is included
*/
dataInLabel: function(dataArray, labelArray) {
Copy link
Contributor

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

Copy link
Contributor Author

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.

* @param {array} dataArray array to format
* @return {array} the formated array
*/
formatDataset: function(dataArray) {
Copy link
Contributor

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 _

Copy link
Contributor Author

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.

for (var i = 0; i < dataArray.length; i++) {
var item = dataArray[i];
if (item.x === label) {
y = item.y;
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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

@benmccann
Copy link
Contributor

@wmzhong don't forget there are some comments on this PR

@benmccann
Copy link
Contributor

@wmzhong a quick reminder that there are some outstanding comments on this PR

@benmccann
Copy link
Contributor

@wmzhong a reminder to take another look at this PR when you get a chance

@andig
Copy link
Contributor

andig commented Aug 8, 2018

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)};
Copy link
Contributor

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

@benmccann
Copy link
Contributor

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

@benmccann
Copy link
Contributor

@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

@benmccann benmccann closed this Aug 15, 2018
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.

4 participants