@datagrok/helm 2.1.32 → 2.1.33

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.33",
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,28 @@ 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
+ let tableCol: DG.Column | null = null;
156
+ if (!temp) {
157
+ try { tableCol = gridCell.cell.column; } catch { tableCol = null; }
158
+ temp = tableCol ? tableCol.temp as RendererGridCellTemp : null;
159
+ }
160
+ if (temp === null) throw new Error(`Monomer placer store (GridColumn or Column) not found.`);
161
+ return [gridCol, tableCol, temp];
162
+ }
163
+
142
164
  /** Helm cell renderer in case of no missed monomer draws with JSDraw2.Editor (webeditor),
143
165
  * in case of missed monomers presented, draws linear sequences aligned in width per monomer.
144
166
  */
@@ -153,16 +175,15 @@ export class HelmCellRenderer extends DG.GridCellRenderer {
153
175
 
154
176
  onMouseMove(gridCell: DG.GridCell, e: MouseEvent): void {
155
177
  try {
156
- /* Can not do anything without tableColumn containing temp */
157
- let tableCol: DG.Column | null = null;
158
- try { tableCol = gridCell.tableColumn; } catch { }
178
+ const [_gridCol, tableCol, temp] = getRendererGridCellTemp(gridCell);
179
+ const helmPlacer = temp[Temps.helmMonomerPlacer];
180
+ /* Can not do anything without tableColumn */
159
181
  if (!tableCol) return;
160
182
 
161
183
  /** {@link gridCell}.bounds */ const gcb = gridCell.bounds;
162
184
  const argsX = e.offsetX - gcb.x;
163
185
  const argsY = e.offsetY - gcb.y;
164
186
 
165
- const helmPlacer = HelmMonomerPlacer.getOrCreate(gridCell.gridColumn, tableCol);
166
187
  const editor: IEditor | null = helmPlacer.getEditor(gridCell.tableRowIndex!);
167
188
  let seqMonomer: ISeqMonomer | null;
168
189
  let missedMonomers: Set<string> = new Set<string>(); // of .size = 0
@@ -225,10 +246,11 @@ export class HelmCellRenderer extends DG.GridCellRenderer {
225
246
  ) {
226
247
  g.save();
227
248
  try {
249
+ const [gridCol, tableCol, temp] = getRendererGridCellTemp(gridCell);
228
250
  /* Can not do anything without tableColumn containing temp */
229
- let tableCol: DG.Column | null = null;
230
- try { tableCol = gridCell.tableColumn; } catch { }
231
251
  if (!tableCol) return;
252
+ let helmPlacer = temp[Temps.helmMonomerPlacer];
253
+ if (!helmPlacer) helmPlacer = temp[Temps.helmMonomerPlacer] = new HelmMonomerPlacer(gridCol, tableCol);
232
254
 
233
255
  const grid = gridCell.gridRow !== -1 ? gridCell.grid : undefined;
234
256
  const missedColor = 'red';
@@ -239,7 +261,6 @@ export class HelmCellRenderer extends DG.GridCellRenderer {
239
261
  const monomerList = parseHelm(seq);
240
262
  const monomers: Set<string> = new Set<string>(monomerList);
241
263
  const missedMonomers: Set<string> = findMonomers(monomerList);
242
- const helmPlacer = HelmMonomerPlacer.getOrCreate(gridCell.gridColumn, tableCol);
243
264
 
244
265
  if (missedMonomers.size == 0) {
245
266
  // 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);