Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coerce to moment when 'datetime' selected by user. #3150

Merged
merged 1 commit into from
Feb 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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