@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
@@ -1,335 +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
- FitResult, fitResultProperties,
12
- sigmoid
13
- } from '@datagrok-libraries/statistics/src/parameter-estimation/fit-curve';
14
-
15
- /**
16
- * Datagrok curve fitting
17
- *
18
- * - Fitting: computing parameters of the specified function to best fit the data
19
- * - Uses BFGS optimization algorithm (multi-threading for performance).
20
- * For dose-response curves, we are typically fitting the sigmoid function
21
- * - Ability to dynamically register custom fitting functions
22
- * - Ability to get fitting performance characteristics (r-squared, classification, etc)
23
- * - Deep integration with the Datagrok grid
24
- * - Either fitting on the fly, or using the supplied function + parameters
25
- * - Multiple series in one cell
26
- * - Ability to define chart, marker, or fitting options (such as fit function or marker color)
27
- * on the column level, with the ability to override it on a grid cell or point level
28
- * - Clicking a point in a chart within a grid makes it an outlier -> curve is re-fitted on the fly
29
- * - Ability to specify a chart as "reference" so that it is shown on every other chart for comparison
30
- * - Ability to overlay curves from multiple grid cells (special viewer)
31
- * - Work with series stored in multiple formats (binary for performance, json for flexibility, etc)
32
- */
33
-
34
- export const FIT_SEM_TYPE = 'fit';
35
- export const FIT_CELL_TYPE = 'fit';
36
- export const TAG_FIT = '.fit';
37
- export const TAG_FIT_CHART_FORMAT = '.fitChartFormat';
38
- export const TAG_FIT_CHART_FORMAT_3DX = '3dx';
39
-
40
- export const CONFIDENCE_INTERVAL_STROKE_COLOR = 'rgba(255,191,63,0.7)';
41
- export const CONFIDENCE_INTERVAL_FILL_COLOR = 'rgba(255,238,204,0.3)';
42
-
43
- export const CURVE_CONFIDENCE_INTERVAL_BOUNDS = {
44
- TOP: 'top',
45
- BOTTOM: 'bottom'
46
- };
47
-
48
- export type FitMarkerType = 'circle' | 'triangle up' | 'triangle down' | 'cross';
49
-
50
- /** A point in the fit series. Only x and y are required. Can override some fields defined in IFitSeriesOptions. */
51
- export interface IFitPoint {
52
- x: number;
53
- y: number;
54
- outlier?: boolean; // if true, renders as 'x' and gets ignored for curve fitting
55
- minY?: number; // when defined, the marker renders as a candlestick with whiskers [minY, maxY]
56
- maxY?: number; // when defined, the marker renders as a candlestick with whiskers [minY, maxY]
57
- marker?: FitMarkerType; // overrides the marker type defined in IFitSeriesOptions
58
- color?: string; // overrides the marker color defined in IFitSeriesOptions
59
- }
60
-
61
-
62
- /** Series options can be either applied globally on a column level, or partially overridden in particular series */
63
- export interface IFitSeriesOptions {
64
- name?: string;
65
- fitFunction?: string;
66
- parameters?: number[]; // auto-fitting when not defined
67
- pointColor?: string;
68
- fitLineColor?: string;
69
- confidenceIntervalColor?: string;
70
- showFitLine?: boolean;
71
- showPoints?: boolean;
72
- showCurveConfidenceInterval?: boolean; // show ribbon
73
- showIntercept?: boolean;
74
- showBoxPlot?: boolean; // if true, multiple values with the same X are rendered as a candlestick
75
- showConfidenceForX?: number;
76
-
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
- export class FitChartData implements IFitChartData {
115
- chartOptions: IFitChartOptions = {};
116
- seriesOptions: IFitSeriesOptions = {}; // Default series options. Individual series can override it.
117
- series: IFitSeries[] = [];
118
- }
119
-
120
-
121
- /** Properties that describe {@link IFitChartOptions}. Useful for editing, initialization, transformations, etc. */
122
- export const fitChartDataProperties: Property[] = [
123
- // Style and zoom
124
- Property.js('minX', TYPE.FLOAT, {description: 'Minimum value of the X axis', nullable: true}),
125
- Property.js('minY', TYPE.FLOAT, {description: 'Minimum value of the Y axis', nullable: true}),
126
- Property.js('maxX', TYPE.FLOAT, {description: 'Maximum value of the X axis', nullable: true}),
127
- Property.js('maxY', TYPE.FLOAT, {description: 'Maximum value of the Y axis', nullable: true}),
128
- Property.js('xAxisName', TYPE.STRING, {description:
129
- 'Label to show on the X axis. If not specified, corresponding data column name is used', nullable: true}),
130
- Property.js('yAxisName', TYPE.STRING, {description:
131
- 'Label to show on the Y axis. If not specified, corresponding data column name is used', nullable: true}),
132
- Property.js('logX', TYPE.BOOL, {defaultValue: false}),
133
- Property.js('logY', TYPE.BOOL, {defaultValue: false}),
134
- Property.js('showStatistics', TYPE.STRING_LIST, { choices: fitResultProperties.map(frp => frp.name) }),
135
- ];
136
-
137
-
138
- /** Properties that describe {@link IFitSeriesOptions}. Useful for editing, initialization, transformations, etc. */
139
- export const fitSeriesProperties: Property[] = [
140
- Property.js('name', TYPE.STRING),
141
- Property.js('fitFunction', TYPE.STRING,
142
- {category: 'Fitting', choices: ['sigmoid', 'linear'], defaultValue: 'sigmoid'}),
143
- Property.js('pointColor', TYPE.STRING,
144
- {category: 'Rendering', defaultValue: DG.Color.toHtml(DG.Color.scatterPlotMarker), nullable: true}),
145
- Property.js('fitLineColor', TYPE.STRING,
146
- {category: 'Rendering', defaultValue: DG.Color.toHtml(DG.Color.scatterPlotMarker), nullable: true}),
147
- Property.js('clickToToggle', TYPE.BOOL, {category: 'Fitting', description:
148
- 'If true, clicking on the point toggles its outlier status and causes curve refitting', nullable: true}),
149
- Property.js('autoFit', TYPE.BOOL,
150
- {category: 'Fitting', description: 'Perform fitting on-the-fly', defaultValue: true}),
151
- Property.js('showFitLine', TYPE.BOOL,
152
- {category: 'Fitting', description: 'Whether the fit line should be rendered', defaultValue: true}),
153
- Property.js('showPoints', TYPE.BOOL,
154
- {category: 'Fitting', description: 'Whether points should be rendered', defaultValue: true}),
155
- ];
156
-
157
-
158
- /** Creates new object with the default values specified in {@link properties} */
159
- function createFromProperties(properties: Property[]): any {
160
- const o: any = {};
161
- for (const p of properties) {
162
- if (p.defaultValue != null)
163
- o[p.name] = p.defaultValue;
164
- }
165
- return o;
166
- }
167
-
168
-
169
- /** Merges properties of the two objects by iterating over the specified {@link properties}
170
- * and assigning properties from {@link source} to {@link target} only when
171
- * the property is not defined in target and is defined in source. */
172
- export function mergeProperties(properties: Property[], source: any, target: any) {
173
- if (!source || !target)
174
- return;
175
-
176
- for (const p of properties) {
177
- if (!(p.name in target) && p.name in source)
178
- target[p.name] = source[p.name];
179
- }
180
- }
181
-
182
-
183
- function createDefaultChartData(): IFitChartData {
184
- return {
185
- chartOptions: createFromProperties(fitChartDataProperties),
186
- seriesOptions: createFromProperties(fitSeriesProperties)
187
- };
188
- }
189
-
190
-
191
- /** Returns existing, or creates new column default chart options. */
192
- export function getColumnChartOptions(gridColumn: DG.GridColumn): IFitChartData {
193
- return gridColumn.temp[TAG_FIT] ??= createDefaultChartData();
194
- }
195
-
196
-
197
- export function getChartBounds(chartData: IFitChartData): DG.Rect {
198
- const o = chartData.chartOptions;
199
- if (o?.minX && o.minY && o.maxX && o.maxY)
200
- return new DG.Rect(o.minX, o.minY, o.maxX - o.minX, o.maxY - o.minY);
201
- if (!chartData.series?.length || chartData.series.length == 0) {
202
- return new DG.Rect(0, 0, 1, 1);
203
- } else {
204
- let bounds = getDataBounds(chartData.series[0].points);
205
- for (let i = 1; i < chartData.series!.length; i++)
206
- bounds = bounds.union(getDataBounds(chartData.series[i].points));
207
- return bounds;
208
- }
209
- }
210
-
211
-
212
- //TODO: move to DG.Rect
213
- export function getDataBounds(points: IFitPoint[]): DG.Rect {
214
- let minX = points[0].x;
215
- let minY = points[0].y;
216
- let maxX = points[0].x;
217
- let maxY = points[0].y;
218
-
219
- for (let i = 1; i < points.length; i++) {
220
- minX = Math.min(minX, points[i].x);
221
- minY = Math.min(minY, points[i].y);
222
- maxX = Math.max(maxX, points[i].x);
223
- maxY = Math.max(maxY, points[i].y);
224
- }
225
-
226
- return new DG.Rect(minX, minY, maxX - minX, maxY - minY);
227
- }
228
-
229
-
230
- /** Fits the series data according to the series fitting settings */
231
- export function fitSeries(series: IFitSeries, statistics: boolean = false): FitResult {
232
- //TODO: optimize the calculation of the initial parameters
233
- const dataBounds = getDataBounds(series.points);
234
- // const ys = series.points.map((p) => p.y);
235
- // const medY = ys[Math.floor(series.points.length / 2)];
236
- const medY = (dataBounds.bottom - dataBounds.top) / 2 + dataBounds.top;
237
- let xAtMedY = -1;
238
- // for (let i = 0; i < series.points.length; i++) {
239
- // if (series.points[i].y === medY) {
240
- // xAtMedY = series.points[i].x;
241
- // break;
242
- // }
243
- // }
244
- let maxYInterval = dataBounds.bottom - dataBounds.top;
245
- let nearestXIndex = 0;
246
- for (let i = 0; i < series.points.length; i++) {
247
- const currentInterval = Math.abs(series.points[i].y - medY);
248
- if (currentInterval < maxYInterval) {
249
- maxYInterval = currentInterval;
250
- nearestXIndex = i;
251
- }
252
- }
253
- xAtMedY = series.points[nearestXIndex].x;
254
-
255
- let slope = series.points[0].y > series.points[series.points.length - 1].y ? 1.2 : -1.2;
256
-
257
- // params are: [max, tan, IC50, min]
258
- const initialParams = [{value: dataBounds.bottom}, {value: slope}, {value: xAtMedY}, {value: dataBounds.top}];
259
-
260
- return fit(
261
- {x: series.points.map((p) => p.x), y: series.points.map((p) => p.y)},
262
- initialParams, sigmoid, FitErrorModel.Constant, 0.05, statistics);
263
- }
264
-
265
- /** Returns a curve function, either using the pre-computed parameters
266
- * or by fitting on-the-fly */
267
- export function getFittedCurve(series: IFitSeries): (x: number) => number {
268
- if (series.parameters)
269
- return (x) => sigmoid(series.parameters!, x);
270
- else
271
- return fitSeries(series).fittedCurve;
272
- }
273
-
274
- /** Returns confidence interval functions */
275
- export function getConfidenceIntrevals(series: IFitSeries): {top: (x: number) => number, bottom: (x: number) => number} {
276
- const confTop = fitSeries(series).confidenceTop;
277
- const confBottom = fitSeries(series).confidenceBottom;
278
- return {top: confTop, bottom: confBottom};
279
- }
280
-
281
- /** Constructs {@link IFitChartData} from the grid cell, taking into account
282
- * chart and fit settings potentially defined on the dataframe and column level. */
283
- export function getChartData(gridCell: DG.GridCell): IFitChartData {
284
- const cellChartData: IFitChartData = gridCell.cell?.column?.type == DG.TYPE.STRING ?
285
- (JSON.parse(gridCell.cell.value ?? '{}') ?? {}) : createDefaultChartData();
286
-
287
- const columnChartOptions = getColumnChartOptions(gridCell.gridColumn);
288
-
289
- cellChartData.series ??= [];
290
- cellChartData.chartOptions ??= columnChartOptions.chartOptions;
291
-
292
- // merge cell options with column options
293
- mergeProperties(fitChartDataProperties, columnChartOptions.chartOptions, cellChartData.chartOptions);
294
- for (const series of cellChartData.series)
295
- mergeProperties(fitSeriesProperties, columnChartOptions.seriesOptions, series);
296
-
297
- return cellChartData;
298
- }
299
-
300
-
301
- const sample: IFitChartData = {
302
- // chartOptions could be retrieved either from the column, or from the cell
303
- 'chartOptions': {
304
- 'minX': 0, 'minY': 0, 'maxX': 5, 'maxY': 10,
305
- 'xAxisName': 'concentration',
306
- 'yAxisName': 'activity',
307
- 'logX': false,
308
- 'logY': false,
309
- },
310
- // These options are used as default options for the series. They could be overridden in series.
311
- 'seriesOptions': {
312
- 'fitFunction': 'sigmoid',
313
- // parameters not specified -> auto-fitting by default
314
- 'pointColor': 'blue',
315
- 'fitLineColor': 'red',
316
- 'clickToToggle': true,
317
- 'showPoints': true,
318
- 'showFitLine': true,
319
- 'showCurveConfidenceInterval': true
320
- },
321
- 'series': [
322
- {
323
- 'fitFunction': 'sigmoid',
324
- // parameters specified -> use them, no autofitting
325
- 'parameters': [1.86011e-07, -0.900, 103.748, -0.001],
326
- 'points': [
327
- {'x': 0, 'y': 0},
328
- {'x': 1, 'y': 0.5},
329
- {'x': 2, 'y': 1},
330
- {'x': 3, 'y': 10, 'outlier': true},
331
- {'x': 4, 'y': 0}
332
- ]
333
- }
334
- ]
335
- };
@@ -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
@@ -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AI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClI,CAAC;CACF"}
@@ -1,101 +0,0 @@
1
- import * as DG from 'datagrok-api/dg';
2
- import {Paint} from "datagrok-api/dg";
3
-
4
-
5
- /** Represents 1D transformation between screen and world coordinates */
6
- interface ITransform {
7
- screenToWorld(screen: number, length: number, min: number, max: number, inverse?: boolean): number;
8
- worldToScreen(world: number, length: number, min: number, max: number, inverse?: boolean): number;
9
- }
10
-
11
-
12
- /** Linear transformation */
13
- class _LinearTransform implements ITransform {
14
- screenToWorld(screen: number, length: number, min: number, max: number, inverse?: boolean) {
15
- const d = inverse ? 1 - screen / length: screen / length;
16
- return min + d * (max - min);
17
- }
18
-
19
- worldToScreen(world: number, length: number, min: number, max: number, inverse?: boolean) {
20
- return inverse
21
- ? ((1 - ((world - min)) / (max - min)) * length)
22
- : ((world - min) / (max - min) * length);
23
- }
24
- }
25
-
26
-
27
- /** Log transformation */
28
- class _LogTransform implements ITransform {
29
- screenToWorld(screen: number, length: number, min: number, max: number, inverse?: boolean) {
30
- min = (min < 0.00000001 ? 0.00000001 : min);
31
-
32
- const maxLog = Math.log(max);
33
- const minLog = Math.log(min);
34
- return Math.exp(minLog + (maxLog - minLog) * (inverse ? length - screen : screen) / length);
35
- }
36
-
37
- worldToScreen(world: number, length: number, min: number, max: number, inverse?: boolean) {
38
- if (world <= 0) return NaN;
39
-
40
- //eliminates problems with rounding
41
- if (world == min) return inverse ? length : 0.0;
42
- if (world == max) return inverse ? 0.0 : length;
43
-
44
- min = (min < 0.00000001 ? 0.00000001 : min);
45
- world = (world < 0.00000001 ? 0.00000001 : world);
46
-
47
- const res = (length * Math.log(world / min) / Math.log(max / min));
48
- return inverse ? length - res : res;
49
- }
50
- }
51
-
52
-
53
- const linearTransform = new _LinearTransform();
54
- const logTransform = new _LogTransform();
55
-
56
-
57
- /** Provides convenient methods for mapping between screen and world coordinates */
58
- export class Viewport {
59
- world: DG.Rect;
60
- screen: DG.Rect;
61
- logX: boolean = false;
62
- logY: boolean = false;
63
- inverseX: boolean = false;
64
- inverseY: boolean = true;
65
-
66
- get xt(): ITransform { return this.logX ? logTransform : linearTransform; }
67
- get yt(): ITransform { return this.logY ? logTransform : linearTransform; }
68
-
69
- constructor(world: DG.Rect, screen: DG.Rect, logX = false, logY = false) {
70
- this.world = world;
71
- this.screen = screen;
72
- this.logX = logX;
73
- this.logY = logY;
74
- }
75
-
76
- xToScreen(world: number): number {
77
- return this.screen.left + this.xt.worldToScreen(world, this.screen.width, this.world.minX, this.world.maxX, this.inverseX);
78
- }
79
-
80
- yToScreen(world: number): number {
81
- return this.screen.top + this.yt.worldToScreen(world, this.screen.height, this.world.minY, this.world.maxY, this.inverseY);
82
- }
83
-
84
- xToWorld(screen: number): number {
85
- return this.xt.worldToScreen(screen, this.screen.width, this.world.minX, this.world.maxX, this.inverseX);
86
- }
87
-
88
- yToWorld(screen: number): number {
89
- return this.yt.worldToScreen(screen, this.screen.height, this.world.minY, this.world.maxY, this.inverseY);
90
- }
91
-
92
- toScreen(world: DG.Point): DG.Point { return new DG.Point(this.xToScreen(world.x), this.yToScreen(world.y)); }
93
- toWorld(screen: DG.Point): DG.Point { return new DG.Point(this.xToWorld(screen.x), this.yToWorld(screen.y)); }
94
-
95
- drawCoordinateGrid(g: CanvasRenderingContext2D, xAxis: DG.Rect | undefined, yAxis: DG.Rect | undefined) {
96
- if (xAxis)
97
- DG.Paint.horzAxis(g, this.world.minX, this.world.maxX, xAxis.x, xAxis.y, xAxis.width, xAxis.height, this.logX, this.inverseX);
98
- if (yAxis)
99
- DG.Paint.vertAxis(g, this.world.minY, this.world.maxY, yAxis.x, yAxis.y, yAxis.width, yAxis.height, this.logY, this.inverseY);
100
- }
101
- }
@@ -1,16 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { category, expect, test } from '@datagrok-libraries/utils/src/test';
11
- category('Fit', () => {
12
- test('test', () => __awaiter(void 0, void 0, void 0, function* () {
13
- expect('test', 'test');
14
- }));
15
- });
16
- //# sourceMappingURL=fit-viewer-test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fit-viewer-test.js","sourceRoot":"","sources":["fit-viewer-test.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAC,MAAM,oCAAoC,CAAC;AAG1E,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE;IACnB,IAAI,CAAC,MAAM,EAAE,GAAS,EAAE;QACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzB,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,11 +0,0 @@
1
- import * as grok from 'datagrok-api/grok';
2
- import * as DG from 'datagrok-api/dg';
3
-
4
- import {category, expect, test} from '@datagrok-libraries/utils/src/test';
5
-
6
-
7
- category('Fit', () => {
8
- test('test', async () => {
9
- expect('test', 'test');
10
- });
11
- });