@@ -219,9 +219,8 @@ gg2list <- function(p, width = NULL, height = NULL,
219
219
220
220
# Initialise panels, add extra data for margins & missing facetting
221
221
# variables, and add on a PANEL variable to data
222
- layout <- ggfun(" create_layout" )(plot $ facet )
223
- data <- layout $ setup(layer_data , plot $ data , plot $ plot_env , plot $ coordinates )
224
- data <- layout $ map(data )
222
+ layout <- ggfun(" create_layout" )(plot $ facet , plot $ coordinates )
223
+ data <- layout $ setup(layer_data , plot $ data , plot $ plot_env )
225
224
226
225
# save the domain of the group for display in tooltips
227
226
groupDomains <- Map(function (x , y ) {
@@ -344,6 +343,7 @@ gg2list <- function(p, width = NULL, height = NULL,
344
343
# displayed, or does it include the range of underlying data
345
344
layout $ reset_scales()
346
345
layout $ train_position(data , scale_x(), scale_y())
346
+ layout $ setup_panel_params()
347
347
data <- layout $ map_position(data )
348
348
349
349
# Train and map non-position scales
@@ -364,9 +364,6 @@ gg2list <- function(p, width = NULL, height = NULL,
364
364
data <- lapply(data , ggfun(" scales_map_df" ), scales = npscales )
365
365
}
366
366
367
- # Train coordinate system
368
- layout $ train_ranges(plot $ coordinates )
369
-
370
367
# Fill in defaults etc.
371
368
data <- by_layer(function (l , d ) l $ compute_geom_2(d ))
372
369
@@ -410,51 +407,51 @@ gg2list <- function(p, width = NULL, height = NULL,
410
407
# https://github.com/plotly/plotly.js/blob/dd1547/src/components/modebar/index.js#L171
411
408
gglayout $ margin $ t <- gglayout $ margin $ t + 16
412
409
413
- # important stuff like layout$panel_ranges is already flipped, but
410
+ # important stuff like layout$panel_params is already flipped, but
414
411
# plot$scales/plot$labels/data aren't. We flip x/y trace data at the very end
415
412
# and scales in the axis loop below.
416
413
if (inherits(plot $ coordinates , " CoordFlip" )) {
417
414
plot $ labels [c(" x" , " y" )] <- plot $ labels [c(" y" , " x" )]
418
415
}
419
416
420
417
# important panel summary stats
421
- nPanels <- nrow(layout $ panel_layout )
422
- nRows <- max(layout $ panel_layout $ ROW )
423
- nCols <- max(layout $ panel_layout $ COL )
418
+ nPanels <- nrow(layout $ layout )
419
+ nRows <- max(layout $ layout $ ROW )
420
+ nCols <- max(layout $ layout $ COL )
424
421
425
422
# panel -> plotly.js axis/anchor info
426
423
# (assume a grid layout by default)
427
- layout $ panel_layout $ xaxis <- layout $ panel_layout $ COL
428
- layout $ panel_layout $ yaxis <- layout $ panel_layout $ ROW
429
- layout $ panel_layout $ xanchor <- nRows
430
- layout $ panel_layout $ yanchor <- 1
424
+ layout $ layout $ xaxis <- layout $ layout $ COL
425
+ layout $ layout $ yaxis <- layout $ layout $ ROW
426
+ layout $ layout $ xanchor <- nRows
427
+ layout $ layout $ yanchor <- 1
431
428
if (inherits(plot $ facet , " FacetWrap" )) {
432
429
if (plot $ facet $ params $ free $ x ) {
433
- layout $ panel_layout $ xaxis <- layout $ panel_layout $ PANEL
434
- layout $ panel_layout $ xanchor <- layout $ panel_layout $ ROW
430
+ layout $ layout $ xaxis <- layout $ layout $ PANEL
431
+ layout $ layout $ xanchor <- layout $ layout $ ROW
435
432
}
436
433
if (plot $ facet $ params $ free $ y ) {
437
- layout $ panel_layout $ yaxis <- layout $ panel_layout $ PANEL
438
- layout $ panel_layout $ yanchor <- layout $ panel_layout $ COL
439
- layout $ panel_layout $ xanchor <- nPanels
434
+ layout $ layout $ yaxis <- layout $ layout $ PANEL
435
+ layout $ layout $ yanchor <- layout $ layout $ COL
436
+ layout $ layout $ xanchor <- nPanels
440
437
}
441
438
if (plot $ facet $ params $ free $ x && plot $ facet $ params $ free $ y ) {
442
- layout $ panel_layout $ xaxis <- layout $ panel_layout $ PANEL
443
- layout $ panel_layout $ yaxis <- layout $ panel_layout $ PANEL
444
- layout $ panel_layout $ xanchor <- layout $ panel_layout $ PANEL
445
- layout $ panel_layout $ yanchor <- layout $ panel_layout $ PANEL
439
+ layout $ layout $ xaxis <- layout $ layout $ PANEL
440
+ layout $ layout $ yaxis <- layout $ layout $ PANEL
441
+ layout $ layout $ xanchor <- layout $ layout $ PANEL
442
+ layout $ layout $ yanchor <- layout $ layout $ PANEL
446
443
}
447
444
}
448
445
# format the axis/anchor to a format plotly.js respects
449
- layout $ panel_layout $ xaxis <- paste0(" xaxis" , sub(" ^1$" , " " , layout $ panel_layout $ xaxis ))
450
- layout $ panel_layout $ yaxis <- paste0(" yaxis" , sub(" ^1$" , " " , layout $ panel_layout $ yaxis ))
451
- layout $ panel_layout $ xanchor <- paste0(" y" , sub(" ^1$" , " " , layout $ panel_layout $ xanchor ))
452
- layout $ panel_layout $ yanchor <- paste0(" x" , sub(" ^1$" , " " , layout $ panel_layout $ yanchor ))
446
+ layout $ layout $ xaxis <- paste0(" xaxis" , sub(" ^1$" , " " , layout $ layout $ xaxis ))
447
+ layout $ layout $ yaxis <- paste0(" yaxis" , sub(" ^1$" , " " , layout $ layout $ yaxis ))
448
+ layout $ layout $ xanchor <- paste0(" y" , sub(" ^1$" , " " , layout $ layout $ xanchor ))
449
+ layout $ layout $ yanchor <- paste0(" x" , sub(" ^1$" , " " , layout $ layout $ yanchor ))
453
450
# for some layers2traces computations, we need the range of each panel
454
- layout $ panel_layout $ x_min <- sapply(layout $ panel_ranges , function (z ) min(z $ x.range ))
455
- layout $ panel_layout $ x_max <- sapply(layout $ panel_ranges , function (z ) max(z $ x.range ))
456
- layout $ panel_layout $ y_min <- sapply(layout $ panel_ranges , function (z ) min(z $ y.range ))
457
- layout $ panel_layout $ y_max <- sapply(layout $ panel_ranges , function (z ) max(z $ y.range ))
451
+ layout $ layout $ x_min <- sapply(layout $ panel_params , function (z ) min(z $ x.range ))
452
+ layout $ layout $ x_max <- sapply(layout $ panel_params , function (z ) max(z $ x.range ))
453
+ layout $ layout $ y_min <- sapply(layout $ panel_params , function (z ) min(z $ y.range ))
454
+ layout $ layout $ y_max <- sapply(layout $ panel_params , function (z ) max(z $ y.range ))
458
455
459
456
# layers -> plotly.js traces
460
457
plot $ tooltip <- tooltip
@@ -464,7 +461,7 @@ gg2list <- function(p, width = NULL, height = NULL,
464
461
465
462
# reattach crosstalk key-set attribute
466
463
data <- Map(function (x , y ) structure(x , set = y ), data , sets )
467
- traces <- layers2traces(data , prestats_data , layout $ panel_layout , plot )
464
+ traces <- layers2traces(data , prestats_data , layout $ layout , plot )
468
465
469
466
# default to just the text in hover info, mainly because of this
470
467
# https://github.com/plotly/plotly.js/issues/320
@@ -509,7 +506,7 @@ gg2list <- function(p, width = NULL, height = NULL,
509
506
)
510
507
# allocate enough space for the _longest_ text label
511
508
axisTextX <- theme [[" axis.text.x" ]] %|| % theme [[" axis.text" ]]
512
- labz <- unlist(lapply(layout $ panel_ranges , " [[" , " x.labels" ))
509
+ labz <- unlist(lapply(layout $ panel_params , " [[" , " x.labels" ))
513
510
lab <- labz [which.max(nchar(labz ))]
514
511
panelMarginY <- panelMarginY + axisTicksX +
515
512
bbox(lab , axisTextX $ angle , unitConvert(axisTextX , " npc" , " height" ))[[" height" ]]
@@ -521,7 +518,7 @@ gg2list <- function(p, width = NULL, height = NULL,
521
518
)
522
519
# allocate enough space for the _longest_ text label
523
520
axisTextY <- theme [[" axis.text.y" ]] %|| % theme [[" axis.text" ]]
524
- labz <- unlist(lapply(layout $ panel_ranges , " [[" , " y.labels" ))
521
+ labz <- unlist(lapply(layout $ panel_params , " [[" , " y.labels" ))
525
522
lab <- labz [which.max(nchar(labz ))]
526
523
panelMarginX <- panelMarginX + axisTicksY +
527
524
bbox(lab , axisTextY $ angle , unitConvert(axisTextY , " npc" , " width" ))[[" width" ]]
@@ -534,7 +531,7 @@ gg2list <- function(p, width = NULL, height = NULL,
534
531
doms <- get_domains(nPanels , nRows , margins )
535
532
536
533
for (i in seq_len(nPanels )) {
537
- lay <- layout $ panel_layout [i , ]
534
+ lay <- layout $ layout [i , ]
538
535
for (xy in c(" x" , " y" )) {
539
536
# find axis specific theme elements that inherit from their parent
540
537
theme_el <- function (el ) {
@@ -549,8 +546,8 @@ gg2list <- function(p, width = NULL, height = NULL,
549
546
550
547
axisName <- lay [, paste0(xy , " axis" )]
551
548
anchor <- lay [, paste0(xy , " anchor" )]
552
- rng <- layout $ panel_ranges [[i ]]
553
- # stuff like layout$panel_ranges is already flipped, but scales aren't
549
+ rng <- layout $ panel_params [[i ]]
550
+ # stuff like layout$panel_params is already flipped, but scales aren't
554
551
sc <- if (inherits(plot $ coordinates , " CoordFlip" )) {
555
552
scales $ get_scales(setdiff(c(" x" , " y" ), xy ))
556
553
} else {
@@ -598,6 +595,7 @@ gg2list <- function(p, width = NULL, height = NULL,
598
595
if (i == 1 ) {
599
596
traces <- lapply(traces , function (z ) { z [[xy ]] <- z [[xy ]] * 86400000 ; z })
600
597
}
598
+ axisObj $ type <- " date"
601
599
}
602
600
# tickvals are currently on 0-1 scale, but we want them on data scale
603
601
axisObj $ tickvals <- scales :: rescale(
@@ -930,7 +928,7 @@ gg2list <- function(p, width = NULL, height = NULL,
930
928
l $ attrs <- setNames(mappingFormulas , ids )
931
929
l $ attrs <- lapply(l $ attrs , function (x ) structure(x , class = " plotly_eval" ))
932
930
# the build step removes the first attrs if no type exists
933
- l $ attrs [[1 ]][[" type" ]] <- " ggplotly "
931
+ l $ attrs [[1 ]][[" type" ]] <- l $ data [[ 1 ]][[ " type " ]] % || % " scatter "
934
932
935
933
l $ cur_data <- ids [[layerData ]]
936
934
l $ visdat <- setNames(lapply(return_dat , function (x ) function (y ) x ), ids )
0 commit comments