Update axis-chart-utils.js

Fix issue with overlapping labels on seriese charts.
This commit is contained in:
Scott Fortmann-Roe 2020-04-19 18:27:16 +01:00
parent e95f0aadaa
commit b6f2483fd2

View File

@ -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 = "";
}
}