audrey06100 commited on
Commit
d3d85e7
·
1 Parent(s): dde47a0
Files changed (2) hide show
  1. app.py +29 -46
  2. app_utils.py +2 -2
app.py CHANGED
@@ -65,14 +65,8 @@ observe_js = """
65
  const newWidth = entry.contentRect.width
66
 
67
  target.style.backgroundSize = `${newWidth}px`;
68
- target.style.setProperty("--indication-dot-size", `${newWidth*0.025}px`);
69
- target.style.setProperty("--indication-text-size", `${newWidth*0.035}px`);
70
-
71
- let all_elem = target.querySelectorAll(":scope > label");
72
- Array.from(all_elem).forEach(item => {
73
- item.querySelector(":scope > input").style.width = `${newWidth*0.025}px`;
74
- item.querySelector(":scope > input").style.height = `${newWidth*0.025}px`;
75
- });
76
  });
77
  });
78
  observer.observe(document.querySelector("#radio-group > div:nth-of-type(2)"));
@@ -96,6 +90,8 @@ init_js = """
96
 
97
  const div = document.querySelector(selector);
98
  const divWidth = div.clientWidth;
 
 
99
 
100
  // add figure of the input montage
101
  div.style.cssText = `
@@ -109,27 +105,24 @@ init_js = """
109
 
110
  // move the radios/checkboxes
111
  let name, left, bottom;
112
- let all_elem = div.querySelectorAll(":scope > label");
113
- Array.from(all_elem).forEach(item => {
114
  name = item.querySelector(":scope > input").getAttribute(attribute);
115
  left = channel_info.inputDict[name].css_position[0];
116
  bottom = channel_info.inputDict[name].css_position[1];
117
 
118
- item.style.cssText = `position: absolute; left: ${left}; bottom: ${bottom};`;
119
  item.className = "";
120
  item.querySelector(":scope > span").innerText = "";
121
  item.querySelector(":scope > input").style.cssText = `
122
  position: absolute;
123
- width: ${divWidth*0.025}px;
124
- height: ${divWidth*0.025}px;
125
  transform: translate(-50%, -50%);
126
  `;
127
  });
128
 
129
  // add indication for the empty tpl_channels
130
- div.style.setProperty("--indication-dot-size", `${divWidth*0.025}px`);
131
- div.style.setProperty("--indication-text-size", `${divWidth*0.035}px`);
132
-
133
  name = stage1_info.emptyTemplate[0];
134
  left = channel_info.templateDict[name].css_position[0];
135
  bottom = channel_info.templateDict[name].css_position[1];
@@ -137,25 +130,21 @@ init_js = """
137
  ${selector}::before {
138
  content: "";
139
  position: absolute;
140
- left: ${left};
141
- bottom: ${bottom};
142
- width: var(--indication-dot-size);
143
- height: var(--indication-dot-size);
144
  border-radius: 50%;
145
  background-color: red;
146
  }
147
  `;
148
- left = parseFloat(left.slice(0, -1))+2.7;
149
- left = left.toString()+"%";
150
- bottom = parseFloat(bottom.slice(0, -1));
151
- bottom = bottom.toString()+"%";
152
  const txt_rule = `
153
  ${selector}::after {
154
  content: "${name}";
155
  position: absolute;
156
- left: ${left};
157
- bottom: ${bottom};
158
- font-size: var(--indication-text-size);
159
  font-weight: 900;
160
  color: red;
161
  }
@@ -183,22 +172,20 @@ update_js = """
183
  let cnt, name, left, bottom;
184
  if(stage1_info.state == "step2-selecting"){
185
  selector = "#radio-group > div:nth-of-type(2)";
186
- cnt = stage1_info.step2.count
187
 
188
  // update the radios
189
- let all_elem = document.querySelectorAll(selector+" > label");
190
- Array.from(all_elem).forEach(item => {
191
  name = item.querySelector(":scope > input").value;
192
  left = channel_info.inputDict[name].css_position[0];
193
  bottom = channel_info.inputDict[name].css_position[1];
194
-
195
- item.style.left = `${left}`;
196
- item.style.bottom = `${bottom}`;
197
  });
198
-
199
  }else if(stage1_info.state == "step3-2-selecting"){
200
  selector = "#chkbox-group > div:nth-of-type(2)";
201
- cnt = stage1_info.step3.count
202
  }else return;
203
 
204
  // update the indication
@@ -209,25 +196,21 @@ update_js = """
209
  ${selector}::before {
210
  content: "";
211
  position: absolute;
212
- left: ${left};
213
- bottom: ${bottom};
214
- width: var(--indication-dot-size);
215
- height: var(--indication-dot-size);
216
  border-radius: 50%;
217
  background-color: red;
218
  }
219
  `;
220
- left = parseFloat(left.slice(0, -1))+2.7;
221
- left = left.toString()+"%";
222
- bottom = parseFloat(bottom.slice(0, -1));
223
- bottom = bottom.toString()+"%";
224
  const txt_rule = `
225
  ${selector}::after {
226
  content: "${name}";
227
  position: absolute;
228
- left: ${left};
229
- bottom: ${bottom};
230
- font-size: var(--indication-text-size);
231
  font-weight: 900;
232
  color: red;
233
  }
 
65
  const newWidth = entry.contentRect.width
66
 
67
  target.style.backgroundSize = `${newWidth}px`;
68
+ target.style.setProperty("--channel-indicator-size", `${newWidth*0.025}px`);
69
+ target.style.setProperty("--channel-name-size", `${newWidth*0.035}px`);
 
 
 
 
 
 
70
  });
71
  });
72
  observer.observe(document.querySelector("#radio-group > div:nth-of-type(2)"));
 
90
 
91
  const div = document.querySelector(selector);
92
  const divWidth = div.clientWidth;
93
+ div.style.setProperty("--channel-indicator-size", `${divWidth*0.025}px`);
94
+ div.style.setProperty("--channel-name-size", `${divWidth*0.035}px`);
95
 
96
  // add figure of the input montage
97
  div.style.cssText = `
 
105
 
106
  // move the radios/checkboxes
107
  let name, left, bottom;
108
+ const elements = div.querySelectorAll(":scope > label");
109
+ Array.from(elements).forEach(item => {
110
  name = item.querySelector(":scope > input").getAttribute(attribute);
111
  left = channel_info.inputDict[name].css_position[0];
112
  bottom = channel_info.inputDict[name].css_position[1];
113
 
114
+ item.style.cssText = `position: absolute; left: ${left}%; bottom: ${bottom}%;`;
115
  item.className = "";
116
  item.querySelector(":scope > span").innerText = "";
117
  item.querySelector(":scope > input").style.cssText = `
118
  position: absolute;
119
+ width: var(--channel-indicator-size);
120
+ height: var(--channel-indicator-size);
121
  transform: translate(-50%, -50%);
122
  `;
123
  });
124
 
125
  // add indication for the empty tpl_channels
 
 
 
126
  name = stage1_info.emptyTemplate[0];
127
  left = channel_info.templateDict[name].css_position[0];
128
  bottom = channel_info.templateDict[name].css_position[1];
 
130
  ${selector}::before {
131
  content: "";
132
  position: absolute;
133
+ left: ${left}%;
134
+ bottom: ${bottom}%;
135
+ width: var(--channel-indicator-size);
136
+ height: var(--channel-indicator-size);
137
  border-radius: 50%;
138
  background-color: red;
139
  }
140
  `;
 
 
 
 
141
  const txt_rule = `
142
  ${selector}::after {
143
  content: "${name}";
144
  position: absolute;
145
+ left: ${left+2.7}%;
146
+ bottom: ${bottom}%;
147
+ font-size: var(--channel-name-size);
148
  font-weight: 900;
149
  color: red;
150
  }
 
172
  let cnt, name, left, bottom;
173
  if(stage1_info.state == "step2-selecting"){
174
  selector = "#radio-group > div:nth-of-type(2)";
175
+ cnt = stage1_info.step2.count;
176
 
177
  // update the radios
178
+ const elements = document.querySelectorAll(selector+" > label");
179
+ Array.from(elements).forEach(item => {
180
  name = item.querySelector(":scope > input").value;
181
  left = channel_info.inputDict[name].css_position[0];
182
  bottom = channel_info.inputDict[name].css_position[1];
183
+ item.style.left = `${left}%`;
184
+ item.style.bottom = `${bottom}%`;
 
185
  });
 
186
  }else if(stage1_info.state == "step3-2-selecting"){
187
  selector = "#chkbox-group > div:nth-of-type(2)";
188
+ cnt = stage1_info.step3.count;
189
  }else return;
190
 
191
  // update the indication
 
196
  ${selector}::before {
197
  content: "";
198
  position: absolute;
199
+ left: ${left}%;
200
+ bottom: ${bottom}%;
201
+ width: var(--channel-indicator-size);
202
+ height: var(--channel-indicator-size);
203
  border-radius: 50%;
204
  background-color: red;
205
  }
206
  `;
 
 
 
 
207
  const txt_rule = `
208
  ${selector}::after {
209
  content: "${name}";
210
  position: absolute;
211
+ left: ${left+2.7}%;
212
+ bottom: ${bottom}%;
213
+ font-size: var(--channel-name-size);
214
  font-weight: 900;
215
  color: red;
216
  }
app_utils.py CHANGED
@@ -210,11 +210,11 @@ def save_figure(channel_info, tpl_montage, filename1, filename2):
210
  for i, name in enumerate(tpl_names):
211
  left = tpl_coords[i,0]/6.4
212
  bottom = tpl_coords[i,1]/6.4
213
- tpl_dict[name]["css_position"] = [str(round(left, 2))+"%", str(round(bottom, 2))+"%"]
214
  for i, name in enumerate(in_names):
215
  left = in_coords[i,0]/6.4
216
  bottom = in_coords[i,1]/6.4
217
- in_dict[name]["css_position"] = [str(round(left, 2))+"%", str(round(bottom, 2))+"%"]
218
 
219
  channel_info.update({
220
  "templateDict" : tpl_dict,
 
210
  for i, name in enumerate(tpl_names):
211
  left = tpl_coords[i,0]/6.4
212
  bottom = tpl_coords[i,1]/6.4
213
+ tpl_dict[name]["css_position"] = [round(left, 2), round(bottom, 2)]
214
  for i, name in enumerate(in_names):
215
  left = in_coords[i,0]/6.4
216
  bottom = in_coords[i,1]/6.4
217
+ in_dict[name]["css_position"] = [round(left, 2), round(bottom, 2)]
218
 
219
  channel_info.update({
220
  "templateDict" : tpl_dict,