[axis formatting] Override the valueformat to be percentage when contribution is selected (#4866)

* force the valueformat to be percentage when contribution is selected

* remove extra empty lines

* simplied the logic by reusing some existing code
This commit is contained in:
Conglei 2018-04-23 10:05:29 -07:00 committed by Maxime Beauchemin
parent 5927e7dfe6
commit 2cd016f11c
1 changed files with 5 additions and 4 deletions

View File

@ -253,7 +253,7 @@ export default function nvd3Vis(slice, payload) {
case 'pie':
chart = nv.models.pieChart();
colorKey = 'x';
chart.valueFormat(f);
chart.valueFormat(formatter);
if (fd.donut) {
chart.donut(true);
}
@ -386,9 +386,10 @@ export default function nvd3Vis(slice, payload) {
const yAxisFormatter = d3FormatPreset(fd.y_axis_format);
if (chart.yAxis && chart.yAxis.tickFormat) {
if (fd.num_period_compare) {
// When computing a "Period Ratio", we force a percentage format
chart.yAxis.tickFormat(d3.format('.1%'));
if (fd.num_period_compare || fd.contribution) {
// When computing a "Period Ratio" or "Contribution" selected, we force a percentage format
const percentageFormat = d3.format('.1%');
chart.yAxis.tickFormat(percentageFormat);
} else {
chart.yAxis.tickFormat(yAxisFormatter);
}