Skip to content

Commit

Permalink
work around hideAxis bug and fix example to work with `reorderable …
Browse files Browse the repository at this point in the history
…= TRUE` see #16
  • Loading branch information
timelyportfolio committed Jan 7, 2016
1 parent 06c0290 commit 54f82dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
15 changes: 14 additions & 1 deletion inst/examples/examples_dimensions.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ parcoords(
parcoords(
mtcars,
brushMode = "2d",
#reorderable = TRUE,
reorderable = TRUE,
dimensions = list(
cyl = list(
tickValues = c(4,6,8)
Expand Down Expand Up @@ -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();
Expand All @@ -64,3 +65,15 @@ function(){
))
)
)


parcoords(
mtcars
,rownames = F
,dimensions = list(
cyl = list(
title = "cylinder",
tickValues = unique(mtcars$cyl)
)
)
)
17 changes: 16 additions & 1 deletion inst/htmlwidgets/parcoords.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
}

Expand All @@ -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){
Expand Down

0 comments on commit 54f82dd

Please sign in to comment.