jbkunst / highcharter

R wrapper for highcharts
http://jkunst.com/highcharter/
Other
720 stars 148 forks source link

Possible drilldown bug #757

Closed jvaccaro2 closed 1 year ago

jvaccaro2 commented 2 years ago

Hi, this it's my first time posting,

I'm trying to create a drilldown barchart with 100 or more datapoints, and I'm trying to show different text Xaxis labels on both the base graph and the drilldowns.

The graph seemingly works as expected, however, upon clicking on a drilldown and pressing the "back to" button the base graph doesn't return to its original form, instead, it has some blank spaces close to the final datapoints, specifically y consecutive blank spaces starting from x-(y*2), being x the total base datapoints and y the number of points on the previously selected drilldown. (this it's the best as I can explain it).

With several different attempts I have found:

Is it a bug or I'm doing something wrong?

Here's a reproducible example:

library(highcharter)
library(dplyr)

#config (uncomment to obtain different outputs)
  #produces  bug
    reps <- 100
    ch1 <- 'A'
    ch2 <- 'B'

  #doesn't produces bug
    #reps <- 100
    #ch1 <- 'A'
    #ch2 <- 'A'

  #doesn't produces bug
    #reps <- 50
    #ch1 <- 'A'
    #ch2 <- 'B'

#base data
y1 <- rexp(reps) %>% sort
id1 <- paste0(ch1,seq(1:reps))
x1 <- id1
df1 <- data.frame(y = y1, id = id1, x = x1)

#drilldown data
y2 <- rep(1:5,reps)
id2 <- paste0(ch1,rep(seq(1:reps),5)) %>% sort
df2 <- data.frame(y = y2, id = id2, name = paste0(ch2, seq(1:reps)))

#drilldown list
ls <- list()
sr <- list()
ls2 <- list()
sr2 <- list()
for(i in 1:nrow(df1)){
  dat = dplyr::filter(df2, id == df1$id[i])
  for(j in 1:nrow(dat)){
    ls2 <- list(y = dat$y[j]
                ,id = df1$id[i]
                ,name = df2$name[j])
    sr2[[j]] <- ls2
  }
  ls = list(
    id = df1$id[i]
    ,type = 'line'
    ,data = sr2)
  sr[[i]] <- ls
}

#graph
hc <-
  hchart(
    df1, "column", hcaes(x = x, y = y, drilldown = id),
    pointPadding = 0,groupPadding = 0) %>%
  hc_drilldown(
    allowPointDrilldown = TRUE,
    series = sr)
hc

bug

Session info R version 4.0.4 (2021-02-15) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 Matrix products: default locale: [1] LC_COLLATE=Spanish_Bolivarian Republic of Venezuela.1252 [2] LC_CTYPE=Spanish_Bolivarian Republic of Venezuela.1252 [3] LC_MONETARY=Spanish_Bolivarian Republic of Venezuela.1252 [4] LC_NUMERIC=C [5] LC_TIME=Spanish_Bolivarian Republic of Venezuela.1252 attached base packages: [1] stats graphics grDevices utils datasets methods [7] base other attached packages: [1] rio_0.5.26 leaflet_2.0.4.1 [3] kableExtra_1.3.4 dichromat_2.0-0 [5] htmlwidgets_1.5.3 highcharter_0.9.4 [7] formattable_0.2.1 cluster_2.1.0 [9] googledrive_1.0.1 zoo_1.8-9 [11] shinydashboardPlus_2.0.1 shinydashboard_0.7.1 [13] plotly_4.10.0 ggplot2_3.3.5 [15] dplyr_1.0.5 DBI_1.1.1 [17] shiny_1.6.0 odbc_1.3.0 [19] crypto2_1.4.3 loaded via a namespace (and not attached): [1] sf_0.9-7 xts_0.12.1 [3] lubridate_1.7.10 bit64_4.0.5 [5] RColorBrewer_1.1-2 webshot_0.5.2 [7] progress_1.2.2 httr_1.4.2 [9] tools_4.0.4 backports_1.4.1 [11] bslib_0.2.4 utf8_1.1.4 [13] R6_2.5.0 KernSmooth_2.23-18 [15] lazyeval_0.2.2 colorspace_2.0-0 [17] withr_2.4.1 tidyselect_1.1.0 [19] prettyunits_1.1.1 bit_4.0.4 [21] curl_4.3 compiler_4.0.4 [23] cli_3.1.0 rvest_1.0.0 [25] xml2_1.3.2 labeling_0.4.2 [27] sass_0.3.1 scales_1.1.1 [29] classInt_0.4-3 proxy_0.4-25 [31] systemfonts_1.0.4 stringr_1.4.0 [33] digest_0.6.27 foreign_0.8-81 [35] rmarkdown_2.7 svglite_2.1.0 [37] pkgconfig_2.0.3 htmltools_0.5.1.1 [39] fastmap_1.1.0 readxl_1.3.1 [41] rlang_0.4.10 TTR_0.24.2 [43] rstudioapi_0.13 quantmod_0.4.18 [45] farver_2.1.0 jquerylib_0.1.3 [47] generics_0.1.0 jsonlite_1.7.2 [49] crosstalk_1.1.1 zip_2.1.1 [51] magrittr_2.0.1 rlist_0.4.6.1 [53] Rcpp_1.0.7 munsell_0.5.0 [55] fansi_0.4.2 lifecycle_1.0.0 [57] stringi_1.7.6 yaml_2.2.1 [59] plyr_1.8.6 grid_4.0.4 [61] blob_1.2.1 promises_1.2.0.1 [63] forcats_0.5.1 crayon_1.4.2 [65] lattice_0.20-41 haven_2.4.0 [67] hms_1.0.0 knitr_1.36 [69] pillar_1.6.1 igraph_1.2.9 [71] glue_1.4.2 evaluate_0.14 [73] leaflet.providers_1.9.0 data.table_1.14.0 [75] vctrs_0.3.8 httpuv_1.5.5 [77] cellranger_1.1.0 gtable_0.3.0 [79] purrr_0.3.4 tidyr_1.1.3 [81] assertthat_0.2.1 cachem_1.0.4 [83] openxlsx_4.2.3 xfun_0.22 [85] mime_0.10 xtable_1.8-4 [87] broom_0.7.6 e1071_1.7-9 [89] later_1.1.0.1 class_7.3-18 [91] rsconnect_0.8.16 viridisLite_0.4.0 [93] tibble_3.1.0 tinytex_0.31 [95] units_0.7-0 ellipsis_0.3.2
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Feel free to reopen it if you find it necessary.