-
Notifications
You must be signed in to change notification settings - Fork 8k
/
types.ts
329 lines (301 loc) · 9.21 KB
/
types.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
* 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 { i18n } from '@kbn/i18n';
import { $Values } from '@kbn/utility-types';
import type { PaletteOutput } from '@kbn/coloring';
import type {
LegendConfig,
AxisExtentConfig,
XYCurveType,
FittingFunction,
EndValue,
YScaleType,
XScaleType,
LineStyle,
IconPosition,
FillStyle,
YAxisConfig,
} from '@kbn/expression-xy-plugin/common';
import {
EventAnnotationConfig,
EventAnnotationGroupConfig,
} from '@kbn/event-annotation-plugin/common';
import {
IconChartArea,
IconChartLine,
IconChartAreaStacked,
IconChartBarHorizontalStacked,
IconChartBarHorizontalPercentage,
IconChartAreaPercentage,
IconChartBar,
IconChartBarStacked,
IconChartBarPercentage,
IconChartBarHorizontal,
} from '@kbn/chart-icons';
import { CollapseFunction } from '../../../common/expressions';
import type { VisualizationType } from '../../types';
import type { ValueLabelConfig } from '../../../common/types';
export const YAxisModes = {
AUTO: 'auto',
LEFT: 'left',
RIGHT: 'right',
BOTTOM: 'bottom',
} as const;
export const SeriesTypes = {
BAR: 'bar',
LINE: 'line',
AREA: 'area',
BAR_STACKED: 'bar_stacked',
AREA_STACKED: 'area_stacked',
BAR_HORIZONTAL: 'bar_horizontal',
BAR_PERCENTAGE_STACKED: 'bar_percentage_stacked',
BAR_HORIZONTAL_STACKED: 'bar_horizontal_stacked',
AREA_PERCENTAGE_STACKED: 'area_percentage_stacked',
BAR_HORIZONTAL_PERCENTAGE_STACKED: 'bar_horizontal_percentage_stacked',
} as const;
export type YAxisMode = $Values<typeof YAxisModes>;
export type SeriesType = $Values<typeof SeriesTypes>;
export interface AxesSettingsConfig {
x: boolean;
yRight: boolean;
yLeft: boolean;
}
export interface AxisConfig extends Omit<YAxisConfig, 'extent'> {
extent?: AxisExtentConfig;
}
export interface LabelsOrientationConfig {
x: number;
yLeft: number;
yRight: number;
}
export interface YConfig {
forAccessor: string;
color?: string;
icon?: string;
lineWidth?: number;
lineStyle?: Exclude<LineStyle, 'dot-dashed'>;
fill?: FillStyle;
iconPosition?: IconPosition;
textVisibility?: boolean;
axisMode?: YAxisMode;
}
export interface XYDataLayerConfig {
layerId: string;
accessors: string[];
layerType: 'data';
seriesType: SeriesType;
xAccessor?: string;
simpleView?: boolean;
yConfig?: YConfig[];
splitAccessor?: string;
palette?: PaletteOutput;
collapseFn?: CollapseFunction;
xScaleType?: XScaleType;
isHistogram?: boolean;
columnToLabel?: string;
}
export interface XYReferenceLineLayerConfig {
layerId: string;
accessors: string[];
yConfig?: YConfig[];
layerType: 'referenceLine';
}
export interface XYByValueAnnotationLayerConfig {
layerId: string;
layerType: 'annotations';
annotations: EventAnnotationConfig[];
indexPatternId: string;
ignoreGlobalFilters: boolean;
}
export type XYPersistedByValueAnnotationLayerConfig = Omit<
XYByValueAnnotationLayerConfig,
'indexPatternId' | 'hide' | 'simpleView'
> & { persistanceType?: 'byValue'; hide?: boolean; simpleView?: boolean }; // props made optional for backwards compatibility since this is how the existing saved objects are
export type XYByReferenceAnnotationLayerConfig = XYByValueAnnotationLayerConfig & {
annotationGroupId: string;
__lastSaved: EventAnnotationGroupConfig;
};
export type XYPersistedByReferenceAnnotationLayerConfig = Pick<
XYByValueAnnotationLayerConfig,
'layerId' | 'layerType'
> & {
persistanceType: 'byReference';
annotationGroupRef: string;
};
/**
* This is the type of hybrid layer we get after the user has made a change to
* a by-reference annotation layer and saved the visualization without
* first saving the changes to the library annotation layer.
*
* We maintain the link to the library annotation group, but allow the users
* changes (persisted in the visualization state) to override the attributes in
* the library version until the user
* - saves the changes to the library annotation group
* - reverts the changes
* - unlinks the layer from the library annotation group
*/
export type XYPersistedLinkedByValueAnnotationLayerConfig = Omit<
XYPersistedByValueAnnotationLayerConfig,
'persistanceType'
> &
Omit<XYPersistedByReferenceAnnotationLayerConfig, 'persistanceType'> & {
persistanceType: 'linked';
};
export type XYAnnotationLayerConfig =
| XYByReferenceAnnotationLayerConfig
| XYByValueAnnotationLayerConfig;
export type XYPersistedAnnotationLayerConfig =
| XYPersistedByReferenceAnnotationLayerConfig
| XYPersistedByValueAnnotationLayerConfig
| XYPersistedLinkedByValueAnnotationLayerConfig;
export type XYPersistedLayerConfig =
| XYDataLayerConfig
| XYReferenceLineLayerConfig
| XYPersistedAnnotationLayerConfig;
export type XYLayerConfig =
| XYDataLayerConfig
| XYReferenceLineLayerConfig
| XYAnnotationLayerConfig;
export interface ValidXYDataLayerConfig extends XYDataLayerConfig {
xAccessor: NonNullable<XYDataLayerConfig['xAccessor']>;
layerId: string;
}
export type ValidLayer = ValidXYDataLayerConfig | XYReferenceLineLayerConfig;
// Persisted parts of the state
export interface XYState {
preferredSeriesType: SeriesType;
legend: LegendConfig;
valueLabels?: ValueLabelConfig;
fittingFunction?: FittingFunction;
emphasizeFitting?: boolean;
endValue?: EndValue;
xExtent?: AxisExtentConfig;
yLeftExtent?: AxisExtentConfig;
yRightExtent?: AxisExtentConfig;
layers: XYLayerConfig[];
xTitle?: string;
yTitle?: string;
yRightTitle?: string;
yLeftScale?: YScaleType;
yRightScale?: YScaleType;
axisTitlesVisibilitySettings?: AxesSettingsConfig;
tickLabelsVisibilitySettings?: AxesSettingsConfig;
gridlinesVisibilitySettings?: AxesSettingsConfig;
labelsOrientation?: LabelsOrientationConfig;
curveType?: XYCurveType;
fillOpacity?: number;
hideEndzones?: boolean;
showCurrentTimeMarker?: boolean;
valuesInLegend?: boolean;
}
export type State = XYState;
export type XYPersistedState = Omit<XYState, 'layers'> & {
layers: XYPersistedLayerConfig[];
};
export type PersistedState = XYPersistedState;
const groupLabelForBar = i18n.translate('xpack.lens.xyVisualization.barGroupLabel', {
defaultMessage: 'Bar',
});
const groupLabelForLineAndArea = i18n.translate('xpack.lens.xyVisualization.lineGroupLabel', {
defaultMessage: 'Line and area',
});
export const visualizationTypes: VisualizationType[] = [
{
id: 'bar',
icon: IconChartBar,
label: i18n.translate('xpack.lens.xyVisualization.barLabel', {
defaultMessage: 'Bar vertical',
}),
groupLabel: groupLabelForBar,
sortPriority: 4,
},
{
id: 'bar_horizontal',
icon: IconChartBarHorizontal,
label: i18n.translate('xpack.lens.xyVisualization.barHorizontalLabel', {
defaultMessage: 'H. Bar',
}),
fullLabel: i18n.translate('xpack.lens.xyVisualization.barHorizontalFullLabel', {
defaultMessage: 'Bar horizontal',
}),
groupLabel: groupLabelForBar,
},
{
id: 'bar_stacked',
icon: IconChartBarStacked,
label: i18n.translate('xpack.lens.xyVisualization.stackedBarLabel', {
defaultMessage: 'Bar vertical stacked',
}),
groupLabel: groupLabelForBar,
},
{
id: 'bar_percentage_stacked',
icon: IconChartBarPercentage,
label: i18n.translate('xpack.lens.xyVisualization.stackedPercentageBarLabel', {
defaultMessage: 'Bar vertical percentage',
}),
groupLabel: groupLabelForBar,
},
{
id: 'bar_horizontal_stacked',
icon: IconChartBarHorizontalStacked,
label: i18n.translate('xpack.lens.xyVisualization.stackedBarHorizontalLabel', {
defaultMessage: 'H. Stacked bar',
}),
fullLabel: i18n.translate('xpack.lens.xyVisualization.stackedBarHorizontalFullLabel', {
defaultMessage: 'Bar horizontal stacked',
}),
groupLabel: groupLabelForBar,
},
{
id: 'bar_horizontal_percentage_stacked',
icon: IconChartBarHorizontalPercentage,
label: i18n.translate('xpack.lens.xyVisualization.stackedPercentageBarHorizontalLabel', {
defaultMessage: 'H. Percentage bar',
}),
fullLabel: i18n.translate(
'xpack.lens.xyVisualization.stackedPercentageBarHorizontalFullLabel',
{
defaultMessage: 'Bar horizontal percentage',
}
),
groupLabel: groupLabelForBar,
},
{
id: 'area',
icon: IconChartArea,
label: i18n.translate('xpack.lens.xyVisualization.areaLabel', {
defaultMessage: 'Area',
}),
groupLabel: groupLabelForLineAndArea,
},
{
id: 'area_stacked',
icon: IconChartAreaStacked,
label: i18n.translate('xpack.lens.xyVisualization.stackedAreaLabel', {
defaultMessage: 'Area stacked',
}),
groupLabel: groupLabelForLineAndArea,
},
{
id: 'area_percentage_stacked',
icon: IconChartAreaPercentage,
label: i18n.translate('xpack.lens.xyVisualization.stackedPercentageAreaLabel', {
defaultMessage: 'Area percentage',
}),
groupLabel: groupLabelForLineAndArea,
},
{
id: 'line',
icon: IconChartLine,
label: i18n.translate('xpack.lens.xyVisualization.lineLabel', {
defaultMessage: 'Line',
}),
groupLabel: groupLabelForLineAndArea,
sortPriority: 2,
},
];