@datagrok/curves 1.3.1 → 1.4.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/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@datagrok/curves",
3
3
  "friendlyName": "Curves",
4
- "version": "1.3.1",
4
+ "version": "1.4.0",
5
5
  "description": "Curves provides support for fitted curves (such as dose-response curves), including in-grid rendering, storing charts in cells, interactivity, and automatic fitting.",
6
6
  "author": {
7
7
  "name": "Dmytro Kovalyov",
8
8
  "email": "dkovalyov@datagrok.ai"
9
9
  },
10
10
  "dependencies": {
11
- "@datagrok-libraries/statistics": "^1.2.13",
11
+ "@datagrok-libraries/statistics": "^1.3.0",
12
12
  "@datagrok-libraries/utils": "^4.1.45",
13
13
  "@types/wu": "^2.1.42",
14
14
  "cash-dom": "^8.0.0",
package/src/fit/const.ts CHANGED
@@ -1,80 +1,48 @@
1
1
  import {IFitSeries} from '@datagrok-libraries/statistics/src/fit/fit-curve';
2
2
 
3
3
  export class FitConstants {
4
- static CELL_DEFAULT_WIDTH = 230;
5
-
6
- static CELL_DEFAULT_HEIGHT = 160;
7
-
8
4
  static TAG_FIT_CHART_FORMAT = '.fitChartFormat';
9
-
10
5
  static TAG_FIT_CHART_FORMAT_3DX = '3dx';
6
+ static FIT_SEM_TYPE = 'fit';
7
+ static FIT_CELL_TYPE = 'fit';
8
+ static TAG_FIT = '.fit';
11
9
 
10
+ static CELL_DEFAULT_WIDTH = 230;
11
+ static CELL_DEFAULT_HEIGHT = 160;
12
12
  static MIN_CELL_RENDERER_PX_WIDTH = 20;
13
-
14
13
  static MIN_CELL_RENDERER_PX_HEIGHT = 10;
15
-
16
14
  static MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH = 70;
17
-
18
15
  static MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT = 45;
19
-
20
- static OUTLIER_PX_SIZE = 12;
21
-
22
- static POINT_PX_SIZE = 4;
23
-
24
- static OUTLIER_HITBOX_RADIUS = 2;
25
-
26
16
  static MIN_AXES_CELL_PX_WIDTH = 100;
27
-
28
17
  static MIN_AXES_CELL_PX_HEIGHT = 55;
29
-
30
18
  static MIN_TITLE_PX_WIDTH = 275;
31
-
32
19
  static MIN_TITLE_PX_HEIGHT = 225;
33
-
34
20
  static MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH = 180;
35
-
36
21
  static MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT = 140;
37
-
38
22
  static MIN_LEGEND_PX_WIDTH = 325;
39
-
40
23
  static MIN_LEGEND_PX_HEIGHT = 275;
41
-
42
24
  static MIN_DROPLINES_VISIBILITY_PX_WIDTH = 120;
43
-
44
25
  static MIN_DROPLINES_VISIBILITY_PX_HEIGHT = 110;
45
-
46
26
  static AXES_LEFT_PX_MARGIN = 38;
47
-
48
27
  static AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS = 45;
49
-
50
28
  static AXES_TOP_PX_MARGIN = 5;
51
-
52
29
  static AXES_TOP_PX_MARGIN_WITH_TITLE = 25;
53
-
54
30
  static AXES_RIGHT_PX_MARGIN = 18;
55
-
56
31
  static AXES_BOTTOM_PX_MARGIN = 15;
57
-
58
32
  static AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS = 30;
59
-
60
33
  static X_AXIS_LABEL_BOTTOM_PX_MARGIN = 4;
34
+ static LEGEND_TOP_PX_MARGIN = 10;
61
35
 
36
+ static OUTLIER_PX_SIZE = 12;
37
+ static POINT_PX_SIZE = 4;
38
+ static OUTLIER_HITBOX_RADIUS = 2;
62
39
  static CANDLESTICK_BORDER_PX_SIZE = 4;
63
-
64
40
  static CANDLESTICK_MEDIAN_PX_SIZE = 3.5;
65
-
66
41
  static CANDLESTICK_OUTLIER_PX_SIZE = 6;
67
-
68
42
  static INFLATE_SIZE = -12 / 2;
69
-
70
- static LEGEND_TOP_PX_MARGIN = 10;
71
-
72
43
  static LEGEND_RECORD_PX_HEIGHT = 18;
73
-
74
44
  static LEGEND_RECORD_LINE_PX_WIDTH = 20;
75
-
76
45
  static LEGEND_RECORD_LINE_RIGHT_PX_MARGIN = 5;
77
-
78
46
  static LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN = 4;
79
47
 
80
48
  static LINE_STYLES: {[key: string]: number[]} = {
@@ -84,6 +52,14 @@ export class FitConstants {
84
52
  'dashdotted': [5, 5, 2, 5],
85
53
  };
86
54
 
55
+ static CURVE_CONFIDENCE_INTERVAL_BOUNDS = {
56
+ TOP: 'top',
57
+ BOTTOM: 'bottom',
58
+ };
59
+
60
+ static CONFIDENCE_INTERVAL_STROKE_COLOR = 'rgba(255,191,63,0.4)';
61
+ static CONFIDENCE_INTERVAL_FILL_COLOR = 'rgba(255,238,204,0.3)';
62
+
87
63
  static CONDITION_MAP: {[key: string]: ((series?: IFitSeries[]) => boolean)} = {
88
64
  'No series to show': (series) => series === undefined || series?.length === 0,
89
65
  'There were series with no points': (series) =>
@@ -4,9 +4,10 @@ import * as DG from 'datagrok-api/dg';
4
4
  import * as grok from 'datagrok-api/grok';
5
5
 
6
6
  import {_package} from '../package';
7
- import {IFitChartData, FIT_SEM_TYPE, sigmoid} from '@datagrok-libraries/statistics/src/fit/fit-curve';
7
+ import {IFitChartData, sigmoid} from '@datagrok-libraries/statistics/src/fit/fit-curve';
8
8
 
9
9
  import wu from 'wu';
10
+ import {FitConstants} from "./const";
10
11
 
11
12
  /** Returns random number from the interval */
12
13
  function rnd(min: number, max: number): number {
@@ -26,7 +27,9 @@ export function createSigmoidPoints(length: number, step: number, pointsPerX: nu
26
27
  for (let num = start, i = 0; num <= end; num += step, i++) {
27
28
  for (let j = 0; j < pointsPerX; j++) {
28
29
  x[i * pointsPerX + j] = num - start + 0.1;
29
- y[i * pointsPerX + j] = sigmoid(params, num);
30
+ const floatParams = new Float32Array(4);
31
+ floatParams.set(params);
32
+ y[i * pointsPerX + j] = sigmoid(floatParams, num);
30
33
  }
31
34
  }
32
35
 
@@ -61,7 +64,7 @@ export function createDemoDataFrame(rowCount: number, chartsCount: number, chart
61
64
  const pointsPerX = colIdx === 3 ? 5 : 1;
62
65
 
63
66
  const jsonColumn = df.columns.addNewString(`json chart ${colIdx}`); // charts as json
64
- jsonColumn.semType = FIT_SEM_TYPE;
67
+ jsonColumn.semType = FitConstants.FIT_SEM_TYPE;
65
68
  let charts = colIdx % 2 === 0 ? chartsPerCell : 1;
66
69
 
67
70
  for (let i = 0; i < rowCount; i++) {
@@ -3,15 +3,20 @@ import * as ui from 'datagrok-api/ui';
3
3
 
4
4
  import {
5
5
  fitSeries,
6
- getColumnChartOptions,
7
6
  getSeriesStatistics,
8
7
  getSeriesFitFunction,
9
- getDataFrameChartOptions,
10
8
  LogOptions,
11
9
  getChartBounds,
12
10
  } from '@datagrok-libraries/statistics/src/fit/fit-data';
13
- import {statisticsProperties, fitSeriesProperties, fitChartDataProperties, FIT_CELL_TYPE, TAG_FIT, IFitChartData, IFitSeries, IFitChartOptions, FIT_SEM_TYPE, IFitSeriesOptions, FitStatistics} from '@datagrok-libraries/statistics/src/fit/fit-curve';
14
- import {getChartData, isColorValid, mergeProperties, substituteZeroes} from './fit-renderer';
11
+ import {statisticsProperties, fitSeriesProperties, fitChartDataProperties, IFitChartData, IFitSeries, IFitChartOptions, IFitSeriesOptions, FitStatistics} from '@datagrok-libraries/statistics/src/fit/fit-curve';
12
+ import {
13
+ getChartData,
14
+ getColumnChartOptions,
15
+ getDataFrameChartOptions,
16
+ isColorValid,
17
+ mergeProperties,
18
+ substituteZeroes
19
+ } from './fit-renderer';
15
20
  import {CellRenderViewer} from './cell-render-viewer';
16
21
  import {convertXMLToIFitChartData} from './fit-parser';
17
22
  import {FitConstants} from './const';
@@ -51,8 +56,10 @@ export function calculateSeriesStats(series: IFitSeries, chartLogOptions: LogOpt
51
56
  if (series.parameters[2] > 0)
52
57
  series.parameters[2] = Math.log10(series.parameters[2]);
53
58
  }
54
- else
55
- series.parameters = fitSeries(series, fitFunction, chartLogOptions).parameters;
59
+ else {
60
+ const params = fitSeries(series, fitFunction, chartLogOptions).parameters;
61
+ series.parameters = [...params];
62
+ }
56
63
 
57
64
  const seriesStatistics = getSeriesStatistics(series, fitFunction, chartLogOptions);
58
65
  return seriesStatistics;
@@ -68,22 +75,29 @@ export function getChartDataAggrStats(chartData: IFitChartData, aggrType: string
68
75
  const seriesStats = calculateSeriesStats(chartData.series![i], chartLogOptions);
69
76
  rSquaredValues[j] = seriesStats.rSquared!;
70
77
  aucValues[j] = seriesStats.auc!;
71
- interceptXValues[j] = seriesStats.interceptX;
72
- interceptYValues[j] = seriesStats.interceptY;
73
- slopeValues[j] = seriesStats.slope;
78
+ interceptXValues[j] = seriesStats.interceptX!;
79
+ interceptYValues[j] = seriesStats.interceptY!;
80
+ slopeValues[j] = seriesStats.slope!;
74
81
  topValues[j] = seriesStats.top!;
75
82
  bottomValues[j] = seriesStats.bottom!;
76
83
  j++;
77
84
  }
78
85
 
79
86
  return {
80
- rSquared: DG.Stats.fromValues(rSquaredValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number,
81
- auc: DG.Stats.fromValues(aucValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number,
82
- interceptX: DG.Stats.fromValues(interceptXValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number,
83
- interceptY: DG.Stats.fromValues(interceptYValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number,
84
- slope: DG.Stats.fromValues(slopeValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number,
85
- top: DG.Stats.fromValues(topValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number,
86
- bottom: DG.Stats.fromValues(bottomValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number
87
+ rSquared: rSquaredValues.some((elem) => elem === undefined || elem === null) ? undefined:
88
+ DG.Stats.fromValues(rSquaredValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number,
89
+ auc: aucValues.some((elem) => elem === undefined || elem === null) ? undefined :
90
+ DG.Stats.fromValues(aucValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number,
91
+ interceptX: interceptXValues.some((elem) => elem === undefined || elem === null) ? undefined :
92
+ DG.Stats.fromValues(interceptXValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number,
93
+ interceptY: interceptYValues.some((elem) => elem === undefined || elem === null) ? undefined :
94
+ DG.Stats.fromValues(interceptYValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number,
95
+ slope: slopeValues.some((elem) => elem === undefined || elem === null) ? undefined :
96
+ DG.Stats.fromValues(slopeValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number,
97
+ top: topValues.some((elem) => elem === undefined || elem === null) ? undefined :
98
+ DG.Stats.fromValues(topValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number,
99
+ bottom: bottomValues.some((elem) => elem === undefined || elem === null) ? undefined :
100
+ DG.Stats.fromValues(bottomValues)[AGGREGATION_TYPES[aggrType] as keyof DG.Stats] as number
87
101
  };
88
102
  }
89
103
 
@@ -111,7 +125,7 @@ function convertJnJColumnToJSON(column: DG.Column): void {
111
125
  }
112
126
 
113
127
  function detectSettings(df: DG.DataFrame): void {
114
- const fitColumns = df.columns.bySemTypeAll(FIT_SEM_TYPE);
128
+ const fitColumns = df.columns.bySemTypeAll(FitConstants.FIT_SEM_TYPE);
115
129
  for (let i = 0; i < fitColumns.length; i++) {
116
130
  fitChartDataProperties.map((prop) => {
117
131
  fitColumns[i].temp[`${CHART_OPTIONS}-custom-${prop.name}`] = false;
@@ -164,11 +178,11 @@ function changeCurvesOptions(gridCell: DG.GridCell, inputBase: DG.InputBase, opt
164
178
  else {
165
179
  let columns: DG.Column[];
166
180
  if (manipulationLevel === MANIPULATION_LEVEL.DATAFRAME) {
167
- gridCell.cell.dataFrame.tags[TAG_FIT] = JSON.stringify(chartOptions);
168
- columns = gridCell.cell.dataFrame.columns.bySemTypeAll(FIT_SEM_TYPE);
181
+ gridCell.cell.dataFrame.tags[FitConstants.TAG_FIT] = JSON.stringify(chartOptions);
182
+ columns = gridCell.cell.dataFrame.columns.bySemTypeAll(FitConstants.FIT_SEM_TYPE);
169
183
  }
170
184
  else {
171
- gridCell.cell.column.tags[TAG_FIT] = JSON.stringify(chartOptions);
185
+ gridCell.cell.column.tags[FitConstants.TAG_FIT] = JSON.stringify(chartOptions);
172
186
  columns = [gridCell.cell.column];
173
187
  }
174
188
 
@@ -177,7 +191,7 @@ function changeCurvesOptions(gridCell: DG.GridCell, inputBase: DG.InputBase, opt
177
191
  const columnChartOptions = getColumnChartOptions(columns[i]);
178
192
  options === CHART_OPTIONS ? delete columnChartOptions.chartOptions![propertyName as keyof IFitChartOptions] :
179
193
  delete columnChartOptions.seriesOptions![propertyName as keyof IFitSeriesOptions];
180
- columns[i].tags[TAG_FIT] = JSON.stringify(columnChartOptions);
194
+ columns[i].tags[FitConstants.TAG_FIT] = JSON.stringify(columnChartOptions);
181
195
  }
182
196
  if (columns[i].temp[`${options}-custom-${propertyName}`] === false) continue;
183
197
 
@@ -218,7 +232,7 @@ export class FitGridCellHandler extends DG.ObjectHandler {
218
232
  }
219
233
 
220
234
  isApplicable(x: any): boolean {
221
- return x instanceof DG.GridCell && x.cellType === FIT_CELL_TYPE;
235
+ return x instanceof DG.GridCell && x.cellType === FitConstants.FIT_CELL_TYPE;
222
236
  }
223
237
 
224
238
  // TODO: add aspect ratio for the cell
@@ -4,7 +4,6 @@ import * as ui from 'datagrok-api/ui';
4
4
 
5
5
  import {
6
6
  IFitChartData,
7
- FIT_CELL_TYPE,
8
7
  IFitSeries,
9
8
  FitStatistics,
10
9
  fitChartDataProperties,
@@ -18,9 +17,7 @@ import {
18
17
  getChartBounds,
19
18
  getSeriesFitFunction,
20
19
  getCurve,
21
- getColumnChartOptions,
22
20
  LogOptions,
23
- getDataFrameChartOptions
24
21
  } from '@datagrok-libraries/statistics/src/fit/fit-data';
25
22
 
26
23
  import {convertXMLToIFitChartData} from './fit-parser';
@@ -160,6 +157,7 @@ export function getChartData(gridCell: DG.GridCell): IFitChartData {
160
157
  mergeProperties(fitChartDataProperties, columnChartOptions.chartOptions, cellChartData.chartOptions);
161
158
  mergeProperties(fitChartDataProperties, dfChartOptions.chartOptions, cellChartData.chartOptions);
162
159
  for (const series of cellChartData.series) {
160
+ mergeProperties(fitSeriesProperties, cellChartData.seriesOptions, series);
163
161
  mergeProperties(fitSeriesProperties, columnChartOptions.seriesOptions, series);
164
162
  mergeProperties(fitSeriesProperties, dfChartOptions.seriesOptions, series);
165
163
  }
@@ -167,6 +165,16 @@ export function getChartData(gridCell: DG.GridCell): IFitChartData {
167
165
  return cellChartData;
168
166
  }
169
167
 
168
+ /** Returns existing, or creates new dataframe default chart options. */
169
+ export function getDataFrameChartOptions(df: DG.DataFrame): IFitChartData {
170
+ return JSON.parse(df.tags[FitConstants.TAG_FIT] ??= JSON.stringify(createDefaultChartData()));
171
+ }
172
+
173
+ /** Returns existing, or creates new column default chart options. */
174
+ export function getColumnChartOptions(column: DG.Column): IFitChartData {
175
+ return JSON.parse(column.tags[FitConstants.TAG_FIT] ??= JSON.stringify(createDefaultChartData()));
176
+ }
177
+
170
178
  /** Performs a chart layout, returning [viewport, xAxis, yAxis] */
171
179
  export function layoutChart(rect: DG.Rect, showAxesLabels: boolean, showTitle: boolean): [DG.Rect, DG.Rect?, DG.Rect?] {
172
180
  if (rect.width < FitConstants.MIN_AXES_CELL_PX_WIDTH || rect.height < FitConstants.MIN_AXES_CELL_PX_HEIGHT)
@@ -217,9 +225,9 @@ export function substituteZeroes(data: IFitChartData): void {
217
225
  }
218
226
 
219
227
  export class FitChartCellRenderer extends DG.GridCellRenderer {
220
- get name() { return FIT_CELL_TYPE; }
228
+ get name() { return FitConstants.FIT_CELL_TYPE; }
221
229
 
222
- get cellType() { return FIT_CELL_TYPE; }
230
+ get cellType() { return FitConstants.FIT_CELL_TYPE; }
223
231
 
224
232
  getDefaultSize(gridColumn: DG.GridColumn): {width?: number | null, height?: number | null} {
225
233
  return {width: FitConstants.CELL_DEFAULT_WIDTH, height: FitConstants.CELL_DEFAULT_HEIGHT};
@@ -382,7 +390,8 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
382
390
  else {
383
391
  const fitResult = fitSeries(series, fitFunc, chartLogOptions);
384
392
  curve = fitResult.fittedCurve;
385
- series.parameters = fitResult.parameters;
393
+ const params = [...fitResult.parameters]
394
+ series.parameters = params;
386
395
  userParamsFlag = false;
387
396
  }
388
397
  }
@@ -4,7 +4,7 @@ import * as ui from 'datagrok-api/ui';
4
4
  import {CellRenderViewer} from './cell-render-viewer';
5
5
  import {FitChartCellRenderer, mergeChartOptions, mergeSeries} from './fit-renderer';
6
6
  import {getChartData, mergeProperties} from './fit-renderer';
7
- import {FIT_SEM_TYPE, FitChartData, fitChartDataProperties, IFitChartData, IFitChartOptions} from '@datagrok-libraries/statistics/src/fit/fit-curve';
7
+ import {FitChartData, fitChartDataProperties, IFitChartData, IFitChartOptions} from '@datagrok-libraries/statistics/src/fit/fit-curve';
8
8
 
9
9
  import {debounce} from 'rxjs/operators';
10
10
  import {interval, merge} from 'rxjs';
@@ -31,7 +31,7 @@ export class MultiCurveViewer extends CellRenderViewer<FitChartCellRenderer> {
31
31
  constructor() {
32
32
  super(new FitChartCellRenderer());
33
33
 
34
- this.curvesColumnNames = this.addProperty('curvesColumnNames', DG.TYPE.COLUMN_LIST, [], {semType: FIT_SEM_TYPE});
34
+ this.curvesColumnNames = this.addProperty('curvesColumnNames', DG.TYPE.COLUMN_LIST, [], {semType: FitConstants.FIT_SEM_TYPE});
35
35
 
36
36
  this.showSelectedRowsCurves = this.bool('showSelectedRowsCurves', false, { description: 'Adds curves from the selected rows'});
37
37
  this.showCurrentRowCurve = this.bool('showCurrentRowCurve', true);
@@ -143,7 +143,7 @@ export class MultiCurveViewer extends CellRenderViewer<FitChartCellRenderer> {
143
143
 
144
144
  onTableAttached(): void {
145
145
  const grid = this.tableView?.grid!;
146
- const fitCol = this.dataFrame.columns.bySemType(FIT_SEM_TYPE);
146
+ const fitCol = this.dataFrame.columns.bySemType(FitConstants.FIT_SEM_TYPE);
147
147
  if (fitCol !== null)
148
148
  this.curvesColumnNames = [fitCol.name];
149
149
 
@@ -1,8 +1,5 @@
1
1
  import * as DG from 'datagrok-api/dg';
2
2
  import {
3
- CONFIDENCE_INTERVAL_FILL_COLOR,
4
- CONFIDENCE_INTERVAL_STROKE_COLOR,
5
- CURVE_CONFIDENCE_INTERVAL_BOUNDS,
6
3
  FitConfidenceIntervals,
7
4
  FitFunction,
8
5
  IFitChartData,
@@ -75,9 +72,15 @@ interface FitAxesLabelsRenderOptions extends FitTitleRenderOptions {
75
72
  }
76
73
 
77
74
  interface FitLegendRenderOptions {
78
- showLegend: boolean;
75
+ showLegend?: boolean;
79
76
  dataBox: DG.Rect;
80
- ratio: number;
77
+ ratio?: number;
78
+ }
79
+
80
+ interface FitLegendColumnlabelSeriesRenderOptions extends FitLegendRenderOptions {
81
+ columnIdx: number;
82
+ drawnCurvesInLegend: number;
83
+ showColumnLabel?: boolean;
81
84
  }
82
85
 
83
86
 
@@ -227,17 +230,17 @@ export function renderFitLine(g: CanvasRenderingContext2D, series: IFitSeries, r
227
230
  export function renderConfidenceIntervals(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitConfidenceIntervalRenderOptions): void {
228
231
  if ((series.showFitLine ?? true) && (series.showCurveConfidenceInterval ?? false)) {
229
232
  // TODO: improve confidence intervals colors
230
- g.strokeStyle = series.confidenceIntervalColor ?? CONFIDENCE_INTERVAL_STROKE_COLOR;
231
- g.fillStyle = series.confidenceIntervalColor ?? CONFIDENCE_INTERVAL_FILL_COLOR;
233
+ g.strokeStyle = series.confidenceIntervalColor ?? FitConstants.CONFIDENCE_INTERVAL_STROKE_COLOR;
234
+ g.fillStyle = series.confidenceIntervalColor ?? FitConstants.CONFIDENCE_INTERVAL_FILL_COLOR;
232
235
 
233
236
  const confidenceIntervals = getSeriesConfidenceInterval(series, renderOptions.fitFunc!,
234
237
  renderOptions.userParamsFlag!, renderOptions.logOptions);
235
238
  drawConfidenceInterval(g, {viewport: renderOptions.viewport, logOptions: renderOptions.logOptions,
236
239
  showAxes: renderOptions.showAxes, showAxesLabels: renderOptions.showAxesLabels, screenBounds: renderOptions.screenBounds,
237
- confidenceIntervals: confidenceIntervals, confidenceType: CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP});
240
+ confidenceIntervals: confidenceIntervals, confidenceType: FitConstants.CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP});
238
241
  drawConfidenceInterval(g, {viewport: renderOptions.viewport, logOptions: renderOptions.logOptions,
239
242
  showAxes: renderOptions.showAxes, showAxesLabels: renderOptions.showAxesLabels, screenBounds: renderOptions.screenBounds,
240
- confidenceIntervals: confidenceIntervals, confidenceType: CURVE_CONFIDENCE_INTERVAL_BOUNDS.BOTTOM});
243
+ confidenceIntervals: confidenceIntervals, confidenceType: FitConstants.CURVE_CONFIDENCE_INTERVAL_BOUNDS.BOTTOM});
241
244
  fillConfidenceInterval(g, {viewport: renderOptions.viewport, logOptions: renderOptions.logOptions,
242
245
  showAxes: renderOptions.showAxes, showAxesLabels: renderOptions.showAxesLabels, screenBounds: renderOptions.screenBounds,
243
246
  confidenceIntervals: confidenceIntervals});
@@ -250,7 +253,7 @@ function drawConfidenceInterval(g: CanvasRenderingContext2D, renderOptions: FitC
250
253
  const axesLeftPxMargin = renderOptions.showAxes ? renderOptions.showAxesLabels ?
251
254
  FitConstants.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : FitConstants.AXES_LEFT_PX_MARGIN : 0;
252
255
  const axesRightPxMargin = renderOptions.showAxes ? FitConstants.AXES_RIGHT_PX_MARGIN : 0;
253
- const confIntervalFunc = renderOptions.confidenceType === CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP ?
256
+ const confIntervalFunc = renderOptions.confidenceType === FitConstants.CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP ?
254
257
  renderOptions.confidenceIntervals!.confidenceTop : renderOptions.confidenceIntervals!.confidenceBottom;
255
258
  for (let i = axesLeftPxMargin; i <= renderOptions.screenBounds.width - axesRightPxMargin; i++) {
256
259
  const x = renderOptions.screenBounds.x + i;
@@ -375,102 +378,53 @@ export function renderLegend(g: CanvasRenderingContext2D, data: IFitChartData, r
375
378
  let drawnCurvesInLegend = 0;
376
379
  for (let i = 0; i < columnNames.length; i++) {
377
380
  const colName = columnNames[i];
378
-
379
- if (data.chartOptions?.showColumnLabel) {
380
- g.beginPath();
381
- g.fillStyle = 'black';
382
- const colNameWidth = g.measureText(colName!).width;
383
- g.fillText(colName!, renderOptions.dataBox.maxX - colNameWidth, renderOptions.dataBox.y +
384
- FitConstants.LEGEND_TOP_PX_MARGIN + (i * FitConstants.LEGEND_RECORD_PX_HEIGHT + FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend));
385
- }
381
+ if (data.chartOptions?.showColumnLabel)
382
+ renderColumnLabel(g, colName!, {dataBox: renderOptions.dataBox, columnIdx: i, drawnCurvesInLegend});
386
383
 
387
384
  const series = data.series?.filter((series) => series.columnName === colName);
388
385
  for (let j = 0; j < series?.length!; j++) {
389
386
  const currentSeries = series![j];
390
387
  if (currentSeries.name === '' || currentSeries.name === null || currentSeries.name === undefined)
391
388
  continue;
392
-
393
- g.beginPath();
394
- g.strokeStyle = currentSeries.fitLineColor!;
395
- g.lineWidth = 2 * renderOptions.ratio;
396
- const textWidth = g.measureText(currentSeries.name).width;
397
- g.moveTo(renderOptions.dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_PX_WIDTH - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,
398
- renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN - FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN +
399
- (data.chartOptions?.showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (i + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend);
400
- g.lineTo(renderOptions.dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,
401
- renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN - FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN +
402
- (data.chartOptions?.showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (i + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend);
403
- const marker = currentSeries.markerType ? currentSeries.markerType as DG.MARKER_TYPE : DG.MARKER_TYPE.CIRCLE;
404
- DG.Paint.marker(g, marker, renderOptions.dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN - FitConstants.LEGEND_RECORD_LINE_PX_WIDTH / 2,
405
- renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN - FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN +
406
- (data.chartOptions?.showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (i + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend,
407
- currentSeries.pointColor!, FitConstants.POINT_PX_SIZE * renderOptions.ratio);
408
- g.fillStyle = currentSeries.fitLineColor!;
409
- g.fillText(currentSeries.name, renderOptions.dataBox.maxX - textWidth,
410
- renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN +
411
- (data.chartOptions?.showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (i + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * drawnCurvesInLegend);
412
- g.stroke();
389
+ renderLegendSeries(g, currentSeries, {dataBox: renderOptions.dataBox, ratio: renderOptions.ratio,
390
+ columnIdx: i, drawnCurvesInLegend, showColumnLabel: data.chartOptions?.showColumnLabel});
413
391
  drawnCurvesInLegend++;
414
392
  }
415
393
  }
416
394
  g.restore();
417
-
418
-
419
-
420
-
421
- // let drawnCurvesInLegend = 0;
422
- // const columnNames = new Set(data.series?.map((series) => series.columnName));
423
- // [...columnNames].forEach((columnName, columnNameIndex) => {
424
- // const series = data.series?.filter((series) => series.columnName === columnName);
425
- // const getOffset = () => data.chartOptions?.showColumnLabel ? 20 : 0;
426
- // if (data.chartOptions?.showColumnLabel) {
427
- // g.beginPath();
428
- // g.fillStyle = 'black';
429
- // const colNameWidth = g.measureText(columnName ?? '').width;
430
- // g.fillText(columnName ?? '', renderOptions.dataBox.maxX - colNameWidth,
431
- // renderOptions.dataBox.y + 20 + (20 * columnNameIndex + 20 * drawnCurvesInLegend));
432
- // }
433
- // for (let i = 0; i < series?.length!; i++) {
434
- // g.beginPath();
435
- // const currentSeries = series![i];
436
- // g.strokeStyle = currentSeries.fitLineColor!;
437
- // g.lineWidth = 2 * renderOptions.ratio;
438
- // const text = `${currentSeries.name ?? ''}`;
439
- // const textWidth = g.measureText(text).width;
440
- // g.moveTo(renderOptions.dataBox.maxX - textWidth - 25,
441
- // renderOptions.dataBox.y + 20 - 4 + (20 * columnNameIndex + getOffset() + 20 * drawnCurvesInLegend));
442
- // g.lineTo(renderOptions.dataBox.maxX - textWidth - 5,
443
- // renderOptions.dataBox.y + 20 - 4 + (20 * columnNameIndex + getOffset() + 20 * drawnCurvesInLegend));
444
- // const marker = currentSeries.markerType ? currentSeries.markerType as DG.MARKER_TYPE : DG.MARKER_TYPE.CIRCLE;
445
- // DG.Paint.marker(g, marker, renderOptions.dataBox.maxX - textWidth - 25 + (20 / 2),
446
- // renderOptions.dataBox.y + 20 - 4 + (20 * columnNameIndex + getOffset() + 20 * drawnCurvesInLegend),
447
- // currentSeries.pointColor!, FitConstants.POINT_PX_SIZE * renderOptions.ratio);
448
- // g.fillStyle = currentSeries.fitLineColor!;
449
- // g.fillText(text, renderOptions.dataBox.maxX - textWidth,
450
- // renderOptions.dataBox.y + 20 + (20 * columnNameIndex + getOffset() + 20 * drawnCurvesInLegend));
451
- // g.stroke();
452
- // drawnCurvesInLegend++;
453
- // }
454
- // });
455
-
456
395
  }
457
396
  }
458
397
 
459
- // function renderLegendSeries(g: CanvasRenderingContext2D, series: IFitSeries): void {
460
- // g.beginPath();
461
- // g.strokeStyle = series.fitLineColor!;
462
- // g.lineWidth = 2 * renderOptions.ratio;
463
- // const textWidth = g.measureText(series.name!).width;
464
- // g.moveTo(renderOptions.dataBox.maxX - textWidth - 25,
465
- // renderOptions.dataBox.y + 20 - 4 + (20 * columnNameIndex + getOffset() + 20 * drawnCurvesInLegend));
466
- // g.lineTo(renderOptions.dataBox.maxX - textWidth - 5,
467
- // renderOptions.dataBox.y + 20 - 4 + (20 * columnNameIndex + getOffset() + 20 * drawnCurvesInLegend));
468
- // const marker = series.markerType ? currentSeries.markerType as DG.MARKER_TYPE : DG.MARKER_TYPE.CIRCLE;
469
- // DG.Paint.marker(g, marker, renderOptions.dataBox.maxX - textWidth - 25 + (20 / 2),
470
- // renderOptions.dataBox.y + 20 - 4 + (20 * columnNameIndex + getOffset() + 20 * drawnCurvesInLegend),
471
- // series.pointColor!, FitConstants.POINT_PX_SIZE * renderOptions.ratio);
472
- // g.fillStyle = series.fitLineColor!;
473
- // g.fillText(text, renderOptions.dataBox.maxX - textWidth,
474
- // renderOptions.dataBox.y + 20 + (20 * columnNameIndex + getOffset() + 20 * drawnCurvesInLegend));
475
- // g.stroke();
476
- // }
398
+ function renderColumnLabel(g: CanvasRenderingContext2D, colName: string, renderOptions: FitLegendColumnlabelSeriesRenderOptions): void {
399
+ g.beginPath();
400
+ g.fillStyle = 'black';
401
+ const colNameWidth = g.measureText(colName!).width;
402
+ g.fillText(colName!, renderOptions.dataBox.maxX - colNameWidth, renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN +
403
+ (renderOptions.columnIdx * FitConstants.LEGEND_RECORD_PX_HEIGHT + FitConstants.LEGEND_RECORD_PX_HEIGHT * renderOptions.drawnCurvesInLegend));
404
+ }
405
+
406
+ function renderLegendSeries(g: CanvasRenderingContext2D, series: IFitSeries, renderOptions: FitLegendColumnlabelSeriesRenderOptions): void {
407
+ g.beginPath();
408
+ g.strokeStyle = series.fitLineColor!;
409
+ g.lineWidth = 2 * renderOptions.ratio!;
410
+ const textWidth = g.measureText(series.name!).width;
411
+ g.moveTo(renderOptions.dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_PX_WIDTH - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,
412
+ renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN - FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN +
413
+ (renderOptions.showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (renderOptions.columnIdx + 1) : 0) +
414
+ FitConstants.LEGEND_RECORD_PX_HEIGHT * renderOptions.drawnCurvesInLegend);
415
+ g.lineTo(renderOptions.dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN,
416
+ renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN - FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN +
417
+ (renderOptions.showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT * (renderOptions.columnIdx + 1) : 0) +
418
+ FitConstants.LEGEND_RECORD_PX_HEIGHT * renderOptions.drawnCurvesInLegend);
419
+ const marker = series.markerType ? series.markerType as DG.MARKER_TYPE : DG.MARKER_TYPE.CIRCLE;
420
+ DG.Paint.marker(g, marker, renderOptions.dataBox.maxX - textWidth - FitConstants.LEGEND_RECORD_LINE_RIGHT_PX_MARGIN
421
+ - FitConstants.LEGEND_RECORD_LINE_PX_WIDTH / 2, renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN -
422
+ FitConstants.LEGEND_RECORD_LINE_BOTTOM_PX_MARGIN + (renderOptions.showColumnLabel ? FitConstants.LEGEND_RECORD_PX_HEIGHT
423
+ * (renderOptions.columnIdx + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * renderOptions.drawnCurvesInLegend,
424
+ series.pointColor!, FitConstants.POINT_PX_SIZE * renderOptions.ratio!);
425
+ g.fillStyle = series.fitLineColor!;
426
+ g.fillText(series.name!, renderOptions.dataBox.maxX - textWidth,
427
+ renderOptions.dataBox.y + FitConstants.LEGEND_TOP_PX_MARGIN + (renderOptions.showColumnLabel ?
428
+ FitConstants.LEGEND_RECORD_PX_HEIGHT * (renderOptions.columnIdx + 1) : 0) + FitConstants.LEGEND_RECORD_PX_HEIGHT * renderOptions.drawnCurvesInLegend);
429
+ g.stroke();
430
+ }
@@ -1,7 +1,6 @@
1
1
  import * as DG from 'datagrok-api/dg';
2
2
  import * as grok from 'datagrok-api/grok';
3
3
 
4
- import {FIT_SEM_TYPE} from '@datagrok-libraries/statistics/src/fit/fit-curve';
5
4
  import {category, expect, test} from '@datagrok-libraries/utils/src/test';
6
5
  import {FitConstants} from '../fit/const';
7
6
 
@@ -17,9 +16,9 @@ category('detectors', () => {
17
16
  const col3 = df.columns.byName('json chart 2');
18
17
  await grok.data.detectSemanticTypes(df);
19
18
 
20
- expect(col1.semType, FIT_SEM_TYPE);
21
- expect(col2.semType, FIT_SEM_TYPE);
22
- expect(col3.semType, FIT_SEM_TYPE);
19
+ expect(col1.semType, FitConstants.FIT_SEM_TYPE);
20
+ expect(col2.semType, FitConstants.FIT_SEM_TYPE);
21
+ expect(col3.semType, FitConstants.FIT_SEM_TYPE);
23
22
  });
24
23
 
25
24
  test('detectXMLCurveChart', async () => {
@@ -29,7 +28,7 @@ category('detectors', () => {
29
28
  const col = df.columns.byName('xmlCurveFitChart');
30
29
  await grok.data.detectSemanticTypes(df);
31
30
 
32
- expect(col.semType, FIT_SEM_TYPE);
31
+ expect(col.semType, FitConstants.FIT_SEM_TYPE);
33
32
  expect(col.tags[FitConstants.TAG_FIT_CHART_FORMAT], FitConstants.TAG_FIT_CHART_FORMAT_3DX);
34
33
  });
35
34
  });