hrbrmstr / metricsgraphics

:chart_with_upwards_trend: htmlwidget interface to the MetricsGraphics.js D3 chart library
http://hrbrmstr.github.io/metricsgraphics/
Other
132 stars 35 forks source link

mjs_add_mouseover: Doesn't work with mjs_point #19

Closed tinyheero closed 9 years ago

tinyheero commented 9 years ago

Hi,

I am testing out the mjs_add_mouseover and was using the test example as an template. I've noticed that it adds custom text for mjs_line(), but doesn't seem to work with the mjs_point()? For example, considering the following data:

dat <- data.frame(value=rnorm(n=30, mean=5, sd=1),
                  value2=rnorm(n=30, mean=4, sd=1),
                  test = c(rep(c('test', 'test2'), 15)))

dat %>%
  mjs_plot(x = value, y = value2) %>%
  mjs_line() %>%
  mjs_add_mouseover("function(d, i) {
                $('{{ID}} svg .mg-active-datapoint')
                    .text('custom text : ' + d.test + ' ' + i);
                 }")

Custom text is added with the d.test, but if I do the following:

dat %>%
  mjs_plot(x = value, y = value2) %>%
  mjs_point() %>%
  mjs_add_mouseover("function(d, i) {
                $('{{ID}} svg .mg-active-datapoint')
                    .text('custom text : ' + d.test + ' ' + i);
                 }")

I get an undefined for the custom test? Am I missing something here?

R version 3.1.2 (2014-10-31)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C               LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8     LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8    LC_PAPER=en_CA.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] dplyr_0.4.1         data.table_1.9.4    metricsgraphics_0.7 htmltools_0.2.6     htmlwidgets_0.3.2   vimcom_1.0-0        setwidth_1.0-3      colorout_1.1-0

loaded via a namespace (and not attached):
 [1] assertthat_0.1  chron_2.3-45    DBI_0.3.1       digest_0.6.8    lazyeval_0.1.10 magrittr_1.5    parallel_3.1.2  plyr_1.8.1      Rcpp_0.11.4     reshape2_1.4.1  RJSONIO_1.3-0   stringr_0.6.2   tools_3.1.2     yaml_2.1.13
tinyheero commented 9 years ago

Hi,

I was wondering if you could point me in the right direction as to where I could look to fix what seems like a bug. Really looking forward to get this to work for scatterplots, but unfortunately I can't get it working...

Thanks!

holgerman commented 9 years ago

Hi, first, thank you for the package, which has great value. I run into exactly the same problem as tinyheero and it would be wonderful if the issue could be solved. Best, Holger.

hrbrmstr commented 9 years ago

Taking a look this weekend

brendanhoganvt commented 9 years ago

I agree this would be very helpful. Does anyone know if it works in the native MetricsGraphics.js utility or is a bug specific to this R package? Thanks!

vasiliosz commented 9 years ago

+1

hrbrmstr commented 9 years ago

Take a look here: https://github.com/mozilla/metrics-graphics/issues/308

This is an issue with metrics-graphics, unfortunately, not the package.

Try using d.point.test vs d.test.

tinyheero commented 9 years ago

Thanks for looking at this. Works for me. Excited to be able to use this.

holgerman commented 9 years ago

Thanks for the solution, that works also fine for me! Love it.

hrbrmstr commented 9 years ago

awesome! glad to have found a solution for it.