View | Details | Raw Unified | Return to bug 16761 | Differences between
and this patch

Collapse All | Expand All

(-)prettyDate.R (-28 / +14 lines)
Lines 111-145 Link Here
111
        startTime <- trunc_POSIXt(lim[1], units = s$start) ## FIXME: should be trunc() eventually
111
        startTime <- trunc_POSIXt(lim[1], units = s$start) ## FIXME: should be trunc() eventually
112
        at <- seqDtime(startTime, end = lim[2], by = s$spec)
112
        at <- seqDtime(startTime, end = lim[2], by = s$spec)
113
113
114
	i <- which(lim[1] <= at & at <= lim[2])
114
	r1 <- sum(at <= lim[1])
115
	if(!length(i)) # at[] is fully outside (to the *left*: rarely)
115
	r2 <- length(at) + 1 - sum(at >= lim[2])
116
	    return(at[FALSE])
116
        if(r2 == length(at) + 1) { # not covering at right
117
	r <- range(i)
117
            { # add point at right
118
        while(lim[1] < at[r[1]]) { # not covering at left
119
            if(r[1] > 1) ## take one more point at left
120
                i <- c(r[1] <- r[1] - 1L, i)
121
            else { # add point at left
122
                nat <- seqDtime(at[1], by=paste("-1",s$spec), length = 2)[2]
123
                if(is.na(nat) || !(nat < at[1])) # failed
124
                    break
125
                at <- c(nat, at)
126
                i <- i + 1L
127
                if(lim[1] <= at[1]) r <- range(i <- c(1L, i))
128
            }
129
        }
130
        while(lim[2] > at[r[2]]) { # not covering at right
131
            if(r[2] < length(at)) ## take one more point at right
132
                i <- c(i, r[2] <- r[2] + 1L)
133
            else { # add point at right
134
                nat <- seqDtime(at[length(at)], by = s$spec, length=2)[2]
118
                nat <- seqDtime(at[length(at)], by = s$spec, length=2)[2]
135
                if(is.na(nat) || !(nat > at[length(at)])) # failed
119
                if(is.na(nat) || !(nat > at[length(at)])) # failed
136
                    break
120
                    r2 <- length(at)
137
                at <- c(at, nat)
121
                else
138
                if(lim[2] >= nat) r <- range(i <- c(i, length(at)))
122
                    at[r2] <- nat
139
            }
123
            }
140
        }
124
        }
141
        ## Now we could see if we are *smaller* than 'n+1' and add even more at[] on both sides
125
        ## Now we could see if we are *smaller* than 'n+1' and add even more at[] on both sides
142
        at[i]
126
        at[r1:r2]
143
    }
127
    }
144
    init.at <- calcSteps(st.i <- steps[[init.i]])
128
    init.at <- calcSteps(st.i <- steps[[init.i]])
145
    ## bump it up if below acceptable threshold
129
    ## bump it up if below acceptable threshold
Lines 152-163 Link Here
152
                nat <- seqDtime(init.at[length(init.at)], by = st.i$spec, length=2)[2]
136
                nat <- seqDtime(init.at[length(init.at)], by = st.i$spec, length=2)[2]
153
                R.fail <- is.na(nat) || !(nat > init.at[length(init.at)])
137
                R.fail <- is.na(nat) || !(nat > init.at[length(init.at)])
154
                if(!R.fail)
138
                if(!R.fail)
155
                    init.at <- c(init.at, nat)
139
                    init.at[length(init.at) + 1] <- nat
156
            } else { # left
140
            } else { # left
157
                nat <- seqDtime(init.at[1], by = paste("-1",st.i$spec), length=2)[2]
141
                nat <- seqDtime(init.at[1], by = paste0("-",st.i$spec), length=2)[2]
158
                L.fail <- is.na(nat) || !(nat < init.at[1])
142
                L.fail <- is.na(nat) || !(nat < init.at[1])
159
                if(!L.fail)
143
                if(!L.fail) {
160
                    init.at <- c(nat, init.at)
144
                    init.at[seq_along(init.at) + 1] <- init.at
145
                    init.at[1] <- nat
146
                }
161
            }
147
            }
162
            if(R.fail && L.fail)
148
            if(R.fail && L.fail)
163
                stop("failed to add more ticks; 'min.n' too large?")
149
                stop("failed to add more ticks; 'min.n' too large?")

Return to bug 16761