160160# ' @importFrom DelayedArray realize
161161# ' @importFrom spatialdataR data_type
162162.df_i <- \(x , k = NULL , ch = NULL , c = NULL , cl = NULL ) {
163- a <- .get_multiscale_data (x , k )
163+ a <- .get_ms_data (x , k )
164164 # max-projection over z-stacks
165165 d <- length(dim(x ))
166166 if (d == 4 ) a <- apply(a , c(1 , 3 , 4 ), max )
@@ -171,21 +171,6 @@ NULL
171171 a <- .prep_ia(a , c , cl )
172172}
173173
174- # ' @importFrom utils tail
175- .get_wh <- \(x ) {
176- wh <- metadata(x )$ wh
177- if (! is.null(wh )) {
178- df <- data.frame (x = wh [[1 ]], y = wh [[2 ]])
179- } else {
180- ds <- dim(data(x , 1 ))
181- df <- data.frame (
182- x = c(0 , tail(ds , 1 )),
183- y = c(0 , tail(ds , 2 )[1 ]))
184- }
185- wh <- list (w = df $ x , h = df $ y )
186- return (wh )
187- }
188-
189174# ' @importFrom ggplot2 guides geom_point geom_blank annotation_raster
190175# ' @importFrom ggplot2 scale_color_identity scale_x_continuous scale_y_reverse
191176.gg_i <- \(x , w , h , pal = NULL ) {
@@ -219,16 +204,8 @@ setMethod("plotImage", "SpatialData", \(x, i=1, j=1, k=NULL, ch=NULL, c=NULL, cl
219204 nms <- unlist(channels(y ))[idx <- .ch_idx(y , ch )]
220205 pal <- pal [seq_along(idx )]; names(pal ) <- nms
221206 }
222- # multi-scale adjustment
207+ # physical space mapping
223208 wh <- .get_wh(y )
224- if (wh $ w [2 ] == tail(dim(y ), 1 ) ||
225- wh $ h [2 ] == tail(dim(y ), 2 )[1 ]) {
226- ts <- .get_multiscale_scale(y )
227- tx <- tail(ts , 1 )
228- ty <- tail(ts , 2 )[1 ]
229- } else tx <- ty <- 1
230- wh $ w [2 ] <- wh $ w [2 ]* tx
231- wh $ h [2 ] <- wh $ h [2 ]* ty
232209 .gg_i(df , wh $ w , wh $ h , pal )
233210})
234211
@@ -238,5 +215,5 @@ setMethod("plotImage", "SpatialData", \(x, i=1, j=1, k=NULL, ch=NULL, c=NULL, cl
238215plotSpatialData <- \() ggplot() + coord_sf(expand = FALSE , reverse = " y" ) + .theme
239216# `annotation_raster` plots the array the same way it is printed, i.e., with the
240217# row 1 at the top, which means we need to flip the y-axis to have the correct axis labels.
241- # We tried flipping the image itself but it means everything gets out of alignement if
218+ # We tried flipping the image itself but it means everything gets out of alignment if
242219# the user sets `scale_y_reverse()` themselves.
0 commit comments