forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
163 lines (151 loc) · 4.65 KB
/
index.d.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
// Type definitions for uPlot 1.0
// Project: https://github.com/leeoniya/uPlot
// Definitions by: Leo Bernard <https://github.com/leolabs>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Minimum TypeScript Version: 3.4
// Types taken from https://github.com/leeoniya/uPlot/pull/153, all credit goes to Bob Klosinski <https://github.com/fluxin>
declare class UPlot {
constructor(opts: UPlot.Options, data: UPlot.Data, ctx: HTMLElement);
readonly width: number;
readonly height: number;
readonly ctx: CanvasRenderingContext2D;
readonly bbox: UPlot.BBox;
readonly select: UPlot.BBox;
redraw(): void;
batch(): void;
destroy(): void;
setData(data: UPlot.Data, something?: boolean): void;
setScale(scale: string, limits: { min: number; max: number }): void;
setCursor(cursor: string): void;
setSelect(opts: UPlot.SelectOpts, unknown?: boolean): void;
setSize(size: { width: number; height: number }): void;
posToIdx(left: number): number;
posToVal(leftTop: number, scaleKey: string): number;
valToPos(val: number, scaleKey: string): number;
}
declare namespace UPlot {
type CanvasStrokeStyle = CanvasRenderingContext2D['strokeStyle'];
type CanvasLineWidth = CanvasRenderingContext2D['lineWidth'];
type CanvasFillStyle = CanvasRenderingContext2D['fillStyle'];
type CanvasLineDash = number[];
type Data = readonly number[][];
interface BBox {
left: number;
top: number;
width: number;
height: number;
}
interface Options {
title?: string;
/** optional HTML attribute to set on the chart's container <div> (uplot.root) */
id?: string;
/** optional HTML attribute to set on the chart's container <div> (uplot.root) */
class?: string;
/** width of the plotting area, excluding title or legend dimensions */
width: number;
/** height of the plotting area, excluding title or legend dimensions */
height: number;
series: Series[];
scales?: ScaleMap;
axes?: Axis[];
hooks?: Hooks;
plugins?: Array<{
hooks: Hooks;
}>;
select?: {
show: boolean;
};
legend?: {
show?: boolean;
};
}
interface SelectOpts {
show?: number;
left?: number;
width?: number;
top?: number;
height?: number;
}
interface Cursor {
show?: boolean;
points?: {
show: boolean | (() => boolean);
};
x: number;
y: number;
drag: {
setSelect: () => void;
setScale: () => void;
x: number;
y: number;
};
sync: {
key: string;
setSeries: () => void;
};
focus: {};
lock: boolean;
}
interface ScaleMap {
[key: string]: Scale;
}
type ValueFunction = (u: UPlot, v: number) => void;
interface Series {
show?: boolean;
/** set to true to connect null data points */
spanGaps?: boolean;
label?: string;
band?: boolean;
stroke?: CanvasStrokeStyle;
width?: CanvasLineWidth;
fill?: CanvasFillStyle;
dash?: CanvasLineDash;
value?: ValueFunction;
}
interface Axis {
show?: boolean;
label?: string;
labelSize?: number;
labelFont?: string;
font?: string;
gap?: number;
size?: number;
stroke?: CanvasStrokeStyle;
grid?: GridOpts;
ticks?: TickOpts;
}
interface GridOpts {
show?: boolean;
stroke?: CanvasStrokeStyle;
width?: number;
dash?: CanvasLineDash;
}
interface TickOpts {
show?: boolean;
stroke?: CanvasStrokeStyle;
width?: number;
dash?: number[];
size?: number;
}
interface Scale {
auto?: boolean;
range?: [number, number];
time?: boolean;
distr?: number;
stroke?: CanvasStrokeStyle;
}
type SpaceFunction = (self: Axis, scaleMin: number, scaleMax: number, dim: number) => number;
type AxisValueFunction = (self: Axis, ticks: ReadonlyArray<number>, space: number) => string[];
type IncrFunction = (self: Axis) => number[];
interface Axis {
scale?: string;
space?: number | SpaceFunction;
incrs?: number[] | IncrFunction;
values?: Array<[number, string, number, string]> | AxisValueFunction;
}
interface Hooks {
init?: Array<(u: UPlot, opts: Options, data: Data) => void>;
setSelect?: Array<(self: UPlot) => void>;
}
}
export = UPlot;