Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-31-2011, 02:59 PM   PM User | #1
tejasagawane
New Coder

 
Join Date: Sep 2011
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
tejasagawane is an unknown quantity at this point
Not able to set steady setTimeout

I want to draw ECG waveform , I have used following logic , i am drawing points that fill in my canvas (i have used specified time stamp after each line drawn so that we can plot the graph points slowly using setTimeout()) and (for redrawing) after that for next points that are not fit in my canvas i am redrawing graph from (next point to previous starting point ) to (next point to previous end point) but here i can not get same time stamp as previous during redrawing next points and so on for next redrawing ...

My coding logic is
Quote:

setTimeout(function doDraw() {
var y=0.1;

if(i==0)
{ copyendx=5;
copyendy=50;
startx=5+x;
starty=50;
}

if(count==0)
{ startx=5+x;
starty=50-(leaderpointsFirst[i]*y);
endx=(5+x);
endy=50-(leaderpointsFirst[i]*y);
drawLine(context,startx,starty,copyendx,copyendy);
i++;
x=x+5;
copyendx=endx;
copyendy=endy;
}

if(count>=1)
{
startx=5+x;
starty=50-(leaderpointsFirst[i+index]*y);
endx=5+x;
endy=50-(leaderpointsFirst[i+index]*y);
drawLine(context,startx,starty,copyendx,copyendy);
i++;
x=x+5;
copyendx=endx;
copyendy=endy;
if([i+index]>leaderpointsFirst.length)
{
return;
}
}

//plot next points which has canvas width>400
if(x>400)
{
if(x==405)
{
startx=5;
endx=5;
starty=50-(leaderpointsFirst[i+index]*y);
endy=50-(leaderpointsFirst[i+index]*y);
drawLine(context,startx,starty,copyendx,copyendy);
i++;
x=x+5;
copyendx=endx;
copyendy=endy;
}
index++;
count++;
x=5;
y=0.1;
graphCanvas.width=graphCanvas.width;
i=0;
doDraw();
}


if (i < leaderpointsFirst.length) {
setTimeout(doDraw, 10);
}


},10);


function drawLine(contextO, startx, starty, endx, endy)
{
contextO.beginPath();
contextO.moveTo(startx, starty);
contextO.lineTo(endx, endy);
contextO.closePath();
contextO.strokeStyle="green";
contextO.stroke();
}
tejasagawane is offline   Reply With Quote
Old 10-31-2011, 05:26 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,456
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
use setInterval for repeating firings, it's generally more uniform timing than chained setTimeouts are in my experience.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Tags
html5, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:33 PM.


Advertisement
Log in to turn off these ads.