How to generate a graph with a curve similar to "sine" in jquery flot?

4

Friends,

I'm using the flot for a project of ECG (electrocardiogram) simulation , and I was faced with a problem, which I think is more of mathematics than programming > ...

So sorry if I'm explaining bad. Good, my problem is to make the transition of the normal beat, for greater! (i.e. what happens when the drug is applied)

For example: The beat is at 70, and I apply adrenaline, and this should go to 210.

Do this straight and quiet, as in this example: (example of own flot) (ranging from "6M" to "TE")

ButIneedittobeawaveformlikea"sine" like this: (ranging from "6M" to "TE")

EISmyquestionforthefloat:

  • Simplifyingthequestion,asIwouldinthe jquery flot (in realtime) , to generate a graph that starts at X and goes to Y, with a "curve" similar to a sine?
asked by anonymous 21.11.2016 / 02:01

1 answer

6

In principle, what you are looking for is an Envelope, to modify the main wave. To simplify things, you can create a function that takes a linear value, and turns it into a curve.

Here's a simple example:

function Easing( i ) {
    i *= 2;
    if (i<1) return 1/(2-i)-.5;
    return 1.5-1/i;
};

If you feed this formula linearly with a value of 0 to 1 , you will also get back a value of 0 to 1 , only nonlinear.

What you need to do, in this case is to get the amplitude of the main wave, and multiply by the result of the formula.


Here is a very basic example of usage. The extensive code is to draw the canvas, but what matters is just the application of the formula:

function Easing( i ) {
	i *= 2;
	if (i<1) return 1/(2-i)-.5;
	return 1.5-1/i;
};

//demonstração:
var canvas = document.getElementById("out");
var context = canvas.getContext("2d"); 
var width = canvas.width;
var height = canvas.height;
var data;

context.beginPath();
context.moveTo(0,height);
context.strokeStyle = 'red';
for(i=0; i<=100; i++)
{
  data = i/100; //linear
  context.lineTo(i/100*width,height-data*height);
  context.stroke();
}

context.beginPath();
context.moveTo(0,height);
context.strokeStyle = 'blue';
for(i=0; i<100; i++)
{
  data = Easing( i/100 ); //usando função
  context.lineTo(i/100*width,height-data*height);
  context.stroke();
}
#out {width:300px; height:200px; border:1px dotted #999}
<canvas id="out"></canvas>

Also check out CODEPEN .


Remember that jQuery itself has easing functions, which already do something similar. Usually used for animations, but nothing prevents you from applying to graphics:

  

link

This site has a number of formulas that might interest you:

  

link

    
21.11.2016 / 03:08