-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscatterplot.js
More file actions
130 lines (115 loc) · 2.65 KB
/
scatterplot.js
File metadata and controls
130 lines (115 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
function rand() {
return Math.random();
}
function addToPlot(divName, xCoord, yCoord, trace) {
Plotly.extendTraces(divName, {
x: [[xCoord]], y: [[yCoord]]
}, [trace])
}
function createPlot(divName, title) {
var layout = {
paper_bgcolor: 'rgba(0,0,0,0)',
plot_bgcolor: 'rgba(0,0,0,0)',
autosize: false,
font: {
family: 'Courier New, monospace',
size: 12,
color: '#ffffff'
},
title: {
text: title,
font: {
family: 'Courier New, monospace',
size: 12,
color: '#ffffff'
},
xref: 'paper',
x: 0.05,
},
width:325,
height:300,
margin: {
l: 25,
r: 25,
b: 50,
t: 50,
pad: 4
}
};
Plotly.plot(divName, [
{
y: [].map(rand),
x: [].map(rand),
mode: 'markers',
line: {color:"rgb(229,139,59)"}, //'#0FE60B'
name: "Unknown",
},
{
y: [].map(rand),
x: [].map(rand),
mode: 'markers',
line: {color:"rgb(230,59,218)"}, //'#0FE60B'
name: "Left",
},
{
y: [].map(rand),
x: [].map(rand),
mode: 'markers',
line: {color:"rgb(59,229,217)"}, //'#0FE60B'
name: "Right",
}], layout);
}
function getDirection(pointArray, frame, centerPoint) {
//Right, Up = 1, Left, Down = 2
var direction = {vertical: 0, horizontal: 0};
nearbyPoints = [];
frameThreshold = 1;
xThreshold = 10;
yThreshold = 10;
sameDirFlag = true;
if(pointArray.length == 0)
return direction;
while(nearbyPoints.length == 0 && frameThreshold != 10) {
nearbyPoints = pointArray.filter(function(value){
return ((frame - frameThreshold < value.frame && value.frame != frame) &&
(value.point.x - centerPoint.x > -xThreshold && value.point.x - centerPoint.x < xThreshold));
});
frameThreshold += 1;
xThreshold += 10;
}
if(nearbyPoints.length == 0)
return direction;
if(nearbyPoints.length == 1) {
if(nearbyPoints[0].point.y >= centerPoint.y)
direction.vertical = 1;
else
direction.vertical = 2;
if(nearbyPoints[0].point.x >= centerPoint.x)
direction.horizontal = 1;
else
direction.horizontal = 2;
} else {
nearbyPoints.forEach(function (point) {
if(point.direction.vertical != nearbyPoints[0].direction.vertical ||
point.direction.horizontal != nearbyPoints[0].direction.horizontal)
sameDirFlag == false;
});
if(sameDirFlag)
return nearbyPoints[0].direction;
else {
if(nearbyPoints[0].point.y >= centerPoint.y)
direction.vertical = 1;
else
direction.vertical = 2;
if(nearbyPoints[0].point.x >= centerPoint.x)
direction.horizontal = 1;
else
direction.horizontal = 2;
}
}
return direction;
}
function purgePlot(divName) {
Plotly.purge(divName);
}
createPlot("motionScatterPlot", "Motion", "#E60B0B");