Skip to content

Commit

Permalink
Support limiting frame rate
Browse files Browse the repository at this point in the history
By @dpuyosa via #83
  • Loading branch information
dpuyosa authored and drewnoakes committed Aug 25, 2017
1 parent c2fca4f commit d88ff03
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
12 changes: 11 additions & 1 deletion builder/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,17 @@
bindRange({target: chart, name: 'Delay', propertyName: 'delay', min: 0, max: 2000});
bindCheckBox({target: chart.options, name: 'Scroll Backwards', propertyName: 'scrollBackwards'});
bindCheckBox({target: chart.options, name: 'Show Tooltip', propertyName: 'tooltip'});

bindCheckBox({
target: chart.options,
name: 'Limit FPS',
propertyName: 'limitFPS',
convert: function (checked) {
return checked ? 15 : 0;
},
convertBack: function (value) {
return value !== 0;
}
});
// Series
startControlSection('Series');
bindColor({target: chart.seriesSet[0].options, name: 'Series line color', propertyName: 'strokeStyle', optional: true, enabled: true, opacity: 1, emptyValue: 'none'});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smoothie",
"version": "1.31.0",
"version": "1.32.0",
"description": "Smoothie Charts: smooooooth JavaScript charts for realtime streaming data",
"main": "./smoothie.js",
"types": "./smoothie.d.ts",
Expand Down
5 changes: 4 additions & 1 deletion smoothie.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for Smoothie Charts 1.29
// Type definitions for Smoothie Charts 1.32
// Project: https://github.com/joewalnes/smoothie
// Definitions by: Drew Noakes <https://drewnoakes.com>
// Mike H. Hawley <https://github.com/mikehhawley>
Expand Down Expand Up @@ -135,6 +135,9 @@ export interface IChartOptions {

/** 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;
}

/**
Expand Down
12 changes: 10 additions & 2 deletions smoothie.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
* v1.29.1: Include types in package, and make property optional, by @TrentHouliston
* v1.30: Fix inverted logic in devicePixelRatio support, by @scanlime
* v1.31: Support tooltips, by @Sly1024 and @drewnoakes
* v1.32: Support frame rate limit, by @dpuyosa
*/

;(function(exports) {
Expand Down Expand Up @@ -283,7 +284,9 @@
* lineWidth: 1,
* strokeStyle: '#BBBBBB'
* },
* tooltipFormatter: SmoothieChart.tooltipFormatter // formatter function for tooltip text
* tooltipFormatter: SmoothieChart.tooltipFormatter, // formatter function for tooltip text
* responsive: false, // whether the chart should adapt to the size of the canvas
* limitFPS: 0 // maximum frame rate the chart will render at, in FPS (zero means no limit)
* }
* </pre>
*
Expand Down Expand Up @@ -351,7 +354,8 @@
strokeStyle: '#BBBBBB'
},
tooltipFormatter: SmoothieChart.tooltipFormatter,
responsive: false
responsive: false,
limitFPS: 0
};

// Based on http://inspirit.github.com/jsfeat/js/compatibility.js
Expand Down Expand Up @@ -681,6 +685,10 @@
SmoothieChart.prototype.render = function(canvas, time) {
var nowMillis = new Date().getTime();

// Respect any frame rate limit.
if (this.options.limitFPS > 0 && nowMillis - this.lastRenderTimeMillis < (1000/this.options.limitFPS))
return;

if (!this.isAnimatingScale) {
// We're not animating. We can use the last render time and the scroll speed to work out whether
// we actually need to paint anything yet. If not, we can return immediately.
Expand Down

0 comments on commit d88ff03

Please sign in to comment.