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

Handle animating stacked bars from null values #8872

Merged
merged 2 commits into from Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/controllers/controller.bar.js
Expand Up @@ -266,7 +266,8 @@ export default class BarController extends DatasetController {
me.updateSharedOptions(sharedOptions, mode, firstOpts);

for (let i = start; i < start + count; i++) {
const vpixels = reset ? {base, head: base} : me._calculateBarValuePixels(i);
const parsed = me.getParsed(i);
const vpixels = reset || isNullOrUndef(parsed[vScale.axis]) ? {base, head: base} : me._calculateBarValuePixels(i);
const ipixels = me._calculateBarIndexPixels(i, ruler);

const properties = {
Expand Down
6 changes: 4 additions & 2 deletions src/controllers/controller.line.js
@@ -1,4 +1,5 @@
import DatasetController from '../core/core.datasetController';
import {isNullOrUndef} from '../helpers';
import {_limitValue, isNumber} from '../helpers/helpers.math';
import {_lookupByKey} from '../helpers/helpers.collection';

Expand Down Expand Up @@ -59,9 +60,10 @@ export default class LineController extends DatasetController {
const point = points[i];
const parsed = me.getParsed(i);
const properties = directUpdate ? point : {};
const nullData = isNullOrUndef(parsed.y);
const x = properties.x = xScale.getPixelForValue(parsed.x, i);
const y = properties.y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(_stacked ? me.applyStack(yScale, parsed, _stacked) : parsed.y, i);
properties.skip = isNaN(x) || isNaN(y);
const y = properties.y = reset || nullData ? yScale.getBasePixel() : yScale.getPixelForValue(_stacked ? me.applyStack(yScale, parsed, _stacked) : parsed.y, i);
properties.skip = isNaN(x) || isNaN(y) || nullData;
properties.stop = i > 0 && (parsed.x - prevParsed.x) > maxGapLength;
properties.parsed = parsed;

Expand Down
20 changes: 20 additions & 0 deletions test/specs/controller.bar.tests.js
Expand Up @@ -30,6 +30,26 @@ describe('Chart.controllers.bar', function() {
expect(meta.controller.index).toBe(0);
});

it('should set null bars to the reset state', function() {
var chart = window.acquireChart({
type: 'bar',
data: {
datasets: [{
data: [10, null, 0, -4],
label: 'dataset1',
}],
labels: ['label1', 'label2', 'label3', 'label4']
}
});

var meta = chart.getDatasetMeta(0);
var bar = meta.data[1];
var {x, y, base} = bar.getProps(['x', 'y', 'base'], true);
expect(isNaN(x)).toBe(false);
expect(isNaN(y)).toBe(false);
expect(isNaN(base)).toBe(false);
});

it('should use the first scale IDs if the dataset does not specify them', function() {
var chart = window.acquireChart({
type: 'bar',
Expand Down
21 changes: 21 additions & 0 deletions test/specs/controller.line.tests.js
Expand Up @@ -917,4 +917,25 @@ describe('Chart.controllers.line', function() {
}
expect(createChart).not.toThrow();
});

it('should set skipped points to the reset state', function() {
var chart = window.acquireChart({
type: 'line',
data: {
datasets: [{
data: [10, null, 0, -4],
label: 'dataset1',
pointBorderWidth: [1, 2, 3, 4]
}],
labels: ['label1', 'label2', 'label3', 'label4']
}
});

var meta = chart.getDatasetMeta(0);
var point = meta.data[1];
var {x, y} = point.getProps(['x', 'y'], true);
expect(point.skip).toBe(true);
expect(isNaN(x)).toBe(false);
expect(isNaN(y)).toBe(false);
});
});