@datagrok/curves 1.6.0 → 1.9.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/.eslintrc.json +39 -0
- package/.vscode/launch.json +10 -9
- package/.vscode/tasks.json +14 -0
- package/CHANGELOG.md +33 -0
- package/README.md +36 -8
- package/databases/plates/0000_init.sql +167 -0
- package/detectors.js +2 -2
- package/dist/package-test.js +15930 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +13750 -1
- package/dist/package.js.map +1 -1
- package/img/plate-dose-response-series.gif +0 -0
- package/img/plate-readers.gif +0 -0
- package/package.json +17 -11
- package/queries/plates-crud.sql +148 -0
- package/src/fit/const.ts +60 -59
- package/src/fit/data-to-curves.ts +220 -0
- package/src/fit/fit-demo.ts +6 -6
- package/src/fit/fit-grid-cell-handler.ts +94 -85
- package/src/fit/fit-renderer.ts +162 -98
- package/src/fit/multi-curve-viewer.ts +69 -28
- package/src/fit/render-utils.ts +346 -288
- package/src/package-api.ts +167 -0
- package/src/package-test.ts +7 -1
- package/src/package.g.ts +140 -2
- package/src/package.ts +221 -79
- package/src/plate/excel-plates.ts +112 -0
- package/src/plate/plate-cell-renderer.ts +48 -0
- package/src/plate/plate-drc-analysis.ts +262 -0
- package/src/plate/plate-reader.ts +28 -0
- package/src/plate/plate-well-validators.ts +41 -0
- package/src/plate/plate-widget.ts +242 -0
- package/src/plate/plate.ts +557 -0
- package/src/plate/plates-folder-preview.ts +63 -0
- package/src/plate/readers/bmg-pherastar-96.ts +42 -0
- package/src/plate/readers/delfia-envision-96-max-rlu.ts +16 -0
- package/src/plate/readers/delfia-envision-by-row.ts +18 -0
- package/src/plate/readers/spectramax.ts +42 -0
- package/src/plate/utils.ts +141 -0
- package/src/plates/numeric_matcher.ts +191 -0
- package/src/plates/objects/plate-template-handler.ts +48 -0
- package/src/plates/plates-app.ts +64 -0
- package/src/plates/plates-crud.ts +502 -0
- package/src/plates/plates-demo.ts +107 -0
- package/src/plates/plates.sql +169 -0
- package/src/plates/views/plates-create-view.ts +123 -0
- package/src/plates/views/plates-schema-view.ts +58 -0
- package/src/plates/views/plates-search-view.ts +137 -0
- package/src/plates/views/plates-templates-view.ts +38 -0
- package/src/tests/curves-cell-renderer-tests.ts +95 -75
- package/src/tests/detector-tests.ts +3 -2
- package/src/tests/fit-tests.ts +199 -163
- package/src/tests/plate-tests.ts +153 -0
- package/src/tests/transform-tests.ts +6 -6
- package/test-console-output-1.log +435 -0
- package/test-record-1.mp4 +0 -0
- package/tsconfig.json +1 -1
- package/src/fit/cell-render-viewer.ts +0 -54
package/src/fit/render-utils.ts
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
1
2
|
import * as DG from 'datagrok-api/dg';
|
|
2
3
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from
|
|
4
|
+
FitConfidenceIntervals,
|
|
5
|
+
FitFunction,
|
|
6
|
+
IFitChartData,
|
|
7
|
+
IFitSeries,
|
|
8
|
+
statisticsProperties
|
|
9
|
+
} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
9
10
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from
|
|
14
|
-
import {Viewport} from
|
|
15
|
-
import {FitConstants} from
|
|
16
|
-
import {BoxPlotStatistics, calculateBoxPlotStatistics} from
|
|
17
|
-
import {StringUtils} from
|
|
18
|
-
|
|
11
|
+
getSeriesConfidenceInterval,
|
|
12
|
+
getSeriesStatistics,
|
|
13
|
+
LogOptions
|
|
14
|
+
} from '@datagrok-libraries/statistics/src/fit/fit-data';
|
|
15
|
+
import {Viewport} from '@datagrok-libraries/utils/src/transform';
|
|
16
|
+
import {FitConstants} from './const';
|
|
17
|
+
import {BoxPlotStatistics, calculateBoxPlotStatistics} from '@datagrok-libraries/statistics/src/box-plot-statistics';
|
|
18
|
+
import {StringUtils} from '@datagrok-libraries/utils/src/string-utils';
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export enum ColorType {
|
|
22
|
+
POINT = 'pointColor',
|
|
23
|
+
OUTLIER = 'outlierColor',
|
|
24
|
+
FIT_LINE = 'fitLineColor',
|
|
25
|
+
}
|
|
26
|
+
export type SeriesColorType = `${ColorType}` | string;
|
|
19
27
|
|
|
20
28
|
interface FitRenderOptions {
|
|
21
29
|
viewport: Viewport;
|
|
30
|
+
screenBounds?: DG.Rect;
|
|
22
31
|
ratio?: number;
|
|
32
|
+
seriesIdx?: number;
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
interface FitPointRenderOptions extends FitRenderOptions {
|
|
@@ -41,6 +51,7 @@ interface FitConfidenceIntervalRenderOptions extends FitLineRenderOptions {
|
|
|
41
51
|
userParamsFlag?: boolean;
|
|
42
52
|
confidenceIntervals?: FitConfidenceIntervals;
|
|
43
53
|
confidenceType?: string;
|
|
54
|
+
dataPoints?: {x: number[], y: number[]};
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
interface FitDroplineRenderOptions extends FitRenderOptions {
|
|
@@ -56,6 +67,9 @@ interface FitStatisticsRenderOptions {
|
|
|
56
67
|
fitFunc: FitFunction;
|
|
57
68
|
logOptions: LogOptions;
|
|
58
69
|
dataBox: DG.Rect;
|
|
70
|
+
screenBounds?: DG.Rect;
|
|
71
|
+
dataPoints?: {x: number[], y: number[]};
|
|
72
|
+
seriesIdx?: number;
|
|
59
73
|
}
|
|
60
74
|
|
|
61
75
|
interface FitTitleRenderOptions {
|
|
@@ -81,351 +95,395 @@ interface FitLegendColumnlabelSeriesRenderOptions extends FitLegendRenderOptions
|
|
|
81
95
|
columnIdx: number;
|
|
82
96
|
drawnCurvesInLegend: number;
|
|
83
97
|
showColumnLabel?: boolean;
|
|
98
|
+
seriesIdx?: number;
|
|
84
99
|
}
|
|
85
100
|
|
|
86
101
|
|
|
87
|
-
export function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const outlierColor = series.outlierColor ? DG.Color.fromHtml(series.outlierColor) ?
|
|
91
|
-
series.outlierColor : DG.Color.toHtml(DG.Color.red) : DG.Color.toHtml(DG.Color.red);
|
|
92
|
-
const fitLineColor = series.fitLineColor ? DG.Color.fromHtml(series.fitLineColor) ? series.fitLineColor :
|
|
93
|
-
DG.Color.toHtml(DG.Color.getCategoricalColor(seriesIdx)) : DG.Color.toHtml(DG.Color.getCategoricalColor(seriesIdx));
|
|
94
|
-
series.pointColor = pointColor;
|
|
95
|
-
series.outlierColor = outlierColor;
|
|
96
|
-
series.fitLineColor = fitLineColor;
|
|
102
|
+
export function getSeriesColor(series: IFitSeries, seriesIdx: number, colorType: SeriesColorType): string {
|
|
103
|
+
const color = DG.Color.toHtml(colorType === 'outlierColor' ? DG.Color.red : DG.Color.getCategoricalColor(seriesIdx));
|
|
104
|
+
return series[colorType] ? DG.Color.fromHtml(series[colorType]) ? series[colorType] : color : color;
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
export function renderConnectDots(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitRenderOptions): void {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
g.stroke();
|
|
108
|
+
if (series.connectDots ?? false) {
|
|
109
|
+
const viewport = renderOptions.viewport;
|
|
110
|
+
g.strokeStyle = getSeriesColor(series, renderOptions.seriesIdx!, 'pointColor');
|
|
111
|
+
g.lineWidth = 2 * renderOptions.ratio!;
|
|
112
|
+
g.beginPath();
|
|
113
|
+
for (let i = 0; i < series.points.length; i++) {
|
|
114
|
+
const x = series.points[i].x;
|
|
115
|
+
const y = series.points[i].y;
|
|
116
|
+
const screenX = viewport.xToScreen(x);
|
|
117
|
+
const screenY = viewport.yToScreen(y);
|
|
118
|
+
if (i === 0)
|
|
119
|
+
g.moveTo(screenX, screenY);
|
|
120
|
+
else
|
|
121
|
+
g.lineTo(screenX, screenY);
|
|
115
122
|
}
|
|
123
|
+
g.stroke();
|
|
124
|
+
}
|
|
116
125
|
}
|
|
117
126
|
|
|
118
127
|
export function renderPoints(g: CanvasRenderingContext2D, series: IFitSeries, options: FitRenderOptions) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
const screenBounds = options.screenBounds!;
|
|
129
|
+
const showPoints = screenBounds.width < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH ||
|
|
130
|
+
screenBounds.height < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT ? '' : series.showPoints ?? 'points';
|
|
131
|
+
if (showPoints) {
|
|
132
|
+
g.strokeStyle = getSeriesColor(series, options.seriesIdx!, ColorType.POINT);
|
|
133
|
+
if ((series.connectDots && series.showPoints !== '') || series.showPoints === 'points')
|
|
134
|
+
drawPoints(g, series, options);
|
|
135
|
+
else if (['candlesticks', 'both'].includes(series.showPoints!))
|
|
136
|
+
drawCandles(g, series, options);
|
|
137
|
+
}
|
|
126
138
|
}
|
|
127
139
|
|
|
128
140
|
/** Performs points drawing */
|
|
129
141
|
function drawPoints(g: CanvasRenderingContext2D, series: IFitSeries, options: FitRenderOptions): void {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
142
|
+
const ratio = options.ratio!;
|
|
143
|
+
const defaultSize = FitConstants.POINT_PX_SIZE * ratio;
|
|
144
|
+
const viewport = options.viewport;
|
|
145
|
+
const connectDots = series.connectDots;
|
|
146
|
+
const pointColor = getSeriesColor(series, options.seriesIdx!, ColorType.POINT);
|
|
147
|
+
const outlierColor = getSeriesColor(series, options.seriesIdx!, ColorType.OUTLIER);
|
|
148
|
+
|
|
149
|
+
for (let i = 0; i < series.points.length!; i++) {
|
|
150
|
+
const p = series.points[i];
|
|
151
|
+
const xScreen = viewport.xToScreen(p.x);
|
|
152
|
+
const yScreen = viewport.yToScreen(p.y);
|
|
153
|
+
const color = connectDots ? pointColor :
|
|
154
|
+
p.outlier ? (p.outlierColor ? DG.Color.fromHtml(p.outlierColor) ? p.outlierColor : outlierColor : outlierColor) :
|
|
155
|
+
(p.color ? DG.Color.fromHtml(p.color) ? p.color : pointColor : pointColor);
|
|
156
|
+
const marker = p.marker ? p.marker as DG.MARKER_TYPE : series.markerType as DG.MARKER_TYPE;
|
|
157
|
+
const outlierMarker = p.outlierMarker ? p.outlierMarker as DG.MARKER_TYPE : series.outlierMarkerType as DG.MARKER_TYPE;
|
|
158
|
+
const size = !connectDots ? p.outlier ? FitConstants.OUTLIER_PX_SIZE * ratio : p.size ? p.size : defaultSize : defaultSize;
|
|
159
|
+
const markerToDraw = !connectDots ? p.outlier ? outlierMarker : marker : marker;
|
|
160
|
+
|
|
161
|
+
DG.Paint.marker(g, markerToDraw, xScreen, yScreen, color, size);
|
|
162
|
+
if (p.stdev && !p.outlier) {
|
|
163
|
+
g.strokeStyle = color;
|
|
164
|
+
g.beginPath();
|
|
165
|
+
g.moveTo(xScreen, viewport.yToScreen(p.y + p.stdev));
|
|
166
|
+
g.lineTo(xScreen, viewport.yToScreen(p.y - p.stdev));
|
|
167
|
+
g.stroke();
|
|
148
168
|
}
|
|
169
|
+
}
|
|
149
170
|
}
|
|
150
171
|
|
|
151
172
|
/** Performs candles drawing */
|
|
152
173
|
function drawCandles(g: CanvasRenderingContext2D, series: IFitSeries, options: FitRenderOptions) : void {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
candleStart = null;
|
|
174
|
+
const ratio = options.ratio!;
|
|
175
|
+
const viewport = options.viewport;
|
|
176
|
+
const pointColor = getSeriesColor(series, options.seriesIdx!, ColorType.POINT);
|
|
177
|
+
for (let i = 0, candleStart = null; i < series.points.length!; i++) {
|
|
178
|
+
const p = series.points[i];
|
|
179
|
+
if (p.outlier)
|
|
180
|
+
continue;
|
|
181
|
+
const nextSame = i + 1 < series.points.length && series.points[i + 1].x === p.x;
|
|
182
|
+
if (!candleStart && nextSame) { candleStart = i; } else if (candleStart !== null && !nextSame) {
|
|
183
|
+
const values: number[] = [];
|
|
184
|
+
for (let j = candleStart, ind = 0; j <= i; j++, ind++)
|
|
185
|
+
values[ind] = series.points[j].y;
|
|
186
|
+
const boxPlotStats = calculateBoxPlotStatistics(values);
|
|
187
|
+
|
|
188
|
+
g.beginPath();
|
|
189
|
+
drawCandlestick(g, {viewport: viewport, ratio: ratio, x: p.x, boxPlotStats: boxPlotStats, color: pointColor});
|
|
190
|
+
g.stroke();
|
|
191
|
+
|
|
192
|
+
if (series.showPoints === 'both') {
|
|
193
|
+
for (let ind = 0; ind < values.length; ind++) {
|
|
194
|
+
if (values[ind] < boxPlotStats.lowerAdjacentValue || values[ind] > boxPlotStats.upperAdjacentValue) {
|
|
195
|
+
DG.Paint.marker(g, DG.MARKER_TYPE.OUTLIER, viewport.xToScreen(p.x),
|
|
196
|
+
viewport.yToScreen(values[ind]), pointColor, FitConstants.CANDLESTICK_OUTLIER_PX_SIZE * ratio);
|
|
197
|
+
}
|
|
182
198
|
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
candleStart = null;
|
|
183
202
|
}
|
|
203
|
+
}
|
|
184
204
|
}
|
|
185
205
|
|
|
186
206
|
/** Performs candlestick drawing */
|
|
187
207
|
function drawCandlestick(g: CanvasRenderingContext2D, renderOptions: FitPointRenderOptions): void {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
208
|
+
const viewport = renderOptions.viewport;
|
|
209
|
+
const x = renderOptions.x;
|
|
210
|
+
const screenX = viewport.xToScreen(x);
|
|
211
|
+
const boxPlotStats = renderOptions.boxPlotStats;
|
|
212
|
+
|
|
213
|
+
drawCandlestickBorder(g, x, boxPlotStats.lowerAdjacentValue, viewport);
|
|
214
|
+
g.moveTo(screenX, viewport.yToScreen(boxPlotStats.lowerAdjacentValue));
|
|
215
|
+
g.lineTo(screenX, viewport.yToScreen(boxPlotStats.upperAdjacentValue));
|
|
216
|
+
drawCandlestickBorder(g, x, boxPlotStats.upperAdjacentValue, viewport);
|
|
217
|
+
DG.Paint.marker(g, DG.MARKER_TYPE.CIRCLE, screenX, viewport.yToScreen(boxPlotStats.q2), renderOptions.color,
|
|
218
|
+
FitConstants.CANDLESTICK_MEDIAN_PX_SIZE * renderOptions.ratio!);
|
|
195
219
|
}
|
|
196
220
|
|
|
197
221
|
/** Performs candlestick border drawing */
|
|
198
222
|
function drawCandlestickBorder(g: CanvasRenderingContext2D, x: number, adjacentValue: number, transform: Viewport): void {
|
|
199
|
-
|
|
200
|
-
|
|
223
|
+
const xScreen = transform.xToScreen(x);
|
|
224
|
+
const yScreen = transform.yToScreen(adjacentValue);
|
|
225
|
+
g.moveTo(xScreen - (FitConstants.CANDLESTICK_BORDER_PX_SIZE / 2), yScreen);
|
|
226
|
+
g.lineTo(xScreen + (FitConstants.CANDLESTICK_BORDER_PX_SIZE / 2), yScreen);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Gets rendering variables */
|
|
230
|
+
function getRenderingVariables(renderOptions: FitConfidenceIntervalRenderOptions | FitLineRenderOptions) {
|
|
231
|
+
const logX = renderOptions.logOptions.logX;
|
|
232
|
+
const logY = renderOptions.logOptions.logY;
|
|
233
|
+
const screenBounds = renderOptions.screenBounds;
|
|
234
|
+
const axesLeftPxMargin = renderOptions.showAxes ? renderOptions.showAxesLabels ?
|
|
235
|
+
FitConstants.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : FitConstants.AXES_LEFT_PX_MARGIN : 0;
|
|
236
|
+
const axesRightPxMargin = renderOptions.showAxes ? FitConstants.AXES_RIGHT_PX_MARGIN : 0;
|
|
237
|
+
const xMin = screenBounds.x + axesLeftPxMargin;
|
|
238
|
+
const xMax = screenBounds.x + screenBounds.width - axesRightPxMargin;
|
|
239
|
+
const viewport = renderOptions.viewport;
|
|
240
|
+
return {logX, logY, xMin, xMax, viewport};
|
|
201
241
|
}
|
|
202
242
|
|
|
203
243
|
export function renderFitLine(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitLineRenderOptions): void {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (j === axesLeftPxMargin)
|
|
222
|
-
g.moveTo(x, y);
|
|
223
|
-
else
|
|
224
|
-
g.lineTo(x, y);
|
|
225
|
-
}
|
|
226
|
-
g.stroke();
|
|
227
|
-
g.restore();
|
|
244
|
+
if (series.showFitLine ?? true) {
|
|
245
|
+
g.save();
|
|
246
|
+
g.strokeStyle = getSeriesColor(series, renderOptions.seriesIdx!, ColorType.FIT_LINE);
|
|
247
|
+
g.lineWidth = 2 * renderOptions.ratio!;
|
|
248
|
+
g.beginPath();
|
|
249
|
+
if (series.lineStyle)
|
|
250
|
+
g.setLineDash(FitConstants.LINE_STYLES[series.lineStyle]);
|
|
251
|
+
const {logX, logY, xMin, xMax, viewport} = getRenderingVariables(renderOptions);
|
|
252
|
+
const curveFunc = renderOptions.curveFunc!;
|
|
253
|
+
|
|
254
|
+
for (let i = xMin; i <= xMax; i++) {
|
|
255
|
+
const xForY = logX ? Math.log10(viewport.xToWorld(i)) : viewport.xToWorld(i);
|
|
256
|
+
const y = logY ? viewport.yToScreen(Math.pow(10, curveFunc(xForY))) : viewport.yToScreen(curveFunc(xForY));
|
|
257
|
+
if (i === xMin)
|
|
258
|
+
g.moveTo(i, y);
|
|
259
|
+
else
|
|
260
|
+
g.lineTo(i, y);
|
|
228
261
|
}
|
|
262
|
+
g.stroke();
|
|
263
|
+
g.restore();
|
|
264
|
+
}
|
|
229
265
|
}
|
|
230
266
|
|
|
231
267
|
export function renderConfidenceIntervals(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitConfidenceIntervalRenderOptions): void {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
268
|
+
if ((series.showFitLine ?? true) && (series.showCurveConfidenceInterval ?? false)) {
|
|
269
|
+
// TODO: improve confidence intervals colors
|
|
270
|
+
g.strokeStyle = series.confidenceIntervalColor ?? FitConstants.CONFIDENCE_INTERVAL_STROKE_COLOR;
|
|
271
|
+
g.fillStyle = series.confidenceIntervalColor ?? FitConstants.CONFIDENCE_INTERVAL_FILL_COLOR;
|
|
272
|
+
const showAxes = renderOptions.showAxes;
|
|
273
|
+
const showAxesLabels = renderOptions.showAxesLabels;
|
|
274
|
+
const logOptions = renderOptions.logOptions;
|
|
275
|
+
const viewport = renderOptions.viewport;
|
|
276
|
+
const screenBounds = renderOptions.screenBounds;
|
|
277
|
+
const dataPoints = series.dataPoints;
|
|
278
|
+
|
|
279
|
+
const confidenceIntervals = getSeriesConfidenceInterval(series, renderOptions.fitFunc!, renderOptions.userParamsFlag!, dataPoints, logOptions);
|
|
280
|
+
drawConfidenceInterval(g, {viewport: viewport, logOptions: logOptions, showAxes: showAxes, showAxesLabels: showAxesLabels,
|
|
281
|
+
screenBounds: screenBounds, confidenceIntervals: confidenceIntervals, confidenceType: FitConstants.CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP});
|
|
282
|
+
drawConfidenceInterval(g, {viewport: viewport, logOptions: logOptions, showAxes: showAxes, showAxesLabels: showAxesLabels,
|
|
283
|
+
screenBounds: screenBounds, confidenceIntervals: confidenceIntervals, confidenceType: FitConstants.CURVE_CONFIDENCE_INTERVAL_BOUNDS.BOTTOM});
|
|
284
|
+
fillConfidenceInterval(g, {viewport: viewport, logOptions: logOptions, showAxes: showAxes, showAxesLabels: showAxesLabels,
|
|
285
|
+
screenBounds: screenBounds, confidenceIntervals: confidenceIntervals});
|
|
286
|
+
}
|
|
249
287
|
}
|
|
250
288
|
|
|
251
289
|
/** Performs a curve confidence interval drawing */
|
|
252
290
|
function drawConfidenceInterval(g: CanvasRenderingContext2D, renderOptions: FitConfidenceIntervalRenderOptions): void {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const confIntervalFunc = renderOptions.confidenceType === FitConstants.CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP ?
|
|
291
|
+
g.beginPath();
|
|
292
|
+
|
|
293
|
+
const {logX, logY, xMin, xMax, viewport} = getRenderingVariables(renderOptions);
|
|
294
|
+
const confIntervalFunc = renderOptions.confidenceType === FitConstants.CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP ?
|
|
258
295
|
renderOptions.confidenceIntervals!.confidenceTop : renderOptions.confidenceIntervals!.confidenceBottom;
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
g.stroke();
|
|
296
|
+
|
|
297
|
+
for (let i = xMin; i <= xMax; i++) {
|
|
298
|
+
const xForY = logX ? Math.log10(viewport.xToWorld(i)) : viewport.xToWorld(i);
|
|
299
|
+
const y = logY ? viewport.yToScreen(Math.pow(10, confIntervalFunc(xForY))) : viewport.yToScreen(confIntervalFunc(xForY));
|
|
300
|
+
if (i === xMin)
|
|
301
|
+
g.moveTo(i, y);
|
|
302
|
+
else
|
|
303
|
+
g.lineTo(i, y);
|
|
304
|
+
}
|
|
305
|
+
g.stroke();
|
|
270
306
|
}
|
|
271
307
|
|
|
272
308
|
/** Performs a curve confidence interval color filling */
|
|
273
309
|
function fillConfidenceInterval(g: CanvasRenderingContext2D, renderOptions: FitConfidenceIntervalRenderOptions): void {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
Math.pow(10, renderOptions.confidenceIntervals!.confidenceBottom(xForY))) :
|
|
298
|
-
renderOptions.viewport.yToScreen(renderOptions.confidenceIntervals!.confidenceBottom(xForY));
|
|
299
|
-
g.lineTo(x, y);
|
|
300
|
-
}
|
|
301
|
-
g.closePath();
|
|
302
|
-
g.fill();
|
|
310
|
+
g.beginPath();
|
|
311
|
+
|
|
312
|
+
const {logX, logY, xMin, xMax, viewport} = getRenderingVariables(renderOptions);
|
|
313
|
+
const confTop = renderOptions.confidenceIntervals!.confidenceTop;
|
|
314
|
+
const confBottom = renderOptions.confidenceIntervals!.confidenceBottom;
|
|
315
|
+
|
|
316
|
+
for (let i = xMin; i <= xMax; i++) {
|
|
317
|
+
const xForY = logX ? Math.log10(viewport.xToWorld(i)) : viewport.xToWorld(i);
|
|
318
|
+
const y = logY ? viewport.yToScreen(Math.pow(10, confTop(xForY))) : viewport.yToScreen(confTop(xForY));
|
|
319
|
+
if (i === xMin)
|
|
320
|
+
g.moveTo(i, y);
|
|
321
|
+
else
|
|
322
|
+
g.lineTo(i, y);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// reverse traverse to make a shape of confidence interval to fill it
|
|
326
|
+
for (let i = xMax; i >= xMin; i--) {
|
|
327
|
+
const xForY = logX ? Math.log10(viewport.xToWorld(i)) : viewport.xToWorld(i);
|
|
328
|
+
const y = logY ? viewport.yToScreen(Math.pow(10, confBottom(xForY))) : viewport.yToScreen(confBottom(xForY));
|
|
329
|
+
g.lineTo(i, y);
|
|
330
|
+
}
|
|
331
|
+
g.closePath();
|
|
332
|
+
g.fill();
|
|
303
333
|
}
|
|
304
334
|
|
|
305
335
|
export function renderDroplines(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitDroplineRenderOptions): void {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
g.
|
|
336
|
+
if ((series.showFitLine ?? true) && series.droplines && renderOptions.showDroplines!) {
|
|
337
|
+
g.save();
|
|
338
|
+
g.strokeStyle = 'blue';
|
|
339
|
+
g.lineWidth = renderOptions.ratio!;
|
|
340
|
+
g.beginPath();
|
|
341
|
+
g.setLineDash([5, 5]);
|
|
342
|
+
const viewport = renderOptions.viewport;
|
|
343
|
+
const dataBounds = renderOptions.dataBounds;
|
|
344
|
+
const curveFunc = renderOptions.curveFunc;
|
|
345
|
+
const logOptions = renderOptions.logOptions;
|
|
346
|
+
for (let j = 0; j < series.droplines.length; j++) {
|
|
347
|
+
const droplineName = series.droplines[j];
|
|
348
|
+
if (droplineName === 'IC50') {
|
|
349
|
+
drawDropline(g, {viewport: viewport, xValue: series.parameters![2], dataBounds: dataBounds,
|
|
350
|
+
curveFunc: curveFunc, logOptions: logOptions});
|
|
351
|
+
}
|
|
320
352
|
}
|
|
353
|
+
g.stroke();
|
|
354
|
+
g.restore();
|
|
355
|
+
}
|
|
321
356
|
}
|
|
322
357
|
|
|
323
358
|
/** Performs a dropline drawing */
|
|
324
359
|
function drawDropline(g: CanvasRenderingContext2D, renderOptions: FitDroplineRenderOptions): void {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
360
|
+
const logX = renderOptions.logOptions.logX;
|
|
361
|
+
const logY = renderOptions.logOptions.logY;
|
|
362
|
+
const xValue = logX ? Math.pow(10, renderOptions.xValue) : renderOptions.xValue;
|
|
363
|
+
const viewport = renderOptions.viewport;
|
|
364
|
+
const dataBounds = renderOptions.dataBounds;
|
|
365
|
+
|
|
366
|
+
const xForY = logX ? Math.log10(xValue) : xValue;
|
|
367
|
+
const y = logY ? Math.pow(10, renderOptions.curveFunc(xForY)) : renderOptions.curveFunc(xForY);
|
|
368
|
+
const screenX = viewport.xToScreen(xValue);
|
|
369
|
+
const screenY = viewport.yToScreen(y);
|
|
370
|
+
g.moveTo(viewport.xToScreen(dataBounds.minX), screenY);
|
|
371
|
+
g.lineTo(screenX, screenY);
|
|
372
|
+
g.lineTo(screenX, viewport.yToScreen(dataBounds.minY));
|
|
332
373
|
}
|
|
333
374
|
|
|
334
375
|
export function renderStatistics(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitStatisticsRenderOptions): void {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
376
|
+
const screenBounds = renderOptions.screenBounds!;
|
|
377
|
+
const statistics = screenBounds.width < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH ||
|
|
378
|
+
screenBounds.height < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT ? [] : renderOptions.statistics;
|
|
379
|
+
if ((series.showFitLine ?? true) && statistics && statistics.length > 0) {
|
|
380
|
+
const dataBox = renderOptions.dataBox;
|
|
381
|
+
const dataPoints = renderOptions.dataPoints;
|
|
382
|
+
const seriesStatistics = getSeriesStatistics(series, renderOptions.fitFunc, dataPoints, renderOptions.logOptions);
|
|
383
|
+
const color = getSeriesColor(series, renderOptions.seriesIdx!, ColorType.FIT_LINE);
|
|
384
|
+
for (let i = 0; i < statistics.length; i++) {
|
|
385
|
+
const statName = statistics[i];
|
|
386
|
+
const prop = statisticsProperties.find((p) => p.name === statName);
|
|
387
|
+
if (prop) {
|
|
388
|
+
const s = StringUtils.formatNumber(prop.get(seriesStatistics));
|
|
389
|
+
g.fillStyle = color;
|
|
390
|
+
g.textAlign = 'left';
|
|
391
|
+
g.fillText(prop.name + ': ' + s, dataBox.x + 5, dataBox.y + 20 + 20 * i);
|
|
392
|
+
}
|
|
347
393
|
}
|
|
394
|
+
}
|
|
348
395
|
}
|
|
349
396
|
|
|
350
397
|
export function renderTitle(g: CanvasRenderingContext2D, renderOptions: FitTitleRenderOptions): void {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
398
|
+
if (renderOptions.showTitle) {
|
|
399
|
+
g.font = '12px Roboto, "Roboto Local"';
|
|
400
|
+
g.textAlign = 'center';
|
|
401
|
+
g.fillStyle = 'black';
|
|
402
|
+
g.fillText(renderOptions.title!, renderOptions.dataBox.midX - 5, renderOptions.screenBounds.y + 15);
|
|
403
|
+
}
|
|
357
404
|
}
|
|
358
405
|
|
|
359
406
|
export function renderAxesLabels(g: CanvasRenderingContext2D, renderOptions: FitAxesLabelsRenderOptions): void {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
407
|
+
if (renderOptions.showAxesLabels) {
|
|
408
|
+
const screenBounds = renderOptions.screenBounds;
|
|
409
|
+
const dataBox = renderOptions.dataBox;
|
|
410
|
+
g.font = '11px Roboto, "Roboto Local"';
|
|
411
|
+
g.textAlign = 'center';
|
|
412
|
+
g.fillStyle = 'black';
|
|
413
|
+
g.fillText(renderOptions.xAxisName!, dataBox.midX - 5, screenBounds.maxY - FitConstants.X_AXIS_LABEL_BOTTOM_PX_MARGIN);
|
|
414
|
+
g.translate(screenBounds.x, screenBounds.y);
|
|
415
|
+
g.rotate(-Math.PI / 2);
|
|
416
|
+
const axesTopPxMargin = renderOptions.showTitle ? FitConstants.AXES_TOP_PX_MARGIN_WITH_TITLE : FitConstants.AXES_TOP_PX_MARGIN;
|
|
417
|
+
g.fillText(renderOptions.yAxisName!, -(dataBox.height / 2 + axesTopPxMargin + 15), 15);
|
|
418
|
+
g.restore();
|
|
419
|
+
}
|
|
372
420
|
}
|
|
373
421
|
|
|
374
422
|
export function renderLegend(g: CanvasRenderingContext2D, data: IFitChartData, renderOptions: FitLegendRenderOptions): void {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
423
|
+
if (renderOptions.showLegend) {
|
|
424
|
+
const dataBox = renderOptions.dataBox;
|
|
425
|
+
const ratio = renderOptions.ratio;
|
|
426
|
+
g.font = '11px Roboto, "Roboto Local"';
|
|
427
|
+
const columnNames = [...new Set(data.series?.map((series) => series.columnName))]
|
|
428
|
+
.filter((colName) => colName !== null && colName !== undefined);
|
|
429
|
+
let drawnCurvesInLegend = 0;
|
|
430
|
+
for (let i = 0; i < columnNames.length; i++) {
|
|
431
|
+
const colName = columnNames[i];
|
|
432
|
+
if (data.chartOptions?.showColumnLabel)
|
|
433
|
+
renderColumnLabel(g, colName!, {dataBox: dataBox, columnIdx: i, drawnCurvesInLegend});
|
|
434
|
+
|
|
435
|
+
const series = data.series?.filter((series) => series.columnName === colName);
|
|
436
|
+
for (let j = 0; j < series?.length!; j++) {
|
|
437
|
+
const currentSeries = series![j];
|
|
438
|
+
if (currentSeries.name === '' || currentSeries.name === null || currentSeries.name === undefined)
|
|
439
|
+
continue;
|
|
440
|
+
renderLegendSeries(g, currentSeries, {dataBox: dataBox, ratio: ratio,
|
|
441
|
+
columnIdx: i, drawnCurvesInLegend, showColumnLabel: data.chartOptions?.showColumnLabel, seriesIdx: j});
|
|
442
|
+
drawnCurvesInLegend++;
|
|
443
|
+
}
|
|
396
444
|
}
|
|
445
|
+
g.restore();
|
|
446
|
+
}
|
|
397
447
|
}
|
|
398
448
|
|
|
399
449
|
function renderColumnLabel(g: CanvasRenderingContext2D, colName: string, renderOptions: FitLegendColumnlabelSeriesRenderOptions): void {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
450
|
+
const dataBox = renderOptions.dataBox;
|
|
451
|
+
g.beginPath();
|
|
452
|
+
g.fillStyle = 'black';
|
|
453
|
+
const colNameWidth = g.measureText(colName!).width;
|
|
454
|
+
g.fillText(colName!, dataBox.maxX - colNameWidth, dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN +
|
|
404
455
|
(renderOptions.columnIdx * FitConstants.LEGEND_RECORD_PX_HEIGHT + FitConstants.LEGEND_RECORD_PX_HEIGHT * renderOptions.drawnCurvesInLegend));
|
|
405
456
|
}
|
|
406
457
|
|
|
407
458
|
function renderLegendSeries(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitLegendColumnlabelSeriesRenderOptions): void {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
FitConstants.
|
|
430
|
-
|
|
459
|
+
const dataBox = renderOptions.dataBox;
|
|
460
|
+
const columnIdx = renderOptions.columnIdx;
|
|
461
|
+
const ratio = renderOptions.ratio!;
|
|
462
|
+
const showColumnLabel = renderOptions.showColumnLabel;
|
|
463
|
+
const drawnCurvesInLegend = renderOptions.drawnCurvesInLegend;
|
|
464
|
+
const pointColor = getSeriesColor(series, renderOptions.seriesIdx!, ColorType.POINT);
|
|
465
|
+
const fitLineColor = getSeriesColor(series, renderOptions.seriesIdx!, ColorType.FIT_LINE);
|
|
466
|
+
g.beginPath();
|
|
467
|
+
g.strokeStyle = fitLineColor;
|
|
468
|
+
g.lineWidth = 2 * ratio;
|
|
469
|
+
const textWidth = g.measureText(series.name!).width;
|
|
470
|
+
g.moveTo(dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_PX_WIDTH - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,
|
|
471
|
+
dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN - FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN +
|
|
472
|
+
(showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (columnIdx + 1) : 0) +
|
|
473
|
+
FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend);
|
|
474
|
+
g.lineTo(dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,
|
|
475
|
+
dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN - FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN +
|
|
476
|
+
(showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (columnIdx + 1) : 0) +
|
|
477
|
+
FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend);
|
|
478
|
+
const marker = series.markerType ? series.markerType as DG.MARKER_TYPE : DG.MARKER_TYPE.CIRCLE;
|
|
479
|
+
DG.Paint.marker(g, marker, dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN -
|
|
480
|
+
FitConstants.LEGEND_RECORD_LINE_PX_WIDTH / 2, dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN -
|
|
481
|
+
FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN + (showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT *
|
|
482
|
+
(columnIdx + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend,
|
|
483
|
+
pointColor, FitConstants.POINT_PX_SIZE * ratio);
|
|
484
|
+
g.fillStyle = fitLineColor;
|
|
485
|
+
g.fillText(series.name!, dataBox.maxX - textWidth,
|
|
486
|
+
dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN + (showColumnLabel ?
|
|
487
|
+
FitConstants.LEGEND_RECORD_PX_HEIGHT * (columnIdx + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend);
|
|
488
|
+
g.stroke();
|
|
431
489
|
}
|