1 | # framerate-history
|
2 | [![npm][npm]][npm-url]
|
3 | [![deps][deps]][deps-url]
|
4 | [![size][size]][size-url]
|
5 |
|
6 | An ES6 class for tracking frame rate for a given period of time.
|
7 |
|
8 | ## Installation
|
9 | ```
|
10 | npm install framerate-history;
|
11 | ```
|
12 |
|
13 | <a name="module_FrameRate"></a>
|
14 |
|
15 | ## FrameRate
|
16 | ### Usage
```
import FrameRate from 'framerate-history';
```
|
17 |
|
18 |
|
19 | | Param | Type | Default |
|
20 | | --- | --- | --- |
|
21 | | settings | <code>Object</code> | |
|
22 | | [settings.onSample] | <code>function</code> | |
|
23 | | [settings.filterStrength] | <code>Number</code> | <code>5</code> |
|
24 | | [settings.historyDuration] | <code>Number</code> | <code>30</code> |
|
25 | | [settings.sampleRate] | <code>Number</code> | <code>10</code> |
|
26 |
|
27 |
|
28 | * [FrameRate](#module_FrameRate)
|
29 | * [.fps](#module_FrameRate+fps) : <code>number</code>
|
30 | * [.history](#module_FrameRate+history) : <code>array</code>
|
31 | * [.filterStrength([value])](#module_FrameRate+filterStrength) ⇒ <code>frameRate</code> \| <code>Number</code>
|
32 | * [.sampleRate([value])](#module_FrameRate+sampleRate) ⇒ <code>frameRate</code> \| <code>Number</code>
|
33 | * [.onSample([callback])](#module_FrameRate+onSample) ⇒ <code>frameRate</code> \| <code>function</code>
|
34 | * [.historyDuration([value])](#module_FrameRate+historyDuration) ⇒ <code>frameRate</code> \| <code>Number</code>
|
35 |
|
36 | <a name="module_FrameRate+fps"></a>
|
37 |
|
38 | ### frameRate.fps : <code>number</code>
|
39 | **Kind**: instance property of [<code>FrameRate</code>](#module_FrameRate)
|
40 | <a name="module_FrameRate+history"></a>
|
41 |
|
42 | ### frameRate.history : <code>array</code>
|
43 | **Kind**: instance property of [<code>FrameRate</code>](#module_FrameRate)
|
44 | <a name="module_FrameRate+filterStrength"></a>
|
45 |
|
46 | ### frameRate.filterStrength([value]) ⇒ <code>frameRate</code> \| <code>Number</code>
|
47 | Sets a filter on the frame rate calculation. Setting to 1 will effectively turn off the filter, the higher the
number the more smooth the curve over time. See this stackoverflow question for details:
https://stackoverflow.com/questions/4787431/check-fps-in-js
|
48 |
|
49 | **Kind**: instance method of [<code>FrameRate</code>](#module_FrameRate)
|
50 |
|
51 | | Param | Type |
|
52 | | --- | --- |
|
53 | | [value] | <code>Number</code> |
|
54 |
|
55 | <a name="module_FrameRate+sampleRate"></a>
|
56 |
|
57 | ### frameRate.sampleRate([value]) ⇒ <code>frameRate</code> \| <code>Number</code>
|
58 | The rate to take samples. Setting to 0 will clear the interval. If the interval is prevented from executing at the desired rate, the history will get filled in with the current frame rate in an attempt to keep the history as accurate as possible.
|
59 |
|
60 | **Kind**: instance method of [<code>FrameRate</code>](#module_FrameRate)
|
61 |
|
62 | | Param | Type | Description |
|
63 | | --- | --- | --- |
|
64 | | [value] | <code>Number</code> | Samples per second |
|
65 |
|
66 | <a name="module_FrameRate+onSample"></a>
|
67 |
|
68 | ### frameRate.onSample([callback]) ⇒ <code>frameRate</code> \| <code>function</code>
|
69 | The callback will get called for every sample taken.
|
70 |
|
71 | **Kind**: instance method of [<code>FrameRate</code>](#module_FrameRate)
|
72 |
|
73 | | Param | Type |
|
74 | | --- | --- |
|
75 | | [callback] | <code>function</code> |
|
76 |
|
77 | <a name="module_FrameRate+historyDuration"></a>
|
78 |
|
79 | ### frameRate.historyDuration([value]) ⇒ <code>frameRate</code> \| <code>Number</code>
|
80 | Defines the duration of tracked history in seconds.
|
81 |
|
82 | **Kind**: instance method of [<code>FrameRate</code>](#module_FrameRate)
|
83 |
|
84 | | Param | Type | Description |
|
85 | | --- | --- | --- |
|
86 | | [value] | <code>Number</code> | Seconds |
|
87 |
|
88 |
|
89 | ## License
|
90 |
|
91 | [MIT](./LICENSE.md)
|
92 |
|
93 | [npm]: https://img.shields.io/npm/v/framerate-history.svg
|
94 | [npm-url]: https://npmjs.com/package/framerate-history
|
95 | [deps]: https://david-dm.org/darrenpaulwright/framerate-history.svg
|
96 | [deps-url]: https://david-dm.org/darrenpaulwright/framerate-history
|
97 | [size]: https://packagephobia.now.sh/badge?p=framerate-history
|
98 | [size-url]: https://packagephobia.now.sh/result?p=framerate-history
|