echarts4r icon indicating copy to clipboard operation
echarts4r copied to clipboard

Adding data to sankey causes emphasis error

Open tylerlittlefield opened this issue 2 years ago • 0 comments

Consider the following example that emphasizes nodes when hovering over the lines:

library(echarts4r)
library(dplyr)

df <- data.frame(
  name = c("start", "start", "start", "start", "start"),
  target = c("node1", "node2", "node3", "node4", "node5"),
  value = round(c(2 / 3, 1 / 9, 1 / 9, 1 / 18, 1 / 18), 2),
  desc = "foo",
  stringsAsFactors = FALSE
)

df %>%
  e_charts() %>%
  e_sankey(
    source = name, 
    target = target, 
    value = value, 
    emphasis = list(focus = "adjacency"),
    lineStyle = list(color = "source", curveness = 0.5),
    nodeAlign = "left"
  )

If I try to add new information to be used in a tool tip, hovering over the lines no longer emphasizes the nodes:

library(echarts4r)
library(dplyr)

df <- data.frame(
  name = c("start", "start", "start", "start", "start"),
  target = c("node1", "node2", "node3", "node4", "node5"),
  value = round(c(2 / 3, 1 / 9, 1 / 9, 1 / 18, 1 / 18), 2),
  desc = "foo",
  stringsAsFactors = FALSE
)

df %>%
  e_charts() %>%
  e_sankey(
    source = name, 
    target = target, 
    value = value, 
    emphasis = list(focus = "adjacency"),
    lineStyle = list(color = "source", curveness = 0.5),
    nodeAlign = "left"
  ) %>% 
  e_add_nested('extra', desc) %>% 
  e_tooltip(formatter = htmlwidgets::JS('function(params){return params.data.extra.desc;}'))

With the following found in the console:

VM10:1 Uncaught TypeError: Cannot read properties of undefined (reading 'desc')
    at eval (eval at tryEval (htmlwidgets.js:252:16), <anonymous>:1:44)
    at e._showTooltipContent (echarts-en.min.js:45:781724)
    at e.<anonymous> (echarts-en.min.js:45:780451)
    at e._showOrMove (echarts-en.min.js:45:778470)
    at e._showSeriesItemTooltip (echarts-en.min.js:45:780420)
    at e._tryShow (echarts-en.min.js:45:778192)
    at e.<anonymous> (echarts-en.min.js:45:775333)
    at jO (echarts-en.min.js:45:686081)
    at echarts-en.min.js:35:6035
    at echarts-en.min.js:45:685666

tylerlittlefield avatar Mar 17 '22 00:03 tylerlittlefield