@datagrok/helm 2.1.32 → 2.1.34

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@datagrok/helm",
3
3
  "friendlyName": "Helm",
4
- "version": "2.1.32",
4
+ "version": "2.1.34",
5
5
  "author": {
6
6
  "name": "Oleksandra Serhiienko",
7
7
  "email": "oserhiienko@datagrok.ai"
@@ -15,9 +15,9 @@
15
15
  "helm/JSDraw/Pistoia.HELM-uncompressed.js"
16
16
  ],
17
17
  "dependencies": {
18
- "@datagrok-libraries/bio": "^5.40.7",
19
- "@datagrok-libraries/chem-meta": "^1.2.3",
20
- "@datagrok-libraries/utils": "^4.1.45",
18
+ "@datagrok-libraries/bio": "^5.40.8",
19
+ "@datagrok-libraries/chem-meta": "^1.2.5",
20
+ "@datagrok-libraries/utils": "^4.2.1",
21
21
  "cash-dom": "^8.1.1",
22
22
  "datagrok-api": "^1.17.0",
23
23
  "dayjs": "^1.10.6",
@@ -8,7 +8,7 @@ import {printLeftOrCentered} from '@datagrok-libraries/bio/src/utils/cell-render
8
8
  import {errorToConsole} from '@datagrok-libraries/utils/src/to-console';
9
9
 
10
10
  import {findMonomers, parseHelm, removeGapsFromHelm} from './utils';
11
- import {IEditor, HelmMonomerPlacer, IEditorMolAtom, ISeqMonomer} from './helm-monomer-placer';
11
+ import {IEditor, HelmMonomerPlacer, IEditorMolAtom, ISeqMonomer, Temps} from './helm-monomer-placer';
12
12
  import {IMonomerLib} from '@datagrok-libraries/bio/src/types/index';
13
13
 
14
14
  // import {_package} from './package'; // NullError: method not found: '_package' on null
@@ -139,6 +139,26 @@ function getHoveredMonomerFallback(
139
139
  return hoveredSeqMonomer;
140
140
  }
141
141
 
142
+ type RendererGridCellTemp = {
143
+ [Temps.helmMonomerPlacer]: HelmMonomerPlacer;
144
+ }
145
+
146
+ function getRendererGridCellTemp(gridCell: DG.GridCell
147
+ ): [DG.GridColumn | null, DG.Column | null, RendererGridCellTemp] {
148
+ /** Primarily store/get MonomerPlacer at GridColumn, fallback at (Table) Column for scatter plot tooltip */
149
+ let temp: RendererGridCellTemp | null = null;
150
+
151
+ let gridCol: DG.GridColumn | null = null;
152
+ try { gridCol = gridCell.gridColumn; } catch { gridCol = null; }
153
+ temp = gridCol ? gridCol.temp as RendererGridCellTemp : null;
154
+
155
+ const tableCol: DG.Column = gridCell.cell.column;
156
+ if (!temp) temp = tableCol.temp;
157
+
158
+ if (temp === null) throw new Error(`Monomer placer store (GridColumn or Column) not found.`);
159
+ return [gridCol, tableCol, temp];
160
+ }
161
+
142
162
  /** Helm cell renderer in case of no missed monomer draws with JSDraw2.Editor (webeditor),
143
163
  * in case of missed monomers presented, draws linear sequences aligned in width per monomer.
144
164
  */
@@ -153,16 +173,15 @@ export class HelmCellRenderer extends DG.GridCellRenderer {
153
173
 
154
174
  onMouseMove(gridCell: DG.GridCell, e: MouseEvent): void {
155
175
  try {
156
- /* Can not do anything without tableColumn containing temp */
157
- let tableCol: DG.Column | null = null;
158
- try { tableCol = gridCell.tableColumn; } catch { }
176
+ const [_gridCol, tableCol, temp] = getRendererGridCellTemp(gridCell);
177
+ const helmPlacer = temp[Temps.helmMonomerPlacer];
178
+ /* Can not do anything without tableColumn */
159
179
  if (!tableCol) return;
160
180
 
161
181
  /** {@link gridCell}.bounds */ const gcb = gridCell.bounds;
162
182
  const argsX = e.offsetX - gcb.x;
163
183
  const argsY = e.offsetY - gcb.y;
164
184
 
165
- const helmPlacer = HelmMonomerPlacer.getOrCreate(gridCell.gridColumn, tableCol);
166
185
  const editor: IEditor | null = helmPlacer.getEditor(gridCell.tableRowIndex!);
167
186
  let seqMonomer: ISeqMonomer | null;
168
187
  let missedMonomers: Set<string> = new Set<string>(); // of .size = 0
@@ -225,10 +244,11 @@ export class HelmCellRenderer extends DG.GridCellRenderer {
225
244
  ) {
226
245
  g.save();
227
246
  try {
247
+ const [gridCol, tableCol, temp] = getRendererGridCellTemp(gridCell);
228
248
  /* Can not do anything without tableColumn containing temp */
229
- let tableCol: DG.Column | null = null;
230
- try { tableCol = gridCell.tableColumn; } catch { }
231
249
  if (!tableCol) return;
250
+ let helmPlacer = temp[Temps.helmMonomerPlacer];
251
+ if (!helmPlacer) helmPlacer = temp[Temps.helmMonomerPlacer] = new HelmMonomerPlacer(gridCol, tableCol);
232
252
 
233
253
  const grid = gridCell.gridRow !== -1 ? gridCell.grid : undefined;
234
254
  const missedColor = 'red';
@@ -239,7 +259,6 @@ export class HelmCellRenderer extends DG.GridCellRenderer {
239
259
  const monomerList = parseHelm(seq);
240
260
  const monomers: Set<string> = new Set<string>(monomerList);
241
261
  const missedMonomers: Set<string> = findMonomers(monomerList);
242
- const helmPlacer = HelmMonomerPlacer.getOrCreate(gridCell.gridColumn, tableCol);
243
262
 
244
263
  if (missedMonomers.size == 0) {
245
264
  // Recreate host to avoid hanging in window.dojox.gfx.svg.Text.prototype.getTextWidth
@@ -43,7 +43,7 @@ export interface ISeqMonomer {
43
43
  }
44
44
 
45
45
  export class HelmMonomerPlacer {
46
- private readonly grid: DG.Grid;
46
+ private readonly grid: DG.Grid | null;
47
47
  public readonly monomerLib: IMonomerLib;
48
48
 
49
49
  private _allPartsList: (string[] | null)[];
@@ -56,11 +56,11 @@ export class HelmMonomerPlacer {
56
56
 
57
57
  private subs: Unsubscribable[] = [];
58
58
 
59
- protected constructor(
60
- public readonly gridCol: DG.GridColumn,
59
+ public constructor(
60
+ public readonly gridCol: DG.GridColumn | null,
61
61
  public readonly col: DG.Column<string>
62
62
  ) {
63
- this.grid = this.gridCol.grid;
63
+ this.grid = this.gridCol ? this.gridCol.grid : null;
64
64
  this.reset();
65
65
  if (this.grid) {
66
66
  this.subs.push(this.col.dataFrame.onDataChanged.subscribe(() => {
@@ -72,7 +72,7 @@ export class HelmMonomerPlacer {
72
72
  }));
73
73
  this.subs.push(grok.events.onViewRemoved.subscribe((view: DG.View) => {
74
74
  try {
75
- if (this.gridCol.grid.view?.id === view.id) this.destroy();
75
+ if (this.grid && this.grid.view?.id === view.id) this.destroy();
76
76
  } catch (err: any) {
77
77
  console.error(err);
78
78
  }
@@ -148,12 +148,6 @@ export class HelmMonomerPlacer {
148
148
  if (this.grid) this.grid.invalidate();
149
149
  }
150
150
 
151
- public static getOrCreate(gridCol: DG.GridColumn, col: DG.Column<string>): HelmMonomerPlacer {
152
- let res: HelmMonomerPlacer = gridCol.temp[Temps.helmMonomerPlacer];
153
- if (!res) res = gridCol.temp[Temps.helmMonomerPlacer] = new HelmMonomerPlacer(gridCol, col);
154
- return res;
155
- }
156
-
157
151
  public setEditor(tableRowIndex: number, editor: IEditor) {
158
152
  this._editorList![tableRowIndex] = editor;
159
153
  }
@@ -164,6 +158,6 @@ export class HelmMonomerPlacer {
164
158
  }
165
159
 
166
160
  export function getAllParts(seq: string | null): string[] {
167
- const monomerList: string[] = seq ? parseHelm(seq) : [];
168
- return seq ? getParts(monomerList, seq) : [];
161
+ const monomerList: string[] = !!seq ? parseHelm(seq) : [];
162
+ return !!seq ? getParts(monomerList, seq) : [];
169
163
  }
@@ -24,7 +24,7 @@ export function removeGapsFromHelm(srcHelm: string): string {
24
24
  export function getParts(subParts: string[], s: string): string[] {
25
25
  const j = 0;
26
26
  const allParts: string[] = [];
27
- for (let k = 0; k < subParts.length; ++k) {
27
+ for (let k = 0; k < (subParts ?? []).length; ++k) {
28
28
  const indexOfMonomer = s.indexOf(subParts[k]);
29
29
  const helmBeforeMonomer = s.slice(j, indexOfMonomer);
30
30
  allParts.push(helmBeforeMonomer);