Passed
Push — master ( 7613c1...d75763 )
by Daiki
02:05
created

main.js (44 issues)

1
(() => {
2
  var W = 2;
3
  var N = 2;
4
  var state = [];
0 ignored issues
show
The variable state seems to be never used. Consider removing it.
Loading history...
5
  var sort_show_flag = false;
6
  var num_of_state = 4;
7
  const Operator_name = [
8
    ["I", "Measure", "X", "Z", "H", "S", "Sd", "T", "Td", "Rx", "Ry", "Rz"],
9
    ["CI", "SCI", "CX", "CZ", "CH", "CS", "CSd", "CT", "CTd", "CRx", "CRy", "CRz"],
10
    ["I", "Fs", "Fe"]
11
  ];
12
13
  let Sim = new Simulate();
14
15
  const X_SHIFT = 0;
16
  const Y_SHIFT = 50;
17
18
  function make_button(name, left, top, id_name){
0 ignored issues
show
The function make_button is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var make_button = function() { /* ... */ }; instead.
Loading history...
19
    if(name==="sort_show" || name==="simulate"){
20
      let button = document.createElement("button");
21
      button.setAttribute("id", id_name);
22
      button.setAttribute("class", name);
23
      button.setAttribute("type", "button");
24
      button.setAttribute("style", "cursor:pointer");
25
      if(name==="sort_show"){
26
        button.innerHTML = "SORT";
27
      }else if(name==="simulate"){
28
        button.innerHTML = "Simulate";
29
      }
30
      document.body.appendChild(button);
31
    }
32
    console.log(name);
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
33
    let button = document.getElementById(id_name);
34
    button.style.left = left + X_SHIFT + "px";
35
    button.style.top = top + Y_SHIFT + "px";
36
  }
37
38
  function make_zero(y){
0 ignored issues
show
The function make_zero is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var make_zero = function() { /* ... */ }; instead.
Loading history...
39
    var canvas = document.createElement("canvas");
40
    canvas.setAttribute("class", "zero");
41
    canvas.setAttribute("id", "z"+y);
42
    canvas.style.position = "absolute";
43
    canvas.style.left = X_SHIFT + "px";
44
    canvas.style.top = 100*(y+1) + Y_SHIFT + "px";
45
    var width = canvas.width;
46
    var height = canvas.height;
47
    var ctx = canvas.getContext('2d');
48
    var img = new Image();
49
    img.src = "./Figures/Zero.png"
50
    img.onload = function(){
51
      ctx.drawImage(img, 0, 0, width, height);
52
    }
53
    document.body.appendChild(canvas);
54
  }
55
56
  function delete_zero(y){
0 ignored issues
show
The function delete_zero is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var delete_zero = function() { /* ... */ }; instead.
Loading history...
57
    var canvas = document.getElementById("z"+y);
58
    canvas.remove();
59
  }
60
61
  function draw_operator_text(canvas){
0 ignored issues
show
The function draw_operator_text is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var draw_operator_text = function() { /* ... */ }; instead.
Loading history...
62
    var width = canvas.width;
63
    var height = canvas.height;
64
    var ctx = canvas.getContext('2d');
65
    var img = new Image();
66
    var id = canvas.object.Operator_id;
67
    var flag = canvas.object.line_flag;
68
    console.log(flag, id);
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
69
    img.src = "./Figures/" + Operator_name[flag][id] + ".png";
70
    ctx.clearRect(0, 0, width, height);
71
    img.onload = function(){
72
      ctx.drawImage(img, 0, 0, width, height);
73
    }
74
  };
75
76
  function make_operator(x, y){
0 ignored issues
show
The function make_operator is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var make_operator = function() { /* ... */ }; instead.
Loading history...
77
    var canvas = document.createElement("canvas");
78
    canvas.setAttribute("class", "operator");
79
    canvas.setAttribute("id", "c"+x+"-"+y);
80
    canvas.style.position = "absolute";
81
    canvas.style.left = 100*(x+1) + X_SHIFT + "px";
82
    canvas.style.top = 100*(y+1) + Y_SHIFT + "px";
83
    document.body.appendChild(canvas);
84
85
    canvas.object = new Operator_Cell(x,y);
86
87
    draw_operator_text(canvas);
88
  }
89
90
  function delete_operator(x, y){
0 ignored issues
show
The function delete_operator is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var delete_operator = function() { /* ... */ }; instead.
Loading history...
91
    console.log("delete x:"+x+",y:"+y);
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
92
    var canvas = document.getElementById("c"+x+"-"+y);
93
    canvas.remove();
94
    delete_input_theta(x,y);
95
  }
96
97
  function check_switch(){
0 ignored issues
show
The function check_switch is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var check_switch = function() { /* ... */ }; instead.
Loading history...
98
    let checkbox = document.getElementById("controll");
99
    checkbox.checked = false;
100
    checkbox = document.getElementById("for_check");
101
    checkbox.checked = false;
102
  }
103
104
  function delete_results(){
0 ignored issues
show
The function delete_results is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var delete_results = function() { /* ... */ }; instead.
Loading history...
105
    let canvases = document.querySelectorAll(".result_left_top");
106
    for(let i=0; i<canvases.length; ++i) if(canvases[i]!=null) canvases[i].remove();
0 ignored issues
show
Comparing canvases.i to null using the != operator is not safe. Consider using !== instead.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
107
    canvases = document.querySelectorAll(".result-bar");
108
    for(let i=0; i<canvases.length; ++i) if(canvases[i]!=null) canvases[i].remove();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
109
    canvases = document.querySelectorAll(".result-index");
110
    for(let i=0; i<canvases.length; ++i) if(canvases[i]!=null) canvases[i].remove();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
111
    canvases = document.querySelectorAll(".sort_show");
112
    for(let i=0; i<canvases.length; ++i) if(canvases[i]!=null) canvases[i].remove();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
113
114
    /*
115
    var canvas = document.getElementById("result_left_top");
116
    if(canvas!=null) canvas.remove();
117
    for(var i=0; i<num_of_state; i++){
118
      canvas = document.getElementById("result-bar-"+i);
119
      if(canvas!=null) canvas.remove();
120
      canvas = document.getElementById("result-index-"+i);
121
      if(canvas!=null) canvas.remove();
122
    }
123
    var button = document.getElementById("sort_show");
124
    if(button!=null) button.remove();
125
    */
126
  }
127
128
  function make_result_left_top(shift){
0 ignored issues
show
The function make_result_left_top is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var make_result_left_top...nction() { /* ... */ }; instead.
Loading history...
129
    var canvas = document.createElement("canvas");
130
    canvas.setAttribute("class", "result_left_top");
131
    canvas.setAttribute("id", "result_left_top");
132
    canvas.style.position = "absolute";
133
    canvas.style.left = 50 + X_SHIFT + "px";
134
    canvas.style.top = 100*(N+2) + Y_SHIFT + 300*shift + "px";
135
    document.body.appendChild(canvas);
136
  }
137
138
  function make_result_bar(index, pos, val, width, shift){
0 ignored issues
show
The function make_result_bar is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var make_result_bar = function() { /* ... */ }; instead.
Loading history...
139
    var canvas = document.createElement("canvas");
140
    canvas.setAttribute("class", "result-bar");
141
    canvas.setAttribute("id", "result-bar-"+index);
142
    canvas.style.position = "absolute";
143
    canvas.style.left = 100+pos*width+X_SHIFT+"px";
144
    canvas.style.top = 100*(N+2)+Y_SHIFT+300*shift+"px";
145
    canvas.width = width;
146
    var height = canvas.height;
147
    var ctx = canvas.getContext('2d');
148
    ctx.fillStyle = 'blue';
149
    ctx.fillRect(width/4, height*(1-val), width/2, height*val);
150
    document.body.appendChild(canvas);
151
  }
152
153
  function index_converter_to_string(index, show_elements_length){
0 ignored issues
show
The function index_converter_to_string is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var index_converter_to_s...nction() { /* ... */ }; instead.
Loading history...
154
    var str="";
155
    var index_copy = index;
156
    for(var i=0; i<show_elements_length; i++){
157
      str = String(index_copy%2) + str;
158
      index_copy=Math.floor(index_copy/2);
159
    }
160
    return str;
161
  }
162
163
  function make_result_index(index, pos, name, width, shift){
0 ignored issues
show
The function make_result_index is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var make_result_index = function() { /* ... */ }; instead.
Loading history...
164
    var canvas = document.createElement("canvas");
165
    canvas.setAttribute("class", "result-index");
166
    canvas.setAttribute("id", "result-index-"+index);
167
    canvas.style.position = "absolute";
168
    canvas.style.left = 100+pos*width+X_SHIFT+"px";
169
    canvas.style.top = 100*(N+2)+200+Y_SHIFT+300*shift+"px";
170
    var ctx = canvas.getContext('2d');
171
    ctx.font = '64px serif';
172
    ctx.fillStyle = '#404040';
173
    ctx.textBaseline = 'middle';
174
    ctx.textAlign = 'center';
175
    ctx.fillText(name, canvas.width/2, canvas.height/2);
176
    document.body.appendChild(canvas);
177
  }
178
179
  function make_result(index, pos, val, show_elements_length, shift){
0 ignored issues
show
The function make_result is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var make_result = function() { /* ... */ }; instead.
Loading history...
180
    //var width = (N+2)*25; canvasの幅を動的に変更しようとしてできなかった
181
    var width = 100;
182
    make_result_bar(index, pos, val, width, shift);
183
    var index_string = index_converter_to_string(index, show_elements_length);
184
    make_result_index(index, pos, index_string, width, shift);
185
  }
186
187
  function show_results(measure_List){
0 ignored issues
show
The function show_results is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var show_results = function() { /* ... */ }; instead.
Loading history...
188
    delete_results();
189
190
    for(let j=0; j<measure_List.length; ++j){
191
      let state_all = [];
192
      make_result_left_top(j);
193
      let List = measure_List[j];
194
      List.forEach((value, key)=>{
195
        state_all.push([key, value]);
196
      });
197
      if(sort_show_flag){
198
        state_all.sort(function(a, b){return b[1]-a[1]});
199
      }else{
200
        state_all.sort(function(a, b){return a[0]-b[0]});
201
      }
202
      let measure_indices_length = 0;
203
      for(let i=0; (1<<i)<state_all.length; ++i){
204
        measure_indices_length++;
205
      }
206
      for(var i=0; i<state_all.length; i++){
207
        make_result(state_all[i][0], i, state_all[i][1], measure_indices_length, j);
208
      }
209
      make_button("sort_show", 20, 100*(N+4)+300*j+10, "sort_show"+j);
210
      document.querySelector('#sort_show'+j).addEventListener('click', () => {
211
        sort_show_flag = !sort_show_flag;
212
        show_results(measure_List);
213
      })
214
    }
215
  }
216
217
  function init(){
0 ignored issues
show
The function init is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var init = function() { /* ... */ }; instead.
Loading history...
218
    make_button("wbutton1", 25, 25, "wbutton1");
219
    document.querySelector('.wbutton1').addEventListener('click', () => {
220
      for(let y=0; y<N; ++y) make_operator(W,y);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
221
      W++;
222
    })
223
224
    make_button("wbutton2", 125, 25, "wbutton2");
225
    document.querySelector('.wbutton2').addEventListener('click', () => {
226
      W--;
227
      if(W==0){
228
        W=1;
229
      }else{
230
        for(let y=0; y<N; ++y){
231
          delete_operator(W,y);
232
          delete_input_theta(W,y);
233
        }
234
        delete_input_fornum(W);
235
      }
236
    })
237
238
    make_button("nbutton1", 225, 25, "nbutton1");
239
    document.querySelector('.nbutton1').addEventListener('click', () => {
240
      delete_results();
241
      make_zero(N);
242
      for(let x=0; x<W; ++x) make_operator(x,N);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
243
      N++;
244
      num_of_state *= 2;
245
    })
246
247
    make_button("nbutton2", 325, 25, "nbutton2");
248
    document.querySelector('.nbutton2').addEventListener('click', () => {
249
      delete_results();
250
      N--;
251
      if(N==0){
252
        N=1;
253
      }else{
254
        num_of_state/=2;
255
        delete_zero(N);
256
        for(let x=0; x<W; ++x){
257
          delete_operator(x,N);
258
          delete_input_theta(x,N);
259
        }
260
      }
261
    })
262
263
    make_button("simulate", 425, 25, "simulate");
264
    document.querySelector('.simulate').addEventListener('click', () => {
265
      sort_show_flag = false;
266
      let results = Sim.simulate(W,N,num_of_state);
267
      state = results[0];
0 ignored issues
show
The variable state seems to be never used. Consider removing it.
Loading history...
268
      measure_List = results[1];
0 ignored issues
show
The variable measure_List seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.measure_List.
Loading history...
269
      show_results(measure_List);
270
      scroll();
271
    })
272
    check_switch();
273
274
    for(var y=0; y<N; y++){
275
      make_zero(y);
276
277
      for(var x=0; x<W; x++){
278
        make_operator(x,y);
279
      }
280
    }
281
  }
282
283
  function make_input_theta(iIdx,iIdy,canvas){
0 ignored issues
show
The function make_input_theta is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var make_input_theta = function() { /* ... */ }; instead.
Loading history...
284
    let input = document.createElement("input");
285
    input.setAttribute("type", "text");
286
    input.setAttribute("name", "input");
287
    input.setAttribute("class", "theta");
288
    input.setAttribute("id", "theta-"+iIdx+"-"+iIdy);
289
    input.setAttribute("value", "0");
290
291
    input.style.width = 50 + "px";
292
    input.style.height = 10 + "px";
293
    input.style.position = "absolute";
294
    input.style.left = 100*(iIdx+1) + X_SHIFT + 25 + "px";
295
    input.style.top = 100*(iIdy+1) + Y_SHIFT + 80 + "px";
296
297
    input.addEventListener('keyup', () => {
298
      canvas.object.theta = input.value;
299
    })
300
301
    document.body.appendChild(input);
302
  }
303
304
  function delete_input_theta(iIdx,iIdy){
0 ignored issues
show
The function delete_input_theta is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var delete_input_theta = function() { /* ... */ }; instead.
Loading history...
305
    let canvas = document.getElementById("theta-"+iIdx+"-"+iIdy);
306
    if(canvas!=null) canvas.remove();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comparing canvas to null using the != operator is not safe. Consider using !== instead.
Loading history...
307
  }
308
309
  function make_input_fornum(iIdx){
0 ignored issues
show
The function make_input_fornum is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var make_input_fornum = function() { /* ... */ }; instead.
Loading history...
310
    let input = document.createElement("input");
311
    input.setAttribute("type", "text");
312
    input.setAttribute("name", "input");
313
    input.setAttribute("class", "fornum");
314
    input.setAttribute("id", "fornum-"+iIdx);
315
    input.setAttribute("value", "0");
316
317
    input.style.width = 50 + "px";
318
    input.style.height = 10 + "px";
319
    input.style.position = "absolute";
320
    input.style.left = 100*(iIdx+1) + X_SHIFT + 25 + "px";
321
    input.style.top = Y_SHIFT + 80 + "px";
322
323
    input.addEventListener('keyup', () => {
324
      let ob = document.getElementById("c"+iIdx+"-0").object;
325
      ob.for_num = input.value;
326
    })
327
328
    document.body.appendChild(input);
329
  }
330
331
  function delete_input_fornum(iIdx){
0 ignored issues
show
The function delete_input_fornum is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var delete_input_fornum ...nction() { /* ... */ }; instead.
Loading history...
332
    let canvas = document.getElementById("fornum-"+iIdx);
333
    if(canvas!=null) canvas.remove();
0 ignored issues
show
Comparing canvas to null using the != operator is not safe. Consider using !== instead.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
334
  }
335
 
336
  function Operator_Cell(iIdx,iIdy){
0 ignored issues
show
The function Operator_Cell is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var Operator_Cell = function() { /* ... */ }; instead.
Loading history...
337
    var self = this;
338
    this.mIdx = iIdx;
339
    this.mIdy = iIdy;
340
    this.Operator_id = 0;
341
    this.line_flag = 0;
342
    this.theta = 0.0;
343
    this.for_num = 0;
344
    this.for_count = 0;
345
    if(iIdy>0){
346
      this.line_flag = document.getElementById("c"+iIdx+"-"+0).object.line_flag;
347
      if(this.line_flag===2){
348
        this.Operator_id = document.getElementById("c"+iIdx+"-"+0).object.Operator_id;
349
      }
350
    }
351
    // line_flag = 0 (nothing) 1 (controll) // 2 (for start) 3 (for end)
352
    this.mCanvas = document.getElementById("c"+iIdx+"-"+iIdy);
353
354
    this.Click = function(e){
355
      console.log(""+self.mIdx+"-"+self.mIdy+" is clicked ");
356
      let controll_button = document.getElementById("controll");
357
      let for_button = document.getElementById("for_check");
358
359
      if(for_button.checked){
360
        if(self.line_flag===2){
361
          self.Operator_id += 1;
362
          self.Operator_id %= Operator_name[self.line_flag].length;
363
          for(let y=0; y<N; ++y){
364
            let another_canvas = document.getElementById("c"+self.mIdx+"-"+y);
365
            another_canvas.object.Operator_id = self.Operator_id;
366
            draw_operator_text(another_canvas);
367
          }
368
          if(self.Operator_id===2) make_input_fornum(self.mIdx);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
369
          else delete_input_fornum(self.mIdx);
370
        }else{
371
          for(let y=0; y<N; ++y){
372
            let another_canvas = document.getElementById("c"+self.mIdx+"-"+y);
373
            if(another_canvas.object.line_flag!==2){
374
              another_canvas.object.line_flag = 2;
375
              another_canvas.object.Operator_id = 0;
376
            }
377
            delete_input_theta(self.mIdx,y);
378
            draw_operator_text(another_canvas);
379
          }
380
        }
381
      }else if(controll_button.checked){
382 View Code Duplication
        if(self.line_flag===1){
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
383
          self.Operator_id += 1;
384
          self.Operator_id %= Operator_name[self.line_flag].length;
385
          delete_input_theta(self.mIdx,self.mIdy);
386
          if(self.Operator_id-1 >= 8 && self.Operator_id-1 <= 10){
387
            make_input_theta(self.mIdx,self.mIdy,this);
388
          }
389
          draw_operator_text(self.mCanvas);
390
        }else{
391
          for(var y=0; y<N; y++){
392
            var another_canvas = document.getElementById("c"+self.mIdx+"-"+y);
393
            if(another_canvas.object.line_flag!==1){
394
              if(another_canvas.object.line_flag===2){
395
                delete_input_fornum(self.mIdx);
396
                another_canvas.object.Operator_id=0;
397
              }
398
              another_canvas.object.line_flag = 1;
399
              if(another_canvas.object.Operator_id==1){
0 ignored issues
show
Comparing another_canvas.object.Operator_id to 1 using the == operator is not safe. Consider using === instead.
Loading history...
400
                another_canvas.object.Operator_id=0;
401
              }
402
            }
403
            draw_operator_text(another_canvas);
404
          }
405
        }
406
      }else{
407 View Code Duplication
        if(self.line_flag!==0){
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
408
          for(var y=0; y<N; y++){
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable y already seems to be declared on line 391. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
409
            var another_canvas = document.getElementById("c"+self.mIdx+"-"+y);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable another_canvas already seems to be declared on line 392. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
410
            if(another_canvas.object.line_flag!==0){
411
              if(another_canvas.object.line_flag===2){
412
                delete_input_fornum(self.mIdx);
413
                another_canvas.object.Operator_id=0;
414
              }
415
              another_canvas.object.line_flag=0;
416
              if(another_canvas.object.Operator_id==1){
417
                another_canvas.object.Operator_id=0;
418
              }
419
            }
420
            draw_operator_text(another_canvas);
421
          }
422
        }else{
423
          self.Operator_id += 1;
424
          self.Operator_id %= Operator_name[self.line_flag].length;
425
          delete_input_theta(self.mIdx,self.mIdy);
426
          if(self.Operator_id-1 >= 8 && self.Operator_id-1 <= 10){
427
            make_input_theta(self.mIdx,self.mIdy,this);
428
          }
429
          draw_operator_text(self.mCanvas);
430
        }
431
      }
432
    }
433
434
    this.mCanvas.onclick = this.Click;
435
  };
436
437
  function scroll(){
0 ignored issues
show
The function scroll is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var scroll = function() { /* ... */ }; instead.
Loading history...
438
    /*
439
    var element = document.documentElement;
440
    var Target = element.scrollHeight - element.clientHeight;
441
    var Pos = window.pageYOffset;
442
    var move = Target/20;
443
    var interval = 1000/100;
444
    window.scrollBy(0, move);
445
    var rep = setTimeout(scroll, interval);
446
    if(Pos === Target){
447
      clearTimeout(rep);
448
    }
449
    //window.scrollTo(0, Target);
450
    */
451
  }
452
453
  window.onload = function(){
454
    init();
455
  };
456
457
})();
458