Skip to content

Commit

Permalink
Coerce to moment when 'datetime' selected by user.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina Samuel committed Feb 6, 2019
1 parent ec475e4 commit 9e67ddf
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions client/app/visualizations/chart/plotly/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ function getHoverInfoPattern(options) {
return result;
}

export function normalizeValue(value, dateTimeFormat = 'YYYY-MM-DD HH:mm:ss') {
export function normalizeValue(value, axisType, dateTimeFormat = 'YYYY-MM-DD HH:mm:ss') {
if (axisType === 'datetime' && moment.utc(value).isValid()) {
value = moment.utc(value);
}
if (moment.isMoment(value)) {
return value.format(dateTimeFormat);
}
Expand Down Expand Up @@ -269,7 +272,7 @@ function preparePieData(seriesList, options) {
yPercent: y / seriesTotal * 100,
raw: extend({}, row.$raw, {
// use custom display format - see also `updateSeriesText`
'@@x': normalizeValue(row.x, options.dateTimeFormat),
'@@x': normalizeValue(row.x, options.xAxis.type, options.dateTimeFormat),
}),
});
});
Expand Down Expand Up @@ -427,7 +430,7 @@ function prepareChartData(seriesList, options) {
const seriesColor = getSeriesColor(seriesOptions, index);

// Sort by x - `Map` preserves order of items
const data = sortX ? sortBy(series.data, d => normalizeValue(d.x)) : series.data;
const data = sortX ? sortBy(series.data, d => normalizeValue(d.x, options.xAxis.type)) : series.data;

// For bubble/scatter charts `y` may be any (similar to `x`) - numeric is only bubble size;
// for other types `y` is always number
Expand All @@ -438,8 +441,8 @@ function prepareChartData(seriesList, options) {
const yValues = [];
const yErrorValues = [];
each(data, (row) => {
const x = normalizeValue(row.x); // number/datetime/category
const y = cleanYValue(row.y); // depends on series type!
const x = normalizeValue(row.x, options.xAxis.type); // number/datetime/category
const y = cleanYValue(row.y, options.yAxis[0].type); // depends on series type!
const yError = cleanNumber(row.yError); // always number
const size = cleanNumber(row.size); // always number
sourceData.set(x, {
Expand All @@ -450,7 +453,7 @@ function prepareChartData(seriesList, options) {
yPercent: null, // will be updated later
raw: extend({}, row.$raw, {
// use custom display format - see also `updateSeriesText`
'@@x': normalizeValue(row.x, options.dateTimeFormat),
'@@x': normalizeValue(row.x, options.xAxis.type, options.dateTimeFormat),
}),
});
xValues.push(x);
Expand Down

0 comments on commit 9e67ddf

Please sign in to comment.