-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.js
More file actions
65 lines (60 loc) 路 1.21 KB
/
Copy pathplot.js
File metadata and controls
65 lines (60 loc) 路 1.21 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
const Util = require('../util/common');
class Plot {
constructor(cfg) {
Util.mix(this, cfg);
this._init();
}
_init() {
const self = this;
const start = self.start;
const end = self.end;
const xMin = Math.min(start.x, end.x);
const xMax = Math.max(start.x, end.x);
const yMin = Math.min(start.y, end.y);
const yMax = Math.max(start.y, end.y);
this.tl = {
x: xMin,
y: yMin
};
this.tr = {
x: xMax,
y: yMin
};
this.bl = {
x: xMin,
y: yMax
};
this.br = {
x: xMax,
y: yMax
};
this.width = xMax - xMin;
this.height = yMax - yMin;
}
/**
* reset
* @param {Object} start start point
* @param {Object} end end point
*/
reset(start, end) {
this.start = start;
this.end = end;
this._init();
}
/**
* check the point is in the range of plot
* @param {Nubmer} x x value
* @param {[type]} y y value
* @return {Boolean} return the result
*/
isInRange(x, y) {
if (Util.isObject(x)) {
y = x.y;
x = x.x;
}
const tl = this.tl;
const br = this.br;
return tl.x <= x && x <= br.x && tl.y <= y && y <= br.y;
}
}
module.exports = Plot;