, , , . , , , , . :
:
function lineDistance( p1x, p1y,p2x, p2y ) {
return Math.sqrt( (p2x - p1x)*(p2x - p1x) + (p2y-p1y)*(p2y-p1y) );
}
, A B C, AB AC + BC.
, , : Math.abs(AB-(AC+BC)) < SomeThreshold. , .
plothover (jsFiddle)
$(placeholder).bind("plothover", function (event, pos, item) {
if (item) {
var tipText;
if (opts.xaxis.mode === "time" || opts.xaxes[0].mode === "time") {
tipText = stringFormat(to.content, item, timestampToDate);
} else {
tipText = stringFormat(to.content, item);
}
$tip.html(tipText).css({
left: tipPosition.x + to.shifts.x,
top: tipPosition.y + to.shifts.y
}).show();
} else {
var series = plot.getData();
var xBeforeIndex = 0;
var xAfterIndex = -1;
var Threshold = 0.0000025;
var i = 1;
while (i <= series[0].data.length && xAfterIndex==-1) {
if (xAfterIndex == -1 && pos.x > series[0].data[i][0]) {
xBeforeIndex = i;
} else if (xAfterIndex == -1) {
xAfterIndex = i;
}
i++;
}
var onTheLine =
lineDistance(
series[0].data[xBeforeIndex][0]/10000,series[0].data[xBeforeIndex][1],
pos.x/10000, pos.y)
+lineDistance(pos.x/10000, pos.y,
series[0].data[xAfterIndex][0]/10000,series[0].data[xAfterIndex][1])
-lineDistance(
series[0].data[xBeforeIndex][0]/10000,series[0].data[xBeforeIndex][1],
series[0].data[xAfterIndex][0]/10000,series[0].data[xAfterIndex][1]);
if (Math.abs(onTheLine) < Threshold) {
tipText = "Found Line";
$tip.html(tipText).css({
left: tipPosition.x + to.shifts.x,
top: tipPosition.y + to.shifts.y
}).show();
} else {
$tip.hide().html('');
}
}
});
, :
- - , .
- , bubblesort, /.
- , x 10000. , Y ( ).
, , . , . , .