Skip to content

Commit af485e2

Browse files
committed
auto select date
1 parent ec543f2 commit af485e2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/module.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,15 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl {
343343
} else {
344344
delete layout.zaxis;
345345
delete layout.scene;
346+
347+
// Check if the X axis should be a date
348+
if (!layout.xaxis.type || layout.xaxis.type === 'auto') {
349+
const mapping = _.get(this.cfg, 'traces[0].mapping.x');
350+
if (mapping && mapping.indexOf('time') >= 0) {
351+
layout.xaxis.type = 'date';
352+
}
353+
}
354+
346355
const isDate = layout.xaxis.type === 'date';
347356
layout.margin = {
348357
l: layout.yaxis.title ? 50 : 35,
@@ -352,6 +361,12 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl {
352361
pad: 2,
353362
};
354363

364+
if (isDate && !layout.xaxis.range) {
365+
const range = this.timeSrv.timeRange();
366+
layout.xaxis.range = [range.from.valueOf(), range.to.valueOf()];
367+
console.log('AUTO range', range, layout.xaxis);
368+
}
369+
355370
// get the css rule of grafana graph axis text
356371
const labelStyle = this.getCssRule('div.flot-text');
357372
if (labelStyle) {

0 commit comments

Comments
 (0)