diff --git a/public/app/plugins/panel/graph/specs/time_region_manager.test.ts b/public/app/plugins/panel/graph/specs/time_region_manager.test.ts index 35e48897282..7ac9e658b83 100644 --- a/public/app/plugins/panel/graph/specs/time_region_manager.test.ts +++ b/public/app/plugins/panel/graph/specs/time_region_manager.test.ts @@ -130,6 +130,33 @@ describe('TimeRegionManager', () => { }); }); + plotOptionsScenario('for time from/to region', ctx => { + const regions = [{ from: '00:00', to: '05:00', fill: true, colorMode: 'red' }]; + const from = moment('2018-12-01T00:00+01:00'); + const to = moment('2018-12-03T23:59+01:00'); + ctx.setup(regions, from, to); + + it('should add 3 markings', () => { + expect(ctx.options.grid.markings.length).toBe(3); + }); + + it('should add one fill between 00:00 and 05:00 each day', () => { + const markings = ctx.options.grid.markings; + + expect(moment(markings[0].xaxis.from).format()).toBe(moment('2018-12-01T01:00:00+01:00').format()); + expect(moment(markings[0].xaxis.to).format()).toBe(moment('2018-12-01T06:00:00+01:00').format()); + expect(markings[0].color).toBe(colorModes.red.color.fill); + + expect(moment(markings[1].xaxis.from).format()).toBe(moment('2018-12-02T01:00:00+01:00').format()); + expect(moment(markings[1].xaxis.to).format()).toBe(moment('2018-12-02T06:00:00+01:00').format()); + expect(markings[1].color).toBe(colorModes.red.color.fill); + + expect(moment(markings[2].xaxis.from).format()).toBe(moment('2018-12-03T01:00:00+01:00').format()); + expect(moment(markings[2].xaxis.to).format()).toBe(moment('2018-12-03T06:00:00+01:00').format()); + expect(markings[2].color).toBe(colorModes.red.color.fill); + }); + }); + plotOptionsScenario('for day of week from/to region', ctx => { const regions = [{ fromDayOfWeek: 7, toDayOfWeek: 7, fill: true, colorMode: 'red' }]; const from = moment('2018-01-01T18:45:05+01:00'); diff --git a/public/app/plugins/panel/graph/time_region_manager.ts b/public/app/plugins/panel/graph/time_region_manager.ts index 95987e40dbe..0c9b94c9013 100644 --- a/public/app/plugins/panel/graph/time_region_manager.ts +++ b/public/app/plugins/panel/graph/time_region_manager.ts @@ -87,6 +87,14 @@ export class TimeRegionManager { continue; } + if (timeRegion.from && !timeRegion.to) { + timeRegion.to = timeRegion.from; + } + + if (!timeRegion.from && timeRegion.to) { + timeRegion.from = timeRegion.to; + } + hRange = { from: this.parseTimeRange(timeRegion.from), to: this.parseTimeRange(timeRegion.to), @@ -108,21 +116,13 @@ export class TimeRegionManager { hRange.to.dayOfWeek = Number(timeRegion.toDayOfWeek); } - if (!hRange.from.h && hRange.to.h) { - hRange.from = hRange.to; - } - - if (hRange.from.h && !hRange.to.h) { - hRange.to = hRange.from; - } - - if (hRange.from.dayOfWeek && !hRange.from.h && !hRange.from.m) { + if (hRange.from.dayOfWeek && hRange.from.h === null && hRange.from.m === null) { hRange.from.h = 0; hRange.from.m = 0; hRange.from.s = 0; } - if (hRange.to.dayOfWeek && !hRange.to.h && !hRange.to.m) { + if (hRange.to.dayOfWeek && hRange.to.h === null && hRange.to.m === null) { hRange.to.h = 23; hRange.to.m = 59; hRange.to.s = 59;