forked from joewalnes/smoothie
-
Notifications
You must be signed in to change notification settings - Fork 1
/
smoothie.d.ts
244 lines (208 loc) · 8.38 KB
/
smoothie.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
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
// Type definitions for Smoothie Charts 1.35
// Project: https://github.com/joewalnes/smoothie
// Definitions by: Drew Noakes <https://drewnoakes.com>
// Mike H. Hawley <https://github.com/mikehhawley>
export interface ITimeSeriesOptions {
resetBounds?: boolean;
resetBoundsInterval?: number;
}
export interface ITimeSeriesPresentationOptions {
strokeStyle?: string;
fillStyle?: string;
lineWidth?: number;
/**
* Controls how lines are drawn between data points.
* Default value is controlled by <code>SmoothieChart</code>'s <code>interpolation</code> option.
*/
interpolation?: "linear" | "step" | "bezier";
tooltipLabel?: string;
}
export declare class TimeSeries {
/**
* Initialises a new <code>TimeSeries</code> with optional data options.
*
* Options are of the form (defaults shown):
*
* <pre>
* {
* resetBounds: true, // enables/disables automatic scaling of the y-axis
* resetBoundsInterval: 3000 // the period between scaling calculations, in millis
* }
* </pre>
*
* Presentation options for TimeSeries are specified as an argument to <code>SmoothieChart.addTimeSeries</code>.
*/
constructor(options?: ITimeSeriesOptions);
/**
* Adjust or inspect the lower y-axis for this <code>TimeSeries</code> object.
*/
minValue: number;
/**
* Adjust or inspect the upper y-axis for this <code>TimeSeries</code> object.
*/
maxValue: number;
/**
* Hide this <code>TimeSeries</code> object in the chart.
*/
disabled: boolean;
/**
* Clears all data and state from this TimeSeries object.
*/
clear(): void;
/**
* Recalculate the min/max values for this <code>TimeSeries</code> object.
*
* This causes the graph to scale itself in the y-axis.
*/
resetBounds(): void;
/**
* Adds a new data point to the <code>TimeSeries</code>, preserving chronological order.
*
* @param timestamp the position, in time, of this data point
* @param value the value of this data point
* @param sumRepeatedTimeStampValues if <code>timestamp</code> has an exact match in the series, this flag controls
* whether it is replaced, or the values summed (defaults to false.)
*/
append(timestamp: number, value: number, sumRepeatedTimeStampValues?: boolean): void;
dropOldData(oldestValidTime: number, maxDataSetLength: number): void;
}
export interface IGridOptions {
/** The background colour of the chart. */
fillStyle?: string;
/** The pixel width of grid lines. */
lineWidth?: number;
/** Colour of grid lines. */
strokeStyle?: string;
/** Distance between vertical grid lines. */
millisPerLine?: number;
/** Number of vertical sections marked out by horizontal grid lines. */
verticalSections?: number;
/** Whether the grid lines trace the border of the chart or not. */
borderVisible?: boolean;
}
export interface ILabelOptions {
/** Enables/disables labels showing the min/max values. */
disabled?: boolean;
/** Colour for text of labels. */
fillStyle?: string;
fontSize?: number;
fontFamily?: string;
precision?: number;
/** Shows intermediate labels between min and max values along y axis. */
showIntermediateLabels?: boolean;
intermediateLabelSameAxis?: boolean;
}
export interface ITitleOptions {
/** The text to display on the left side of the chart. Defaults to "". */
text?: string;
/** Colour for text. */
fillStyle?: string;
fontSize?: number;
fontFamily?: string;
/** The vertical position of the text. Defaults to "middle". */
verticalAlign?: "top" | "middle" | "bottom";
}
export interface IRange { min: number; max: number }
export interface IHorizontalLine {
value?: number;
color?: string;
lineWidth?: number;
}
export interface IChartOptions {
/** Specify to clamp the lower y-axis to a given value. */
minValue?: number;
/** Specify to clamp the upper y-axis to a given value. */
maxValue?: number;
/** Allows proportional padding to be added above the chart. For 10% padding, specify 1.1. */
minValueScale?: number;
/** Allows proportional padding to be added below the chart. For 10% padding, specify 1.1. */
maxValueScale?: number;
yRangeFunction?: (range: IRange) => IRange;
/** Controls the rate at which y-value zoom animation occurs. */
scaleSmoothing?: number;
/** Sets the speed at which the chart pans by. */
millisPerPixel?: number;
/** Whether to render at different DPI depending upon the device. Enabled by default. */
enableDpiScaling?: boolean;
/** Callback function that formats the min y value label */
yMinFormatter?: (min: number, precision: number) => string;
/** Callback function that formats the max y value label */
yMaxFormatter?: (max: number, precision: number) => string;
/** Callback function that formats the intermediate y value labels */
yIntermediateFormatter?: (intermediate: number, precision: number) => string;
maxDataSetLength?: number;
/** Default value for time series presentation options' <code>interpolation</code>. Defaults to "bezier". */
interpolation?: ITimeSeriesPresentationOptions['interpolation'];
/** Optional function to format time stamps for bottom of chart. You may use <code>SmoothieChart.timeFormatter</code>, or your own/ */
timestampFormatter?: (date: Date) => string;
horizontalLines?: IHorizontalLine[];
grid?: IGridOptions;
labels?: ILabelOptions;
title?: ITitleOptions;
tooltip?: boolean;
tooltipLine?: { lineWidth: number, strokeStyle: string };
tooltipFormatter?: (timestamp: number, data: {series: TimeSeries, index: number, value: number}[]) => string;
/** Whether to use time of latest data as current time. */
nonRealtimeData?: boolean;
/**
* Displays not the latest data, but data from the given percentile.
* Useful when trying to see old data saved by setting a high value for maxDataSetLength.
* Should be a value between 0 and 1.
*/
displayDataFromPercentile?: number;
/** Allows the chart to stretch according to its containers and layout settings. Default is <code>false</code>, for backwards compatibility. */
responsive?: boolean;
/** The maximum frame rate the chart will render at, in FPS. Default is <code>0</code>, meaning no limit. */
limitFPS?: number;
}
/**
* Initialises a new <code>SmoothieChart</code>.
*
* Options are optional and may be sparsely populated. Just specify the values you
* need and the rest will be given sensible defaults.
*/
export declare class SmoothieChart {
constructor(chartOptions?: IChartOptions);
/**
* Change or inspect presentation options.
*/
options: IChartOptions;
/**
* Adds a <code>TimeSeries</code> to this chart, with optional presentation options.
*/
addTimeSeries(series: TimeSeries, seriesOptions?: ITimeSeriesPresentationOptions): void;
/**
* Removes the specified <code>TimeSeries</code> from the chart.
*/
removeTimeSeries(series: TimeSeries): void;
/**
* Gets render options for the specified <code>TimeSeries</code>.
*
* As you may use a single <code>TimeSeries</code> in multiple charts with different formatting in each usage,
* these settings are stored in the chart.
*/
getTimeSeriesOptions(timeSeries: TimeSeries): ITimeSeriesPresentationOptions;
/**
* Brings the specified <code>TimeSeries</code> to the top of the chart. It will be rendered last.
*/
bringToFront(timeSeries: TimeSeries): void;
/**
* Instructs the <code>SmoothieChart</code> to start rendering to the provided canvas, with specified delay.
*
* @param canvas the target canvas element
* @param delayMillis an amount of time to wait before a data point is shown. This can prevent the end of the series
* from appearing on screen, with new values flashing into view, at the expense of some latency.
*/
streamTo(canvas: HTMLCanvasElement, delayMillis?: number): void;
/**
* Starts the animation of this chart. Called by <code>streamTo</code>.
*/
start(): void;
/**
* Stops the animation of this chart.
*/
stop(): void;
updateValueRange(): void;
render(canvas?: HTMLCanvasElement, time?: number): void;
static timeFormatter(date: Date): string;
}