mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix 8706 (#8734)
* heatmap: fix incorrect time for UTC timezone, fixes #8706 * heatmap: fix tests for time format
This commit is contained in:
parent
8634c9d457
commit
97a7081b57
@ -100,10 +100,17 @@ export default function link(scope, elem, attrs, ctrl) {
|
|||||||
|
|
||||||
let ticks = chartWidth / DEFAULT_X_TICK_SIZE_PX;
|
let ticks = chartWidth / DEFAULT_X_TICK_SIZE_PX;
|
||||||
let grafanaTimeFormatter = grafanaTimeFormat(ticks, timeRange.from, timeRange.to);
|
let grafanaTimeFormatter = grafanaTimeFormat(ticks, timeRange.from, timeRange.to);
|
||||||
|
let timeFormat;
|
||||||
|
let dashboardTimeZone = ctrl.dashboard.getTimezone();
|
||||||
|
if (dashboardTimeZone === 'utc') {
|
||||||
|
timeFormat = d3.utcFormat(grafanaTimeFormatter);
|
||||||
|
} else {
|
||||||
|
timeFormat = d3.timeFormat(grafanaTimeFormatter);
|
||||||
|
}
|
||||||
|
|
||||||
let xAxis = d3.axisBottom(xScale)
|
let xAxis = d3.axisBottom(xScale)
|
||||||
.ticks(ticks)
|
.ticks(ticks)
|
||||||
.tickFormat(d3.timeFormat(grafanaTimeFormatter))
|
.tickFormat(timeFormat)
|
||||||
.tickPadding(X_AXIS_TICK_PADDING)
|
.tickPadding(X_AXIS_TICK_PADDING)
|
||||||
.tickSize(chartHeight);
|
.tickSize(chartHeight);
|
||||||
|
|
||||||
|
@ -153,11 +153,11 @@ describe('grafanaHeatmap', function () {
|
|||||||
it('should draw correct X axis', function () {
|
it('should draw correct X axis', function () {
|
||||||
var xTicks = getTicks(ctx.element, ".axis-x");
|
var xTicks = getTicks(ctx.element, ".axis-x");
|
||||||
let expectedTicks = [
|
let expectedTicks = [
|
||||||
formatLocalTime("01 Mar 2017 10:00:00"),
|
formatTime("01 Mar 2017 10:00:00"),
|
||||||
formatLocalTime("01 Mar 2017 10:15:00"),
|
formatTime("01 Mar 2017 10:15:00"),
|
||||||
formatLocalTime("01 Mar 2017 10:30:00"),
|
formatTime("01 Mar 2017 10:30:00"),
|
||||||
formatLocalTime("01 Mar 2017 10:45:00"),
|
formatTime("01 Mar 2017 10:45:00"),
|
||||||
formatLocalTime("01 Mar 2017 11:00:00")
|
formatTime("01 Mar 2017 11:00:00")
|
||||||
];
|
];
|
||||||
expect(xTicks).to.eql(expectedTicks);
|
expect(xTicks).to.eql(expectedTicks);
|
||||||
});
|
});
|
||||||
@ -261,7 +261,7 @@ function getTicks(element, axisSelector) {
|
|||||||
}).get();
|
}).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatLocalTime(timeStr) {
|
function formatTime(timeStr) {
|
||||||
let format = "HH:mm";
|
let format = "HH:mm";
|
||||||
return moment.utc(timeStr, 'DD MMM YYYY HH:mm:ss').local().format(format);
|
return moment.utc(timeStr, 'DD MMM YYYY HH:mm:ss').format(format);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user