-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhepexplorer.js
5596 lines (4981 loc) · 203 KB
/
hepexplorer.js
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
(function(global, factory) {
typeof exports === 'object' && typeof module !== 'undefined'
? (module.exports = factory(require('webcharts')))
: typeof define === 'function' && define.amd
? define(['webcharts'], factory)
: (global.hepexplorer = factory(global.webCharts));
})(this, function(webcharts) {
'use strict';
if (typeof Object.assign != 'function') {
Object.defineProperty(Object, 'assign', {
value: function assign(target, varArgs) {
if (target == null) {
// TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) {
// Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}
if (!Array.prototype.find) {
Object.defineProperty(Array.prototype, 'find', {
value: function value(predicate) {
// 1. Let O be ? ToObject(this value).
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
var o = Object(this);
// 2. Let len be ? ToLength(? Get(O, 'length')).
var len = o.length >>> 0;
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
var thisArg = arguments[1];
// 5. Let k be 0.
var k = 0;
// 6. Repeat, while k < len
while (k < len) {
// a. Let Pk be ! ToString(k).
// b. Let kValue be ? Get(O, Pk).
// c. Let testResult be ToBoolean(? Call(predicate, T, � kValue, k, O �)).
// d. If testResult is true, return kValue.
var kValue = o[k];
if (predicate.call(thisArg, kValue, k, o)) {
return kValue;
}
// e. Increase k by 1.
k++;
}
// 7. Return undefined.
return undefined;
}
});
}
if (!Array.prototype.findIndex) {
Object.defineProperty(Array.prototype, 'findIndex', {
value: function value(predicate) {
// 1. Let O be ? ToObject(this value).
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
var o = Object(this);
// 2. Let len be ? ToLength(? Get(O, "length")).
var len = o.length >>> 0;
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
var thisArg = arguments[1];
// 5. Let k be 0.
var k = 0;
// 6. Repeat, while k < len
while (k < len) {
// a. Let Pk be ! ToString(k).
// b. Let kValue be ? Get(O, Pk).
// c. Let testResult be ToBoolean(? Call(predicate, T, � kValue, k, O �)).
// d. If testResult is true, return k.
var kValue = o[k];
if (predicate.call(thisArg, kValue, k, o)) {
return k;
}
// e. Increase k by 1.
k++;
}
// 7. Return -1.
return -1;
}
});
}
(function() {
if (typeof window.CustomEvent === 'function') return false;
function CustomEvent(event, params) {
params = params || { bubbles: false, cancelable: false, detail: null };
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
}
window.CustomEvent = CustomEvent;
})();
// https://github.com/wbkd/d3-extended
d3.selection.prototype.moveToFront = function() {
return this.each(function() {
this.parentNode.appendChild(this);
});
};
d3.selection.prototype.moveToBack = function() {
return this.each(function() {
var firstChild = this.parentNode.firstChild;
if (firstChild) {
this.parentNode.insertBefore(this, firstChild);
}
});
};
var _typeof =
typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
? function(obj) {
return typeof obj;
}
: function(obj) {
return obj &&
typeof Symbol === 'function' &&
obj.constructor === Symbol &&
obj !== Symbol.prototype
? 'symbol'
: typeof obj;
};
var defineProperty = function(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
};
/*------------------------------------------------------------------------------------------------\
Clone a variable (http://stackoverflow.com/a/728694).
\------------------------------------------------------------------------------------------------*/
function clone(obj) {
var copy;
//Handle the 3 simple types, and null or undefined
if (null == obj || 'object' != (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)))
return obj;
//Handle Date
if (obj instanceof Date) {
copy = new Date();
copy.setTime(obj.getTime());
return copy;
}
//Handle Array
if (obj instanceof Array) {
copy = [];
for (var i = 0, len = obj.length; i < len; i++) {
copy[i] = clone(obj[i]);
}
return copy;
}
//Handle Object
if (obj instanceof Object) {
copy = {};
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
}
return copy;
}
throw new Error("Unable to copy obj! Its type isn't supported.");
}
function settings() {
return {
//LB domain settings
id_col: 'USUBJID',
studyday_col: 'DY',
value_col: 'STRESN',
measure_col: 'TEST',
normal_col_low: null,
normal_col_high: 'STNRHI',
visit_col: null,
visitn_col: null,
//DM domain settings
group_cols: null,
filters: null,
details: null,
//EX domain settings
exposure_stdy_col: 'EXSTDY',
exposure_endy_col: 'EXENDY',
exposure_trt_col: 'EXTRT',
exposure_dose_col: 'EXDOSE',
exposure_dosu_col: 'EXDOSU',
//analysis settings
analysisFlag: {
value_col: null,
values: []
},
baseline: {
value_col: null, //synced with studyday_col in syncsettings()
values: [0]
},
calculate_palt: true,
measure_values: {
ALT: 'Aminotransferase, alanine (ALT)',
AST: 'Aminotransferase, aspartate (AST)',
TB: 'Total Bilirubin',
ALP: 'Alkaline phosphatase (ALP)'
},
add_measures: false,
x_options: 'all',
x_default: 'ALT',
y_options: ['TB'],
y_default: 'TB',
point_size_options: 'all',
point_size_default: 'Uniform',
cuts: {
TB: {
relative_baseline: 4.8,
relative_uln: 2
},
ALP: {
relative_baseline: 3.8,
relative_uln: 1
},
nrRatio: {
relative_baseline: 5,
relative_uln: 5
},
rRatio: {
relative_baseline: 5,
relative_uln: 5
},
defaults: {
relative_baseline: 3.8,
relative_uln: 3
}
},
imputation_methods: {
ALT: 'data-driven',
AST: 'data-driven',
TB: 'data-driven',
ALP: 'data-driven'
},
imputation_values: null,
display: 'relative_uln', //or "relative_baseline"
plot_max_values: true,
plot_day: null, //set in onLayout/initStudyDayControl
display_options: [
{
label: 'Upper limit of normal adjusted (eDish)',
value: 'relative_uln'
},
{ label: 'Baseline adjusted (mDish)', value: 'relative_baseline' }
],
measureBounds: [0.01, 0.99],
populationProfileURL: null,
participantProfileURL: null,
r_ratio_filter: true,
r_ratio: [0, null],
visit_window: 30,
title: 'Hepatic Safety Explorer',
downloadLink: true,
filters_multiselect: true,
warningText:
"This graphic has been thoroughly tested, but is not validated. Any clinical recommendations based on this tool should be confirmed using your organization's standard operating procedures.",
//all values set in onLayout/quadrants/*.js
quadrants: [
{
label: "Possible Hy's Law Range",
position: 'upper-right',
dataValue: 'xHigh:yHigh',
count: null,
total: null,
percent: null
},
{
label: 'Hyperbilirubinemia',
position: 'upper-left',
dataValue: 'xNormal:yHigh',
count: null,
total: null,
percent: null
},
{
label: "Temple's Corollary",
position: 'lower-right',
dataValue: 'xHigh:yNormal',
count: null,
total: null,
percent: null
},
{
label: 'Normal Range',
position: 'lower-left',
dataValue: 'xNormal:yNormal',
count: null,
total: null,
percent: null
}
],
//Standard webcharts settings
x: {
column: null, //set in onPreprocess/updateAxisSettings
label: null, // set in onPreprocess/updateAxisSettings,
type: 'linear',
behavior: 'raw',
format: '.2f'
//domain: [0, null]
},
y: {
column: null, // set in onPreprocess/updateAxisSettings,
label: null, // set in onPreprocess/updateAxisSettings,
type: 'linear',
behavior: 'raw',
format: '.2f'
//domain: [0, null]
},
marks: [
{
per: [], // set in syncSettings()
type: 'circle',
summarizeY: 'mean',
summarizeX: 'mean',
attributes: { 'fill-opacity': 0 }
}
],
gridlines: 'xy',
color_by: null, //set in syncSettings
max_width: 600,
aspect: 1,
legend: { location: 'top' },
margin: { right: 25, top: 25, bottom: 75 }
};
}
//Replicate settings in multiple places in the settings object
function syncSettings(settings$$1) {
var defaults = settings();
settings$$1.marks[0].per[0] = settings$$1.id_col;
//set grouping config
if (typeof settings$$1.group_cols == 'string') {
settings$$1.group_cols = [
{ value_col: settings$$1.group_cols, label: settings$$1.group_cols }
];
}
if (!(settings$$1.group_cols instanceof Array && settings$$1.group_cols.length)) {
settings$$1.group_cols = [{ value_col: 'NONE', label: 'None' }];
} else {
settings$$1.group_cols = settings$$1.group_cols.map(function(group) {
return {
value_col: group.value_col || group,
label: group.label || group.value_col || group
};
});
var hasNone =
settings$$1.group_cols
.map(function(m) {
return m.value_col;
})
.indexOf('NONE') > -1;
if (!hasNone) {
settings$$1.group_cols.unshift({ value_col: 'NONE', label: 'None' });
}
}
if (settings$$1.group_cols.length > 1) {
settings$$1.color_by = settings$$1.group_cols[1].value_col
? settings$$1.group_cols[1].value_col
: settings$$1.group_cols[1];
} else {
settings$$1.color_by = 'NONE';
}
//make sure filters is an Array
if (!(settings$$1.filters instanceof Array)) {
settings$$1.filters =
typeof settings$$1.filters == 'string' ? [settings$$1.filters] : [];
}
//Define default details.
var defaultDetails = [{ value_col: settings$$1.id_col, label: 'Subject Identifier' }];
if (settings$$1.filters) {
settings$$1.filters.forEach(function(filter) {
var obj = {
value_col: filter.value_col ? filter.value_col : filter,
label: filter.label
? filter.label
: filter.value_col
? filter.value_col
: filter
};
if (
defaultDetails.find(function(f) {
return f.value_col == obj.value_col;
}) == undefined
) {
defaultDetails.push(obj);
}
});
}
if (settings$$1.group_cols) {
settings$$1.group_cols
.filter(function(f) {
return f.value_col != 'NONE';
})
.forEach(function(group) {
var obj = {
value_col: group.value_col ? group.value_col : filter,
label: group.label
? group.label
: group.value_col
? group.value_col
: filter
};
if (
defaultDetails.find(function(f) {
return f.value_col == obj.value_col;
}) == undefined
) {
defaultDetails.push(obj);
}
});
}
//parse details to array if needed
if (!(settings$$1.details instanceof Array)) {
settings$$1.details =
typeof settings$$1.details == 'string' ? [settings$$1.details] : [];
}
//If [settings.details] is not specified:
if (!settings$$1.details) settings$$1.details = defaultDetails;
else {
//If [settings.details] is specified:
//Allow user to specify an array of columns or an array of objects with a column property
//and optionally a column label.
settings$$1.details.forEach(function(detail) {
if (
defaultDetails
.map(function(d) {
return d.value_col;
})
.indexOf(detail.value_col ? detail.value_col : detail) === -1
)
defaultDetails.push({
value_col: detail.value_col ? detail.value_col : detail,
label: detail.label
? detail.label
: detail.value_col
? detail.value_col
: detail
});
});
settings$$1.details = defaultDetails;
}
// If settings.analysisFlag is null
if (!settings$$1.analysisFlag) settings$$1.analysisFlag = { value_col: null, values: [] };
if (!settings$$1.analysisFlag.value_col) settings$$1.analysisFlag.value_col = null;
if (!(settings$$1.analysisFlag.values instanceof Array)) {
settings$$1.analysisFlag.values =
typeof settings$$1.analysisFlag.values == 'string'
? [settings$$1.analysisFlag.values]
: [];
}
//if it is null, set settings.baseline.value_col to settings.studyday_col.
if (!settings$$1.baseline) settings$$1.baseline = { value_col: null, values: [] };
if (!settings$$1.baseline.value_col)
settings$$1.baseline.value_col = settings$$1.studyday_col;
if (!(settings$$1.baseline.values instanceof Array)) {
settings$$1.baseline.values =
typeof settings$$1.baseline.values == 'string' ? [settings$$1.baseline.values] : [];
}
//merge in default measure_values if user hasn't specified changes
Object.keys(defaults.measure_values).forEach(function(val) {
if (!settings$$1.measure_values.hasOwnProperty(val))
settings$$1.measure_values[val] = defaults.measure_values[val];
});
//check for 'all' in x_, y_ and point_size_options, but keep track if all options are used for later
var allMeasures = Object.keys(settings$$1.measure_values);
settings$$1.x_options_all = settings$$1.x_options == 'all';
if (settings$$1.x_options == 'all') settings$$1.x_options = allMeasures;
settings$$1.y_options_all = settings$$1.y_options == 'all';
if (settings$$1.y_options == 'all') settings$$1.y_options = allMeasures;
settings$$1.point_size_options_all = settings$$1.point_size_options == 'all';
if (settings$$1.point_size_options == 'all') settings$$1.point_size_options = allMeasures;
//parse x_ and y_options to array if needed
if (!(settings$$1.x_options instanceof Array)) {
settings$$1.x_options =
typeof settings$$1.x_options == 'string' ? [settings$$1.x_options] : [];
}
if (!(settings$$1.y_options instanceof Array)) {
settings$$1.y_options =
typeof settings$$1.y_options == 'string' ? [settings$$1.y_options] : [];
}
//set starting values for axis and point size settings.
settings$$1.point_size =
settings$$1.point_size_options.indexOf(settings$$1.point_size_default) > -1
? settings$$1.point_size_default
: settings$$1.point_size_default == 'rRatio'
? 'rRatio'
: 'Uniform';
settings$$1.x.column =
settings$$1.x_options.indexOf(settings$$1.x_default) > -1
? settings$$1.x_default
: settings$$1.x_options[0];
settings$$1.y.column =
settings$$1.y_options.indexOf(settings$$1.y_default) > -1
? settings$$1.y_default
: settings$$1.y_options[0];
// track initial Cutpoint (lets us detect when cutpoint should change)
settings$$1.cuts.x = settings$$1.x.column;
settings$$1.cuts.y = settings$$1.y.column;
settings$$1.cuts.display = settings$$1.display;
// Confirm detault cuts are set
settings$$1.cuts.defaults = settings$$1.cuts.defaults || defaults.cuts.defaults;
settings$$1.cuts.defaults.relative_uln =
settings$$1.cuts.defaults.relative_uln || defaults.cuts.defaults.relative_uln;
settings$$1.cuts.defaults.relative_baseline =
settings$$1.cuts.defaults.relative_baseline || defaults.cuts.defaults.relative_baseline;
// keep default cuts if user hasn't provided an alternative
var cutMeasures = Object.keys(settings$$1.cuts);
Object.keys(defaults.cuts).forEach(function(m) {
if (cutMeasures.indexOf(m) == -1) {
settings$$1.cuts[m] = defaults.cuts[m];
}
});
return settings$$1;
}
function controlInputs() {
return [
{
type: 'number',
label: 'R Ratio Range',
description: 'Filter points based on R ratio [(ALT/ULN) / (ALP/ULN)]',
option: 'r_ratio[0]'
},
{
type: 'number',
label: null, //combined with r_ratio[0] control in formatRRatioControl()
description: null,
option: 'r_ratio[1]'
},
{
type: 'dropdown',
label: 'Group',
description: 'Grouping variable',
options: ['color_by'],
start: null, // set in syncControlInputs()
values: ['NONE'], // set in syncControlInputs()
require: true
},
{
type: 'dropdown',
label: 'Display Type',
description: 'Relative or absolute axes',
options: ['displayLabel'],
start: null, // set in syncControlInputs()
values: null, // set in syncControlInputs()
require: true
},
{
type: 'radio',
option: 'plot_max_values',
label: 'Plot Style',
values: [true, false],
relabels: ['Max Values', 'By Study Day']
},
{
type: 'number',
label: 'Study Day',
description: null, //set in onDraw/updateStudyDaySlider
option: 'plot_day'
},
{
type: 'dropdown',
label: 'X-axis Measure',
description: null, // set in syncControlInputs()
option: 'x.column',
start: null, // set in syncControlInputs()
values: null, //set in syncControlInptus()
require: true
},
{
type: 'number',
label: null, // set in syncControlInputs
description: 'X-axis Reference Line',
option: null // set in syncControlInputs
},
{
type: 'dropdown',
label: 'Y-axis Measure',
description: null, // set in syncControlInputs()
option: 'y.column',
start: null, // set in syncControlInputs()
values: null, //set in syncControlInptus()
require: true
},
{
type: 'number',
label: null, // set in syncControlInputs
description: 'Y-axis Reference Line',
option: null // set in syncControlInputs
},
{
type: 'dropdown',
label: 'Point Size',
description: 'Parameter to set point radius',
options: ['point_size'],
start: null, // set in syncControlInputs()
values: ['Uniform', 'rRatio', 'nrRatio'],
require: true
},
{
type: 'dropdown',
label: 'Axis Type',
description: 'Linear or Log Axes',
options: ['x.type', 'y.type'],
start: null, // set in syncControlInputs()
values: ['linear', 'log'],
require: true
},
{
type: 'number',
label: 'Highlight Points Based on Timing',
description: 'Fill points with max values less than X days apart',
option: 'visit_window'
}
];
}
//Map values from settings to control inputs
function syncControlInputs(controlInputs, settings) {
////////////////////////
// Group control
///////////////////////
var groupControl = controlInputs.find(function(controlInput) {
return controlInput.label === 'Group';
});
//sync start value
groupControl.start = settings.color_by; //sync start value
//sync values
settings.group_cols
.filter(function(group) {
return group.value_col !== 'NONE';
})
.forEach(function(group) {
groupControl.values.push(group.value_col);
});
//drop the group control if NONE is the only option
if (settings.group_cols.length == 1)
controlInputs = controlInputs.filter(function(controlInput) {
return controlInput.label != 'Group';
});
//////////////////////////
// x-axis measure control
//////////////////////////
// drop the control if there's only one option
if (settings.x_options.length === 1)
controlInputs = controlInputs.filter(function(controlInput) {
return controlInput.option !== 'x.column';
});
else {
//otherwise sync the properties
var xAxisMeasureControl = controlInputs.find(function(controlInput) {
return controlInput.option === 'x.column';
});
//xAxisMeasureControl.description = settings.x_options.join(', ');
xAxisMeasureControl.start = settings.x.column;
xAxisMeasureControl.values = settings.x_options;
}
//////////////////////////////////
// x-axis reference line control
//////////////////////////////////
var xRefControl = controlInputs.find(function(controlInput) {
return controlInput.description === 'X-axis Reference Line';
});
xRefControl.label = settings.x_options[0] + ' Cutpoint';
xRefControl.option = 'settings.cuts.' + [settings.x.column] + '.' + [settings.display];
////////////////////////////
// y-axis measure control
////////////////////////////
// drop the control if there's only one option
if (settings.y_options.length === 1)
controlInputs = controlInputs.filter(function(controlInput) {
return controlInput.option !== 'y.column';
});
else {
//otherwise sync the properties
var yAxisMeasureControl = controlInputs.find(function(controlInput) {
return controlInput.option === 'y.column';
});
// yAxisMeasureControl.description = settings.y_options.join(', ');
yAxisMeasureControl.start = settings.y.column;
yAxisMeasureControl.values = settings.y_options;
}
//////////////////////////////////
// y-axis reference line control
//////////////////////////////////
var yRefControl = controlInputs.find(function(controlInput) {
return controlInput.description === 'Y-axis Reference Line';
});
yRefControl.label = settings.y_options[0] + ' Cutpoint';
yRefControl.option = 'settings.cuts.' + [settings.y.column] + '.' + [settings.display];
//////////////////////////////////
// R ratio filter control
//////////////////////////////////
//drop the R Ratio control if r_ratio_filter is false
if (!settings.r_ratio_filter) {
controlInputs = controlInputs.filter(function(controlInput) {
return ['r_ratio[0]', 'r_ratio[1]'].indexOf(controlInput.option) == -1;
});
}
//////////////////////////////////
// Point size control
//////////////////////////////////
var pointSizeControl = controlInputs.find(function(ci) {
return ci.label === 'Point Size';
});
pointSizeControl.start = settings.point_size;
settings.point_size_options.forEach(function(d) {
pointSizeControl.values.push(d);
});
//drop the pointSize control if NONE is the only option
if (settings.point_size_options.length == 0)
controlInputs = controlInputs.filter(function(controlInput) {
return controlInput.label != 'Point Size';
});
//////////////////////////////////
// Display control
//////////////////////////////////
controlInputs.find(function(controlInput) {
return controlInput.label === 'Display Type';
}).values = settings.display_options.map(function(m) {
return m.label;
});
//////////////////////////////////
// Add filters to inputs
//////////////////////////////////
if (settings.filters && settings.filters.length > 0) {
var otherFilters = settings.filters.map(function(filter) {
filter = {
type: 'subsetter',
value_col: filter.value_col ? filter.value_col : filter,
label: filter.label
? filter.label
: filter.value_col
? filter.value_col
: filter,
multiple: settings.filters_multiselect
};
return filter;
});
return d3.merge([otherFilters, controlInputs]);
} else return controlInputs;
}
var configuration = {
settings: settings,
syncSettings: syncSettings,
controlInputs: controlInputs,
syncControlInputs: syncControlInputs
};
function checkMeasureDetails() {
var chart = this;
var config = this.config;
var measures = d3
.set(
this.raw_data.map(function(d) {
return d[config.measure_col];
})
)
.values()
.sort();
var specifiedMeasures = Object.keys(config.measure_values).map(function(e) {
return config.measure_values[e];
});
var missingMeasures = [];
Object.keys(config.measure_values).forEach(function(d) {
if (measures.indexOf(config.measure_values[d]) == -1) {
missingMeasures.push(config.measure_values[d]);
delete config.measure_values[d];
}
});
var nMeasuresRemoved = missingMeasures.length;
if (nMeasuresRemoved > 0)
console.warn(
'The data are missing ' +
(nMeasuresRemoved === 1 ? 'this measure' : 'these measures') +
': ' +
missingMeasures.join(', ') +
'.'
);
//automatically add Measures if requested
if (config.add_measures) {
measures.forEach(function(m, i) {
if (specifiedMeasures.indexOf(m) == -1) {
config.measure_values['m' + i] = m;
}
});
}
// add measures for nrRatio and rRatio
config.measure_values.nrRatio = 'nrRatio';
config.measure_values.rRatio = 'rRatio';
//check that x_options, y_options and size_options all have value keys/values in measure_values
var valid_options = Object.keys(config.measure_values);
var all_settings = ['x_options', 'y_options', 'point_size_options'];
all_settings.forEach(function(setting) {
// remove invalid options
config[setting].forEach(function(option) {
if (valid_options.indexOf(option) == -1) {
delete config[options][option];
console.warn(
option +
" wasn't found in the measure_values index and has been removed from config." +
setting +
'. This may cause problems with the chart.'
);
}
});
// update the control input settings
var controlLabel =
setting == 'x_options'
? 'X-axis Measure'
: setting == 'y_options'
? 'Y-axis Measure'
: 'Point Size';
var input = chart.controls.config.inputs.find(function(ci) {
return ci.label == controlLabel;
});
if (input) {
//only update this if the input settings exist - axis inputs with only one value are deleted
// add options for controls requesting 'all' measures
if (config[setting + '_all']) {
var point_size_options = d3.merge([['Uniform'], valid_options]);
config[setting] =
setting == 'point_size_options' ? point_size_options : valid_options;
input.values = config[setting];
}
}
});
//check that all measure_values have associated cuts
Object.keys(config.measure_values).forEach(function(m) {
// does a cut point for the measure exist? If not, create a placeholder.
if (!config.cuts.hasOwnProperty(m)) {
config.cuts[m] = {};
}
// does the cut have non-null baseline and ULN cuts associated, if not use the default values
config.cuts[m].relative_baseline =
config.cuts[m].relative_baseline || config.cuts.defaults.relative_baseline;
config.cuts[m].relative_uln =
config.cuts[m].relative_uln || config.cuts.defaults.relative_uln;
});
}
function iterateOverData() {
var _this = this;
this.raw_data.forEach(function(d) {
d[_this.config.x.column] = null; // placeholder variable for x-axis
d[_this.config.y.column] = null; // placeholder variable for y-axis
d.NONE = 'All Participants'; // placeholder variable for non-grouped comparisons
//Remove space characters from result variable.
if (typeof d[_this.config.value_col] == 'string')
d[_this.config.value_col] = d[_this.config.value_col].replace(/\s/g, ''); // remove space characters
});
}
function addRRatioFilter() {
if (this.config.r_ratio_filter) {
this.filters.push({
col: 'rRatioFlag',
val: 'Y',
choices: ['Y', 'N'],
loose: undefined
});
}
}
function imputeColumn(data, measure_column, value_column, measure, llod, imputed_value, drop) {
//returns a data set with imputed values (or drops records) for records at or below a lower threshold for a given measure
//data = the data set for imputation
//measure_column = the column with the text measure names
//value_column = the column with the numeric values to be changed via imputation
//measure = the measure to be imputed
//llod = the lower limit of detection - values at or below the llod are imputed
//imputed_value = value for imputed records
//drop = boolean flag indicating whether values at or below the llod should be dropped (default = false)
if (drop == undefined) drop = false;
if (drop) {
return data.filter(function(f) {
dropFlag = d[measure_column] == measure && +d[value_column] <= 0;