@datagrok/curves 1.12.1 → 1.13.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.
- package/CHANGELOG.md +81 -0
- package/CLAUDE.md +118 -15
- package/README.md +51 -4
- package/dist/package-test.js +7963 -4867
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +3411 -2024
- package/dist/package.js.map +1 -1
- package/files/demo/Assay_Curves.csv +43 -43
- package/package.json +5 -4
- package/scripts/calculateMSR.py +16 -7
- package/src/fit/curve-converter.ts +8 -1
- package/src/fit/data-to-curves.ts +10 -5
- package/src/fit/fit-chart-data.ts +323 -0
- package/src/fit/fit-grid-cell-handler.ts +98 -231
- package/src/fit/fit-inspection.ts +3 -3
- package/src/fit/fit-interaction.ts +181 -0
- package/src/fit/fit-layout.ts +64 -0
- package/src/fit/fit-legend.ts +292 -0
- package/src/fit/fit-options.ts +222 -0
- package/src/fit/fit-parser.ts +16 -5
- package/src/fit/fit-renderer.ts +180 -469
- package/src/fit/fit-statistics.ts +154 -0
- package/src/fit/multi-curve-viewer.ts +46 -20
- package/src/fit/render-utils.ts +208 -150
- package/src/package-api.ts +92 -14
- package/src/package-test.ts +6 -0
- package/src/package.g.ts +70 -15
- package/src/package.ts +121 -15
- package/src/tests/calculated-columns-tests.ts +299 -0
- package/src/tests/converter-tests.ts +29 -0
- package/src/tests/curve-data.ts +82 -0
- package/src/tests/fit-cache-tests.ts +128 -0
- package/src/tests/fit-tests.ts +310 -3
- package/src/tests/legend-tests.ts +243 -0
- package/src/tests/multi-curve-viewer-tests.ts +100 -0
- package/src/tests/panel-renderer-tests.ts +502 -0
- package/src/tests/project-tests.ts +99 -0
- package/src/tests/transform-tests.ts +3 -2
- package/test-console-output-1.log +357 -110
- package/test-record-1.mp4 +0 -0
package/src/tests/fit-tests.ts
CHANGED
|
@@ -2,19 +2,40 @@
|
|
|
2
2
|
import {
|
|
3
3
|
getSeriesFitFunction,
|
|
4
4
|
getCurve,
|
|
5
|
-
fitSeries,
|
|
6
5
|
getSeriesConfidenceInterval,
|
|
7
6
|
getSeriesStatistics,
|
|
8
7
|
getPointsArrays,
|
|
8
|
+
getSeriesFit,
|
|
9
|
+
toDataSpace,
|
|
9
10
|
} from '@datagrok-libraries/statistics/src/fit/fit-data';
|
|
11
|
+
import {getDataPoints} from '@datagrok-libraries/statistics/src/fit/fit-points';
|
|
12
|
+
import {
|
|
13
|
+
fitSeries,
|
|
14
|
+
fitFunctions,
|
|
15
|
+
DEFAULT_FIT_FUNCTION,
|
|
16
|
+
getFitFunction,
|
|
17
|
+
getStatistic,
|
|
18
|
+
getStatisticProperty,
|
|
19
|
+
isFit,
|
|
20
|
+
FitTypeMap,
|
|
21
|
+
FitSeries,
|
|
22
|
+
SigmoidFit,
|
|
23
|
+
LinearFit,
|
|
24
|
+
LogLinearFit,
|
|
25
|
+
ExponentialFit,
|
|
26
|
+
FourPLDoseResponseFit,
|
|
27
|
+
JSFunctionFit,
|
|
28
|
+
} from '@datagrok-libraries/statistics/src/fit/fit-engine';
|
|
10
29
|
import {
|
|
11
30
|
sigmoid,
|
|
12
31
|
FIT_FUNCTION_SIGMOID,
|
|
13
32
|
IFitSeries,
|
|
14
|
-
FIT_FUNCTION_LINEAR, FIT_FUNCTION_LOG_LINEAR, FIT_FUNCTION_EXPONENTIAL,
|
|
33
|
+
FIT_FUNCTION_LINEAR, FIT_FUNCTION_LOG_LINEAR, FIT_FUNCTION_EXPONENTIAL, FIT_FUNCTION_4PL_DOSE_RESPONSE,
|
|
34
|
+
FIT_FUNCTION_4PL_REGRESSION, linear, logLinear, exponential
|
|
15
35
|
} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
16
36
|
import {calculateBoxPlotStatistics} from '@datagrok-libraries/statistics/src/box-plot-statistics';
|
|
17
|
-
import {category, test, expect, expectArray} from '@datagrok-libraries/test/src/test';
|
|
37
|
+
import {category, test, expect, expectArray, expectFloat} from '@datagrok-libraries/test/src/test';
|
|
38
|
+
import {droplineFraction} from '../fit/render-utils';
|
|
18
39
|
|
|
19
40
|
|
|
20
41
|
const sigmoidSeries: IFitSeries = {'fitLineColor': '#1f77b4', 'pointColor': '#1f77b4', 'showCurveConfidenceInterval': false, 'points': [{'x': 0.10000000149011612, 'y': 1.7412786483764648}, {'x': 0.6000000238418579, 'y': 1.8561450242996216}, {'x': 1.100000023841858, 'y': 1.6065685749053955}, {'x': 1.600000023841858, 'y': 1.70476496219635}, {'x': 2.0999999046325684, 'y': 1.5737264156341553}, {'x': 2.5999999046325684, 'y': 1.6007002592086792}, {'x': 3.0999999046325684, 'y': 1.6796687841415405}, {'x': 3.5999999046325684, 'y': 1.656104326248169}, {'x': 4.099999904632568, 'y': 1.782997488975525}, {'x': 4.599999904632568, 'y': 1.530208945274353}, {'x': 5.099999904632568, 'y': 1.1572397947311401}, {'x': 5.599999904632568, 'y': 0.8691964745521545}, {'x': 6.099999904632568, 'y': 0.3228665590286255}, {'x': 6.599999904632568, 'y': 0.2990703880786896}, {'x': 7.099999904632568, 'y': 0.23361243307590485}], 'fitFunction': 'sigmoid', 'clickToToggle': false, 'showFitLine': true, 'showPoints': 'points', 'parameters': [1.6914372095641517, 1.1536998642628853, 5.410173358224149, 0.2089689354045083]};
|
|
@@ -61,6 +82,20 @@ category('fit', () => {
|
|
|
61
82
|
expect(polynomialFitFunc.y(polynomialFitFunc.getInitialParameters(polynomialXs, polynomialYs), 1.1), 7.3231);
|
|
62
83
|
});
|
|
63
84
|
|
|
85
|
+
test('a series that names no fit function is fitted with the default', async () => {
|
|
86
|
+
// clearing the option leaves the series without one, and the panel and the renderer both ask
|
|
87
|
+
// before anything fills the default in
|
|
88
|
+
const cleared = new FitSeries(sigmoidSeries.points);
|
|
89
|
+
expect(getSeriesFitFunction(cleared).name, DEFAULT_FIT_FUNCTION, 'naming none should name the default');
|
|
90
|
+
(cleared as any).fitFunction = null;
|
|
91
|
+
expect(getSeriesFitFunction(cleared).name, DEFAULT_FIT_FUNCTION, 'and so should clearing it');
|
|
92
|
+
(cleared as any).fitFunction = 'no such fit function';
|
|
93
|
+
expect(getSeriesFitFunction(cleared).name, DEFAULT_FIT_FUNCTION, 'as should naming one that is gone');
|
|
94
|
+
// what the property panel asks of every series before it offers droplines
|
|
95
|
+
expect(getSeriesFitFunction(cleared).hasAsymptotes !== undefined, true,
|
|
96
|
+
'the fit it hands back should be usable, not undefined');
|
|
97
|
+
});
|
|
98
|
+
|
|
64
99
|
test('getCurve', async () => {
|
|
65
100
|
const sigmoidCurve = getCurve(sigmoidSeries, sigmoidFitFunc);
|
|
66
101
|
const linearCurve = getCurve(linearSeries, linearFitFunc);
|
|
@@ -167,6 +202,221 @@ category('fit', () => {
|
|
|
167
202
|
expect(polynomialSeriesStatistics.rSquared, 0.846055768956569);
|
|
168
203
|
});
|
|
169
204
|
|
|
205
|
+
test('fillParams', async () => {
|
|
206
|
+
const sigmoidCurve = fitSeries(sigmoidSeries, sigmoidFitFunc);
|
|
207
|
+
const sigmoidFit = sigmoidFitFunc.fillParams(sigmoidCurve, sigmoidSeries) as SigmoidFit;
|
|
208
|
+
expect(sigmoidFit.name, FIT_FUNCTION_SIGMOID);
|
|
209
|
+
expect(sigmoidFit.top, sigmoidCurve.parameters[0]);
|
|
210
|
+
expect(sigmoidFit.slope, sigmoidCurve.parameters[1]);
|
|
211
|
+
expect(sigmoidFit.ic50, sigmoidCurve.parameters[2]);
|
|
212
|
+
expect(sigmoidFit.bottom, sigmoidCurve.parameters[3]);
|
|
213
|
+
expect(sigmoidFit.interceptY, sigmoidCurve.fittedCurve(sigmoidCurve.parameters[2]));
|
|
214
|
+
|
|
215
|
+
const linearCurve = fitSeries(linearSeries, linearFitFunc);
|
|
216
|
+
const linearFit = linearFitFunc.fillParams(linearCurve, linearSeries) as LinearFit;
|
|
217
|
+
expect(linearFit.slope, linearCurve.parameters[0]);
|
|
218
|
+
expect(linearFit.intercept, linearCurve.parameters[1]);
|
|
219
|
+
|
|
220
|
+
const logLinearCurve = fitSeries(logLinearSeries, logLinearFitFunc);
|
|
221
|
+
const logLinearFit = logLinearFitFunc.fillParams(logLinearCurve, logLinearSeries) as LogLinearFit;
|
|
222
|
+
expect(logLinearFit.name, FIT_FUNCTION_LOG_LINEAR);
|
|
223
|
+
expect(logLinearFit.slope, logLinearCurve.parameters[0]);
|
|
224
|
+
expect(logLinearFit.intercept, logLinearCurve.parameters[1]);
|
|
225
|
+
|
|
226
|
+
const exponentialCurve = fitSeries(exponentialSeries, exponentialFitFunc);
|
|
227
|
+
const exponentialFit = exponentialFitFunc.fillParams(exponentialCurve, exponentialSeries) as ExponentialFit;
|
|
228
|
+
expect(exponentialFit.mantissa, exponentialCurve.parameters[0]);
|
|
229
|
+
expect(exponentialFit.power, exponentialCurve.parameters[1]);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('fillParams dose-response', async () => {
|
|
233
|
+
const fitFunc = fitFunctions[FIT_FUNCTION_4PL_DOSE_RESPONSE];
|
|
234
|
+
const curve = fitSeries(sigmoidSeries, fitFunc);
|
|
235
|
+
const fit = fitFunc.fillParams(curve, sigmoidSeries) as FourPLDoseResponseFit;
|
|
236
|
+
|
|
237
|
+
expect(fit.name, FIT_FUNCTION_4PL_DOSE_RESPONSE);
|
|
238
|
+
expect(fit.ic50, curve.parameters[2]);
|
|
239
|
+
expect(fit.ec50, curve.parameters[2]);
|
|
240
|
+
expect(fit.top, curve.parameters[0]);
|
|
241
|
+
expect(fit.bottom, curve.parameters[3]);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('fillParams custom function', async () => {
|
|
245
|
+
const curve = fitSeries(polynomialSeries, polynomialFitFunc);
|
|
246
|
+
const fit = polynomialFitFunc.fillParams(curve, polynomialSeries) as JSFunctionFit;
|
|
247
|
+
|
|
248
|
+
expectArray(fit.parameters, curve.parameters);
|
|
249
|
+
for (let i = 0; i < polynomialFitFunc.parameterNames.length; i++)
|
|
250
|
+
expect(fit[polynomialFitFunc.parameterNames[i]], curve.parameters[i]);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test('fillParams data points', async () => {
|
|
254
|
+
const curve = fitSeries(sigmoidSeries, sigmoidFitFunc);
|
|
255
|
+
const defaultFit = sigmoidFitFunc.fillParams(curve, sigmoidSeries);
|
|
256
|
+
const explicitFit = sigmoidFitFunc.fillParams(curve, sigmoidSeries,
|
|
257
|
+
getDataPoints(sigmoidSeries, undefined, false));
|
|
258
|
+
const logFit = sigmoidFitFunc.fillParams(curve, sigmoidSeries, undefined, {logX: true, logY: false});
|
|
259
|
+
|
|
260
|
+
expect(explicitFit.rSquared, defaultFit.rSquared);
|
|
261
|
+
expect(explicitFit.auc, defaultFit.auc);
|
|
262
|
+
expect(logFit.rSquared === defaultFit.rSquared, false);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('statisticsProperties', async () => {
|
|
266
|
+
expectArray(sigmoidFitFunc.statisticsProperties.map((p) => p.name),
|
|
267
|
+
['rSquared', 'auc', 'top', 'slope', 'ic50', 'bottom', 'interceptY', 'maxY', 'minY', 'pIC50']);
|
|
268
|
+
expectArray(linearFitFunc.statisticsProperties.map((p) => p.name),
|
|
269
|
+
['rSquared', 'auc', 'slope', 'intercept']);
|
|
270
|
+
expectArray(logLinearFitFunc.statisticsProperties.map((p) => p.name),
|
|
271
|
+
['rSquared', 'auc', 'slope', 'intercept']);
|
|
272
|
+
expectArray(exponentialFitFunc.statisticsProperties.map((p) => p.name),
|
|
273
|
+
['rSquared', 'auc', 'mantissa', 'power']);
|
|
274
|
+
expectArray(fitFunctions[FIT_FUNCTION_4PL_DOSE_RESPONSE].statisticsProperties.map((p) => p.name),
|
|
275
|
+
['rSquared', 'auc', 'top', 'slope', 'ic50', 'bottom', 'interceptY', 'maxY', 'minY', 'pIC50']);
|
|
276
|
+
expectArray(polynomialFitFunc.statisticsProperties.map((p) => p.name),
|
|
277
|
+
['rSquared', 'auc', 'Slope', 'Intercept', 'Parameter3', 'Parameter4']);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test('statisticsProperties friendly names', async () => {
|
|
281
|
+
// parameter labels come from the fit function's own parameterNames, so the two cannot drift
|
|
282
|
+
expectArray(sigmoidFitFunc.statisticsProperties.map((p) => p.friendlyName),
|
|
283
|
+
['R²', 'AUC', 'Top', 'Slope', 'IC50', 'Bottom', 'Y at IC50', 'Max Y', 'Min Y', 'pIC50']);
|
|
284
|
+
expectArray(fitFunctions[FIT_FUNCTION_4PL_REGRESSION].statisticsProperties.map((p) => p.friendlyName),
|
|
285
|
+
['R²', 'AUC', 'Top', 'Slope', 'EC50', 'Bottom', 'Y at EC50', 'Max Y', 'Min Y']);
|
|
286
|
+
expectArray(fitFunctions[FIT_FUNCTION_4PL_DOSE_RESPONSE].statisticsProperties.map((p) => p.friendlyName),
|
|
287
|
+
['R²', 'AUC', 'Max', 'Hill', 'IC50', 'Min', 'Y at IC50', 'Max Y', 'Min Y', 'pIC50']);
|
|
288
|
+
expectArray(linearFitFunc.statisticsProperties.map((p) => p.friendlyName),
|
|
289
|
+
['R²', 'AUC', 'Slope', 'Intercept']);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test('getStatistic legacy names', async () => {
|
|
293
|
+
// getFitFunction is typed, so these need no casts - the fit type is known at compile time
|
|
294
|
+
const sigmoidFit = getSeriesFit(sigmoidSeries, getFitFunction('sigmoid'));
|
|
295
|
+
expect(getStatistic(sigmoidFit, 'interceptX'), sigmoidFit.ic50);
|
|
296
|
+
// the property panel's "+" button passes the current names, extracted columns from saved projects
|
|
297
|
+
// pass the legacy ones - both have to resolve off the same fit
|
|
298
|
+
expect(getStatistic(sigmoidFit, 'ic50'), sigmoidFit.ic50);
|
|
299
|
+
expect(getStatistic(sigmoidFit, 'maxY'), sigmoidFit.maxY);
|
|
300
|
+
expect(getStatistic(sigmoidFit, 'minY'), sigmoidFit.minY);
|
|
301
|
+
expect(getStatistic(sigmoidFit, 'top'), sigmoidFit.top);
|
|
302
|
+
expect(getStatistic(sigmoidFit, 'bottom'), sigmoidFit.bottom);
|
|
303
|
+
expect(getStatistic(sigmoidFit, 'slope'), sigmoidFit.slope);
|
|
304
|
+
|
|
305
|
+
const regressionFit = getSeriesFit({...sigmoidSeries, parameters: undefined}, getFitFunction('4pl-regression'));
|
|
306
|
+
expect(getStatistic(regressionFit, 'interceptX'), regressionFit.ec50);
|
|
307
|
+
|
|
308
|
+
const doseResponseFit = getSeriesFit({...sigmoidSeries, parameters: undefined},
|
|
309
|
+
getFitFunction('4pl-dose-response'));
|
|
310
|
+
expect(getStatistic(doseResponseFit, 'interceptX'), doseResponseFit.ic50);
|
|
311
|
+
|
|
312
|
+
// legacy names a 2-parameter fit lacks fall back to the slot the pre-typed API read positionally,
|
|
313
|
+
// and the descriptor has to agree - a value with no descriptor renders nothing on the plot
|
|
314
|
+
const linearFit = getSeriesFit(linearSeries, getFitFunction('linear'));
|
|
315
|
+
expect(getStatistic(linearFit, 'top'), linearFit.parameters[0]);
|
|
316
|
+
expect(getStatisticProperty(getFitFunction('linear'), 'top') !== undefined, true);
|
|
317
|
+
expect(getStatisticProperty(getFitFunction('linear'), 'interceptX') === undefined, true);
|
|
318
|
+
expect(getStatistic(linearFit, 'interceptX') === undefined);
|
|
319
|
+
expect(getStatistic(linearFit, 'interceptY') === undefined);
|
|
320
|
+
expect(getStatistic(linearFit, 'bottom') === undefined);
|
|
321
|
+
expect(getStatistic(linearFit, 'slope'), linearFit.slope);
|
|
322
|
+
|
|
323
|
+
// the pre-typed API reported interceptY for every fit function, custom ones included
|
|
324
|
+
const jsFit = getSeriesFit(polynomialSeries, getSeriesFitFunction(polynomialSeries));
|
|
325
|
+
expect(typeof getStatistic(jsFit, 'interceptY'), 'number');
|
|
326
|
+
// and a value with no descriptor is skipped by the plot, so both have to resolve
|
|
327
|
+
expect(getStatisticProperty(getSeriesFitFunction(polynomialSeries), 'interceptY') !== undefined, true);
|
|
328
|
+
|
|
329
|
+
// never resolves to a non-numeric field of the fit
|
|
330
|
+
expect(getStatistic(sigmoidFit, 'series') === undefined);
|
|
331
|
+
expect(getStatistic(sigmoidFit, 'parameters') === undefined);
|
|
332
|
+
expect(getStatistic(sigmoidFit, 'name') === undefined);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
test('FitSeries options', async () => {
|
|
336
|
+
// this only compiles if FitSeries still exposes every IFitSeriesOptions member
|
|
337
|
+
const series = new FitSeries([{x: 1, y: 2}]);
|
|
338
|
+
series.name = 'a';
|
|
339
|
+
series.fitFunction = FIT_FUNCTION_SIGMOID;
|
|
340
|
+
series.parameters = [1, 2, 3, 4];
|
|
341
|
+
series.parameterBounds = [{min: 0, max: 1}];
|
|
342
|
+
series.markerType = 'circle';
|
|
343
|
+
series.outlierMarkerType = 'outlier';
|
|
344
|
+
series.lineStyle = 'dashed';
|
|
345
|
+
series.pointColor = '#111111';
|
|
346
|
+
series.fitLineColor = '#222222';
|
|
347
|
+
series.confidenceIntervalColor = '#333333';
|
|
348
|
+
series.outlierColor = '#444444';
|
|
349
|
+
series.connectDots = false;
|
|
350
|
+
series.showFitLine = true;
|
|
351
|
+
series.showPoints = 'points';
|
|
352
|
+
series.showOutliers = true;
|
|
353
|
+
series.showCurveConfidenceInterval = false;
|
|
354
|
+
series.errorModel = 'constant';
|
|
355
|
+
series.clickToToggle = true;
|
|
356
|
+
series.labels = {batch: 'A1'};
|
|
357
|
+
series.droplines = ['IC50'];
|
|
358
|
+
series.columnName = 'curve';
|
|
359
|
+
series.auxLegendName = 'aux';
|
|
360
|
+
|
|
361
|
+
expect(series.name, 'a');
|
|
362
|
+
expect(series.showPoints, 'points');
|
|
363
|
+
expect(series.droplines![0], 'IC50');
|
|
364
|
+
expect(series.auxLegendName, 'aux');
|
|
365
|
+
|
|
366
|
+
// a series stays JSON-serializable - an own `fit` property used to make this circular
|
|
367
|
+
const json = JSON.parse(JSON.stringify(series));
|
|
368
|
+
expect(json.name, 'a');
|
|
369
|
+
expect(json.columnName, 'curve');
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test('maxY and minY', async () => {
|
|
373
|
+
const sigmoidFit = getSeriesFit(sigmoidSeries, getFitFunction('sigmoid'));
|
|
374
|
+
expect(sigmoidFit.maxY, Math.max(sigmoidFit.top, sigmoidFit.bottom));
|
|
375
|
+
expect(sigmoidFit.minY, Math.min(sigmoidFit.top, sigmoidFit.bottom));
|
|
376
|
+
expect(sigmoidFit.maxY >= sigmoidFit.minY, true);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
test('toDataSpace', async () => {
|
|
380
|
+
const logX = {logX: true, logY: false};
|
|
381
|
+
const fitSpace = getSeriesFit(sigmoidSeries, getFitFunction('sigmoid'), undefined, logX);
|
|
382
|
+
const rawIc50 = fitSpace.ic50;
|
|
383
|
+
// toDataSpace mutates in place, so capture before converting
|
|
384
|
+
const untouchedTop = fitSpace.top;
|
|
385
|
+
const dataSpace = toDataSpace(fitSpace, logX);
|
|
386
|
+
|
|
387
|
+
// the inflection point is fitted in log space and must be reported as a concentration
|
|
388
|
+
expect(dataSpace.ic50, Math.pow(10, rawIc50));
|
|
389
|
+
// pIC50 is derived from the concentration, so only after the conversion
|
|
390
|
+
expect(dataSpace.pIC50, -Math.log10(Math.pow(10, rawIc50)));
|
|
391
|
+
expect(dataSpace.top, untouchedTop);
|
|
392
|
+
|
|
393
|
+
// the y asymptotes are reported in the space they were fitted in. A stored bottom of 0 has no
|
|
394
|
+
// finite logarithm, so the forward map has to skip it while the inverse would still return 1 -
|
|
395
|
+
// the two could never be exact inverses, so neither converts
|
|
396
|
+
const logY = {logX: false, logY: true};
|
|
397
|
+
const yFit = getSeriesFit(sigmoidSeries, getFitFunction('sigmoid'), undefined, logY);
|
|
398
|
+
const rawTop = yFit.top;
|
|
399
|
+
const rawIc50Y = yFit.ic50;
|
|
400
|
+
toDataSpace(yFit, logY);
|
|
401
|
+
expect(yFit.top, rawTop);
|
|
402
|
+
expect(yFit.ic50, rawIc50Y); // x untouched when logX is off
|
|
403
|
+
|
|
404
|
+
// no log axes means no conversion at all
|
|
405
|
+
const plain = getSeriesFit(sigmoidSeries, getFitFunction('sigmoid'));
|
|
406
|
+
const plainIc50 = plain.ic50;
|
|
407
|
+
toDataSpace(plain, {logX: false, logY: false});
|
|
408
|
+
expect(plain.ic50, plainIc50);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test('isFit narrowing', async () => {
|
|
412
|
+
// a runtime-dispatched fit function yields a plain Fit; isFit narrows it to the concrete type
|
|
413
|
+
const fit = getSeriesFit(sigmoidSeries, getSeriesFitFunction(sigmoidSeries));
|
|
414
|
+
expect(isFit(fit, 'sigmoid'));
|
|
415
|
+
expect(isFit(fit, 'linear') === false);
|
|
416
|
+
if (isFit(fit, 'sigmoid'))
|
|
417
|
+
expect(fit.ic50, getStatistic(fit, 'interceptX'));
|
|
418
|
+
});
|
|
419
|
+
|
|
170
420
|
test('calculateBoxPlotStatistics', async () => {
|
|
171
421
|
const values = [0.7654603719711304, 0.8199243545532227, 0.8257747292518616, 0.9558155536651611, 0.9596694707870483];
|
|
172
422
|
const boxPlotStats = calculateBoxPlotStatistics(values);
|
|
@@ -178,6 +428,52 @@ category('fit', () => {
|
|
|
178
428
|
expect(boxPlotStats.upperAdjacentValue, 0.9558155536651611);
|
|
179
429
|
});
|
|
180
430
|
|
|
431
|
+
test('ICxx is the x at that fraction of the curve', async () => {
|
|
432
|
+
// travelled fraction, measured from the low-x asymptote - so the same call means IC90 on a
|
|
433
|
+
// descending curve and EC90 on an ascending one
|
|
434
|
+
const at = (fitFunc: keyof FitTypeMap, params: number[], fraction: number,
|
|
435
|
+
lowX: number, highX: number): number => {
|
|
436
|
+
const f = getFitFunction(fitFunc)!;
|
|
437
|
+
const array = Float32Array.from(params);
|
|
438
|
+
const start = f.y(array, lowX);
|
|
439
|
+
const end = f.y(array, highX);
|
|
440
|
+
return (f.y(array, f.inverse(array, fraction)!) - start) / (end - start);
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
for (const fitFunc of ['sigmoid', '4pl-dose-response'] as (keyof FitTypeMap)[]) {
|
|
444
|
+
for (const slope of [1.2, -1.2]) {
|
|
445
|
+
for (const fraction of [0.1, 0.5, 0.9]) {
|
|
446
|
+
expectFloat(at(fitFunc, [100, slope, -6.5, 5], fraction, -1e6, 1e6), fraction, 0.001,
|
|
447
|
+
`${fitFunc}, slope ${slope}, IC${fraction * 100}`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
// the power parameterization, where x is a concentration rather than its logarithm
|
|
452
|
+
for (const slope of [1.2, -1.2]) {
|
|
453
|
+
for (const fraction of [0.1, 0.5, 0.9])
|
|
454
|
+
expectFloat(at('4pl-regression', [100, slope, 3e-7, 5], fraction, 1e-30, 1e30), fraction, 0.001);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// IC50 is the inflection point, which is what the droplines drew before there was a family
|
|
458
|
+
const sigmoidFunc = getFitFunction('sigmoid')!;
|
|
459
|
+
expect(sigmoidFunc.inverse(Float32Array.from([100, 1.2, -6.5, 5]), 0.5), -6.5);
|
|
460
|
+
|
|
461
|
+
// nothing to travel between, so nothing to name
|
|
462
|
+
for (const fitFunc of ['linear', 'log-linear', 'exponential'] as (keyof FitTypeMap)[])
|
|
463
|
+
expect(getFitFunction(fitFunc)!.inverse(Float32Array.from([1, 2]), 0.9) === undefined, true, fitFunc);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
test('a dropline name asks for a fraction', async () => {
|
|
467
|
+
expect(droplineFraction('IC50'), 0.5);
|
|
468
|
+
expect(droplineFraction('IC90'), 0.9);
|
|
469
|
+
expect(droplineFraction('EC50'), 0.5);
|
|
470
|
+
expect(droplineFraction('ic55'), 0.55);
|
|
471
|
+
expect(droplineFraction('IC12.5'), 0.125);
|
|
472
|
+
// the asymptotes themselves are never reached, and these are not concentrations at all
|
|
473
|
+
for (const name of ['IC0', 'IC100', 'AUC', ''])
|
|
474
|
+
expect(droplineFraction(name) === undefined, true, name);
|
|
475
|
+
});
|
|
476
|
+
|
|
181
477
|
test('sigmoid', async () => {
|
|
182
478
|
const parameters = [2.612687371569039, -1.421800778574126, 5.16688669906018, 0.341788492203575];
|
|
183
479
|
const params = new Float32Array(4);
|
|
@@ -213,4 +509,15 @@ category('fit', () => {
|
|
|
213
509
|
expect(exponential(params, 0.5), 0.2957925783034655);
|
|
214
510
|
expect(exponential(params, 0.98746), 0.0010630898492656174);
|
|
215
511
|
});
|
|
512
|
+
|
|
513
|
+
test('the combined error model fits to fixed values', async () => {
|
|
514
|
+
// noisy on purpose: a perfect fit leaves no residuals for the error model to weigh
|
|
515
|
+
const series = {fitFunction: 'sigmoid', errorModel: 'combined',
|
|
516
|
+
points: [1e-9, 3e-9, 1e-8, 3e-8, 1e-7, 3e-7, 1e-6, 3e-6, 1e-5, 3e-5, 1e-4]
|
|
517
|
+
.map((x, i) => ({x: x, y: (5 + 95 / (1 + Math.pow(10, Math.log10(x) + 6.5))) * (1 + 0.08 * Math.sin(i * 2.4))}))};
|
|
518
|
+
const logOptions = {logX: true, logY: false};
|
|
519
|
+
const fit = fitSeries(series as any, getSeriesFitFunction(series as any), undefined, logOptions);
|
|
520
|
+
expectArray(Array.from(fit.parameters).map((p) => Number(p.toFixed(6))),
|
|
521
|
+
[100.771515, 0.984725, -6.517356, 5.065719]);
|
|
522
|
+
});
|
|
216
523
|
});
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import * as DG from 'datagrok-api/dg';
|
|
2
|
+
import * as ui from 'datagrok-api/ui';
|
|
3
|
+
|
|
4
|
+
import {category, test, expect, expectArray} from '@datagrok-libraries/test/src/test';
|
|
5
|
+
import {IFitChartData} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
6
|
+
import {chooseLegendCorner, legendEntries, legendTooltip, legendTooltipElement, maxTooltipRows} from '../fit/fit-legend';
|
|
7
|
+
|
|
8
|
+
import {sigmoidPoints, renderedTexts, renderedRows} from './curve-data';
|
|
9
|
+
|
|
10
|
+
/** Curves spread over several columns, the way the multi curve viewer hands them over. */
|
|
11
|
+
function multiColumnJson(columns: {column: string, series: string[]}[], showColumnLabel: boolean = true): string {
|
|
12
|
+
const series = [];
|
|
13
|
+
for (const {column, series: names} of columns) {
|
|
14
|
+
for (const name of names) {
|
|
15
|
+
series.push({fitFunction: 'sigmoid', name: name, columnName: column,
|
|
16
|
+
points: sigmoidPoints(-6.5)});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return JSON.stringify({chartOptions: {logX: true, showColumnLabel: showColumnLabel},
|
|
20
|
+
series: series} as IFitChartData);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const PLOT = new DG.Rect(0, 0, 500, 400);
|
|
24
|
+
|
|
25
|
+
function measureWidth(text: string): number {
|
|
26
|
+
const g = ui.canvas(10, 10).getContext('2d')!;
|
|
27
|
+
g.font = '11px Roboto, "Roboto Local"';
|
|
28
|
+
return g.measureText(text).width;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
category('legend', () => {
|
|
32
|
+
test('a column holding one curve does not get a row of its own', async () => {
|
|
33
|
+
// the siRNA shape: four curve columns, one curve each
|
|
34
|
+
const data = JSON.parse(multiColumnJson([
|
|
35
|
+
{column: 'curve', series: ['PF5624 P1_1h']},
|
|
36
|
+
{column: 'durability_curve', series: ['siR-0016_durability']},
|
|
37
|
+
{column: 'in_vivo_dr_curve', series: ['siR-0016_invivo_dr']},
|
|
38
|
+
{column: 'plasma_stability_curve', series: ['siR-0016_plasma_stab']},
|
|
39
|
+
])) as IFitChartData;
|
|
40
|
+
expectArray(legendEntries(data).map((e) => e.text),
|
|
41
|
+
['PF5624 P1_1h', 'siR-0016_durability', 'siR-0016_invivo_dr', 'siR-0016_plasma_stab']);
|
|
42
|
+
|
|
43
|
+
// a column with several curves still groups them under its name
|
|
44
|
+
const grouped = JSON.parse(multiColumnJson([{column: 'curve', series: ['low', 'high']}])) as IFitChartData;
|
|
45
|
+
expectArray(legendEntries(grouped).map((e) => e.text), ['curve', 'low', 'high']);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('a name shared by two columns is qualified by the column', async () => {
|
|
49
|
+
const data = JSON.parse(multiColumnJson([
|
|
50
|
+
{column: 'day 1', series: ['control']},
|
|
51
|
+
{column: 'day 7', series: ['control']},
|
|
52
|
+
])) as IFitChartData;
|
|
53
|
+
expectArray(legendEntries(data).map((e) => e.text), ['day 1: control', 'day 7: control']);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('two curves named alike in one column are left as the data has them', async () => {
|
|
57
|
+
// the demo shape: one column, both series called Run:2023-08-08 - a column prefix on both would
|
|
58
|
+
// tell them apart no better and take twice the width
|
|
59
|
+
const data = JSON.parse(multiColumnJson([
|
|
60
|
+
{column: 'multiple styled series', series: ['Run:2023-08-08', 'Run:2023-08-08']},
|
|
61
|
+
])) as IFitChartData;
|
|
62
|
+
expectArray(legendEntries(data).map((e) => e.text),
|
|
63
|
+
['multiple styled series', 'Run:2023-08-08', 'Run:2023-08-08']);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('a shortened row says what it stands for when hovered', async () => {
|
|
67
|
+
const long = 'Copy of 20250528_NHA Assay_analysis Plate_1 rep 2 run 3 reader B plate map 7 revision 2';
|
|
68
|
+
const data = JSON.parse(multiColumnJson([{column: 'curve', series: [long]}])) as IFitChartData;
|
|
69
|
+
const drawn = renderedRows(JSON.stringify(data), 'legendHover', 500, 400);
|
|
70
|
+
const row = drawn.rows.find((r) => r.text.startsWith('Copy of'))!;
|
|
71
|
+
expect(row !== undefined, true, 'the curve should be named');
|
|
72
|
+
|
|
73
|
+
const hovered = legendTooltip(drawn.data, drawn.dataBox, row.x + 5, row.y - 4);
|
|
74
|
+
expect(hovered?.length, 1, 'hovering the row should say one thing');
|
|
75
|
+
expect(hovered![0].text, long, 'and it should be the whole name');
|
|
76
|
+
expect(legendTooltip(drawn.data, drawn.dataBox, drawn.dataBox.x + 5, drawn.dataBox.maxY - 5) === null, true,
|
|
77
|
+
'the rest of the plot should say nothing');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('candlesticks and statistics count as ink, not just fit lines', async () => {
|
|
81
|
+
// a plateau drawn as candlesticks, no fit line: it used to report nothing, so the legend sat on it
|
|
82
|
+
const points = [];
|
|
83
|
+
for (const x of [1e-9, 1e-8, 1e-7, 1e-6, 1e-5]) {
|
|
84
|
+
points.push({x: x, y: 100});
|
|
85
|
+
points.push({x: x, y: 96});
|
|
86
|
+
}
|
|
87
|
+
points.push({x: 1e-4, y: 0});
|
|
88
|
+
const candles = JSON.stringify({chartOptions: {logX: true},
|
|
89
|
+
series: [{name: 'Run:2023-08-08', columnName: 'curve', showPoints: 'candlesticks', showFitLine: false,
|
|
90
|
+
connectDots: true, points: points}]} as IFitChartData);
|
|
91
|
+
const drawn = renderedRows(candles, 'legendCandles', 500, 400);
|
|
92
|
+
const row = drawn.rows.find((r) => r.text.startsWith('Run:'))!;
|
|
93
|
+
expect(row !== undefined, true, 'the curve should be named');
|
|
94
|
+
expect(row.y > drawn.dataBox.midY, true, `points fill the top, so the legend belongs below: y=${row.y}`);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('the statistics on the plot are ink the legend keeps clear of', async () => {
|
|
98
|
+
const data = JSON.parse(multiColumnJson([{column: 'curve', series: ['Run:2023-08-08']}])) as IFitChartData;
|
|
99
|
+
data.chartOptions!.showStatistics = ['ic50'];
|
|
100
|
+
const drawn = renderedRows(JSON.stringify(data), 'legendStats', 500, 400);
|
|
101
|
+
const statistic = drawn.rows.find((r) => r.text.startsWith('IC50'))!;
|
|
102
|
+
const row = drawn.rows.find((r) => r.text.startsWith('Run:'))!;
|
|
103
|
+
expect(statistic !== undefined && row !== undefined, true, 'both should be drawn');
|
|
104
|
+
expect(Math.abs(row.y - statistic.y) > 10 || Math.abs(row.x - statistic.x) > 60, true,
|
|
105
|
+
`the legend should not land on the statistics: legend ${row.x},${row.y} vs ${statistic.x},${statistic.y}`);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('a curve across the top sends the legend to the bottom', async () => {
|
|
109
|
+
// the shape that misplaced it: a plateau spanning the plot just under the top, both bottom
|
|
110
|
+
// corners empty. Sitting right below the top left box is still crowding it
|
|
111
|
+
const box = new DG.Rect(0, 0, 400, 300);
|
|
112
|
+
const plateau = [];
|
|
113
|
+
for (let x = box.x + 10; x < box.maxX - 10; x += 8)
|
|
114
|
+
plateau.push(new DG.Point(x, box.y + 30));
|
|
115
|
+
const corner = chooseLegendCorner(box, 120, 20, plateau).rect;
|
|
116
|
+
expect(corner.y > box.midY, true, `expected a bottom corner, got y=${corner.y}`);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('the legend takes a corner the curves leave free', async () => {
|
|
120
|
+
const box = new DG.Rect(0, 0, 400, 300);
|
|
121
|
+
const busyTopRight = Array.from({length: 30}, (_, i) => new DG.Point(box.maxX - 10 - i, box.y + 10 + i % 20));
|
|
122
|
+
const corner = chooseLegendCorner(box, 120, 60, busyTopRight).rect;
|
|
123
|
+
expect(corner.x < box.midX, true, 'a crowded top right should push the legend away');
|
|
124
|
+
|
|
125
|
+
// a couple of stray points are not a reason to move
|
|
126
|
+
const almostFree = [new DG.Point(box.maxX - 20, box.y + 20), new DG.Point(box.maxX - 30, box.y + 30)];
|
|
127
|
+
expect(chooseLegendCorner(box, 120, 60, almostFree).rect.x > box.midX, true, 'it should stay put');
|
|
128
|
+
// and neither is a chart with no free corner at all
|
|
129
|
+
const busyAll = [];
|
|
130
|
+
for (const corner of [[box.maxX - 20, box.y + 20], [box.x + 20, box.y + 20],
|
|
131
|
+
[box.maxX - 20, box.maxY - 20], [box.x + 20, box.maxY - 20]]) {
|
|
132
|
+
for (let i = 0; i < 30; i++)
|
|
133
|
+
busyAll.push(new DG.Point(corner[0], corner[1] + (i % 10)));
|
|
134
|
+
}
|
|
135
|
+
expect(chooseLegendCorner(box, 120, 60, busyAll).rect.x > box.midX, true, 'nowhere better means no move');
|
|
136
|
+
expect(chooseLegendCorner(box, 120, 60).rect.x > box.midX, true, 'and with nothing drawn it is the top right');
|
|
137
|
+
|
|
138
|
+
// once placed it holds its corner unless the alternative is clearly emptier, so a few pixels of
|
|
139
|
+
// resizing cannot make it hop
|
|
140
|
+
const mild = [...busyTopRight.slice(0, 6), new DG.Point(box.x + 20, box.maxY - 20)];
|
|
141
|
+
const held = chooseLegendCorner(box, 120, 60, mild, 3);
|
|
142
|
+
expect(held.index, 3, 'it should keep the corner it was in');
|
|
143
|
+
expect(chooseLegendCorner(box, 120, 60, busyTopRight, 3).index, 3, 'even when the top right is busy');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('a name is only shortened when it really does not fit', async () => {
|
|
147
|
+
// this one was cut although the corner it sits in is wide open
|
|
148
|
+
const name = 'SigmoidalInhibitionFunction';
|
|
149
|
+
for (const width of [500, 430, 380]) {
|
|
150
|
+
const drawn = renderedTexts(multiColumnJson([{column: 'curve', series: [name]}]),
|
|
151
|
+
`legendFits${width}`, width, 400);
|
|
152
|
+
expect(drawn.includes(name), true,
|
|
153
|
+
`at ${width}px expected the whole name, got: ${drawn.filter((t) => t.startsWith('Sigmo'))}`);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('a name too long for any corner is ellipsized', async () => {
|
|
158
|
+
const long = 'Copy of 20250528_NHA Assay_analysis Plate_1 rep 2 run 3 reader B plate map 7 revision 2';
|
|
159
|
+
const data = multiColumnJson([{column: 'curve', series: [long]}]);
|
|
160
|
+
const drawn = renderedTexts(data, 'legendEllipsis', 500, 400);
|
|
161
|
+
const entry = drawn.find((t) => t.startsWith('Copy of'));
|
|
162
|
+
expect(entry !== undefined, true, 'the curve should be named');
|
|
163
|
+
expect(entry!.endsWith('…'), true, `expected an ellipsis, got: ${entry}`);
|
|
164
|
+
expect(entry!.length < long.length, true, 'the name should be shortened');
|
|
165
|
+
// it is capped, so the legend can never take more than a corner of the plot it annotates
|
|
166
|
+
expect(measureWidth(entry!) <= PLOT.width * 0.55, true, 'the row must stay within its cap');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('naming the curves can be turned off for the whole plot', async () => {
|
|
170
|
+
const data = JSON.parse(multiColumnJson([{column: 'curve', series: ['Run:2023-08-08']}])) as IFitChartData;
|
|
171
|
+
expect(renderedTexts(JSON.stringify(data), 'legendOn', 500, 400).includes('Run:2023-08-08'), true);
|
|
172
|
+
|
|
173
|
+
data.chartOptions!.showLegend = false;
|
|
174
|
+
const off = renderedTexts(JSON.stringify(data), 'legendOff', 500, 400);
|
|
175
|
+
expect(off.includes('Run:2023-08-08'), false, 'showLegend: false should leave the curves unnamed');
|
|
176
|
+
// and the rest of the chart is untouched
|
|
177
|
+
expect(off.some((t) => t === 'Conc.' || t === 'Activity' || t.length > 0), true);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('hovering what did not fit gives the whole legend', async () => {
|
|
181
|
+
const names = Array.from({length: 40}, (_, i) => `series ${i}`);
|
|
182
|
+
const drawn = renderedRows(multiColumnJson([{column: 'curve', series: names}]), 'legendMoreHover', 500, 400);
|
|
183
|
+
const more = drawn.rows.find((r) => r.text.startsWith('+') && r.text.endsWith('more'))!;
|
|
184
|
+
expect(more !== undefined, true, 'the legend should say how many it left out');
|
|
185
|
+
|
|
186
|
+
const hovered = legendTooltip(drawn.data, drawn.dataBox, more.x + 5, more.y - 4);
|
|
187
|
+
// one row per curve plus the column that groups them
|
|
188
|
+
expect(hovered?.length, names.length + 1, 'the tooltip should carry every row the legend has');
|
|
189
|
+
expect(hovered!.some((r) => r.text === 'series 39'), true, 'including the ones it could not draw');
|
|
190
|
+
expect(hovered!.every((r) => r.color.length > 0), true, 'each named in the colour of its curve');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('a legend short enough to list keeps every row in the tooltip', async () => {
|
|
194
|
+
const data: IFitChartData = JSON.parse(multiColumnJson([{column: 'curve',
|
|
195
|
+
series: Array.from({length: 4}, (_, i) => `series ${i}`)}]));
|
|
196
|
+
const entries = legendEntries(data);
|
|
197
|
+
const element = legendTooltipElement(entries);
|
|
198
|
+
expect(element.querySelectorAll('canvas').length, entries.length, 'every row should carry its glyph');
|
|
199
|
+
expect(element.innerText.includes('more'), false, 'nothing is left to count when it all fits');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('a legend too long for the window is counted rather than listed', async () => {
|
|
203
|
+
const data: IFitChartData = JSON.parse(multiColumnJson([{column: 'curve',
|
|
204
|
+
series: Array.from({length: 300}, (_, i) => `series ${i}`)}]));
|
|
205
|
+
const entries = legendEntries(data);
|
|
206
|
+
const rows = maxTooltipRows();
|
|
207
|
+
expect(entries.length > rows, true, 'the fixture should outgrow any window');
|
|
208
|
+
const element = legendTooltipElement(entries);
|
|
209
|
+
expect(element.querySelectorAll('canvas').length, rows, 'it lists what the window has room for');
|
|
210
|
+
expect(element.innerText.trim().endsWith(`+${entries.length - rows} more`), true,
|
|
211
|
+
'and counts the rest');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('a name the plot shortened is given back whole, however long', async () => {
|
|
215
|
+
const long = 'x'.repeat(2000);
|
|
216
|
+
const data: IFitChartData = JSON.parse(multiColumnJson([{column: 'curve', series: [long]}]));
|
|
217
|
+
const entries = legendEntries(data);
|
|
218
|
+
expect(entries.length, 1, 'a column holding one curve is named once');
|
|
219
|
+
expect(legendTooltipElement(entries).innerText.includes(long), true,
|
|
220
|
+
'hovering that one row is what says the whole of a name');
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('names that long are labels once the hover lists several', async () => {
|
|
224
|
+
const long = 'x'.repeat(2000);
|
|
225
|
+
const data: IFitChartData = JSON.parse(multiColumnJson([{column: 'curve',
|
|
226
|
+
series: [`${long} a`, `${long} b`, `${long} c`]}]));
|
|
227
|
+
const element = legendTooltipElement(legendEntries(data));
|
|
228
|
+
expect(element.innerText.includes(long), false, 'a list of cells of JSON should not be spelled out');
|
|
229
|
+
expect(element.innerText.includes('…'), true, 'each row should say it was shortened');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('more curves than fit are counted instead of stacked', async () => {
|
|
233
|
+
const names = Array.from({length: 40}, (_, i) => `series ${i}`);
|
|
234
|
+
const drawn = renderedTexts(multiColumnJson([{column: 'curve', series: names}]), 'legendOverflow', 500, 400);
|
|
235
|
+
const more = drawn.find((t) => t.startsWith('+') && t.endsWith('more'));
|
|
236
|
+
expect(more !== undefined, true, 'the legend should say how many it left out');
|
|
237
|
+
// the names it did draw plus the ones it counted cover every curve
|
|
238
|
+
const shown = drawn.filter((t) => t.startsWith('series ')).length;
|
|
239
|
+
expect(shown > 0, true, 'it should still draw the curves that fit');
|
|
240
|
+
expect(shown + parseInt(more!.slice(1), 10), names.length,
|
|
241
|
+
'drawn names plus the counted ones should cover every curve');
|
|
242
|
+
});
|
|
243
|
+
});
|