Skip to content

Commit

Permalink
tweak echart theme
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Nov 13, 2023
1 parent d9e6f98 commit ae6fc5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion inst/showcase/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ui <- nextui_page(
server <- function(input, output, session) {
main <- mod_poke_select_server("poke_select_1")
mod_poke_info_server("poke_info_1", main$selected, main$is_shiny)
mod_poke_stats_server("poke_stats_1", main$selected)
mod_poke_stats_server("poke_stats_1", main$selected, reactive(input$theme))
mod_poke_move_server("poke_move_1", main$selected)
}

Expand Down
15 changes: 10 additions & 5 deletions inst/showcase/modules/mod_poke_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ get_max_of_max <- function(data = get_max_stats()) {
max()
}

create_radar_stats <- function(pokemon) {
create_radar_stats <- function(pokemon, theme) {
# R CMD check stop crying ...
x <- y <- z <- NULL

Expand All @@ -52,6 +52,9 @@ create_radar_stats <- function(pokemon) {

# Also adds previous pokemon stats to compare
# Check that the evolution belongs to the first 151 pkmns ...

legend_color <- if (theme == "light") "#000" else "#fff"

if (length(pokemon$evolve_from) > 0 && pokemon$evolve_from$id <= 151) {
tmp <- process_pokemon_stats(
poke_data[[pokemon$evolve_from$name]]$stats
Expand All @@ -65,12 +68,14 @@ create_radar_stats <- function(pokemon) {
max = get_max_of_max()
) |>
e_radar(z, name = paste0(pokemon$evolve_from$name, " Stats")) |>
e_tooltip(trigger = "item")
e_tooltip(trigger = "item") |>
e_legend(textStyle = list(color = legend_color))
} else {
data |>
e_charts(x) |>
e_radar(y, name = paste0(pokemon$name, " Stats"), max = get_max_of_max()) |>
e_tooltip(trigger = "item")
e_tooltip(trigger = "item") |>
e_legend(textStyle = list(color = legend_color))
}
}

Expand Down Expand Up @@ -121,7 +126,7 @@ mod_poke_stats_ui <- function(id) {
)
}

mod_poke_stats_server <- function(id, selected) {
mod_poke_stats_server <- function(id, selected, theme) {
moduleServer(id, function(input, output, session) {
ns <- session$ns

Expand Down Expand Up @@ -156,7 +161,7 @@ mod_poke_stats_server <- function(id, selected) {
# Generate radar chart for pokemons
output$poke_stats <- renderEcharts4r({
req(!is.null(selected()))
create_radar_stats(selected())
create_radar_stats(selected(), theme())
})

output$sum_stats <- renderText({
Expand Down

0 comments on commit ae6fc5b

Please sign in to comment.