sunburstR icon indicating copy to clipboard operation
sunburstR copied to clipboard

Have legend on as a default?

Open MarkEdmondson1234 opened this issue 8 years ago • 13 comments

Is it possible to not have to click to see the legend?

edit: in light of "time != money" which I agree with completly given my year old daughter ;) I'm happy to help with coding it if you point me in the right direction and think it possible. I've used sunburstR for a while for web analytics multi-touch analysis and it rocks.

MarkEdmondson1234 avatar May 19 '16 05:05 MarkEdmondson1234

An ugly hack to accomplish this using onRender:

# devtools::install_github("timelyportfolio/sunburstR")

library(sunburstR)

# read in sample visit-sequences.csv data provided in source
#   https://gist.github.com/kerryrodden/7090426#file-visit-sequences-csv
sequences <- read.csv(
  system.file("examples/visit-sequences.csv",package="sunburstR")
  ,header=F
  ,stringsAsFactors = FALSE
)

sunburst(sequences)

# with new htmlwidgets, we get onRender
htmlwidgets::onRender(
  sunburst(sequences),
"
function(el,x){
  // check legend
  d3.select(el).select('.sunburst-togglelegend').property('checked',true);
  // simulate click
  d3.select(el).select('.sunburst-togglelegend').on('click')();
}
"
)

I am trying to think through how best to provide this as an option for sunburstR on the R side.

I'd love your help testing #13 and #14. The new behavior is default now if you install the newest from Github.

timelyportfolio avatar May 19 '16 15:05 timelyportfolio

@MarkEdmondson1234 in terms of time != money, parcoords and sunburstR are the clear winners in popularity based on blog views, so I plan to focus on these. I will probably target a CRAN release in the next couple of months.

timelyportfolio avatar May 19 '16 15:05 timelyportfolio

Hi Kent,

Just so you know, I think upgrading to 1.0.2 made this hack stop working, and the default behavior seems to still not be having the legend turned on.

Many thanks!

vrybkin avatar Nov 14 '17 16:11 vrybkin

Interesting, I will check to see what might be happening. Thanks for the report.

timelyportfolio avatar Nov 14 '17 18:11 timelyportfolio

I'm pretty sure this hack broke because d3 is no longer added to the global namespace. You can work around that by using the withD3 = TRUE parameter.

library(sunburstR)
library(htmlwidgets)

sequences <- read.csv(
    system.file("examples/visit-sequences.csv",package="sunburstR")
    ,header=F
    ,stringsAsFactors = FALSE
)

htmlwidgets::onRender(
    sunburst(sequences, withD3 = T),
    "
    function(el,x){
    // check legend
    d3.select(el).select('.sunburst-togglelegend').property('checked',true);
    // simulate click
    d3.select(el).select('.sunburst-togglelegend').on('click')();
    }
    "
)

cjyetman avatar Nov 20 '17 06:11 cjyetman

Thanks again @cjyetman. @vrybkin, I think this will solve the problem. Please let us know if it does not.

timelyportfolio avatar Nov 20 '17 12:11 timelyportfolio

Thank you for your replies, @timelyportfolio and @cjyetman!

Your proposed change does work on render. However, suppose that I have my sunburst plot attached to a data set dependent on reactivity. When the data set changes, the legend functionality flip-flops after the sunburst is re-rendered, i.e. to turn the legend on, you have to uncheck the legend box, and to turn the legend off, you have to check the legend box. I think this quirk is fine, but just letting you know.

Many thanks for your help!

vrybkin avatar Nov 21 '17 15:11 vrybkin

This may be a better way to do it...

library(sunburstR)
library(htmlwidgets)

sequences <- read.csv(
    system.file("examples/visit-sequences.csv",package="sunburstR")
    ,header=F
    ,stringsAsFactors = FALSE
)

htmlwidgets::onRender(
    sunburst(sequences, withD3 = T),
    "
    function(el,x){
    d3.select(el).select('.sunburst-togglelegend').property('checked', true);
    d3.select(el).select('.sunburst-legend').style('visibility', '');
    }
    "
)

cjyetman avatar Nov 21 '17 18:11 cjyetman

Thanks, @cjyetman - this works like a charm!

vrybkin avatar Nov 27 '17 19:11 vrybkin

Hi!, I am new to sunburst i tried to follow above instructions but unable to on legends. Would you please help me to resolve this issue? I am interested to label each section with their name @cjyetman attached is my file. Waiting for your prompt response.

Abid

m1c

mirzaabidpp avatar Nov 28 '17 20:11 mirzaabidpp

@mirzaabidpp you'd probably be better served on Stack Overflow for questions like that. GitHub issues are used for reporting bugs and feature requests. Also, there is no file attached.

cjyetman avatar Nov 28 '17 20:11 cjyetman

Is there any option to remove the word "Legend", or Change it?

mmc00 avatar Jan 07 '18 04:01 mmc00

@mmc00 As I said in the previous comment, GitHub issues are typically used for reporting bugs and feature requests rather than support requests, and each issue is about a precise thing, so asking additional questions that go beyond the original topic is not very helpful or productive.

That being said, you could add the following JavaScript to the example above to change the "Legend" text...

document.getElementsByClassName('sunburst-sidebar')[0].childNodes[2].nodeValue = '';

cjyetman avatar Jan 07 '18 10:01 cjyetman