/
well.js
98 lines (85 loc) · 2.2 KB
/
well.js
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
var Well = function(row, col, index, options){
/*
A "well" models a microplate well.
It includes conceptual functions for managing
well volume
*/
options = options || {};
this.row = row;
this.col = col;
this.index = index;
this.maxVolume = parseInt(options.maxVolume, 10);
this.volume = parseInt(options.volume, 10);
this.padding = parseInt(options.padding, 10) || 5;
this.color = options.color || 'white';
switch(options.shape){
case 'circle':
this.shape = 'circle'
break;
case 'rounded':
this.shape = 'rounded';
break;
default:
this.shape = 'square';
break;
}
Object.defineProperty(this, 'coordinate', {
get: function(){
if(
[this.row, this.col].every(function(coord){
return parseInt(coord, 10);
})
){
return this.row + ',' + this.col;
}
return this.row + this.col;
}
});
Object.defineProperty(this, 'empty', {
get: function(){
return !this.volume;
}
});
Object.defineProperty(this, 'full', {
get: function(){
return this.volume === this.maxVolume;
}
});
}
Well.prototype.removeVol = function(vol){
this.volume -= vol;
if(this.volume < 0){
this.volume = 0;
}
}
Well.prototype.addVol = function(vol){
this.volume += vol;
if(this.volume > this.maxVolume){
this.volume = this.maxVolume;
}
}
Well.prototype.render = function(attribs){
switch(this.shape){
case 'rounded':
var radius = attribs.size * 0.05;
var size = attribs.size;
return $('<rect>').attr('rx', radius).attr('ry', radius)
.attr('width', size).attr('height', size)
.attr('x', attribs.xoffset).attr('y', attribs.yoffset)
.attr('fill', this.color).attr('stroke', 'black')
.attr('class', 'well');
case 'circle':
var radius = attribs.size / 2;
return $('<circle>').attr('r', radius).attr('cx', attribs.xoffset + radius)
.attr('cy', attribs.yoffset + radius)
.attr('fill', this.color).attr('stroke', 'black')
.attr('class', 'well');
default:
var radius = attribs.size * 0.05;
var size = attribs.size;
return $('<rect>').attr('width', size).attr('height', size)
.attr('x', attribs.xoffset).attr('y', attribs.yoffset)
.attr('fill', this.color).attr('stroke', 'black')
.attr('class', 'well');
}
}