Skip to content

Commit 106c955

Browse files
authored
Merge pull request #17 from gowachin/issue_fix
Fix plot missing time info #16
2 parents 443eb8e + c7273d6 commit 106c955

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: DiveR
22
Type: Package
33
Title: Simulation Tool for Scuba Diving and Gas Desaturation
4-
Version: 0.4.0
4+
Version: 0.4.1
55
Author: Maxime Jaunatre
66
Maintainer: Maxime Jaunatre <[email protected]>
77
Description: Package for scubadiving planification.

R/graphic.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ plot.dive <- function(x,
6464
if (!add) {x$dtcurve$times <- x$dtcurve$times + x$hour[1]}
6565

6666
dtcurve <- x$dtcurve
67+
desat <- x$desat$desat_stop
6768
# set global plot ----
6869
delta_x <- diff(x$hour) * 0.1
6970
delta_y <- (depth(x) - min(dtcurve$depths)) * 0.2
@@ -178,11 +179,15 @@ plot.dive <- function(x,
178179
if(time_print){
179180
time_i <- times_inf(x, col = call_par$col)
180181
do.call(text, time_i)
181-
} else if(deco_print){
182-
for (i in x$desat$depth[x$desat$time > 0]) {
182+
}
183+
if(deco_print){
184+
for (i in desat$depth[desat$time > 0]) {
183185
text(
184-
x = mean(dtcurve$time[dtcurve$depths == i]), y = -i,
185-
paste(x$desat$time[x$desat$depth == i], "'", sep = ""), pos = 3,
186+
x = mean(c(desat$hour[desat$depth == i],
187+
desat$hour[desat$depth == i] + desat$time[desat$depth == i])) +
188+
x$hour[1],
189+
y = -i,
190+
labels = paste(desat$time[desat$depth == i], "'", sep = ""), pos = 3,
186191
col = call_par$col
187192
)
188193
}
@@ -391,6 +396,7 @@ plot.ndive <- function(x,
391396
def_cols = def_cols, cut_inter = cut_inter, legend = legend,
392397
add = add)
393398

399+
394400
# SOLO plot only call plot.dive
395401
if (x$type == 'solo'){
396402
solo_par <- call_par
@@ -417,7 +423,7 @@ plot.ndive <- function(x,
417423
min(x$dive1$dtcurve$depths, x$dive2$dtcurve$depths) - delta_y)
418424

419425
# TODO : why a duplicate here from line 457 ?
420-
call_par <- list(...)
426+
# call_par <- list(...)
421427

422428
names_defaut_par <- names(default_par)
423429
for (i in seq_along(default_par)) {

R/graphic_utils.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,7 @@ times_inf <- function(x, col = "black"){
6666

6767
desat <- x$desat$desat_stop
6868

69-
times <- c(times, (desat$time + 2 *desat$hour ) /2 )
70-
depths <- c(depths, desat$depth)
71-
dtimes <- c(dtimes, desat$time)
72-
73-
times <- times[!duplicated(dtimes)] + x$hour[1]
74-
depths <- depths[!duplicated(dtimes)]
75-
dtimes <- dtimes[!duplicated(dtimes)]
69+
times <- times + x$hour[1]
7670

7771
pos <- rep(3,length(dtimes))
7872

R/methods_dive.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,10 @@ rm_secu <- function(dive){
304304
dtcurve$times <- replace(
305305
dtcurve$times, length(dtcurve$times),
306306
tail(dtcurve$times, 1) - 0.5 + 3/params["ascent_speed"])
307+
307308
desat$desat_stop[3,3] <- NA
308-
desat$desat_stop <- type.convert(desat$desat_stop) # cause only NA
309+
desat$desat_stop <- type.convert(desat$desat_stop, as.is = NA)
310+
# cause only logical NA
309311
params["dtr"] <- params["dtr"] - 0.5 + 3/params["ascent_speed"]
310312
hour[2] <- hour[2] - 0.5 + 3/params["ascent_speed"]
311313
rownames(dtcurve) <- 1:nrow(dtcurve)

tests/testthat/test-graphic_utils.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ test_that("depth_inf_output", {
4343
test_that("time_inf_output", {
4444
d <- dive(depth = c(0, 20, 19, 10, 7),
4545
time = c(0, 2, 15, 20, 40))
46-
exp <- data.frame(x = c(8.5, 17.5, 30.0, 41.9, NA),
47-
y = c(-19.5, -14.5, -8.5, -3.0, -9.0),
48-
labels = c("13'", "5'", "20'", "3'", "0'"),
49-
pos = rep(3, 5), col = rep("black", 5),
46+
exp <- data.frame(x = c(8.5, 17.5, 30.0, 41.9),
47+
y = c(-19.5, -14.5, -8.5, -3.0),
48+
labels = c("13'", "5'", "20'", "3'"),
49+
pos = rep(3, 4), col = rep("black", 4),
5050
stringsAsFactors = FALSE)
5151
expect_equal(times_inf(d), exp)
5252
})

0 commit comments

Comments
 (0)