[TSVB] Wrong x-axis formatting if "dateFormat" configuration property is not specified (#84899)

* [TSVB] Wrong x-axis formatting if "dateFormat" configuration property is not specified

* Update create_xaxis_formatter.js

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Alexey Antonov 2020-12-04 18:14:58 +03:00 committed by GitHub
parent 9d6d78320b
commit 71f863ef66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 7 deletions

View file

@ -18,18 +18,18 @@
*/
import moment from 'moment';
export function getFormat(interval, rules, dateFormat) {
function getFormat(interval, rules = []) {
for (let i = rules.length - 1; i >= 0; i--) {
const rule = rules[i];
if (!rule[0] || interval >= moment.duration(rule[0])) {
return rule[1];
}
}
return dateFormat;
}
export function createXaxisFormatter(interval, rules, dateFormat) {
return (val) => {
return moment(val).format(getFormat(interval, rules, dateFormat));
return moment(val).format(getFormat(interval, rules) ?? dateFormat);
};
}

View file

@ -46,10 +46,6 @@ class TimeseriesVisualization extends Component {
dateFormat = this.props.getConfig('dateFormat');
xAxisFormatter = (interval) => (val) => {
if (!this.scaledDataFormat || !this.dateFormat) {
return val;
}
const formatter = createXaxisFormatter(interval, this.scaledDataFormat, this.dateFormat);
return formatter(val);
};