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

Add drawTime: beforeDraw option to filler #8973

Merged
merged 1 commit into from Apr 24, 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
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.