From 219f3a0cb14fc54f4f8cb5e881bdf813389b54f0 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Fri, 8 Dec 2017 17:16:22 +0100 Subject: [PATCH 01/34] remove tmp file --- inst/application/server.R | 2 ++ man/exchangesStack.Rd | 10 +++++----- man/prodStack.Rd | 10 +++++----- tests/testthat/helper-init.R | 1 + tests/testthat/test-ts_plot.R | 11 ++++++++++- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/inst/application/server.R b/inst/application/server.R index 23fae84..4350aaf 100644 --- a/inst/application/server.R +++ b/inst/application/server.R @@ -117,9 +117,11 @@ function(input, output, session) { } }) + # in case of Rinno / packaging app for windows # (and so comment previous observe....!) # + # in app mod # observe({ # if(input$quit > 0){ # stopApp() diff --git a/man/exchangesStack.Rd b/man/exchangesStack.Rd index ad632ea..ad489e5 100644 --- a/man/exchangesStack.Rd +++ b/man/exchangesStack.Rd @@ -8,11 +8,11 @@ exchangesStack(x, area = NULL, mcYear = "average", dateRange = NULL, colors = NULL, main = NULL, ylab = NULL, unit = c("MWh", "GWh", "TWh"), compare = NULL, compareOpts = list(), interactive = getInteractivity(), legend = TRUE, - legendId = sample(1000000000, 1), groupId = legendId, - legendItemsPerRow = 5, width = NULL, height = NULL, - xyCompare = c("union", "intersect"), h5requestFiltering = list(), - stepPlot = FALSE, drawPoints = FALSE, timeSteph5 = "hourly", - mcYearh5 = NULL, tablesh5 = c("areas", "links"), ...) + legendId = sample(1e+09, 1), groupId = legendId, legendItemsPerRow = 5, + width = NULL, height = NULL, xyCompare = c("union", "intersect"), + h5requestFiltering = list(), stepPlot = FALSE, drawPoints = FALSE, + timeSteph5 = "hourly", mcYearh5 = NULL, tablesh5 = c("areas", "links"), + ...) } \arguments{ \item{x}{Object of class \code{antaresData} created with function diff --git a/man/prodStack.Rd b/man/prodStack.Rd index f6c3df7..e5a7a99 100644 --- a/man/prodStack.Rd +++ b/man/prodStack.Rd @@ -15,11 +15,11 @@ prodStack(x, stack = "eco2mix", areas = NULL, mcYear = "average", dateRange = NULL, main = "Production stack", unit = c("MWh", "GWh", "TWh"), compare = NULL, compareOpts = list(), interactive = getInteractivity(), legend = TRUE, - legendId = sample(1000000000, 1), groupId = legendId, - legendItemsPerRow = 5, width = NULL, height = NULL, - xyCompare = c("union", "intersect"), h5requestFiltering = list(), - stepPlot = FALSE, drawPoints = FALSE, timeSteph5 = "hourly", - mcYearh5 = NULL, tablesh5 = c("areas", "links"), ...) + legendId = sample(1e+09, 1), groupId = legendId, legendItemsPerRow = 5, + width = NULL, height = NULL, xyCompare = c("union", "intersect"), + h5requestFiltering = list(), stepPlot = FALSE, drawPoints = FALSE, + timeSteph5 = "hourly", mcYearh5 = NULL, tablesh5 = c("areas", "links"), + ...) } \arguments{ \item{name}{name of the stack to create or update} diff --git a/tests/testthat/helper-init.R b/tests/testthat/helper-init.R index ba421b4..9745d8a 100644 --- a/tests/testthat/helper-init.R +++ b/tests/testthat/helper-init.R @@ -21,6 +21,7 @@ if (sourcedir != "") { assign("studyPath", file.path(path, "test_case"), envir = globalenv()) assign("nweeks", 2, envir = globalenv()) + assign("pathtemp", path, envir = globalenv()) } setSimulationPath(get("studyPath", envir = globalenv())) diff --git a/tests/testthat/test-ts_plot.R b/tests/testthat/test-ts_plot.R index 6e7aa7a..e9d93ab 100644 --- a/tests/testthat/test-ts_plot.R +++ b/tests/testthat/test-ts_plot.R @@ -92,4 +92,13 @@ describe("tsPlot, no interactive return error", { expect_error(tsPlot(dta, interactive = FALSE, compare = "areas")) -}) \ No newline at end of file +}) + +if(requireNamespace("rhdf5")){ + rhdf5::H5close() +} +if(dir.exists(pathtemp)) +{ + unlink(pathtemp, recursive = TRUE) +} + From 0be89773f65b4288245db1153cf419354276a802 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Fri, 8 Dec 2017 17:34:55 +0100 Subject: [PATCH 02/34] remove note --- R/stack_map.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/stack_map.R b/R/stack_map.R index 336cfc8..4407bd2 100644 --- a/R/stack_map.R +++ b/R/stack_map.R @@ -32,8 +32,8 @@ stackMap <- function(x, mapLayout) if(is.null(colorLink2)){ colorLink2 <- "none" } - - + #Remove note + areaChartType <- sizeMiniPlot <- NULL sizeArea2 <- sizeArea if(is.null(sizeArea2)){ sizeArea2 <- "none" From 7fa7603e98346fa8f453f051c45a6ee764cc0f14 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Fri, 8 Dec 2017 17:41:29 +0100 Subject: [PATCH 03/34] test travis --- .travis.yml | 86 ++++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/.travis.yml b/.travis.yml index e1ad58b..34f5955 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,42 +1,46 @@ -# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r - -language: R -dist: trusty -sudo: required -cache: packages - -before_install: - sudo apt-get install -y libprotobuf-dev protobuf-compiler - -r: bioc-devel - -r_github_packages: - - hadley/devtools#1263 - - Bioconductor-mirror/zlibbioc - - Bioconductor-mirror/rhdf5 - - rte-antares-rpackage/manipulateWidget@develop - - rte-antares-rpackage/antaresMaps - - rte-antares-rpackage/antaresRead@develop - - rte-antares-rpackage/antaresProcessing@develop - -addons: - apt: - sources: - - sourceline: 'ppa:opencpu/jq' - packages: - - libjq-dev - - valgrind - - libgdal-dev - - libproj-dev - - libv8-3.14-dev - -include: - - r: release - - r: oldrel - - r: devel - -r_packages: - - covr - -after_success: +# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r + +language: R +dist: trusty +sudo: required +cache: packages + +before_install: + sudo apt-get install -y libprotobuf-dev protobuf-compiler + +r: + - bioc-devel + - oldrel + - release + - devel + +r_github_packages: + - hadley/devtools#1263 + - Bioconductor-mirror/zlibbioc + - Bioconductor-mirror/rhdf5 + - rte-antares-rpackage/manipulateWidget@develop + - rte-antares-rpackage/antaresMaps + - rte-antares-rpackage/antaresRead@develop + - rte-antares-rpackage/antaresProcessing@develop + +addons: + apt: + sources: + - sourceline: 'ppa:opencpu/jq' + packages: + - libjq-dev + - valgrind + - libgdal-dev + - libproj-dev + - libv8-3.14-dev + +include: + - r: release + - r: oldrel + - r: devel + +r_packages: + - covr + +after_success: - Rscript -e 'library(covr); codecov()' \ No newline at end of file From 13006697461a7a5756fe7ab3d44082b941f39b61 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Mon, 11 Dec 2017 11:38:33 +0100 Subject: [PATCH 04/34] add test --- tests/testthat/test-h5Request.R | 29 +++++++++++++++++++++++++++++ tests/testthat/test-plotXY.R | 11 +++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/testthat/test-h5Request.R create mode 100644 tests/testthat/test-plotXY.R diff --git a/tests/testthat/test-h5Request.R b/tests/testthat/test-h5Request.R new file mode 100644 index 0000000..a322fdf --- /dev/null +++ b/tests/testthat/test-h5Request.R @@ -0,0 +1,29 @@ +describe("h5", { + if(requireNamespace("rhdf5")){ + writeAntaresH5() + optsH5 <- setSimulationPath(getwd(), 1) + + expect_true(class(.getDateRange(optsH5, "hourly")) == "Date") + + expect_true(class(.getGraphFunction("ts")) == "function") + + fid <- rhdf5::H5Fopen(optsH5$h5path) + expect_true(all(.getTimeStep(fid) %in% c("hourly","daily","weekly","monthly","annual"))) + + expect_true(length(.getElements(optsH5, "areas", fid, "hourly")$areas) == 18) + expect_true(length(.getElements(optsH5, "clusters", fid, "hourly")$clusters) == 15) + expect_true(identical(.getClustersNames(fid, "hourly"), + .getElements(optsH5, "clusters", fid, "hourly")$clusters)) + + + + expect_true(length(.getVariablesH5(fid, "hourly", "areas")$areas) == 29) + + expect_true(length(.getTableInH5(fid, "hourly")) == 3) + + .tryCloseH5() + } + + +}) + \ No newline at end of file diff --git a/tests/testthat/test-plotXY.R b/tests/testthat/test-plotXY.R new file mode 100644 index 0000000..99e9ef6 --- /dev/null +++ b/tests/testthat/test-plotXY.R @@ -0,0 +1,11 @@ +describe("prodStack, no interactive", { + dta <- readAntares(areas = "all") + + + + VV <- plotXY(dta, "NODU", "LOAD", precision = 50, + sizeOnCount = FALSE) + expect_true("htmlwidget" %in% class(VV)) + + +}) \ No newline at end of file From a5201dc82a5c4ae1ce793643a8d3d645b9ed11b7 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Mon, 11 Dec 2017 12:06:59 +0100 Subject: [PATCH 05/34] tests --- R/plot_thermal_group_capacities.R | 2 +- tests/testthat/test-h5Request.R | 10 +++++----- tests/testthat/test-plotThermalGroupCapacities.R | 10 ++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 tests/testthat/test-plotThermalGroupCapacities.R diff --git a/R/plot_thermal_group_capacities.R b/R/plot_thermal_group_capacities.R index 9b3cc60..6d0c55c 100644 --- a/R/plot_thermal_group_capacities.R +++ b/R/plot_thermal_group_capacities.R @@ -16,7 +16,7 @@ plotThermalGroupCapacities <- function(data, area = 'all', main = "Thermal group areaTp <- area data <- data[area %in% areaTp] } - data <- data.table::dcast(data, area~group, value.var = "thermalGroupCapacity") + data <- data.table::dcast(data, area~group, value.var = "thermalGroupCapacities") data <- data[,lapply(.SD, function(X){X[is.na(X)] <- 0;X}), .SDcols = 1:ncol(data)] toPLot <- names(data)[names(data)!="area"] p <- plot_ly(data, type = 'bar') %>% diff --git a/tests/testthat/test-h5Request.R b/tests/testthat/test-h5Request.R index a322fdf..8e5fa4b 100644 --- a/tests/testthat/test-h5Request.R +++ b/tests/testthat/test-h5Request.R @@ -1,7 +1,7 @@ describe("h5", { if(requireNamespace("rhdf5")){ - writeAntaresH5() - optsH5 <- setSimulationPath(getwd(), 1) + writeAntaresH5(pathtemp) + optsH5 <- setSimulationPath(pathtemp) expect_true(class(.getDateRange(optsH5, "hourly")) == "Date") @@ -10,8 +10,8 @@ describe("h5", { fid <- rhdf5::H5Fopen(optsH5$h5path) expect_true(all(.getTimeStep(fid) %in% c("hourly","daily","weekly","monthly","annual"))) - expect_true(length(.getElements(optsH5, "areas", fid, "hourly")$areas) == 18) - expect_true(length(.getElements(optsH5, "clusters", fid, "hourly")$clusters) == 15) + expect_true(length(.getElements(optsH5, "areas", fid, "hourly")$areas) == 9) + expect_true(length(.getElements(optsH5, "clusters", fid, "hourly")$clusters) == 7) expect_true(identical(.getClustersNames(fid, "hourly"), .getElements(optsH5, "clusters", fid, "hourly")$clusters)) @@ -19,7 +19,7 @@ describe("h5", { expect_true(length(.getVariablesH5(fid, "hourly", "areas")$areas) == 29) - expect_true(length(.getTableInH5(fid, "hourly")) == 3) + expect_true(length(.getTableInH5(fid, "hourly")) == 4) .tryCloseH5() } diff --git a/tests/testthat/test-plotThermalGroupCapacities.R b/tests/testthat/test-plotThermalGroupCapacities.R new file mode 100644 index 0000000..7b39973 --- /dev/null +++ b/tests/testthat/test-plotThermalGroupCapacities.R @@ -0,0 +1,10 @@ +describe("plotThermalGroupCapacities", { + opts <- setSimulationPath(studyPath) + GG <- plotThermalGroupCapacities( data = thermalGroupCapacities(opts)) + + expect_true("htmlwidget" %in% class(GG)) + + + +}) + From 391996c02f199c5523095587df438f3f48367710 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Mon, 11 Dec 2017 14:34:29 +0100 Subject: [PATCH 06/34] test --- tests/testthat/test-h5Request.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-h5Request.R b/tests/testthat/test-h5Request.R index 8e5fa4b..c57e513 100644 --- a/tests/testthat/test-h5Request.R +++ b/tests/testthat/test-h5Request.R @@ -23,6 +23,7 @@ describe("h5", { .tryCloseH5() } + }) From 111d4b8998836e18b74b0f73f14dfefaf9e169b8 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Mon, 11 Dec 2017 14:52:08 +0100 Subject: [PATCH 07/34] appveyor develop antaresProcessing --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 4de1121..d580767 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,7 +17,7 @@ build_script: - travis-tool.sh install_bioc zlibbioc - travis-tool.sh install_bioc rhdf5 - ./travis-tool.sh install_github rte-antares-rpackage/antaresRead@develop - - ./travis-tool.sh install_github rte-antares-rpackage/antaresProcessing@developTit + - ./travis-tool.sh install_github rte-antares-rpackage/antaresProcessing@develop - ./travis-tool.sh install_github rte-antares-rpackage/manipulateWidget@develop - ./travis-tool.sh install_github rte-antares-rpackage/antaresMaps From f77caf9daa69b0ea7d4397439df6e0509274cc97 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Mon, 11 Dec 2017 14:59:45 +0100 Subject: [PATCH 08/34] travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 34f5955..b41f610 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: R dist: trusty sudo: required -cache: packages +cache: false before_install: sudo apt-get install -y libprotobuf-dev protobuf-compiler From a02326f48e05312be2fe20fcfddf99af89dce5c6 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Mon, 11 Dec 2017 15:02:09 +0100 Subject: [PATCH 09/34] devtools --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b41f610..4c0eb29 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ r: - devel r_github_packages: - - hadley/devtools#1263 + - hadley/devtools - Bioconductor-mirror/zlibbioc - Bioconductor-mirror/rhdf5 - rte-antares-rpackage/manipulateWidget@develop From 2893bf9d31e1cdb15887db8a00f2c8c443f50e52 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Mon, 11 Dec 2017 15:20:00 +0100 Subject: [PATCH 10/34] travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4c0eb29..6e20bd8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: R dist: trusty sudo: required -cache: false +cache: packages before_install: sudo apt-get install -y libprotobuf-dev protobuf-compiler From 7057c731c28abf39630cd01ebdfe75bd423d8d35 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Mon, 11 Dec 2017 15:23:51 +0100 Subject: [PATCH 11/34] travis --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e20bd8..b80e338 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,10 @@ r: - release - devel +r_packages: + - covr + - devtools + r_github_packages: - hadley/devtools - Bioconductor-mirror/zlibbioc @@ -39,8 +43,7 @@ include: - r: oldrel - r: devel -r_packages: - - covr + after_success: - Rscript -e 'library(covr); codecov()' \ No newline at end of file From 5d9fb1e46753edd29f99a9ba9d5d22177597fc3d Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Mon, 11 Dec 2017 15:57:07 +0100 Subject: [PATCH 12/34] remove devtools from github --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b80e338..d7f26e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,6 @@ r_packages: - devtools r_github_packages: - - hadley/devtools - Bioconductor-mirror/zlibbioc - Bioconductor-mirror/rhdf5 - rte-antares-rpackage/manipulateWidget@develop From 28c9195d6570eff16e10430f6922cb7a3c53ac65 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Mon, 11 Dec 2017 16:21:37 +0100 Subject: [PATCH 13/34] use bioc --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index d7f26e8..d9ab5ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,12 @@ dist: trusty sudo: required cache: packages + before_install: sudo apt-get install -y libprotobuf-dev protobuf-compiler +use_bioc: true + r: - bioc-devel - oldrel From d30310ead974392d9791acea104606e59c90542e Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Mon, 11 Dec 2017 16:35:26 +0100 Subject: [PATCH 14/34] use bioc --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d9ab5ab..c4d090c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,8 @@ cache: packages before_install: sudo apt-get install -y libprotobuf-dev protobuf-compiler -use_bioc: true +bioc_required: true +bioc_use_devel: true r: - bioc-devel From 899440d8664f36af786c1315d94e13576260c238 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Mon, 11 Dec 2017 17:04:56 +0100 Subject: [PATCH 15/34] multi os --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index c4d090c..aeda538 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,11 @@ before_install: bioc_required: true bioc_use_devel: true +os: + - linux + - osx + + r: - bioc-devel - oldrel From afaa0a3f06e546efddfa2457e9c824caad9e3f83 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Tue, 12 Dec 2017 11:17:45 +0100 Subject: [PATCH 16/34] remove bug raw --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index aeda538..51b8357 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,6 @@ sudo: required cache: packages -before_install: - sudo apt-get install -y libprotobuf-dev protobuf-compiler bioc_required: true bioc_use_devel: true From 8b6c0ad330b3661d890be080d4aa66cb073ec800 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Tue, 12 Dec 2017 17:10:42 +0100 Subject: [PATCH 17/34] travis package deb --- .travis.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 51b8357..238551e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,7 @@ r: r_packages: - covr - devtools + - antaresProcessing r_github_packages: - Bioconductor-mirror/zlibbioc @@ -43,12 +44,6 @@ addons: - libgdal-dev - libproj-dev - libv8-3.14-dev - -include: - - r: release - - r: oldrel - - r: devel - after_success: From 4c8dad02c3ada7cfbf3e92a2446365971af7cf51 Mon Sep 17 00:00:00 2001 From: zawam Date: Thu, 14 Dec 2017 10:14:34 +0100 Subject: [PATCH 18/34] update news and description --- DESCRIPTION | 4 +- NEWS | 252 +++++++++++++++++++++++++++------------------------- 2 files changed, 135 insertions(+), 121 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9e7dab2..2e7ff34 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: antaresViz Type: Package Title: Antares Visualizations -Version: 0.11.3 -Date: 2017-12-07 +Version: 0.12.0 +Date: 2017-12-14 Authors@R: c( person("Jalal-Edine", "ZAWAM", , "jalal-edine.zawam@rte-france.com", role = c("aut", "cre")), person("Francois", "Guillem", , "francois.guillem@rte-france.com", role = "aut"), diff --git a/NEWS b/NEWS index 77f1308..ca2e61d 100644 --- a/NEWS +++ b/NEWS @@ -1,120 +1,134 @@ -Copyright © 2016 RTE Réseau de transport d’électricité - -Changes in version 0.11 (2017-07-17) - -NEW FEATURES: -* In plotMap(), it is now possible to represent areas with polygons instead of circles. To do see, user needs to provide a SpatialPolygonsDataFrame object to function mapLayout(). He is then able to interactively set associations between an area and a polygon. - -BUGFIXES: -* Hour was not correctly printed in some charts. -* It was not possible anymore to choose a specific Monte-Carlo scenario in plotMap() when interactive = FALSE. -* Non numeric columns were not correcly handled by plotMap(). -* Heatmaps were not correctly displayed in comparison mode. - -Changes in version 0.10 (2017-06-20) - -BREAKING CHANGES: -* Function plotMapOptions() has lost some parameters of little use and has gained new ones. This may break some scripts. - -NEW FEATURES: -* Comparison mode: All functions can now be used to compare two or more antaresData objects. It is also possible to use a single antaresData object but to compare multiple charts with different parameters. - -BUGFIXES: -* mapLayout() was containing references to the deprecated 'mapStudio' package. This causes a crash on computers where this package has not been installed when it was alive. - - -Changes in version 0.9 (2017-05-31) - -NEW FEATURES: -* plotMap() can now export animated maps. -* It is now possible to set minimal and maximal size of labels in maps. -* plotMap() can now bind non-numeric columns to the color of areas and links. -* It is now possible to set the size of plots in Rmarkdown documents with "runtime:shiny" - -BUGFIXES: -* plotMap(interactive=TRUE) now works in Rmarkdown documents with "runtime:shiny" - - -Changes in version 0.8 (2017-04-07) - -NEW FEATURES: -* All visualisation functions now accept synthetic and detailed data. A new parameter "mcYear" permits to choose whether to view averaged data or a given Monte-Carlo scenario. -* plotMap() now always uses the absolute value of variable 'FLOW LIN.' to avoid any confusion. Direction of flows are represented with arrows. -* plotMap() can now also represent categorical variables. -* It is now possible to use custom color palette for continuous color scales in maps and heatmaps. -* In heatmaps, the y-axis now contains month names instead of week ids. Moreover the info displayed when hovering data has been improved. -* exchangesStack() can now also represent exchanges with rest of the world (column 'ROW BAL.'). -* A new function called setInteractivity() has been added to globally turn off or turn on interactive mode. - -BUGFIXES: -* In plotMap(), several parameters were not working in non-interactive mode. -* In plotMap(), some links were not displayed if the associated values were small. -* Numbers are now correctly rounded on popups and legend in plotMap(). -* Invalid date/hours were displayed on charts due to problems of timezone. -* It was not possible to change width and height of heatmaps. - - -Changes in version 0.7 (2017-02-23) - -NEW FEATURES: -* plot() method can now generate heatmaps. -* plot() method has a new parameter "aggregate" to choose whether to visualize individual plots or aggregated plot. -* plotMap() can now display labels. This may require to increase area size so there is enough place for labels. - -BUGFIXES: -* Many small problems detected by R CMD CHECK have been solved. - - -Changes in version 0.6 (2017-01-23) - -BREAKING CHANGES: -* productionStack and has been renamed prodStack. - -NEW FEATURES: -* plotMap() can now use pie charts, bar charts and polar area charts to represent multiple variables. -* plotMap() can now represent average values on the whole period instead of representing only a single time step. -* plotMap() can now display labels on areas. This feature is still experimental for now and will be improved in next versions. -* It is now possible to choose which variables are displayed in popups in maps created with plotMap(). -* It is now possible to manually set break points for color scales in maps thourgh parameter "options" of plotMap. -* plot() method for antaresDataTable can now output monotone, density and cululated distribution. -* There is now a plot() method for antaresDataList objects. -* It is now possible to register custom production stack aliases with function 'setProdStackLegend'. New aliases are then available in prodStack(). -* The package now also provides a plot method for antaresDataList objects. - -BUGFIXES: -* plot() was not working with annual data. - -Changes in version 0.5 (2016-11-14) - -NEW FEATURES: -* plotMap() can now represent only areas and/or links. It is not necessary anymore to import both to create a map. -* plotMap() can now represent multiple variables with barcharts. A new option is available to choose whether to use the same scale for different variables or one scale per variable. -* plotMap() now displays a nice and clear legend. -* It is now possible to add a title to a map. -* plotMap() has a new parameter "options". With this parameter, user can modify many graphical parameters like colors, size of elements, parameters to construct color scales, etc. -* It is now possible to use a custom base map imported with package "sp". So an internet connection is not necesary anymore to display a nice map. -* When user clicks on a link or an area in a map, a popup appears and display values of the variables represented. - - -Changes in version 0.4 (2016-10-06) - -BREAKING CHANGES: -* add a file LICENSE and copyright to sources files - - -Changes in version 0.3 (2016-09-27) - -NEW FEATURES: -* New function exchangesStack to draw the exchanges of an area with its neighbours -* New function mapLayout that helps the user to bind areas of an antares study with geographical coordinates. The function launches an interactive widget where the user can place and move areas. -* New plot method for objects return by mapLayout(). It generates an interactive map that represents the network of an antares study. -* New function plotMap to visualize the results of an Antares simulation on a map. -* All functions have gained new arguments to control graphical parameters like title, axis label, colors, width and height. -* All functions that produce time series (stacked or not) now produce a beautiful and very clear legend. -* Time series plots (stacked or not) can share a unique legend. When they do, their zoom is synchronised: if the users zooms on one graphic, the zoom is also applied to the other graphics. This can be very helpful in shiny application or interactive documents produced with Rmarkdown. - -Changes in version 0.2 (2016-08-22) - -NEW FEATURES: -* plot method for antaresTable objects and productionStack have an improved interface that helps user choose what he wants to visualize. +Copyright © 2016 RTE Réseau de transport d’électricité + + +Changes in version 0.12.0 (2017-14-12) + +NEW FEATURES: +* plot(), prodStack(), exchangesStack(), plotMap() work with studies in h5. +* new function runAppAntaresViz(). +* new function plotThermalGroupCapacities(). +* new function limitSizeGraph(). +* new function plotXY(). +* new function modXY(). +* new function stackMap(). +* new option stepPlot in plot(), prodStack() and exchangesStack(). + + +Changes in version 0.11 (2017-07-17) + +NEW FEATURES: +* In plotMap(), it is now possible to represent areas with polygons instead of circles. To do see, user needs to provide a SpatialPolygonsDataFrame object to function mapLayout(). He is then able to interactively set associations between an area and a polygon. + +BUGFIXES: +* Hour was not correctly printed in some charts. +* It was not possible anymore to choose a specific Monte-Carlo scenario in plotMap() when interactive = FALSE. +* Non numeric columns were not correcly handled by plotMap(). +* Heatmaps were not correctly displayed in comparison mode. + +Changes in version 0.10 (2017-06-20) + +BREAKING CHANGES: +* Function plotMapOptions() has lost some parameters of little use and has gained new ones. This may break some scripts. + +NEW FEATURES: +* Comparison mode: All functions can now be used to compare two or more antaresData objects. It is also possible to use a single antaresData object but to compare multiple charts with different parameters. + +BUGFIXES: +* mapLayout() was containing references to the deprecated 'mapStudio' package. This causes a crash on computers where this package has not been installed when it was alive. + + +Changes in version 0.9 (2017-05-31) + +NEW FEATURES: +* plotMap() can now export animated maps. +* It is now possible to set minimal and maximal size of labels in maps. +* plotMap() can now bind non-numeric columns to the color of areas and links. +* It is now possible to set the size of plots in Rmarkdown documents with "runtime:shiny" + +BUGFIXES: +* plotMap(interactive=TRUE) now works in Rmarkdown documents with "runtime:shiny" + + +Changes in version 0.8 (2017-04-07) + +NEW FEATURES: +* All visualisation functions now accept synthetic and detailed data. A new parameter "mcYear" permits to choose whether to view averaged data or a given Monte-Carlo scenario. +* plotMap() now always uses the absolute value of variable 'FLOW LIN.' to avoid any confusion. Direction of flows are represented with arrows. +* plotMap() can now also represent categorical variables. +* It is now possible to use custom color palette for continuous color scales in maps and heatmaps. +* In heatmaps, the y-axis now contains month names instead of week ids. Moreover the info displayed when hovering data has been improved. +* exchangesStack() can now also represent exchanges with rest of the world (column 'ROW BAL.'). +* A new function called setInteractivity() has been added to globally turn off or turn on interactive mode. + +BUGFIXES: +* In plotMap(), several parameters were not working in non-interactive mode. +* In plotMap(), some links were not displayed if the associated values were small. +* Numbers are now correctly rounded on popups and legend in plotMap(). +* Invalid date/hours were displayed on charts due to problems of timezone. +* It was not possible to change width and height of heatmaps. + + +Changes in version 0.7 (2017-02-23) + +NEW FEATURES: +* plot() method can now generate heatmaps. +* plot() method has a new parameter "aggregate" to choose whether to visualize individual plots or aggregated plot. +* plotMap() can now display labels. This may require to increase area size so there is enough place for labels. + +BUGFIXES: +* Many small problems detected by R CMD CHECK have been solved. + + +Changes in version 0.6 (2017-01-23) + +BREAKING CHANGES: +* productionStack and has been renamed prodStack. + +NEW FEATURES: +* plotMap() can now use pie charts, bar charts and polar area charts to represent multiple variables. +* plotMap() can now represent average values on the whole period instead of representing only a single time step. +* plotMap() can now display labels on areas. This feature is still experimental for now and will be improved in next versions. +* It is now possible to choose which variables are displayed in popups in maps created with plotMap(). +* It is now possible to manually set break points for color scales in maps thourgh parameter "options" of plotMap. +* plot() method for antaresDataTable can now output monotone, density and cululated distribution. +* There is now a plot() method for antaresDataList objects. +* It is now possible to register custom production stack aliases with function 'setProdStackLegend'. New aliases are then available in prodStack(). +* The package now also provides a plot method for antaresDataList objects. + +BUGFIXES: +* plot() was not working with annual data. + +Changes in version 0.5 (2016-11-14) + +NEW FEATURES: +* plotMap() can now represent only areas and/or links. It is not necessary anymore to import both to create a map. +* plotMap() can now represent multiple variables with barcharts. A new option is available to choose whether to use the same scale for different variables or one scale per variable. +* plotMap() now displays a nice and clear legend. +* It is now possible to add a title to a map. +* plotMap() has a new parameter "options". With this parameter, user can modify many graphical parameters like colors, size of elements, parameters to construct color scales, etc. +* It is now possible to use a custom base map imported with package "sp". So an internet connection is not necesary anymore to display a nice map. +* When user clicks on a link or an area in a map, a popup appears and display values of the variables represented. + + +Changes in version 0.4 (2016-10-06) + +BREAKING CHANGES: +* add a file LICENSE and copyright to sources files + + +Changes in version 0.3 (2016-09-27) + +NEW FEATURES: +* New function exchangesStack to draw the exchanges of an area with its neighbours +* New function mapLayout that helps the user to bind areas of an antares study with geographical coordinates. The function launches an interactive widget where the user can place and move areas. +* New plot method for objects return by mapLayout(). It generates an interactive map that represents the network of an antares study. +* New function plotMap to visualize the results of an Antares simulation on a map. +* All functions have gained new arguments to control graphical parameters like title, axis label, colors, width and height. +* All functions that produce time series (stacked or not) now produce a beautiful and very clear legend. +* Time series plots (stacked or not) can share a unique legend. When they do, their zoom is synchronised: if the users zooms on one graphic, the zoom is also applied to the other graphics. This can be very helpful in shiny application or interactive documents produced with Rmarkdown. + +Changes in version 0.2 (2016-08-22) + +NEW FEATURES: +* plot method for antaresTable objects and productionStack have an improved interface that helps user choose what he wants to visualize. * plot method for antaresTable objects can now draw time series but also barplots and monotones. \ No newline at end of file From b80492e1ebe6b7147bf5c00c39470b83dc09e680 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Thu, 14 Dec 2017 10:21:12 +0100 Subject: [PATCH 19/34] default color links #156 --- R/map_helpers.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/map_helpers.R b/R/map_helpers.R index 14322bf..b4efa6f 100644 --- a/R/map_helpers.R +++ b/R/map_helpers.R @@ -58,6 +58,7 @@ res <- list(coords = data, dir = 0) # color + if (!colVar %in% names(data)) colVar <- "none" if (colVar != "none") { if (is.numeric(data[[colVar]])) { @@ -327,7 +328,7 @@ options$linkColorScaleOpts) # Use default values if needed - if (is.null(optsLink$color)) optsLink$color <- options$linkDefaultCol + if (is.null(optsLink$color) | options$linkDefaultCol != "#BEBECE") optsLink$color <- options$linkDefaultCol if (is.null(optsLink$size)) { optsLink$size <- options$linkDefaultSize optsLink$maxSize <- options$linkMaxSize From 74862886ceef6881049da9481d88afec410fdac7 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Thu, 14 Dec 2017 10:53:17 +0100 Subject: [PATCH 20/34] #158 --- .travis.yml | 1 - .../application/src/server/01_set_read_data.R | 6 +++ inst/application/src/server/07_write_h5.R | 5 ++ inst/application/src/ui/03_ui_convert_h5.R | 47 ++++++++++++++++--- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 238551e..f471898 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,6 @@ os: r: - - bioc-devel - oldrel - release - devel diff --git a/inst/application/src/server/01_set_read_data.R b/inst/application/src/server/01_set_read_data.R index 802dd44..e15baca 100644 --- a/inst/application/src/server/01_set_read_data.R +++ b/inst/application/src/server/01_set_read_data.R @@ -175,6 +175,12 @@ observe({ updateSelectInput(session, "rmva_storageFlexibility", "storageFlexibility :", choices = opts$areaList, selected = NULL) updateSelectInput(session, "rmva_production", "production :", choices = opts$areaList, selected = NULL) + + # removeVirtualAreas + updateSelectInput(session, "rmva_storageFlexibility_h5", "storageFlexibility :", choices = opts$areaList, selected = NULL) + updateSelectInput(session, "rmva_production_h5", "production :", choices = opts$areaList, selected = NULL) + + }) } }) diff --git a/inst/application/src/server/07_write_h5.R b/inst/application/src/server/07_write_h5.R index becfce3..d04bfc3 100644 --- a/inst/application/src/server/07_write_h5.R +++ b/inst/application/src/server/07_write_h5.R @@ -18,6 +18,11 @@ observe({ mustRun = input$mustRun_h5, thermalModulation = input$thermalModulation_h5, overwrite = input$overwrite_h5, + removeVirtualAreas = input$rmva_ctrl_h5, + storageFlexibility = input$rmva_storageFlexibility_h5, + production = input$rmva_production_h5, + reassignCosts = input$rmva_reassignCosts_h5, + newCols = input$rmva_newCols_h5, opts = opts() )}, error = function(e){ diff --git a/inst/application/src/ui/03_ui_convert_h5.R b/inst/application/src/ui/03_ui_convert_h5.R index 893f78c..0ab8f58 100644 --- a/inst/application/src/ui/03_ui_convert_h5.R +++ b/inst/application/src/ui/03_ui_convert_h5.R @@ -54,14 +54,47 @@ tabPanel("Convert to h5", checkboxInput("linkCapacity_h5", label = "linkCapacity") ) ), + + fluidRow( - column(12, - div(actionButton("write_h5", "Convert study to h5", icon = icon("floppy-o")), align = "center") ) - ) + column(3, + h4("removeVirtualAreas :") + ), + column(9, + + checkboxInput("rmva_ctrl_h5", "enabled", FALSE) + + ), + conditionalPanel("input.rmva_ctrl_h5", + fluidRow( + column(3, + selectInput("rmva_storageFlexibility_h5", "storageFlexibility :", choices = NULL, selected = NULL, multiple = TRUE) + ), + column(3, + selectInput("rmva_production_h5", "production :", choices = NULL, selected = NULL, multiple = TRUE) + ), + + column(3, + br(), + checkboxInput("rmva_reassignCosts_h5", "reassignCosts", FALSE) + ), + + column(3, + br(), + checkboxInput("rmva_newCols_h5", "newCols", FALSE)) + + )), + + fluidRow( + column(12, + div(actionButton("write_h5", "Convert study to h5", icon = icon("floppy-o")), align = "center") ) + ) + ) + ) + ), + conditionalPanel(condition = "output.have_study && output.current_opts_h5 === true", + h3("Already a .h5 study...!") ) ) - ), - conditionalPanel(condition = "output.have_study && output.current_opts_h5 === true", - h3("Already a .h5 study...!") - ) + ) \ No newline at end of file From 639ea1ca09e76b9e0f75d05a363c08c545f1383a Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Thu, 14 Dec 2017 11:22:43 +0100 Subject: [PATCH 21/34] remove magrittr dep (import by leafleat) --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9e7dab2..fe66bc3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,6 @@ Depends: Imports: dygraphs (>= 1.1.1), shiny (>= 0.13.0), - magrittr, plotly (>= 4.5.6), htmltools, htmlwidgets (>= 0.7.0), From 04c32a309354dc533161954b1825ffcecc5af81d Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Thu, 14 Dec 2017 14:10:33 +0100 Subject: [PATCH 22/34] build exe boolean in app --- inst/application/server.R | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/inst/application/server.R b/inst/application/server.R index 4350aaf..f3cca99 100644 --- a/inst/application/server.R +++ b/inst/application/server.R @@ -109,28 +109,32 @@ function(input, output, session) { #---------------- # quit #---------------- + buildExe <- FALSE + if(!buildExe) + { # in case of classic use : observe({ if(input$quit > 0){ stopApp(returnValue = TRUE) } }) - + }else{ + # in case of Rinno / packaging app for windows + # (and so comment previous observe....!) + # + # in app mod + observe({ + if(input$quit > 0){ + stopApp() + q("no") + } + }) + + session$onSessionEnded(function() { + stopApp() + q("no") + }) + } - # in case of Rinno / packaging app for windows - # (and so comment previous observe....!) - # - # in app mod - # observe({ - # if(input$quit > 0){ - # stopApp() - # q("no") - # } - # }) - # - # session$onSessionEnded(function() { - # stopApp() - # q("no") - # }) } From 83a531a4485226e693a44d7dc27745e862b7c709 Mon Sep 17 00:00:00 2001 From: Benoit Thieurmel Date: Thu, 14 Dec 2017 15:49:04 +0100 Subject: [PATCH 23/34] add merge states in map_layout --- DESCRIPTION | 4 +++- NAMESPACE | 2 ++ R/map_layout.R | 62 ++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fe66bc3..818a1cb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,7 +25,7 @@ Encoding: UTF-8 Depends: antaresRead (>= 2.0.0), antaresProcessing (>= 0.12.0), - spMaps (>= 0.1) + spMaps (>= 0.2) Imports: dygraphs (>= 1.1.1), shiny (>= 0.13.0), @@ -35,6 +35,8 @@ Imports: manipulateWidget (>= 0.8.0), leaflet (>= 1.1.0), sp, + rgeos, + raster, webshot, data.table, methods, diff --git a/NAMESPACE b/NAMESPACE index 79f1b51..e9f67ee 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -57,6 +57,8 @@ importFrom(plotly,add_trace) importFrom(plotly,config) importFrom(plotly,layout) importFrom(plotly,plot_ly) +importFrom(raster,aggregate) +importFrom(rgeos,gDistance) importFrom(shiny,runApp) importFrom(stats,as.formula) importFrom(stats,density) diff --git a/R/map_layout.R b/R/map_layout.R index eeab209..fb00bd1 100644 --- a/R/map_layout.R +++ b/R/map_layout.R @@ -109,18 +109,28 @@ changeCoordsUI <- function(id, map_builder = TRUE) { tagList( fluidRow( - column(5, + column(4, if(map_builder){ selectInput(ns("ml_countries"), "Countries : ", width = "100%", choices = choices_map, selected = "all", multiple = TRUE) } ), - column(5, + column(4, if(map_builder){ selectInput(ns("ml_states"), "States : ", width = "100%", choices = choices_map, selected = NULL, multiple = TRUE) } - ), + ), + column(1, + if(map_builder){ + div(br(), checkboxInput(ns("merge_cty"), "Merge country ?", TRUE), align = "center") + } + ), + column(1, + if(map_builder){ + div(br(), checkboxInput(ns("merge_ste"), "Merge states ?", TRUE), align = "center") + } + ), column(2, if(map_builder){ div(br(), actionButton(ns("set_map_ml"), "Set map"), align = "center") @@ -162,6 +172,8 @@ changeCoordsUI <- function(id, map_builder = TRUE) { } # changeCoords Module SERVER function +#' @importFrom rgeos gDistance +#' @importFrom raster aggregate changeCoordsServer <- function(input, output, session, layout, what = reactive("areas"), map = reactive(NULL), map_builder = TRUE, stopApp = FALSE){ @@ -184,7 +196,8 @@ changeCoordsServer <- function(input, output, session, if(!is.null(map()) & input$set_map_ml == 0){ map() } else { - getSpMaps(countries = isolate(input$ml_countries), states = isolate(input$ml_states)) + getSpMaps(countries = isolate(input$ml_countries), states = isolate(input$ml_states), + mergeCountry = isolate(input$merge_cty)) } } }) @@ -329,7 +342,12 @@ changeCoordsServer <- function(input, output, session, observeEvent(input$done, { coords <- sp::SpatialPoints(coords()[, c("lon", "lat")], proj4string = sp::CRS("+proj=longlat +datum=WGS84")) + + map <- current_map() + + # info1 <<- list(coords = coords, map = map) + if (!is.null(map)) { map <- sp::spTransform(map, sp::CRS("+proj=longlat +datum=WGS84")) map$geoAreaId <- 1:length(map) @@ -354,12 +372,46 @@ changeCoordsServer <- function(input, output, session, final_links[final_coords, `:=`(x1 = x, y1 = y),on=c(toDistrict = "district")] } + # info2 <<- list(mapCoords = mapCoords, final_coords = final_coords, final_links = final_links) + if (!is.null(map)) { final_coords$geoAreaId <- mapCoords$geoAreaId final_coords_map <- final_coords[!is.na(final_coords$geoAreaId),] - map <- map[final_coords_map$geoAreaId,] + if(!isolate(input$merge_ste)){ + map <- map[final_coords_map$geoAreaId,] + } else { + if(all(c("name", "code") %in% names(map))){ + keep_code <- unique(map$code[final_coords_map$geoAreaId]) + # subset on countries + map <- map[map$code %in% keep_code,] + # set unlink states + map$geoAreaId[!map$geoAreaId %in% final_coords_map$geoAreaId] <- NA + + ind_na <- which(is.na(map$geoAreaId)) + if(length(ind_na) > 0){ + # have to find nearestArea... + treat_cty <- unique(map$code[ind_na]) + + for(cty in treat_cty){ + ind_cty <- which(map$code %in% cty) + ind_miss <- which(map$code %in% cty & is.na(map$geoAreaId)) + areas <- coords[coords$geoAreaId %in% map$geoAreaId[ind_cty], ] + if(nrow(areas) > 0){ + areas_min <- suppressWarnings(apply(rgeos::gDistance(map[ind_miss, ], areas, byid = TRUE),2, which.min)) + map$geoAreaId[ind_miss] <- areas$geoAreaId[areas_min] + } + } + + map <- raster::aggregate(map, by = c("geoAreaId")) + map <- map[match(final_coords_map$geoAreaId, map$geoAreaId), ] + } + } else { + map <- map[final_coords_map$geoAreaId,] + } + } res <- list(coords = final_coords_map, links = final_links, map = map, all_coords = final_coords) + } else { res <- list(coords = final_coords, links = final_links, map = map, all_coords = final_coords) } From 72c3886b81bb238b0c9870445a038f3683b793a9 Mon Sep 17 00:00:00 2001 From: Benoit Thieurmel Date: Thu, 14 Dec 2017 15:49:11 +0100 Subject: [PATCH 24/34] update man --- man/exchangesStack.Rd | 10 +++++----- man/prodStack.Rd | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/man/exchangesStack.Rd b/man/exchangesStack.Rd index ad489e5..ad632ea 100644 --- a/man/exchangesStack.Rd +++ b/man/exchangesStack.Rd @@ -8,11 +8,11 @@ exchangesStack(x, area = NULL, mcYear = "average", dateRange = NULL, colors = NULL, main = NULL, ylab = NULL, unit = c("MWh", "GWh", "TWh"), compare = NULL, compareOpts = list(), interactive = getInteractivity(), legend = TRUE, - legendId = sample(1e+09, 1), groupId = legendId, legendItemsPerRow = 5, - width = NULL, height = NULL, xyCompare = c("union", "intersect"), - h5requestFiltering = list(), stepPlot = FALSE, drawPoints = FALSE, - timeSteph5 = "hourly", mcYearh5 = NULL, tablesh5 = c("areas", "links"), - ...) + legendId = sample(1000000000, 1), groupId = legendId, + legendItemsPerRow = 5, width = NULL, height = NULL, + xyCompare = c("union", "intersect"), h5requestFiltering = list(), + stepPlot = FALSE, drawPoints = FALSE, timeSteph5 = "hourly", + mcYearh5 = NULL, tablesh5 = c("areas", "links"), ...) } \arguments{ \item{x}{Object of class \code{antaresData} created with function diff --git a/man/prodStack.Rd b/man/prodStack.Rd index e5a7a99..f6c3df7 100644 --- a/man/prodStack.Rd +++ b/man/prodStack.Rd @@ -15,11 +15,11 @@ prodStack(x, stack = "eco2mix", areas = NULL, mcYear = "average", dateRange = NULL, main = "Production stack", unit = c("MWh", "GWh", "TWh"), compare = NULL, compareOpts = list(), interactive = getInteractivity(), legend = TRUE, - legendId = sample(1e+09, 1), groupId = legendId, legendItemsPerRow = 5, - width = NULL, height = NULL, xyCompare = c("union", "intersect"), - h5requestFiltering = list(), stepPlot = FALSE, drawPoints = FALSE, - timeSteph5 = "hourly", mcYearh5 = NULL, tablesh5 = c("areas", "links"), - ...) + legendId = sample(1000000000, 1), groupId = legendId, + legendItemsPerRow = 5, width = NULL, height = NULL, + xyCompare = c("union", "intersect"), h5requestFiltering = list(), + stepPlot = FALSE, drawPoints = FALSE, timeSteph5 = "hourly", + mcYearh5 = NULL, tablesh5 = c("areas", "links"), ...) } \arguments{ \item{name}{name of the stack to create or update} From 460a66f99038533b80a062433e5e4b7b35fef576 Mon Sep 17 00:00:00 2001 From: Benoit Thieurmel Date: Thu, 14 Dec 2017 16:01:24 +0100 Subject: [PATCH 25/34] rm title select input from map --- R/map.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/map.R b/R/map.R index a5b7aef..40c1f46 100644 --- a/R/map.R +++ b/R/map.R @@ -642,7 +642,6 @@ plotMap <- function(x, mapLayout, colAreaVar = "none", sizeAreaVars = c(), .display = any(sapply(params$x, function(p) {"links" %in% names(p$x)})) ), mapLayout = mwSharedValue(mapLayout), - main = mwText(main, label = "title"), params = mwSharedValue({ .getDataForComp(x_tranform, NULL, compare, compareOpts, processFun = processFun, mapLayout = mapLayout) From 2cedc07cd9a161ed331785d8e9a4ba0a7e62ba4b Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Thu, 14 Dec 2017 16:46:21 +0100 Subject: [PATCH 26/34] more test --- R/map.R | 17 ++++++++++-- man/plotMap.Rd | 2 +- tests/testthat/test-graphUtils.R | 47 ++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 tests/testthat/test-graphUtils.R diff --git a/R/map.R b/R/map.R index a5b7aef..2da9f93 100644 --- a/R/map.R +++ b/R/map.R @@ -58,7 +58,7 @@ #' step at a time. In interactive mode, an input control permits to choose the #' time step shown. #' @param timeId -#' A single time id present in the data. Only used if \code{type="detail"} +#' time id present in the data. #' @param main #' Title of the map. #' @param options @@ -245,7 +245,20 @@ plotMap <- function(x, mapLayout, colAreaVar = "none", sizeAreaVars = c(), timeIdMax <- max(x[[1]]$timeId) # Select first timeId if necessary - if (is.null(timeId)) timeId <- timeIdMin + if (is.null(timeId)){ + timeId <- timeIdMin + }else{ + timeIdTp <- timeId + if(!is.null(x$areas)){ + x$areas <- x$areas[timeId %in% timeIdTp] + } + + if(!is.null(x$links)){ + x$links <- x$links[timeId %in% timeIdTp] + } + + + } # Keep only links and areas present in the data if (areas) { diff --git a/man/plotMap.Rd b/man/plotMap.Rd index 8e1c564..aeb1a36 100644 --- a/man/plotMap.Rd +++ b/man/plotMap.Rd @@ -68,7 +68,7 @@ represented on the map. If it is equal to \code{"detail"}, only one time step at a time. In interactive mode, an input control permits to choose the time step shown.} -\item{timeId}{A single time id present in the data. Only used if \code{type="detail"}} +\item{timeId}{time id present in the data.} \item{mcYear}{If \code{x}, contains multiple Monte-Carlo scenarios, this parameter determine which scenario is displayed. Must be an integer representing the diff --git a/tests/testthat/test-graphUtils.R b/tests/testthat/test-graphUtils.R new file mode 100644 index 0000000..03cef82 --- /dev/null +++ b/tests/testthat/test-graphUtils.R @@ -0,0 +1,47 @@ +context(".compOpts") + + +describe(".compOpts", { + + expect_true(.compOpts("", "cp")$ncharts == 2) + expect_true(.compOpts("", NULL)$ncharts == 1) + expect_true(.compOpts(list(), NULL)$ncharts == 1) +}) + + +context(".dateRangeJoin") +describe(".dateRangeJoin", { + dt <- list() + dt$x <- list(list(dateRange = as.Date(c("2010-01-01", "2010-01-10"))), + list(dateRange = as.Date(c("2010-01-02", "2010-01-09")))) + + + + + expect_true(.dateRangeJoin(dt, "union", "min") == as.Date("2010-01-01")) + expect_true(.dateRangeJoin(dt, "union", "max") == as.Date("2010-01-10")) + expect_true(.dateRangeJoin(dt, "intersect", "max") == as.Date("2010-01-09")) + expect_true(.dateRangeJoin(dt, "intersect", "min") == as.Date("2010-01-02")) + + dt2 <- list() + dt2$x <- list(list(ar = list(dateRange = as.Date(c("2010-01-01", "2010-01-10")))), + list(ar = list(dateRange = as.Date(c("2010-01-02", "2010-01-09"))))) + + expect_true(.dateRangeJoin(dt2, "union", "min", "ar") == as.Date("2010-01-01")) + expect_true(.dateRangeJoin(dt2, "union", "max", "ar") == as.Date("2010-01-10")) + expect_true(.dateRangeJoin(dt2, "intersect", "max", "ar") == as.Date("2010-01-09")) + expect_true(.dateRangeJoin(dt2, "intersect", "min", "ar") == as.Date("2010-01-02")) + +}) + +context(".loadH5Data") +describe(".loadH5Data", { + opts <- setSimulationPath(studyPath) + sharerequest <- list() + sharerequest$mcYearh_l <- "all" + sharerequest$tables_l <- c("areas", "links", "clusters", "districts") + sharerequest$timeSteph5_l <- "hourly" + expect_true("antaresDataList" %in% class(.loadH5Data(sharerequest, opts))) + +}) + From e068a49f266dee88d975951e298c39aff2bbc894 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Thu, 14 Dec 2017 16:55:27 +0100 Subject: [PATCH 27/34] remove old file --- R/api_info.R | 161 --------------------------------------------------- 1 file changed, 161 deletions(-) delete mode 100644 R/api_info.R diff --git a/R/api_info.R b/R/api_info.R deleted file mode 100644 index db24422..0000000 --- a/R/api_info.R +++ /dev/null @@ -1,161 +0,0 @@ -.giveH5DataToApi <- function(sharerequest, infos, areas = NULL, links = NULL, clusters = NULL, districts = NULL){ - if(infos$isH5){ - gc() - if(length(sharerequest$mcYearh_l)==0) {mcYearh2 <- NULL}else{ - if("all"%in%sharerequest$mcYearh_l){ - mcYearh2 <- "all" - }else{ - mcYearh2 <- as.numeric(sharerequest$mcYearh_l) - } - } - if(!is.null(sharerequest$tables_l)) - { - if("areas" %in% sharerequest$tables_l){ - areas <- "all" - } - if("links" %in% sharerequest$tables_l){ - links <- "all" - } - if("clusters" %in% sharerequest$tables_l){ - clusters <- "all" - } - if("districts" %in% sharerequest$tables_l){ - districts <- "all" - } - } - readAntares(areas = areas, links = links, clusters = clusters,districts = districts , mcYears = mcYearh2, - timeStep = sharerequest$timeSteph5_l, opts = infos$dataInput) - }else{ - infos$dataInput - } -} - - - - - - - - -.giveDateInfos <- function(yD, params, xyCompare, minMax, tabl = NULL){ - use <- NULL - nulTab <- is.null(tabl) - if(!is.null(params)) - { - if(minMax == "min") - { - if(is.null(yD)){ - if(!nulTab) - { - use <- params$x[[1]][[tabl]]$dataDateRange[1] - } - else{ - use <- params$x[[1]]$dataDateRange[1] - } - }else if(xyCompare == "union"){ - use <- min( - do.call("c",(lapply(params$x, function(vv){ - if(nulTab){ - unique(vv$dataDateRange[1]) - }else{ - vv[[tabl]]$dataDateRange[1] - } - } - )))) - } else if(xyCompare == "intersect"){ - use <- max( - do.call("c",(lapply(params$x, function(vv){ - if(nulTab){ - unique(vv$dataDateRange[1]) - }else{ - vv[[tabl]]$dataDateRange[1] - } - } - )))) - } - } - if(minMax == "max") - { - if(is.null(yD)){ - if(!nulTab) - { - use <- params$x[[1]][[tabl]]$dataDateRange[2] - } - else{ - use <- params$x[[1]]$dataDateRange[2] - } - }else if(xyCompare == "union"){ - use <- max( - do.call("c",(lapply(params$x, function(vv){ - if(nulTab){ - unique(vv$dataDateRange[2]) - }else{ - vv[[tabl]]$dataDateRange[2] - } - } - )))) - } else if(xyCompare == "intersect"){ - use <- min( - do.call("c",(lapply(params$x, function(vv){ - if(nulTab){ - unique(vv$dataDateRange[2]) - }else{ - vv[[tabl]]$dataDateRange[2] - } - } - )))) - } - }} - use -} - -.giveParamH5 <- function(X_I, Y_I, xyCompare){ - if(X_I$isH5){ - opts <- X_I$dataInput - fid <- rhdf5::H5Fopen(opts$h5path) - timeStepS <- .getTimeStep(fid) - timeStepS <- as.character(timeStepS) - mcYearS <- opts$mcYears - tabl <- .getTableInH5(fid, timeStepS[1]) - rhdf5::H5Fclose(fid) - xPart = list( - timeStepS = timeStepS, - mcYearS = mcYearS, - tabl = tabl - ) - - }else{ - xPart = NULL - } - if(Y_I$isH5){ - opts <- Y_I$dataInput - fid <- rhdf5::H5Fopen(opts$h5path) - timeStepS <- .getTimeStep(fid) - timeStepS <- as.character(timeStepS) - mcYearS <- opts$mcYears - tabl <- .getTableInH5(fid, timeStepS[1]) - tabl <- tabl[tabl%in%c("areas", "districts")] - rhdf5::H5Fclose(fid) - yPart = list( - timeStepS = timeStepS, - mcYearS = mcYearS, - tabl = tabl - ) - }else{ - yPart = NULL - } - if(is.null(xPart) & is.null(yPart)){ - ret <- NULL - }else if(is.null(xPart)){ - ret <- yPart - }else if(is.null(yPart)){ - ret <- xPart - }else{ - ret <- list() - ret$timeStepS <- .compareOperation(list(xPart$timeStepS, yPart$timeStepS), xyCompare) - ret$mcYearS <- sort(.compareOperation(list(xPart$mcYearS, yPart$mcYearS), xyCompare)) - ret$tabl <- .compareOperation(list(xPart$tabl, yPart$tabl), xyCompare) - } - rhdf5::H5close() - ret -} \ No newline at end of file From 24205cb80965b519933f8c4eec2a9326935ea1b1 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Thu, 14 Dec 2017 16:59:17 +0100 Subject: [PATCH 28/34] control h5 --- man/exchangesStack.Rd | 10 ++--- man/prodStack.Rd | 10 ++--- tests/testthat/test-graphUtils.R | 74 ++++++++++++++++---------------- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/man/exchangesStack.Rd b/man/exchangesStack.Rd index ad632ea..ad489e5 100644 --- a/man/exchangesStack.Rd +++ b/man/exchangesStack.Rd @@ -8,11 +8,11 @@ exchangesStack(x, area = NULL, mcYear = "average", dateRange = NULL, colors = NULL, main = NULL, ylab = NULL, unit = c("MWh", "GWh", "TWh"), compare = NULL, compareOpts = list(), interactive = getInteractivity(), legend = TRUE, - legendId = sample(1000000000, 1), groupId = legendId, - legendItemsPerRow = 5, width = NULL, height = NULL, - xyCompare = c("union", "intersect"), h5requestFiltering = list(), - stepPlot = FALSE, drawPoints = FALSE, timeSteph5 = "hourly", - mcYearh5 = NULL, tablesh5 = c("areas", "links"), ...) + legendId = sample(1e+09, 1), groupId = legendId, legendItemsPerRow = 5, + width = NULL, height = NULL, xyCompare = c("union", "intersect"), + h5requestFiltering = list(), stepPlot = FALSE, drawPoints = FALSE, + timeSteph5 = "hourly", mcYearh5 = NULL, tablesh5 = c("areas", "links"), + ...) } \arguments{ \item{x}{Object of class \code{antaresData} created with function diff --git a/man/prodStack.Rd b/man/prodStack.Rd index f6c3df7..e5a7a99 100644 --- a/man/prodStack.Rd +++ b/man/prodStack.Rd @@ -15,11 +15,11 @@ prodStack(x, stack = "eco2mix", areas = NULL, mcYear = "average", dateRange = NULL, main = "Production stack", unit = c("MWh", "GWh", "TWh"), compare = NULL, compareOpts = list(), interactive = getInteractivity(), legend = TRUE, - legendId = sample(1000000000, 1), groupId = legendId, - legendItemsPerRow = 5, width = NULL, height = NULL, - xyCompare = c("union", "intersect"), h5requestFiltering = list(), - stepPlot = FALSE, drawPoints = FALSE, timeSteph5 = "hourly", - mcYearh5 = NULL, tablesh5 = c("areas", "links"), ...) + legendId = sample(1e+09, 1), groupId = legendId, legendItemsPerRow = 5, + width = NULL, height = NULL, xyCompare = c("union", "intersect"), + h5requestFiltering = list(), stepPlot = FALSE, drawPoints = FALSE, + timeSteph5 = "hourly", mcYearh5 = NULL, tablesh5 = c("areas", "links"), + ...) } \arguments{ \item{name}{name of the stack to create or update} diff --git a/tests/testthat/test-graphUtils.R b/tests/testthat/test-graphUtils.R index 03cef82..969b436 100644 --- a/tests/testthat/test-graphUtils.R +++ b/tests/testthat/test-graphUtils.R @@ -8,40 +8,40 @@ describe(".compOpts", { expect_true(.compOpts(list(), NULL)$ncharts == 1) }) - -context(".dateRangeJoin") -describe(".dateRangeJoin", { - dt <- list() - dt$x <- list(list(dateRange = as.Date(c("2010-01-01", "2010-01-10"))), - list(dateRange = as.Date(c("2010-01-02", "2010-01-09")))) - - - - - expect_true(.dateRangeJoin(dt, "union", "min") == as.Date("2010-01-01")) - expect_true(.dateRangeJoin(dt, "union", "max") == as.Date("2010-01-10")) - expect_true(.dateRangeJoin(dt, "intersect", "max") == as.Date("2010-01-09")) - expect_true(.dateRangeJoin(dt, "intersect", "min") == as.Date("2010-01-02")) - - dt2 <- list() - dt2$x <- list(list(ar = list(dateRange = as.Date(c("2010-01-01", "2010-01-10")))), - list(ar = list(dateRange = as.Date(c("2010-01-02", "2010-01-09"))))) - - expect_true(.dateRangeJoin(dt2, "union", "min", "ar") == as.Date("2010-01-01")) - expect_true(.dateRangeJoin(dt2, "union", "max", "ar") == as.Date("2010-01-10")) - expect_true(.dateRangeJoin(dt2, "intersect", "max", "ar") == as.Date("2010-01-09")) - expect_true(.dateRangeJoin(dt2, "intersect", "min", "ar") == as.Date("2010-01-02")) - -}) - -context(".loadH5Data") -describe(".loadH5Data", { - opts <- setSimulationPath(studyPath) - sharerequest <- list() - sharerequest$mcYearh_l <- "all" - sharerequest$tables_l <- c("areas", "links", "clusters", "districts") - sharerequest$timeSteph5_l <- "hourly" - expect_true("antaresDataList" %in% class(.loadH5Data(sharerequest, opts))) - -}) - +if(requireNamespace("rhdf5")){ + context(".dateRangeJoin") + describe(".dateRangeJoin", { + dt <- list() + dt$x <- list(list(dateRange = as.Date(c("2010-01-01", "2010-01-10"))), + list(dateRange = as.Date(c("2010-01-02", "2010-01-09")))) + + + + + expect_true(.dateRangeJoin(dt, "union", "min") == as.Date("2010-01-01")) + expect_true(.dateRangeJoin(dt, "union", "max") == as.Date("2010-01-10")) + expect_true(.dateRangeJoin(dt, "intersect", "max") == as.Date("2010-01-09")) + expect_true(.dateRangeJoin(dt, "intersect", "min") == as.Date("2010-01-02")) + + dt2 <- list() + dt2$x <- list(list(ar = list(dateRange = as.Date(c("2010-01-01", "2010-01-10")))), + list(ar = list(dateRange = as.Date(c("2010-01-02", "2010-01-09"))))) + + expect_true(.dateRangeJoin(dt2, "union", "min", "ar") == as.Date("2010-01-01")) + expect_true(.dateRangeJoin(dt2, "union", "max", "ar") == as.Date("2010-01-10")) + expect_true(.dateRangeJoin(dt2, "intersect", "max", "ar") == as.Date("2010-01-09")) + expect_true(.dateRangeJoin(dt2, "intersect", "min", "ar") == as.Date("2010-01-02")) + + }) + + context(".loadH5Data") + describe(".loadH5Data", { + opts <- setSimulationPath(studyPath) + sharerequest <- list() + sharerequest$mcYearh_l <- "all" + sharerequest$tables_l <- c("areas", "links", "clusters", "districts") + sharerequest$timeSteph5_l <- "hourly" + expect_true("antaresDataList" %in% class(.loadH5Data(sharerequest, opts))) + + }) +} From 4411eacda45f9e43d959c6c1fcd6f32daa8a41c5 Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Thu, 14 Dec 2017 17:07:09 +0100 Subject: [PATCH 29/34] clean --- R/h5_utils_plot.R | 108 ---------------------------------------------- 1 file changed, 108 deletions(-) diff --git a/R/h5_utils_plot.R b/R/h5_utils_plot.R index 4e81aa8..fd2418b 100644 --- a/R/h5_utils_plot.R +++ b/R/h5_utils_plot.R @@ -1,112 +1,4 @@ -.getData <- function(path, table, mcYear, variable, elements, dateRange, timeStep){ - opts <- antaresRead::.getOptionsH5(path) - if(mcYear == "MC-All") - { - mcYear <- NULL - } - areas <- links <- clusters <- districts <- NULL - assign(table, as.character(elements)) - data <- antaresRead::.h5ReadAntares(path = path, - areas = areas, - links = links, - clusters = clusters, - districts = districts, - mcYears = mcYear, - select = variable, - timeStep = timeStep, - perf = FALSE) - if(nrow(data) == 0){return(data)} - - colsId <- antaresRead::getIdCols(data) - - if("cluster" %in% colsId){ - idV <- c("area", "cluster") - } else if ("area"%in%colsId){ - idV <- "area" - } else if ("link"%in%colsId){ - idV <- "link" - } else if ("district"%in%colsId){ - idV <- "district" - } - valueCol <- setdiff(names(data), colsId) - valueCol <- intersect(valueCol, variable) - - data <- data[,.SD, .SDcols = c("timeId", "time", valueCol, idV)] - if(length(idV) > 1){ - data[, "newKey" := paste0(lapply(.SD, as.character), collapse = " < "), .SDcols = idV,by=1:nrow(data)] - data[,c(idV) := NULL] - idV <- "newKey" - }else{ - setnames(data, idV, "newKey") - } - data$newKey <- as.character(data$newKey) - - if(ncol(data) > 4){ - data <- melt(data, c("newKey", "timeId", "time")) - data[, "newKey" := paste0(data$newKey, " - ", as.character(variable)),by=1:nrow(data)] - data[, variable := NULL] - valueCol <- "value" - } - - - odc <- c("timeId", "time", valueCol, "newKey") - setcolorder(data, odc) - setnames(data, names(data), c("timeId", "time", "value", "element")) - - data[,time := .timeIdToDate(timeId, timeStep, opts)] - data[time >= dateRange[1] & time <= dateRange[2]] - -} - -.doPlot <- function(.id, - path, - table, - mcYear, - variable, - elements, - timeStep, - data, - dateRange, - type, - minValue, - maxValue, - colors, - main, - ylab, - legend, - legendItemsPerRow, - width, - height, - opts, - colorScaleOpts, - group){ - - - data <- .getData(ifelse(length(path) == 1 , path , path[.id]), table, mcYear, variable, elements, dateRange, timeStep) - if(nrow(data) == 0){return(NULL)} - f <- .getGraphFunction(type) - - f( - data, - timeStep = timeStep, - variable = variable, - confInt = 0, - minValue = minValue, - maxValue = maxValue, - colors = colors, - main = if(length(main) <= 1) main else main[.id], - ylab = if(length(ylab) <= 1) ylab else ylab[.id], - legend = legend, - legendItemsPerRow = legendItemsPerRow, - width = width, - height = height, - opts = opts, - colorScaleOpts = colorScaleOpts, - group = group - ) - -} .getstructure <- function(fid, strgp){ From e226c45be4aceeb30aafa6fd3074270065fb056b Mon Sep 17 00:00:00 2001 From: TitouanRobert Date: Thu, 14 Dec 2017 17:08:47 +0100 Subject: [PATCH 30/34] develop antaresMap --- .travis.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f471898..b633972 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ r_github_packages: - Bioconductor-mirror/zlibbioc - Bioconductor-mirror/rhdf5 - rte-antares-rpackage/manipulateWidget@develop - - rte-antares-rpackage/antaresMaps + - rte-antares-rpackage/antaresMaps@develop - rte-antares-rpackage/antaresRead@develop - rte-antares-rpackage/antaresProcessing@develop diff --git a/appveyor.yml b/appveyor.yml index d580767..2d794b7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,7 +19,7 @@ build_script: - ./travis-tool.sh install_github rte-antares-rpackage/antaresRead@develop - ./travis-tool.sh install_github rte-antares-rpackage/antaresProcessing@develop - ./travis-tool.sh install_github rte-antares-rpackage/manipulateWidget@develop - - ./travis-tool.sh install_github rte-antares-rpackage/antaresMaps + - ./travis-tool.sh install_github rte-antares-rpackage/antaresMaps@develop test_script: - travis-tool.sh run_tests From e0fb9887891ec796adfda468a1054ccde7fad9d5 Mon Sep 17 00:00:00 2001 From: Benoit Thieurmel Date: Fri, 15 Dec 2017 10:16:11 +0100 Subject: [PATCH 31/34] fix map_layout id using polygons ? --- R/map.R | 214 ++++++++++++++++++++++++------------------------ R/map_helpers.R | 2 - R/map_layout.R | 26 +++--- 3 files changed, 123 insertions(+), 119 deletions(-) diff --git a/R/map.R b/R/map.R index 40c1f46..2344bac 100644 --- a/R/map.R +++ b/R/map.R @@ -178,12 +178,12 @@ plotMap <- function(x, mapLayout, colAreaVar = "none", sizeAreaVars = c(), if(colAreaVar != "none" & colAreaVar%in%colorsVars$Column & runScale) { - raw <- colorsVars[Column == colAreaVar] - options <- plotMapOptions(areaColorScaleOpts = colorScaleOptions( - negCol = "#FFFFFF", - zeroCol = rgb(raw$red, raw$green, raw$blue, maxColorValue = 255), - posCol = rgb(raw$red/2, raw$green/2, raw$blue/2, maxColorValue = 255))) - + raw <- colorsVars[Column == colAreaVar] + options <- plotMapOptions(areaColorScaleOpts = colorScaleOptions( + negCol = "#FFFFFF", + zeroCol = rgb(raw$red, raw$green, raw$blue, maxColorValue = 255), + posCol = rgb(raw$red/2, raw$green/2, raw$blue/2, maxColorValue = 255))) + } if (is.null(mcYear)) mcYear <- "average" @@ -214,7 +214,7 @@ plotMap <- function(x, mapLayout, colAreaVar = "none", sizeAreaVars = c(), # new_env for save and control mapLayout env_plotFun <- new.env() - + processFun <- function(x, mapLayout) { if (!is(x, "antaresData")) { stop("Argument 'x' must be an object of class 'antaresData' created with function 'readAntares'.") @@ -251,6 +251,9 @@ plotMap <- function(x, mapLayout, colAreaVar = "none", sizeAreaVars = c(), if (areas) { areaList <- unique(x$areas$area) mapLayout$coords <- mapLayout$coords[area %in% areaList] + if(!is.null(mapLayout$map)){ + mapLayout$map <- mapLayout$map[match(mapLayout$coords$geoAreaId, mapLayout$map$geoAreaId), ] + } } if (links) { linkList <- unique(x$links$link) @@ -419,7 +422,7 @@ plotMap <- function(x, mapLayout, colAreaVar = "none", sizeAreaVars = c(), if(is.null(tmp_options)){ tmp_options <- plotMapOptions() } - + params$x[[.id]]$plotFun(t = params$x[[.id]]$timeId, colAreaVar = colAreaVar, sizeAreaVars = sizeAreaVars, @@ -484,10 +487,10 @@ plotMap <- function(x, mapLayout, colAreaVar = "none", sizeAreaVars = c(), }, label = "table", multiple = TRUE), mcYearH5 = mwSelect(choices = c(paramsH5[["mcYearS"]]), - value = { - if(.initial){paramsH5[["mcYearS"]][1]}else{NULL} - }, - label = "mcYear", multiple = TRUE), + value = { + if(.initial){paramsH5[["mcYearS"]][1]}else{NULL} + }, + label = "mcYear", multiple = TRUE), .display = {any(unlist(lapply(x_in, .isSimOpts)))} ), sharerequest = mwSharedValue({ @@ -558,106 +561,105 @@ plotMap <- function(x, mapLayout, colAreaVar = "none", sizeAreaVars = c(), if(.initial) areaChartType else NULL }), - sizeMiniPlot = mwCheckbox(FALSE), - .display = length(sizeAreaVars) >= 2), - uniqueScale = mwCheckbox(uniqueScale, label = "Unique scale", - .display = length(sizeAreaVars) >= 2 && areaChartType != "pie"), - showLabels = mwCheckbox(showLabels, label = "Show labels", - .display = length(sizeAreaVars) >= 2), - popupAreaVars = mwSelect( - choices = - { - if (mcYear == "average") { - c("none", - as.character(.compareOperation(lapply(params$x, function(vv){ - unique(vv$areaValColumnsSynt) - }), xyCompare)) - ) - }else{ - c("none", as.character(.compareOperation(lapply(params$x, function(vv){ - unique(vv$areaValColumns) - }), xyCompare))) - } - }, - value = { - if(.initial) popupAreaVars - else NULL - }, - label = "Popup", - multiple = TRUE - ), - labelAreaVar = mwSelect( - choices = { - if (mcYear == "average") { - c("none", - as.character(.compareOperation(lapply(params$x, function(vv){ - unique(vv$areaValColumnsSynt) - }), xyCompare)) - ) - }else{ - c("none", as.character(.compareOperation(lapply(params$x, function(vv){ - unique(vv$areaValColumns) - }), xyCompare))) - } - }, - value = { - if(.initial) labelAreaVar - else NULL - }, label = "Label", - .display = length(sizeAreaVars) < 2 - ), - .display = any(sapply(params$x, function(p) {"areas" %in% names(p$x)})) - ), - - Links = mwGroup( - colLinkVar = mwSelect( - { - c("none", + sizeMiniPlot = mwCheckbox(FALSE), + .display = length(sizeAreaVars) >= 2), + uniqueScale = mwCheckbox(uniqueScale, label = "Unique scale", + .display = length(sizeAreaVars) >= 2 && areaChartType != "pie"), + showLabels = mwCheckbox(showLabels, label = "Show labels", + .display = length(sizeAreaVars) >= 2), + popupAreaVars = mwSelect( + choices = + { + if (mcYear == "average") { + c("none", as.character(.compareOperation(lapply(params$x, function(vv){ - unique(vv$linkValColums) - }), xyCompare))) - }, - value = { - if(.initial) colLinkVar - else NULL - }, label = "Color"), - sizeLinkVar = mwSelect({c("none", - as.character(.compareOperation(lapply(params$x, function(vv){ - unique(vv$linkNumValColumns) - }), xyCompare)) - )}, + unique(vv$areaValColumnsSynt) + }), xyCompare)) + ) + }else{ + c("none", as.character(.compareOperation(lapply(params$x, function(vv){ + unique(vv$areaValColumns) + }), xyCompare))) + } + }, value = { - if(.initial) sizeLinkVar + if(.initial) popupAreaVars else NULL - }, label = "Width"), - popupLinkVars = mwSelect( { c("none", - as.character(.compareOperation(lapply(params$x, function(vv){ - unique(vv$linkValColums) - }), xyCompare))) - }, + }, + label = "Popup", + multiple = TRUE + ), + labelAreaVar = mwSelect( + choices = { + if (mcYear == "average") { + c("none", + as.character(.compareOperation(lapply(params$x, function(vv){ + unique(vv$areaValColumnsSynt) + }), xyCompare)) + ) + }else{ + c("none", as.character(.compareOperation(lapply(params$x, function(vv){ + unique(vv$areaValColumns) + }), xyCompare))) + } + }, value = { - if(.initial) popupLinkVars + if(.initial) labelAreaVar else NULL - }, label = "Popup", multiple = TRUE), - .display = any(sapply(params$x, function(p) {"links" %in% names(p$x)})) + }, label = "Label", + .display = length(sizeAreaVars) < 2 ), - mapLayout = mwSharedValue(mapLayout), - params = mwSharedValue({ - .getDataForComp(x_tranform, NULL, compare, compareOpts, - processFun = processFun, mapLayout = mapLayout) - }), - .width = width, - .height = height, - .compare = { - compare - }, - .compareOpts = { - compareOptions - }, - .return = function(w, e) {combineWidgets(w, title = main, width = width, height = height)}, - ... - ) + .display = any(sapply(params$x, function(p) {"areas" %in% names(p$x)})) + ), + Links = mwGroup( + colLinkVar = mwSelect( + { + c("none", + as.character(.compareOperation(lapply(params$x, function(vv){ + unique(vv$linkValColums) + }), xyCompare))) + }, + value = { + if(.initial) colLinkVar + else NULL + }, label = "Color"), + sizeLinkVar = mwSelect({c("none", + as.character(.compareOperation(lapply(params$x, function(vv){ + unique(vv$linkNumValColumns) + }), xyCompare)) + )}, + value = { + if(.initial) sizeLinkVar + else NULL + }, label = "Width"), + popupLinkVars = mwSelect( { c("none", + as.character(.compareOperation(lapply(params$x, function(vv){ + unique(vv$linkValColums) + }), xyCompare))) + }, + value = { + if(.initial) popupLinkVars + else NULL + }, label = "Popup", multiple = TRUE), + .display = any(sapply(params$x, function(p) {"links" %in% names(p$x)})) + ), + mapLayout = mwSharedValue(mapLayout), + params = mwSharedValue({ + .getDataForComp(x_tranform, NULL, compare, compareOpts, + processFun = processFun, mapLayout = mapLayout) + }), + .width = width, + .height = height, + .compare = { + compare + }, + .compareOpts = { + compareOptions + }, + .return = function(w, e) {combineWidgets(w, title = main, width = width, height = height)}, + ... + ) + } - diff --git a/R/map_helpers.R b/R/map_helpers.R index b4efa6f..b20884d 100644 --- a/R/map_helpers.R +++ b/R/map_helpers.R @@ -165,7 +165,6 @@ if (is.null(x$areas)) return(map) if (nrow(x$areas) == 0) return(map) - timeStep <- attr(x, "timeStep") # Just in case, we do not want to accidentally modify the original map layout. @@ -317,7 +316,6 @@ if (is.null(x$links)) return(map) if (nrow(x$links) == 0) return(map) - timeStep <- attr(x, "timeStep") ml <- copy(mapLayout) diff --git a/R/map_layout.R b/R/map_layout.R index fb00bd1..7d0978a 100644 --- a/R/map_layout.R +++ b/R/map_layout.R @@ -383,31 +383,35 @@ changeCoordsServer <- function(input, output, session, if(all(c("name", "code") %in% names(map))){ keep_code <- unique(map$code[final_coords_map$geoAreaId]) # subset on countries - map <- map[map$code %in% keep_code,] + tmp_map <- map[map$code %in% keep_code,] # set unlink states - map$geoAreaId[!map$geoAreaId %in% final_coords_map$geoAreaId] <- NA + tmp_map$geoAreaId[!tmp_map$geoAreaId %in% final_coords_map$geoAreaId] <- NA - ind_na <- which(is.na(map$geoAreaId)) + ind_na <- which(is.na(tmp_map$geoAreaId)) if(length(ind_na) > 0){ # have to find nearestArea... - treat_cty <- unique(map$code[ind_na]) + treat_cty <- unique(tmp_map$code[ind_na]) for(cty in treat_cty){ - ind_cty <- which(map$code %in% cty) - ind_miss <- which(map$code %in% cty & is.na(map$geoAreaId)) - areas <- coords[coords$geoAreaId %in% map$geoAreaId[ind_cty], ] + ind_cty <- which(tmp_map$code %in% cty) + ind_miss <- which(tmp_map$code %in% cty & is.na(tmp_map$geoAreaId)) + areas <- coords[coords$geoAreaId %in% tmp_map$geoAreaId[ind_cty], ] if(nrow(areas) > 0){ - areas_min <- suppressWarnings(apply(rgeos::gDistance(map[ind_miss, ], areas, byid = TRUE),2, which.min)) - map$geoAreaId[ind_miss] <- areas$geoAreaId[areas_min] + areas_min <- suppressWarnings(apply(rgeos::gDistance(tmp_map),2, which.min)) + tmp_map$geoAreaId[ind_miss] <- areas$geoAreaId[areas_min] } } - map <- raster::aggregate(map, by = c("geoAreaId")) - map <- map[match(final_coords_map$geoAreaId, map$geoAreaId), ] + tmp_map <- raster::aggregate(tmp_map, by = c("geoAreaId")) + map <- tmp_map[match(final_coords_map$geoAreaId, tmp_map$geoAreaId), ] + } else { + map <- map[final_coords_map$geoAreaId,] } } else { map <- map[final_coords_map$geoAreaId,] } + # remove if multiple same polygon. Needed other change... + # map <- map[!duplicated(map$geoAreaId), ] } res <- list(coords = final_coords_map, links = final_links, map = map, all_coords = final_coords) From 9402e46f2eed86c1fc1c8f152b8aae7b79a0afc7 Mon Sep 17 00:00:00 2001 From: Benoit Thieurmel Date: Fri, 15 Dec 2017 10:32:51 +0100 Subject: [PATCH 32/34] fix merge polygons bug + app control --- R/map_layout.R | 8 ++------ inst/application/src/ui/08_ui_map.R | 8 +++++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/R/map_layout.R b/R/map_layout.R index 7d0978a..079e182 100644 --- a/R/map_layout.R +++ b/R/map_layout.R @@ -345,9 +345,7 @@ changeCoordsServer <- function(input, output, session, map <- current_map() - - # info1 <<- list(coords = coords, map = map) - + if (!is.null(map)) { map <- sp::spTransform(map, sp::CRS("+proj=longlat +datum=WGS84")) map$geoAreaId <- 1:length(map) @@ -372,8 +370,6 @@ changeCoordsServer <- function(input, output, session, final_links[final_coords, `:=`(x1 = x, y1 = y),on=c(toDistrict = "district")] } - # info2 <<- list(mapCoords = mapCoords, final_coords = final_coords, final_links = final_links) - if (!is.null(map)) { final_coords$geoAreaId <- mapCoords$geoAreaId final_coords_map <- final_coords[!is.na(final_coords$geoAreaId),] @@ -397,7 +393,7 @@ changeCoordsServer <- function(input, output, session, ind_miss <- which(tmp_map$code %in% cty & is.na(tmp_map$geoAreaId)) areas <- coords[coords$geoAreaId %in% tmp_map$geoAreaId[ind_cty], ] if(nrow(areas) > 0){ - areas_min <- suppressWarnings(apply(rgeos::gDistance(tmp_map),2, which.min)) + areas_min <- suppressWarnings(apply(rgeos::gDistance(tmp_map[ind_miss, ], areas, byid = TRUE),2, which.min)) tmp_map$geoAreaId[ind_miss] <- areas$geoAreaId[areas_min] } } diff --git a/inst/application/src/ui/08_ui_map.R b/inst/application/src/ui/08_ui_map.R index ae5840f..1cfc199 100644 --- a/inst/application/src/ui/08_ui_map.R +++ b/inst/application/src/ui/08_ui_map.R @@ -3,7 +3,13 @@ navbarMenu("plotMap", fluidRow( column(12, conditionalPanel(condition = "output.have_data", - antaresViz:::changeCoordsUI("ml") + conditionalPanel(condition = "output.have_data_links || output.have_data_areas", + antaresViz:::changeCoordsUI("ml") + ), + conditionalPanel(condition = "output.have_data_links === false && output.have_data_areas === false", + h3("No data imported") + ) + ), conditionalPanel(condition = "output.have_data === false", h3("No data imported") From eada640486cf8c79029c0a7609c2ba09409a19eb Mon Sep 17 00:00:00 2001 From: zawam Date: Fri, 15 Dec 2017 10:38:24 +0100 Subject: [PATCH 33/34] we need antaresProcessing 0.13 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index e05c045..f12bccf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,7 +24,7 @@ LazyData: TRUE Encoding: UTF-8 Depends: antaresRead (>= 2.0.0), - antaresProcessing (>= 0.12.0), + antaresProcessing (>= 0.13.0), spMaps (>= 0.2) Imports: dygraphs (>= 1.1.1), From 67873e1ca90c0f0f21a35be7bce448b65b8a76a3 Mon Sep 17 00:00:00 2001 From: zawam Date: Wed, 20 Dec 2017 15:45:26 +0100 Subject: [PATCH 34/34] update date --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index ca2e61d..6cfe08e 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,7 @@ Copyright © 2016 RTE Réseau de transport d’électricité -Changes in version 0.12.0 (2017-14-12) +Changes in version 0.12.0 (2017-12-14) NEW FEATURES: * plot(), prodStack(), exchangesStack(), plotMap() work with studies in h5.