-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
index.ts
71 lines (64 loc) · 2.39 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { CoreSetup, IUiSettingsClient } from 'kibana/public';
import moment from 'moment-timezone';
import { ExpressionsSetup } from '../../../../../src/plugins/expressions/public';
import { EditorFrameSetup, FormatFactory } from '../types';
import { ChartsPluginSetup } from '../../../../../src/plugins/charts/public';
import { LensPluginStartDependencies } from '../plugin';
export interface XyVisualizationPluginSetupPlugins {
expressions: ExpressionsSetup;
formatFactory: Promise<FormatFactory>;
editorFrame: EditorFrameSetup;
charts: ChartsPluginSetup;
}
function getTimeZone(uiSettings: IUiSettingsClient) {
const configuredTimeZone = uiSettings.get('dateFormat:tz');
if (configuredTimeZone === 'Browser') {
return moment.tz.guess();
}
return configuredTimeZone;
}
export class XyVisualization {
constructor() {}
setup(
core: CoreSetup<LensPluginStartDependencies, void>,
{ expressions, formatFactory, editorFrame, charts }: XyVisualizationPluginSetupPlugins
) {
editorFrame.registerVisualization(async () => {
const {
legendConfig,
yAxisConfig,
tickLabelsConfig,
gridlinesConfig,
axisTitlesVisibilityConfig,
layerConfig,
xyChart,
getXyChartRenderer,
getXyVisualization,
} = await import('../async_services');
const [, { data }] = await core.getStartServices();
const palettes = await charts.palettes.getPalettes();
expressions.registerFunction(() => legendConfig);
expressions.registerFunction(() => yAxisConfig);
expressions.registerFunction(() => tickLabelsConfig);
expressions.registerFunction(() => gridlinesConfig);
expressions.registerFunction(() => axisTitlesVisibilityConfig);
expressions.registerFunction(() => layerConfig);
expressions.registerFunction(() => xyChart);
expressions.registerRenderer(
getXyChartRenderer({
formatFactory,
chartsThemeService: charts.theme,
paletteService: palettes,
timeZone: getTimeZone(core.uiSettings),
})
);
return getXyVisualization({ paletteService: palettes, data });
});
}
}