From b6f2483fd230b50c86e35b0194c46a1fe1f3079b Mon Sep 17 00:00:00 2001 From: Scott Fortmann-Roe Date: Sun, 19 Apr 2020 18:27:16 +0100 Subject: [PATCH] Update axis-chart-utils.js Fix issue with overlapping labels on seriese charts. --- src/js/utils/axis-chart-utils.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/js/utils/axis-chart-utils.js b/src/js/utils/axis-chart-utils.js index 079a48c..626c00f 100644 --- a/src/js/utils/axis-chart-utils.js +++ b/src/js/utils/axis-chart-utils.js @@ -101,6 +101,13 @@ export function getShortenedLabels(chartWidth, labels=[], isSeries=true) { if(allowedSpace <= 0) allowedSpace = 1; let allowedLetters = allowedSpace / DEFAULT_CHAR_WIDTH; + let seriesMultiple; + if(isSeries) { + // Find the maximum label length for spacing calculations + let maxLabelLength = Math.max(...labels.map(label => label.length)); + seriesMultiple = Math.ceil(maxLabelLength/allowedLetters); + } + let calcLabels = labels.map((label, i) => { label += ""; if(label.length > allowedLetters) { @@ -112,8 +119,7 @@ export function getShortenedLabels(chartWidth, labels=[], isSeries=true) { label = label.slice(0, allowedLetters) + '..'; } } else { - let multiple = Math.ceil(label.length/allowedLetters); - if(i % multiple !== 0) { + if(i % seriesMultiple !== 0) { label = ""; } }