timelyportfolio/parcoords

Using brushReset()

tbadams45 opened this issue · 14 comments

Is there a way to call parcoords.brushReset() on a button click? I know it's possible to run custom Javascript using the tasksparameter, but it's my understanding that this can only be used to run Javascript code directly after the parcoords plot has been produced.

I've made a workaround by taking a dependency on a reactive value (v$reset <- runif(1)) that changes everytime the reset button is selected, but it's a little messy.

In this case, I think we can use the fairly unknown and undocumented HTMLWidgets.find method to accomplish this task. Here is a non-shiny example. On another note, since this was one of my first ever widgets I neglected to add an id argument to parcoords, so finding is difficult. I have resolved with , which will require a reinstall.

library(parcoords)
library(htmltools)

browsable(
  tagList(
    tags$button(id="btn-resetbrush", onclick="reset_brush()", "reset brush"),
    parcoords(mtcars, brushMode="1d", elementId="parcoords1"),
    tags$script(
"
function reset_brush(){
  HTMLWidgets.find('#parcoords1').instance.parcoords.brushReset();
}
"      
    )
  )
)

Excellent! Unfortunately, right now I can't use the master branch because I need to use the dimensions list, so I can't use the elementID, but this is a very smooth answer. Thanks.

Sounds like time to merge the dimensions. I will try to get this done by the end of the week.

Thanks! Much appreciated. Making a great package better. :) Just so you know on my end, the solution (dependency on runif() variable) that I have right now is working, so there's no rush.

@tbadams45, could I lean on you again to test master? I somehow got out of sync with the resize, so I have had to manually merge the resize and dimensions. There is a change to access the parcoords in JavaScript. I changed the code above to reflect the change. We can do either

document.getElementById('#parcoords1').parcoords.brushReset();
//or note the instance.parcoords

HTMLWidgets.find('#parcoords').instance.parcoords.brushReset();

@timelyportfolio I think so. What would you like me to test specifically? Did you make any changes since #29?

Most changes are internal. If you have a set of examples that you could run quickly to visually inspect, I would really appreciate it. I have run through all my local examples, but I know they are not comprehensive.

@timelyportfolio, I ran a few quick checks in my existing app to see if everything was working as expected. Didn't notice anything unusual. The most complicated example I did is below, and that worked just fine.

parcoords(
      obj_space_disp_data$d, 
      rownames = FALSE,
      brushMode = "1D-axes",
      brushPredicate = "and",
      reorderable = TRUE,
      alpha = 0.6,
      queue = TRUE,
      rate  = 200,
      color = list(
        colorBy = "cost",
        colorScale = htmlwidgets::JS('
          d3.scale.threshold()
          .domain([80000000,90000000,97500000,102500000,107500000,112000000])
          .range(["#feedde","#fdbe85","#fd8d3c","#e6550d","#a63603"])
          ')
        ),
      dimensions = list(
        ID   = list(title = "ID", tickValues = id_ticks),
        cost = list(title = "Cost"),
        dom_rel = list(title = "Dom. Reliability"),
        irr_rel = list(title = "Irr. Reliability"),
        eco_rel = list(title = "Env. Reliability"),
        dom_crel = list(title = "Dom. Crit. Reliability")
      ),
      tasks = htmlwidgets::JS("function f(){this.parcoords.alphaOnBrushed(0.15);}")
    ) 

Great to hear! I will try to keep pushing forward. I really appreciate your help.

Certainly! Thanks for your work.

@tbadams45 if you have any beautiful examples that you produce and would like to contribute, I would love to add them. I have not had the time to make any pretty examples.

Duly noted. I've been spending most of my time related to parcoords incorporating it into a set of linked visualizations to help water planners gain insight into the impacts of different design and operating decisions. However, I'm working as an undergrad in the department and don't have much control about whether or not we release this work to the public... otherwise I'd gladly post everything right now.

@jtr13, does this #28 (comment) help with your emailed issue? There are lots of options for clearing the brushes. This one adds a button.

jtr13 commented

It works! Thanks so much! I was about to ask our 10-year-old where to click to reset (he is good for stuff like that and explaining to me that The Weekend is a person.) If I get good examples from the class I will send them your way.