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

Sort docs sub menus alphabetically, add line and plugin sample #10138

Merged
merged 2 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ module.exports = {
children: [
'plugins/chart-area-border',
'plugins/quadrants',
'plugins/doughnut-empty-state',
kurkle marked this conversation as resolved.
Show resolved Hide resolved
]
},
'utils'
Expand Down
77 changes: 77 additions & 0 deletions docs/samples/plugins/doughnut-empty-state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Doughnut Empty State

```js chart-editor
// <block:data:2>
const data = {
labels: [],
datasets: [
{
label: 'Dataset 1',
data: []
}
]
};
// </block:data>

// <block:plugin:1>
const plugin = {
id: 'emptyDoughnut',
afterDraw(chart, args, options) {
const {datasets} = chart.data;
const {color, width, radiusDecrease} = options;
let hasData = false;

for (let i = 0; i < datasets.length; i += 1) {
const dataset = datasets[i];
hasData |= dataset.data.length > 0;
}

if (!hasData) {
const {chartArea: {left, top, right, bottom}, ctx} = chart;
const centerX = (left + right) / 2;
const centerY = (top + bottom) / 2;
const r = Math.min(right - left, bottom - top) / 2;

ctx.beginPath();
ctx.lineWidth = width || 2;
ctx.strokeStyle = color || 'rgba(255, 128, 0, 0.5)';
ctx.arc(centerX, centerY, (r - radiusDecrease || 0), 0, 2 * Math.PI);
ctx.stroke();
}
}
};
// </block:plugin>

// <block:config:0>
const config = {
type: 'doughnut',
data: data,
options: {
plugins: {
emptyDoughnut: {
color: 'rgba(255, 128, 0, 0.5)',
width: 2,
radiusDecrease: 20
}
}
},
plugins: [plugin]
};
// </block:config>

const actions = [
{
name: 'Randomize',
handler(chart) {
chart.data.datasets.forEach(dataset => {
dataset.data = Utils.points(NUMBER_CFG);
});
chart.update();
}
},
];

module.exports = {
actions,
config,
};