|
@@ -50,13 +50,14 @@ export function getChartData(data, query, options = {}) {
|
|
|
* @param {Boolean} [options.useTimestamps] (default: false) Return raw timestamps instead of formatting dates
|
|
|
* @param {Boolean} [options.assumeNullAsZero] (default: false) Assume null values as 0
|
|
|
* @param {Boolean} [options.allSeries] (default: false) Return all series instead of top 10
|
|
|
+ * @param {Object} [options.fieldLabelMap] (default: false) Maps value from Snuba to a defined label
|
|
|
* @returns {Array}
|
|
|
*/
|
|
|
export function getChartDataByDay(rawData, query, options = {}) {
|
|
|
// We only chart the first aggregation for now
|
|
|
const aggregate = query.aggregations[0][2];
|
|
|
|
|
|
- const data = getDataWithKeys(rawData, query);
|
|
|
+ const data = getDataWithKeys(rawData, query, options);
|
|
|
|
|
|
// We only want to show the top 10 series
|
|
|
const top10Series = getTopSeries(
|
|
@@ -143,14 +144,14 @@ function getTopSeries(data, aggregate, limit = NUMBER_OF_SERIES_BY_DAY) {
|
|
|
return new Set(limit <= 0 ? orderedData : orderedData.slice(0, limit));
|
|
|
}
|
|
|
|
|
|
-function getDataWithKeys(data, query) {
|
|
|
+function getDataWithKeys(data, query, options = {}) {
|
|
|
const {aggregations, fields} = query;
|
|
|
// We only chart the first aggregation for now
|
|
|
const aggregate = aggregations[0][2];
|
|
|
|
|
|
return data.map(row => {
|
|
|
const key = fields.length
|
|
|
- ? fields.map(field => getLabel(row[field])).join(',')
|
|
|
+ ? fields.map(field => getLabel(row[field], options)).join(',')
|
|
|
: aggregate;
|
|
|
|
|
|
return {
|
|
@@ -173,7 +174,7 @@ function formatDate(datetime, enabled = true) {
|
|
|
// Converts a value to a string for the chart label. This could
|
|
|
// potentially cause incorrect grouping, e.g. if the value null and string
|
|
|
// 'null' are both present in the same series they will be merged into 1 value
|
|
|
-function getLabel(value) {
|
|
|
+function getLabel(value, options) {
|
|
|
if (typeof value === 'object') {
|
|
|
try {
|
|
|
value = JSON.stringify(value);
|
|
@@ -183,6 +184,10 @@ function getLabel(value) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (options.fieldLabelMap && options.fieldLabelMap.hasOwnProperty(value)) {
|
|
|
+ return options.fieldLabelMap[value];
|
|
|
+ }
|
|
|
+
|
|
|
return value;
|
|
|
}
|
|
|
|