@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.
Files changed (58) hide show
  1. package/.eslintrc.json +39 -0
  2. package/.vscode/launch.json +10 -9
  3. package/.vscode/tasks.json +14 -0
  4. package/CHANGELOG.md +33 -0
  5. package/README.md +36 -8
  6. package/databases/plates/0000_init.sql +167 -0
  7. package/detectors.js +2 -2
  8. package/dist/package-test.js +15930 -1
  9. package/dist/package-test.js.map +1 -1
  10. package/dist/package.js +13750 -1
  11. package/dist/package.js.map +1 -1
  12. package/img/plate-dose-response-series.gif +0 -0
  13. package/img/plate-readers.gif +0 -0
  14. package/package.json +17 -11
  15. package/queries/plates-crud.sql +148 -0
  16. package/src/fit/const.ts +60 -59
  17. package/src/fit/data-to-curves.ts +220 -0
  18. package/src/fit/fit-demo.ts +6 -6
  19. package/src/fit/fit-grid-cell-handler.ts +94 -85
  20. package/src/fit/fit-renderer.ts +162 -98
  21. package/src/fit/multi-curve-viewer.ts +69 -28
  22. package/src/fit/render-utils.ts +346 -288
  23. package/src/package-api.ts +167 -0
  24. package/src/package-test.ts +7 -1
  25. package/src/package.g.ts +140 -2
  26. package/src/package.ts +221 -79
  27. package/src/plate/excel-plates.ts +112 -0
  28. package/src/plate/plate-cell-renderer.ts +48 -0
  29. package/src/plate/plate-drc-analysis.ts +262 -0
  30. package/src/plate/plate-reader.ts +28 -0
  31. package/src/plate/plate-well-validators.ts +41 -0
  32. package/src/plate/plate-widget.ts +242 -0
  33. package/src/plate/plate.ts +557 -0
  34. package/src/plate/plates-folder-preview.ts +63 -0
  35. package/src/plate/readers/bmg-pherastar-96.ts +42 -0
  36. package/src/plate/readers/delfia-envision-96-max-rlu.ts +16 -0
  37. package/src/plate/readers/delfia-envision-by-row.ts +18 -0
  38. package/src/plate/readers/spectramax.ts +42 -0
  39. package/src/plate/utils.ts +141 -0
  40. package/src/plates/numeric_matcher.ts +191 -0
  41. package/src/plates/objects/plate-template-handler.ts +48 -0
  42. package/src/plates/plates-app.ts +64 -0
  43. package/src/plates/plates-crud.ts +502 -0
  44. package/src/plates/plates-demo.ts +107 -0
  45. package/src/plates/plates.sql +169 -0
  46. package/src/plates/views/plates-create-view.ts +123 -0
  47. package/src/plates/views/plates-schema-view.ts +58 -0
  48. package/src/plates/views/plates-search-view.ts +137 -0
  49. package/src/plates/views/plates-templates-view.ts +38 -0
  50. package/src/tests/curves-cell-renderer-tests.ts +95 -75
  51. package/src/tests/detector-tests.ts +3 -2
  52. package/src/tests/fit-tests.ts +199 -163
  53. package/src/tests/plate-tests.ts +153 -0
  54. package/src/tests/transform-tests.ts +6 -6
  55. package/test-console-output-1.log +435 -0
  56. package/test-record-1.mp4 +0 -0
  57. package/tsconfig.json +1 -1
  58. package/src/fit/cell-render-viewer.ts +0 -54
@@ -1,25 +1,35 @@
1
+ /* eslint-disable max-len */
1
2
  import * as DG from 'datagrok-api/dg';
2
3
  import {
3
- FitConfidenceIntervals,
4
- FitFunction,
5
- IFitChartData,
6
- IFitSeries,
7
- statisticsProperties
8
- } from "@datagrok-libraries/statistics/src/fit/fit-curve";
4
+ FitConfidenceIntervals,
5
+ FitFunction,
6
+ IFitChartData,
7
+ IFitSeries,
8
+ statisticsProperties
9
+ } from '@datagrok-libraries/statistics/src/fit/fit-curve';
9
10
  import {
10
- getSeriesConfidenceInterval,
11
- getSeriesStatistics,
12
- LogOptions
13
- } from "@datagrok-libraries/statistics/src/fit/fit-data";
14
- import {Viewport} from "@datagrok-libraries/utils/src/transform";
15
- import {FitConstants} from "./const";
16
- import {BoxPlotStatistics, calculateBoxPlotStatistics} from "@datagrok-libraries/statistics/src/box-plot-statistics";
17
- import {StringUtils} from "@datagrok-libraries/utils/src/string-utils";
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 assignSeriesColors(series: IFitSeries, seriesIdx: number): void {
88
- const pointColor = series.pointColor ? DG.Color.fromHtml(series.pointColor) ? series.pointColor :
89
- DG.Color.toHtml(DG.Color.getCategoricalColor(seriesIdx)) : DG.Color.toHtml(DG.Color.getCategoricalColor(seriesIdx));
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
- if (series.connectDots ?? false) {
101
- g.strokeStyle = series.pointColor!;
102
- g.lineWidth = 2 * renderOptions.ratio!;
103
- g.beginPath();
104
- for (let i = 0; i < series.points.length; i++) {
105
- const x = series.points[i].x;
106
- const y = series.points[i].y;
107
- const screenX = renderOptions.viewport.xToScreen(x);
108
- const screenY = renderOptions.viewport.yToScreen(y);
109
- if (i === 0)
110
- g.moveTo(screenX, screenY);
111
- else
112
- g.lineTo(screenX, screenY);
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
- if (series.showPoints ?? 'points') {
120
- g.strokeStyle = series.pointColor!;
121
- if ((series.connectDots && series.showPoints !== '') || series.showPoints === 'points')
122
- drawPoints(g, series, options);
123
- else if (['candlesticks', 'both'].includes(series.showPoints!))
124
- drawCandles(g, series, options);
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
- for (let i = 0; i < series.points.length!; i++) {
131
- const p = series.points[i];
132
- const color = series.connectDots ? series.pointColor! :
133
- p.outlier ? (p.outlierColor ? DG.Color.fromHtml(p.outlierColor) ? p.outlierColor : series.outlierColor! : series.outlierColor!) :
134
- (p.color ? DG.Color.fromHtml(p.color) ? p.color : series.pointColor! : series.pointColor!);
135
- const marker = p.marker ? p.marker as DG.MARKER_TYPE : series.markerType as DG.MARKER_TYPE;
136
- const outlierMarker = p.outlierMarker ? p.outlierMarker as DG.MARKER_TYPE : series.outlierMarkerType as DG.MARKER_TYPE;
137
- const size = !series.connectDots ? p.outlier ? FitConstants.OUTLIER_PX_SIZE * options.ratio! :
138
- p.size ? p.size : FitConstants.POINT_PX_SIZE * options.ratio! : FitConstants.POINT_PX_SIZE * options.ratio!;
139
- DG.Paint.marker(g, !series.connectDots ? p.outlier ? outlierMarker : marker : marker,
140
- options.viewport.xToScreen(p.x), options.viewport.yToScreen(p.y), color, size);
141
- if (p.stdev && !p.outlier) {
142
- g.strokeStyle = color;
143
- g.beginPath();
144
- g.moveTo(options.viewport.xToScreen(p.x), options.viewport.yToScreen(p.y + p.stdev));
145
- g.lineTo(options.viewport.xToScreen(p.x), options.viewport.yToScreen(p.y - p.stdev));
146
- g.stroke();
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
- for (let i = 0, candleStart = null; i < series.points.length!; i++) {
154
- const p = series.points[i];
155
- if (p.outlier)
156
- continue;
157
- const nextSame = i + 1 < series.points.length && series.points[i + 1].x === p.x;
158
- if (!candleStart && nextSame)
159
- candleStart = i;
160
- else if (candleStart !== null && !nextSame) {
161
- const values: number[] = [];
162
- for (let j = candleStart, ind = 0; j <= i; j++, ind++)
163
- values[ind] = series.points[j].y;
164
- const boxPlotStats = calculateBoxPlotStatistics(values);
165
-
166
- g.beginPath();
167
- drawCandlestick(g, {viewport: options.viewport, ratio: options.ratio!, x: p.x,
168
- boxPlotStats: boxPlotStats, color: series.pointColor!});
169
- g.stroke();
170
-
171
- if (series.showPoints === 'both') {
172
- for (let ind = 0; ind < values.length; ind++) {
173
- if (values[ind] < boxPlotStats.lowerAdjacentValue || values[ind] > boxPlotStats.upperAdjacentValue) {
174
- DG.Paint.marker(g, DG.MARKER_TYPE.OUTLIER,
175
- options.viewport.xToScreen(p.x), options.viewport.yToScreen(values[ind]),
176
- series.pointColor!, FitConstants.CANDLESTICK_OUTLIER_PX_SIZE * options.ratio!);
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
- drawCandlestickBorder(g, renderOptions.x, renderOptions.boxPlotStats.lowerAdjacentValue, renderOptions.viewport);
189
- g.moveTo(renderOptions.viewport.xToScreen(renderOptions.x), renderOptions.viewport.yToScreen(renderOptions.boxPlotStats.lowerAdjacentValue));
190
- g.lineTo(renderOptions.viewport.xToScreen(renderOptions.x), renderOptions.viewport.yToScreen(renderOptions.boxPlotStats.upperAdjacentValue));
191
- drawCandlestickBorder(g, renderOptions.x, renderOptions.boxPlotStats.upperAdjacentValue, renderOptions.viewport);
192
- DG.Paint.marker(g, DG.MARKER_TYPE.CIRCLE, renderOptions.viewport.xToScreen(renderOptions.x),
193
- renderOptions.viewport.yToScreen(renderOptions.boxPlotStats.q2), renderOptions.color,
194
- FitConstants.CANDLESTICK_MEDIAN_PX_SIZE * renderOptions.ratio!);
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
- g.moveTo(transform.xToScreen(x) - (FitConstants.CANDLESTICK_BORDER_PX_SIZE / 2), transform.yToScreen(adjacentValue));
200
- g.lineTo(transform.xToScreen(x) + (FitConstants.CANDLESTICK_BORDER_PX_SIZE / 2), transform.yToScreen(adjacentValue));
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
- if (series.showFitLine ?? true) {
205
- g.save();
206
- g.strokeStyle = series.fitLineColor!;
207
- g.lineWidth = 2 * renderOptions.ratio!;
208
- g.beginPath();
209
- if (series.lineStyle)
210
- g.setLineDash(FitConstants.LINE_STYLES[series.lineStyle]);
211
-
212
- const axesLeftPxMargin = renderOptions.showAxes ? renderOptions.showAxesLabels ?
213
- FitConstants.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : FitConstants.AXES_LEFT_PX_MARGIN : 0;
214
- const axesRightPxMargin = renderOptions.showAxes ? FitConstants.AXES_RIGHT_PX_MARGIN : 0;
215
- for (let j = axesLeftPxMargin; j <= renderOptions.screenBounds.width - axesRightPxMargin; j++) {
216
- const x = renderOptions.screenBounds.x + j;
217
- const xForY = renderOptions.logOptions.logX ? Math.log10(renderOptions.viewport.xToWorld(x)) :
218
- renderOptions.viewport.xToWorld(x);
219
- const y = renderOptions.logOptions.logY ? renderOptions.viewport.yToScreen(Math.pow(10, renderOptions.curveFunc!(xForY))) :
220
- renderOptions.viewport.yToScreen(renderOptions.curveFunc!(xForY));
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
- if ((series.showFitLine ?? true) && (series.showCurveConfidenceInterval ?? false)) {
233
- // TODO: improve confidence intervals colors
234
- g.strokeStyle = series.confidenceIntervalColor ?? FitConstants.CONFIDENCE_INTERVAL_STROKE_COLOR;
235
- g.fillStyle = series.confidenceIntervalColor ?? FitConstants.CONFIDENCE_INTERVAL_FILL_COLOR;
236
-
237
- const confidenceIntervals = getSeriesConfidenceInterval(series, renderOptions.fitFunc!,
238
- renderOptions.userParamsFlag!, renderOptions.logOptions);
239
- drawConfidenceInterval(g, {viewport: renderOptions.viewport, logOptions: renderOptions.logOptions,
240
- showAxes: renderOptions.showAxes, showAxesLabels: renderOptions.showAxesLabels, screenBounds: renderOptions.screenBounds,
241
- confidenceIntervals: confidenceIntervals, confidenceType: FitConstants.CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP});
242
- drawConfidenceInterval(g, {viewport: renderOptions.viewport, logOptions: renderOptions.logOptions,
243
- showAxes: renderOptions.showAxes, showAxesLabels: renderOptions.showAxesLabels, screenBounds: renderOptions.screenBounds,
244
- confidenceIntervals: confidenceIntervals, confidenceType: FitConstants.CURVE_CONFIDENCE_INTERVAL_BOUNDS.BOTTOM});
245
- fillConfidenceInterval(g, {viewport: renderOptions.viewport, logOptions: renderOptions.logOptions,
246
- showAxes: renderOptions.showAxes, showAxesLabels: renderOptions.showAxesLabels, screenBounds: renderOptions.screenBounds,
247
- confidenceIntervals: confidenceIntervals});
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
- g.beginPath();
254
- const axesLeftPxMargin = renderOptions.showAxes ? renderOptions.showAxesLabels ?
255
- FitConstants.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : FitConstants.AXES_LEFT_PX_MARGIN : 0;
256
- const axesRightPxMargin = renderOptions.showAxes ? FitConstants.AXES_RIGHT_PX_MARGIN : 0;
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
- for (let i = axesLeftPxMargin; i <= renderOptions.screenBounds.width - axesRightPxMargin; i++) {
260
- const x = renderOptions.screenBounds.x + i;
261
- const xForY = renderOptions.logOptions.logX ? Math.log10(renderOptions.viewport.xToWorld(x)) : renderOptions.viewport.xToWorld(x);
262
- const y = renderOptions.logOptions.logY ? renderOptions.viewport.yToScreen(Math.pow(10, confIntervalFunc(xForY))) :
263
- renderOptions.viewport.yToScreen(confIntervalFunc(xForY));
264
- if (i === axesLeftPxMargin)
265
- g.moveTo(x, y);
266
- else
267
- g.lineTo(x, y);
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
- g.beginPath();
275
- const axesLeftPxMargin = renderOptions.showAxes ? renderOptions.showAxesLabels ?
276
- FitConstants.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : FitConstants.AXES_LEFT_PX_MARGIN : 0;
277
- const axesRightPxMargin = renderOptions.showAxes ? FitConstants.AXES_RIGHT_PX_MARGIN : 0;
278
- for (let i = axesLeftPxMargin; i <= renderOptions.screenBounds.width - axesRightPxMargin; i++) {
279
- const x = renderOptions.screenBounds.x + i;
280
- const xForY = renderOptions.logOptions.logX ? Math.log10(renderOptions.viewport.xToWorld(x)) :
281
- renderOptions.viewport.xToWorld(x);
282
- const y = renderOptions.logOptions.logY ? renderOptions.viewport.yToScreen(
283
- Math.pow(10, renderOptions.confidenceIntervals!.confidenceTop(xForY))) :
284
- renderOptions.viewport.yToScreen(renderOptions.confidenceIntervals!.confidenceTop(xForY));
285
- if (i === axesLeftPxMargin)
286
- g.moveTo(x, y);
287
- else
288
- g.lineTo(x, y);
289
- }
290
-
291
- // reverse traverse to make a shape of confidence interval to fill it
292
- for (let i = renderOptions.screenBounds.width - axesRightPxMargin; i >= axesLeftPxMargin; i--) {
293
- const x = renderOptions.screenBounds.x + i;
294
- const xForY = renderOptions.logOptions.logX ? Math.log10(renderOptions.viewport.xToWorld(x)) :
295
- renderOptions.viewport.xToWorld(x);
296
- const y = renderOptions.logOptions.logY ? renderOptions.viewport.yToScreen(
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
- if ((series.showFitLine ?? true) && series.droplines && renderOptions.showDroplines!) {
307
- g.save();
308
- g.strokeStyle = 'blue';
309
- g.lineWidth = renderOptions.ratio!;
310
- g.beginPath();
311
- g.setLineDash([5, 5]);
312
- for (let j = 0; j < series.droplines.length; j++) {
313
- const droplineName = series.droplines[j];
314
- if (droplineName === 'IC50')
315
- drawDropline(g, {viewport: renderOptions.viewport, xValue: series.parameters![2],
316
- dataBounds: renderOptions.dataBounds, curveFunc: renderOptions.curveFunc, logOptions: renderOptions.logOptions});
317
- }
318
- g.stroke();
319
- 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
+ }
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
- if (renderOptions.logOptions.logX)
326
- renderOptions.xValue = Math.pow(10, renderOptions.xValue);
327
- const xForY = renderOptions.logOptions.logX ? Math.log10(renderOptions.xValue) : renderOptions.xValue;
328
- const y = renderOptions.logOptions.logY ? Math.pow(10, renderOptions.curveFunc(xForY)) : renderOptions.curveFunc(xForY);
329
- g.moveTo(renderOptions.viewport.xToScreen(renderOptions.dataBounds.minX), renderOptions.viewport.yToScreen(y));
330
- g.lineTo(renderOptions.viewport.xToScreen(renderOptions.xValue), renderOptions.viewport.yToScreen(y));
331
- g.lineTo(renderOptions.viewport.xToScreen(renderOptions.xValue), renderOptions.viewport.yToScreen(renderOptions.dataBounds.minY));
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
- if ((series.showFitLine ?? true) && renderOptions.statistics) {
336
- const statistics = getSeriesStatistics(series, renderOptions.fitFunc, renderOptions.logOptions);
337
- for (let i = 0; i < renderOptions.statistics.length; i++) {
338
- const statName = renderOptions.statistics[i];
339
- const prop = statisticsProperties.find((p) => p.name === statName);
340
- if (prop) {
341
- const s = StringUtils.formatNumber(prop.get(statistics));
342
- g.fillStyle = series.fitLineColor!;
343
- g.textAlign = 'left';
344
- g.fillText(prop.name + ': ' + s, renderOptions.dataBox.x + 5, renderOptions.dataBox.y + 20 + 20 * i);
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
- if (renderOptions.showTitle) {
352
- g.font = '12px Roboto, "Roboto Local"';
353
- g.textAlign = 'center';
354
- g.fillStyle = 'black';
355
- g.fillText(renderOptions.title!, renderOptions.dataBox.midX - 5, renderOptions.screenBounds.y + 15);
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
- if (renderOptions.showAxesLabels) {
361
- g.font = '11px Roboto, "Roboto Local"';
362
- g.textAlign = 'center';
363
- g.fillStyle = 'black';
364
- g.fillText(renderOptions.xAxisName!, renderOptions.dataBox.midX - 5,
365
- renderOptions.screenBounds.maxY - FitConstants.X_AXIS_LABEL_BOTTOM_PX_MARGIN);
366
- g.translate(renderOptions.screenBounds.x, renderOptions.screenBounds.y);
367
- g.rotate(-Math.PI / 2);
368
- const axesTopPxMargin = renderOptions.showTitle ? FitConstants.AXES_TOP_PX_MARGIN_WITH_TITLE : FitConstants.AXES_TOP_PX_MARGIN;
369
- g.fillText(renderOptions.yAxisName!, -(renderOptions.dataBox.height / 2 + axesTopPxMargin + 15), 15);
370
- g.restore();
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
- if (renderOptions.showLegend) {
376
- g.font = '11px Roboto, "Roboto Local"';
377
- const columnNames = [...new Set(data.series?.map((series) => series.columnName))]
378
- .filter((colName) => colName !== null && colName !== undefined);
379
- let drawnCurvesInLegend = 0;
380
- for (let i = 0; i < columnNames.length; i++) {
381
- const colName = columnNames[i];
382
- if (data.chartOptions?.showColumnLabel)
383
- renderColumnLabel(g, colName!, {dataBox: renderOptions.dataBox, columnIdx: i, drawnCurvesInLegend});
384
-
385
- const series = data.series?.filter((series) => series.columnName === colName);
386
- for (let j = 0; j < series?.length!; j++) {
387
- const currentSeries = series![j];
388
- if (currentSeries.name === '' || currentSeries.name === null || currentSeries.name === undefined)
389
- continue;
390
- renderLegendSeries(g, currentSeries, {dataBox: renderOptions.dataBox, ratio: renderOptions.ratio,
391
- columnIdx: i, drawnCurvesInLegend, showColumnLabel: data.chartOptions?.showColumnLabel});
392
- drawnCurvesInLegend++;
393
- }
394
- }
395
- 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
+ }
396
444
  }
445
+ g.restore();
446
+ }
397
447
  }
398
448
 
399
449
  function renderColumnLabel(g: CanvasRenderingContext2D, colName: string, renderOptions: FitLegendColumnlabelSeriesRenderOptions): void {
400
- g.beginPath();
401
- g.fillStyle = 'black';
402
- const colNameWidth = g.measureText(colName!).width;
403
- g.fillText(colName!, renderOptions.dataBox.maxX - colNameWidth, renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN +
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
- g.beginPath();
409
- g.strokeStyle = series.fitLineColor!;
410
- g.lineWidth = 2 * renderOptions.ratio!;
411
- const textWidth = g.measureText(series.name!).width;
412
- g.moveTo(renderOptions.dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_PX_WIDTH - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,
413
- renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN - FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN +
414
- (renderOptions.showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (renderOptions.columnIdx + 1) : 0) +
415
- FitConstants.LEGEND_RECORD_PX_HEIGHT * renderOptions.drawnCurvesInLegend);
416
- g.lineTo(renderOptions.dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,
417
- renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN - FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN +
418
- (renderOptions.showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (renderOptions.columnIdx + 1) : 0) +
419
- FitConstants.LEGEND_RECORD_PX_HEIGHT * renderOptions.drawnCurvesInLegend);
420
- const marker = series.markerType ? series.markerType as DG.MARKER_TYPE : DG.MARKER_TYPE.CIRCLE;
421
- DG.Paint.marker(g, marker, renderOptions.dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN
422
- - FitConstants.LEGEND_RECORD_LINE_PX_WIDTH / 2, renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN -
423
- FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN + (renderOptions.showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT
424
- * (renderOptions.columnIdx + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * renderOptions.drawnCurvesInLegend,
425
- series.pointColor!, FitConstants.POINT_PX_SIZE * renderOptions.ratio!);
426
- g.fillStyle = series.fitLineColor!;
427
- g.fillText(series.name!, renderOptions.dataBox.maxX - textWidth,
428
- renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN + (renderOptions.showColumnLabel ?
429
- FitConstants.LEGEND_RECORD_PX_HEIGHT * (renderOptions.columnIdx + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * renderOptions.drawnCurvesInLegend);
430
- g.stroke();
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
  }