Commit 3f11c4ec authored by MichaelZinsmaier's avatar MichaelZinsmaier

added saddle detection which should result in nicer curves and hopefully does...

added saddle detection which should result in nicer curves and hopefully does not lead to new problems
parent 99b7923c
...@@ -266,37 +266,62 @@ ...@@ -266,37 +266,62 @@
var xdata = new Array; var xdata = new Array;
var ydata = new Array; var ydata = new Array;
var X = 0;
var Y = 1;
if (curvedLinesOptions.fit) { if (curvedLinesOptions.fit) {
//insert a point before and after the "real" data point to force the line //insert a point before and after the "real" data point to force the line
//to have a max,min at the data point //to have a max,min at the data point however only if it is a lowest or highest point of the
//curve => avoid saddles
var neigh = curvedLinesOptions.fitPointDist; var neigh = curvedLinesOptions.fitPointDist;
var j = 0; var j = 0;
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
//smooth front var front = new Array;
xdata[j] = data[i][0] - 0.1; var back = new Array;
//smooth front
front[X] = data[i][X] - 0.1;
if (i > 0) { if (i > 0) {
ydata[j] = data[i-1][1] * neigh + data[i][1] * (1 - neigh); front[Y] = data[i-1][Y] * neigh + data[i][Y] * (1 - neigh);
} else { } else {
ydata[j] = data[i][1]; front[Y] = data[i][Y];
}
//smooth back
back[X] = data[i][X] + 0.1;
if ((i + 1) < data.length) {
back[Y] = data[i+1][Y] * neigh + data[i][Y] * (1 - neigh);
} else {
back[Y] = data[i][Y];
} }
//test for a saddle
if ((front[Y] <= data[i][Y] && back[Y] <= data[i][Y]) || //max or partial horizontal
(front[Y] >= data[i][Y] && back[Y] >= data[i][Y])) { //min or partial horizontal
//add curve points
xdata[j] = front[X];
ydata[j] = front[Y];
j++; j++;
xdata[j] = data[i][0]; xdata[j] = data[i][0];
ydata[j] = data[i][1]; ydata[j] = data[i][1];
j++; j++;
//smooth back xdata[j] = back[X];
xdata[j] = data[i][0] + 0.1; ydata[j] = back[Y];
if ((i + 1) < data.length) { j++;
ydata[j] = data[i+1][1] * neigh + data[i][1] * (1 - neigh); } else { //saddle
} else { //use original point only
xdata[j] = data[i][0];
ydata[j] = data[i][1]; ydata[j] = data[i][1];
j++;
} }
j++;
} }
} else { } else {
//just use the datapoints //just use the datapoints
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment