-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy paththeme.ts
574 lines (535 loc) · 14.6 KB
/
theme.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { $Values } from 'utility-types';
import { Color } from '../../common/colors';
import { Pixels, Ratio } from '../../common/geometry';
import { FontStyle } from '../../common/text_utils';
import { ColorVariant, HorizontalAlignment, RecursivePartial, VerticalAlignment } from '../common';
import { Margins, SimplePadding } from '../dimensions';
import { Point } from '../point';
/** @public */
export interface Visible {
visible: boolean;
}
/** @public */
export interface TextStyle {
fontSize: number;
fontFamily: string;
fontStyle?: FontStyle;
fill: Color;
padding: number | SimplePadding;
}
/**
* Offset in pixels
* @public
*/
export interface TextOffset {
/**
* X offset of tick in px or string with % of height
*/
x: number | string;
/**
* X offset of tick in px or string with % of height
*/
y: number | string;
/**
* Offset coordinate system reference
*
* - `global` - aligns offset coordinate system to global (non-rotated) coordinate system
* - `local` - aligns offset coordinate system to local rotated coordinate system
*/
reference: 'global' | 'local';
}
/**
* Text alignment
* @public
*/
export interface TextAlignment {
horizontal: HorizontalAlignment;
vertical: VerticalAlignment;
}
/**
* Shared style properties for varies geometries
* @public
*/
export interface GeometryStyle {
/**
* Opacity multiplier
*
* if set to `0.5` all given opacities will be halfed
*/
opacity: number;
}
/**
* Shared style properties for varies geometries
* @public
*/
export interface GeometryStateStyle {
/**
* Opacity multiplier
*
* if set to `0.5` all given opacities will be halfed
*/
opacity: number;
}
/** @public */
export interface SharedGeometryStateStyle {
default: GeometryStateStyle;
highlighted: GeometryStateStyle;
unhighlighted: GeometryStateStyle;
}
/**
* The stroke color style
* @public
*/
export interface StrokeStyle<C = Color> {
/** The stroke color in hex, rgba, hsl */
stroke: C;
/** The stroke width in pixel */
strokeWidth: number;
}
/** @public */
export type TickStyle = StrokeStyle &
Visible & {
/**
* Amount of padding between tick line and labels
*/
padding: number;
/**
* length of tick line
*/
size: number;
};
/**
* The dash array for a stroke
* @public
*/
export interface StrokeDashArray {
/** The dash array for dashed strokes */
dash: number[];
}
/** @public */
export interface FillStyle {
/** The fill color in hex, rgba, hsl */
fill: Color;
}
/** @public */
export interface Opacity {
/** The opacity value from 0 to 1 */
opacity: number;
}
/** @public */
export interface AxisStyle {
axisTitle: TextStyle & Visible;
axisPanelTitle: TextStyle & Visible;
axisLine: StrokeStyle & Visible;
tickLabel: TextStyle &
Visible & {
/** The degrees of rotation of the tick labels */
rotation: number;
/**
* Offset in pixels to render text relative to anchor
*
* **Note:** rotation aligns to global cartesian coordinates
*/
offset: TextOffset;
alignment: TextAlignment;
};
tickLine: TickStyle;
gridLine: {
horizontal: GridLineStyle;
vertical: GridLineStyle;
lumaSteps: number[];
};
}
/**
* @public
*/
export interface GridLineStyle {
visible: boolean;
stroke: Color;
strokeWidth: number;
opacity: number;
dash: number[];
}
/**
* @public
*/
export interface GoalStyles {
progressLine: Pick<StrokeStyle, 'stroke'>;
targetLine: Pick<StrokeStyle, 'stroke'>;
tickLine: Pick<StrokeStyle, 'stroke'>;
tickLabel: Omit<TextStyle, 'padding' | 'fontSize'>;
majorLabel: Omit<TextStyle, 'padding' | 'fontSize'>;
minorLabel: Omit<TextStyle, 'padding' | 'fontSize'>;
majorCenterLabel: Omit<TextStyle, 'padding' | 'fontSize'>;
minorCenterLabel: Omit<TextStyle, 'padding' | 'fontSize'>;
minFontSize: number;
maxFontSize: number;
}
/** @public */
export interface ScalesConfig {
/**
* The proportion of the range that is reserved for blank space between bands.
* A value of 0 means no blank space between bands, and a value of 1 means a bandwidth of zero.
* A number between 0 and 1.
*/
barsPadding: number;
/**
* The proportion of the range that is reserved for blank space between bands in histogramMode.
* A value of 0 means no blank space between bands, and a value of 1 means a bandwidth of zero.
* A number between 0 and 1.
*/
histogramPadding: number;
}
/** @public */
export interface ColorConfig {
vizColors: Color[];
defaultVizColor: Color;
}
/**
* The background style applied to the chart.
* This is used to coordinate adequate contrast of the text in partition and treemap charts.
* @public
*/
export interface BackgroundStyle {
/**
* The background color
*/
color: string;
}
/** @public */
export interface LegendLabelOptions {
/**
* Sets maxlines allowable before truncating
*
* Setting value to `0` will _never_ truncate the text
*
* @defaultValue 1
*/
maxLines: number;
}
/** @public */
export interface LegendStyle {
/**
* Max width used for left/right legend
*
* or
*
* Width of `LegendItem` for top/bottom legend
*/
verticalWidth: number;
/**
* Max height used for top/bottom legend
*/
horizontalHeight: number;
/**
* Added buffer between label and value.
*
* Smaller values render a more compact legend
*/
spacingBuffer: number;
/**
* Legend padding. The Chart margins are independent of the legend.
*
* TODO: make SimplePadding when after axis changes are added
*/
margin: number;
/**
* Options to control legend labels
*/
labelOptions: LegendLabelOptions;
}
/** @public */
export interface Theme {
/**
* Space btw parent DOM element and first available element of the chart (axis if exists, else the chart itself)
*/
chartMargins: Margins;
/**
* Space btw the chart geometries and axis; if no axis, pads space btw chart & container
*/
chartPaddings: Margins;
/**
* Global line styles.
*
* __Note:__ This is not used to set the color of a specific series. As such, any changes to the styles will not be reflected in the tooltip, legend, etc..
*
* You may use `SeriesColorAccessor` to assign colors to a given series or replace the `theme.colors.vizColors` colors to your desired colors.
*/
lineSeriesStyle: LineSeriesStyle;
/**
* Global area styles.
*
* __Note:__ This is not used to set the color of a specific series. As such, any changes to the styles will not be reflected in the tooltip, legend, etc..
*
* You may use `SeriesColorAccessor` to assign colors to a given series or replace the `theme.colors.vizColors` colors to your desired colors.
*/
areaSeriesStyle: AreaSeriesStyle;
/**
* Global bar styles.
*
* __Note:__ This is not used to set the color of a specific series. As such, any changes to the styles will not be reflected in the tooltip, legend, etc..
*
* You may use `SeriesColorAccessor` to assign colors to a given series or replace the `theme.colors.vizColors` colors to your desired colors.
*/
barSeriesStyle: BarSeriesStyle;
/**
* Global bubble styles.
*
* __Note:__ This is not used to set the color of a specific series. As such, any changes to the styles will not be reflected in the tooltip, legend, etc..
*
* You may use `SeriesColorAccessor` to assign colors to a given series or replace the `theme.colors.vizColors` colors to your desired colors.
*/
bubbleSeriesStyle: BubbleSeriesStyle;
arcSeriesStyle: ArcSeriesStyle;
sharedStyle: SharedGeometryStateStyle;
axes: AxisStyle;
scales: ScalesConfig;
colors: ColorConfig;
legend: LegendStyle;
crosshair: CrosshairStyle;
/**
* Used to scale radius with `markSizeAccessor`
*
* value from 1 to 100
*/
markSizeRatio?: number;
/**
* The background allows the consumer to provide a color of the background container of the chart.
* This can then be used to calculate the contrast of the text for partition charts.
*/
background: BackgroundStyle;
goal: GoalStyles;
}
/** @public */
export type PartialTheme = RecursivePartial<Theme>;
/** @public */
export type DisplayValueStyle = Omit<TextStyle, 'fill' | 'fontSize'> & {
offsetX: number;
offsetY: number;
fontSize:
| number
| {
min: number;
max: number;
};
fill:
| Color
| { color: Color; borderColor?: Color; borderWidth?: number }
| {
textBorder?: number;
};
alignment?: {
horizontal: Exclude<HorizontalAlignment, 'far' | 'near'>;
vertical: Exclude<VerticalAlignment, 'far' | 'near'>;
};
};
/** @public */
export const PointShape = Object.freeze({
Circle: 'circle' as const,
Square: 'square' as const,
Diamond: 'diamond' as const,
Plus: 'plus' as const,
X: 'x' as const,
Triangle: 'triangle' as const,
});
/** @public */
export type PointShape = $Values<typeof PointShape>;
/** @public */
export interface PointStyle {
/** is the point visible or hidden */
visible: boolean;
/** a static stroke color if defined, if not it will use the color of the series */
stroke?: Color | ColorVariant;
/** the stroke width of the point */
strokeWidth: number;
/** a static fill color if defined, if not it will use the color of the series */
fill?: Color | ColorVariant;
/** the opacity of each point on the theme/series */
opacity: number;
/** the radius of each point of the theme/series */
radius: number;
/** shape for the point, default to circle */
shape?: PointShape;
}
/** @public */
export interface LineStyle {
/** is the line visible or hidden ? */
visible: boolean;
/** a static stroke color if defined, if not it will use the color of the series */
stroke?: Color | ColorVariant;
/** the stroke width of the line */
strokeWidth: number;
/** the opacity of each line on the theme/series */
opacity: number;
/** the dash array */
dash?: number[];
}
/** @public */
export const TextureShape = Object.freeze({
...PointShape,
Line: 'line' as const,
});
/** @public */
export type TextureShape = $Values<typeof TextureShape>;
/** @public */
export interface TexturedStylesBase {
/** polygon fill color for texture */
fill?: Color | ColorVariant;
/** polygon stroke color for texture */
stroke?: Color | ColorVariant;
/** polygon stroke width for texture */
strokeWidth?: number;
/** polygon opacity for texture */
opacity?: number;
/** polygon opacity for texture */
dash?: number[];
/** polygon opacity for texture */
size?: number;
/**
* The angle of rotation for entire texture
* in degrees
*/
rotation?: number;
/**
* The angle of rotation for polygons
* in degrees
*/
shapeRotation?: number;
/** texture spacing between polygons */
spacing?: Partial<Point> | number;
/** overall origin offset of pattern */
offset?: Partial<Point> & {
/** apply offset along global coordinate axes */
global?: boolean;
};
}
/** @public */
export interface TexturedShapeStyles extends TexturedStylesBase {
/** typed of texture designs currently supported */
shape: TextureShape;
}
/** @public */
export interface TexturedPathStyles extends TexturedStylesBase {
/** path for polygon texture */
path: string | Path2D;
}
/**
* @public
*
* Texture style config for area spec
*/
export type TexturedStyles = TexturedPathStyles | TexturedShapeStyles;
/** @public */
export interface AreaStyle {
/** applying textures to the area on the theme/series */
texture?: TexturedStyles;
/** is the area is visible or hidden ? */
visible: boolean;
/** a static fill color if defined, if not it will use the color of the series */
fill?: Color | ColorVariant;
/** the opacity of each area on the theme/series */
opacity: number;
}
/** @public */
export interface ArcStyle {
/** is the arc is visible or hidden ? */
visible: boolean;
/** a static fill color if defined, if not it will use the color of the series */
fill?: Color | ColorVariant;
/** a static stroke color if defined, if not it will use the color of the series */
stroke?: Color | ColorVariant;
/** the stroke width of the line */
strokeWidth: number;
/** the opacity of each arc on the theme/series */
opacity: number;
}
/** @public */
export interface RectStyle {
/** a static fill color if defined, if not it will use the color of the series */
fill?: Color | ColorVariant;
/** the opacity of each rect on the theme/series */
opacity: number;
/** The width of the rect in pixel. If expressed together with `widthRatio` then the `widthRatio`
* will express the max available size, where the `widthPixel` express the derived/min width. */
widthPixel?: Pixels;
/** The ratio of the width limited to [0,1]. If expressed together with `widthPixel` then the `widthRatio`
* will express the max available size, where the `widthPixel` express the derived/min width. */
widthRatio?: Ratio;
/** applying textures to the bar on the theme/series */
texture?: TexturedStyles;
}
/** @public */
export interface RectBorderStyle {
/**
* Border visibility
*/
visible: boolean;
/**
* Border stroke color
*/
stroke?: Color | ColorVariant;
/**
* Border stroke width
*/
strokeWidth: number;
/**
* Border stroke opacity
*/
strokeOpacity?: number;
}
/** @public */
export interface BarSeriesStyle {
rect: RectStyle;
rectBorder: RectBorderStyle;
displayValue: DisplayValueStyle;
}
/** @public */
export interface BubbleSeriesStyle {
point: PointStyle;
}
/** @public */
export interface LineSeriesStyle {
line: LineStyle;
point: PointStyle;
}
/** @public */
export interface AreaSeriesStyle {
area: AreaStyle;
line: LineStyle;
point: PointStyle;
}
/** @public */
export interface ArcSeriesStyle {
arc: ArcStyle;
}
/** @public */
export interface CrosshairStyle {
band: FillStyle & Visible;
line: StrokeStyle & Visible & Partial<StrokeDashArray>;
crossLine: StrokeStyle & Visible & Partial<StrokeDashArray>;
}
/**
* The style for a linear annotation
* @public
*/
export interface LineAnnotationStyle {
/**
* The style for the line geometry
*/
line: StrokeStyle & Opacity & Partial<StrokeDashArray>;
/**
* The style for the text shown on the tooltip.
* @deprecated This style is not currently used and will
* soon be removed.
*/
details: TextStyle;
}
/** @public */
export type RectAnnotationStyle = StrokeStyle & FillStyle & Opacity & Partial<StrokeDashArray>;