@@ -4,13 +4,18 @@ function on_report_load(conditional_probability_viral_loads) {
4
4
}
5
5
6
6
/* Generate the concentration plot using d3 library. */
7
- function draw_plot ( svg_id ) {
7
+ function draw_plot ( svg_id , group_id , times , concentrations_zoomed ,
8
+ concentrations , cumulative_doses , long_range_cumulative_doses ,
9
+ exposed_presence_intervals , short_range_interactions ) {
8
10
9
11
// Used for controlling the short-range interactions
10
- let button_full_exposure = document . getElementById ( "button_full_exposure" ) ;
11
- let button_hide_high_concentration = document . getElementById ( "button_hide_high_concentration" ) ;
12
- let long_range_checkbox = document . getElementById ( 'long_range_cumulative_checkbox' )
13
- let show_sr_legend = short_range_expirations ?. length > 0 ;
12
+ let button_full_exposure = document . getElementById ( `button_full_exposure-group_${ group_id } ` ) ;
13
+ let button_hide_high_concentration = document . getElementById ( `button_hide_high_concentration-group_${ group_id } ` ) ;
14
+ let long_range_checkbox = document . getElementById ( `long_range_cumulative_checkbox-group_${ group_id } ` ) ;
15
+ let show_sr_legend = short_range_interactions . length > 0 ;
16
+
17
+ let short_range_intervals = short_range_interactions . map ( ( interaction ) => interaction [ "presence_interval" ] ) ;
18
+ let short_range_expirations = short_range_interactions . map ( ( interaction ) => interaction [ "expiration" ] ) ;
14
19
15
20
var data_for_graphs = {
16
21
'concentrations' : [ ] ,
@@ -521,12 +526,12 @@ function draw_plot(svg_id) {
521
526
}
522
527
523
528
// Draw for the first time to initialize.
524
- redraw ( ) ;
529
+ redraw ( svg_id ) ;
525
530
update_concentration_plot ( concentrations , cumulative_doses ) ;
526
531
527
532
// Redraw based on the new size whenever the browser window is resized.
528
533
window . addEventListener ( "resize" , e => {
529
- redraw ( ) ;
534
+ redraw ( svg_id ) ;
530
535
if ( button_full_exposure && button_full_exposure . disabled ) update_concentration_plot ( concentrations , cumulative_doses ) ;
531
536
else update_concentration_plot ( concentrations_zoomed , long_range_cumulative_doses )
532
537
} ) ;
@@ -536,12 +541,13 @@ function draw_plot(svg_id) {
536
541
// 'list_of_scenarios' is a dictionary with all the scenarios
537
542
// 'times' is a list of times for all the scenarios
538
543
function draw_generic_concentration_plot (
539
- plot_svg_id ,
544
+ svg_id ,
545
+ times ,
540
546
y_axis_label ,
541
547
h_lines ,
542
548
) {
543
549
544
- if ( plot_svg_id === 'CO2_concentration_graph' ) {
550
+ if ( svg_id === 'CO2_concentration_graph' ) {
545
551
list_of_scenarios = { 'CO₂ concentration' : { 'concentrations' : CO2_concentrations } } ;
546
552
min_y_axis_domain = 400 ;
547
553
}
@@ -575,7 +581,7 @@ function draw_generic_concentration_plot(
575
581
var first_scenario = Object . values ( data_for_scenarios ) [ 0 ]
576
582
577
583
// Add main SVG element
578
- var plot_div = document . getElementById ( plot_svg_id ) ;
584
+ var plot_div = document . getElementById ( svg_id ) ;
579
585
var vis = d3 . select ( plot_div ) . append ( 'svg' ) ;
580
586
581
587
var xRange = d3 . scaleTime ( ) . domain ( [ first_scenario [ 0 ] . hour , first_scenario [ first_scenario . length - 1 ] . hour ] ) ;
@@ -706,7 +712,7 @@ function draw_generic_concentration_plot(
706
712
}
707
713
708
714
function update_concentration_plot ( concentration_data ) {
709
- list_of_scenarios = ( plot_svg_id === 'CO2_concentration_graph' ) ? { 'CO₂ concentration' : { 'concentrations' : CO2_concentrations } } : alternative_scenarios
715
+ list_of_scenarios = ( svg_id === 'CO2_concentration_graph' ) ? { 'CO₂ concentration' : { 'concentrations' : CO2_concentrations } } : alternative_scenarios
710
716
var highest_concentration = 0.
711
717
712
718
for ( scenario in list_of_scenarios ) {
@@ -739,11 +745,11 @@ function draw_generic_concentration_plot(
739
745
var graph_width ;
740
746
var graph_height ;
741
747
742
- function redraw ( ) {
748
+ function redraw ( svg_id ) {
743
749
// Define width and height according to the screen size. Always use an already defined
744
- var window_width = document . getElementById ( 'concentration_plot' ) . clientWidth ;
750
+ var window_width = document . getElementById ( svg_id ) . clientWidth ;
745
751
var div_width = window_width ;
746
- var div_height = document . getElementById ( 'concentration_plot' ) . clientHeight ;
752
+ var div_height = document . getElementById ( svg_id ) . clientHeight ;
747
753
graph_width = div_width ;
748
754
graph_height = div_height ;
749
755
var margins = { top : 30 , right : 20 , bottom : 50 , left : 60 } ;
@@ -882,12 +888,12 @@ function draw_generic_concentration_plot(
882
888
}
883
889
884
890
// Draw for the first time to initialize.
885
- redraw ( ) ;
891
+ redraw ( svg_id ) ;
886
892
update_concentration_plot ( 'concentrations' ) ;
887
893
888
894
// Redraw based on the new size whenever the browser window is resized.
889
895
window . addEventListener ( "resize" , e => {
890
- redraw ( ) ;
896
+ redraw ( svg_id ) ;
891
897
update_concentration_plot ( 'concentrations' ) ;
892
898
} ) ;
893
899
}
0 commit comments