@@ -492,10 +492,10 @@ gg2list <- function(p, width = NULL, height = NULL,
492492 layout $ layout $ xanchor <- paste0(" y" , sub(" ^1$" , " " , layout $ layout $ xanchor ))
493493 layout $ layout $ yanchor <- paste0(" x" , sub(" ^1$" , " " , layout $ layout $ yanchor ))
494494 # for some layers2traces computations, we need the range of each panel
495- layout $ layout $ x_min <- sapply(layout $ panel_params , function (z ) min(z $ x.range %|| % z $ x_range ))
496- layout $ layout $ x_max <- sapply(layout $ panel_params , function (z ) max(z $ x.range %|| % z $ x_range ))
497- layout $ layout $ y_min <- sapply(layout $ panel_params , function (z ) min(z $ y.range %|| % z $ y_range ))
498- layout $ layout $ y_max <- sapply(layout $ panel_params , function (z ) max(z $ y.range %|| % z $ y_range ))
495+ layout $ layout $ x_min <- sapply(layout $ panel_params , function (z ) min(z [[ " x " ]] $ dimension %()% z $ x.range %|| % z $ x_range ))
496+ layout $ layout $ x_max <- sapply(layout $ panel_params , function (z ) max(z [[ " x " ]] $ dimension %()% z $ x.range %|| % z $ x_range ))
497+ layout $ layout $ y_min <- sapply(layout $ panel_params , function (z ) min(z [[ " y " ]] $ dimension %()% z $ y.range %|| % z $ y_range ))
498+ layout $ layout $ y_max <- sapply(layout $ panel_params , function (z ) max(z [[ " y " ]] $ dimension %()% z $ y.range %|| % z $ y_range ))
499499
500500 # layers -> plotly.js traces
501501 plot $ tooltip <- tooltip
@@ -552,7 +552,7 @@ gg2list <- function(p, width = NULL, height = NULL,
552552 )
553553 # allocate enough space for the _longest_ text label
554554 axisTextX <- theme [[" axis.text.x" ]] %|| % theme [[" axis.text" ]]
555- labz <- unlist(lapply(layout $ panel_params , " [[" , " x.labels" ))
555+ labz <- unlist(lapply(layout $ panel_params , function ( pp ) pp [[" x " ]] $ get_labels %()% pp $ x.labels ))
556556 lab <- labz [which.max(nchar(labz ))]
557557 panelMarginY <- panelMarginY + axisTicksX +
558558 bbox(lab , axisTextX $ angle , unitConvert(axisTextX , " npc" , " height" ))[[" height" ]]
@@ -564,7 +564,7 @@ gg2list <- function(p, width = NULL, height = NULL,
564564 )
565565 # allocate enough space for the _longest_ text label
566566 axisTextY <- theme [[" axis.text.y" ]] %|| % theme [[" axis.text" ]]
567- labz <- unlist(lapply(layout $ panel_params , " [[" , " y.labels" ))
567+ labz <- unlist(lapply(layout $ panel_params , function ( pp ) pp [[" y " ]] $ get_labels %()% pp $ y.labels ))
568568 lab <- labz [which.max(nchar(labz ))]
569569 panelMarginX <- panelMarginX + axisTicksY +
570570 bbox(lab , axisTextY $ angle , unitConvert(axisTextY , " npc" , " width" ))[[" width" ]]
@@ -601,7 +601,10 @@ gg2list <- function(p, width = NULL, height = NULL,
601601 idx <- rng $ graticule $ type == direction & ! is.na(rng $ graticule $ degree_label )
602602 tickData <- rng $ graticule [idx , ]
603603 # TODO: how to convert a language object to unicode character string?
604- rng [[paste0(xy , " .labels" )]] <- as.character(tickData [[" degree_label" ]])
604+ rng [[paste0(xy , " .labels" )]] <- sub(
605+ " \\ *\\ s+degree[ ]?[\\ *]?" , " °" ,
606+ sub(" \" " , " " , tickData [[" degree_label" ]])
607+ )
605608 rng [[paste0(xy , " .major" )]] <- tickData [[paste0(xy , " _start" )]]
606609
607610 # If it doesn't already exist (for this panel),
@@ -636,14 +639,7 @@ gg2list <- function(p, width = NULL, height = NULL,
636639 tickExists <- with(rng $ graticule , sapply(degree_label , is.language ))
637640 if (sum(tickExists ) == 0 ) {
638641 theme $ axis.ticks.length <- 0
639- } else {
640- # convert the special *degree expression in plotmath to HTML entity
641- # TODO: can this be done more generally for all ?
642- rng [[paste0(xy , " .labels" )]] <- sub(
643- " \\ *\\ s+degree[ ]?[\\ *]?" , " °" , rng [[paste0(xy , " .labels" )]]
644- )
645642 }
646-
647643 }
648644
649645 # stuff like layout$panel_params is already flipped, but scales aren't
@@ -673,16 +669,19 @@ gg2list <- function(p, width = NULL, height = NULL,
673669 isDiscrete <- identical(sc $ scale_name , " position_d" )
674670 isDiscreteType <- isDynamic && isDiscrete
675671
672+ ticktext <- rng [[xy ]]$ get_labels %()% rng [[paste0(xy , " .labels" )]]
673+ tickvals <- rng [[xy ]]$ break_positions %()% rng [[paste0(xy , " .major" )]]
674+
676675 axisObj <- list (
677676 # TODO: log type?
678677 type = if (isDateType ) " date" else if (isDiscreteType ) " category" else " linear" ,
679678 autorange = isDynamic ,
680679 range = rng [[paste0(xy , " .range" )]] %|| % rng [[paste0(xy , " _range" )]],
681680 tickmode = if (isDynamic ) " auto" else " array" ,
682- ticktext = rng [[paste0( xy , " .labels " )]] ,
683- tickvals = rng [[paste0( xy , " .major " )]] ,
681+ ticktext = ticktext ,
682+ tickvals = tickvals ,
684683 categoryorder = " array" ,
685- categoryarray = rng [[paste0( xy , " .labels " )]] ,
684+ categoryarray = ticktext ,
686685 nticks = nrow(rng ),
687686 ticks = if (is_blank(axisTicks )) " " else " outside" ,
688687 tickcolor = toRGB(axisTicks $ colour ),
0 commit comments