From c348c12b99b16f15f19d6f0cbb11f22240a700f1 Mon Sep 17 00:00:00 2001 From: Trent DiBacco Date: Wed, 12 Apr 2017 17:33:57 -0700 Subject: [PATCH] Add ability to format category name and series point value. --- export-csv.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/export-csv.js b/export-csv.js index ac7c574..f673595 100644 --- a/export-csv.js +++ b/export-csv.js @@ -55,7 +55,13 @@ item.name + (keyLength > 1 ? ' ('+ key + ')' : '') : 'Category'; }, - xAxisIndices = []; + xAxisIndices = [], + rowCategoryFormatter = options.rowCategoryFormatter || function (point, series) { + return null; + }, + rowValueFormatter = options.rowValueFormatter || function (point, series) { + return null; + }; // Loop the series and index values i = 0; @@ -94,7 +100,8 @@ each(series.points, function (point, pIdx) { var key = requireSorting ? point.x : pIdx, prop, - val; + val, + categoryName = rowCategoryFormatter(point, series); j = 0; @@ -112,10 +119,15 @@ rows[key].name = point.name; } + // If rowCategoryFormatter provides override. + if (categoryName) { + rows[key].name = categoryName; + } + while (j < valueCount) { prop = pointArrayMap[j]; // y, z etc val = point[prop]; - rows[key][i + j] = pick(categoryMap[prop][val], val); // Pick a Y axis category if present + rows[key][i + j] = pick(rowValueFormatter(point, series), categoryMap[prop][val], val); // Pick a Y axis category if present j = j + 1; }