From 04cae86dcb2599de62c1aa058a67bc7a449f89d5 Mon Sep 17 00:00:00 2001 From: Kim Truong <47833996+khtruong@users.noreply.github.com> Date: Mon, 1 Apr 2019 13:56:43 -0700 Subject: [PATCH] fix: exception thrown for charts without a x-axis (#36) * fix: pie chart exception * fix: incoporate krist's feedbacl --- .../src/NVD3Vis.js | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js b/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js index c9b1359ad..51c9ec6ca 100644 --- a/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js +++ b/packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js @@ -495,15 +495,17 @@ function nvd3Vis(element, props) { if (chart.x2Axis && chart.x2Axis.tickFormat) { chart.x2Axis.tickFormat(xAxisFormatter); } - const isXAxisString = isVizTypes(['dist_bar', 'box_plot']); - if (!isXAxisString && chart.xAxis && chart.xAxis.tickFormat) { - chart.xAxis.tickFormat(xAxisFormatter); - } else { - chart.xAxis.tickFormat(d => - d.length > MAX_NO_CHARACTERS_IN_LABEL - ? `${d.substring(0, MAX_NO_CHARACTERS_IN_LABEL)}…` - : d, - ); + if (chart.xAxis && chart.xAxis.tickFormat) { + const isXAxisString = isVizTypes(['dist_bar', 'box_plot']); + if (isXAxisString) { + chart.xAxis.tickFormat(d => + d.length > MAX_NO_CHARACTERS_IN_LABEL + ? `${d.substring(0, MAX_NO_CHARACTERS_IN_LABEL)}…` + : d, + ); + } else { + chart.xAxis.tickFormat(xAxisFormatter); + } } let yAxisFormatter = getTimeOrNumberFormatter(yAxisFormat);