@datagrok/curves 1.1.0 → 1.2.1

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 (52) hide show
  1. package/.vscode/tasks.json +1 -1
  2. package/CHANGELOG.md +62 -0
  3. package/README.md +116 -10
  4. package/detectors.js +2 -2
  5. package/dist/package-test.js +2791 -1099
  6. package/dist/package-test.js.map +1 -1
  7. package/dist/package.js +2037 -1458
  8. package/dist/package.js.map +1 -1
  9. package/img/curves.gif +0 -0
  10. package/img/custom-fit-function.gif +0 -0
  11. package/package.json +5 -5
  12. package/src/fit/fit-demo.js +13 -7
  13. package/src/fit/fit-demo.js.map +1 -1
  14. package/src/fit/fit-demo.ts +14 -8
  15. package/src/fit/fit-grid-cell-handler.js +23 -11
  16. package/src/fit/fit-grid-cell-handler.js.map +1 -1
  17. package/src/fit/fit-grid-cell-handler.ts +33 -14
  18. package/src/fit/fit-parser.js +23 -19
  19. package/src/fit/fit-parser.js.map +1 -1
  20. package/src/fit/fit-parser.ts +26 -21
  21. package/src/fit/fit-renderer.js +299 -70
  22. package/src/fit/fit-renderer.js.map +1 -1
  23. package/src/fit/fit-renderer.ts +354 -72
  24. package/src/fit/multi-curve-viewer.js +4 -3
  25. package/src/fit/multi-curve-viewer.js.map +1 -1
  26. package/src/fit/multi-curve-viewer.ts +4 -10
  27. package/src/package-test.js +3 -0
  28. package/src/package-test.js.map +1 -1
  29. package/src/package-test.ts +3 -0
  30. package/src/package.js +2 -7
  31. package/src/package.js.map +1 -1
  32. package/src/package.ts +2 -9
  33. package/src/tests/curves-cell-renderer-tests.js +103 -0
  34. package/src/tests/curves-cell-renderer-tests.js.map +1 -0
  35. package/src/tests/curves-cell-renderer-tests.ts +107 -0
  36. package/src/tests/detector-tests.js +2 -1
  37. package/src/tests/detector-tests.js.map +1 -1
  38. package/src/tests/detector-tests.ts +2 -1
  39. package/src/tests/fit-tests.js +82 -0
  40. package/src/tests/fit-tests.js.map +1 -0
  41. package/src/tests/fit-tests.ts +95 -0
  42. package/src/tests/transform-tests.js +26 -0
  43. package/src/tests/transform-tests.js.map +1 -0
  44. package/src/tests/transform-tests.ts +21 -0
  45. package/tsconfig.json +1 -1
  46. package/webpack.config.js +1 -0
  47. package/src/fit/fit-data.js +0 -215
  48. package/src/fit/fit-data.js.map +0 -1
  49. package/src/fit/fit-data.ts +0 -328
  50. package/src/fit/transform.js +0 -73
  51. package/src/fit/transform.js.map +0 -1
  52. package/src/fit/transform.ts +0 -99
@@ -1,215 +0,0 @@
1
- /* eslint-disable valid-jsdoc */
2
- /* eslint-disable no-multi-spaces */
3
- import * as DG from 'datagrok-api/dg';
4
- import { Property } from 'datagrok-api/src/entities';
5
- import { TYPE } from 'datagrok-api/src/const';
6
- import { fit, FitErrorModel, fitResultProperties, sigmoid } from '@datagrok-libraries/statistics/src/parameter-estimation/fit-curve';
7
- /**
8
- * Datagrok curve fitting
9
- *
10
- * - Fitting: computing parameters of the specified function to best fit the data
11
- * - Uses BFGS optimization algorithm (multi-threading for performance).
12
- * For dose-response curves, we are typically fitting the sigmoid function
13
- * - Ability to dynamically register custom fitting functions
14
- * - Ability to get fitting performance characteristics (r-squared, classification, etc)
15
- * - Deep integration with the Datagrok grid
16
- * - Either fitting on the fly, or using the supplied function + parameters
17
- * - Multiple series in one cell
18
- * - Ability to define chart, marker, or fitting options (such as fit function or marker color)
19
- * on the column level, with the ability to override it on a grid cell or point level
20
- * - Clicking a point in a chart within a grid makes it an outlier -> curve is re-fitted on the fly
21
- * - Ability to specify a chart as "reference" so that it is shown on every other chart for comparison
22
- * - Ability to overlay curves from multiple grid cells (special viewer)
23
- * - Work with series stored in multiple formats (binary for performance, json for flexibility, etc)
24
- */
25
- export const FIT_SEM_TYPE = 'fit';
26
- export const FIT_CELL_TYPE = 'fit';
27
- export const TAG_FIT = '.fit';
28
- export const TAG_FIT_CHART_FORMAT = '.fitChartFormat';
29
- export const TAG_FIT_CHART_FORMAT_3DX = '3dx';
30
- export const CONFIDENCE_INTERVAL_STROKE_COLOR = 'rgba(255,191,63,0.7)';
31
- export const CONFIDENCE_INTERVAL_FILL_COLOR = 'rgba(255,238,204,0.3)';
32
- export const CURVE_CONFIDENCE_INTERVAL_BOUNDS = {
33
- TOP: 'top',
34
- BOTTOM: 'bottom'
35
- };
36
- /** Class that implements {@link IFitChartData} interface */
37
- export class FitChartData {
38
- constructor() {
39
- this.chartOptions = {};
40
- this.seriesOptions = {}; // Default series options. Individual series can override it.
41
- this.series = [];
42
- }
43
- }
44
- /** Properties that describe {@link IFitChartOptions}. Useful for editing, initialization, transformations, etc. */
45
- export const fitChartDataProperties = [
46
- // Style and zoom
47
- Property.js('minX', TYPE.FLOAT, { description: 'Minimum value of the X axis', nullable: true }),
48
- Property.js('minY', TYPE.FLOAT, { description: 'Minimum value of the Y axis', nullable: true }),
49
- Property.js('maxX', TYPE.FLOAT, { description: 'Maximum value of the X axis', nullable: true }),
50
- Property.js('maxY', TYPE.FLOAT, { description: 'Maximum value of the Y axis', nullable: true }),
51
- Property.js('xAxisName', TYPE.STRING, { description: 'Label to show on the X axis. If not specified, corresponding data column name is used', nullable: true }),
52
- Property.js('yAxisName', TYPE.STRING, { description: 'Label to show on the Y axis. If not specified, corresponding data column name is used', nullable: true }),
53
- Property.js('logX', TYPE.BOOL, { defaultValue: false }),
54
- Property.js('logY', TYPE.BOOL, { defaultValue: false }),
55
- Property.js('showStatistics', TYPE.STRING_LIST, { choices: fitResultProperties.map(frp => frp.name) }),
56
- ];
57
- /** Properties that describe {@link IFitSeriesOptions}. Useful for editing, initialization, transformations, etc. */
58
- export const fitSeriesProperties = [
59
- Property.js('name', TYPE.STRING),
60
- Property.js('fitFunction', TYPE.STRING, { category: 'Fitting', choices: ['sigmoid', 'linear'], defaultValue: 'sigmoid' }),
61
- Property.js('pointColor', TYPE.STRING, { category: 'Rendering', defaultValue: DG.Color.toHtml(DG.Color.scatterPlotMarker), nullable: true }),
62
- Property.js('fitLineColor', TYPE.STRING, { category: 'Rendering', defaultValue: DG.Color.toHtml(DG.Color.scatterPlotMarker), nullable: true }),
63
- Property.js('clickToToggle', TYPE.BOOL, { category: 'Fitting', description: 'If true, clicking on the point toggles its outlier status and causes curve refitting', nullable: true }),
64
- Property.js('autoFit', TYPE.BOOL, { category: 'Fitting', description: 'Perform fitting on-the-fly', defaultValue: true }),
65
- Property.js('showFitLine', TYPE.BOOL, { category: 'Fitting', description: 'Whether the fit line should be rendered', defaultValue: true }),
66
- Property.js('showPoints', TYPE.BOOL, { category: 'Fitting', description: 'Whether points should be rendered', defaultValue: true }),
67
- ];
68
- /** Creates new object with the default values specified in {@link properties} */
69
- function createFromProperties(properties) {
70
- const o = {};
71
- for (const p of properties) {
72
- if (p.defaultValue !== null)
73
- o[p.name] = p.defaultValue;
74
- }
75
- return o;
76
- }
77
- /** Merges properties of the two objects by iterating over the specified {@link properties}
78
- * and assigning properties from {@link source} to {@link target} only when
79
- * the property is not defined in target and is defined in source. */
80
- export function mergeProperties(properties, source, target) {
81
- if (!source || !target)
82
- return;
83
- for (const p of properties) {
84
- if (!(p.name in target) && p.name in source)
85
- target[p.name] = source[p.name];
86
- }
87
- }
88
- /** Creates default {@link IFitChartData} object */
89
- function createDefaultChartData() {
90
- return {
91
- chartOptions: createFromProperties(fitChartDataProperties),
92
- seriesOptions: createFromProperties(fitSeriesProperties)
93
- };
94
- }
95
- /** Returns existing, or creates new column default chart options. */
96
- export function getColumnChartOptions(gridColumn) {
97
- var _a;
98
- var _b;
99
- return (_a = (_b = gridColumn.temp)[TAG_FIT]) !== null && _a !== void 0 ? _a : (_b[TAG_FIT] = createDefaultChartData());
100
- }
101
- /** Returns the bounds of an {@link IFitChartData} object */
102
- export function getChartBounds(chartData) {
103
- var _a;
104
- const o = chartData.chartOptions;
105
- if ((o === null || o === void 0 ? void 0 : o.minX) && o.minY && o.maxX && o.maxY)
106
- return new DG.Rect(o.minX, o.minY, o.maxX - o.minX, o.maxY - o.minY);
107
- if (!((_a = chartData.series) === null || _a === void 0 ? void 0 : _a.length) || chartData.series.length == 0) {
108
- return new DG.Rect(0, 0, 1, 1);
109
- }
110
- else {
111
- let bounds = getDataBounds(chartData.series[0].points);
112
- for (let i = 1; i < chartData.series.length; i++)
113
- bounds = bounds.union(getDataBounds(chartData.series[i].points));
114
- return bounds;
115
- }
116
- }
117
- //TODO: move to DG.Rect
118
- /** Gets the bounds of provided points */
119
- export function getDataBounds(points) {
120
- let minX = points[0].x;
121
- let minY = points[0].y;
122
- let maxX = points[0].x;
123
- let maxY = points[0].y;
124
- for (let i = 1; i < points.length; i++) {
125
- minX = Math.min(minX, points[i].x);
126
- minY = Math.min(minY, points[i].y);
127
- maxX = Math.max(maxX, points[i].x);
128
- maxY = Math.max(maxY, points[i].y);
129
- }
130
- return new DG.Rect(minX, minY, maxX - minX, maxY - minY);
131
- }
132
- /** Fits the series data according to the series fitting settings */
133
- export function fitSeries(series, statistics = false) {
134
- const dataBounds = getDataBounds(series.points);
135
- const medY = (dataBounds.bottom - dataBounds.top) / 2 + dataBounds.top;
136
- let maxYInterval = dataBounds.bottom - dataBounds.top;
137
- let nearestXIndex = 0;
138
- for (let i = 0; i < series.points.length; i++) {
139
- const currentInterval = Math.abs(series.points[i].y - medY);
140
- if (currentInterval < maxYInterval) {
141
- maxYInterval = currentInterval;
142
- nearestXIndex = i;
143
- }
144
- }
145
- const xAtMedY = series.points[nearestXIndex].x;
146
- const slope = series.points[0].y > series.points[series.points.length - 1].y ? 1.2 : -1.2;
147
- // params are: [max, tan, IC50, min]
148
- const initialParams = [{ value: dataBounds.bottom }, { value: slope }, { value: xAtMedY }, { value: dataBounds.top }];
149
- return fit({ x: series.points.map((p) => p.x), y: series.points.map((p) => p.y) }, initialParams, sigmoid, FitErrorModel.Constant, 0.05, statistics);
150
- }
151
- // /** Returns a curve function, either using the pre-computed parameters
152
- // * or by fitting on-the-fly */
153
- // export function getFittedCurve(series: IFitSeries): (x: number) => number {
154
- // if (series.parameters)
155
- // return (x) => sigmoid(series.parameters!, x);
156
- // else
157
- // return fitSeries(series).fittedCurve;
158
- // }
159
- // /** Returns confidence interval functions */
160
- // export function getConfidenceIntervals(series: IFitSeries): {top: (x: number) => number, bottom: (x: number) => number} {
161
- // const confTop = fitSeries(series).confidenceTop;
162
- // const confBottom = fitSeries(series).confidenceBottom;
163
- // return {top: confTop, bottom: confBottom};
164
- // }
165
- /** Constructs {@link IFitChartData} from the grid cell, taking into account
166
- * chart and fit settings potentially defined on the dataframe and column level. */
167
- export function getChartData(gridCell) {
168
- var _a, _b, _c, _d, _e, _f;
169
- const cellChartData = ((_b = (_a = gridCell.cell) === null || _a === void 0 ? void 0 : _a.column) === null || _b === void 0 ? void 0 : _b.type) === DG.TYPE.STRING ?
170
- ((_d = JSON.parse((_c = gridCell.cell.value) !== null && _c !== void 0 ? _c : '{}')) !== null && _d !== void 0 ? _d : {}) : createDefaultChartData();
171
- const columnChartOptions = getColumnChartOptions(gridCell.gridColumn);
172
- (_e = cellChartData.series) !== null && _e !== void 0 ? _e : (cellChartData.series = []);
173
- (_f = cellChartData.chartOptions) !== null && _f !== void 0 ? _f : (cellChartData.chartOptions = columnChartOptions.chartOptions);
174
- // merge cell options with column options
175
- mergeProperties(fitChartDataProperties, columnChartOptions.chartOptions, cellChartData.chartOptions);
176
- for (const series of cellChartData.series)
177
- mergeProperties(fitSeriesProperties, columnChartOptions.seriesOptions, series);
178
- return cellChartData;
179
- }
180
- const sample = {
181
- // chartOptions could be retrieved either from the column, or from the cell
182
- 'chartOptions': {
183
- 'minX': 0, 'minY': 0, 'maxX': 5, 'maxY': 10,
184
- 'xAxisName': 'concentration',
185
- 'yAxisName': 'activity',
186
- 'logX': false,
187
- 'logY': false,
188
- },
189
- // These options are used as default options for the series. They could be overridden in series.
190
- 'seriesOptions': {
191
- 'fitFunction': 'sigmoid',
192
- // parameters not specified -> auto-fitting by default
193
- 'pointColor': 'blue',
194
- 'fitLineColor': 'red',
195
- 'clickToToggle': true,
196
- 'showPoints': true,
197
- 'showFitLine': true,
198
- 'showCurveConfidenceInterval': true
199
- },
200
- 'series': [
201
- {
202
- 'fitFunction': 'sigmoid',
203
- // parameters specified -> use them, no autofitting
204
- 'parameters': [1.86011e-07, -0.900, 103.748, -0.001],
205
- 'points': [
206
- { 'x': 0, 'y': 0 },
207
- { 'x': 1, 'y': 0.5 },
208
- { 'x': 2, 'y': 1 },
209
- { 'x': 3, 'y': 10, 'outlier': true },
210
- { 'x': 4, 'y': 0 }
211
- ]
212
- }
213
- ]
214
- };
215
- //# sourceMappingURL=fit-data.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fit-data.js","sourceRoot":"","sources":["fit-data.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,oCAAoC;AAEpC,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAC,QAAQ,EAAC,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AAE5C,OAAO,EACL,GAAG,EACH,aAAa,EAEF,mBAAmB,EAC9B,OAAO,EACR,MAAM,mEAAmE,CAAC;AAE3E;;;;;;;;;;;;;;;;;EAiBE;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;AAClC,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;AACnC,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC;AAC9B,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AACtD,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAE9C,MAAM,CAAC,MAAM,gCAAgC,GAAG,sBAAsB,CAAC;AACvE,MAAM,CAAC,MAAM,8BAA8B,GAAG,uBAAuB,CAAC;AAEtE,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC9C,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,QAAQ;CACjB,CAAC;AAmEF,4DAA4D;AAC5D,MAAM,OAAO,YAAY;IAAzB;QACE,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gGAAgG;IAChG,eAAe,EAAE;QACf,aAAa,EAAE,SAAS;QACxB,sDAAsD;QACtD,YAAY,EAAE,MAAM;QACpB,cAAc,EAAE,KAAK;QACrB,eAAe,EAAE,IAAI;QACrB,YAAY,EAAE,IAAI;QAClB,aAAa,EAAE,IAAI;QACnB,6BAA6B,EAAE,IAAI;KACpC;IACD,QAAQ,EAAE;QACR;YACE,aAAa,EAAE,SAAS;YACxB,mDAAmD;YACnD,YAAY,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC;YACpD,QAAQ,EAAE;gBACR,EAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAC;gBAChB,EAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAC;gBAClB,EAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAC;gBAChB,EAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAC;gBAClC,EAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAC;aACjB;SACF;KACF;CACF,CAAC"}
@@ -1,328 +0,0 @@
1
- /* eslint-disable valid-jsdoc */
2
- /* eslint-disable no-multi-spaces */
3
-
4
- import * as DG from 'datagrok-api/dg';
5
- import {Property} from 'datagrok-api/src/entities';
6
- import {TYPE} from 'datagrok-api/src/const';
7
-
8
- import {
9
- fit,
10
- FitErrorModel,
11
- FitParam,
12
- FitResult, fitResultProperties,
13
- sigmoid
14
- } from '@datagrok-libraries/statistics/src/parameter-estimation/fit-curve';
15
-
16
- /**
17
- * Datagrok curve fitting
18
- *
19
- * - Fitting: computing parameters of the specified function to best fit the data
20
- * - Uses BFGS optimization algorithm (multi-threading for performance).
21
- * For dose-response curves, we are typically fitting the sigmoid function
22
- * - Ability to dynamically register custom fitting functions
23
- * - Ability to get fitting performance characteristics (r-squared, classification, etc)
24
- * - Deep integration with the Datagrok grid
25
- * - Either fitting on the fly, or using the supplied function + parameters
26
- * - Multiple series in one cell
27
- * - Ability to define chart, marker, or fitting options (such as fit function or marker color)
28
- * on the column level, with the ability to override it on a grid cell or point level
29
- * - Clicking a point in a chart within a grid makes it an outlier -> curve is re-fitted on the fly
30
- * - Ability to specify a chart as "reference" so that it is shown on every other chart for comparison
31
- * - Ability to overlay curves from multiple grid cells (special viewer)
32
- * - Work with series stored in multiple formats (binary for performance, json for flexibility, etc)
33
- */
34
-
35
- export const FIT_SEM_TYPE = 'fit';
36
- export const FIT_CELL_TYPE = 'fit';
37
- export const TAG_FIT = '.fit';
38
- export const TAG_FIT_CHART_FORMAT = '.fitChartFormat';
39
- export const TAG_FIT_CHART_FORMAT_3DX = '3dx';
40
-
41
- export const CONFIDENCE_INTERVAL_STROKE_COLOR = 'rgba(255,191,63,0.7)';
42
- export const CONFIDENCE_INTERVAL_FILL_COLOR = 'rgba(255,238,204,0.3)';
43
-
44
- export const CURVE_CONFIDENCE_INTERVAL_BOUNDS = {
45
- TOP: 'top',
46
- BOTTOM: 'bottom'
47
- };
48
-
49
- export type FitMarkerType = 'circle' | 'triangle up' | 'triangle down' | 'cross';
50
-
51
- /** A point in the fit series. Only x and y are required. Can override some fields defined in IFitSeriesOptions. */
52
- export interface IFitPoint {
53
- x: number;
54
- y: number;
55
- outlier?: boolean; // if true, renders as 'x' and gets ignored for curve fitting
56
- minY?: number; // when defined, the marker renders as a candlestick with whiskers [minY, maxY]
57
- maxY?: number; // when defined, the marker renders as a candlestick with whiskers [minY, maxY]
58
- marker?: FitMarkerType; // overrides the marker type defined in IFitSeriesOptions
59
- color?: string; // overrides the marker color defined in IFitSeriesOptions
60
- }
61
-
62
-
63
- /** Series options can be either applied globally on a column level, or partially overridden in particular series */
64
- export interface IFitSeriesOptions {
65
- name?: string;
66
- fitFunction?: string;
67
- parameters?: number[]; // auto-fitting when not defined
68
- pointColor?: string;
69
- fitLineColor?: string;
70
- confidenceIntervalColor?: string;
71
- showFitLine?: boolean;
72
- showPoints?: boolean;
73
- showCurveConfidenceInterval?: boolean; // show ribbon
74
- showIntercept?: boolean;
75
- showBoxPlot?: boolean; // if true, multiple values with the same X are rendered as a candlestick
76
- showConfidenceForX?: number;
77
- clickToToggle?: boolean; // If true, clicking on the point toggles its outlier status and causes curve refitting
78
- }
79
-
80
-
81
- /** A series consists of points, has a name, and options.
82
- * If defined, seriesOptions are merged with {@link IFitChartData.seriesOptions} */
83
- export interface IFitSeries extends IFitSeriesOptions {
84
- points: IFitPoint[];
85
- }
86
-
87
-
88
- /** Chart options. For fitted curves, this object is stored in the grid column tags and is
89
- * used by the renderer. */
90
- export interface IFitChartOptions {
91
- minX?: number;
92
- minY?: number;
93
- maxX?: number;
94
- maxY?: number;
95
-
96
- xAxisName?: string;
97
- yAxisName?: string;
98
-
99
- logX?: boolean;
100
- logY?: boolean;
101
-
102
- showStatistics?: string[];
103
- }
104
-
105
-
106
- /** Data for the fit chart. */
107
- export interface IFitChartData {
108
- chartOptions?: IFitChartOptions;
109
- seriesOptions?: IFitSeriesOptions; // Default series options. Individual series can override it.
110
- series?: IFitSeries[];
111
- }
112
-
113
-
114
- /** Class that implements {@link IFitChartData} interface */
115
- export class FitChartData implements IFitChartData {
116
- chartOptions: IFitChartOptions = {};
117
- seriesOptions: IFitSeriesOptions = {}; // Default series options. Individual series can override it.
118
- series: IFitSeries[] = [];
119
- }
120
-
121
-
122
- /** Properties that describe {@link IFitChartOptions}. Useful for editing, initialization, transformations, etc. */
123
- export const fitChartDataProperties: Property[] = [
124
- // Style and zoom
125
- Property.js('minX', TYPE.FLOAT, {description: 'Minimum value of the X axis', nullable: true}),
126
- Property.js('minY', TYPE.FLOAT, {description: 'Minimum value of the Y axis', nullable: true}),
127
- Property.js('maxX', TYPE.FLOAT, {description: 'Maximum value of the X axis', nullable: true}),
128
- Property.js('maxY', TYPE.FLOAT, {description: 'Maximum value of the Y axis', nullable: true}),
129
- Property.js('xAxisName', TYPE.STRING, {description:
130
- 'Label to show on the X axis. If not specified, corresponding data column name is used', nullable: true}),
131
- Property.js('yAxisName', TYPE.STRING, {description:
132
- 'Label to show on the Y axis. If not specified, corresponding data column name is used', nullable: true}),
133
- Property.js('logX', TYPE.BOOL, {defaultValue: false}),
134
- Property.js('logY', TYPE.BOOL, {defaultValue: false}),
135
- Property.js('showStatistics', TYPE.STRING_LIST, { choices: fitResultProperties.map(frp => frp.name) }),
136
- ];
137
-
138
-
139
- /** Properties that describe {@link IFitSeriesOptions}. Useful for editing, initialization, transformations, etc. */
140
- export const fitSeriesProperties: Property[] = [
141
- Property.js('name', TYPE.STRING),
142
- Property.js('fitFunction', TYPE.STRING,
143
- {category: 'Fitting', choices: ['sigmoid', 'linear'], defaultValue: 'sigmoid'}),
144
- Property.js('pointColor', TYPE.STRING,
145
- {category: 'Rendering', defaultValue: DG.Color.toHtml(DG.Color.scatterPlotMarker), nullable: true}),
146
- Property.js('fitLineColor', TYPE.STRING,
147
- {category: 'Rendering', defaultValue: DG.Color.toHtml(DG.Color.scatterPlotMarker), nullable: true}),
148
- Property.js('clickToToggle', TYPE.BOOL, {category: 'Fitting', description:
149
- 'If true, clicking on the point toggles its outlier status and causes curve refitting', nullable: true}),
150
- Property.js('autoFit', TYPE.BOOL,
151
- {category: 'Fitting', description: 'Perform fitting on-the-fly', defaultValue: true}),
152
- Property.js('showFitLine', TYPE.BOOL,
153
- {category: 'Fitting', description: 'Whether the fit line should be rendered', defaultValue: true}),
154
- Property.js('showPoints', TYPE.BOOL,
155
- {category: 'Fitting', description: 'Whether points should be rendered', defaultValue: true}),
156
- ];
157
-
158
-
159
- /** Creates new object with the default values specified in {@link properties} */
160
- function createFromProperties(properties: Property[]): any {
161
- const o: any = {};
162
- for (const p of properties) {
163
- if (p.defaultValue !== null)
164
- o[p.name] = p.defaultValue;
165
- }
166
- return o;
167
- }
168
-
169
-
170
- /** Merges properties of the two objects by iterating over the specified {@link properties}
171
- * and assigning properties from {@link source} to {@link target} only when
172
- * the property is not defined in target and is defined in source. */
173
- export function mergeProperties(properties: Property[], source: any, target: any): void {
174
- if (!source || !target)
175
- return;
176
-
177
- for (const p of properties) {
178
- if (!(p.name in target) && p.name in source)
179
- target[p.name] = source[p.name];
180
- }
181
- }
182
-
183
- /** Creates default {@link IFitChartData} object */
184
- function createDefaultChartData(): IFitChartData {
185
- return {
186
- chartOptions: createFromProperties(fitChartDataProperties),
187
- seriesOptions: createFromProperties(fitSeriesProperties)
188
- };
189
- }
190
-
191
-
192
- /** Returns existing, or creates new column default chart options. */
193
- export function getColumnChartOptions(gridColumn: DG.GridColumn): IFitChartData {
194
- return gridColumn.temp[TAG_FIT] ??= createDefaultChartData();
195
- }
196
-
197
-
198
- /** Returns the bounds of an {@link IFitChartData} object */
199
- export function getChartBounds(chartData: IFitChartData): DG.Rect {
200
- const o = chartData.chartOptions;
201
- if (o?.minX && o.minY && o.maxX && o.maxY)
202
- return new DG.Rect(o.minX, o.minY, o.maxX - o.minX, o.maxY - o.minY);
203
- if (!chartData.series?.length || chartData.series.length == 0) {
204
- return new DG.Rect(0, 0, 1, 1);
205
- } else {
206
- let bounds = getDataBounds(chartData.series[0].points);
207
- for (let i = 1; i < chartData.series!.length; i++)
208
- bounds = bounds.union(getDataBounds(chartData.series[i].points));
209
- return bounds;
210
- }
211
- }
212
-
213
-
214
- //TODO: move to DG.Rect
215
- /** Gets the bounds of provided points */
216
- export function getDataBounds(points: IFitPoint[]): DG.Rect {
217
- let minX = points[0].x;
218
- let minY = points[0].y;
219
- let maxX = points[0].x;
220
- let maxY = points[0].y;
221
-
222
- for (let i = 1; i < points.length; i++) {
223
- minX = Math.min(minX, points[i].x);
224
- minY = Math.min(minY, points[i].y);
225
- maxX = Math.max(maxX, points[i].x);
226
- maxY = Math.max(maxY, points[i].y);
227
- }
228
-
229
- return new DG.Rect(minX, minY, maxX - minX, maxY - minY);
230
- }
231
-
232
-
233
- /** Fits the series data according to the series fitting settings */
234
- export function fitSeries(series: IFitSeries, statistics: boolean = false): FitResult {
235
- const dataBounds = getDataBounds(series.points);
236
- const medY = (dataBounds.bottom - dataBounds.top) / 2 + dataBounds.top;
237
-
238
- let maxYInterval = dataBounds.bottom - dataBounds.top;
239
- let nearestXIndex = 0;
240
- for (let i = 0; i < series.points.length; i++) {
241
- const currentInterval = Math.abs(series.points[i].y - medY);
242
- if (currentInterval < maxYInterval) {
243
- maxYInterval = currentInterval;
244
- nearestXIndex = i;
245
- }
246
- }
247
- const xAtMedY = series.points[nearestXIndex].x;
248
- const slope = series.points[0].y > series.points[series.points.length - 1].y ? 1.2 : -1.2;
249
-
250
- // params are: [max, tan, IC50, min]
251
- const initialParams: FitParam[] = [{value: dataBounds.bottom}, {value: slope}, {value: xAtMedY}, {value: dataBounds.top}];
252
-
253
- return fit(
254
- {x: series.points.map((p) => p.x), y: series.points.map((p) => p.y)},
255
- initialParams, sigmoid, FitErrorModel.Constant, 0.05, statistics);
256
- }
257
-
258
- // /** Returns a curve function, either using the pre-computed parameters
259
- // * or by fitting on-the-fly */
260
- // export function getFittedCurve(series: IFitSeries): (x: number) => number {
261
- // if (series.parameters)
262
- // return (x) => sigmoid(series.parameters!, x);
263
- // else
264
- // return fitSeries(series).fittedCurve;
265
- // }
266
-
267
- // /** Returns confidence interval functions */
268
- // export function getConfidenceIntervals(series: IFitSeries): {top: (x: number) => number, bottom: (x: number) => number} {
269
- // const confTop = fitSeries(series).confidenceTop;
270
- // const confBottom = fitSeries(series).confidenceBottom;
271
- // return {top: confTop, bottom: confBottom};
272
- // }
273
-
274
- /** Constructs {@link IFitChartData} from the grid cell, taking into account
275
- * chart and fit settings potentially defined on the dataframe and column level. */
276
- export function getChartData(gridCell: DG.GridCell): IFitChartData {
277
- const cellChartData: IFitChartData = gridCell.cell?.column?.type === DG.TYPE.STRING ?
278
- (JSON.parse(gridCell.cell.value ?? '{}') ?? {}) : createDefaultChartData();
279
-
280
- const columnChartOptions = getColumnChartOptions(gridCell.gridColumn);
281
-
282
- cellChartData.series ??= [];
283
- cellChartData.chartOptions ??= columnChartOptions.chartOptions;
284
-
285
- // merge cell options with column options
286
- mergeProperties(fitChartDataProperties, columnChartOptions.chartOptions, cellChartData.chartOptions);
287
- for (const series of cellChartData.series)
288
- mergeProperties(fitSeriesProperties, columnChartOptions.seriesOptions, series);
289
-
290
- return cellChartData;
291
- }
292
-
293
-
294
- const sample: IFitChartData = {
295
- // chartOptions could be retrieved either from the column, or from the cell
296
- 'chartOptions': {
297
- 'minX': 0, 'minY': 0, 'maxX': 5, 'maxY': 10,
298
- 'xAxisName': 'concentration',
299
- 'yAxisName': 'activity',
300
- 'logX': false,
301
- 'logY': false,
302
- },
303
- // These options are used as default options for the series. They could be overridden in series.
304
- 'seriesOptions': {
305
- 'fitFunction': 'sigmoid',
306
- // parameters not specified -> auto-fitting by default
307
- 'pointColor': 'blue',
308
- 'fitLineColor': 'red',
309
- 'clickToToggle': true,
310
- 'showPoints': true,
311
- 'showFitLine': true,
312
- 'showCurveConfidenceInterval': true
313
- },
314
- 'series': [
315
- {
316
- 'fitFunction': 'sigmoid',
317
- // parameters specified -> use them, no autofitting
318
- 'parameters': [1.86011e-07, -0.900, 103.748, -0.001],
319
- 'points': [
320
- {'x': 0, 'y': 0},
321
- {'x': 1, 'y': 0.5},
322
- {'x': 2, 'y': 1},
323
- {'x': 3, 'y': 10, 'outlier': true},
324
- {'x': 4, 'y': 0}
325
- ]
326
- }
327
- ]
328
- };
@@ -1,73 +0,0 @@
1
- import * as DG from 'datagrok-api/dg';
2
- /** Linear transformation */
3
- class _LinearTransform {
4
- screenToWorld(screen, length, min, max, inverse) {
5
- const d = inverse ? 1 - screen / length : screen / length;
6
- return min + d * (max - min);
7
- }
8
- worldToScreen(world, length, min, max, inverse) {
9
- return inverse
10
- ? ((1 - ((world - min)) / (max - min)) * length)
11
- : ((world - min) / (max - min) * length);
12
- }
13
- }
14
- /** Log transformation */
15
- class _LogTransform {
16
- screenToWorld(screen, length, min, max, inverse) {
17
- min = (min < 0.00000001 ? 0.00000001 : min);
18
- const maxLog = Math.log(max);
19
- const minLog = Math.log(min);
20
- return Math.exp(minLog + (maxLog - minLog) * (inverse ? length - screen : screen) / length);
21
- }
22
- worldToScreen(world, length, min, max, inverse) {
23
- if (world <= 0)
24
- return NaN;
25
- //eliminates problems with rounding
26
- if (world === min)
27
- return inverse ? length : 0.0;
28
- if (world === max)
29
- return inverse ? 0.0 : length;
30
- min = (min < 0.00000001 ? 0.00000001 : min);
31
- world = (world < 0.00000001 ? 0.00000001 : world);
32
- const res = (length * Math.log(world / min) / Math.log(max / min));
33
- return inverse ? length - res : res;
34
- }
35
- }
36
- const linearTransform = new _LinearTransform();
37
- const logTransform = new _LogTransform();
38
- /** Provides convenient methods for mapping between screen and world coordinates */
39
- export class Viewport {
40
- get xt() { return this.logX ? logTransform : linearTransform; }
41
- get yt() { return this.logY ? logTransform : linearTransform; }
42
- constructor(world, screen, logX = false, logY = false) {
43
- this.logX = false;
44
- this.logY = false;
45
- this.inverseX = false;
46
- this.inverseY = true;
47
- this.world = world;
48
- this.screen = screen;
49
- this.logX = logX;
50
- this.logY = logY;
51
- }
52
- xToScreen(world) {
53
- return this.screen.left + this.xt.worldToScreen(world, this.screen.width, this.world.minX, this.world.maxX, this.inverseX);
54
- }
55
- yToScreen(world) {
56
- return this.screen.top + this.yt.worldToScreen(world, this.screen.height, this.world.minY, this.world.maxY, this.inverseY);
57
- }
58
- xToWorld(screen) {
59
- return this.xt.worldToScreen(screen, this.screen.width, this.world.minX, this.world.maxX, this.inverseX);
60
- }
61
- yToWorld(screen) {
62
- return this.yt.worldToScreen(screen, this.screen.height, this.world.minY, this.world.maxY, this.inverseY);
63
- }
64
- toScreen(world) { return new DG.Point(this.xToScreen(world.x), this.yToScreen(world.y)); }
65
- toWorld(screen) { return new DG.Point(this.xToWorld(screen.x), this.yToWorld(screen.y)); }
66
- drawCoordinateGrid(g, xAxis, yAxis) {
67
- if (xAxis)
68
- DG.Paint.horzAxis(g, this.world.minX, this.world.maxX, xAxis.x, xAxis.y, xAxis.width, xAxis.height, this.logX, this.inverseX);
69
- if (yAxis)
70
- DG.Paint.vertAxis(g, this.world.minY, this.world.maxY, yAxis.x, yAxis.y, yAxis.width, yAxis.height, this.logY, this.inverseY);
71
- }
72
- }
73
- //# sourceMappingURL=transform.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform.js","sourceRoot":"","sources":["transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAUtC,4BAA4B;AAC5B,MAAM,gBAAgB;IACpB,aAAa,CAAC,MAAc,EAAE,MAAc,EAAE,GAAW,EAAE,GAAW,EAAE,OAAiB;QACvF,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC,GAAG,MAAM,GAAG,MAAM,CAAA,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC;QAC1D,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,aAAa,CAAC,KAAa,EAAE,MAAc,EAAE,GAAW,EAAE,GAAW,EAAE,OAAiB;QACtF,OAAO,OAAO;YACZ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;YAChD,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IAC7C,CAAC;CACF;AAGD,yBAAyB;AACzB,MAAM,aAAa;IACjB,aAAa,CAAC,MAAc,EAAE,MAAc,EAAE,GAAW,EAAE,GAAW,EAAE,OAAiB;QACvF,GAAG,GAAG,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAE5C,MAAM,MAAM,GAAG,IAAI,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