@datagrok/curves 1.11.0 → 1.12.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.
@@ -20,8 +20,8 @@ import {
20
20
  LogOptions, getDataPoints,
21
21
  } from '@datagrok-libraries/statistics/src/fit/fit-data';
22
22
 
23
- import {convertXMLToIFitChartData} from './fit-parser';
24
23
  import {FitConstants} from '@datagrok-libraries/statistics/src/fit/const';
24
+ import {parseCellValue, isNativeFormat} from './curve-converter';
25
25
  import {
26
26
  renderAxesLabels,
27
27
  renderConfidenceIntervals, renderConnectDots,
@@ -155,8 +155,7 @@ function getChartData(tableCell: DG.Cell): IFitChartData {
155
155
  cellValue = cellValue.replaceAll('|', '');
156
156
  const column = tableCell.column;
157
157
  const cellChartData: IFitChartData = column ? (column.type === DG.TYPE.STRING ?
158
- (column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
159
- convertXMLToIFitChartData(cellValue) : JSON.parse(cellValue ?? '{}') ?? {}) :
158
+ parseCellValue(cellValue, column) :
160
159
  createDefaultChartData()) : JSON.parse(cellValue ?? '{}') ?? {};
161
160
 
162
161
  const columnChartOptions = tableCell.column ? getColumnChartOptions(tableCell.column) : {};
@@ -260,8 +259,8 @@ export function substituteZeroes(data: IFitChartData): void {
260
259
 
261
260
  export function setOutlier(gridCell: DG.GridCell, p: IFitPoint, seriesIdx: number, pointIdx: number, _data?: IFitChartData) {
262
261
  p.outlier = !p.outlier;
263
- // temporarily works only for JSON structure
264
- if (gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) !== FitConstants.TAG_FIT_CHART_FORMAT_3DX) {
262
+ // outlier toggling works only for native JSON format (no converter)
263
+ if (isNativeFormat(gridCell.cell.column)) {
265
264
  const gridCellValue = JSON.parse(gridCell.cell.value) as IFitChartData;
266
265
  gridCellValue.series![seriesIdx].points[pointIdx].outlier = p.outlier;
267
266
  gridCell.cell.column.set(gridCell.cell.rowIndex, JSON.stringify(gridCellValue), true);
@@ -276,8 +275,7 @@ export function setOutlier(gridCell: DG.GridCell, p: IFitPoint, seriesIdx: numbe
276
275
  }
277
276
  const columns = gridCell.grid.dataFrame.columns.byTags({'.sourceColumn': gridCell.cell.column.name});
278
277
  if (columns) {
279
- _data ??= gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
280
- convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell.cell);
278
+ _data ??= getOrCreateParsedChartData(gridCell.cell);
281
279
  for (const column of columns) {
282
280
  const chartLogOptions: LogOptions = {logX: _data.chartOptions?.logX, logY: _data.chartOptions?.logY};
283
281
  const stats = column.tags['.seriesAggregation'] !== null ?
@@ -341,8 +339,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
341
339
  if (!gridCell.cell.value || !gridCell.cell.column)
342
340
  return;
343
341
 
344
- const data = gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
345
- convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell.cell, false);
342
+ const data = getOrCreateParsedChartData(gridCell.cell, false);
346
343
 
347
344
  for (const [message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
348
345
  if (condition(data.series)) {
@@ -496,8 +493,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
496
493
  return;
497
494
 
498
495
  const isRenderedOnGrid = gridCell?.grid && gridCell?.grid.dart && g.canvas === gridCell?.grid?.canvas; // only use cache for grid, because there is no guarantee that rowIdx will be correct for other places
499
- const data = gridCell.cell.column?.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
500
- convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell.cell, isRenderedOnGrid);
496
+ const data = getOrCreateParsedChartData(gridCell.cell, isRenderedOnGrid);
501
497
  const screenBounds = FitChartCellRenderer.inflateScreenBounds(new DG.Rect(x, y, w, h));
502
498
 
503
499
  for (const [_message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
@@ -538,10 +534,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
538
534
  ui.tooltip.show(content, e.x, e.y);
539
535
  }
540
536
 
541
- // TODO: add caching
542
- const data = gridCell.cell.column?.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
543
- convertXMLToIFitChartData(gridCell.cell.value) :
544
- getOrCreateParsedChartData(gridCell?.cell);
537
+ const data = getOrCreateParsedChartData(gridCell?.cell);
545
538
 
546
539
  if (screenBounds.width >= FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH &&
547
540
  screenBounds.height >= FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
@@ -0,0 +1,251 @@
1
+ import * as DG from 'datagrok-api/dg';
2
+
3
+ import {
4
+ IFitChartData,
5
+ IFitChartOptions,
6
+ IFitSeries,
7
+ IFitPoint,
8
+ FIT_FUNCTION_SIGMOID,
9
+ } from '@datagrok-libraries/statistics/src/fit/fit-curve';
10
+
11
+
12
+ const PZFX_NS = 'http://graphpad.com/prism/Prism.htm';
13
+
14
+
15
+ export interface PzfxSubcolumn {
16
+ values: (number | null)[];
17
+ excluded: boolean[];
18
+ }
19
+
20
+ export interface PzfxYColumn {
21
+ title: string;
22
+ subcolumns: PzfxSubcolumn[];
23
+ }
24
+
25
+ export interface PzfxTable {
26
+ id: string;
27
+ title: string;
28
+ tableType: string;
29
+ xFormat: string;
30
+ xTitle: string;
31
+ xValues: (number | null)[];
32
+ yColumns: PzfxYColumn[];
33
+ }
34
+
35
+
36
+ /** Returns child elements matching a local name, handling XML namespaces. */
37
+ function getChildren(parent: Element, localName: string): Element[] {
38
+ const results: Element[] = [];
39
+ for (let i = 0; i < parent.children.length; i++) {
40
+ const child = parent.children[i];
41
+ if (child.localName === localName)
42
+ results.push(child);
43
+ }
44
+ return results;
45
+ }
46
+
47
+ /** Returns the first child element matching a local name. */
48
+ function getChild(parent: Element, localName: string): Element | null {
49
+ for (let i = 0; i < parent.children.length; i++) {
50
+ if (parent.children[i].localName === localName)
51
+ return parent.children[i];
52
+ }
53
+ return null;
54
+ }
55
+
56
+ /** Returns the text content of the first child element matching a local name. */
57
+ function getChildText(parent: Element, localName: string): string {
58
+ const el = getChild(parent, localName);
59
+ return el?.textContent?.trim() ?? '';
60
+ }
61
+
62
+ /** Parses `<d>` elements from a `<Subcolumn>` element. */
63
+ function parseSubcolumn(subcolEl: Element): PzfxSubcolumn {
64
+ const dElements = getChildren(subcolEl, 'd');
65
+ const values: (number | null)[] = [];
66
+ const excluded: boolean[] = [];
67
+
68
+ for (const d of dElements) {
69
+ const text = d.textContent?.trim() ?? '';
70
+ if (text === '') {
71
+ values.push(null);
72
+ excluded.push(false);
73
+ } else {
74
+ values.push(parseFloat(text));
75
+ excluded.push(d.getAttribute('Excluded') === '1');
76
+ }
77
+ }
78
+
79
+ return {values, excluded};
80
+ }
81
+
82
+ /** Parses a `<YColumn>` element. */
83
+ function parseYColumn(yColEl: Element): PzfxYColumn {
84
+ const title = getChildText(yColEl, 'Title');
85
+ const subcolumns = getChildren(yColEl, 'Subcolumn').map(parseSubcolumn);
86
+ return {title, subcolumns};
87
+ }
88
+
89
+ /** Parses a `<Table>` or `<HugeTable>` element. */
90
+ function parseTable(tableEl: Element): PzfxTable {
91
+ const id = tableEl.getAttribute('ID') ?? '';
92
+ const tableType = tableEl.getAttribute('TableType') ?? '';
93
+ const xFormat = tableEl.getAttribute('XFormat') ?? '';
94
+ const title = getChildText(tableEl, 'Title');
95
+
96
+ let xTitle = '';
97
+ let xValues: (number | null)[] = [];
98
+
99
+ const xCol = getChild(tableEl, 'XColumn');
100
+ if (xCol) {
101
+ xTitle = getChildText(xCol, 'Title');
102
+ const xSubcol = getChild(xCol, 'Subcolumn');
103
+ if (xSubcol)
104
+ xValues = parseSubcolumn(xSubcol).values;
105
+ }
106
+
107
+ const yColumns = getChildren(tableEl, 'YColumn').map(parseYColumn);
108
+
109
+ return {id, title, tableType, xFormat, xTitle, xValues, yColumns};
110
+ }
111
+
112
+
113
+ /** Parses a PZFX XML string and returns an array of tables.
114
+ * Truncates at the closing root tag to handle trailing binary data. */
115
+ export function parsePzfxXml(xmlText: string): PzfxTable[] {
116
+ const closingTag = '</GraphPadPrismFile>';
117
+ const closingIdx = xmlText.indexOf(closingTag);
118
+ if (closingIdx !== -1)
119
+ xmlText = xmlText.substring(0, closingIdx + closingTag.length);
120
+
121
+ const parser = new DOMParser();
122
+ const doc = parser.parseFromString(xmlText, 'text/xml');
123
+
124
+ const root = doc.documentElement;
125
+ if (root.nodeName === 'parsererror')
126
+ return [];
127
+
128
+ const tables: PzfxTable[] = [];
129
+ for (let i = 0; i < root.children.length; i++) {
130
+ const el = root.children[i];
131
+ if (el.localName === 'Table' || el.localName === 'HugeTable')
132
+ tables.push(parseTable(el));
133
+ }
134
+ return tables;
135
+ }
136
+
137
+
138
+ /** Converts a PZFX XY table to an IFitChartData object.
139
+ * Returns null for non-XY tables or tables without numeric X data. */
140
+ export function pzfxTableToFitChartData(table: PzfxTable): IFitChartData | null {
141
+ if (table.tableType !== 'XY' || table.xValues.length === 0)
142
+ return null;
143
+
144
+ const series: IFitSeries[] = [];
145
+
146
+ for (const yCol of table.yColumns) {
147
+ const points: IFitPoint[] = [];
148
+
149
+ for (const subcol of yCol.subcolumns) {
150
+ for (let i = 0; i < table.xValues.length; i++) {
151
+ const x = table.xValues[i];
152
+ if (x == null || i >= subcol.values.length)
153
+ continue;
154
+ const y = subcol.values[i];
155
+ if (y == null)
156
+ continue;
157
+ points.push({
158
+ x,
159
+ y,
160
+ outlier: subcol.excluded[i] || false,
161
+ });
162
+ }
163
+ }
164
+
165
+ if (points.length === 0)
166
+ continue;
167
+
168
+ series.push({
169
+ name: yCol.title,
170
+ fitFunction: FIT_FUNCTION_SIGMOID,
171
+ showFitLine: true,
172
+ showPoints: 'points',
173
+ clickToToggle: true,
174
+ droplines: ['IC50'],
175
+ points,
176
+ });
177
+ }
178
+
179
+ if (series.length === 0)
180
+ return null;
181
+
182
+ const chartOptions: IFitChartOptions = {
183
+ logX: true,
184
+ xAxisName: table.xTitle || 'Concentration',
185
+ yAxisName: 'Response',
186
+ title: table.title,
187
+ };
188
+
189
+ return {chartOptions, series};
190
+ }
191
+
192
+
193
+ /** Converts PZFX XY tables into a DataFrame with a fit column. Each row is one XY table. */
194
+ export function pzfxToFitDataFrame(tables: PzfxTable[]): DG.DataFrame {
195
+ const xyTables = tables.filter((t) => t.tableType === 'XY');
196
+ const names: string[] = [];
197
+ const curves: string[] = [];
198
+
199
+ for (const table of xyTables) {
200
+ const chartData = pzfxTableToFitChartData(table);
201
+ if (!chartData)
202
+ continue;
203
+ names.push(table.title || table.id);
204
+ curves.push(JSON.stringify(chartData));
205
+ }
206
+
207
+ const df = DG.DataFrame.create(names.length);
208
+ df.setTag(DG.Tags.Id, crypto.randomUUID());
209
+ df.name = 'PZFX Curves';
210
+
211
+ const nameCol = df.columns.addNewString('Table');
212
+ for (let i = 0; i < names.length; i++)
213
+ nameCol.set(i, names[i]);
214
+
215
+ const curveCol = df.columns.addNewString('Fitted Curve');
216
+ curveCol.semType = 'fit';
217
+ curveCol.meta.cellRenderer = 'fit';
218
+ for (let i = 0; i < curves.length; i++)
219
+ curveCol.set(i, curves[i]);
220
+
221
+ return df;
222
+ }
223
+
224
+
225
+ /** Converts a non-XY PZFX table into a plain DataFrame. */
226
+ export function pzfxTableToDataFrame(table: PzfxTable): DG.DataFrame {
227
+ const maxRows = Math.max(...table.yColumns.map((yc) =>
228
+ Math.max(...yc.subcolumns.map((sc) => sc.values.length), 0)), 0);
229
+
230
+ const df = DG.DataFrame.create(maxRows);
231
+ df.setTag(DG.Tags.Id, crypto.randomUUID());
232
+ df.name = table.title || table.id;
233
+
234
+ for (const yCol of table.yColumns) {
235
+ if (yCol.subcolumns.length === 1) {
236
+ const col = df.columns.addNewFloat(yCol.title || 'Values');
237
+ const sc = yCol.subcolumns[0];
238
+ for (let i = 0; i < sc.values.length; i++)
239
+ col.set(i, sc.values[i] ?? DG.FLOAT_NULL);
240
+ } else {
241
+ for (let si = 0; si < yCol.subcolumns.length; si++) {
242
+ const col = df.columns.addNewFloat(`${yCol.title}_${si + 1}`);
243
+ const sc = yCol.subcolumns[si];
244
+ for (let i = 0; i < sc.values.length; i++)
245
+ col.set(i, sc.values[i] ?? DG.FLOAT_NULL);
246
+ }
247
+ }
248
+ }
249
+
250
+ return df;
251
+ }
@@ -54,4 +54,33 @@ export namespace funcs {
54
54
  export async function addAggrStatisticsColumn(table: DG.DataFrame , colName: string , propName: string , aggrType: string ): Promise<DG.Column> {
55
55
  return await grok.functions.call('Curves:AddAggrStatisticsColumn', { table, colName, propName, aggrType });
56
56
  }
57
+
58
+ /**
59
+ Returns XML 3DX curve converter function
60
+ */
61
+ export async function convertXmlCurveToJsonFunc(): Promise<any> {
62
+ return await grok.functions.call('Curves:ConvertXmlCurveToJsonFunc', {});
63
+ }
64
+
65
+ /**
66
+ Returns compact dose-response JSON converter function
67
+ */
68
+ export async function convertCompactDrToJsonFunc(): Promise<any> {
69
+ return await grok.functions.call('Curves:ConvertCompactDrToJsonFunc', {});
70
+ }
71
+
72
+ /**
73
+ Returns PZFX curve converter function
74
+ */
75
+ export async function convertPzfxToJsonFunc(): Promise<any> {
76
+ return await grok.functions.call('Curves:ConvertPzfxToJsonFunc', {});
77
+ }
78
+
79
+ export async function previewPzfx(file: DG.FileInfo ): Promise<DG.View> {
80
+ return await grok.functions.call('Curves:PreviewPzfx', { file });
81
+ }
82
+
83
+ export async function pzfxFileHandler(bytes: any ): Promise<any> {
84
+ return await grok.functions.call('Curves:PzfxFileHandler', { bytes });
85
+ }
57
86
  }
@@ -3,9 +3,11 @@ import * as DG from 'datagrok-api/dg';
3
3
  import {runTests, tests, TestContext, initAutoTests as initTests} from '@datagrok-libraries/test/src/test';
4
4
 
5
5
  import './tests/detector-tests';
6
+ import './tests/converter-tests';
6
7
  import './tests/curves-cell-renderer-tests';
7
8
  import './tests/transform-tests';
8
9
  import './tests/fit-tests';
10
+ import './tests/pzfx-tests';
9
11
 
10
12
  export const _package = new DG.Package();
11
13
  export {tests};
package/src/package.g.ts CHANGED
@@ -31,8 +31,8 @@ export async function curveFitDemo() : Promise<void> {
31
31
  }
32
32
 
33
33
  //meta.role: init
34
- export function _initCurves() : void {
35
- PackageFunctions._initCurves();
34
+ export async function _initCurves() : Promise<void> {
35
+ await PackageFunctions._initCurves();
36
36
  }
37
37
 
38
38
  //input: dataframe df
@@ -86,3 +86,43 @@ export function addStatisticsColumn(table: DG.DataFrame, colName: string, propNa
86
86
  export function addAggrStatisticsColumn(table: DG.DataFrame, colName: string, propName: string, aggrType: string) : any {
87
87
  return PackageFunctions.addAggrStatisticsColumn(table, colName, propName, aggrType);
88
88
  }
89
+
90
+ //description: Returns XML 3DX curve converter function
91
+ //output: dynamic result
92
+ //meta.role: curveConverter
93
+ //meta.curveFormat: 3dx
94
+ export function convertXmlCurveToJsonFunc() : any {
95
+ return PackageFunctions.convertXmlCurveToJsonFunc();
96
+ }
97
+
98
+ //description: Returns compact dose-response JSON converter function
99
+ //output: dynamic result
100
+ //meta.role: curveConverter
101
+ //meta.curveFormat: compact-dr
102
+ export function convertCompactDrToJsonFunc() : any {
103
+ return PackageFunctions.convertCompactDrToJsonFunc();
104
+ }
105
+
106
+ //description: Returns PZFX curve converter function
107
+ //output: dynamic result
108
+ //meta.role: curveConverter
109
+ //meta.curveFormat: pzfx
110
+ export function convertPzfxToJsonFunc() : any {
111
+ return PackageFunctions.convertPzfxToJsonFunc();
112
+ }
113
+
114
+ //input: file file
115
+ //output: view result
116
+ //meta.role: fileViewer
117
+ //meta.fileViewer: pzfx
118
+ export async function previewPzfx(file: DG.FileInfo) : Promise<any> {
119
+ return await PackageFunctions.previewPzfx(file);
120
+ }
121
+
122
+ //input: list bytes
123
+ //output: list<dataframe> result
124
+ //meta.role: fileHandler
125
+ //meta.ext: pzfx
126
+ export function pzfxFileHandler(bytes: Uint8Array) : any {
127
+ return PackageFunctions.pzfxFileHandler(bytes);
128
+ }
package/src/package.ts CHANGED
@@ -10,15 +10,18 @@ import * as ui from 'datagrok-api/ui';
10
10
  import {FitGridCellHandler, calculateSeriesStats, getChartDataAggrStats} from './fit/fit-grid-cell-handler';
11
11
  import {getOrCreateParsedChartData, substituteZeroes} from './fit/fit-renderer';
12
12
  import {curveDemo} from './fit/fit-demo';
13
- import {convertXMLToIFitChartData} from './fit/fit-parser';
13
+ import {convertXmlCurveToJson} from './fit/converters/xml-converter';
14
+ import {convertCompactDrToJson} from './fit/converters/compact-dr-converter';
15
+ import {convertPzfxToJson} from './fit/converters/pzfx-converter';
16
+ import {registerCurveConverter, initExternalConverters} from './fit/curve-converter';
14
17
  import {LogOptions} from '@datagrok-libraries/statistics/src/fit/fit-data';
15
18
  import {FitStatistics} from '@datagrok-libraries/statistics/src/fit/fit-curve';
16
- import {FitConstants} from '@datagrok-libraries/statistics/src/fit/const';
17
19
 
18
20
  // import {PlateWidget} from './plate/plate-widget';
19
21
 
20
22
  import * as api from './package-api';
21
23
  import {convertDataToCurves, dataToCurvesUI} from './fit/data-to-curves';
24
+ import {parsePzfxXml, pzfxTableToFitChartData, pzfxToFitDataFrame, pzfxTableToDataFrame} from './formats/pzfx/pzfx-parser';
22
25
 
23
26
  export const _package = new DG.Package();
24
27
 
@@ -60,8 +63,14 @@ export class PackageFunctions {
60
63
  // }
61
64
 
62
65
  @grok.decorators.init()
63
- static _initCurves(): void {
66
+ static async _initCurves(): Promise<void> {
64
67
  DG.ObjectHandler.register(new FitGridCellHandler());
68
+ // Register local converters by format name (avoids circular dependency with DG.Func.find)
69
+ registerCurveConverter('3dx', convertXmlCurveToJson);
70
+ registerCurveConverter('compact-dr', convertCompactDrToJson);
71
+ registerCurveConverter('pzfx', convertPzfxToJson);
72
+ // Discover converters from external packages (skips already-registered local ones)
73
+ await initExternalConverters();
65
74
  }
66
75
 
67
76
  @grok.decorators.func()
@@ -123,8 +132,7 @@ export class PackageFunctions {
123
132
  const cell = df.cell(i, sourceColName);
124
133
  if (!cell || !cell.value)
125
134
  return null;
126
- const chartData = cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
127
- convertXMLToIFitChartData(cell.value) : getOrCreateParsedChartData(cell, true); // false because there is no dataframe
135
+ const chartData = getOrCreateParsedChartData(cell, true);
128
136
  if (chartData.series![seriesNumber] === undefined || chartData.series![seriesNumber].points.every((p) => p.outlier))
129
137
  return null;
130
138
  if (chartData.chartOptions?.allowXZeroes && chartData.chartOptions?.logX &&
@@ -154,9 +162,7 @@ export class PackageFunctions {
154
162
  const cell = df.cell(i, colName);
155
163
  if (!cell || !cell.value)
156
164
  return null;
157
- const chartData =
158
- cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
159
- convertXMLToIFitChartData(cell.value) : getOrCreateParsedChartData(cell);
165
+ const chartData = getOrCreateParsedChartData(cell);
160
166
  if (chartData.series?.every((series) => series.points.every((p) => p.outlier)))
161
167
  return null;
162
168
  if (chartData.chartOptions?.allowXZeroes && chartData.chartOptions?.logX &&
@@ -168,4 +174,60 @@ export class PackageFunctions {
168
174
  df.columns.insert(column, df.columns.names().indexOf(colName) + 1);
169
175
  return column;
170
176
  }
177
+
178
+ @grok.decorators.func({description: 'Returns XML 3DX curve converter function', meta: {role: 'curveConverter', curveFormat: '3dx'}})
179
+ static convertXmlCurveToJsonFunc(): (value: string) => string {
180
+ return convertXmlCurveToJson;
181
+ }
182
+
183
+ @grok.decorators.func({description: 'Returns compact dose-response JSON converter function', meta: {role: 'curveConverter', curveFormat: 'compact-dr'}})
184
+ static convertCompactDrToJsonFunc(): (value: string) => string {
185
+ return convertCompactDrToJson;
186
+ }
187
+
188
+ @grok.decorators.func({description: 'Returns PZFX curve converter function', meta: {role: 'curveConverter', curveFormat: 'pzfx'}})
189
+ static convertPzfxToJsonFunc(): (value: string) => string {
190
+ return convertPzfxToJson;
191
+ }
192
+
193
+ @grok.decorators.fileViewer({fileViewer: 'pzfx'})
194
+ static async previewPzfx(file: DG.FileInfo): Promise<DG.View> {
195
+ const view = DG.View.create();
196
+ view.name = file.name;
197
+
198
+ const text = await file.readAsString();
199
+ const tables = parsePzfxXml(text);
200
+ const xyTables = tables.filter((t) => t.tableType === 'XY');
201
+
202
+ if (xyTables.length === 0) {
203
+ const nonXyDfs = tables.map(pzfxTableToDataFrame);
204
+ for (const df of nonXyDfs)
205
+ view.append(DG.Viewer.grid(df).root);
206
+ return view;
207
+ }
208
+
209
+ const df = pzfxToFitDataFrame(xyTables);
210
+ const grid = DG.Viewer.grid(df);
211
+ grid.root.style.width = '100%';
212
+ grid.root.style.height = '100%';
213
+ view.append(grid.root);
214
+
215
+ return view;
216
+ }
217
+
218
+ @grok.decorators.fileHandler({ext: 'pzfx'})
219
+ static pzfxFileHandler(@grok.decorators.param({type: 'list'}) bytes: Uint8Array): DG.DataFrame[] {
220
+ const text = new TextDecoder().decode(new Uint8Array(bytes));
221
+ const tables = parsePzfxXml(text);
222
+ const results: DG.DataFrame[] = [];
223
+
224
+ const xyTables = tables.filter((t) => t.tableType === 'XY');
225
+ if (xyTables.length > 0)
226
+ results.push(pzfxToFitDataFrame(xyTables));
227
+
228
+ for (const table of tables.filter((t) => t.tableType !== 'XY'))
229
+ results.push(pzfxTableToDataFrame(table));
230
+
231
+ return results;
232
+ }
171
233
  }