plokmii commited on
Commit
d4128b8
·
verified ·
1 Parent(s): 4ff6743

Upload templates/dsa_analysis.html with huggingface_hub

Browse files
Files changed (1) hide show
  1. templates/dsa_analysis.html +56 -14
templates/dsa_analysis.html CHANGED
@@ -180,6 +180,16 @@
180
  highlightTokensInCell(tr.cells[0], ds);
181
  highlightTokensInCell(tr.cells[1], ds);
182
  });
 
 
 
 
 
 
 
 
 
 
183
  }
184
  function saveDonorHLA(btn) {
185
  const obj = {};
@@ -207,6 +217,11 @@
207
  });
208
  } catch(e) {}
209
  }
 
 
 
 
 
210
  highlightDSA();
211
  });
212
  </script>
@@ -234,13 +249,13 @@
234
  {% if comp_dates and comp_dates | length >= 2 %}
235
  <h5>{{ comp_label }} &mdash; MFI Trend</h5>
236
  <div class="mb-2">
237
- <small class="text-muted">Top antibodies by Max MFI</small>
238
- <select id="filter-{{ comp_id }}" class="form-select form-select-sm d-inline-block ms-2" style="width:auto;"
239
- onchange="updateChart('{{ comp_id }}')">
240
- <option value="10">Top 10</option>
241
- <option value="20" selected>Top 20</option>
242
- <option value="all">All</option>
243
- </select>
244
  </div>
245
  <div class="chart-container"><canvas id="{{ comp_id }}"></canvas></div>
246
  <script>
@@ -262,8 +277,23 @@
262
  }
263
  allData.sort((x, y) => Math.max(...y.values.filter(v=>v!==null)) - Math.max(...x.values.filter(v=>v!==null)));
264
  let chartInstance = null;
 
 
 
 
 
 
265
  function buildChart(limit) {
266
- const data = limit === 'all' ? allData : allData.slice(0, parseInt(limit));
 
 
 
 
 
 
 
 
 
267
  const datasets = data.map((ag, i) => ({
268
  label: ag.antigen + (ag.allele && ag.allele !== ag.antigen ? ' (' + ag.allele + ')' : ''),
269
  data: ag.values, borderColor: getColor(ag.antigen, i),
@@ -280,12 +310,24 @@
280
  x: { title: { display: true, text: 'Report Date' } } } }
281
  });
282
  }
283
- const origUpdate = window['updateChart'];
284
- window['updateChart'] = function(id) {
285
- if (id === '{{ comp_id }}') { const sel = document.getElementById('filter-' + id); buildChart(sel.value); }
286
- else if (origUpdate) origUpdate(id);
287
- };
288
- buildChart(20);
 
 
 
 
 
 
 
 
 
 
 
 
289
  })();
290
  </script>
291
  {% endif %}
 
180
  highlightTokensInCell(tr.cells[0], ds);
181
  highlightTokensInCell(tr.cells[1], ds);
182
  });
183
+ ['chart1', 'chart2'].forEach(cid => {
184
+ const fn = window['rebuildDsaChart_' + cid];
185
+ if (typeof fn === 'function') fn();
186
+ });
187
+ }
188
+ function setDsaFilter(chartId, btn, val) {
189
+ btn.parentElement.querySelectorAll('.btn').forEach(b => b.classList.remove('active'));
190
+ btn.classList.add('active');
191
+ const fn = window['updateDsaFilter_' + chartId];
192
+ if (typeof fn === 'function') fn(val);
193
  }
194
  function saveDonorHLA(btn) {
195
  const obj = {};
 
217
  });
218
  } catch(e) {}
219
  }
220
+ // After donor inputs are populated, re-apply default (may switch to DSA mode)
221
+ ['chart1', 'chart2'].forEach(cid => {
222
+ const fn = window['applyDsaDefault_' + cid];
223
+ if (typeof fn === 'function') fn();
224
+ });
225
  highlightDSA();
226
  });
227
  </script>
 
249
  {% if comp_dates and comp_dates | length >= 2 %}
250
  <h5>{{ comp_label }} &mdash; MFI Trend</h5>
251
  <div class="mb-2">
252
+ <small class="text-muted me-2">點圖例可顯示/隱藏抗體</small>
253
+ <div class="btn-group btn-group-sm" id="filter-{{ comp_id }}">
254
+ <button type="button" class="btn btn-outline-secondary" onclick="setDsaFilter('{{ comp_id }}',this,'all')">全部</button>
255
+ <button type="button" class="btn btn-outline-danger" onclick="setDsaFilter('{{ comp_id }}',this,'dsa')">DSA</button>
256
+ <button type="button" class="btn btn-outline-secondary" onclick="setDsaFilter('{{ comp_id }}',this,'10')">Top 10</button>
257
+ <button type="button" class="btn btn-outline-secondary" onclick="setDsaFilter('{{ comp_id }}',this,'20')">Top 20</button>
258
+ </div>
259
  </div>
260
  <div class="chart-container"><canvas id="{{ comp_id }}"></canvas></div>
261
  <script>
 
277
  }
278
  allData.sort((x, y) => Math.max(...y.values.filter(v=>v!==null)) - Math.max(...x.values.filter(v=>v!==null)));
279
  let chartInstance = null;
280
+ let currentFilter = '20';
281
+ function matchesDonor(ag, ds) {
282
+ if (ag.antigen && ds.has(ag.antigen)) return true;
283
+ if (ag.allele && ds.has(ag.allele)) return true;
284
+ return false;
285
+ }
286
  function buildChart(limit) {
287
+ if (limit) currentFilter = limit;
288
+ let data;
289
+ if (currentFilter === 'dsa') {
290
+ const ds = (typeof getDonorSet === 'function') ? getDonorSet() : new Set();
291
+ data = allData.filter(ag => matchesDonor(ag, ds));
292
+ } else if (currentFilter === 'all') {
293
+ data = allData;
294
+ } else {
295
+ data = allData.slice(0, parseInt(currentFilter));
296
+ }
297
  const datasets = data.map((ag, i) => ({
298
  label: ag.antigen + (ag.allele && ag.allele !== ag.antigen ? ' (' + ag.allele + ')' : ''),
299
  data: ag.values, borderColor: getColor(ag.antigen, i),
 
310
  x: { title: { display: true, text: 'Report Date' } } } }
311
  });
312
  }
313
+ window['rebuildDsaChart_{{ comp_id }}'] = function() { buildChart(); };
314
+ window['updateDsaFilter_{{ comp_id }}'] = function(val) { buildChart(val); };
315
+ function applyDefault() {
316
+ let defaultFilter = '20';
317
+ try {
318
+ const ds = (typeof getDonorSet === 'function') ? getDonorSet() : new Set();
319
+ if (ds.size > 0 && allData.some(ag => matchesDonor(ag, ds))) defaultFilter = 'dsa';
320
+ } catch (e) {}
321
+ buildChart(defaultFilter);
322
+ document.querySelectorAll('#filter-{{ comp_id }} .btn').forEach(b => {
323
+ b.classList.remove('active');
324
+ if ((defaultFilter === 'dsa' && b.textContent === 'DSA') ||
325
+ (defaultFilter === '20' && b.textContent === 'Top 20'))
326
+ b.classList.add('active');
327
+ });
328
+ }
329
+ window['applyDsaDefault_{{ comp_id }}'] = applyDefault;
330
+ applyDefault();
331
  })();
332
  </script>
333
  {% endif %}