@datagrok/curves 1.0.1
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/.vscode/launch.json +13 -0
- package/.vscode/tasks.json +10 -0
- package/README.md +19 -0
- package/detectors.js +35 -0
- package/dist/package-test.js +591 -0
- package/dist/package-test.js.map +1 -0
- package/dist/package.js +15899 -0
- package/dist/package.js.map +1 -0
- package/package.json +53 -0
- package/package.png +0 -0
- package/src/fit/cell-render-viewer.js +33 -0
- package/src/fit/cell-render-viewer.js.map +1 -0
- package/src/fit/cell-render-viewer.ts +45 -0
- package/src/fit/fit-data.js +221 -0
- package/src/fit/fit-data.js.map +1 -0
- package/src/fit/fit-data.ts +335 -0
- package/src/fit/fit-demo.js +91 -0
- package/src/fit/fit-demo.js.map +1 -0
- package/src/fit/fit-demo.ts +98 -0
- package/src/fit/fit-grid-cell-handler.js +54 -0
- package/src/fit/fit-grid-cell-handler.js.map +1 -0
- package/src/fit/fit-grid-cell-handler.ts +70 -0
- package/src/fit/fit-parser.js +115 -0
- package/src/fit/fit-parser.js.map +1 -0
- package/src/fit/fit-parser.ts +144 -0
- package/src/fit/fit-renderer.js +167 -0
- package/src/fit/fit-renderer.js.map +1 -0
- package/src/fit/fit-renderer.ts +202 -0
- package/src/fit/multi-curve-viewer.js +67 -0
- package/src/fit/multi-curve-viewer.js.map +1 -0
- package/src/fit/multi-curve-viewer.ts +87 -0
- package/src/fit/transform.js +73 -0
- package/src/fit/transform.js.map +1 -0
- package/src/fit/transform.ts +101 -0
- package/src/package-test.js +26 -0
- package/src/package-test.js.map +1 -0
- package/src/package-test.ts +18 -0
- package/src/package.js +50 -0
- package/src/package.js.map +1 -0
- package/src/package.ts +48 -0
- package/src/tests/fit-viewer-test.js +16 -0
- package/src/tests/fit-viewer-test.js.map +1 -0
- package/src/tests/fit-viewer-test.ts +11 -0
- package/tsconfig.json +71 -0
- package/webpack.config.js +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Curves
|
|
2
|
+
|
|
3
|
+
**Curves** provides support for fitted curves (such as dose-response curves),
|
|
4
|
+
including in-grid rendering, storing charts in cells, interactivity, and automatic fitting.
|
|
5
|
+
|
|
6
|
+
- Fitting: computing parameters of the specified function to best fit the data
|
|
7
|
+
- Uses BFGS optimization algorithm (multi-threading for performance).
|
|
8
|
+
For dose-response curves, we are typically fitting the sigmoid function
|
|
9
|
+
- Ability to dynamically register custom fitting functions
|
|
10
|
+
- Ability to get fitting performance characteristics (r-squared, classification, etc)
|
|
11
|
+
- Deep integration with the Datagrok grid
|
|
12
|
+
- Either fitting on the fly, or using the supplied function + parameters
|
|
13
|
+
- Multiple series in one cell
|
|
14
|
+
- Ability to define chart, marker, or fitting options (such as fit function or marker color)
|
|
15
|
+
on the column level, with the ability to override it on a grid cell or point level
|
|
16
|
+
- Clicking a point in a chart within a grid makes it an outlier -> curve is re-fitted on the fly
|
|
17
|
+
- Ability to specify a chart as "reference" so that it is shown on every other chart for comparison
|
|
18
|
+
- Ability to overlay curves from multiple grid cells (special viewer)
|
|
19
|
+
- Work with series stored in multiple formats (binary for performance, json for flexibility, etc)
|
package/detectors.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The class contains semantic type detectors.
|
|
3
|
+
* Detectors are functions tagged with `DG.FUNC_TYPES.SEM_TYPE_DETECTOR`.
|
|
4
|
+
* See also: https://datagrok.ai/help/develop/how-to/define-semantic-type-detectors
|
|
5
|
+
* The class name is comprised of <PackageName> and the `PackageDetectors` suffix.
|
|
6
|
+
* Follow this naming convention to ensure that your detectors are properly loaded.
|
|
7
|
+
*/
|
|
8
|
+
const FIT_SEM_TYPE = 'fit';
|
|
9
|
+
class CurvesPackageDetectors extends DG.Package {
|
|
10
|
+
//tags: semTypeDetector
|
|
11
|
+
//input: column col
|
|
12
|
+
//output: string semType
|
|
13
|
+
detectXMLCurveChart(col) {
|
|
14
|
+
if (DG.Detector.sampleCategories(col, (s) => s.startsWith('<chart>') && s.endsWith('</chart>'), 1)) {
|
|
15
|
+
col.setTag('.fitChartFormat', '3dx');
|
|
16
|
+
col.semType = FIT_SEM_TYPE;
|
|
17
|
+
return col.semType;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//tags: semTypeDetector
|
|
23
|
+
//input: column col
|
|
24
|
+
//output: string semType
|
|
25
|
+
detectFit(col) {
|
|
26
|
+
if (DG.Detector.sampleCategories(col, (s) => {
|
|
27
|
+
return s.includes('series') && s.includes('points') && s.includes('parameters') &&
|
|
28
|
+
s.includes('fitLineColor') && s.includes('pointColor') && s.includes('showCurveConfidenceInterval');
|
|
29
|
+
}, 1)) {
|
|
30
|
+
col.semType = FIT_SEM_TYPE;
|
|
31
|
+
return col.semType;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
var curves_test;
|
|
2
|
+
/******/ (() => { // webpackBootstrap
|
|
3
|
+
/******/ "use strict";
|
|
4
|
+
/******/ var __webpack_modules__ = ({
|
|
5
|
+
|
|
6
|
+
/***/ "./node_modules/@datagrok-libraries/utils/src/test.js":
|
|
7
|
+
/*!************************************************************!*\
|
|
8
|
+
!*** ./node_modules/@datagrok-libraries/utils/src/test.js ***!
|
|
9
|
+
\************************************************************/
|
|
10
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
11
|
+
|
|
12
|
+
__webpack_require__.r(__webpack_exports__);
|
|
13
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
14
|
+
/* harmony export */ "Test": () => (/* binding */ Test),
|
|
15
|
+
/* harmony export */ "TestContext": () => (/* binding */ TestContext),
|
|
16
|
+
/* harmony export */ "after": () => (/* binding */ after),
|
|
17
|
+
/* harmony export */ "assure": () => (/* binding */ assure),
|
|
18
|
+
/* harmony export */ "awaitCheck": () => (/* binding */ awaitCheck),
|
|
19
|
+
/* harmony export */ "before": () => (/* binding */ before),
|
|
20
|
+
/* harmony export */ "category": () => (/* binding */ category),
|
|
21
|
+
/* harmony export */ "currentCategory": () => (/* binding */ currentCategory),
|
|
22
|
+
/* harmony export */ "delay": () => (/* binding */ delay),
|
|
23
|
+
/* harmony export */ "expect": () => (/* binding */ expect),
|
|
24
|
+
/* harmony export */ "expectArray": () => (/* binding */ expectArray),
|
|
25
|
+
/* harmony export */ "expectFloat": () => (/* binding */ expectFloat),
|
|
26
|
+
/* harmony export */ "expectObject": () => (/* binding */ expectObject),
|
|
27
|
+
/* harmony export */ "expectTable": () => (/* binding */ expectTable),
|
|
28
|
+
/* harmony export */ "initAutoTests": () => (/* binding */ initAutoTests),
|
|
29
|
+
/* harmony export */ "isDialogPresent": () => (/* binding */ isDialogPresent),
|
|
30
|
+
/* harmony export */ "runTests": () => (/* binding */ runTests),
|
|
31
|
+
/* harmony export */ "test": () => (/* binding */ test),
|
|
32
|
+
/* harmony export */ "testEvent": () => (/* binding */ testEvent),
|
|
33
|
+
/* harmony export */ "testViewer": () => (/* binding */ testViewer),
|
|
34
|
+
/* harmony export */ "tests": () => (/* binding */ tests)
|
|
35
|
+
/* harmony export */ });
|
|
36
|
+
/* harmony import */ var datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! datagrok-api/grok */ "datagrok-api/grok");
|
|
37
|
+
/* harmony import */ var datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__);
|
|
38
|
+
/* harmony import */ var datagrok_api_dg__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! datagrok-api/dg */ "datagrok-api/dg");
|
|
39
|
+
/* harmony import */ var datagrok_api_dg__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(datagrok_api_dg__WEBPACK_IMPORTED_MODULE_1__);
|
|
40
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
43
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
44
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
45
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
const tests = {};
|
|
52
|
+
const autoTestsCatName = 'Auto Tests';
|
|
53
|
+
const wasRegistered = {};
|
|
54
|
+
let currentCategory;
|
|
55
|
+
var assure;
|
|
56
|
+
(function (assure) {
|
|
57
|
+
function notNull(value, name) {
|
|
58
|
+
if (value == null)
|
|
59
|
+
throw new Error(`${name == null ? 'Value' : name} not defined`);
|
|
60
|
+
}
|
|
61
|
+
assure.notNull = notNull;
|
|
62
|
+
})(assure || (assure = {}));
|
|
63
|
+
class TestContext {
|
|
64
|
+
constructor(catchUnhandled, report) {
|
|
65
|
+
this.catchUnhandled = true;
|
|
66
|
+
this.report = false;
|
|
67
|
+
if (catchUnhandled !== undefined)
|
|
68
|
+
this.catchUnhandled = catchUnhandled;
|
|
69
|
+
if (report !== undefined)
|
|
70
|
+
this.report = report;
|
|
71
|
+
}
|
|
72
|
+
;
|
|
73
|
+
}
|
|
74
|
+
class Test {
|
|
75
|
+
constructor(category, name, test, options) {
|
|
76
|
+
var _a;
|
|
77
|
+
this.category = category;
|
|
78
|
+
this.name = name;
|
|
79
|
+
options !== null && options !== void 0 ? options : (options = {});
|
|
80
|
+
(_a = options.timeout) !== null && _a !== void 0 ? _a : (options.timeout = 30000);
|
|
81
|
+
this.options = options;
|
|
82
|
+
this.test = () => __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
let result = '';
|
|
85
|
+
try {
|
|
86
|
+
result = yield test();
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
reject(e);
|
|
90
|
+
}
|
|
91
|
+
resolve(result);
|
|
92
|
+
}));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function testEvent(event, handler, trigger, ms = 0) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
let sub;
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
sub = event.subscribe((args) => {
|
|
101
|
+
try {
|
|
102
|
+
handler(args);
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
reject(e);
|
|
106
|
+
}
|
|
107
|
+
sub.unsubscribe();
|
|
108
|
+
resolve('OK');
|
|
109
|
+
});
|
|
110
|
+
setTimeout(() => {
|
|
111
|
+
sub.unsubscribe();
|
|
112
|
+
// eslint-disable-next-line prefer-promise-reject-errors
|
|
113
|
+
reject('timeout');
|
|
114
|
+
}, ms);
|
|
115
|
+
trigger();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function test(name, test, options) {
|
|
120
|
+
if (tests[currentCategory] == undefined)
|
|
121
|
+
tests[currentCategory] = {};
|
|
122
|
+
if (tests[currentCategory].tests == undefined)
|
|
123
|
+
tests[currentCategory].tests = [];
|
|
124
|
+
tests[currentCategory].tests.push(new Test(currentCategory, name, test, options));
|
|
125
|
+
}
|
|
126
|
+
/* Tests two objects for equality, throws an exception if they are not equal. */
|
|
127
|
+
function expect(actual, expected = true, error) {
|
|
128
|
+
if (error)
|
|
129
|
+
error = `${error}, `;
|
|
130
|
+
else
|
|
131
|
+
error = '';
|
|
132
|
+
if (actual !== expected)
|
|
133
|
+
throw new Error(`${error}Expected "${expected}", got "${actual}"`);
|
|
134
|
+
}
|
|
135
|
+
function expectFloat(actual, expected, tolerance = 0.001, error) {
|
|
136
|
+
if ((actual === Number.POSITIVE_INFINITY && expected === Number.POSITIVE_INFINITY) ||
|
|
137
|
+
(actual === Number.NEGATIVE_INFINITY && expected === Number.NEGATIVE_INFINITY) ||
|
|
138
|
+
(actual === Number.NaN && expected === Number.NaN) || (isNaN(actual) && isNaN(expected)))
|
|
139
|
+
return;
|
|
140
|
+
const areEqual = Math.abs(actual - expected) < tolerance;
|
|
141
|
+
expect(areEqual, true, `${error !== null && error !== void 0 ? error : ''} (tolerance = ${tolerance})`);
|
|
142
|
+
if (!areEqual)
|
|
143
|
+
throw new Error(`Expected ${expected}, got ${actual} (tolerance = ${tolerance})`);
|
|
144
|
+
}
|
|
145
|
+
function expectTable(actual, expected, error) {
|
|
146
|
+
const expectedRowCount = expected.rowCount;
|
|
147
|
+
const actualRowCount = actual.rowCount;
|
|
148
|
+
expect(actualRowCount, expectedRowCount, `${error !== null && error !== void 0 ? error : ''}, row count`);
|
|
149
|
+
for (const column of expected.columns) {
|
|
150
|
+
const actualColumn = actual.columns.byName(column.name);
|
|
151
|
+
if (actualColumn == null)
|
|
152
|
+
throw new Error(`Column ${column.name} not found`);
|
|
153
|
+
if (actualColumn.type != column.type)
|
|
154
|
+
throw new Error(`Column ${column.name} type expected ${column.type} got ${actualColumn.type}`);
|
|
155
|
+
for (let i = 0; i < expectedRowCount; i++) {
|
|
156
|
+
const value = column.get(i);
|
|
157
|
+
const actualValue = actualColumn.get(i);
|
|
158
|
+
if (column.type == datagrok_api_dg__WEBPACK_IMPORTED_MODULE_1__.TYPE.FLOAT)
|
|
159
|
+
expectFloat(actualValue, value, 0.0001, error);
|
|
160
|
+
else if (column.type == datagrok_api_dg__WEBPACK_IMPORTED_MODULE_1__.TYPE.DATE_TIME)
|
|
161
|
+
expect(actualValue.isSame(value), true, error);
|
|
162
|
+
else
|
|
163
|
+
expect(actualValue, value, error);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function expectObject(actual, expected) {
|
|
168
|
+
for (const [expectedKey, expectedValue] of Object.entries(expected)) {
|
|
169
|
+
if (!actual.hasOwnProperty(expectedKey))
|
|
170
|
+
throw new Error(`Expected property "${expectedKey}" not found`);
|
|
171
|
+
const actualValue = actual[expectedKey];
|
|
172
|
+
if (actualValue instanceof Array && expectedValue instanceof Array)
|
|
173
|
+
expectArray(actualValue, expectedValue);
|
|
174
|
+
else if (actualValue instanceof Object && expectedValue instanceof Object)
|
|
175
|
+
expectObject(actualValue, expectedValue);
|
|
176
|
+
else if (Number.isFinite(actualValue) && Number.isFinite(expectedValue))
|
|
177
|
+
expectFloat(actualValue, expectedValue);
|
|
178
|
+
else if (actualValue != expectedValue)
|
|
179
|
+
throw new Error(`Expected (${expectedValue}) for key '${expectedKey}', got (${actualValue})`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function expectArray(actual, expected) {
|
|
183
|
+
const actualLength = actual.length;
|
|
184
|
+
const expectedLength = expected.length;
|
|
185
|
+
if (actualLength != expectedLength) {
|
|
186
|
+
throw new Error(`Arrays are of different length: actual array length is ${actualLength} ` +
|
|
187
|
+
`and expected array length is ${expectedLength}`);
|
|
188
|
+
}
|
|
189
|
+
for (let i = 0; i < actualLength; i++) {
|
|
190
|
+
if (actual[i] instanceof Array && expected[i] instanceof Array)
|
|
191
|
+
expectArray(actual[i], expected[i]);
|
|
192
|
+
else if (actual[i] instanceof Object && expected[i] instanceof Object)
|
|
193
|
+
expectObject(actual[i], expected[i]);
|
|
194
|
+
else if (actual[i] != expected[i])
|
|
195
|
+
throw new Error(`Expected ${expected[i]} at position ${i}, got ${actual[i]}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/* Defines a test suite. */
|
|
199
|
+
function category(category, tests) {
|
|
200
|
+
currentCategory = category;
|
|
201
|
+
tests();
|
|
202
|
+
}
|
|
203
|
+
/* Defines a function to be executed before the tests in this category are executed. */
|
|
204
|
+
function before(before) {
|
|
205
|
+
if (tests[currentCategory] == undefined)
|
|
206
|
+
tests[currentCategory] = {};
|
|
207
|
+
tests[currentCategory].before = before;
|
|
208
|
+
}
|
|
209
|
+
/* Defines a function to be executed after the tests in this category are executed. */
|
|
210
|
+
function after(after) {
|
|
211
|
+
if (tests[currentCategory] == undefined)
|
|
212
|
+
tests[currentCategory] = {};
|
|
213
|
+
tests[currentCategory].after = after;
|
|
214
|
+
}
|
|
215
|
+
function addNamespace(s, f) {
|
|
216
|
+
return s.replace(new RegExp(f.name, 'gi'), f.nqName);
|
|
217
|
+
}
|
|
218
|
+
function initAutoTests(packageId, module) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
if (wasRegistered[packageId])
|
|
221
|
+
return;
|
|
222
|
+
const moduleTests = module ? module.tests : tests;
|
|
223
|
+
if (moduleTests[autoTestsCatName] !== undefined) {
|
|
224
|
+
wasRegistered[packageId] = true;
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const moduleAutoTests = [];
|
|
228
|
+
const packFunctions = yield datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__.dapi.functions.filter(`package.id = "${packageId}"`).list();
|
|
229
|
+
const reg = new RegExp(/.*\/\/\s*skip[:\s]*(.*)$/);
|
|
230
|
+
for (const f of packFunctions) {
|
|
231
|
+
const tests = f.options['test'];
|
|
232
|
+
if (!(tests && Array.isArray(tests) && tests.length))
|
|
233
|
+
continue;
|
|
234
|
+
for (let i = 0; i < tests.length; i++) {
|
|
235
|
+
const skipReasons = tests[i].match(reg);
|
|
236
|
+
let skipReason;
|
|
237
|
+
if (skipReasons && (skipReasons === null || skipReasons === void 0 ? void 0 : skipReasons.length) > 1)
|
|
238
|
+
skipReason = skipReasons[1];
|
|
239
|
+
moduleAutoTests.push(new Test(autoTestsCatName, tests.length === 1 ? f.name : `${f.name} ${i + 1}`, () => __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
const res = yield datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__.functions.eval(addNamespace(tests[i], f));
|
|
241
|
+
// eslint-disable-next-line no-throw-literal
|
|
242
|
+
if (res !== true)
|
|
243
|
+
throw `Failed: ${tests[i]}`;
|
|
244
|
+
}), { skipReason: skipReason }));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
wasRegistered[packageId] = true;
|
|
248
|
+
if (!moduleAutoTests.length)
|
|
249
|
+
return;
|
|
250
|
+
moduleTests[autoTestsCatName] = { tests: moduleAutoTests };
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function runTests(options) {
|
|
254
|
+
var _a, _b, _c, _d;
|
|
255
|
+
var _e;
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
const package_ = (_b = (_a = datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__.functions.getCurrentCall()) === null || _a === void 0 ? void 0 : _a.func) === null || _b === void 0 ? void 0 : _b.package;
|
|
258
|
+
yield initAutoTests(package_.id);
|
|
259
|
+
const results = [];
|
|
260
|
+
console.log(`Running tests`);
|
|
261
|
+
options !== null && options !== void 0 ? options : (options = {});
|
|
262
|
+
(_c = (_e = options).testContext) !== null && _c !== void 0 ? _c : (_e.testContext = new TestContext());
|
|
263
|
+
datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__.shell.lastError = '';
|
|
264
|
+
for (const [key, value] of Object.entries(tests)) {
|
|
265
|
+
if ((options === null || options === void 0 ? void 0 : options.category) != undefined) {
|
|
266
|
+
if (!key.toLowerCase().startsWith(options === null || options === void 0 ? void 0 : options.category.toLowerCase()))
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
console.log(`Started ${key} category`);
|
|
270
|
+
try {
|
|
271
|
+
if (value.before)
|
|
272
|
+
yield value.before();
|
|
273
|
+
}
|
|
274
|
+
catch (x) {
|
|
275
|
+
value.beforeStatus = x.toString();
|
|
276
|
+
}
|
|
277
|
+
const t = (_d = value.tests) !== null && _d !== void 0 ? _d : [];
|
|
278
|
+
const res = [];
|
|
279
|
+
for (let i = 0; i < t.length; i++)
|
|
280
|
+
res.push(yield execTest(t[i], options === null || options === void 0 ? void 0 : options.test));
|
|
281
|
+
const data = (yield Promise.all(res)).filter((d) => d.result != 'skipped');
|
|
282
|
+
try {
|
|
283
|
+
if (value.after)
|
|
284
|
+
yield value.after();
|
|
285
|
+
}
|
|
286
|
+
catch (x) {
|
|
287
|
+
value.afterStatus = x.toString();
|
|
288
|
+
}
|
|
289
|
+
if (value.afterStatus)
|
|
290
|
+
data.push({ category: key, name: 'init', result: value.afterStatus, success: false, ms: 0, skipped: false });
|
|
291
|
+
if (value.beforeStatus)
|
|
292
|
+
data.push({ category: key, name: 'init', result: value.beforeStatus, success: false, ms: 0, skipped: false });
|
|
293
|
+
results.push(...data);
|
|
294
|
+
}
|
|
295
|
+
if (options.testContext.catchUnhandled) {
|
|
296
|
+
yield delay(1000);
|
|
297
|
+
if (datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__.shell.lastError.length > 0) {
|
|
298
|
+
results.push({
|
|
299
|
+
category: 'Unhandled exceptions',
|
|
300
|
+
name: 'exceptions',
|
|
301
|
+
result: datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__.shell.lastError, success: false, ms: 0, skipped: false
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (options.testContext.report) {
|
|
306
|
+
const logger = new datagrok_api_dg__WEBPACK_IMPORTED_MODULE_1__.Logger();
|
|
307
|
+
const successful = results.filter((r) => r.success).length;
|
|
308
|
+
const skipped = results.filter((r) => r.skipped).length;
|
|
309
|
+
const failed = results.filter((r) => !r.success);
|
|
310
|
+
const description = 'Package @package tested: @successful successful, @skipped skipped, @failed failed tests';
|
|
311
|
+
const params = {
|
|
312
|
+
successful: successful,
|
|
313
|
+
skipped: skipped,
|
|
314
|
+
failed: failed.length,
|
|
315
|
+
package: package_
|
|
316
|
+
};
|
|
317
|
+
for (const r of failed)
|
|
318
|
+
Object.assign(params, { [`${r.category} | ${r.name}`]: r.result });
|
|
319
|
+
logger.log(description, params, 'package-tested');
|
|
320
|
+
}
|
|
321
|
+
return results;
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
function execTest(t, predicate) {
|
|
325
|
+
var _a, _b, _c;
|
|
326
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
327
|
+
let r;
|
|
328
|
+
const filter = predicate != undefined && (!t.name.toLowerCase().startsWith(predicate.toLowerCase()));
|
|
329
|
+
const skip = ((_a = t.options) === null || _a === void 0 ? void 0 : _a.skipReason) || filter;
|
|
330
|
+
const skipReason = filter ? 'skipped' : (_b = t.options) === null || _b === void 0 ? void 0 : _b.skipReason;
|
|
331
|
+
if (!skip)
|
|
332
|
+
console.log(`Started ${t.category} ${t.name}`);
|
|
333
|
+
const start = new Date();
|
|
334
|
+
try {
|
|
335
|
+
if (skip)
|
|
336
|
+
r = { success: true, result: skipReason, ms: 0, skipped: true };
|
|
337
|
+
else
|
|
338
|
+
r = { success: true, result: (_c = yield t.test()) !== null && _c !== void 0 ? _c : 'OK', ms: 0, skipped: false };
|
|
339
|
+
}
|
|
340
|
+
catch (x) {
|
|
341
|
+
r = { success: false, result: x.toString(), ms: 0, skipped: false };
|
|
342
|
+
}
|
|
343
|
+
const stop = new Date();
|
|
344
|
+
// @ts-ignore
|
|
345
|
+
r.ms = stop - start;
|
|
346
|
+
if (!skip)
|
|
347
|
+
console.log(`Finished ${t.category} ${t.name} for ${r.ms} ms`);
|
|
348
|
+
r.category = t.category;
|
|
349
|
+
r.name = t.name;
|
|
350
|
+
return r;
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
/* Waits [ms] milliseconds */
|
|
354
|
+
function delay(ms) {
|
|
355
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
yield new Promise((r) => setTimeout(r, ms));
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
function awaitCheck(checkHandler, error = 'Timeout exceeded', wait = 500, interval = 50) {
|
|
360
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
361
|
+
return new Promise((resolve, reject) => {
|
|
362
|
+
setTimeout(() => {
|
|
363
|
+
clearInterval(intervalId);
|
|
364
|
+
reject(new Error(error));
|
|
365
|
+
}, wait);
|
|
366
|
+
// @ts-ignore
|
|
367
|
+
const intervalId = setInterval(() => {
|
|
368
|
+
if (checkHandler()) {
|
|
369
|
+
clearInterval(intervalId);
|
|
370
|
+
resolve();
|
|
371
|
+
}
|
|
372
|
+
}, interval);
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
function isDialogPresent(dialogTitle) {
|
|
377
|
+
const dialogs = datagrok_api_dg__WEBPACK_IMPORTED_MODULE_1__.Dialog.getOpenDialogs();
|
|
378
|
+
for (let i = 0; i < dialogs.length; i++) {
|
|
379
|
+
if (dialogs[i].title == dialogTitle)
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
function testViewer(v, df, detectSemanticTypes = false) {
|
|
385
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
386
|
+
if (detectSemanticTypes)
|
|
387
|
+
yield datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__.data.detectSemanticTypes(df);
|
|
388
|
+
const tv = datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__.shell.addTableView(df);
|
|
389
|
+
const viewerName = `[name=viewer-${v.replace(/\s+/g, '-')} i]`;
|
|
390
|
+
const selector = `${viewerName} canvas,${viewerName} svg,${viewerName} img,
|
|
391
|
+
${viewerName} input,${viewerName} h1,${viewerName} a`;
|
|
392
|
+
const res = [];
|
|
393
|
+
try {
|
|
394
|
+
let viewer = tv.addViewer(v);
|
|
395
|
+
yield awaitCheck(() => document.querySelector(selector) !== null, 'cannot load viewer', 3000);
|
|
396
|
+
res.push(Array.from(tv.viewers).length);
|
|
397
|
+
Array.from(df.row(0).cells).forEach((c) => c.value = null);
|
|
398
|
+
df.rows.select((row) => row.idx > 1 && row.idx < 7);
|
|
399
|
+
for (let i = 7; i < 12; i++)
|
|
400
|
+
df.filter.set(i, false);
|
|
401
|
+
df.currentRowIdx = 1;
|
|
402
|
+
const props = viewer.getOptions(true).look;
|
|
403
|
+
const newProps = {};
|
|
404
|
+
Object.keys(props).filter((k) => typeof props[k] === 'boolean').forEach((k) => newProps[k] = !props[k]);
|
|
405
|
+
viewer.setOptions(newProps);
|
|
406
|
+
yield delay(250);
|
|
407
|
+
const layout = tv.saveLayout();
|
|
408
|
+
const oldProps = viewer.getOptions().look;
|
|
409
|
+
tv.resetLayout();
|
|
410
|
+
res.push(Array.from(tv.viewers).length);
|
|
411
|
+
tv.loadLayout(layout);
|
|
412
|
+
yield awaitCheck(() => document.querySelector(selector) !== null, 'cannot load viewer from layout', 3000);
|
|
413
|
+
yield delay(250);
|
|
414
|
+
res.push(Array.from(tv.viewers).length);
|
|
415
|
+
viewer = Array.from(tv.viewers).find((v) => v.type !== 'Grid');
|
|
416
|
+
expectArray(res, [2, 1, 2]);
|
|
417
|
+
expect(JSON.stringify(viewer.getOptions().look), JSON.stringify(oldProps));
|
|
418
|
+
}
|
|
419
|
+
finally {
|
|
420
|
+
tv.close();
|
|
421
|
+
datagrok_api_grok__WEBPACK_IMPORTED_MODULE_0__.shell.closeTable(df);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
/***/ }),
|
|
428
|
+
|
|
429
|
+
/***/ "./src/tests/fit-viewer-test.js":
|
|
430
|
+
/*!**************************************!*\
|
|
431
|
+
!*** ./src/tests/fit-viewer-test.js ***!
|
|
432
|
+
\**************************************/
|
|
433
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
434
|
+
|
|
435
|
+
__webpack_require__.r(__webpack_exports__);
|
|
436
|
+
/* harmony import */ var _datagrok_libraries_utils_src_test__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @datagrok-libraries/utils/src/test */ "./node_modules/@datagrok-libraries/utils/src/test.js");
|
|
437
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
438
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
439
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
440
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
441
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
442
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
443
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
444
|
+
});
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
(0,_datagrok_libraries_utils_src_test__WEBPACK_IMPORTED_MODULE_0__.category)('Fit', () => {
|
|
448
|
+
(0,_datagrok_libraries_utils_src_test__WEBPACK_IMPORTED_MODULE_0__.test)('test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
449
|
+
(0,_datagrok_libraries_utils_src_test__WEBPACK_IMPORTED_MODULE_0__.expect)('test', 'test');
|
|
450
|
+
}));
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
/***/ }),
|
|
455
|
+
|
|
456
|
+
/***/ "datagrok-api/dg":
|
|
457
|
+
/*!*********************!*\
|
|
458
|
+
!*** external "DG" ***!
|
|
459
|
+
\*********************/
|
|
460
|
+
/***/ ((module) => {
|
|
461
|
+
|
|
462
|
+
module.exports = DG;
|
|
463
|
+
|
|
464
|
+
/***/ }),
|
|
465
|
+
|
|
466
|
+
/***/ "datagrok-api/grok":
|
|
467
|
+
/*!***********************!*\
|
|
468
|
+
!*** external "grok" ***!
|
|
469
|
+
\***********************/
|
|
470
|
+
/***/ ((module) => {
|
|
471
|
+
|
|
472
|
+
module.exports = grok;
|
|
473
|
+
|
|
474
|
+
/***/ })
|
|
475
|
+
|
|
476
|
+
/******/ });
|
|
477
|
+
/************************************************************************/
|
|
478
|
+
/******/ // The module cache
|
|
479
|
+
/******/ var __webpack_module_cache__ = {};
|
|
480
|
+
/******/
|
|
481
|
+
/******/ // The require function
|
|
482
|
+
/******/ function __webpack_require__(moduleId) {
|
|
483
|
+
/******/ // Check if module is in cache
|
|
484
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
485
|
+
/******/ if (cachedModule !== undefined) {
|
|
486
|
+
/******/ return cachedModule.exports;
|
|
487
|
+
/******/ }
|
|
488
|
+
/******/ // Create a new module (and put it into the cache)
|
|
489
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
490
|
+
/******/ // no module.id needed
|
|
491
|
+
/******/ // no module.loaded needed
|
|
492
|
+
/******/ exports: {}
|
|
493
|
+
/******/ };
|
|
494
|
+
/******/
|
|
495
|
+
/******/ // Execute the module function
|
|
496
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
497
|
+
/******/
|
|
498
|
+
/******/ // Return the exports of the module
|
|
499
|
+
/******/ return module.exports;
|
|
500
|
+
/******/ }
|
|
501
|
+
/******/
|
|
502
|
+
/************************************************************************/
|
|
503
|
+
/******/ /* webpack/runtime/compat get default export */
|
|
504
|
+
/******/ (() => {
|
|
505
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
506
|
+
/******/ __webpack_require__.n = (module) => {
|
|
507
|
+
/******/ var getter = module && module.__esModule ?
|
|
508
|
+
/******/ () => (module['default']) :
|
|
509
|
+
/******/ () => (module);
|
|
510
|
+
/******/ __webpack_require__.d(getter, { a: getter });
|
|
511
|
+
/******/ return getter;
|
|
512
|
+
/******/ };
|
|
513
|
+
/******/ })();
|
|
514
|
+
/******/
|
|
515
|
+
/******/ /* webpack/runtime/define property getters */
|
|
516
|
+
/******/ (() => {
|
|
517
|
+
/******/ // define getter functions for harmony exports
|
|
518
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
519
|
+
/******/ for(var key in definition) {
|
|
520
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
521
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
522
|
+
/******/ }
|
|
523
|
+
/******/ }
|
|
524
|
+
/******/ };
|
|
525
|
+
/******/ })();
|
|
526
|
+
/******/
|
|
527
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
528
|
+
/******/ (() => {
|
|
529
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
530
|
+
/******/ })();
|
|
531
|
+
/******/
|
|
532
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
533
|
+
/******/ (() => {
|
|
534
|
+
/******/ // define __esModule on exports
|
|
535
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
536
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
537
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
538
|
+
/******/ }
|
|
539
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
540
|
+
/******/ };
|
|
541
|
+
/******/ })();
|
|
542
|
+
/******/
|
|
543
|
+
/************************************************************************/
|
|
544
|
+
var __webpack_exports__ = {};
|
|
545
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
546
|
+
(() => {
|
|
547
|
+
/*!*****************************!*\
|
|
548
|
+
!*** ./src/package-test.ts ***!
|
|
549
|
+
\*****************************/
|
|
550
|
+
__webpack_require__.r(__webpack_exports__);
|
|
551
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
552
|
+
/* harmony export */ "_package": () => (/* binding */ _package),
|
|
553
|
+
/* harmony export */ "test": () => (/* binding */ test),
|
|
554
|
+
/* harmony export */ "tests": () => (/* reexport safe */ _datagrok_libraries_utils_src_test__WEBPACK_IMPORTED_MODULE_1__.tests)
|
|
555
|
+
/* harmony export */ });
|
|
556
|
+
/* harmony import */ var datagrok_api_dg__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! datagrok-api/dg */ "datagrok-api/dg");
|
|
557
|
+
/* harmony import */ var datagrok_api_dg__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(datagrok_api_dg__WEBPACK_IMPORTED_MODULE_0__);
|
|
558
|
+
/* harmony import */ var _datagrok_libraries_utils_src_test__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @datagrok-libraries/utils/src/test */ "./node_modules/@datagrok-libraries/utils/src/test.js");
|
|
559
|
+
/* harmony import */ var _tests_fit_viewer_test__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./tests/fit-viewer-test */ "./src/tests/fit-viewer-test.js");
|
|
560
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
561
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
562
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
563
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
564
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
565
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
566
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
567
|
+
});
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
const _package = new datagrok_api_dg__WEBPACK_IMPORTED_MODULE_0__.Package();
|
|
573
|
+
|
|
574
|
+
//name: test
|
|
575
|
+
//input: string category {optional: true}
|
|
576
|
+
//input: string test {optional: true}
|
|
577
|
+
//input: object testContext {optional: true}
|
|
578
|
+
//output: dataframe result
|
|
579
|
+
function test(category, test, testContext) {
|
|
580
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
581
|
+
const data = yield (0,_datagrok_libraries_utils_src_test__WEBPACK_IMPORTED_MODULE_1__.runTests)({ category, test, testContext });
|
|
582
|
+
return datagrok_api_dg__WEBPACK_IMPORTED_MODULE_0__.DataFrame.fromObjects(data);
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
})();
|
|
587
|
+
|
|
588
|
+
curves_test = __webpack_exports__;
|
|
589
|
+
/******/ })()
|
|
590
|
+
;
|
|
591
|
+
//# sourceMappingURL=package-test.js.map
|