@@ -506,10 +506,10 @@ gg2list <- function(p, width = NULL, height = NULL,
506506 layout $ layout $ xanchor <- paste0(" y" , sub(" ^1$" , " " , layout $ layout $ xanchor ))
507507 layout $ layout $ yanchor <- paste0(" x" , sub(" ^1$" , " " , layout $ layout $ yanchor ))
508508 # for some layers2traces computations, we need the range of each panel
509- layout $ layout $ x_min <- sapply(layout $ panel_params , function (z ) min(z $ x.range %|| % z $ x_range ))
510- layout $ layout $ x_max <- sapply(layout $ panel_params , function (z ) max(z $ x.range %|| % z $ x_range ))
511- layout $ layout $ y_min <- sapply(layout $ panel_params , function (z ) min(z $ y.range %|| % z $ y_range ))
512- layout $ layout $ y_max <- sapply(layout $ panel_params , function (z ) max(z $ y.range %|| % z $ y_range ))
509+ layout $ layout $ x_min <- sapply(layout $ panel_params , function (z ) { min(z [[ " x " ]] $ dimension %()% z $ x.range %|| % z $ x_range ) } )
510+ layout $ layout $ x_max <- sapply(layout $ panel_params , function (z ) { max(z [[ " x " ]] $ dimension %()% z $ x.range %|| % z $ x_range ) } )
511+ layout $ layout $ y_min <- sapply(layout $ panel_params , function (z ) { min(z [[ " y " ]] $ dimension %()% z $ y.range %|| % z $ y_range ) } )
512+ layout $ layout $ y_max <- sapply(layout $ panel_params , function (z ) { max(z [[ " y " ]] $ dimension %()% z $ y.range %|| % z $ y_range ) } )
513513
514514 # layers -> plotly.js traces
515515 plot $ tooltip <- tooltip
@@ -566,7 +566,7 @@ gg2list <- function(p, width = NULL, height = NULL,
566566 )
567567 # allocate enough space for the _longest_ text label
568568 axisTextX <- theme [[" axis.text.x" ]] %|| % theme [[" axis.text" ]]
569- labz <- unlist(lapply(layout $ panel_params , " [[" , " x.labels" ))
569+ labz <- unlist(lapply(layout $ panel_params , function ( pp ) { pp [[" x " ]] $ get_labels %()% pp $ x.labels } ))
570570 lab <- labz [which.max(nchar(labz ))]
571571 panelMarginY <- panelMarginY + axisTicksX +
572572 bbox(lab , axisTextX $ angle , unitConvert(axisTextX , " npc" , " height" ))[[" height" ]]
@@ -578,7 +578,7 @@ gg2list <- function(p, width = NULL, height = NULL,
578578 )
579579 # allocate enough space for the _longest_ text label
580580 axisTextY <- theme [[" axis.text.y" ]] %|| % theme [[" axis.text" ]]
581- labz <- unlist(lapply(layout $ panel_params , " [[" , " y.labels" ))
581+ labz <- unlist(lapply(layout $ panel_params , function ( pp ) { pp [[" y " ]] $ get_labels %()% pp $ y.labels } ))
582582 lab <- labz [which.max(nchar(labz ))]
583583 panelMarginX <- panelMarginX + axisTicksY +
584584 bbox(lab , axisTextY $ angle , unitConvert(axisTextY , " npc" , " width" ))[[" width" ]]
@@ -615,7 +615,10 @@ gg2list <- function(p, width = NULL, height = NULL,
615615 idx <- rng $ graticule $ type == direction & ! is.na(rng $ graticule $ degree_label )
616616 tickData <- rng $ graticule [idx , ]
617617 # TODO: how to convert a language object to unicode character string?
618- rng [[paste0(xy , " .labels" )]] <- as.character(tickData [[" degree_label" ]])
618+ rng [[paste0(xy , " .labels" )]] <- sub(
619+ " \\ *\\ s+degree[ ]?[\\ *]?" , " °" ,
620+ gsub(" \" " , " " , tickData [[" degree_label" ]])
621+ )
619622 rng [[paste0(xy , " .major" )]] <- tickData [[paste0(xy , " _start" )]]
620623
621624 # If it doesn't already exist (for this panel),
@@ -650,14 +653,7 @@ gg2list <- function(p, width = NULL, height = NULL,
650653 tickExists <- with(rng $ graticule , sapply(degree_label , is.language ))
651654 if (sum(tickExists ) == 0 ) {
652655 theme $ axis.ticks.length <- 0
653- } else {
654- # convert the special *degree expression in plotmath to HTML entity
655- # TODO: can this be done more generally for all ?
656- rng [[paste0(xy , " .labels" )]] <- sub(
657- " \\ *\\ s+degree[ ]?[\\ *]?" , " °" , rng [[paste0(xy , " .labels" )]]
658- )
659656 }
660-
661657 }
662658
663659 # stuff like layout$panel_params is already flipped, but scales aren't
@@ -687,16 +683,19 @@ gg2list <- function(p, width = NULL, height = NULL,
687683 isDiscrete <- identical(sc $ scale_name , " position_d" )
688684 isDiscreteType <- isDynamic && isDiscrete
689685
686+ ticktext <- rng [[xy ]]$ get_labels %()% rng [[paste0(xy , " .labels" )]]
687+ tickvals <- rng [[xy ]]$ break_positions %()% rng [[paste0(xy , " .major" )]]
688+
690689 axisObj <- list (
691690 # TODO: log type?
692691 type = if (isDateType ) " date" else if (isDiscreteType ) " category" else " linear" ,
693692 autorange = isDynamic ,
694693 range = rng [[paste0(xy , " .range" )]] %|| % rng [[paste0(xy , " _range" )]],
695694 tickmode = if (isDynamic ) " auto" else " array" ,
696- ticktext = rng [[paste0( xy , " .labels " )]] ,
697- tickvals = rng [[paste0( xy , " .major " )]] ,
695+ ticktext = ticktext ,
696+ tickvals = tickvals ,
698697 categoryorder = " array" ,
699- categoryarray = rng [[paste0( xy , " .labels " )]] ,
698+ categoryarray = ticktext ,
700699 nticks = nrow(rng ),
701700 ticks = if (is_blank(axisTicks )) " " else " outside" ,
702701 tickcolor = toRGB(axisTicks $ colour ),
0 commit comments