@datagrok/curves 1.12.2 → 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 +77 -0
- package/CLAUDE.md +118 -15
- package/README.md +51 -4
- package/dist/package-test.js +11551 -8501
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +3368 -2022
- package/dist/package.js.map +1 -1
- package/files/demo/Assay_Curves.csv +43 -43
- package/package.json +2 -2
- package/scripts/calculateMSR.py +16 -7
- 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 +78 -0
- package/src/package-test.ts +6 -0
- package/src/package.g.ts +59 -11
- package/src/package.ts +97 -18
- package/src/tests/calculated-columns-tests.ts +299 -0
- package/src/tests/converter-tests.ts +23 -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 +347 -103
- package/test-record-1.mp4 +0 -0
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as DG from 'datagrok-api/dg';
|
|
2
|
+
import * as grok from 'datagrok-api/grok';
|
|
3
|
+
|
|
4
|
+
import {category, test, expect, delay} from '@datagrok-libraries/test/src/test';
|
|
5
|
+
import {FitConstants} from '@datagrok-libraries/statistics/src/fit/const';
|
|
6
|
+
import {getOrCreateParsedChartData} from '../fit/fit-chart-data';
|
|
7
|
+
import {MultiCurveViewer} from '../fit/multi-curve-viewer';
|
|
8
|
+
import {multiSeriesCurveJson} from './curve-data';
|
|
9
|
+
|
|
10
|
+
function curveTable(name: string): DG.DataFrame {
|
|
11
|
+
const col = DG.Column.fromStrings('curve', [multiSeriesCurveJson([-7, -5]), multiSeriesCurveJson([-6, -4])]);
|
|
12
|
+
col.semType = FitConstants.FIT_SEM_TYPE;
|
|
13
|
+
const df = DG.DataFrame.fromColumns([col]);
|
|
14
|
+
df.name = name;
|
|
15
|
+
return df;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
category('multi curve viewer', () => {
|
|
19
|
+
test('merging cell series leaves the cell alone, and unmerging comes back', async () => {
|
|
20
|
+
const df = curveTable('multiCurveMerge');
|
|
21
|
+
const tv = grok.shell.addTableView(df);
|
|
22
|
+
try {
|
|
23
|
+
df.currentRowIdx = 0;
|
|
24
|
+
tv.addViewer('MultiCurveViewer', {curvesColumnNames: ['curve']});
|
|
25
|
+
await delay(1000);
|
|
26
|
+
// addViewer hands back the host wrapper, and the merge happens on the JS instance behind it
|
|
27
|
+
const viewer = Array.from(tv.viewers).find((v) => v.type === 'MultiCurveViewer') as MultiCurveViewer;
|
|
28
|
+
expect(viewer !== undefined, true, 'the viewer was not added');
|
|
29
|
+
expect(viewer.data?.series?.length, 2, 'the current row carries two curves');
|
|
30
|
+
|
|
31
|
+
viewer.props.set('mergeCellSeries', true as unknown as object);
|
|
32
|
+
await delay(500);
|
|
33
|
+
expect(viewer.data?.series?.length, 1, 'merging should leave one curve in the viewer');
|
|
34
|
+
// the parsed data is cached and shared with the grid - merging into it used to rewrite the cell
|
|
35
|
+
expect(getOrCreateParsedChartData(df.cell(0, 'curve')).series!.length, 2,
|
|
36
|
+
'the cell itself must still hold both curves');
|
|
37
|
+
|
|
38
|
+
viewer.props.set('mergeCellSeries', false as unknown as object);
|
|
39
|
+
await delay(500);
|
|
40
|
+
expect(viewer.data?.series?.length, 2, 'unmerging should bring both curves back');
|
|
41
|
+
} finally {
|
|
42
|
+
tv.close();
|
|
43
|
+
}
|
|
44
|
+
}, {timeout: 60000});
|
|
45
|
+
|
|
46
|
+
test('the viewer names where each of its curves came from', async () => {
|
|
47
|
+
const df = curveTable('multiCurveFitIdentities');
|
|
48
|
+
const tv = grok.shell.addTableView(df);
|
|
49
|
+
try {
|
|
50
|
+
df.currentRowIdx = 0;
|
|
51
|
+
tv.addViewer('MultiCurveViewer', {curvesColumnNames: ['curve']});
|
|
52
|
+
await delay(1500);
|
|
53
|
+
const viewer = Array.from(tv.viewers).find((v) => v.type === 'MultiCurveViewer') as any;
|
|
54
|
+
expect(viewer.fitIdentities.length, viewer.data.series.length,
|
|
55
|
+
'every series should carry an identity, in the order they are drawn');
|
|
56
|
+
expect(viewer.fitIdentities.every((id: string | undefined) => id !== undefined), true,
|
|
57
|
+
'and none of them should be missing');
|
|
58
|
+
} finally {
|
|
59
|
+
tv.close();
|
|
60
|
+
}
|
|
61
|
+
}, {timeout: 60000});
|
|
62
|
+
|
|
63
|
+
test('the viewer answers the same hovers the grid does', async () => {
|
|
64
|
+
const logIC50s = Array.from({length: 40}, (_, i) => -8 + i * 0.1);
|
|
65
|
+
const col = DG.Column.fromStrings('curve', [multiSeriesCurveJson(logIC50s)]);
|
|
66
|
+
col.semType = FitConstants.FIT_SEM_TYPE;
|
|
67
|
+
const df = DG.DataFrame.fromColumns([col]);
|
|
68
|
+
df.name = 'multiCurveHover';
|
|
69
|
+
const tv = grok.shell.addTableView(df);
|
|
70
|
+
try {
|
|
71
|
+
df.currentRowIdx = 0;
|
|
72
|
+
tv.addViewer('MultiCurveViewer', {curvesColumnNames: ['curve']});
|
|
73
|
+
await delay(2000);
|
|
74
|
+
const viewer = Array.from(tv.viewers).find((v) => v.type === 'MultiCurveViewer') as any;
|
|
75
|
+
expect(viewer.data.series.length, 40, 'the current row carries all the curves');
|
|
76
|
+
|
|
77
|
+
// the grid routes mouse moves to the cell renderer; the viewer has to do it itself
|
|
78
|
+
const canvas: HTMLCanvasElement = viewer.canvas;
|
|
79
|
+
const rect = canvas.getBoundingClientRect();
|
|
80
|
+
// any row will do - whether the tail collapses into `+N more` depends on the viewer's height
|
|
81
|
+
let tooltip: string[] = [];
|
|
82
|
+
for (let x = 10; x < canvas.width - 5 && tooltip.length === 0; x += 10) {
|
|
83
|
+
for (let y = 6; y < canvas.height - 5; y += 6) {
|
|
84
|
+
canvas.dispatchEvent(new MouseEvent('mousemove',
|
|
85
|
+
{bubbles: true, clientX: rect.left + x, clientY: rect.top + y}));
|
|
86
|
+
const shown = document.querySelector('.d4-tooltip') as HTMLElement | null;
|
|
87
|
+
const lines: string[] = shown?.innerText ?
|
|
88
|
+
shown.innerText.split(String.fromCharCode(10)).filter((t: string) => t.trim().length > 0) : [];
|
|
89
|
+
if (lines.some((line) => line.startsWith('series '))) {
|
|
90
|
+
tooltip = lines;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
expect(tooltip.length > 0, true, 'hovering the legend in the viewer should name a curve');
|
|
96
|
+
} finally {
|
|
97
|
+
tv.close();
|
|
98
|
+
}
|
|
99
|
+
}, {timeout: 90000});
|
|
100
|
+
});
|