Skip to content

Commit

Permalink
Add drawTime: beforeDraw option to filler (#8973)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Apr 24, 2021
1 parent 0ad0d35 commit eaa3a68
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/charts/area.md
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion docs/samples/area/line-drawtime.md
Expand Up @@ -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
},
{
Expand Down Expand Up @@ -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) {
Expand Down
27 changes: 20 additions & 7 deletions src/plugins/plugin.filler.js
Expand Up @@ -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;
}

if (source) {
source.line.updateControlPoints(area);
source.line.updateControlPoints(area);
if (draw) {
drawfill(chart.ctx, source, area);
}
}
},

if (options.drawTime === 'beforeDatasetsDraw') {
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) {
drawfill(chart.ctx, source, chart.chartArea);
}
}
},
Expand Down
47 changes: 47 additions & 0 deletions test/fixtures/plugin.filler/radar/beforeDraw.js
@@ -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 added test/fixtures/plugin.filler/radar/beforeDraw.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit eaa3a68

Please sign in to comment.