Skip to content

Commit

Permalink
fixed bug with exporting to csv when categories are null
Browse files Browse the repository at this point in the history
  • Loading branch information
yungfox committed Apr 9, 2024
1 parent 9158723 commit ae266b8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/modules/Exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ class Exports {
}
}

// let the caller know the current category is null. this can happen for example
// when dealing with line charts having inconsistent time series data
if (cat === null)
return 'nullvalue'

if (Array.isArray(cat)) {
cat = cat.join(' ')
}
Expand All @@ -282,6 +287,11 @@ class Exports {
columns = []

let cat = getCat(i)

// current category is null, let's move on to the next one
if (cat === 'nullvalue')
continue

if (!cat) {
if (dataFormat.isFormatXY()) {
cat = series[sI].data[i].x
Expand All @@ -296,8 +306,8 @@ class Exports {
isTimeStamp(cat)
? w.config.chart.toolbar.export.csv.dateFormatter(cat)
: Utils.isNumber(cat)
? cat
: cat.split(columnDelimiter).join('')
? cat
: cat.split(columnDelimiter).join('')
)

for (let ci = 0; ci < w.globals.series.length; ci++) {
Expand Down Expand Up @@ -380,8 +390,8 @@ class Exports {
isTimeStamp(cat) && w.config.xaxis.type === 'datetime'
? w.config.chart.toolbar.export.csv.dateFormatter(cat)
: Utils.isNumber(cat)
? cat
: cat.split(columnDelimiter).join(''),
? cat
: cat.split(columnDelimiter).join(''),
data[cat].join(columnDelimiter),
])
})
Expand Down Expand Up @@ -446,7 +456,7 @@ class Exports {

this.triggerDownload(
'data:text/csv; charset=utf-8,' +
encodeURIComponent(universalBOM + result),
encodeURIComponent(universalBOM + result),
fileName ? fileName : w.config.chart.toolbar.export.csv.filename,
'.csv'
)
Expand Down

0 comments on commit ae266b8

Please sign in to comment.