sunburstR
sunburstR copied to clipboard
Have legend on as a default?
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.
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.
@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.
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!
Interesting, I will check to see what might be happening. Thanks for the report.
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')();
}
"
)
Thanks again @cjyetman. @vrybkin, I think this will solve the problem. Please let us know if it does not.
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!
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', '');
}
"
)
Thanks, @cjyetman - this works like a charm!
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
@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.
Is there any option to remove the word "Legend", or Change it?
@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 = '';