Skip to content

Commit

Permalink
feat: improve customization of gv-chart-gauge-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
gcusnieux committed May 30, 2023
1 parent d6d6a08 commit 4350493
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
50 changes: 27 additions & 23 deletions src/charts/gv-chart-gauge-progress/gv-chart-gauge-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,35 @@ export class GvChartGaugeProgress extends GvChartGauge {

async getOptions() {
const options = await super.getOptions();

const max = this.max;
options.series[0].dataLabels = [
{
enabled: true,
align: 'center',
verticalAlign: 'middle',
formatter: function () {
if (this.y >= max) {
return `Done !`;
}
const remainingTime = Math.ceil((max - this.y) / 60000);
const prefix = `${remainingTime} min`;
const suffix = 'remaining...';
const spaces = Array(Math.round((suffix.length - prefix.length) / 2))
.fill(' ')
.join('');
return `${spaces}${prefix}<br/>${suffix}`;
},
borderWidth: 0,
style: {
fontSize: '16px',
},

const dataLabel = {
enabled: true,
align: 'center',
verticalAlign: 'middle',
formatter: function () {
if (this.y >= max) {
return `Done !`;
}
const remainingTime = Math.ceil((max - this.y) / 60000);
const prefix = `${remainingTime} min`;
const suffix = 'remaining...';
const spaces = Array(Math.round((suffix.length - prefix.length) / 2))
.fill('&nbsp;')
.join('');
return `${spaces}${prefix}<br/>${suffix}`;
},
];
borderWidth: 0,
};
if (options.series[0].dataLabels) {
if (Array.isArray(options.series[0].dataLabels) && options.series[0].dataLabels.length > 0) {
options.series[0].dataLabels[0] = { ...options.series[0].dataLabels[0], ...dataLabel };
} else {
options.series[0].dataLabels = { ...options.series[0].dataLabels, ...dataLabel };
}
} else {
options.series[0].dataLabels = dataLabel;
}

return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ const series = [
y: 0,
},
],
dataLabels: {
color: 'var(--gv-theme-color-info)',
enabled: true,
align: 'center',
verticalAlign: 'middle',
style: {
fontSize: '14px',
textOutline: 'none',
},
},
},
];

Expand Down

0 comments on commit 4350493

Please sign in to comment.