-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmogPanel.js
254 lines (206 loc) · 6.49 KB
/
mogPanel.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
var colorList = ["ghostWhite", "red", "pink", "cyan", "lime", "yellow", "magenta", "lightSkyBlue", "gray", "orange"];
var mog = new MOG();
var label = new Array(6);
for (var i=0; i<6; i++)
label[i] = new Array(4);
var outColor = new Array(6);
for (var i=0; i<6; i++)
outColor[i] = new Array(4);
var inColor = new Array(6);
for (var i=0; i<6; i++)
inColor[i] = new Array(4);
var underlyingMOGUpdated = false;
function setSquareColors(outColorArray, inColorArray) {
for (var i=0; i<6; i++)
for (var j=0; j<4; j++)
outColor[i][j] = outColorArray[i][j];
for (var i=0; i<6; i++)
for (var j=0; j<4; j++)
inColor[i][j] = inColorArray[i][j];
repaintAll();
}
function setAllSquareColors(colorArray) {
setSquareColors(colorArray, colorArray);
}
function clearAll() {
underlyingMOGUpdated = true;
resetLabelsAndColors();
for (var i=0; i<6; i++)
for (var j=0; j<4; j++)
mog.setArrayElement(i,j,false);
repaintAll();
}
function complement() {
underlyingMOGUpdated = true;
resetLabelsAndColors();
for (var i=0; i<6; i++)
for (var j=0; j<4; j++)
mog.toggleArrayElement(i,j);
repaintAll();
}
function clickSquare(i, j) {
resetLabelsAndColors();
repaintAll();
toggleSquare(i, j);
setButtonStatuses();
}
function toggleSquare(i, j) {
underlyingMOGUpdated = true;
mog.toggleArrayElement(i, j);
repaintOne(i, j);
}
function setOutSquareColor(i, j, value) {
outColor[i][j] = value;
repaintOne(i, j);
}
function setInSquareColor(i, j, value) {
inColor[i][j] = value;
repaintOne(i, j);
}
function setSquareColor(i, j, value) {
outColor[i][j] = value;
inColor[i][j] = value;
repaintOne(i, j);
}
function setButtonStatuses() {
var orbitClass = mog.getOrbitClassification();
$('#complete').prop('disabled', !(orbitClass == "S5"));
$('#sextet').prop('disabled', !(orbitClass == "S4"));
$('#block').prop('disabled', !(
orbitClass == "S4" ||
orbitClass == "U6" ||
orbitClass == "U8" ||
orbitClass == "U10" ||
orbitClass == "T10" ||
orbitClass == "S10" ||
orbitClass == "S11" ||
orbitClass == "S12" ||
orbitClass == "S12+" ||
orbitClass == "T12"
));
}
function repaintOne(i, j) {
var outerColor;
var outerSquare = $('#mog_' + i + '_' + j);
if (outColor[i][j] != -1)
outerColor = colorList[outColor[i][j]];
else if (mog.getArrayElement(i,j))
outerColor = colorList[1];
else outerColor = colorList[0];
outerSquare.css('background-color', outerColor);
var innerColor;
var innerSquare = $('#inner_' + i + '_' + j);
if (inColor[i][j] != -1)
innerColor = colorList[inColor[i][j]];
else if (mog.getArrayElement(i,j))
innerColor = colorList[1];
else innerColor = colorList[0];
innerSquare.css('background-color', innerColor);
innerSquare.html(label[i][j]);
if (underlyingMOGUpdated) {
$('#orbitClass').html(mog.getOrbitClassification());
underlyingMOGUpdated = false;
}
}
function repaintAll() {
for (var i=0; i<6; i++) {
for (var j=0; j<4; j++) {
repaintOne(i, j);
}
}
}
function resetLabelsAndColors() {
for (var i=0; i<6; i++) {
for (var j=0; j<4; j++) {
label[i][j] = "";
outColor[i][j] = -1;
inColor[i][j] = -1;
}
}
}
function complete() {
if (mog.getWeight() == 5) {
var completionI, completionJ;
completionI = new Array(3);
completionJ = new Array(3);
mog.getOctadCompletion(completionI, completionJ);
for (var k=0; k<3; k++)
setSquareColor(completionI[k], completionJ[k], 2);
}
}
function sextet() {
var sextet = mog.getSextet();
setAllSquareColors(sextet);
}
function dualRep() {
var len;
var repI = new Array(4), repJ = new Array(4);
len = mog.getDualRepresentative(repI, repJ);
clearAll();
for (var k=0; k<len; k++)
toggleSquare(repI[k], repJ[k]);
setButtonStatuses();
}
function orbit() {
showOrbits(false);
}
function block() {
showOrbits(true);
}
function showOrbits(withBlocks) {
/* Labels each square with the orbit classification of the diagram that would result if that square were
* added (if it is not currently marked) or removed (if it is currently marked).
*/
underlyingMOGUpdated = true;
var colorToUse, nextMarkedColor = 1, nextComplementColor = 4;
var blockColorArray = null;
var colorClass = new Array(7);
for(var i=0; i<7; i++)
colorClass[i] = "";
if (withBlocks)
blockColorArray = mog.getBlockDecomposition();
for (var i=0; i<6; i++)
for (var j=0; j<4; j++) {
mog.toggleArrayElement(i,j);
label[i][j] = mog.getOrbitClassification();
mog.toggleArrayElement(i,j);
if (mog.getArrayElement(i,j))
label[i][j] = label[i][j] + "*";
colorToUse = 0;
for (var k=1; k<=6; k++)
if (colorClass[k] == label[i][j]) {
colorToUse = k ;
break;
}
if (colorToUse == 0) {
if (mog.getArrayElement(i,j)) {
colorToUse = nextMarkedColor;
colorClass[nextMarkedColor] = label[i][j];
while (colorClass[nextMarkedColor] != "") {
nextMarkedColor = (nextMarkedColor % 6) + 1;
if (nextMarkedColor == colorToUse)
console.error("showOrbits: ran out of colors, should not happen");
}
}
else {
colorToUse = nextComplementColor;
colorClass[nextComplementColor] = label[i][j];
while (colorClass[nextComplementColor] != "") {
nextComplementColor = (nextComplementColor % 6) + 1;
if (nextComplementColor == colorToUse)
console.error("showOrbits: ran out of colors, should not happen");
}
}
}
outColor[i][j] = colorToUse;
if (blockColorArray == null)
inColor[i][j] = outColor[i][j];
else inColor[i][j] = blockColorArray[i][j];
}
repaintAll();
}
$(document).ready(function() {
resetLabelsAndColors();
repaintAll();
setButtonStatuses();
});