1 | # Framerate History
|
2 |
|
3 | > An ES6 class for tracking framerate for a given period of time.
|
4 | >
|
5 | > [![npm][npm]][npm-url]
|
6 | [![deps][deps]][deps-url]
|
7 | [![size][size]][size-url]
|
8 | [![vulnerabilities][vulnerabilities]][vulnerabilities-url]
|
9 | [![license][license]][license-url]
|
10 |
|
11 |
|
12 | <br><a name="Installation"></a>
|
13 |
|
14 | ## Installation
|
15 | ```
npm install framerate-history
```
|
16 |
|
17 | <br><a name="FrameRate"></a>
|
18 |
|
19 | ## FrameRate
|
20 | ``` javascript
import FrameRate from 'framerate-history';
```
|
21 |
|
22 | * [FrameRate](#FrameRate)
|
23 | * [new FrameRate(settings)](#new_FrameRate_new)
|
24 | * [.fps](#FrameRate+fps) ⇒ <code>Number</code>
|
25 | * [.history](#FrameRate+history) ⇒ <code>Array</code>
|
26 | * [.filterStrength([value])](#FrameRate+filterStrength) ⇒ <code>Number</code>
|
27 | * [.sampleRate([value])](#FrameRate+sampleRate) ⇒ <code>Number</code>
|
28 | * [.onSample([callback])](#FrameRate+onSample) ⇒ <code>function</code>
|
29 | * [.historyDuration([value])](#FrameRate+historyDuration) ⇒ <code>Number</code>
|
30 |
|
31 |
|
32 | <br><a name="new_FrameRate_new"></a>
|
33 |
|
34 | ### new FrameRate(settings)
|
35 |
|
36 | | Param | Type | Default |
|
37 | | --- | --- | --- |
|
38 | | settings | <code>Object</code> | |
|
39 | | [settings.onSample] | <code>function</code> | |
|
40 | | [settings.filterStrength] | <code>Number</code> | <code>5</code> |
|
41 | | [settings.historyDuration] | <code>Number</code> | <code>30</code> |
|
42 | | [settings.sampleRate] | <code>Number</code> | <code>10</code> |
|
43 |
|
44 |
|
45 | <br><a name="FrameRate+fps"></a>
|
46 |
|
47 | ### frameRate.fps ⇒ <code>Number</code> _`🔒 Read only`_
|
48 |
|
49 | > The last recorded FPS
|
50 |
|
51 |
|
52 | <br><a name="FrameRate+history"></a>
|
53 |
|
54 | ### frameRate.history ⇒ <code>Array</code> _`🔒 Read only`_
|
55 |
|
56 | > The FPS recordings over the history duration
|
57 |
|
58 |
|
59 | <br><a name="FrameRate+filterStrength"></a>
|
60 |
|
61 | ### frameRate.filterStrength([value]) ⇒ <code>Number</code> _`🔗 Chainable`_
|
62 |
|
63 | > 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
|
64 |
|
65 | **Default**: <code>5</code>
|
66 |
|
67 | | Param | Type |
|
68 | | --- | --- |
|
69 | | [value] | <code>Number</code> |
|
70 |
|
71 |
|
72 | <br><a name="FrameRate+sampleRate"></a>
|
73 |
|
74 | ### frameRate.sampleRate([value]) ⇒ <code>Number</code> _`🔗 Chainable`_
|
75 |
|
76 | > 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.
|
77 |
|
78 | **Default**: <code>10</code>
|
79 |
|
80 | | Param | Type | Description |
|
81 | | --- | --- | --- |
|
82 | | [value] | <code>Number</code> | Samples per second |
|
83 |
|
84 |
|
85 | <br><a name="FrameRate+onSample"></a>
|
86 |
|
87 | ### frameRate.onSample([callback]) ⇒ <code>function</code> _`🔗 Chainable`_
|
88 |
|
89 | > The callback will get called for every sample taken.
|
90 |
|
91 |
|
92 | | Param | Type | Description |
|
93 | | --- | --- | --- |
|
94 | | [callback] | <code>function</code> | The callback is given one param, the FPS history array. |
|
95 |
|
96 |
|
97 | <br><a name="FrameRate+historyDuration"></a>
|
98 |
|
99 | ### frameRate.historyDuration([value]) ⇒ <code>Number</code> _`🔗 Chainable`_
|
100 |
|
101 | > Defines the duration of tracked history.
|
102 |
|
103 | **Default**: <code>30</code>
|
104 |
|
105 | | Param | Type | Description |
|
106 | | --- | --- | --- |
|
107 | | [value] | <code>Number</code> | Seconds |
|
108 |
|
109 |
|
110 | [npm]: https://img.shields.io/npm/v/framerate-history.svg
|
111 | [npm-url]: https://npmjs.com/package/framerate-history
|
112 | [deps]: https://david-dm.org/darrenpaulwright/framerate-history.svg
|
113 | [deps-url]: https://david-dm.org/darrenpaulwright/framerate-history
|
114 | [size]: https://packagephobia.now.sh/badge?p=framerate-history
|
115 | [size-url]: https://packagephobia.now.sh/result?p=framerate-history
|
116 | [vulnerabilities]: https://snyk.io/test/github/DarrenPaulWright/framerate-history/badge.svg?targetFile=package.json
|
117 | [vulnerabilities-url]: https://snyk.io/test/github/DarrenPaulWright/framerate-history?targetFile=package.json
|
118 | [license]: https://img.shields.io/github/license/DarrenPaulWright/framerate-history.svg
|
119 | [license-url]: https://npmjs.com/package/framerate-history/LICENSE.md
|