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

fix issue #11717 #11844

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/controllers/controller.bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,12 @@ export default class BarController extends DatasetController {
.filter(meta => meta.controller.options.grouped);
const stacked = iScale.options.stacked;
const stacks = [];
const currentParsed = this._cachedMeta.controller.getParsed(dataIndex);
const xStackIndex = currentParsed && currentParsed[iScale.axis];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that iScaleValue might be a better name since this is not really the stack index but the value of the index scale

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 think that iScaleValue might be a better name since this is not really the stack index but the value of the index scale

Hi LeeLenaleee, x may not a good name. From the parsed data perspective, it's iScale value. But from the chart perspective, it's represent in which section. The 'RED' or the 'Blue' in the original issue example.
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would keep the code context here in mind more then how it shows on the chart itself. We read the property of the index scale which can also be the y axis. And internally it is a number and not the string you see at the chart. This conversion happens later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, going to update the codes


const skipNull = (meta) => {
const parsed = meta.controller.getParsed(dataIndex);
const filtered = meta._parsed.filter(item => item[iScale.axis] === xStackIndex);
const parsed = filtered.length > 0 ? filtered[0] : undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const filtered = meta._parsed.filter(item => item[iScale.axis] === xStackIndex);
const parsed = filtered.length > 0 ? filtered[0] : undefined;
const parsed = meta._parsed.find(item => item[iScale.axis] === xStackIndex);

const val = parsed && parsed[meta.vScale.axis];

if (isNullOrUndef(val) || isNaN(val)) {
Expand Down
86 changes: 86 additions & 0 deletions test/specs/controller.bar.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,92 @@ describe('Chart.controllers.bar', function() {
expect(unevenChart).not.toThrow();
});

it('should correctly count the number of stacks when skipNull and different order datasets', function() {

const chart = window.acquireChart({
type: 'bar',
data: {
datasets: [
{
id: '1',
label: 'USA',
data: [
{
xScale: 'First',
Country: 'USA',
yScale: 524
},
{
xScale: 'Second',
Country: 'USA',
yScale: 325
}
],

yAxisID: 'yScale',
xAxisID: 'xScale',

parsing: {
yAxisKey: 'yScale',
xAxisKey: 'xScale'
}
},
{
id: '2',
label: 'BRA',
data: [
{
xScale: 'Second',
Country: 'BRA',
yScale: 183
},
{
xScale: 'First',
Country: 'BRA',
yScale: 177
}
],

yAxisID: 'yScale',
xAxisID: 'xScale',

parsing: {
yAxisKey: 'yScale',
xAxisKey: 'xScale'
}
},
{
id: '3',
label: 'DEU',
data: [
{
xScale: 'First',
Country: 'DEU',
yScale: 162
}
],

yAxisID: 'yScale',
xAxisID: 'xScale',

parsing: {
yAxisKey: 'yScale',
xAxisKey: 'xScale'
}
}
]
},
options: {
skipNull: true
}
});

var meta = chart.getDatasetMeta(0);
expect(meta.controller._getStackCount(0)).toBe(3);
expect(meta.controller._getStackCount(1)).toBe(2);

});

it('should not override tooltip title and label callbacks', async() => {
const chart = window.acquireChart({
type: 'bar',
Expand Down
Loading