mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
GraphNG: cache ianaName & reduce calls to getTimeZoneInfo() (#31712)
This commit is contained in:
parent
56ce068a91
commit
a5f3889b93
@ -43,7 +43,6 @@ UPlotConfigBuilder {
|
|||||||
"x": false,
|
"x": false,
|
||||||
"y": false,
|
"y": false,
|
||||||
},
|
},
|
||||||
"getTimeZone": [Function],
|
|
||||||
"hasBottomAxis": true,
|
"hasBottomAxis": true,
|
||||||
"hasLeftAxis": true,
|
"hasLeftAxis": true,
|
||||||
"hooks": Object {
|
"hooks": Object {
|
||||||
@ -116,6 +115,7 @@ UPlotConfigBuilder {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tz": "UTC",
|
||||||
"tzDate": [Function],
|
"tzDate": [Function],
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@ -163,7 +163,6 @@ UPlotConfigBuilder {
|
|||||||
"x": false,
|
"x": false,
|
||||||
"y": false,
|
"y": false,
|
||||||
},
|
},
|
||||||
"getTimeZone": [Function],
|
|
||||||
"hasBottomAxis": true,
|
"hasBottomAxis": true,
|
||||||
"hasLeftAxis": true,
|
"hasLeftAxis": true,
|
||||||
"hooks": Object {
|
"hooks": Object {
|
||||||
@ -236,6 +235,7 @@ UPlotConfigBuilder {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tz": "UTC",
|
||||||
"tzDate": [Function],
|
"tzDate": [Function],
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@ -283,7 +283,6 @@ UPlotConfigBuilder {
|
|||||||
"x": false,
|
"x": false,
|
||||||
"y": false,
|
"y": false,
|
||||||
},
|
},
|
||||||
"getTimeZone": [Function],
|
|
||||||
"hasBottomAxis": true,
|
"hasBottomAxis": true,
|
||||||
"hasLeftAxis": true,
|
"hasLeftAxis": true,
|
||||||
"hooks": Object {
|
"hooks": Object {
|
||||||
@ -356,6 +355,7 @@ UPlotConfigBuilder {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tz": "UTC",
|
||||||
"tzDate": [Function],
|
"tzDate": [Function],
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@ -403,7 +403,6 @@ UPlotConfigBuilder {
|
|||||||
"x": false,
|
"x": false,
|
||||||
"y": false,
|
"y": false,
|
||||||
},
|
},
|
||||||
"getTimeZone": [Function],
|
|
||||||
"hasBottomAxis": true,
|
"hasBottomAxis": true,
|
||||||
"hasLeftAxis": true,
|
"hasLeftAxis": true,
|
||||||
"hooks": Object {
|
"hooks": Object {
|
||||||
@ -476,6 +475,7 @@ UPlotConfigBuilder {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tz": "UTC",
|
||||||
"tzDate": [Function],
|
"tzDate": [Function],
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@ -523,7 +523,6 @@ UPlotConfigBuilder {
|
|||||||
"x": false,
|
"x": false,
|
||||||
"y": false,
|
"y": false,
|
||||||
},
|
},
|
||||||
"getTimeZone": [Function],
|
|
||||||
"hasBottomAxis": true,
|
"hasBottomAxis": true,
|
||||||
"hasLeftAxis": true,
|
"hasLeftAxis": true,
|
||||||
"hooks": Object {
|
"hooks": Object {
|
||||||
@ -596,6 +595,7 @@ UPlotConfigBuilder {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tz": "UTC",
|
||||||
"tzDate": [Function],
|
"tzDate": [Function],
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@ -643,7 +643,6 @@ UPlotConfigBuilder {
|
|||||||
"x": false,
|
"x": false,
|
||||||
"y": false,
|
"y": false,
|
||||||
},
|
},
|
||||||
"getTimeZone": [Function],
|
|
||||||
"hasBottomAxis": true,
|
"hasBottomAxis": true,
|
||||||
"hasLeftAxis": true,
|
"hasLeftAxis": true,
|
||||||
"hooks": Object {
|
"hooks": Object {
|
||||||
@ -716,6 +715,7 @@ UPlotConfigBuilder {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tz": "UTC",
|
||||||
"tzDate": [Function],
|
"tzDate": [Function],
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@ -763,7 +763,6 @@ UPlotConfigBuilder {
|
|||||||
"x": false,
|
"x": false,
|
||||||
"y": false,
|
"y": false,
|
||||||
},
|
},
|
||||||
"getTimeZone": [Function],
|
|
||||||
"hasBottomAxis": true,
|
"hasBottomAxis": true,
|
||||||
"hasLeftAxis": true,
|
"hasLeftAxis": true,
|
||||||
"hooks": Object {
|
"hooks": Object {
|
||||||
@ -836,6 +835,7 @@ UPlotConfigBuilder {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tz": "UTC",
|
||||||
"tzDate": [Function],
|
"tzDate": [Function],
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@ -883,7 +883,6 @@ UPlotConfigBuilder {
|
|||||||
"x": false,
|
"x": false,
|
||||||
"y": false,
|
"y": false,
|
||||||
},
|
},
|
||||||
"getTimeZone": [Function],
|
|
||||||
"hasBottomAxis": true,
|
"hasBottomAxis": true,
|
||||||
"hasLeftAxis": true,
|
"hasLeftAxis": true,
|
||||||
"hooks": Object {
|
"hooks": Object {
|
||||||
@ -956,6 +955,7 @@ UPlotConfigBuilder {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tz": "UTC",
|
||||||
"tzDate": [Function],
|
"tzDate": [Function],
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
@ -54,6 +54,11 @@ function mockDataFrame() {
|
|||||||
return preparePlotFrame([df1, df2]);
|
return preparePlotFrame([df1, df2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jest.mock('@grafana/data', () => ({
|
||||||
|
...(jest.requireActual('@grafana/data') as any),
|
||||||
|
DefaultTimeZone: 'utc',
|
||||||
|
}));
|
||||||
|
|
||||||
describe('GraphNG utils', () => {
|
describe('GraphNG utils', () => {
|
||||||
describe('preparePlotConfigBuilder', () => {
|
describe('preparePlotConfigBuilder', () => {
|
||||||
const frame = mockDataFrame();
|
const frame = mockDataFrame();
|
||||||
|
@ -27,12 +27,11 @@ UPlotConfigBuilder {
|
|||||||
"panelBg": "#000000",
|
"panelBg": "#000000",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"timeZone": "browser",
|
"timeZone": "utc",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"bands": Array [],
|
"bands": Array [],
|
||||||
"getTimeZone": [Function],
|
|
||||||
"hasBottomAxis": true,
|
"hasBottomAxis": true,
|
||||||
"hasLeftAxis": true,
|
"hasLeftAxis": true,
|
||||||
"hooks": Object {},
|
"hooks": Object {},
|
||||||
@ -148,6 +147,7 @@ UPlotConfigBuilder {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"tz": "UTC",
|
||||||
"tzDate": [Function],
|
"tzDate": [Function],
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
@ -79,6 +79,11 @@ function mockDataFrame() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jest.mock('@grafana/data', () => ({
|
||||||
|
...(jest.requireActual('@grafana/data') as any),
|
||||||
|
DefaultTimeZone: 'utc',
|
||||||
|
}));
|
||||||
|
|
||||||
describe('GraphNG utils', () => {
|
describe('GraphNG utils', () => {
|
||||||
test('preparePlotConfigBuilder', () => {
|
test('preparePlotConfigBuilder', () => {
|
||||||
const frame = mockDataFrame();
|
const frame = mockDataFrame();
|
||||||
|
@ -20,8 +20,11 @@ export class UPlotConfigBuilder {
|
|||||||
private hasLeftAxis = false;
|
private hasLeftAxis = false;
|
||||||
private hasBottomAxis = false;
|
private hasBottomAxis = false;
|
||||||
private hooks: Hooks.Arrays = {};
|
private hooks: Hooks.Arrays = {};
|
||||||
|
private tz: string | undefined = undefined;
|
||||||
|
|
||||||
constructor(private getTimeZone = () => DefaultTimeZone) {}
|
constructor(getTimeZone = () => DefaultTimeZone) {
|
||||||
|
this.tz = getTimeZoneInfo(getTimeZone(), Date.now())?.ianaName;
|
||||||
|
}
|
||||||
|
|
||||||
addHook(type: keyof Hooks.Defs, hook: valueof<Hooks.Defs>) {
|
addHook(type: keyof Hooks.Defs, hook: valueof<Hooks.Defs>) {
|
||||||
if (!this.hooks[type]) {
|
if (!this.hooks[type]) {
|
||||||
@ -166,15 +169,8 @@ export class UPlotConfigBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private tzDate = (ts: number) => {
|
private tzDate = (ts: number) => {
|
||||||
if (!this.getTimeZone) {
|
let date = new Date(ts);
|
||||||
return new Date(ts);
|
|
||||||
}
|
|
||||||
const tz = getTimeZoneInfo(this.getTimeZone(), Date.now())?.ianaName;
|
|
||||||
|
|
||||||
if (!tz) {
|
return this.tz ? uPlot.tzDate(date, this.tz) : date;
|
||||||
return new Date(ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
return uPlot.tzDate(new Date(ts), tz);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user