-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAutoIntegrateMetricsVisualizer.js
More file actions
677 lines (573 loc) · 25.6 KB
/
AutoIntegrateMetricsVisualizer.js
File metadata and controls
677 lines (573 loc) · 25.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
// AutoIntegrate Astro Image Metrics Visualizer Dialog
// For SubFrame Selector metrics visualization
#ifndef AUTOINTEGRATEMETRICSVISUALIZER_JS
#define AUTOINTEGRATEMETRICSVISUALIZER_JS
function AutoIntegrateMetricsVisualizer(global)
{
this.__base__ = Object;
this.__base__();
var dialog;
var WINDOW_TITLE = "AutoIntegrate Metrics Visualizer";
// Sample data structure - replace with your actual metrics arrays
var metricsData = [
{ name: "fwhm", data: [2.1, 2.3, 1.8, 2.5, 2.0, 2.2, 1.9, 2.4, 2.1, 1.7], limit: 0.0, filter_high: true },
{ name: "eccentricity", data: [0.15, 0.22, 0.18, 0.28, 0.12, 0.19, 0.16, 0.25, 0.14, 0.11], limit: 0.0, filter_high: true },
{ name: "snr", data: [45.2, 38.7, 52.1, 33.8, 48.9, 41.3, 46.7, 35.2, 49.8, 54.3], limit: 0.0, filter_high: true },
{ name: "stars", data: [0.85, 0.72, 0.91, 0.65, 0.88, 0.78, 0.83, 0.69, 0.87, 0.93], limit: 0.0, filter_high: false }
];
var metricsFilteredOut = [];
var alwaysFilteredOut = []; // Input metrics that are always filtered out
var numberOfDataSets = 0;
// Custom plotting control
function PlotControl(parent, metrics, stats, color) {
this.__base__ = Control;
this.__base__(parent);
this.metrics = metrics;
this.title = metrics.name;
this.data = metrics.data;
this.filter_high = metrics.filter_high;
this.plotColor = color || 0xFF0066CC; // Default blue
this.margin = 40;
this.preferredWidth = 500;
this.preferredHeight = 250;
this.plot_limit = metrics.limit || 0.0;
this.toolTip = "<p>Plot for " + this.title + " metric.<br>" +
"Set a limit to filter out values.<br>" +
"Current limit: " + this.plot_limit.toFixed(8) +
(this.filter_high ? " (Max)" : " (Min)") + "<p>" +
"<p>Gray points indicate values filtered out by outliers.<br>" +
"White points indicate values filtered out by the current limits.</p>" +
"<p>Green lines indicate one sigma limits.<br>" +
"Red lines indicate two sigma limits.</p>" +
"<p><b>Double-click on the plot to set the limit at that Y-axis value.</b></p>";
if (this.title == 'None') {
this.enabled = false;
}
this.setMinSize(this.preferredWidth, this.preferredHeight);
// Calculate data statistics
this.minValue = Math.min.apply(Math, this.data);
this.maxValue = Math.max.apply(Math, this.data);
this.range = this.maxValue - this.minValue;
// Store reference to the limit edit control (will be set later)
this.limitEdit = null;
// Mouse event handling for double-click to set limit
this.onMouseDoubleClick = function(x, y, button, buttonState, modifiers) {
// Calculate plot area
var plotX = this.margin;
var plotY = this.margin;
var plotWidth = this.width - 2 * this.margin;
var plotHeight = this.height - 2 * this.margin;
// Check if click is within plot area
if (x >= plotX && x <= plotX + plotWidth &&
y >= plotY && y <= plotY + plotHeight) {
// Convert Y coordinate to data value
var normalizedY = (plotY + plotHeight - y) / plotHeight;
var dataValue = this.minValue + (normalizedY * this.range);
// Update the limit
this.plot_limit = dataValue;
this.metrics.limit = dataValue;
// Update the limit edit control if available
if (this.limitEdit) {
this.limitEdit.setValue(dataValue);
}
// Update the dialog
dialog.updateData();
console.writeln("Limit set to " + dataValue.toFixed(8) + " for " + this.title);
}
};
this.onPaint = function(x0, y0, x1, y1) {
// console.writeln("PlotControl onPaint: " + this.title + " plot_limit " + this.plot_limit);
var graphics = new Graphics(this);
graphics.fillRect(this.boundsRect, new Brush(0xFF2D2D30)); // Dark background
// Calculate plot area
var plotX = this.margin;
var plotY = this.margin;
var plotWidth = this.width - 2 * this.margin;
var plotHeight = this.height - 2 * this.margin;
// Draw plot background
graphics.fillRect(new Rect(plotX, plotY, plotX + plotWidth, plotY + plotHeight),
new Brush(0xFF1E1E1E));
// Draw border
graphics.pen = new Pen(0xFF404040, 1);
graphics.drawRect(plotX, plotY, plotX + plotWidth, plotY + plotHeight);
// Draw title
graphics.pen = new Pen(0xFFFFFFFF);
graphics.font = new Font("Arial", 12);
var titleWidth = graphics.font.width(this.title);
graphics.drawText((this.width - titleWidth) / 2, 20, this.title);
// Draw grid lines
graphics.pen = new Pen(0xFF404040, 1);
for (var i = 1; i < 5; i++) {
var y = plotY + (plotHeight * i / 5);
graphics.drawLine(plotX, y, plotX + plotWidth, y);
}
// Draw one sigma and two sigma lines at the top and bottom
if (this.range > 0) {
// Draw upper limits
var oneSigma = stats.mean + stats.stdDev;
var twoSigma = stats.mean + (stats.stdDev * 2);
var oneSigmaY = plotY + plotHeight - (plotHeight * (oneSigma - this.minValue) / this.range);
var twoSigmaY = plotY + plotHeight - (plotHeight * (twoSigma - this.minValue) / this.range);
if (oneSigmaY > plotY) {
graphics.pen = new Pen(0xFF008000, 1); // Green for one sigma
graphics.drawLine(plotX, oneSigmaY, plotX + plotWidth, oneSigmaY);
}
if (twoSigmaY > plotY) {
graphics.pen = new Pen(0xFFCD5C5C, 1); // Red for two sigma
graphics.drawLine(plotX, twoSigmaY, plotX + plotWidth, twoSigmaY);
}
// Draw lower limits
var oneSigmaLow = stats.mean - stats.stdDev;
var twoSigmaLow = stats.mean - (stats.stdDev * 2);
var oneSigmaLowY = plotY + plotHeight - (plotHeight * (oneSigmaLow - this.minValue) / this.range);
var twoSigmaLowY = plotY + plotHeight - (plotHeight * (twoSigmaLow - this.minValue) / this.range);
if (oneSigmaLowY < plotY + plotHeight) {
graphics.pen = new Pen(0xFF008000, 1); // Green for one sigma
graphics.drawLine(plotX, oneSigmaLowY, plotX + plotWidth, oneSigmaLowY);
}
if (twoSigmaLowY < plotY + plotHeight) {
// Draw two sigma line
graphics.pen = new Pen(0xFFCD5C5C, 1); // Red for two sigma
graphics.drawLine(plotX, twoSigmaLowY, plotX + plotWidth, twoSigmaLowY);
}
}
// Draw current limit line if set
if (this.plot_limit != 0.0 && this.range > 0) {
var limitY = plotY + plotHeight - (plotHeight * (this.plot_limit - this.minValue) / this.range);
if (limitY >= plotY && limitY <= plotY + plotHeight) {
graphics.pen = new Pen(0xFFFFFF00, 2); // Yellow for limit line
graphics.drawLine(plotX, limitY, plotX + plotWidth, limitY);
// Draw limit value label
graphics.font = new Font("Arial", 10);
var limitLabel = "Limit: " + this.plot_limit.toFixed(4);
var labelWidth = graphics.font.width(limitLabel);
graphics.fillRect(new Rect(plotX + plotWidth - labelWidth - 10, limitY - 12,
plotX + plotWidth - 5, limitY - 2),
new Brush(0xFF2D2D30));
graphics.pen = new Pen(0xFFFFFF00);
graphics.drawText(plotX + plotWidth - labelWidth - 8, limitY - 2, limitLabel);
}
}
// Draw data points and lines
if (this.data.length > 0) {
graphics.pen = new Pen(this.plotColor, 2);
graphics.antialiasing = true;
var points = [];
var accept_count = 0;
for (var i = 0; i < this.data.length; i++) {
var x = plotX + (plotWidth * i / (this.data.length - 1));
var normalizedValue = (this.data[i] - this.minValue) / this.range;
var y = plotY + plotHeight - (plotHeight * normalizedValue);
// Count filtering for this metric
if (this.plot_limit == 0.0) {
accept_count++;
} else if (this.filter_high) {
if (this.data[i] <= this.plot_limit) {
accept_count++;
}
} else {
if (this.data[i] >= this.plot_limit) {
accept_count++;
}
}
points.push(new Point(x, y));
}
if (0) {
// Draw connecting lines
for (var i = 0; i < points.length - 1; i++) {
graphics.drawLine(points[i], points[i + 1]);
}
}
// Draw data points
for (var i = 0; i < points.length; i++) {
if (alwaysFilteredOut[i]) {
// Gray points always filtered out by outliers
graphics.brush = new Brush(0xffC0C0C0);
} else if (metricsFilteredOut[i]) {
// White points filtered out by limits
graphics.brush = new Brush(0xFFFFFFFF);
} else {
graphics.brush = new Brush(this.plotColor);
}
graphics.fillCircle(points[i], 2);
}
// Draw value labels
graphics.pen = new Pen(0xFFCCCCCC);
graphics.font = new Font("Arial", 8);
// Y-axis labels
for (var i = 0; i <= 5; i++) {
if (i == 0) {
var value = this.minValue;
} else if (i == 5) {
var value = this.maxValue;
} else {
// Calculate intermediate values
var value = this.minValue + (this.range * i / 5);
}
// Calculate Y position for label
var y = plotY + plotHeight - (plotHeight * i / 5);
// Adaptive change the number of decimals based on range
if (this.range < 10.0) {
var label = value.toFixed(4);
} else if (this.range < 100.0) {
var label = value.toFixed(3);
} else if (this.range < 1000.0) {
var label = value.toFixed(2);
} else {
var label = value.toFixed(1);
}
// graphics.drawText(5, y - 4, label);
graphics.drawText(5, y, label);
}
if (0) {
// X-axis labels (frame numbers)
for (var i = 0; i < Math.min(this.data.length, 10); i += Math.max(1, Math.floor(this.data.length / 10))) {
var x = plotX + (plotWidth * i / (this.data.length - 1));
graphics.drawText(x - 5, plotY + plotHeight + 15, (i + 1).toString());
}
}
this.dataLabel.text = accept_count + " / " + this.data.length;
} else {
this.dataLabel.text = "";
}
graphics.end();
};
}
PlotControl.prototype = new Control;
// Statistics panel
function StatsControl(parent, title, data) {
this.__base__ = Control;
this.__base__(parent);
this.title = title;
this.data = data;
if (title == 'None') {
this.visible = false;
return;
}
// Calculate statistics
var sum = this.data.reduce(function(a, b) { return a + b; }, 0);
this.mean = sum / this.data.length;
this.min = Math.min.apply(Math, this.data);
this.max = Math.max.apply(Math, this.data);
var variance = this.data.reduce(function(acc, val) {
return acc + Math.pow(val - this.mean, 2);
}.bind(this), 0) / this.data.length;
this.stdDev = Math.sqrt(variance);
// Create labels for statistics
this.titleLabel = new Label(this);
this.titleLabel.text = this.title + " Statistics:";
this.titleLabel.textAlignment = TextAlign_Left|TextAlign_VertCenter;
this.titleLabel.styleSheet = "font-weight: bold;";
this.meanLabel = new Label(this);
this.meanLabel.text = "Mean: " + this.mean.toFixed(8);
this.meanLabel.textAlignment = TextAlign_Left|TextAlign_VertCenter;
this.minLabel = new Label(this);
this.minLabel.text = "Min: " + this.min.toFixed(8);
this.minLabel.textAlignment = TextAlign_Left|TextAlign_VertCenter;
this.maxLabel = new Label(this);
this.maxLabel.text = "Max: " + this.max.toFixed(8);
this.maxLabel.textAlignment = TextAlign_Left|TextAlign_VertCenter;
this.stdDevLabel = new Label(this);
this.stdDevLabel.text = "Std Dev: " + this.stdDev.toFixed(8);
this.stdDevLabel.textAlignment = TextAlign_Left|TextAlign_VertCenter;
// Layout
this.sizer = new VerticalSizer;
this.sizer.margin = 6;
this.sizer.spacing = 2;
this.sizer.add(this.titleLabel);
this.sizer.addSpacing(4);
this.sizer.add(this.meanLabel);
this.sizer.add(this.minLabel);
this.sizer.add(this.maxLabel);
this.sizer.add(this.stdDevLabel);
this.sizer.addStretch();
}
StatsControl.prototype = new Control;
function newLimitEdit(parent, title, plot) {
var limitEdit = new NumericEdit(parent);
if (title == 'None') {
limitEdit.enabled = false;
}
limitEdit.real = true;
limitEdit.textAlignment = TextAlign_Left|TextAlign_VertCenter;
limitEdit.label.text = title + " Limit" + (plot.filter_high ? " (Max)" : " (Min)");
limitEdit.label.textAlignment = TextAlign_Left|TextAlign_VertCenter;
limitEdit.minWidth = 50;
limitEdit.setPrecision( 8 );
limitEdit.setRange(0, 1000000);
limitEdit.setValue(plot.plot_limit || 0.0);
limitEdit.plot = plot;
if (limitEdit.plot.filter_high) {
limitEdit.toolTip = "Set the maximum value for " + title + " metric. Values above this limit will be filtered out.";
} else {
limitEdit.toolTip = "Set the minimum value for " + title + " metric. Values below this limit will be filtered out.";
}
limitEdit.onValueUpdated = function(value) {
// console.writeln("Limit Updated: " + value + " for " + this.label.text);
this.plot.plot_limit = value;
this.plot.metrics.limit = value;
// Update plot with new limit
dialog.updateData();
};
return limitEdit;
}
function newLabel(parent)
{
var lbl = new Label( parent );
lbl.text = "";
lbl.textAlignment = TextAlign_Right|TextAlign_VertCenter;
return lbl;
}
// Main dialog
function AstroMetricsDialog() {
this.__base__ = Dialog;
this.__base__();
this.windowTitle = WINDOW_TITLE;
// this.minWidth = 800;
if (numberOfDataSets > 2) {
this.minHeight = 780;
} else {
this.minHeight = 600;
}
this.subtitleLabel = new Label(this);
this.subtitleLabel.text = "Update limit value or double click on the plot to set limit.";
this.subtitleLabel.textAlignment = TextAlign_Center;
this.subtitleLabel.styleSheet = "font-size: 9pt; color: #888888; font-style: italic;";
this.totalLabel = newLabel(this);
this.totalLabel.textAlignment = TextAlign_Center;
this.totalLabel.styleSheet = "font-size: 9pt; color: #888888; font-style: italic;";
// Sizer for the total accepted frames
this.totatitleLabelSizer = new VerticalSizer;
this.totatitleLabelSizer.add(this.subtitleLabel);
this.totatitleLabelSizer.add(this.totalLabel);
this.totatitleLabelSizer.addStretch();
// Create statistics panels
this.data1Stats = new StatsControl(this, metricsData[0].name, metricsData[0].data);
this.data2Stats = new StatsControl(this, metricsData[1].name, metricsData[1].data);
this.data3Stats = new StatsControl(this, metricsData[2].name, metricsData[2].data);
this.data4Stats = new StatsControl(this, metricsData[3].name, metricsData[3].data);
// Create plot controls for each metric
this.data1Plot = new PlotControl(this, metricsData[0], this.data1Stats, 0xFF00AA00);
this.data2Plot = new PlotControl(this, metricsData[1], this.data2Stats, 0xFFFF6600);
this.data3Plot = new PlotControl(this, metricsData[2], this.data3Stats, 0xFF0066FF);
this.data4Plot = new PlotControl(this, metricsData[3], this.data4Stats, 0xFFCC0066);
// Edit fields for limits
this.data1LimitEdit = newLimitEdit(this, metricsData[0].name, this.data1Plot);
this.data2LimitEdit = newLimitEdit(this, metricsData[1].name, this.data2Plot);
this.data3LimitEdit = newLimitEdit(this, metricsData[2].name, this.data3Plot);
this.data4LimitEdit = newLimitEdit(this, metricsData[3].name, this.data4Plot);
// Link the plot controls to their limit edit controls
this.data1Plot.limitEdit = this.data1LimitEdit;
this.data2Plot.limitEdit = this.data2LimitEdit;
this.data3Plot.limitEdit = this.data3LimitEdit;
this.data4Plot.limitEdit = this.data4LimitEdit;
this.data1Label = newLabel(this);
this.data1Plot.dataLabel = this.data1Label;
this.data2Label = newLabel(this);
this.data2Plot.dataLabel = this.data2Label;
this.data3Label = newLabel(this);
this.data3Plot.dataLabel = this.data3Label;
this.data4Label = newLabel(this);
this.data4Plot.dataLabel = this.data4Label;
// Sizer for the edit fields
this.data1LimitEditSizer = new HorizontalSizer;
this.data1LimitEditSizer.addSpacing(4);
this.data1LimitEditSizer.add(this.data1LimitEdit);
this.data1LimitEditSizer.addSpacing(20);
this.data1LimitEditSizer.add(this.data1Label);
this.data1LimitEditSizer.addStretch();
this.data2LimitEditSizer = new HorizontalSizer;
this.data2LimitEditSizer.addSpacing(4);
this.data2LimitEditSizer.add(this.data2LimitEdit);
this.data2LimitEditSizer.addSpacing(20);
this.data2LimitEditSizer.add(this.data2Label);
this.data2LimitEditSizer.addStretch();
this.data3LimitEditSizer = new HorizontalSizer;
this.data3LimitEditSizer.addSpacing(4);
this.data3LimitEditSizer.add(this.data3LimitEdit);
this.data3LimitEditSizer.addSpacing(20);
this.data3LimitEditSizer.add(this.data3Label);
this.data3LimitEditSizer.addStretch();
this.data4LimitEditSizer = new HorizontalSizer;
this.data4LimitEditSizer.addSpacing(4);
this.data4LimitEditSizer.add(this.data4LimitEdit);
this.data4LimitEditSizer.addSpacing(20);
this.data4LimitEditSizer.add(this.data4Label);
this.data4LimitEditSizer.addStretch();
if (metricsData[1].data.length == 0) {
// If no data for second metric, hide it
this.data2Plot.hide();
this.data2Stats.hide();
this.data2LimitEdit.hide();
}
if (metricsData[2].data.length == 0) {
// If no data for third metric, hide it
this.data3Plot.hide();
this.data3Stats.hide();
this.data3LimitEdit.hide();
}
if (metricsData[3].data.length == 0) {
// If no data for fourth metric, hide it
this.data4Plot.hide();
this.data4Stats.hide();
this.data4LimitEdit.hide();
}
// Layout
this.plotsGroupBox = new GroupBox(this);
this.plotsGroupBox.title = "Metrics Visualization";
this.plotsGroupBox.sizer = new VerticalSizer;
// Plot 1 with data plot and edit field for limit
this.data1Plotsizer = new VerticalSizer;
this.data1Plotsizer.add(this.data1Plot);
this.data1Plotsizer.addSpacing(4);
this.data1Plotsizer.add(this.data1LimitEditSizer);
// Plot2 with data plot and edit field for limit
this.data2Plotsizer = new VerticalSizer;
this.data2Plotsizer.add(this.data2Plot);
this.data2Plotsizer.addSpacing(4);
this.data2Plotsizer.add(this.data2LimitEditSizer);
// Plot3 with data plot and edit field for limit
this.data3Plotsizer = new VerticalSizer;
this.data3Plotsizer.add(this.data3Plot);
this.data3Plotsizer.addSpacing(4);
this.data3Plotsizer.add(this.data3LimitEditSizer);
// Plot4 with data plot and edit field for limit
this.data4Plotsizer = new VerticalSizer;
this.data4Plotsizer.add(this.data4Plot);
this.data4Plotsizer.addSpacing(4);
this.data4Plotsizer.add(this.data4LimitEditSizer);
// First row of plots
this.topRowSizer = new HorizontalSizer;
this.topRowSizer.addSpacing(20);
this.topRowSizer.add(this.data1Plotsizer);
this.topRowSizer.addSpacing(10);
this.topRowSizer.add(this.data2Plotsizer);
// Second row of plots
this.bottomRowSizer = new HorizontalSizer;
this.bottomRowSizer.addSpacing(20);
this.bottomRowSizer.add(this.data3Plotsizer);
this.bottomRowSizer.addSpacing(10);
this.bottomRowSizer.add(this.data4Plotsizer);
this.plotsGroupBox.sizer.add(this.topRowSizer);
this.plotsGroupBox.sizer.addSpacing(10);
this.plotsGroupBox.sizer.add(this.bottomRowSizer);
this.plotsGroupBox.sizer.addSpacing(4);
// Statistics section
this.statsGroupBox = new GroupBox(this);
this.statsGroupBox.title = "Statistics Summary";
this.statsGroupBox.sizer = new HorizontalSizer;
this.statsGroupBox.sizer.add(this.data1Stats);
this.statsGroupBox.sizer.add(this.data2Stats);
this.statsGroupBox.sizer.add(this.data3Stats);
this.statsGroupBox.sizer.add(this.data4Stats);
// Buttons
this.okButton = new PushButton(this);
this.okButton.text = "OK";
this.okButton.icon = this.scaledResource(":/icons/ok.png");
this.okButton.onClick = function() {
// Confirm before exiting the dialog to avoid accidental exit with enter key
if ((new MessageBox("Do you really want to close " + WINDOW_TITLE + " and apply limits?",
WINDOW_TITLE, StdIcon_Warning, StdButton_Yes, StdButton_No)).execute() == StdButton_Yes)
{
this.dialog.ok();
}
};
this.cancelButton = new PushButton(this);
this.cancelButton.text = "Cancel";
this.cancelButton.icon = this.scaledResource(":/icons/cancel.png");
this.cancelButton.onClick = function() {
this.dialog.cancel();
};
this.buttonsRowSizer = new HorizontalSizer;
this.buttonsRowSizer.addStretch();
this.buttonsRowSizer.add(this.okButton);
this.buttonsRowSizer.addSpacing(10);
this.buttonsRowSizer.add(this.cancelButton);
// Main sizer
this.sizer = new VerticalSizer;
this.sizer.margin = 6;
this.sizer.spacing = 4;
this.sizer.add(this.totatitleLabelSizer);
this.sizer.add(this.subtitleLabel);
this.sizer.add(this.plotsGroupBox);
this.sizer.add(this.statsGroupBox);
this.sizer.add(this.buttonsRowSizer);
this.sizer.addStretch();
this.ensureLayoutUpdated();
this.adjustToContents();
}
AstroMetricsDialog.prototype = new Dialog;
// Function to update data and refresh dialog
AstroMetricsDialog.prototype.updateData = function() {
// console.writeln("Updating data");
this.updateFilteredOut();
// Force repaint
this.data1Plot.repaint();
this.data2Plot.repaint();
this.data3Plot.repaint();
this.data4Plot.repaint();
};
AstroMetricsDialog.prototype.updateFilteredOut = function() {
// console.writeln("Initializing filtering...");
metricsFilteredOut = [];
// Initialize metricsFilteredOut
for (let i = 0; i < metricsData.length; i++) {
for (let j = 0; j < metricsData[i].data.length; j++) {
metricsFilteredOut[j] = false;
}
}
// Check filtering conditions
for (let i = 0; i < metricsData.length; i++) {
let metric = metricsData[i];
if (metric.name == 'None') {
// console.writeln("Skipping metric: " + metric.name);
continue; // Skip metrics with name 'None'
}
if (metric.limit == 0.0) {
// console.writeln("No limit set for metric: " + metric.name);
continue; // No filtering if limit is 0
}
// console.writeln("Filtering metric: " + metric.name + " with limit: " + metric.limit);
if (metric.filter_high) {
for (let j = 0; j < metric.data.length; j++) {
if (metric.data[j] > metric.limit) {
metricsFilteredOut[j] = true;
}
}
} else {
for (let j = 0; j < metric.data.length; j++) {
if (metric.data[j] < metric.limit) {
metricsFilteredOut[j] = true;
}
}
}
}
// Count accepted frames
let accepted = 0;
for (let i = 0; i < metricsFilteredOut.length; i++) {
if (!metricsFilteredOut[i] && !alwaysFilteredOut[i]) {
accepted++;
}
}
this.totalLabel.text = "Accepted Frames: " + accepted + " / " + metricsFilteredOut.length;
};
// Main execution function
function main(data, filtered_out) {
//console.writeln("Starting AutoIntegrate Metrics Visualizer...");
metricsData = data;
alwaysFilteredOut = filtered_out || []; // Input metrics that are always filtered out
// Count the number of non-zero data sets
numberOfDataSets = 0;
for (let i = 0; i < metricsData.length; i++) {
if (metricsData[i].data.length > 0) {
numberOfDataSets++;
}
}
dialog = new AstroMetricsDialog();
dialog.updateFilteredOut();
return dialog.execute();
}
this.main = main;
} /* AutoIntegrateMetricsVisualizer */
AutoIntegrateMetricsVisualizer.prototype = new Object;
#endif /* AUTOINTEGRATEMETRICSVISUALIZER_JS */