-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathQCTrendPlotPanel.js
More file actions
2456 lines (2140 loc) · 97 KB
/
QCTrendPlotPanel.js
File metadata and controls
2456 lines (2140 loc) · 97 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
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2016-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
if (!LABKEY.targetedms) {
LABKEY.targetedms = {};
}
if (!LABKEY.targetedms.PlotSettingsUtil) {
LABKEY.targetedms.PlotSettingsUtil = {
saveAsDefault: function () {
LABKEY.Ajax.request({
method: 'POST',
url: LABKEY.ActionURL.buildURL('targetedms', 'saveQCPlotSettingsAsDefault'),
success: function() { alert('Defaults saved successfully'); },
failure: LABKEY.Utils.getCallbackWrapper(function(error) { alert('Failed to save defaults'); console.log(error); }, this, true)
});
},
revertToDefault: function () {
LABKEY.Ajax.request({
method: 'POST',
url: LABKEY.ActionURL.buildURL('targetedms', 'revertToDefaultQCPlotSettings'),
success: function() { window.location.reload(); },
failure: LABKEY.Utils.getCallbackWrapper(function(error) { alert('Failed to revert to defaults'); console.log(error); }, this, true)
});
},
formatNumeric: function(val) {
if (LABKEY.vis.isValid(val)) {
if (val > 100000 || val < -100000) {
return val.toExponential(3);
}
return parseFloat(val.toFixed(3));
}
return "N/A";
}
}
}
/**
* Class to create a panel for displaying the R plot for the trending of retention times, peak areas, and other
* values for the selected graph parameters.
*/
Ext4.define('LABKEY.targetedms.QCTrendPlotPanel', {
extend: 'LABKEY.targetedms.BaseQCPlotPanel',
mixins: {helper: 'LABKEY.targetedms.QCPlotHelperWrapper'},
header: false,
border: false,
labelAlign: 'left',
items: [],
defaults: {
xtype: 'panel',
border: false
},
// properties specific to this TargetedMS QC plot implementation
yAxisScale: 'linear',
metric: null,
plotTypes: ['Metric Value'],
dateRangeOffset: 0,
minAcquiredTime: null,
maxAcquiredTime: null,
startDate: null,
endDate: null,
groupedX: false,
singlePlot: false,
showDataPoints: false,
showExpRunRange: false,
showExcluded: false,
showExcludedPrecursors: false,
showReferenceGS: true,
plotWidth: null,
enableBrushing: false,
havePlotOptionsChanged: false,
selectedAnnotations: {},
runs: null,
trailingRuns: null,
minWidth: 1250, // Keep in sync with the width defined in qcTrendPlot.jsp
width: '100%',
SHOW_ALL_IN_A_SINGLE_PLOT: 'Show all series in a single plot',
LABEL_WIDTH: 115,
// Max number of plots/series to show per page
maxCount: 50,
initComponent : function() {
Ext4.tip.QuickTipManager.init();
this.callParent();
// min and max acquired date must be provided
if (this.minAcquiredTime == null || this.maxAcquiredTime == null)
Ext4.get(this.plotDivId).update("<span class='labkey-error'>Unable to render report. Missing min and max AcquiredTime from data query.</span>");
else {
Ext4.get(this.plotDivId).update("Loading...");
// Load replicate annotations in the callback.
LABKEY.targetedms.QCMetricConfigLoader.getMetrics(this.queryContainerReplicateAnnotations, this, function() {
Ext4.get(this.plotDivId).update('Failed to load');
});
}
},
queryInitialPlotOptions : function() {
// If there are URL parameters (i.e. from Pareto Plot click), set those as initial values as well.
LABKEY.Ajax.request({
url: LABKEY.ActionURL.buildURL('targetedms', 'leveyJenningsPlotOptions.api'),
method: 'POST',
scope: this,
success: LABKEY.Utils.getCallbackWrapper(function(response) {
// convert the boolean and integer values from strings
var initValues = {};
Ext4.iterate(response.properties, function(key, value)
{
if (value === "true" || value === "false") {
value = value === "true";
}
else if (value && value.length > 0 && !isNaN(Number(value))) {
value = +value;
}
else if (key === 'plotTypes') { // convert string to array
// We've renamed this plot type in the UI and need to map previously saved values
value = value.replace('Levey-Jennings', 'Metric Value');
value = value.split(',');
}
if(key === 'selectedAnnotations' && value) {
const annotations = {};
const a = value.split(',');
for (let i = 0; i < a.length; i++)
{
const b = a[i].split(":");
const name = b[0];
const val = b[1];
let selected = annotations[name];
if(!selected)
{
selected = [];
annotations[name] = selected;
}
selected.push(val);
}
initValues[key] = annotations;
}
else {
initValues[key] = value;
}
});
// apply any URL parameters to the initial values
Ext4.apply(initValues, this.getInitialValuesFromUrlParams());
// Initialize the form
this.initPlotForm(initValues);
}, this, false)
});
},
queryContainerReplicateAnnotations : function(metrics) {
this.metricPropArr = metrics.sort(function(a, b) {
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
});
LABKEY.Ajax.request({
url: LABKEY.ActionURL.buildURL('targetedms', 'GetContainerReplicateAnnotations.api'),
method: 'GET',
scope: this,
success: LABKEY.Utils.getCallbackWrapper(function(response) {
var annotationNodes = [];
Ext4.iterate(response.replicateAnnotations, function(annotation)
{
var annotValueNodes = [];
annotation.values.forEach(function(value){
var valueNode = {text: value, leaf: true, iconCls: 'tree-node-noicon', checked: false};
annotValueNodes.push(valueNode);
});
var annotNode = {text: annotation.name, expanded: true, iconCls: 'tree-node-noicon', children: annotValueNodes};
annotationNodes.push(annotNode);
});
this.replicateAnnotationsNodes = annotationNodes;
// Load persisted plot options for logged in users.
this.queryInitialPlotOptions();
}, this, false),
failure: LABKEY.Utils.getCallbackWrapper(function (response) {
this.failureHandler(response);
}, null, true)
});
},
calculateStartDateByOffset : function() {
if (this.dateRangeOffset > 0) {
var startDateByOffset = this.maxAcquiredTime ? new Date(this.maxAcquiredTime) : new Date();
startDateByOffset.setDate(startDateByOffset.getDate() - this.dateRangeOffset);
return startDateByOffset;
}
return this.minAcquiredTime;
},
calculateEndDateByOffset : function() {
if (this.dateRangeOffset > 0)
return this.maxAcquiredTime ? this.maxAcquiredTime : new Date();
return this.maxAcquiredTime;
},
initPlotForm : function(initValues) {
// apply the initial values to the panel object so they are used in form field initialization
Ext4.apply(this, initValues);
// if we have a dateRangeOffset, we need to calculate the start and end date
if (this.dateRangeOffset > -1) {
this.startDate = this.formatDate(this.calculateStartDateByOffset());
this.endDate = this.formatDate(this.calculateEndDateByOffset());
}
this.getExpRunRangeDetails();
// We just finished loading the previously set options so clear any dirty state
this.havePlotOptionsChanged = false;
},
getExpRunRangeDetails: function() {
var urlParams = LABKEY.ActionURL.getParameters();
this.showExpRunRange = parseInt(urlParams['RunId']) > 0;
if (this.showExpRunRange) {
this.getExperimentRunDetails(urlParams['RunId'])
}
else {
// initialize the form panel toolbars and display the plot
this.add(this.initPlotFormToolbars());
this.displayTrendPlot();
}
},
getExperimentRunDetails: function (runId) {
var sql = "Select MIN(sf.AcquiredTime) AS StartDate,\n" +
" MAX(sf.AcquiredTime) AS EndDate,\n" +
" sf.ReplicateId.RunId.FileName\n" +
"FROM targetedms.SampleFile sf\n" +
"WHERE sf.ReplicateId.RunId ='" + runId + "'\n" +
"GROUP BY sf.ReplicateId.RunId.FileName";
LABKEY.Query.executeSql({
schemaName: 'targetedms',
sql: sql,
containerFilter: LABKEY.Query.containerFilter.allFolders,
scope: this,
success: function (response) {
if (response.rows.length === 0) {
this.failureHandler({message: 'Could not find run ' + runId});
}
else {
let runDetails = response.rows[0];
this.expRunDetails = {};
this.expRunDetails['fileName'] = runDetails.FileName;
this.expRunDetails['startDate'] = runDetails.StartDate;
this.expRunDetails['endDate'] = runDetails.EndDate;
Ext4.apply(this, {
startDate: this.formatDate(this.expRunDetails['startDate']),
endDate: this.formatDate(this.expRunDetails['endDate']),
dateRangeOffset: -1
});
// initialize the form panel toolbars and display the plot
this.add(this.initPlotFormToolbars());
this.displayTrendPlot();
}
},
failure: this.failureHandler
});
},
initPlotFormToolbars: function () {
// Build a single top region with three columns of controls for a more compact layout.
const columnDefaults = {
xtype: 'container',
layout: { type: 'vbox', align: 'center' },
defaults: {
width: 380,
// Add a little vertical spacing between stacked controls
margin: '0 10 10 0'
}
};
const col1 = Ext4.create('Ext.container.Container', Ext4.apply({ itemId: 'qc-controls-col-1' }, columnDefaults));
// Primary controls: metrics and date range
col1.add(this.getMetricCombo1());
col1.add(this.getMetricCombo2());
col1.add(this.getScaleCombo());
if (this.metric) {
//hiding the show All series in a single plot checkbox for run scoped metrics
this.getPlotGroupRadioGroup().setVisible(this.getMetricPropsById(this.metric).precursorScoped);
}
// Create vertical line separator component
const separator = {
xtype: 'component',
autoEl: {
tag: 'div',
style: 'width: 1px; background-color: #e0e0e0; height: 100%;'
},
width: 1,
margin: '0 12px',
// Ensure this separator does not expand like other flexed columns
flex: 0
};
const col2 = Ext4.create('Ext.container.Container', Ext4.apply({ itemId: 'qc-controls-col-2' }, columnDefaults));
// Plot configuration controls
col2.add(this.getDateRangeCombo());
// Show custom date range inline when selected
col2.add(this.getCustomDateRangeToolbar());
col2.add(this.getGroupedXRadioGroup());
col2.add(this.getExcludedReplicatesRadioGroup());
const col3 = Ext4.create('Ext.container.Container', Ext4.apply({ itemId: 'qc-controls-col-3' }, columnDefaults));
// Display toggles and filters
col3.add(this.getPlotTypeOptions());
col3.add(this.getTrailingRunsField());
col3.add(this.getPlotGroupRadioGroup());
col3.add(this.getExcludedPrecursorsRadioGroup());
col3.add(this.getReferenceGuideSetRadioGroup());
if (this.canUserEdit()) {
const buttonContainer = Ext4.create('Ext.form.FieldContainer', {
hideEmptyLabel: false,
labelWidth: this.LABEL_WIDTH,
items: [this.getGuideSetCreateButton()]
});
col3.add(buttonContainer);
}
if (this.replicateAnnotationsNodes.length > 0) {
col2.add(this.getAnnotationFiltersToolbar());
col2.add(this.getSelectedAnnotationsToolbar());
}
// Ensure single-plot checkbox visibility mirrors previous logic when metrics are run-scoped
if (this.metric) {
var showSinglePlot = this.getMetricPropsById(this.metric).precursorScoped;
this.getPlotGroupRadioGroup().setVisible(showSinglePlot);
}
const columnsToolbar = Ext4.create('Ext.toolbar.Toolbar', {
ui: 'footer',
cls: 'levey-jennings-toolbar',
padding: 10,
layout: { type: 'hbox', align: 'stretch' }, // Changed to stretch to make separators full height
defaults: { flex: 1 },
items: [col1, separator, col2, separator, col3] // Added separators between columns
});
return [
{ tbar: columnsToolbar },
{ tbar: this.getGuideSetMessageToolbar() },
{ tbar: this.getDateRangeErrorToolbar() },
{ tbar: this.getExperimentRunDateRangeToolbar() }
];
},
getTrailingRunsField: function () {
if (!this.trailingRunsField) {
this.trailingRunsField = Ext4.create('Ext.form.field.Number', {
xtype : 'numberfield',
fieldLabel: 'Trailing last',
labelWidth: this.LABEL_WIDTH,
enableKeyEvents: true,
id : 'trailingRuns',
value: this.trailingRuns ? this.trailingRuns : this.runs > 10 ? 10 : this.runs,
hidden: true,
activeError: '',
allowDecimals: false,
minValue: 2,
listeners: {
scope: this,
change: function (cmp, newVal) {
this.trailingRuns = newVal;
this.havePlotOptionsChanged = true;
this.displayTrendPlot();
}
}
});
}
return this.trailingRunsField;
},
getPlotTypeOptions: function() {
let plotTypeCheckBoxes = [];
let selectedPlotTypes = [];
Ext4.each(LABKEY.targetedms.QCPlotHelperBase.qcPlotTypes, function(plotType){
plotTypeCheckBoxes.push({
inputValue: plotType,
});
if (this.isPlotTypeSelected(plotType)) {
selectedPlotTypes.push(plotType);
this.getTrailingRunsField().hidden = !((plotType.indexOf("Trailing Mean") > -1 || plotType.indexOf("Trailing CV") > -1));
}
}, this);
return {
xtype: 'plottype-checkcombo',
labelWidth: this.LABEL_WIDTH,
id: 'qc-plot-type-with-y-options',
fieldLabel: 'Plot types',
expandToFitContent: true,
addAllSelector: false,
queryMode: 'local',
store: Ext4.create('Ext.data.Store', {
fields: ['inputValue'],
data: plotTypeCheckBoxes,
}),
displayField: 'inputValue',
valueField: 'inputValue',
value: selectedPlotTypes,
listeners: {
scope: this,
change: function(cmp, newVal) {
var newValues = newVal;
this.plotTypes = newValues ? Ext4.isArray(newValues) ? newValues : [newValues] : [];
if (this.trailingRuns === undefined || this.trailingRuns === null) {
this.trailingRuns = 10;
}
this.getTrailingRunsField().setVisible(newValues.indexOf("Trailing Mean") > -1 || newValues.indexOf("Trailing CV") > -1);
this.havePlotOptionsChanged = true;
this.displayTrendPlot();
}
}
}
},
getAnnotationFiltersToolbar : function() {
if (!this.annotationFiltersToolbar) {
this.annotationFiltersToolbar = Ext4.create('Ext.form.FieldContainer', {
fieldLabel: 'Replicate filter',
labelWidth: this.LABEL_WIDTH,
items: [
this.getAnnotationListTree(),
{
xtype: 'container',
layout: {
type: 'hbox',
pack: 'end' // Right-align the buttons
},
items: [
this.getApplyAnnotationFiltersButton(),
{xtype: 'tbspacer', width: 5},
this.getClearAnnotationFiltersButton()
]
}
]
});
if(this.replicateAnnotationsNodes.length > 0) {
var annotationsTree = this.getAnnotationListTree();
var rootNode = annotationsTree.getRootNode();
var annotations = this.selectedAnnotations;
if(Object.keys(annotations).length > 0) {
rootNode.cascadeBy(function (node) {
if (!node.isRoot() && !node.isLeaf()) {
var annotationName = node.get('text');
var selected = annotations[annotationName];
if (selected) {
for (var i = 0; i < selected.length; i++) {
var child = node.findChild('text', selected[i]);
if (child) {
child.set('checked', true);
}
}
}
}
});
this.clearAnnotationFiltersButton.show();
// If the tree is currently collapsed, keep buttons hidden
if (this.getAnnotationListTree().collapsed) {
this.clearAnnotationFiltersButton.hide();
this.getApplyAnnotationFiltersButton().hide();
}
}
}
this.annotationFiltersToolbar.setVisible(this.replicateAnnotationsNodes.length > 0);
}
return this.annotationFiltersToolbar;
},
getSelectedAnnotationsToolbar: function() {
if (!this.selectedAnnotationsToolbar) {
this.selectedAnnotationsToolbar = Ext4.create('Ext.toolbar.Toolbar', {
ui: 'footer',
cls: 'levey-jennings-toolbar',
padding: '0 0 0 0',
layout: {pack: 'center'},
hidden: true,
items: []
});
if(Object.keys(this.selectedAnnotations).length > 0) {
this.updateSelectedAnnotationsToolbar();
}
}
return this.selectedAnnotationsToolbar;
},
getCustomDateRangeToolbar : function() {
if (!this.customDateRangeToolbar) {
// Render the custom range controls inline beneath the date range combo,
// left-aligned so they stay within the same column and don't overlap
// with the label column.
this.customDateRangeToolbar = Ext4.create('Ext.form.FieldContainer', {
fieldLabel: 'Custom dates',
labelWidth: this.LABEL_WIDTH,
hidden: this.dateRangeOffset > -1,
layout: { type: 'hbox', align: 'middle' },
items: [
this.getStartDateField(),
{xtype: 'tbspacer', width: '3%'},
{xtype: 'label', text: ' to ', width: '3%'},
{xtype: 'tbspacer', width: '3%'},
this.getEndDateField()
]
});
}
return this.customDateRangeToolbar;
},
getGuideSetMessageToolbar : function() {
if (!this.guideSetMessageToolbar) {
this.guideSetMessageToolbar = Ext4.create('Ext.toolbar.Toolbar', {
ui: 'footer',
cls: 'guideset-toolbar-msg',
hidden: true,
layout: { pack: 'center' },
items: [{
xtype: 'box',
itemId: 'GuideSetMessageToolBar',
html: 'Please click and drag in the plot to select the guide set training date range.'
}]
});
}
return this.guideSetMessageToolbar;
},
getDateRangeErrorToolbar : function() {
if (!this.dateRangeErrorToolbar) {
this.dateRangeErrorToolbar = Ext4.create('Ext.toolbar.Toolbar', {
ui: 'footer',
hidden: true,
layout: { pack: 'center' },
items: [{
xtype: 'label',
id: 'DateRangeErrorBar',
cls: 'labkey-error',
text: 'Please correct the date range. Check the start and end dates are valid.'
}]
});
}
return this.dateRangeErrorToolbar;
},
getExperimentRunDateRangeToolbar : function() {
if (!this.experimentRunDateRangeToolbar) {
var hidden = !this.showExpRunRange;
var returnUrl = LABKEY.ActionURL.getReturnUrl();
var htmlStr = this.showExpRunRange
? "<a href=" + Ext4.String.htmlEncode(returnUrl) + ">"
+ Ext4.String.htmlEncode(this.expRunDetails.fileName) + " : "
+ Ext4.String.htmlEncode(this.formatDate(this.expRunDetails.startDate, false)) + " through "
+ Ext4.String.htmlEncode(this.formatDate(this.expRunDetails.endDate, false))
+ "</a>"
: "";
this.experimentRunDateRangeToolbar = Ext4.create('Ext.toolbar.Toolbar', {
ui: 'footer',
cls: 'expDateRange-toolbar-msg',
hidden: hidden,
layout: { pack: 'center' },
items: [{
xtype: 'box',
html: htmlStr
}]
});
}
return this.experimentRunDateRangeToolbar;
},
isValidQCPlotType: function(plotType) {
var valid = false;
Ext4.each(LABKEY.targetedms.QCPlotHelperBase.qcPlotTypes, function(type){
if (plotType === type) {
valid = true;
}
});
return valid;
},
getInitialValuesFromUrlParams : function() {
var urlParams = LABKEY.ActionURL.getParameters(),
paramValues = {},
alertMessage = '', sep = '',
paramValue,
metric;
paramValue = urlParams['metric'];
if (paramValue !== undefined) {
metric = this.validateMetricId(paramValue);
if(metric == null) {
alertMessage += "Invalid metric, reverting to default metric.";
sep = ' ';
}
else {
paramValues['metric'] = metric;
}
}
if (urlParams['startDate'] !== undefined) {
paramValue = new Date(urlParams['startDate']);
if(paramValue === "Invalid Date") {
alertMessage += sep + "Invalid Start Date, reverting to default start date.";
sep = ' ';
}
else {
paramValues['dateRangeOffset'] = -1; // force to custom date range selection
paramValues['startDate'] = this.formatDate(new Date(urlParams['startDate']));
}
}
if (urlParams['endDate'] !== undefined) {
paramValue = new Date(urlParams['endDate']);
if(paramValue === "Invalid Date") {
alertMessage += sep + "Invalid End Date, reverting to default end date.";
}
else {
paramValues['dateRangeOffset'] = -1; // force to custom date range selection
paramValues['endDate'] = this.formatDate(new Date(urlParams['endDate']));
}
}
paramValue = urlParams['plotTypes'];
if (paramValue !== undefined) {
var plotTypes = [];
if (!Ext4.isArray(paramValue))
paramValue = paramValue.split(',');
Ext4.each(paramValue, function (value) {
if (this.isValidQCPlotType(value.trim()))
plotTypes.push(value.trim());
}, this);
if (plotTypes.length === 0) {
alertMessage += sep + "Invalid Plot Type, reverting to default plot type.";
}
else {
paramValues['plotTypes'] = plotTypes;
}
}
if (alertMessage.length > 0) {
LABKEY.Utils.alert('Invalid URL Parameter(s)', alertMessage);
}
else if (Object.keys(paramValues).length > 0) {
this.havePlotOptionsChanged = true;
return paramValues;
}
return null;
},
validateMetricId : function(id) {
// convert id to an integer, handling a parsing failure gracefully
id = parseInt(id);
for (let i = 0; i < this.metricPropArr.length; i++) {
if (this.metricPropArr[i].id === id) {
return this.metricPropArr[i].id;
}
}
return null;
},
getYAxisOptions: function () {
return {
fields: ['value', 'display'],
data: [['linear', 'Linear'], ['log', 'Log'], ['percentDeviation', 'Percent of Mean'], ['standardDeviation', 'Standard Deviations'], ['deltaFromMean', 'Delta from Mean']]
}
},
getScaleCombo : function() {
if (!this.scaleCombo) {
this.scaleCombo = Ext4.create('Ext.form.field.ComboBox', {
id: 'scale-combo-box',
fieldLabel: 'Y-axis scale',
labelWidth: this.LABEL_WIDTH,
triggerAction: 'all',
mode: 'local',
store: Ext4.create('Ext.data.ArrayStore', this.getYAxisOptions()),
valueField: 'value',
displayField: 'display',
value: this.yAxisScale,
forceSelection: true,
editable: false,
listeners: {
scope: this,
change: function(cmp, newVal, oldVal) {
this.yAxisScale = newVal;
this.havePlotOptionsChanged = true;
// call processPlotData instead of renderPlots so that we recalculate min y-axis scale for log
this.setLoadingMsg();
this.processPlotData();
}
}
});
}
return this.scaleCombo;
},
getDateRangeCombo : function() {
if (!this.dateRangeCombo) {
this.dateRangeCombo = Ext4.create('Ext.form.field.ComboBox', {
id: 'daterange-combo-box',
labelWidth: this.LABEL_WIDTH,
fieldLabel: 'Date range',
triggerAction: 'all',
mode: 'local',
store: Ext4.create('Ext.data.ArrayStore', {
fields: ['value', 'display'],
data: [
[0, 'All dates'],
[7, 'Last 7 days'],
[15, 'Last 15 days'],
[30, 'Last 30 days'],
[90, 'Last 90 days'],
[180, 'Last 180 days'],
[365, 'Last 365 days'],
[-1, 'Custom range']
]
}),
valueField: 'value',
displayField: 'display',
value: this.dateRangeOffset,
forceSelection: true,
editable: false,
listeners: {
scope: this,
change: function(cmp, newVal, oldVal) {
this.dateRangeOffset = newVal;
this.havePlotOptionsChanged = true;
var showCustomRangeItems = this.dateRangeOffset === -1;
this.getCustomDateRangeToolbar().setVisible(showCustomRangeItems);
if (!showCustomRangeItems) {
this.getDateRangeErrorToolbar().hide();
// either use the min and max values based on the data
// or calculate range based on today's date and the offset
this.startDate = this.formatDate(this.calculateStartDateByOffset());
this.endDate = this.formatDate(this.calculateEndDateByOffset());
this.displayTrendPlot();
}
else {
this.applyCustomDateRange();
}
}
}
});
}
return this.dateRangeCombo;
},
createDateField: function (config) {
var defaultConfig = {
width: '45%',
allowBlank: false,
format: 'Y-m-d',
listeners: {
scope: this,
change: this.applyCustomDateRange
}
};
return Ext4.create('Ext.form.field.Date', Ext4.apply(defaultConfig, config));
},
getStartDateField: function () {
if (!this.startDateField) {
this.startDateField = this.createDateField({
id: 'start-date-field',
value: this.startDate
});
}
return this.startDateField;
},
getEndDateField: function () {
if (!this.endDateField) {
this.endDateField = this.createDateField({
id: 'end-date-field',
value: this.showExpRunRange ? this.formatDate(this.expRunDetails.endDate, false) : this.endDate
});
}
return this.endDateField;
},
assignDefaultMetricIfNull: function () {
if (this.metric == null || isNaN(Number(this.metric)) || !this.getMetricPropsById(this.metric)) {
this.metric = null;
for (let i = 0; i < this.metricPropArr.length; i++) {
if (this.metricPropArr[i].name === 'Retention Time') {
this.metric = this.metricPropArr[i].id;
}
}
// Fall back on the first one
if (!this.metric && this.metricPropArr.length > 0) {
this.metric = this.metricPropArr[0].id;
}
}
if (this.metric2 && !this.getMetricPropsById(this.metric2)) {
this.metric2 = null;
}
},
getSecondMetricList : function() {
const primaryMetric = this.getMetricPropsById(this.metric);
const subset = this.metricPropArr.filter(function(metric) {
return !primaryMetric ||
(primaryMetric.precursorScoped === metric.precursorScoped && primaryMetric.id !== metric.id);
});
return [{
// It's easier to use 0 to avoid ambiguity of null vs not defined in JSON calls
id: 0,
name: this.noSecondMetricText
}, ...subset];
},
createMetricCombo : function(primary) {
let data;
if (primary) {
data = this.metricPropArr;
}
else {
data = this.getSecondMetricList();
}
this.assignDefaultMetricIfNull();
return Ext4.create('Ext.form.field.ComboBox', {
id: 'metric-type-field' + (primary ? '1' : '2'),
fieldLabel: primary ? 'Y-axis left' : 'Y-axis right',
labelWidth: this.LABEL_WIDTH,
triggerAction: 'all',
queryMode: 'local',
store: Ext4.create('Ext.data.Store', {
fields: ['id', 'name'],
data: data
}),
valueField: 'id',
displayField: 'name',
tpl : '<tpl for="."><li role="option" style="min-height: 1.75em;" class="x4-boundlist-item">{name:htmlEncode}</li></tpl>',
value: primary ? this.metric : this.metric2,
forceSelection: true,
allowBlank: !primary,
emptyText: primary ? 'No metric' : 'No second metric',
editable: false,
listeners: {
scope: this,
change: function(cmp, newVal) {
if (primary) {
this.metric = newVal;
const filteredMetrics = this.getSecondMetricList();
this.getMetricCombo2().getStore().loadData(filteredMetrics);
const metric2 = this.metric2;
const found = filteredMetrics.find(function(metric) {
return metric.id === metric2;
})
if (!found) {
this.getMetricCombo2().setValue(null);
}
}
else {
this.metric2 = newVal;
}
this.havePlotOptionsChanged = true;
// Update single-plot checkbox visibility directly in the 3-column layout
var showAllSeriesCheckBox = this.getMetricPropsById(this.metric).precursorScoped;
this.getPlotGroupRadioGroup().setVisible(showAllSeriesCheckBox);
if (this.filterQCPoints) {
this.resetFilterPointsIndices();
}
this.displayTrendPlot();
}
}
});
},
getMetricCombo1 : function() {
if (!this.metricField) {
this.metricField = this.createMetricCombo(true);
}
return this.metricField;
},
getMetricCombo2 : function() {
if (!this.metricField2) {
this.metricField2 = this.createMetricCombo(false);
}
return this.metricField2;
},
getAnnotationListTree : function() {
if (!this.annotationFiltersField) {
const store = Ext4.create('Ext.data.TreeStore', {
root: {expanded: false, children: this.replicateAnnotationsNodes},
});
this.annotationFiltersField = Ext4.create('Ext.tree.Panel', {
id: 'annotation-filter-field',
height: 150,
title: 'Expand to select annotations',
store: store,
rootVisible: false,
titleCollapse: true,
collapsed: true,
collapsible: true,
header: { style: 'background-color: #ffffff' },
useArrows: true,
lines: false,
listeners: {
scope: this,
expand: function() {
// Show Apply button when expanded
this.getApplyAnnotationFiltersButton().show();
// Only show Clear button when there are selected annotations
if (Object.keys(this.selectedAnnotations || {}).length > 0) {
this.getClearAnnotationFiltersButton().show();
}
},
collapse: function() {
// Hide both buttons when collapsed
this.getApplyAnnotationFiltersButton().hide();
this.getClearAnnotationFiltersButton().hide();
}
}
});
this.getApplyAnnotationFiltersButton().hide();
this.getClearAnnotationFiltersButton().hide();
}
return this.annotationFiltersField;
},
getApplyAnnotationFiltersButton : function() {
if (!this.applyAnnotationFiltersButton) {
this.applyAnnotationFiltersButton = Ext4.create('Ext.button.Button', {
text: 'Apply',
handler: this.applyAnnotationFiltersBtnClick,
scope: this
});
}
return this.applyAnnotationFiltersButton;
},
getClearAnnotationFiltersButton : function() {
if (!this.clearAnnotationFiltersButton) {
this.clearAnnotationFiltersButton = Ext4.create('Ext.button.Button', {
text: 'Clear',
handler: this.clearAnnotationFiltersBtnClick,
scope: this,
hidden: true
});
}
return this.clearAnnotationFiltersButton;
},