-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
widget.ts
57 lines (48 loc) · 1.19 KB
/
widget.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
/**
* The width of the grid we're filling
*/
export const GRID_WIDTH = 24;
/**
* A single dashboard widget
*/
export interface IWidget {
/**
* The amount of horizontal grid units the widget will take up
*/
readonly width: number;
/**
* The amount of vertical grid units the widget will take up
*/
readonly height: number;
/**
* Place the widget at a given position
*/
position(x: number, y: number): void;
/**
* Return the widget JSON for use in the dashboard
*/
toJson(): any[];
}
/**
* A real CloudWatch widget that has its own fixed size and remembers its position
*
* This is in contrast to other widgets which exist for layout purposes.
*/
export abstract class ConcreteWidget implements IWidget {
public readonly width: number;
public readonly height: number;
protected x?: number;
protected y?: number;
constructor(width: number, height: number) {
this.width = width;
this.height = height;
if (this.width > GRID_WIDTH) {
throw new Error(`Widget is too wide, max ${GRID_WIDTH} units allowed`);
}
}
public position(x: number, y: number): void {
this.x = x;
this.y = y;
}
public abstract toJson(): any[];
}