@@ -492,10 +492,10 @@ gg2list <- function(p, width = NULL, height = NULL,
492
492
layout $ layout $ xanchor <- paste0(" y" , sub(" ^1$" , " " , layout $ layout $ xanchor ))
493
493
layout $ layout $ yanchor <- paste0(" x" , sub(" ^1$" , " " , layout $ layout $ yanchor ))
494
494
# 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 ))
499
499
500
500
# layers -> plotly.js traces
501
501
plot $ tooltip <- tooltip
@@ -552,7 +552,7 @@ gg2list <- function(p, width = NULL, height = NULL,
552
552
)
553
553
# allocate enough space for the _longest_ text label
554
554
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 ))
556
556
lab <- labz [which.max(nchar(labz ))]
557
557
panelMarginY <- panelMarginY + axisTicksX +
558
558
bbox(lab , axisTextX $ angle , unitConvert(axisTextX , " npc" , " height" ))[[" height" ]]
@@ -564,7 +564,7 @@ gg2list <- function(p, width = NULL, height = NULL,
564
564
)
565
565
# allocate enough space for the _longest_ text label
566
566
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 ))
568
568
lab <- labz [which.max(nchar(labz ))]
569
569
panelMarginX <- panelMarginX + axisTicksY +
570
570
bbox(lab , axisTextY $ angle , unitConvert(axisTextY , " npc" , " width" ))[[" width" ]]
@@ -601,7 +601,10 @@ gg2list <- function(p, width = NULL, height = NULL,
601
601
idx <- rng $ graticule $ type == direction & ! is.na(rng $ graticule $ degree_label )
602
602
tickData <- rng $ graticule [idx , ]
603
603
# 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
+ )
605
608
rng [[paste0(xy , " .major" )]] <- tickData [[paste0(xy , " _start" )]]
606
609
607
610
# If it doesn't already exist (for this panel),
@@ -636,14 +639,7 @@ gg2list <- function(p, width = NULL, height = NULL,
636
639
tickExists <- with(rng $ graticule , sapply(degree_label , is.language ))
637
640
if (sum(tickExists ) == 0 ) {
638
641
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
- )
645
642
}
646
-
647
643
}
648
644
649
645
# stuff like layout$panel_params is already flipped, but scales aren't
@@ -673,16 +669,19 @@ gg2list <- function(p, width = NULL, height = NULL,
673
669
isDiscrete <- identical(sc $ scale_name , " position_d" )
674
670
isDiscreteType <- isDynamic && isDiscrete
675
671
672
+ ticktext <- rng [[xy ]]$ get_labels %()% rng [[paste0(xy , " .labels" )]]
673
+ tickvals <- rng [[xy ]]$ break_positions %()% rng [[paste0(xy , " .major" )]]
674
+
676
675
axisObj <- list (
677
676
# TODO: log type?
678
677
type = if (isDateType ) " date" else if (isDiscreteType ) " category" else " linear" ,
679
678
autorange = isDynamic ,
680
679
range = rng [[paste0(xy , " .range" )]] %|| % rng [[paste0(xy , " _range" )]],
681
680
tickmode = if (isDynamic ) " auto" else " array" ,
682
- ticktext = rng [[paste0( xy , " .labels " )]] ,
683
- tickvals = rng [[paste0( xy , " .major " )]] ,
681
+ ticktext = ticktext ,
682
+ tickvals = tickvals ,
684
683
categoryorder = " array" ,
685
- categoryarray = rng [[paste0( xy , " .labels " )]] ,
684
+ categoryarray = ticktext ,
686
685
nticks = nrow(rng ),
687
686
ticks = if (is_blank(axisTicks )) " " else " outside" ,
688
687
tickcolor = toRGB(axisTicks $ colour ),
0 commit comments