Snazzy JavaScript with the help of a modern Browser

But do We actually have a real feel for “fast” in the context of our browsers? Do we know what do we mean by “fast”, in this context? When for example someone suggests doing something in HTML+JavaScript? Well…

To help us understand how fast is fast web content, in here I can “reveal” that I have made one very short JavaScript example that is using Flot™ library and jQuery™.

http://jsfiddle.net/dbjdbj/4B2Gd/

Above you will see one near-time example, of continuous data set production and it’s repeated re-draw-ing. The “jittering” axes are automatically scaled. I think for scripting language this is pretty damn fast.
And once more here is the amazingly short piece of JavaScript behind, that I have written as a POC1. Calculate two data sets, and then just redraw using them. Repeat.

[sourcecode language=”javascript”] $(function () {
var flot = null ,
new_dataset = function ( hF_, size_ ) {
var d1 = [], d2 = [], size = size_ || 1400, hF = hF_ || (20 * Math.random()) ;
for (var i = 0; i < size; i += hF ) { d1.push([i, Math.sin(i)]); d2.push([i, Math.cos(i)]); } return [d1,d2] ; }, maxi = 1000, $counter = $("#counter"), tid = setInterval ( function () { if ( 0 > maxi– ) { clearInterval(tid); return; }
$counter.html( "" + maxi ) ;
flot = $.plot($("#placeholder"), new_dataset());
flot.draw();
}, 1 ) ;
});
[/sourcecode]

Enjoy…


1. POC is Proof Of Concept

Leave a Reply