diff --git a/plotting/datasheet.R b/plotting/datasheet.R index 1c34cf2aee01ec686e9b6676a46679158307711e..56ecfb63ba9c28ec4dd6895e475f379e19aa9640 100644 --- a/plotting/datasheet.R +++ b/plotting/datasheet.R @@ -433,7 +433,7 @@ datasheet_panel = function (list_df2plot, df_meta, trend_period, info_header, ti } if (!is.null(df_page)) { - section = 'fiche station' + section = 'Fiche station' subsection = code n_page = df_page$n[nrow(df_page)] + 1 df_page = bind_rows( @@ -497,11 +497,11 @@ datasheet_panel = function (list_df2plot, df_meta, trend_period, info_header, ti LM = cbind(rep(99, times=LMrow), LM, rep(99, times=LMrow)) LMcol = ncol(LM) - margin_height = 0.5 + margin_size = 0.5 height = 29.7 width = 21 - Norm_ratio = height * (info_ratio + time_ratio + var_ratio*nbp) / (height - 2*margin_height - foot_height) + Norm_ratio = height * (info_ratio + time_ratio + var_ratio*nbp) / (height - 2*margin_size - foot_height) info_height = height * info_ratio / Norm_ratio time_height = height * time_ratio / Norm_ratio @@ -514,13 +514,13 @@ datasheet_panel = function (list_df2plot, df_meta, trend_period, info_header, ti heightLM[Hcut == 2] = time_height heightLM[Hcut > 2 & Hcut < id_foot] = var_height heightLM[Hcut == id_foot] = foot_height - heightLM[Hcut == 99] = margin_height + heightLM[Hcut == 99] = margin_size - col_width = (width - 2*margin_height) / (LMcol - 2) + col_width = (width - 2*margin_size) / (LMcol - 2) Wcut = LM[(nrow(LM)-1),] widthLM = rep(col_width, times=LMcol) - widthLM[Wcut == 99] = margin_height + widthLM[Wcut == 99] = margin_size # Plot the graph as the layout plot = grid.arrange(grobs=P, layout_matrix=LM, diff --git a/plotting/layout.R b/plotting/layout.R index 4fb5889e2246cfe15e884dbcf2eda2b8bfc26e44..cb2437bb9983b85542d4f9e1710cdda1e6ab8523 100644 --- a/plotting/layout.R +++ b/plotting/layout.R @@ -242,7 +242,7 @@ datasheet_layout = function (df_data, df_meta, layout_matrix, list_df2plot[[i]] = df2plot } - df_page = tibble(section='sommaire', subsection=NA, n=1) + df_page = tibble(section='Sommaire', subsection=NA, n=1) # If map needs to be plot if ('map' %in% toplot) { @@ -299,8 +299,6 @@ datasheet_layout = function (df_data, df_meta, layout_matrix, outdirTmp=outdirTmp, df_page=df_page) } - - print(df_page) summary_panel(df_page, foot_note, @@ -315,6 +313,11 @@ datasheet_layout = function (df_data, df_meta, layout_matrix, details = file.info(list.files(outdirTmp, full.names=TRUE)) details = details[with(details, order(as.POSIXct(mtime))),] listfile_path = rownames(details) + + summary_path = listfile_path[length(listfile_path)] + listfile_path = listfile_path[-length(listfile_path)] + listfile_path = c(summary_path, listfile_path) + pdf_combine(input=listfile_path, output=file.path(outdir, outfile)) } @@ -487,22 +490,42 @@ palette_tester = function (n=256) { summary_panel = function (df_page, foot_note, foot_height, resources_path, AEAGlogo_file, INRAElogo_file, FRlogo_file, outdirTmp) { text_title = paste( - "<b> Analyse de stationnarité </b>", + "<b>Analyse de Stationnarité Hydrologique</b>", + sep='') + + text_subtitle = paste( + "Bassin Adour-Garonnne", sep='') Sec_name = rle(df_page$section)$values nSec = length(Sec_name) - text_sum = '' + nlim = 50 + + text_sum1 = '' + text_page1 = '' + text_sum2 = '' + text_page2 = '' + + nline = 0 + nline_max = 25 for (idS in 1:nSec) { sec_name = Sec_name[idS] subSec_name = rle(df_page$subsection[df_page$section == sec_name])$values n_page = df_page$n[df_page$section == sec_name][1] + + line = paste("<b>", idS, ". ", sec_name, "</b>", "<br>", sep='') + page = paste("<b>p.", n_page, "</b><br>", sep='') - text_sum = paste(text_sum, - idS, ". ", "<b>", sec_name, "</b>", - ' ', 'p.', n_page, "<br>", - sep='') + if (nline <= nline_max) { + text_sum1 = paste(text_sum1, line, sep='') + text_page1 = paste(text_page1, page, sep='') + } else { + text_sum2 = paste(text_sum2, line, sep='') + text_page2 = paste(text_page2, page, sep='') + } + + nline = nline + 1 nSSec = length(subSec_name) for (idSS in 1:nSSec) { @@ -510,23 +533,35 @@ summary_panel = function (df_page, foot_note, foot_height, resources_path, AEAGl if (!is.na(subsec_name)) { n_page = df_page$n[df_page$section == sec_name & df_page$subsection == subsec_name][1] + + line = paste(" ", idS, ".", idSS, ". ", + subsec_name, "<br>", sep='') + page = paste("p.", n_page, "<br>", sep='') - text_sum = paste(text_sum, - idS, ".", idSS, ". ", subsec_name, - ' ', 'p.', n_page, "<br>", - sep='') + if (nline <= nline_max) { + text_sum1 = paste(text_sum1, line, sep='') + text_page1 = paste(text_page1, page, sep='') + } else { + text_sum2 = paste(text_sum2, line, sep='') + text_page2 = paste(text_page2, page, sep='') + } + + nline = nline + 1 } } } - - text_sum = gsub('<ol>', '', text_sum) - - text_sum = "1. <b>sommaire</b><br>2. <b>carte des tendances observées</b><br>2.1. QA p.2<br>2.2. QMNA p.3<br>2.3. VCN10 p.4<br>2.4. DEB p.5<br>2.5. CEN p.6<br>3. <b>carte des écarts observés</b><br>3.1. QA p.7<br>3.2. QMNA p.8<br>3.3. VCN10 p.9<br>3.4. DEB p.10<br>3.5. CEN p.11<br>4. <b>tableau récapitulatif de saisonnalité</b><br>4.1. Adour p.12<br>5. <b>tableau récapitulatif de sévérité</b><br>5.1. Adour p.13<br>6. <b>fiche station</b><br>6.1. Q7002910 p.14<br>" + # text_sum1 = gsub("é", "é", text_sum1) + text_sum1 = gsub(" ", "<span style='color:white'>_</span>", + text_sum1) + text_sum1 = gsub('[.]', '.', text_sum1) + text_page1 = gsub('[.]', '.', text_page1) - print(text_title) - print(text_sum) + # text_sum2 = gsub("é", "é", text_sum2) + text_sum2 = gsub(" ", "<span style='color:white'>_</span>", + text_sum2) + text_sum2 = gsub('[.]', '.', text_sum2) + text_page2 = gsub('[.]', '.', text_page2) - # text_sum = 'test<br>test<br><b>test</b>' # Converts all texts to graphical object in the right position gtitle = richtext_grob(text_title, @@ -535,11 +570,36 @@ summary_panel = function (df_page, foot_note, foot_height, resources_path, AEAGl hjust=0, vjust=1, gp=gpar(col="#00A3A8", fontsize=20)) - gsum = richtext_grob(text_sum, - x=0, y=1, - margin=unit(c(t=0, r=0, b=0, l=0), "mm"), - hjust=0, vjust=1, - gp=gpar(col="#00A3A8", fontsize=10)) + gsubtitle = richtext_grob(text_subtitle, + x=0, y=1, + margin=unit(c(t=0, r=0, b=0, l=0), "mm"), + hjust=0, vjust=1, + gp=gpar(col="#00A3A8", fontsize=15)) + + gsum1 = richtext_grob(text_sum1, + x=0, y=1, + margin=unit(c(t=0, r=0, b=0, l=0), "mm"), + hjust=0, vjust=1, + gp=gpar(col="#00A3A8", fontsize=10)) + + gpage1 = richtext_grob(text_page1, + x=0, y=1, + margin=unit(c(t=0, r=0, b=0, l=0), "mm"), + hjust=0, vjust=1, + gp=gpar(col="#00A3A8", fontsize=10)) + + gsum2 = richtext_grob(text_sum2, + x=0, y=1, + margin=unit(c(t=0, r=0, b=0, l=0), "mm"), + hjust=0, vjust=1, + gp=gpar(col="#00A3A8", fontsize=10)) + + gpage2 = richtext_grob(text_page2, + x=0, y=1, + margin=unit(c(t=0, r=0, b=0, l=0), "mm"), + hjust=0, vjust=1, + gp=gpar(col="#00A3A8", fontsize=10)) + # If there is a foot note if (foot_note) { @@ -549,20 +609,26 @@ summary_panel = function (df_page, foot_note, foot_height, resources_path, AEAGl AEAGlogo_file, INRAElogo_file, FRlogo_file, foot_height) - P = list(gtitle, gsum, foot) - LM = matrix(c(1, - 2, - 3), - nrow=3, byrow=TRUE) + P = list(gtitle, gsubtitle, gsum1, gpage1, gsum2, gpage2, foot) + LM = matrix(c(1, 1, 1, 1, + 2, 2, 2, 2, + 3, 4, 5, 6, + 7, 7, 7, 7), + nrow=4, byrow=TRUE) } else { foot_height = 0 - P = list(gtitle, gsum) - LM = matrix(c(1, - 2), - nrow=2, byrow=TRUE) + P = list(gtitle, gsubtitle, gsum1, gpage1, gsum2, gpage2) + LM = matrix(c(1, 1, 1, 1, + 2, 2, 2, 2, + 3, 4, 5, 6), + nrow=3, byrow=TRUE) } - id_foot = 2 - + id_title = 1 + id_subtitle = 2 + id_page1 = 4 + id_page2 = 6 + id_foot = 7 + LMcol = ncol(LM) LMrow = nrow(LM) @@ -570,23 +636,29 @@ summary_panel = function (df_page, foot_note, foot_height, resources_path, AEAGl LMrow = nrow(LM) LM = cbind(rep(99, times=LMrow), LM, rep(99, times=LMrow)) LMcol = ncol(LM) - - margin_height = 0.5 + + title_height = 0.75 + subtitle_height = 1.25 + margin_size = 0.5 + page_width = 0.5 height = 29.7 width = 21 - row_height = (height - 2*margin_height - foot_height) / (LMrow - 3) + row_height = (height - 2*margin_size - foot_height - title_height - subtitle_height) / (LMrow - 5) Hcut = LM[, 2] heightLM = rep(row_height, times=LMrow) + heightLM[Hcut == id_title] = title_height + heightLM[Hcut == id_subtitle] = subtitle_height heightLM[Hcut == id_foot] = foot_height - heightLM[Hcut == 99] = margin_height + heightLM[Hcut == 99] = margin_size - col_width = (width - 2*margin_height) / (LMcol - 2) + col_width = (width - 2*margin_size - 2*page_width) / (LMcol - 4) - Wcut = LM[(nrow(LM)-1),] + Wcut = LM[4,] widthLM = rep(col_width, times=LMcol) - widthLM[Wcut == 99] = margin_height + widthLM[Wcut == id_page1 | Wcut == id_page2] = page_width + widthLM[Wcut == 99] = margin_size # Arranges the graphical object plot = grid.arrange(grobs=P, layout_matrix=LM, diff --git a/plotting/map.R b/plotting/map.R index 5403fc0ae98ba8b75b9090865b2991143bee9dfe..991e0c3354f7887d8f586f4c03359002ec95c990 100644 --- a/plotting/map.R +++ b/plotting/map.R @@ -892,9 +892,9 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer_trend=1, if (!is.null(df_page)) { if (j > 1) { - section = 'carte des écarts observés' + section = 'Carte des écarts observés' } else { - section = 'carte des tendances observées' + section = 'Carte des tendances observées' } subsection = var n_page = df_page$n[nrow(df_page)] + 1 @@ -946,22 +946,22 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer_trend=1, LM = cbind(rep(99, times=LMrow), LM, rep(99, times=LMrow)) LMcol = ncol(LM) - margin_height = 0.5 + margin_size = 0.5 height = 21 width = 29.7 - row_height = (height - 2*margin_height - foot_height) / (LMrow - 3) + row_height = (height - 2*margin_size - foot_height) / (LMrow - 3) Hcut = LM[, 2] heightLM = rep(row_height, times=LMrow) heightLM[Hcut == id_foot] = foot_height - heightLM[Hcut == 99] = margin_height + heightLM[Hcut == 99] = margin_size - col_width = (width - 2*margin_height) / (LMcol - 2) + col_width = (width - 2*margin_size) / (LMcol - 2) Wcut = LM[(nrow(LM)-1),] widthLM = rep(col_width, times=LMcol) - widthLM[Wcut == 99] = margin_height + widthLM[Wcut == 99] = margin_size # Arranges the graphical object plot = grid.arrange(grobs=P, layout_matrix=LM, diff --git a/plotting/matrix.R b/plotting/matrix.R index 65ce7c9e43f34c1f71e6198a6455b8044ca464c7..189ea3775595d4b245940043e40519bc0a84a453 100644 --- a/plotting/matrix.R +++ b/plotting/matrix.R @@ -1141,7 +1141,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice } if (!is.null(df_page)) { - section = paste('tableau récapitulatif de ', + section = paste('Tableau récapitulatif de ', type, sep='') subsection = title n_page = df_page$n[nrow(df_page)] + 1 @@ -1193,20 +1193,20 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice LM, rep(99, times=LMrow)) LMcol = ncol(LM) - margin_height = 0.5 + margin_size = 0.5 - row_height = (height - 2*margin_height - foot_height) / (LMrow - 3) + row_height = (height - 2*margin_size - foot_height) / (LMrow - 3) Hcut = LM[, 2] heightLM = rep(row_height, times=LMrow) heightLM[Hcut == id_foot] = foot_height - heightLM[Hcut == 99] = margin_height + heightLM[Hcut == 99] = margin_size - col_width = (width - 2*margin_height) / (LMcol - 2) + col_width = (width - 2*margin_size) / (LMcol - 2) Wcut = LM[(nrow(LM)-1),] widthLM = rep(col_width, times=LMcol) - widthLM[Wcut == 99] = margin_height + widthLM[Wcut == 99] = margin_size # Arranges the graphical object plot = grid.arrange(grobs=P, layout_matrix=LM, diff --git a/script.R b/script.R index f4550cdf600b9f2fa52f30ba3e8863af0e389d9a..6eb0fb9ea5d2aed0900c1a2e6ffd78f5bbea4257 100644 --- a/script.R +++ b/script.R @@ -309,29 +309,33 @@ datasheet_layout(toplot=c( ), df_meta=df_meta, - df_data=list(res_QAtrend$data, - res_QMNAtrend$data, - res_VCN10trend$data, - res_DEBtrend$data, - res_CENtrend$data), + df_data=list( + res_QAtrend$data, + res_QMNAtrend$data, + res_VCN10trend$data, + res_DEBtrend$data, + res_CENtrend$data), - df_trend=list(res_QAtrend$trend, - res_QMNAtrend$trend, - res_VCN10trend$trend, - res_DEBtrend$trend, - res_CENtrend$trend), + df_trend=list( + res_QAtrend$trend, + res_QMNAtrend$trend, + res_VCN10trend$trend, + res_DEBtrend$trend, + res_CENtrend$trend), - var=list('QA', - 'QMNA', - 'VCN10', - 'DEB', - 'CEN'), + var=list( + 'QA', + 'QMNA', + 'VCN10', + 'DEB', + 'CEN'), - type=list('sévérité', - 'sévérité', - 'sévérité', - 'saisonnalité', - 'saisonnalité'), + type=list( + 'sévérité', + 'sévérité', + 'sévérité', + 'saisonnalité', + 'saisonnalité'), layout_matrix=matrix(c(1, 2, 3, 4, 5), ncol=1),