From 54f82ddac45dc1281acdfff14b7c18520051501d Mon Sep 17 00:00:00 2001 From: timelyportfolio Date: Thu, 7 Jan 2016 12:50:57 -0600 Subject: [PATCH] work around `hideAxis` bug and fix example to work with `reorderable = TRUE` see #16 --- inst/examples/examples_dimensions.R | 15 ++++++++++++++- inst/htmlwidgets/parcoords.js | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/inst/examples/examples_dimensions.R b/inst/examples/examples_dimensions.R index 213a7a7..77e3efc 100644 --- a/inst/examples/examples_dimensions.R +++ b/inst/examples/examples_dimensions.R @@ -15,7 +15,7 @@ parcoords( parcoords( mtcars, brushMode = "2d", - #reorderable = TRUE, + reorderable = TRUE, dimensions = list( cyl = list( tickValues = c(4,6,8) @@ -46,6 +46,7 @@ function(){ // duplicated from the widget js code // to make sure reorderable and brushes work if( this.x.options.reorderable ) { + this.parcoords.remove this.parcoords.reorderable(); } else { this.parcoords.createAxes(); @@ -64,3 +65,15 @@ function(){ )) ) ) + + +parcoords( + mtcars + ,rownames = F + ,dimensions = list( + cyl = list( + title = "cylinder", + tickValues = unique(mtcars$cyl) + ) + ) +) diff --git a/inst/htmlwidgets/parcoords.js b/inst/htmlwidgets/parcoords.js index 08e2202..37882a3 100644 --- a/inst/htmlwidgets/parcoords.js +++ b/inst/htmlwidgets/parcoords.js @@ -20,6 +20,19 @@ HTMLWidgets.widget({ // someone supplies data in an atypical way if( x.data.constructor.name === "Object" ){ // use HTMLWidgets function to convert to an array of objects (row format) + // with experimental dimensions + // bug with hideAxis so remove rownames from data + if( typeof x.options.rownames == "undefined" || + x.options.rownames === false + ) { + var tempdata = {}; + Object.keys(x.data) + .filter(function(ky) {return ky!=="names"} ) + .map(function(ky){ + tempdata[ky] = x.data[ky]; + }) + x.data = tempdata; + } x.data = HTMLWidgets.dataframeToD3( x.data ) } @@ -31,11 +44,13 @@ HTMLWidgets.widget({ var parcoords = d3.parcoords()("#" + el.id) .data( x.data ); +/* remove this because of bug with experimental dimensions + handle for now by removing rownames from the data if( typeof x.options.rownames == "undefined" || x.options.rownames === false ) { //rownames = F so hide the axis parcoords.hideAxis(["names"]); } - +*/ //identify the brushed elements and return those data IDs to Rshiny //the parcoords.on("brush",function(d)){} only works with 1D-axes selection if (HTMLWidgets.shinyMode){