From 3221d72f420a58b86aff8a6d99200cc6de871faa Mon Sep 17 00:00:00 2001 From: Allen Short Date: Wed, 2 May 2018 23:12:56 +0000 Subject: [PATCH] Pad series text to be same length as x axis (re #391) --- .../app/visualizations/chart/plotly/utils.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/client/app/visualizations/chart/plotly/utils.js b/client/app/visualizations/chart/plotly/utils.js index 3379296766..7dd4a063d7 100644 --- a/client/app/visualizations/chart/plotly/utils.js +++ b/client/app/visualizations/chart/plotly/utils.js @@ -395,17 +395,22 @@ export function prepareLayout(element, seriesList, options, data) { function updateSeriesText(seriesList, options) { each(seriesList, (series) => { series.text = []; - series.sourceData.forEach((item) => { - let text = formatNumber(item.y); - if (item.yError !== undefined) { - text = `${text} \u00B1 ${formatNumber(item.yError)}`; - } + series.x.forEach((xvalue) => { + const item = series.sourceData.get(xvalue); + if (item !== undefined) { + let text = formatNumber(item.y); + if (item.yError !== undefined) { + text = `${text} \u00B1 ${formatNumber(item.yError)}`; + } - if (options.series.percentValues) { - text = `${formatPercent(Math.abs(item.yPercent))}% (${text})`; - } + if (options.series.percentValues) { + text = `${formatPercent(Math.abs(item.yPercent))}% (${text})`; + } - series.text.push(text); + series.text.push(text); + } else { + series.text.push(null); + } }); }); return seriesList;