@datagrok/curves 1.8.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/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/package.json +12 -8
- package/queries/plates-crud.sql +148 -0
- package/src/fit/const.ts +60 -60
- 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 +48 -44
- package/src/fit/fit-renderer.ts +56 -55
- package/src/fit/multi-curve-viewer.ts +38 -18
- package/src/fit/render-utils.ts +315 -315
- package/src/package-api.ts +167 -0
- package/src/package-test.ts +1 -1
- package/src/package.g.ts +133 -3
- package/src/package.ts +198 -299
- package/src/plate/excel-plates.ts +1 -1
- package/src/plate/plate-cell-renderer.ts +20 -12
- package/src/plate/plate-drc-analysis.ts +262 -0
- package/src/plate/plate-reader.ts +5 -5
- package/src/plate/plate-well-validators.ts +41 -0
- package/src/plate/plate-widget.ts +132 -368
- package/src/plate/plate.ts +168 -57
- package/src/plate/plates-folder-preview.ts +63 -0
- package/src/plate/readers/bmg-pherastar-96.ts +7 -7
- package/src/plate/readers/delfia-envision-96-max-rlu.ts +4 -3
- package/src/plate/readers/delfia-envision-by-row.ts +3 -3
- package/src/plate/readers/spectramax.ts +7 -8
- package/src/plate/utils.ts +22 -10
- 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 +93 -92
- package/src/tests/detector-tests.ts +3 -2
- package/src/tests/fit-tests.ts +199 -198
- package/src/tests/plate-tests.ts +6 -7
- package/src/tests/transform-tests.ts +4 -4
- package/test-console-output-1.log +435 -0
- package/test-record-1.mp4 +0 -0
- package/tsconfig.json +1 -1
package/src/fit/render-utils.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
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
|
|
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';
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
export enum ColorType {
|
|
@@ -104,386 +105,385 @@ export function getSeriesColor(series: IFitSeries, seriesIdx: number, colorType:
|
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
export function renderConnectDots(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitRenderOptions): void {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
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);
|
|
123
122
|
}
|
|
123
|
+
g.stroke();
|
|
124
|
+
}
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
export function renderPoints(g: CanvasRenderingContext2D, series: IFitSeries, options: FitRenderOptions) {
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
const screenBounds = options.screenBounds!;
|
|
129
|
+
const showPoints = screenBounds.width < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH ||
|
|
129
130
|
screenBounds.height < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT ? '' : series.showPoints ?? 'points';
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
+
}
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
/** Performs points drawing */
|
|
140
141
|
function drawPoints(g: CanvasRenderingContext2D, series: IFitSeries, options: FitRenderOptions): void {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
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();
|
|
168
168
|
}
|
|
169
|
+
}
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
/** Performs candles drawing */
|
|
172
173
|
function drawCandles(g: CanvasRenderingContext2D, series: IFitSeries, options: FitRenderOptions) : void {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
viewport.yToScreen(values[ind]), pointColor, FitConstants.CANDLESTICK_OUTLIER_PX_SIZE * ratio);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
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
|
+
}
|
|
203
198
|
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
candleStart = null;
|
|
204
202
|
}
|
|
203
|
+
}
|
|
205
204
|
}
|
|
206
205
|
|
|
207
206
|
/** Performs candlestick drawing */
|
|
208
207
|
function drawCandlestick(g: CanvasRenderingContext2D, renderOptions: FitPointRenderOptions): void {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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!);
|
|
220
219
|
}
|
|
221
220
|
|
|
222
221
|
/** Performs candlestick border drawing */
|
|
223
222
|
function drawCandlestickBorder(g: CanvasRenderingContext2D, x: number, adjacentValue: number, transform: Viewport): void {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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);
|
|
228
227
|
}
|
|
229
228
|
|
|
230
229
|
/** Gets rendering variables */
|
|
231
230
|
function getRenderingVariables(renderOptions: FitConfidenceIntervalRenderOptions | FitLineRenderOptions) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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};
|
|
242
241
|
}
|
|
243
242
|
|
|
244
243
|
export function renderFitLine(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitLineRenderOptions): void {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
g.stroke();
|
|
264
|
-
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);
|
|
265
261
|
}
|
|
262
|
+
g.stroke();
|
|
263
|
+
g.restore();
|
|
264
|
+
}
|
|
266
265
|
}
|
|
267
266
|
|
|
268
267
|
export function renderConfidenceIntervals(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitConfidenceIntervalRenderOptions): void {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
+
}
|
|
288
287
|
}
|
|
289
288
|
|
|
290
289
|
/** Performs a curve confidence interval drawing */
|
|
291
290
|
function drawConfidenceInterval(g: CanvasRenderingContext2D, renderOptions: FitConfidenceIntervalRenderOptions): void {
|
|
292
|
-
|
|
291
|
+
g.beginPath();
|
|
293
292
|
|
|
294
|
-
|
|
295
|
-
|
|
293
|
+
const {logX, logY, xMin, xMax, viewport} = getRenderingVariables(renderOptions);
|
|
294
|
+
const confIntervalFunc = renderOptions.confidenceType === FitConstants.CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP ?
|
|
296
295
|
renderOptions.confidenceIntervals!.confidenceTop : renderOptions.confidenceIntervals!.confidenceBottom;
|
|
297
296
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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();
|
|
307
306
|
}
|
|
308
307
|
|
|
309
308
|
/** Performs a curve confidence interval color filling */
|
|
310
309
|
function fillConfidenceInterval(g: CanvasRenderingContext2D, renderOptions: FitConfidenceIntervalRenderOptions): void {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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();
|
|
334
333
|
}
|
|
335
334
|
|
|
336
335
|
export function renderDroplines(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitDroplineRenderOptions): void {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
g.stroke();
|
|
354
|
-
g.restore();
|
|
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
|
+
}
|
|
355
352
|
}
|
|
353
|
+
g.stroke();
|
|
354
|
+
g.restore();
|
|
355
|
+
}
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
/** Performs a dropline drawing */
|
|
359
359
|
function drawDropline(g: CanvasRenderingContext2D, renderOptions: FitDroplineRenderOptions): void {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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));
|
|
373
373
|
}
|
|
374
374
|
|
|
375
375
|
export function renderStatistics(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitStatisticsRenderOptions): void {
|
|
376
|
-
|
|
377
|
-
|
|
376
|
+
const screenBounds = renderOptions.screenBounds!;
|
|
377
|
+
const statistics = screenBounds.width < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH ||
|
|
378
378
|
screenBounds.height < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT ? [] : renderOptions.statistics;
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
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
|
+
}
|
|
394
393
|
}
|
|
394
|
+
}
|
|
395
395
|
}
|
|
396
396
|
|
|
397
397
|
export function renderTitle(g: CanvasRenderingContext2D, renderOptions: FitTitleRenderOptions): void {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
+
}
|
|
404
404
|
}
|
|
405
405
|
|
|
406
406
|
export function renderAxesLabels(g: CanvasRenderingContext2D, renderOptions: FitAxesLabelsRenderOptions): void {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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
|
+
}
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
export function renderLegend(g: CanvasRenderingContext2D, data: IFitChartData, renderOptions: FitLegendRenderOptions): void {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
g.restore();
|
|
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
|
+
}
|
|
446
444
|
}
|
|
445
|
+
g.restore();
|
|
446
|
+
}
|
|
447
447
|
}
|
|
448
448
|
|
|
449
449
|
function renderColumnLabel(g: CanvasRenderingContext2D, colName: string, renderOptions: FitLegendColumnlabelSeriesRenderOptions): void {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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 +
|
|
455
455
|
(renderOptions.columnIdx * FitConstants.LEGEND_RECORD_PX_HEIGHT + FitConstants.LEGEND_RECORD_PX_HEIGHT * renderOptions.drawnCurvesInLegend));
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
function renderLegendSeries(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitLegendColumnlabelSeriesRenderOptions): void {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
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
472
|
(showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (columnIdx + 1) : 0) +
|
|
473
473
|
FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend);
|
|
474
|
-
|
|
475
|
-
|
|
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
476
|
(showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (columnIdx + 1) : 0) +
|
|
477
477
|
FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend);
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN + (showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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
487
|
FitConstants.LEGEND_RECORD_PX_HEIGHT * (columnIdx + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend);
|
|
488
|
-
|
|
488
|
+
g.stroke();
|
|
489
489
|
}
|