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

Respect fill: false with custom draw times #10414

Merged
merged 9 commits into from
Jun 22, 2022
4 changes: 4 additions & 0 deletions src/plugins/plugin.filler/filler.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ export function _createBoundaryLine(boundary, line) {
_fullLoop: _loop
}) : null;
}

export function _shouldApplyFill(source) {
return source && source.fill !== false;
}
12 changes: 6 additions & 6 deletions src/plugins/plugin.filler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import LineElement from '../../elements/element.line';
import {_drawfill} from './filler.drawing';
import { _shouldApplyFill } from './filler.helper';
import {_decodeFill, _resolveTarget} from './filler.options';

export default {
Expand Down Expand Up @@ -53,7 +54,7 @@ export default {
const area = chart.chartArea;
for (let i = metasets.length - 1; i >= 0; --i) {
const source = metasets[i].$filler;
if (!source || source.fill === false) {
if (!_shouldApplyFill(source)) {
LeeLenaleee marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

Expand All @@ -65,16 +66,15 @@ export default {
},

beforeDatasetsDraw(chart, _args, options) {
const source = args.meta.$filler;

if (!source || source.fill === false || options.drawTime !== 'beforeDatasetsDraw') {
if (options.drawTime !== 'beforeDatasetsDraw') {
return;
}

const metasets = chart.getSortedVisibleDatasetMetas();
for (let i = metasets.length - 1; i >= 0; --i) {
const source = metasets[i].$filler;
if (source) {
console.log(source)
LeeLenaleee marked this conversation as resolved.
Show resolved Hide resolved
if (_shouldApplyFill(source)) {
_drawfill(chart.ctx, source, chart.chartArea);
}
}
Expand All @@ -83,7 +83,7 @@ export default {
beforeDatasetDraw(chart, args, options) {
const source = args.meta.$filler;

if (!source || source.fill === false || options.drawTime !== 'beforeDatasetDraw') {
if (!_shouldApplyFill(source) || options.drawTime !== 'beforeDatasetDraw') {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
config: {
type: 'line',
data: {
labels: ['0', '1', '2', '3', '4', '5'],
datasets: [{
backgroundColor: 'red',
data: [3, -3, 0, 5, -5, 0],
fill: false
}]
},
options: {
plugins: {
legend: false,
title: false,
filler: {
drawTime: 'beforeDatasetDraw'
}
},
}
},
};

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
config: {
type: 'line',
data: {
labels: ['0', '1', '2', '3', '4', '5'],
datasets: [{
backgroundColor: 'red',
data: [3, -3, 0, 5, -5, 0],
fill: false
}]
},
options: {
plugins: {
legend: false,
title: false,
filler: {
drawTime: 'beforeDatasetsDraw'
}
},
}
},
};

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDraw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
config: {
type: 'line',
data: {
labels: ['0', '1', '2', '3', '4', '5'],
datasets: [{
backgroundColor: 'red',
data: [3, -3, 0, 5, -5, 0],
fill: false
}]
},
options: {
plugins: {
legend: false,
title: false,
filler: {
drawTime: 'beforeDraw'
}
},
}
},
};

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.