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

Upload templates/combined_analysis.html with huggingface_hub

Browse files
Files changed (1) hide show
  1. templates/combined_analysis.html +56 -14
templates/combined_analysis.html CHANGED
@@ -183,6 +183,16 @@
183
  highlightTokensInCell(tr.cells[0], ds);
184
  highlightTokensInCell(tr.cells[1], ds);
185
  });
 
 
 
 
 
 
 
 
 
 
186
  }
187
  function saveDonorHLA(btn) {
188
  const obj = {};
@@ -210,6 +220,10 @@
210
  });
211
  } catch(e) {}
212
  }
 
 
 
 
213
  highlightDSA();
214
  });
215
  </script>
@@ -237,15 +251,16 @@
237
  ] %}
238
  {% if comp_dates and comp_dates | length >= 1 %}
239
  <h5>{{ comp_label }} &mdash; Combined MFI Trend
240
- <small class="text-muted ms-2">PRA 實線&#x25CF; / DSA 虛線&#x25B2;</small>
241
  </h5>
242
  <div class="mb-2">
243
- <select id="filter-{{ comp_id }}" class="form-select form-select-sm d-inline-block ms-2" style="width:auto;"
244
- onchange="updateChart('{{ comp_id }}')">
245
- <option value="10">Top 10</option>
246
- <option value="20" selected>Top 20</option>
247
- <option value="all">All</option>
248
- </select>
 
249
  </div>
250
  <div class="chart-container"><canvas id="{{ comp_id }}"></canvas></div>
251
  <script>
@@ -273,8 +288,23 @@
273
  });
274
  allData.sort((x, y) => y._max - x._max);
275
  let chartInstance = null;
 
 
 
 
 
 
276
  function buildChart(limit) {
277
- const data = limit === 'all' ? allData : allData.slice(0, parseInt(limit));
 
 
 
 
 
 
 
 
 
278
  const datasets = [];
279
  data.forEach((ag, i) => {
280
  const col = getColor(ag.antigen || ag.allele, i);
@@ -307,12 +337,24 @@
307
  x: { title: { display: true, text: 'Report Date' } } } }
308
  });
309
  }
310
- const origUpdate = window['updateChart'];
311
- window['updateChart'] = function(id) {
312
- if (id === '{{ comp_id }}') { const sel = document.getElementById('filter-' + id); buildChart(sel.value); }
313
- else if (origUpdate) origUpdate(id);
314
- };
315
- buildChart(20);
 
 
 
 
 
 
 
 
 
 
 
 
316
  })();
317
  </script>
318
  {% endif %}
 
183
  highlightTokensInCell(tr.cells[0], ds);
184
  highlightTokensInCell(tr.cells[1], ds);
185
  });
186
+ ['chart1', 'chart2'].forEach(cid => {
187
+ const fn = window['rebuildCombinedChart_' + cid];
188
+ if (typeof fn === 'function') fn();
189
+ });
190
+ }
191
+ function setCombinedFilter(chartId, btn, val) {
192
+ btn.parentElement.querySelectorAll('.btn').forEach(b => b.classList.remove('active'));
193
+ btn.classList.add('active');
194
+ const fn = window['updateCombinedFilter_' + chartId];
195
+ if (typeof fn === 'function') fn(val);
196
  }
197
  function saveDonorHLA(btn) {
198
  const obj = {};
 
220
  });
221
  } catch(e) {}
222
  }
223
+ ['chart1', 'chart2'].forEach(cid => {
224
+ const fn = window['applyCombinedDefault_' + cid];
225
+ if (typeof fn === 'function') fn();
226
+ });
227
  highlightDSA();
228
  });
229
  </script>
 
251
  ] %}
252
  {% if comp_dates and comp_dates | length >= 1 %}
253
  <h5>{{ comp_label }} &mdash; Combined MFI Trend
254
+ <small class="text-muted ms-2">DSA 實線&#x25B2; / PRA 虛線&#x25CF;</small>
255
  </h5>
256
  <div class="mb-2">
257
+ <small class="text-muted me-2">點圖例可顯示/隱藏抗體</small>
258
+ <div class="btn-group btn-group-sm" id="filter-{{ comp_id }}">
259
+ <button type="button" class="btn btn-outline-secondary" onclick="setCombinedFilter('{{ comp_id }}',this,'all')">全部</button>
260
+ <button type="button" class="btn btn-outline-danger" onclick="setCombinedFilter('{{ comp_id }}',this,'dsa')">DSA</button>
261
+ <button type="button" class="btn btn-outline-secondary" onclick="setCombinedFilter('{{ comp_id }}',this,'10')">Top 10</button>
262
+ <button type="button" class="btn btn-outline-secondary" onclick="setCombinedFilter('{{ comp_id }}',this,'20')">Top 20</button>
263
+ </div>
264
  </div>
265
  <div class="chart-container"><canvas id="{{ comp_id }}"></canvas></div>
266
  <script>
 
288
  });
289
  allData.sort((x, y) => y._max - x._max);
290
  let chartInstance = null;
291
+ let currentFilter = '20';
292
+ function matchesDonor(ag, ds) {
293
+ if (ag.antigen && ds.has(ag.antigen)) return true;
294
+ if (ag.allele && ds.has(ag.allele)) return true;
295
+ return false;
296
+ }
297
  function buildChart(limit) {
298
+ if (limit) currentFilter = limit;
299
+ let data;
300
+ if (currentFilter === 'dsa') {
301
+ const ds = (typeof getDonorSet === 'function') ? getDonorSet() : new Set();
302
+ data = allData.filter(ag => matchesDonor(ag, ds));
303
+ } else if (currentFilter === 'all') {
304
+ data = allData;
305
+ } else {
306
+ data = allData.slice(0, parseInt(currentFilter));
307
+ }
308
  const datasets = [];
309
  data.forEach((ag, i) => {
310
  const col = getColor(ag.antigen || ag.allele, i);
 
337
  x: { title: { display: true, text: 'Report Date' } } } }
338
  });
339
  }
340
+ window['rebuildCombinedChart_{{ comp_id }}'] = function() { buildChart(); };
341
+ window['updateCombinedFilter_{{ comp_id }}'] = function(val) { buildChart(val); };
342
+ function applyDefault() {
343
+ let defaultFilter = '20';
344
+ try {
345
+ const ds = (typeof getDonorSet === 'function') ? getDonorSet() : new Set();
346
+ if (ds.size > 0 && allData.some(ag => matchesDonor(ag, ds))) defaultFilter = 'dsa';
347
+ } catch (e) {}
348
+ buildChart(defaultFilter);
349
+ document.querySelectorAll('#filter-{{ comp_id }} .btn').forEach(b => {
350
+ b.classList.remove('active');
351
+ if ((defaultFilter === 'dsa' && b.textContent === 'DSA') ||
352
+ (defaultFilter === '20' && b.textContent === 'Top 20'))
353
+ b.classList.add('active');
354
+ });
355
+ }
356
+ window['applyCombinedDefault_{{ comp_id }}'] = applyDefault;
357
+ applyDefault();
358
  })();
359
  </script>
360
  {% endif %}