@datagrok/curves 1.5.0 → 1.8.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.
@@ -0,0 +1,129 @@
1
+ import * as DG from 'datagrok-api/dg';
2
+ import { PLATE_OUTLIER_WELL_NAME } from './plate';
3
+ import wu from 'wu';
4
+ //@ts-ignore
5
+ import * as jStat from 'jstat';
6
+
7
+
8
+ /** If the condition is false, throws message(). */
9
+ export function assure(condition: boolean, errorMessage: string | (() => string)) {
10
+ if (!condition)
11
+ throw new Error(typeof errorMessage === 'string' ? errorMessage : errorMessage());
12
+ }
13
+
14
+
15
+ export function firstWhere<T>(items: Iterable<T>, check: ((item: T) => boolean)): T | null {
16
+ for (const x of items)
17
+ if (check(x))
18
+ return x;
19
+ return null;
20
+ }
21
+
22
+ /**
23
+ * Converts a number to Excel column letters (A-ZZ)
24
+ * Examples:
25
+ * 0 -> "A"
26
+ * 25 -> "Z"
27
+ * 26 -> "AA"
28
+ * 51 -> "AZ"
29
+ * 701 -> "ZZ"
30
+ *
31
+ * @param num - The zero-based column number to convert
32
+ * @returns The Excel column letter(s)
33
+ * @throws Error if the column number is negative or would require more than 2 letters
34
+ */
35
+ export function numToExcel(num: number): string {
36
+ assure(num >= 0, 'Column number cannot be negative');
37
+ assure(num < 701, 'Column number too large - would require more than 2 letters');
38
+
39
+ const _a = 'A'.charCodeAt(0);
40
+ if (num < 24)
41
+ return String.fromCharCode(_a + num);
42
+
43
+ const firstLetter = Math.floor(num / 26);
44
+ const secondLetter = num % 26;
45
+
46
+ return String.fromCharCode(_a + firstLetter - 1) + String.fromCharCode(_a + secondLetter);
47
+ }
48
+
49
+
50
+ /** Converts Excel column letter to number.
51
+ * Opposite to {@link numToExcel}. */
52
+ export function excelToNum(row: string): number {
53
+ let result = 0;
54
+ for (let i = 0; i < row.length; i++)
55
+ result = result * 26 + (row.charCodeAt(i) - 64);
56
+ return result - 1;
57
+ }
58
+
59
+
60
+ /** Parses the 'A3' cell position notation to 0-based {row, col} structure. */
61
+ export function parseExcelPosition(cell: string): [number, number] {
62
+ const match = cell.match(/^([A-Za-z]+)(\d+)$/);
63
+ if (!match)
64
+ throw new Error("Invalid cell format. Expected format like 'A3'.");
65
+
66
+ const row = excelToNum(match[1].toUpperCase());
67
+ const col = parseInt(match[2]) - 1;
68
+
69
+ return [ row, col ];
70
+ }
71
+
72
+ export function getMaxPosition(positions: Iterable<[number, number]>): [number, number] {
73
+ return wu(positions).reduce((max, [row, col]) => [Math.max(max[0], row), Math.max(max[1], col)], [0, 0]);
74
+ }
75
+
76
+ export function toStandardSize([rows, cols]: number[]): [number, number] {
77
+ if (rows <= 8 && cols <= 12)
78
+ return [8, 12];
79
+ if (rows <= 16 && cols <= 24)
80
+ return [16, 24];
81
+ if (rows <= 32 && cols <= 48)
82
+ return [32, 48];
83
+ throw `${rows}x${cols} exceeds maximum plate size 32x48`;
84
+ }
85
+
86
+ export function safeLog(num: number) {
87
+ return num <= 0 ? 0 : Math.log10(num);
88
+ }
89
+
90
+ export function mapFromRow(row: DG.Row, outlierSetFunc?: (row: number, checkBoxState: boolean) => void) {
91
+ if (!row || row.idx == null || row.idx < 0 || !row.table)
92
+ return {};
93
+ const res: {[index: string]: any} = {};
94
+ const idx = row.idx;
95
+ for (const column of row.table.columns) {
96
+ if (column.name?.toLowerCase() === PLATE_OUTLIER_WELL_NAME?.toLowerCase() && column.type === DG.COLUMN_TYPE.BOOL && outlierSetFunc) {
97
+ const currentVal = column.isNone(idx) ? false : column.get(idx);
98
+ const check = document.createElement('input');
99
+ check.type = 'checkbox';
100
+ check.checked = check.value = currentVal;
101
+ check.onchange = (e) => outlierSetFunc(row.idx, check.checked);
102
+ res[column.name] = check;
103
+ } else
104
+ res[column.name] = column.isNone(idx) ? 'No data' : column.isNumerical && column.type !== DG.COLUMN_TYPE.DATE_TIME ? formatTableNumber(column.get(idx)) : column.get(idx);
105
+ }
106
+ return res;
107
+ }
108
+
109
+ export function formatTableNumber(num: number): string | number {
110
+ if (num === 0)
111
+ return '0';
112
+ if (Math.abs(num) < 1e-3)
113
+ return DG.format(num, 'scientific');
114
+ else if (Math.abs(num) < 1)
115
+ return DG.format(num, '0.0000');
116
+ return num;
117
+ }
118
+
119
+ export type JSTATStatistics = 'mean' | 'median' | 'std' | 'min' | 'max' | 'meansqerr' | 'geomean'; // TODO: add more
120
+
121
+ export const jstatStatistics: Record<JSTATStatistics, (val: number[]) => number> = {
122
+ mean: jStat.mean,
123
+ median: jStat.median,
124
+ std: jStat.stdev,
125
+ min: jStat.min,
126
+ max: jStat.max,
127
+ meansqerr: jStat.meansqerr,
128
+ geomean: jStat.geomean
129
+ }
@@ -42,16 +42,24 @@ export async function scrollTable(el: HTMLElement, delta: number, cycles: number
42
42
  }
43
43
  }
44
44
 
45
+ async function getTime(func: (chartData?: IFitChartData | null) => Promise<void>, funcChartData?: IFitChartData | null): Promise<number> {
46
+ const start = Date.now();
47
+ await func(funcChartData);
48
+ const stop = Date.now();
49
+ return stop.valueOf() - start.valueOf();
50
+ }
51
+
45
52
 
46
53
  category('creation', () => {
47
54
  test('fit curve creation', async () => {
48
- const start = Date.now();
49
- const df = createDemoDataFrame(DG.Test.isInBenchmark ? 1000 : 100, 5, 2);
50
- grok.shell.addTableView(df);
51
- const stop = Date.now();
52
- await delay(50);
53
- console.log(`Creation took ${stop.valueOf() - start.valueOf()} ms`)
54
- return `${DG.Test.isInBenchmark ? 1000 : 100} points, took ${stop.valueOf() - start.valueOf()} ms`
55
+ const pointsAmount = DG.Test.isInBenchmark ? 1000 : 100;
56
+ const func = async (chartData?: IFitChartData | null) => {
57
+ const df = createDemoDataFrame(pointsAmount, 5, 2);
58
+ grok.shell.addTableView(df);
59
+ };
60
+ const time = await getTime(func, null);
61
+ console.log(`Creation took ${time} ms`)
62
+ return `${pointsAmount} points, took ${time} ms`
55
63
  }, {benchmark: true});
56
64
  });
57
65
 
@@ -67,11 +75,14 @@ category('rendering', () => {
67
75
 
68
76
  const fitChartCellRenderer = new FitChartCellRenderer();
69
77
  const fitChartData: IFitChartData = createIFitChartData(DG.Test.isInBenchmark ? 50 : 15);
70
- for (let i = 1; i <= renderingTimesAmount; i++) {
71
- fitChartCellRenderer.renderCurves(g, new DG.Rect(canvas.clientLeft, canvas.clientTop, canvasWidth, canvasHeight).inflate(FitConstants.INFLATE_SIZE, FitConstants.INFLATE_SIZE), fitChartData);
78
+ const times: number[] = [];
79
+ const func = async (chartData?: IFitChartData | null) => {
80
+ fitChartCellRenderer.renderCurves(g, FitChartCellRenderer.inflateScreenBounds(new DG.Rect(canvas.clientLeft, canvas.clientTop, canvasWidth, canvasHeight)), fitChartData);
72
81
  g.clearRect(0, 0, canvasWidth, canvasHeight);
73
- }
74
- return `rendering performed ${renderingTimesAmount} times`;
82
+ };
83
+ for (let i = 1; i <= renderingTimesAmount; i++)
84
+ times[times.length] = await getTime(func);
85
+ return `rendering performed ${renderingTimesAmount} times, max time is ${Math.max(...times)} ms, min time is ${Math.min(...times)} ms, average time is ${times.reduce((a, b) => a + b, 0) / times.length} ms`;
75
86
  }, {benchmark: true});
76
87
 
77
88
  test('rendering different fitChartData on canvas', async () => {
@@ -84,25 +95,33 @@ category('rendering', () => {
84
95
  const g = canvas.getContext('2d')!;
85
96
 
86
97
  const fitChartCellRenderer = new FitChartCellRenderer();
98
+ const times: number[] = [];
99
+ const func = async (chartData?: IFitChartData | null) => {
100
+ fitChartCellRenderer.renderCurves(g, FitChartCellRenderer.inflateScreenBounds(new DG.Rect(canvas.clientLeft, canvas.clientTop, canvasWidth, canvasHeight)), chartData!);
101
+ g.clearRect(0, 0, canvasWidth, canvasHeight);
102
+ }
87
103
  for (let i = 1; i <= renderingTimesAmount; i++) {
88
104
  const fitChartData = createIFitChartData(DG.Test.isInBenchmark ? 50 : 15);
89
- fitChartCellRenderer.renderCurves(g, new DG.Rect(canvas.clientLeft, canvas.clientTop, canvasWidth, canvasHeight).inflate(FitConstants.INFLATE_SIZE, FitConstants.INFLATE_SIZE), fitChartData);
90
- g.clearRect(0, 0, canvasWidth, canvasHeight);
105
+ times[times.length] = await getTime(func, fitChartData);
91
106
  }
92
- return `rendering performed ${renderingTimesAmount} times`;
107
+ return `rendering performed ${renderingTimesAmount} times, max time is ${Math.max(...times)} ms, min time is ${Math.min(...times)} ms, average time is ${times.reduce((a, b) => a + b, 0) / times.length} ms`;
93
108
  }, {benchmark: true});
94
109
 
95
110
  test('rendering in grid', async () => {
96
- const df = createDemoDataFrame(30, 5, 2);
111
+ const df = createDemoDataFrame(50, 5, 5);
97
112
  const tv = grok.shell.addTableView(df);
98
113
  const scrollCycles = 10;
99
- const scrollDelta = 300;
114
+ const scrollDeltaPlus = 300;
115
+ const scrollDeltaMinus = -300;
100
116
  await delay(100);
101
117
  const canvas = tv.grid.root.getElementsByTagName('canvas')[2];
102
- const start = new Date();
103
- await scrollTable(canvas, scrollDelta, scrollCycles, 10);
104
- const stop = new Date();
105
- console.log(`curves rendering took ${stop.valueOf() - start.valueOf()} ms`);
106
- return `${stop.valueOf() - start.valueOf()} ms`;
107
- });
118
+ const func = async (chartData?: IFitChartData | null) => {
119
+ await scrollTable(canvas, scrollDeltaPlus, scrollCycles, 1);
120
+ await scrollTable(canvas, scrollDeltaMinus, scrollCycles, 1);
121
+ await scrollTable(canvas, scrollDeltaPlus, scrollCycles, 1);
122
+ };
123
+ const time = await getTime(func, null) - 30;
124
+ console.log(`curves rendering took ${time} ms`);
125
+ return time;
126
+ }, {benchmark: true});
108
127
  });
@@ -41,7 +41,7 @@ category('fit', () => {
41
41
  expect(logLinearFitFunc.name, FIT_FUNCTION_LOG_LINEAR);
42
42
  expect(exponentialFitFunc.name, FIT_FUNCTION_EXPONENTIAL);
43
43
  expect(polynomialFitFunc.name, 'Polynomial');
44
- expectArray(sigmoidFitFunc.parameterNames, ['Top', 'Bottom', 'Slope', 'IC50']);
44
+ expectArray(sigmoidFitFunc.parameterNames, ['Top', 'Slope', 'IC50', 'Bottom']);
45
45
  expectArray(linearFitFunc.parameterNames, ['Slope', 'Intercept']);
46
46
  expectArray(logLinearFitFunc.parameterNames, ['Slope', 'Intercept']);
47
47
  expectArray(exponentialFitFunc.parameterNames, ['Mantissa', 'Power']);
@@ -88,19 +88,54 @@ category('fit', () => {
88
88
  const polynomialFitSeries = fitSeries(polynomialSeries, polynomialFitFunc);
89
89
  const stop = Date.now();
90
90
 
91
- expect(sigmoidFitSeries.fittedCurve(2.5), 1.7048618582775712);
92
- expect(linearFitSeries.fittedCurve(2.5), 1.5337481647729874);
93
- expect(logLinearFitSeries.fittedCurve(2.5), 1.4879121793209378);
94
- expect(exponentialFitSeries.fittedCurve(0.00001345), 2.739771889293024);
95
- expect(polynomialFitSeries.fittedCurve(3.99876), 6.449473383870631);
96
- expectArray(sigmoidFitSeries.parameters, [1.7049071788787842, 1.569833517074585, 5.36868143081665, 0.2605934143066406]);
97
- expectArray(linearFitSeries.parameters, [-0.21358928084373474, 2.067721366882324]);
98
- expectArray(logLinearFitSeries.parameters, [-1.1107122898101807, 2.879371404647827]);
99
- expectArray(exponentialFitSeries.parameters, [2.739849090576172, -2.0949888229370117]);
100
- expectArray(polynomialFitSeries.parameters, [0.05000000074505806, -0.887523889541626, 2.861894130706787, 6]);
91
+ expect(sigmoidFitSeries.fittedCurve(2.5), 1.6903875076701773);
92
+ expect(linearFitSeries.fittedCurve(2.5), 1.5348530188202858);
93
+ expect(logLinearFitSeries.fittedCurve(2.5), 1.3696734183366701);
94
+ expect(exponentialFitSeries.fittedCurve(0.00001345), 2.005337264075174);
95
+ expect(polynomialFitSeries.fittedCurve(3.99876), 5.911350894323636);
96
+ expectArray(sigmoidFitSeries.parameters, [1.690911054611206, 1.1880898475646973, 5.402130603790283, 0.22163867950439453]);
97
+ expectArray(linearFitSeries.parameters, [-0.21431826055049896, 2.070648670196533]);
98
+ expectArray(logLinearFitSeries.parameters, [-0.6303421854972839, 2.1593427658081055]);
99
+ expectArray(exponentialFitSeries.parameters, [2.005340814590454, -0.13163800537586212]);
100
+ expectArray(polynomialFitSeries.parameters, [0.06199381500482559, -0.9554166793823242, 2.872941017150879, 5.736424446105957]);
101
101
  return `${stop.valueOf() - start.valueOf()} ms`;
102
102
  });
103
103
 
104
+ test('fitSeries sigmoid benchmark', async () => {
105
+ const start = Date.now();
106
+ fitSeries(sigmoidSeries, sigmoidFitFunc);
107
+ const stop = Date.now();
108
+ return `${stop.valueOf() - start.valueOf()} ms`;
109
+ }, {benchmark: true});
110
+
111
+ test('fitSeries linear benchmark', async () => {
112
+ const start = Date.now();
113
+ fitSeries(linearSeries, linearFitFunc);
114
+ const stop = Date.now();
115
+ return `${stop.valueOf() - start.valueOf()} ms`;
116
+ }, {benchmark: true});
117
+
118
+ test('fitSeries log-linear benchmark', async () => {
119
+ const start = Date.now();
120
+ fitSeries(logLinearSeries, logLinearFitFunc);
121
+ const stop = Date.now();
122
+ return `${stop.valueOf() - start.valueOf()} ms`;
123
+ }, {benchmark: true});
124
+
125
+ test('fitSeries exponential benchmark', async () => {
126
+ const start = Date.now();
127
+ fitSeries(exponentialSeries, exponentialFitFunc);
128
+ const stop = Date.now();
129
+ return `${stop.valueOf() - start.valueOf()} ms`;
130
+ }, {benchmark: true});
131
+
132
+ test('fitSeries polynomial benchmark', async () => {
133
+ const start = Date.now();
134
+ fitSeries(polynomialSeries, polynomialFitFunc);
135
+ const stop = Date.now();
136
+ return `${stop.valueOf() - start.valueOf()} ms`;
137
+ }, {benchmark: true});
138
+
104
139
  test('getSeriesConfidenceInterval', async () => {
105
140
  const sigmoidSeriesConfidenceIntervals = getSeriesConfidenceInterval(sigmoidSeries, sigmoidFitFunc, true);
106
141
  const linearSeriesConfidenceIntervals = getSeriesConfidenceInterval(linearSeries, linearFitFunc, true);
@@ -0,0 +1,154 @@
1
+ import * as DG from 'datagrok-api/dg';
2
+ import * as ui from 'datagrok-api/ui';
3
+
4
+ import {category, expect, test} from '@datagrok-libraries/utils/src/test';
5
+ import {Plate} from '../plate/plate';
6
+
7
+ // @ts-ignore
8
+ import * as jStat from 'jstat';
9
+ import {excelToNum, numToExcel} from '../plate/utils';
10
+ import {PlateWidget} from '../plate/plate-widget';
11
+
12
+
13
+ function getPlate(): Plate {
14
+ const concentration = Plate.fromCsvTable(concentrationCsv, 'concentration');
15
+ const layout = Plate.fromCsvTable(layoutCsv, 'role');
16
+ const readout = Plate.fromCsvTable(readoutCsv, 'readout');
17
+
18
+ return Plate.fromPlates([concentration, layout, readout]);
19
+ }
20
+
21
+ category('plates', () => {
22
+ test('fromCsvPlate', async () => {
23
+ const plate = Plate.fromCsv(concentrationCsv, { field: 'concentration' });
24
+ plate.print();
25
+ expect(plate.rows, 16);
26
+ expect(plate.cols, 24);
27
+ });
28
+
29
+ test('mergePlates', async () => {
30
+ const concentration = Plate.fromCsvTable(concentrationCsv, 'concentration');
31
+ const layout = Plate.fromCsvTable(layoutCsv, 'role');
32
+ const readout = Plate.fromCsvTable(readoutCsv, 'value');
33
+
34
+ readout.merge(layout).merge(concentration).print();
35
+ });
36
+
37
+ test('fromFile', async () => {
38
+ const concentration = await Plate.fromCsvTableFile('System:DemoFiles/hts/plate/concentration.csv', 'concentration');
39
+ const layout = await Plate.fromCsvTableFile('System:DemoFiles/hts/plate/layout.csv', 'role');
40
+ const readout = await Plate.fromCsvTableFile('System:DemoFiles/hts/plate/readout.csv', 'value');
41
+
42
+ Plate.fromPlates([concentration, layout, readout]).print();
43
+ });
44
+
45
+ test('fromExcel', async () => {
46
+ const plate = await Plate.fromExcelPath('System:DemoFiles/hts/xlsx_plates/plate1.xlsx');
47
+ ui.dialog({title: 'Inspect plate'})
48
+ .add(PlateWidget.detailedView(plate.data).root)
49
+ .show({width: 500, height: 500});
50
+ await DG.delay(10000);
51
+ });
52
+
53
+ test('normalization', async () => {
54
+ const plate = getPlate();
55
+
56
+ const hcMean = jStat.mean(plate.fieldValues('readout', {match: {'layout': 'High Control'}}));
57
+ const lcMean = jStat.mean(plate.fieldValues('readout', {match: {'layout': 'Low Control'}}));
58
+ plate.normalize('readout', value => (hcMean - value) / (hcMean - lcMean));
59
+ });
60
+
61
+ test('use case', async () => {
62
+ const plate = getPlate();
63
+
64
+ const hcMean = jStat.mean(plate.fieldValues('readout', {match: {'layout': 'High Control'}}));
65
+ const lcMean = jStat.mean(plate.fieldValues('readout', {match: {'layout': 'Low Control'}}));
66
+ plate.normalize('readout', value => (hcMean - value) / (hcMean - lcMean));
67
+
68
+ const drc = plate.doseResponseSeries({concentration: 'concentration', value: 'readout'}); // if we get
69
+ Plate.inspectSeries(drc['Compound 1'], '4pl-regression');
70
+ });
71
+
72
+ test('render', async () => {
73
+ const plate = getPlate();
74
+ ui.dialog({title: 'Inspect plate'})
75
+ .add(PlateWidget.detailedView(plate.data).root)
76
+ .show({width: 500, height: 500});
77
+ await DG.delay(10000);
78
+ });
79
+
80
+ test('numToExcel', async () => {
81
+ expect(numToExcel(0), 'A');
82
+ expect(numToExcel(1), 'B');
83
+ expect(numToExcel(26), 'AA');
84
+ expect(numToExcel(52), 'BA');
85
+ });
86
+
87
+ test('excelToNum', async () => {
88
+ expect(excelToNum('A'), 0);
89
+ expect(excelToNum('B'), 1);
90
+ expect(excelToNum('Z'), 25);
91
+
92
+ expect(excelToNum('AA'), 26);
93
+ expect(excelToNum('BA'), 52);
94
+ });
95
+ });
96
+
97
+
98
+
99
+
100
+ const concentrationCsv = `col 1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
101
+ A,,,,,,,,,,,,,,,,,,,,,,,,
102
+ B,,0.00001,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,
103
+ C,,0.00000,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00000,
104
+ D,,0.00001,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,
105
+ E,,0.00000,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00000,
106
+ F,,0.00001,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,
107
+ G,,0.00000,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00000,
108
+ H,,0.00001,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,
109
+ I,,0.00000,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00000,
110
+ J,,0.00001,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,
111
+ K,,0.00000,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00000,
112
+ L,,0.00001,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,
113
+ M,,0.00000,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00000,
114
+ N,,0.00001,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,
115
+ O,,0.00000,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00001,0.00000403,0.00000163,0.000000656,0.000000265,0.000000107,0.0000000431,0.0000000174,0.00000000701,0.00000000183,0.00000,
116
+ P,,,,,,,,,,,,,,,,,,,,,,,,`;
117
+
118
+
119
+ const layoutCsv = `col 1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
120
+ A,,,,,,,,,,,,,,,,,,,,,,,,
121
+ B,,Low Control,Compound 1,Compound 1,Compound 1,Compound 1,Compound 1,Compound 1,Compound 1,Compound 1,Compound 1,Compound 1,Compound 41,Compound 41,Compound 41,Compound 41,Compound 41,Compound 41,Compound 41,Compound 41,Compound 41,Compound 41,Low Control,
122
+ C,,High Control,Compound 1,Compound 1,Compound 1,Compound 1,Compound 1,Compound 1,Compound 1,Compound 1,Compound 1,Compound 1,Compound 41,Compound 41,Compound 41,Compound 41,Compound 41,Compound 41,Compound 41,Compound 41,Compound 41,Compound 41,High Control,
123
+ D,,Low Control,Compound 42,Compound 42,Compound 42,Compound 42,Compound 42,Compound 42,Compound 42,Compound 42,Compound 42,Compound 42,Compound 43,Compound 43,Compound 43,Compound 43,Compound 43,Compound 43,Compound 43,Compound 43,Compound 43,Compound 43,Low Control,
124
+ E,,High Control,Compound 42,Compound 42,Compound 42,Compound 42,Compound 42,Compound 42,Compound 42,Compound 42,Compound 42,Compound 42,Compound 43,Compound 43,Compound 43,Compound 43,Compound 43,Compound 43,Compound 43,Compound 43,Compound 43,Compound 43,High Control,
125
+ F,,Low Control,Compound 44,Compound 44,Compound 44,Compound 44,Compound 44,Compound 44,Compound 44,Compound 44,Compound 44,Compound 44,Compound 45,Compound 45,Compound 45,Compound 45,Compound 45,Compound 45,Compound 45,Compound 45,Compound 45,Compound 45,Low Control,
126
+ G,,High Control,Compound 44,Compound 44,Compound 44,Compound 44,Compound 44,Compound 44,Compound 44,Compound 44,Compound 44,Compound 44,Compound 45,Compound 45,Compound 45,Compound 45,Compound 45,Compound 45,Compound 45,Compound 45,Compound 45,Compound 45,High Control,
127
+ H,,Low Control,Compound 46,Compound 46,Compound 46,Compound 46,Compound 46,Compound 46,Compound 46,Compound 46,Compound 46,Compound 46,Compound 47,Compound 47,Compound 47,Compound 47,Compound 47,Compound 47,Compound 47,Compound 47,Compound 47,Compound 47,Low Control,
128
+ I,,High Control,Compound 46,Compound 46,Compound 46,Compound 46,Compound 46,Compound 46,Compound 46,Compound 46,Compound 46,Compound 46,Compound 47,Compound 47,Compound 47,Compound 47,Compound 47,Compound 47,Compound 47,Compound 47,Compound 47,Compound 47,High Control,
129
+ J,,Low Control,Compound 48,Compound 48,Compound 48,Compound 48,Compound 48,Compound 48,Compound 48,Compound 48,Compound 48,Compound 48,Compound 49,Compound 49,Compound 49,Compound 49,Compound 49,Compound 49,Compound 49,Compound 49,Compound 49,Compound 49,Low Control,
130
+ K,,High Control,Compound 48,Compound 48,Compound 48,Compound 48,Compound 48,Compound 48,Compound 48,Compound 48,Compound 48,Compound 48,Compound 49,Compound 49,Compound 49,Compound 49,Compound 49,Compound 49,Compound 49,Compound 49,Compound 49,Compound 49,High Control,
131
+ L,,Low Control,Compound 50,Compound 50,Compound 50,Compound 50,Compound 50,Compound 50,Compound 50,Compound 50,Compound 50,Compound 50,Compound 51,Compound 51,Compound 51,Compound 51,Compound 51,Compound 51,Compound 51,Compound 51,Compound 51,Compound 51,Low Control,
132
+ M,,High Control,Compound 50,Compound 50,Compound 50,Compound 50,Compound 50,Compound 50,Compound 50,Compound 50,Compound 50,Compound 50,Compound 51,Compound 51,Compound 51,Compound 51,Compound 51,Compound 51,Compound 51,Compound 51,Compound 51,Compound 51,High Control,
133
+ N,,Low Control,Compound 52,Compound 52,Compound 52,Compound 52,Compound 52,Compound 52,Compound 52,Compound 52,Compound 52,Compound 52,Compound 53,Compound 53,Compound 53,Compound 53,Compound 53,Compound 53,Compound 53,Compound 53,Compound 53,Compound 53,Low Control,
134
+ O,,High Control,Compound 52,Compound 52,Compound 52,Compound 52,Compound 52,Compound 52,Compound 52,Compound 52,Compound 52,Compound 52,Compound 53,Compound 53,Compound 53,Compound 53,Compound 53,Compound 53,Compound 53,Compound 53,Compound 53,Compound 53,High Control,
135
+ P,,,,,,,,,,,,,,,,,,,,,,,,`;
136
+
137
+
138
+ const readoutCsv = `col 1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
139
+ A,,,,,,,,,,,,,,,,,,,,,,,,
140
+ B,,0.07219099668,0.06947737465,0.07019976172,0.07263956168,0.07334269904,0.07654089128,0.07628940202,0.08834969214,0.13557287840,0.1486864679,0.1503697113,0.15200083420,0.15061775480,0.15309907440,0.15286653780,0.15379914010,0.15155727890,0.15232794460,0.15298766400,0.1538730651,0.1542393465,0.15071555580,
141
+ C,,0.14996855360,0.07212290660,0.06957076093,0.07069321642,0.07227733865,0.07664359412,0.07918610560,0.07808503586,0.12496495030,0.1378908893,0.1465698921,0.15578283900,0.15186884230,0.15151635070,0.15141401530,0.15052587190,0.15486747600,0.15294037650,0.15241116130,0.1546532344,0.1537365814,0.07231605295,
142
+ D,,0.07023863668,0.07030474895,0.07086594623,0.07378772619,0.07813099195,0.08443275691,0.10024937710,0.11821695280,0.14031173800,0.1505845411,0.1505987702,0.07099481653,0.07322787956,0.07588648236,0.08377558210,0.09888790085,0.11395358370,0.12947949180,0.14055841590,0.1493699333,0.1540055735,0.15226875140,
143
+ E,,0.14929130930,0.06932695867,0.07157716491,0.07214187679,0.07721194315,0.08504549754,0.10174360480,0.11748417490,0.13321393730,0.1456650512,0.1483001297,0.07167267085,0.07383087952,0.07670410142,0.08204578635,0.09386326869,0.11296832520,0.30900000000,0.13807843210,0.1487301787,0.1519785410,0.07219836243,
144
+ F,,0.07063914398,0.07039007372,0.07078597316,0.07132027961,0.07222210814,0.07442561862,0.08135627908,0.09196745273,0.11146019360,0.1364485205,0.1450632971,0.08126099235,0.09318398047,0.10961914380,0.12860206080,0.14110717340,0.14655533300,0.15212245890,0.15233422070,0.1521740437,0.1539843278,0.15514745160,
145
+ G,,0.15147635060,0.07238581078,0.06968522213,0.07128524617,0.07252406181,0.07567350355,0.07943235275,0.09117074615,0.10537654310,0.1344820888,0.1400224330,0.08242500433,0.09563371204,0.10936069820,0.12848949680,0.14108995770,0.14405660970,0.15031406210,0.15131600980,0.1522018720,0.1534152011,0.07219962790,
146
+ H,,0.07201551934,0.14139074650,0.10970399700,0.14927003800,0.15153471030,0.15239784500,0.15275285200,0.15300022370,0.15204696770,0.1499048651,0.1522479639,0.08013306126,0.08511773454,0.09873312909,0.11965236570,0.13423325770,0.14790643020,0.14787378410,0.15121033310,0.1516832849,0.1546688514,0.15391338010,
147
+ I,,0.15106747120,0.14298828240,0.14478508750,0.14400005770,0.12812788070,0.15020659840,0.15070640480,0.14981230230,0.15107167610,0.1525554191,0.1492535524,0.08018720930,0.08601155699,0.09880353225,0.11672648890,0.13325225690,0.14354164670,0.14463708830,0.15318329890,0.1521327032,0.1512182552,0.07244861048,
148
+ J,,0.07134151692,0.07106139536,0.07290563639,0.07320964199,0.07531163459,0.08077714646,0.08726929940,0.10068593880,0.11914215450,0.1418191958,0.1443463920,0.07247201272,0.06999750950,0.07076991276,0.07228675508,0.07237591892,0.07201251723,0.07741640477,0.08773368972,0.1219768071,0.1387552698,0.15192226570,
149
+ K,,0.15000436380,0.07156625599,0.07087075250,0.07123659002,0.07345421874,0.07832545577,0.08734304748,0.09985159477,0.11591447310,0.1397237122,0.1459823861,0.07214517236,0.07005683091,0.07016838344,0.07131776580,0.07200174821,0.07350492337,0.07785311421,0.08866229169,0.1234911377,0.1371697196,0.07064796366,
150
+ L,,0.07054096934,0.07004726921,0.07201825002,0.07179815990,0.07268889103,0.07379454514,0.07427085340,0.07982570255,0.08854676858,0.1198873673,0.1322562498,0.07034679393,0.07523627163,0.07582258339,0.08392782907,0.09669262374,0.11261560310,0.12874291890,0.14171585180,0.1491004443,0.1502214336,0.15198125010,
151
+ M,,0.15232172270,0.07166689716,0.07099964730,0.07172948942,0.07140356089,0.07359647053,0.07391627346,0.07872536050,0.08793247921,0.1177668597,0.1316288144,0.06733039177,0.07260462946,0.07516068933,0.08359475310,0.09611904399,0.11364151330,0.12772328380,0.14070692820,0.1486696188,0.1541842928,0.07174453270,
152
+ N,,0.07126884935,0.07332587669,0.07786873273,0.08482253378,0.10140499840,0.11854947500,0.13401382360,0.14613488070,0.15066237370,0.1545757395,0.1510962397,0.07286614211,0.07215169457,0.07227939024,0.07337505876,0.07530546981,0.08265249465,0.09167518260,0.11122719660,0.1391977320,0.1459690588,0.15291802550,
153
+ O,,0.15243482930,0.07280165939,0.07688708790,0.31500000000,0.09886803400,0.11454911710,0.12960429510,0.14047477320,0.14718270040,0.1509524590,0.1501338551,0.07212897291,0.07072700474,0.07059273173,0.07088234657,0.07421414395,0.08105493058,0.09094554089,0.10660934950,0.1358113503,0.1432621746,0.07009305748,
154
+ P,,,,,,,,,,,,,,,,,,,,,,,,`;
@@ -1,7 +1,7 @@
1
1
  import * as DG from 'datagrok-api/dg';
2
2
 
3
3
  import {Viewport} from '@datagrok-libraries/utils/src/transform';
4
- import {layoutChart} from '../fit/fit-renderer';
4
+ import {FitChartCellRenderer, layoutChart} from '../fit/fit-renderer';
5
5
 
6
6
  import {category, expect, test} from '@datagrok-libraries/utils/src/test';
7
7
  import {FitConstants} from '../fit/const';
@@ -9,7 +9,7 @@ import {FitConstants} from '../fit/const';
9
9
 
10
10
  category('viewport', () => {
11
11
  test('viewportMethods', async () => {
12
- const screenBounds = new DG.Rect(120, 20, 160, 100).inflate(FitConstants.INFLATE_SIZE, FitConstants.INFLATE_SIZE);
12
+ const screenBounds = FitChartCellRenderer.inflateScreenBounds(new DG.Rect(120, 20, 160, 100));
13
13
  const [dataBox] = layoutChart(screenBounds, false, false);
14
14
  const dataBounds = new DG.Rect(0.1, 0.06, 7, 5.94);
15
15
  const viewport = new Viewport(dataBounds, dataBox, false, false);
@@ -1,54 +0,0 @@
1
- import * as DG from 'datagrok-api/dg';
2
- import * as ui from 'datagrok-api/ui';
3
- import {FitChartCellRenderer} from './fit-renderer';
4
-
5
-
6
- export class CellRenderViewer<TRenderer extends DG.GridCellRenderer = DG.GridCellRenderer> extends DG.JsViewer {
7
- canvas: HTMLCanvasElement = ui.canvas();
8
- renderer: TRenderer;
9
- gridCell?: DG.GridCell;
10
- gridCellStyle: DG.GridCellStyle = DG.GridCellStyle.create();
11
-
12
- constructor(renderer: TRenderer) {
13
- super();
14
-
15
- this.renderer = renderer;
16
- this.root.append(this.canvas);
17
-
18
- this.canvas.style.width = '100%';
19
- this.canvas.style.height = '100%';
20
-
21
- ui.tools.handleResize(this.canvas, (w: number, h: number) => {
22
- this.canvas.width = w;
23
- this.canvas.height = h;
24
- this.render();
25
- });
26
-
27
- const bind = (f: (gridCell: DG.GridCell, e: MouseEvent) => void) => (e: MouseEvent) => {
28
- if (this.gridCell)
29
- f(this.gridCell, e);
30
- }
31
-
32
- this.canvas.onmousemove = bind(this.renderer.onMouseMove);
33
- this.canvas.onmouseenter = bind(this.renderer.onMouseEnter);
34
- this.canvas.onmouseleave = bind(this.renderer.onMouseLeave);
35
- }
36
-
37
- static fromGridCell(gridCell: DG.GridCell): CellRenderViewer {
38
- const viewer = new CellRenderViewer(new FitChartCellRenderer());
39
- viewer.gridCell = gridCell;
40
- viewer.render();
41
- return viewer;
42
- }
43
-
44
- render(): void {
45
- if (!this.gridCell)
46
- return;
47
-
48
- const g = this.canvas.getContext('2d')!;
49
- g.clearRect(0, 0, this.canvas.width, this.canvas.height);
50
-
51
- this.renderer.renderInternal(g, 0, 0, this.canvas.width, this.canvas.height,
52
- this.gridCell.dart, this.gridCellStyle);
53
- }
54
- }