Skip to content

Commit fa101c6

Browse files
committed
JS API TS declaration file extended with template string literal types.
1 parent 1da5e2a commit fa101c6

File tree

1 file changed

+49
-28
lines changed

1 file changed

+49
-28
lines changed

src/apps/weblib/js-api/vizzu.d.ts

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1+
type SeriesName = string;
2+
13
interface DataSeries {
2-
name: string,
4+
name: SeriesName;
35
type: 'categories'|'values';
46
values: string[]|number[];
57
}
68

9+
interface Record {
10+
[key: SeriesName]: string|number;
11+
}
12+
713
interface DataSet {
814
series: DataSeries[];
915
filter: (record: any) => boolean;
1016
}
1117

1218
interface Channel {
1319
title: string|null;
14-
attach: string[];
15-
detach: string[];
16-
range: string;
20+
attach: SeriesName[];
21+
detach: SeriesName[];
22+
range: `${number},${number},${number}`;
1723
labelLevel: number;
1824
}
1925

@@ -39,37 +45,47 @@ interface Descriptor {
3945
split: boolean;
4046
}
4147

48+
type Length = `${number}px`|`${number}%`|number;
49+
50+
type Color = `#${number}`
51+
|`rgb(${number},${number},${number})`
52+
|`rgba(${number},${number},${number},${number})`;
53+
4254
interface Padding {
43-
paddingTop: number|string;
44-
paddingRight: number|string;
45-
paddingBottom: number|string;
46-
paddingLeft: number|string;
55+
paddingTop: Length;
56+
paddingRight: Length;
57+
paddingBottom: Length;
58+
paddingLeft: Length;
4759
}
4860

4961
interface Font {
5062
fontFamily: string;
5163
fontStyle: 'normal'|'italic'|'oblique';
5264
fontWeight: 'normal'|'bold'|number;
53-
fontSize: number|string;
65+
fontSize: Length;
5466
}
5567

5668
interface Box {
57-
backgroundColor: string;
58-
borderColor: string;
69+
backgroundColor: Color;
70+
borderColor: Color;
5971
borderWidth: number;
6072
}
6173

6274
interface Text {
63-
color: string;
75+
color: Color;
6476
textAlign: 'center'|'left'|'right';
65-
backgroundColor: string;
77+
backgroundColor: Color;
6678
overflow: 'visible'|'hidden';
6779
numberFormat: 'none'|'groupped'|'prefixed';
6880
}
6981

82+
type ColorTransform = `color(${Color})`
83+
| `lightness(${number})`
84+
| `grayscale(${number})`;
85+
7086
interface MarkerLabel extends Label {
7187
position: 'below'|'center'|'above';
72-
filter: string;
88+
filter: ColorTransform;
7389
format: 'valueFirst'|'categoriesFirst';
7490
}
7591

@@ -79,28 +95,28 @@ interface Marker {
7995
borderOpacityMode: 'straight'|'premultiplied';
8096
fillOpacity: number;
8197
guides: {
82-
color: string;
98+
color: Color;
8399
lineWidth: number;
84100
};
85101
label: MarkerLabel;
86102
}
87103

88104
interface Axis {
89-
color: string;
105+
color: Color;
90106
title: Label;
91107
label: Label;
92108
ticks: {
93-
color: string;
109+
color: Color;
94110
lineWidth: number;
95-
length: number|string;
111+
length: Length;
96112
position: 'outside'|'inside'|'center';
97113
};
98114
guides: {
99-
color: string;
115+
color: Color;
100116
lineWidth: number;
101117
};
102118
interlaceing: {
103-
color: string;
119+
color: Color;
104120
};
105121
}
106122

@@ -110,18 +126,21 @@ interface Plot extends Padding, Box {
110126
}
111127

112128
interface Legend extends Padding, Box {
113-
width: number|string;
129+
width: Length;
114130
title: Label;
115131
label: Label;
116132
marker: {
117133
type: 'circle'|'square';
118-
size: number|string;
134+
size: Length;
119135
};
120136
}
121137

138+
type ColorGradient = string;
139+
type ColorPalette = string;
140+
122141
interface Data {
123-
colorGradient: string;
124-
colorPalette: string;
142+
colorGradient: ColorGradient;
143+
colorPalette: ColorPalette;
125144
minLightness: number;
126145
maxLightness: number;
127146
lineWidth: number;
@@ -151,18 +170,20 @@ interface AnimationTarget {
151170
}
152171

153172
interface AnimControl {
154-
seek(value: string): void;
173+
seek(value: `${number}%`|`${number}s`|`${number}ms`): void;
155174
pause(): void;
156175
play(): void;
157176
stop(): void;
158177
reverse(): void;
159178
}
160179

180+
type EventName = string;
181+
161182
export default class Vizzu {
162-
constructor(container: any);
183+
constructor(container: string|HTMLElement);
163184
initializing: Promise<Vizzu>;
164-
on(eventName: string, handler: any): void;
165-
off(eventName: string, handler: any): void;
185+
on(eventName: EventName, handler: (event: any) => void): void;
186+
off(eventName: EventName, handler: (event: any) => void): void;
166187
animate(obj: AnimationTarget): Promise<Vizzu>;
167188
get animation(): AnimControl;
168189
version(): string;

0 commit comments

Comments
 (0)