Created
September 6, 2014 14:53
-
-
Save AdrianRossouw/c2b17c10a0b8e4706606 to your computer and use it in GitHub Desktop.
famous debug view - uses smoothie charts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var F = require('./famous'); | |
var extend = require('./extend'); | |
var AppState = require('./app-state'); | |
var Smoothie = require('smoothie'); | |
var colors = require('random-colors')(10); | |
module.exports = extend(F.View, { | |
constructor: function() { | |
F.View.apply(this, arguments); | |
var surface = new F.Surface({ | |
content: '<canvas id="smoothie-chart" width=300 height=100></canvas>' | |
}); | |
var modifier = new F.Modifier({ | |
size: [300, 100], | |
align: [0, 1.0], | |
origin: [0, 1.0], | |
transform: F.Transform.translate(0, 0, 10000) | |
}); | |
this.add(modifier).add(surface); | |
var chart = new Smoothie.SmoothieChart(); | |
var series = {}; | |
series.fps = new Smoothie.TimeSeries(); | |
if (process.env.DEBUG_FPS) { | |
chart.addTimeSeries(series.fps, { | |
lineWidth:2, | |
strokeStyle:'#00ff00', | |
fillStyle:'rgba(91,227,74,0.30)' | |
}); | |
// Install render-handlers | |
F.Engine.on('prerender', function() { | |
series.fps.append(new Date().getTime(), F.Engine.getFPS()); | |
}); | |
} | |
AppState.debug = function(name, value) { | |
var opts = {lineWidth: 2, resetBounds: true}; | |
if (!series[name]) { | |
series[name] = new Smoothie.TimeSeries(); | |
opts.strokeStyle = colors.pop(); | |
console.log(opts); | |
chart.addTimeSeries(series[name], opts); | |
} | |
series[name].append(new Date().getTime(), value); | |
}; | |
surface.on('deploy', function() { | |
var canvas = document.getElementById('smoothie-chart'); | |
chart.streamTo(canvas, 1096); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment