@datagrok/curves 1.0.1 → 1.2.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 (57) hide show
  1. package/.vscode/tasks.json +1 -1
  2. package/CHANGELOG.md +25 -0
  3. package/README.md +89 -10
  4. package/detectors.js +5 -3
  5. package/dist/package-test.js +16704 -94
  6. package/dist/package-test.js.map +1 -1
  7. package/dist/package.js +2014 -1475
  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/cell-render-viewer.js.map +1 -1
  13. package/src/fit/cell-render-viewer.ts +6 -5
  14. package/src/fit/fit-demo.js +18 -11
  15. package/src/fit/fit-demo.js.map +1 -1
  16. package/src/fit/fit-demo.ts +22 -16
  17. package/src/fit/fit-grid-cell-handler.js +30 -21
  18. package/src/fit/fit-grid-cell-handler.js.map +1 -1
  19. package/src/fit/fit-grid-cell-handler.ts +39 -24
  20. package/src/fit/fit-parser.js +19 -16
  21. package/src/fit/fit-parser.js.map +1 -1
  22. package/src/fit/fit-parser.ts +22 -20
  23. package/src/fit/fit-renderer.js +285 -79
  24. package/src/fit/fit-renderer.js.map +1 -1
  25. package/src/fit/fit-renderer.ts +347 -87
  26. package/src/fit/multi-curve-viewer.js +7 -6
  27. package/src/fit/multi-curve-viewer.js.map +1 -1
  28. package/src/fit/multi-curve-viewer.ts +15 -19
  29. package/src/package-test.js +4 -1
  30. package/src/package-test.js.map +1 -1
  31. package/src/package-test.ts +4 -1
  32. package/src/package.js +2 -7
  33. package/src/package.js.map +1 -1
  34. package/src/package.ts +2 -9
  35. package/src/tests/curves-cell-renderer-tests.js +103 -0
  36. package/src/tests/curves-cell-renderer-tests.js.map +1 -0
  37. package/src/tests/curves-cell-renderer-tests.ts +107 -0
  38. package/src/tests/detector-tests.js +39 -0
  39. package/src/tests/detector-tests.js.map +1 -0
  40. package/src/tests/detector-tests.ts +35 -0
  41. package/src/tests/fit-tests.js +82 -0
  42. package/src/tests/fit-tests.js.map +1 -0
  43. package/src/tests/fit-tests.ts +95 -0
  44. package/src/tests/transform-tests.js +26 -0
  45. package/src/tests/transform-tests.js.map +1 -0
  46. package/src/tests/transform-tests.ts +21 -0
  47. package/tsconfig.json +1 -1
  48. package/webpack.config.js +1 -0
  49. package/src/fit/fit-data.js +0 -221
  50. package/src/fit/fit-data.js.map +0 -1
  51. package/src/fit/fit-data.ts +0 -335
  52. package/src/fit/transform.js +0 -73
  53. package/src/fit/transform.js.map +0 -1
  54. package/src/fit/transform.ts +0 -101
  55. package/src/tests/fit-viewer-test.js +0 -16
  56. package/src/tests/fit-viewer-test.js.map +0 -1
  57. package/src/tests/fit-viewer-test.ts +0 -11
@@ -3,7 +3,7 @@
3
3
  "tasks": [
4
4
  {
5
5
  "type": "shell",
6
- "command": "(cmd.exe /c \"webpack) -and (grok publish dev\")",
6
+ "command": "(cmd.exe /c \"npm run build) -and (grok publish dev\")",
7
7
  "label": "rebuild"
8
8
  }
9
9
  ]
package/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Curves changelog
2
+
3
+ ## 1.1.0 (2023-07-21)
4
+
5
+ This release focuses on improving analysis stability and usability.
6
+
7
+ *Dependency: datagarok-api >= 1.16.0*
8
+
9
+ ### Features
10
+
11
+ * Improved curve fitting and confidence intervals:
12
+ * Added a semantic type detector for "fit" to render fitted curves.
13
+ * Fixed performance issues during fitting.
14
+ * Automated data sorting during fitting.
15
+ * Implemented interactive parameter recalculating.
16
+ * Added different marker types.
17
+ * Improved axes cell rendering.
18
+ * Added the possibility to run curves by user-defined Javascript function.
19
+ * [#2100](https://github.com/datagrok-ai/public/issues/2100): Made cell renderer edit mode a resizeable window.
20
+ * [#2101](https://github.com/datagrok-ai/public/issues/2101): Improved curves properties and rendering:
21
+ * Don't render curves before the axes start.
22
+ * Changed margins in grid cell for axes
23
+ * Added the capability to control parameter bounds.
24
+ * Fixed curves rendering by inverting the y while converting the coordinates.
25
+ * [#2105](https://github.com/datagrok-ai/public/issues/2105): Outliers are now shown in red color and with a much bigger size.
package/README.md CHANGED
@@ -1,19 +1,98 @@
1
1
  # Curves
2
2
 
3
- **Curves** provides support for fitted curves (such as dose-response curves),
3
+ **Curves** provides support for fitted curves (such as dose-response curves),
4
4
  including in-grid rendering, storing charts in cells, interactivity, and automatic fitting.
5
5
 
6
6
  - Fitting: computing parameters of the specified function to best fit the data
7
- - Uses BFGS optimization algorithm (multi-threading for performance).
7
+ - Uses the BFGS optimization algorithm (multi-threading for performance).
8
8
  For dose-response curves, we are typically fitting the sigmoid function
9
- - Ability to dynamically register custom fitting functions
10
- - Ability to get fitting performance characteristics (r-squared, classification, etc)
9
+ - Ability to dynamically register custom fitting functions
10
+ - Automatic fit function determination
11
+ - Caching of custom fitting functions
12
+ - Ability to get fitting performance characteristics (r-squared, classification, etc.)
11
13
  - Deep integration with the Datagrok grid
12
- - Either fitting on the fly, or using the supplied function + parameters
13
- - Multiple series in one cell
14
- - Ability to define chart, marker, or fitting options (such as fit function or marker color)
14
+ - Either fitting on the fly or using the supplied function + parameters
15
+ - Multiple series in one cell
16
+ - Confidence intervals drawing
17
+ - Ability to define chart, marker, or fitting options (such as fit function or marker color)
15
18
  on the column level, with the ability to override it on a grid cell or point level
16
- - Clicking a point in a chart within a grid makes it an outlier -> curve is re-fitted on the fly
17
- - Ability to specify a chart as "reference" so that it is shown on every other chart for comparison
19
+ - Clicking a point in a chart within a grid makes it an outlier -> curve is re-fitted on the fly
20
+ - Ability to specify a chart as a "reference" so that it is shown on every other chart for comparison
18
21
  - Ability to overlay curves from multiple grid cells (special viewer)
19
- - Work with series stored in multiple formats (binary for performance, json for flexibility, etc)
22
+ - Work with series stored in multiple formats (binary for performance, JSON for flexibility, etc.)
23
+
24
+ ## Rendering fitted curves using JSON format
25
+
26
+ To render a fitted curve based on series points, you need to write it in the following JSON format:
27
+
28
+ ```json
29
+ {
30
+ "series": [
31
+ {
32
+ "fitLineColor": "#2ca02c",
33
+ "pointColor": "#2ca02c",
34
+ "showCurveConfidenceInterval": true,
35
+ "fitFunction": "sigmoid",
36
+ "parameters": [1.7391934768969721, -0.9451759934029763, 4.846020678949615, 0.15841886339211816],
37
+ "points": [
38
+ { "x": 0.10000000149011612, "y": 0.04152340441942215 },
39
+ { "x": 0.6000000238418579, "y": 0.11901605129241943 },
40
+ { "x": 1.100000023841858, "y": 0.11143334954977036 },
41
+ { "x": 1.600000023841858, "y": 0.0444009006023407 },
42
+ { "x": 2.0999999046325684, "y": 0.22933608293533325 },
43
+ { "x": 2.5999999046325684, "y": 0.3057132065296173 },
44
+ { "x": 3.0999999046325684, "y": 0.28693410754203796 },
45
+ { "x": 3.5999999046325684, "y": 0.3156140148639679 },
46
+ { "x": 4.099999904632568, "y": 0.4246906042098999 },
47
+ { "x": 4.599999904632568, "y": 0.6663704514503479 },
48
+ { "x": 5.099999904632568, "y": 1.2085251808166504 },
49
+ { "x": 5.599999904632568, "y": 1.4426130056381226 },
50
+ { "x": 6.099999904632568, "y": 1.7591952085494995 },
51
+ { "x": 6.599999904632568, "y": 1.702673077583313 },
52
+ { "x": 7.099999904632568, "y": 1.6438066959381104 }
53
+ ]
54
+ }
55
+ ],
56
+ "chartOptions": { "showStatistics": ["auc"] }
57
+ }
58
+ ```
59
+
60
+ Each series has its own `fit line color` and `point color` assigned. Additionally, each series has a boolean field
61
+ indicating whether or not to display the curve confidence intervals. The `fit function` for each series can be
62
+ either a sigmoid function or a [custom-defined function](/README.md#creating-custom-fit-function). Furthermore,
63
+ the `parameters` for the fit function can be explicitly set or left unset. If the parameters are set explicitly,
64
+ the fitting process won't be executed, and vice versa. The `data points` for each series are represented as
65
+ arrays of objects, with each object containing x and y coordinates.
66
+
67
+ Moreover, the user has the option to obtain various statistics, such as the area under the curve (`auc`) or the
68
+ coefficient of determination (`rSquared`).
69
+
70
+ ![curves](./img/curves.gif)
71
+
72
+ ## Creating custom fit function
73
+
74
+ To render a custom fit function, you need to write in the following JSON format:
75
+
76
+ ```json
77
+ "fitFunction": {
78
+ "name": "Polynomial",
79
+ "function": "([p1, p2, p3, p4], x) => p1 * x * x * x + p2 * x * x + p3 * x + p4",
80
+ "getInitialParameters": "(xs, ys) => [0.1, -1, 4, 4]",
81
+ "parameterNames": ["Slope", "Intercept", "Parameter 3", "Parameter 4"]
82
+ }
83
+ ```
84
+
85
+ Each fitting function has its own `name`. This name is used to cache the created custom function, enabling
86
+ efficient retrieval and reuse. Additionally, the fit function has `parameter names`, which are stored as
87
+ an array of strings.
88
+
89
+ Also, there are two functions: `getInitialParameters`, which takes arrays of x and y and returns determined
90
+ initial parameters values, and `function`, which takes the array of parameters and given x coordinate and
91
+ returns the result of the fit function. These functions are written as JavaScript arrow function expressions.
92
+
93
+ ![custom-fit-function](./img/custom-fit-function.gif)
94
+
95
+ See also:
96
+
97
+ - [Packages](../../help/develop/develop.md#packages)
98
+ - [JavaScript API](../../help/develop/js-api.md)
package/detectors.js CHANGED
@@ -6,13 +6,15 @@
6
6
  * Follow this naming convention to ensure that your detectors are properly loaded.
7
7
  */
8
8
  const FIT_SEM_TYPE = 'fit';
9
+ const TAG_FIT_CHART_FORMAT = '.fitChartFormat';
10
+ const TAG_FIT_CHART_FORMAT_3DX = '3dx';
9
11
  class CurvesPackageDetectors extends DG.Package {
10
12
  //tags: semTypeDetector
11
13
  //input: column col
12
14
  //output: string semType
13
15
  detectXMLCurveChart(col) {
14
16
  if (DG.Detector.sampleCategories(col, (s) => s.startsWith('<chart>') && s.endsWith('</chart>'), 1)) {
15
- col.setTag('.fitChartFormat', '3dx');
17
+ col.setTag(TAG_FIT_CHART_FORMAT, TAG_FIT_CHART_FORMAT_3DX);
16
18
  col.semType = FIT_SEM_TYPE;
17
19
  return col.semType;
18
20
  }
@@ -24,8 +26,8 @@ class CurvesPackageDetectors extends DG.Package {
24
26
  //output: string semType
25
27
  detectFit(col) {
26
28
  if (DG.Detector.sampleCategories(col, (s) => {
27
- return s.includes('series') && s.includes('points') && s.includes('parameters') &&
28
- s.includes('fitLineColor') && s.includes('pointColor') && s.includes('showCurveConfidenceInterval');
29
+ return s.includes('series') && s.includes('points') && s.includes('fitLineColor') &&
30
+ s.includes('pointColor') && s.includes('showCurveConfidenceInterval');
29
31
  }, 1)) {
30
32
  col.semType = FIT_SEM_TYPE;
31
33
  return col.semType;