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

Optimize category parse for usual use case #6959

Merged
merged 1 commit into from
Jan 14, 2020
Merged

Conversation

kurkle
Copy link
Member

@kurkle kurkle commented Jan 14, 2020

When labels array contains item for each data point, the label is going to be at the same index.
So check there first, before going for indexOf.

With this chart:

function generateFakeData() {
	var res = [];
	var i = 0;
	for (i = 0; i < 50000; ++i) {
		res.push(i);
	}

	return res;
}

var chart = new Chart(ctx, {
	type: 'line',
	data: {
		labels: generateFakeData(),
		datasets: [
			{
				label: '# of Votes',
				data: generateFakeData()
			}
		]
	},
	options: {
		animation: false,
		tooltips: {
			intersect: false
		},
		scales: {
			y: {
				beginAtZero: true
			}
		}
	}
});

master:
image

pr:
image

@benmccann
Copy link
Contributor

I'm not sure I understand why the label array would contain the data for that data point. Can you explain the use case a bit more with an example?

@kurkle
Copy link
Member Author

kurkle commented Jan 14, 2020

https://www.chartjs.org/samples/master/charts/bar/stacked.html for example. Labels and data points are matched by index.
But if you have data: [{x: 'b', y: 1}, {x: 'a', y: 2}], labels: ['a', 'b'] the index won't match.

@etimberg etimberg merged commit dc638d3 into chartjs:master Jan 14, 2020
@kurkle kurkle deleted the category branch February 19, 2020 18:25
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.

3 participants