@datagrok/bio 2.10.28 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,33 +28,15 @@ export function getCompositionAnalysisWidget(val: DG.SemanticValue) {
28
28
  break;
29
29
  }
30
30
 
31
- const counts = new Map<string, number>();
32
- let max = 0;
31
+ const counts: { [m: string]: number } = {};
33
32
  const uh = UnitsHandler.getOrCreate(val.cell.column);
34
33
  const splitter = uh.getSplitter();
35
34
  const parts = splitter(val.value);
36
- const len = parts.length;
37
- wu(parts).filter((p) => !!p && p !== '').forEach((c: string) => {
38
- const count = counts.get(c) || 0;
39
- counts.set(c, count + 1);
40
- max = Math.max(max, count + 1);
35
+ wu(parts).filter((p) => !!p && p !== '').forEach((m: string) => {
36
+ const count = counts[m] || 0;
37
+ counts[m] = count + 1;
41
38
  });
42
- max /= len;// percentage
43
- // calculate frequencies
44
- const compositionMap: { [key: string]: HTMLElement } = {};
45
- const valueArray = Array.from(counts.entries());
46
- valueArray.sort((a, b) => b[1] - a[1]);
47
- valueArray.forEach(([key, value]) => {
48
- const ratio = value / len;
49
- const color = palette.get(key);
50
- const barDiv = ui.div('', {classes: 'macromolecule-cell-comp-analysis-bar'});
51
- barDiv.style.width = `${ratio / max * 50}px`;
52
- const valueDiv = ui.div((ratio * 100).toFixed(2) + '%');
53
- barDiv.style.backgroundColor = color;
54
- compositionMap[key] = ui.div([barDiv, valueDiv], {classes: 'macromolecule-cell-comp-analysis-value'});
55
- });
56
-
57
- const table = ui.tableFromMap(compositionMap);
39
+ const table = buildCompositionTable(palette, counts);
58
40
  Array.from(table.rows).forEach((row) => {
59
41
  const barCol = (row.getElementsByClassName('macromolecule-cell-comp-analysis-bar')[0] as HTMLDivElement)
60
42
  .style.backgroundColor;
@@ -64,3 +46,33 @@ export function getCompositionAnalysisWidget(val: DG.SemanticValue) {
64
46
  host.appendChild(table);
65
47
  return new DG.Widget(host);
66
48
  }
49
+
50
+ export function buildCompositionTable(palette: SeqPalette, counts: { [m: string]: number }): HTMLTableElement {
51
+ let sumValue: number = 0;
52
+ let maxValue: number | null = null;
53
+ for (const value of Object.values(counts)) {
54
+ sumValue = sumValue + value;
55
+ maxValue = maxValue === null ? value : Math.max(maxValue, value);
56
+ }
57
+ const maxRatio = maxValue! / sumValue;
58
+ const elMap: { [m: string]: HTMLElement } = Object.assign({}, ...Array.from(Object.entries(counts))
59
+ .sort((a, b) => b[1] - a[1])
60
+ .map(([m, value]) => {
61
+ const ratio = value / sumValue;
62
+ const color = palette.get(m);
63
+ const barDiv = ui.div('', {classes: 'macromolecule-cell-comp-analysis-bar'});
64
+ barDiv.style.width = `${50 * ratio / maxRatio}px`;
65
+ barDiv.style.backgroundColor = color;
66
+ const valueDiv = ui.div(`${(100 * ratio).toFixed(2)}%`);
67
+ const el = ui.div([barDiv, valueDiv], {classes: 'macromolecule-cell-comp-analysis-value'});
68
+ return ({[m]: el});
69
+ }));
70
+
71
+ const table = ui.tableFromMap(elMap);
72
+ Array.from(table.rows).forEach((row) => {
73
+ const barCol = (row.getElementsByClassName('macromolecule-cell-comp-analysis-bar')[0] as HTMLDivElement)
74
+ .style.backgroundColor;
75
+ row.cells[0].style.color = barCol;
76
+ });
77
+ return table;
78
+ }
package/webpack.config.js CHANGED
@@ -14,7 +14,7 @@ module.exports = {
14
14
  },
15
15
  resolve: {
16
16
  fallback: {'url': false},
17
- extensions: ['.wasm', '.mjs', '.ts', '.js', '.json', '.tsx'],
17
+ extensions: ['.wasm', '.mjs', '.ts', '.tsx', '.js', '.json'],
18
18
  },
19
19
  module: {
20
20
  rules: [