Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echarts 5.1.1 has the register_map with the option to choose svg and I’m trying to implement it. #319

Closed
ghost opened this issue May 10, 2021 · 5 comments

Comments

@ghost
Copy link

ghost commented May 10, 2021

I’m trying to use the new map svg feature of echarts 5.1.1. So, I have manually updated my echarts4r package to the new version. However, I’m missing something when implementing register_map to svg. Like this example: https://echarts.apache.org/examples/en/editor.html?c=geo-beef-cuts

So I trying to implant this way:
The Echarts js code:

 echarts.registerMap('Beef_cuts_France', { svg });

The equivalent in R:

svg='https://echarts.apache.org/examples/data/asset/geo/Beef_cuts_France.svg'
q$x$registerMap[[1]] = list(mapName="USA", list(svg))

As you can se the equivalent would use a named and an unnamed list, and R doesn’t allow that.
Any Idea of what could help?

Complete code:

library(echarts4r)
svg='https://echarts.apache.org/examples/data/asset/geo/Beef_cuts_France.svg'

q=data %>% 
  e_charts() %>% 
  e_map_register("USA", json= json) %>%
  e_map(value, map = "USA")

q$x$registerMap[[1]] = list(mapName="USA", list(svg))
q

Thank you

@ghost ghost changed the title Echarts 5.1.1 has the register_map with the option to choose svg and trying to implement it. Echarts 5.1.1 has the register_map with the option to choose svg and I’m trying to implement it. May 10, 2021
@JohnCoene
Copy link
Owner

Pretty neat, I did not know this was added. Reinstall the latest version and use the new e_svg function. I have put this example here

url <- "https://echarts.apache.org/examples/data/asset/geo/Beef_cuts_France.svg"

svg <- url %>% 
  readLines() %>% 
  paste0(collapse = "")

data <- tibble::tibble(
  name = c(
    "Queue", 
    "Langue",
    "Plat de joue",
    "Collier",
    "Rumsteck"
  ),
  value = runif(5, 10, 15)
)

data %>% 
  e_charts(name) %>% 
  e_svg_register("beef", svg) %>% 
  e_svg(
    value,
    map = "beef",
    label = list(
      show = FALSE
    )
  ) %>% 
  e_visual_map(value)

@ghost
Copy link
Author

ghost commented May 10, 2021

Awesome! Thank you very much!!

@ghost
Copy link
Author

ghost commented May 10, 2021

I have installed the latest version, using install_github(). But it returns an error
“Error in e_svg(., value, map = "beef", label = list(show = FALSE)) :
could not find function "e_svg" “. Maybe the server has not updated yet.

@JohnCoene
Copy link
Owner

It should work after restarting the R session.

  1. Install
  2. Restart R/session
  3. Try again

@ghost
Copy link
Author

ghost commented May 10, 2021

Thanks!! It is working!
Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant