Add drawTime: beforeDraw option to filler (#8973)

This commit is contained in:
Jukka Kurkela 2021-04-24 22:27:52 +03:00 committed by GitHub
parent 0ad0d35c09
commit eaa3a68cea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 9 deletions

View File

@ -68,7 +68,7 @@ Namespace: `options.plugins.filler`
| Option | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `drawTime` | `string` | `beforeDatasetDraw` | Filler draw time. Supported values: `'beforeDatasetDraw'`, `'beforeDatasetsDraw'`
| `drawTime` | `string` | `beforeDatasetDraw` | Filler draw time. Supported values: `'beforeDraw'`, `'beforeDatasetDraw'`, `'beforeDatasetsDraw'`
| [`propagate`](#propagate) | `boolean` | `true` | Fill propagation when target is hidden.
### propagate

View File

@ -26,7 +26,7 @@ const data = {
label: 'Dataset 1',
data: generateData(),
borderColor: Utils.CHART_COLORS.red,
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.red),
backgroundColor: Utils.CHART_COLORS.red,
fill: true
},
{
@ -58,6 +58,13 @@ const actions = [
chart.update();
}
},
{
name: 'drawTime: beforeDraw',
handler: (chart) => {
chart.options.plugins.filler.drawTime = 'beforeDraw';
chart.update();
}
},
{
name: 'Randomize',
handler(chart) {

View File

@ -565,19 +565,32 @@ export default {
}
},
beforeDatasetsDraw(chart, _args, options) {
beforeDraw(chart, _args, options) {
const draw = options.drawTime === 'beforeDraw';
const metasets = chart.getSortedVisibleDatasetMetas();
const area = chart.chartArea;
for (let i = metasets.length - 1; i >= 0; --i) {
const source = metasets[i].$filler;
if (!source) {
continue;
}
source.line.updateControlPoints(area);
if (draw) {
drawfill(chart.ctx, source, area);
}
}
},
beforeDatasetsDraw(chart, _args, options) {
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) {
source.line.updateControlPoints(area);
if (options.drawTime === 'beforeDatasetsDraw') {
drawfill(chart.ctx, source, area);
}
drawfill(chart.ctx, source, chart.chartArea);
}
}
},

View File

@ -0,0 +1,47 @@
module.exports = {
config: {
type: 'radar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [9, 7, 3, 5, 2, 3],
fill: 'origin',
borderColor: 'red',
backgroundColor: 'green',
pointRadius: 12,
pointBackgroundColor: 'red'
}]
},
options: {
layout: {
padding: 20
},
plugins: {
legend: false,
filler: {
drawTime: 'beforeDraw'
}
},
scales: {
r: {
angleLines: {
color: 'rgba(0,0,0,0.5)',
lineWidth: 2
},
grid: {
color: 'rgba(0,0,0,0.5)',
lineWidth: 2
},
pointLabels: {
display: false
},
ticks: {
beginAtZero: true,
display: false
},
}
}
}
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB