Skip to content

Commit

Permalink
Make the new intersections work with arbitrary ordering of intersecti…
Browse files Browse the repository at this point in the history
…on members
  • Loading branch information
krassowski committed Jan 13, 2021
1 parent 93b4ee8 commit d0fa6ad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
21 changes: 17 additions & 4 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,18 @@ note_time = function(text) {
}


intersection_vector_to_id = function (intersection_vector, sanitized_labels, sets_ordering_in_ids) {
not_in_known_map = NOT_IN_KNOWN_SETS
names(not_in_known_map) = NOT_IN_KNOWN_SETS
sanitizer_map = c(sanitized_labels, not_in_known_map)
sets = unname(sanitizer_map[intersection_vector])
sets_ordering_in_ids = c(
sets_ordering_in_ids,
NOT_IN_KNOWN_SETS
)
paste(sets_ordering_in_ids[sets_ordering_in_ids %in% sets], collapse='-')
}


#' Prepare data for UpSet plots
#'
Expand Down Expand Up @@ -383,11 +395,12 @@ upset_data = function(

# sanitize or encode names of intersections selection/order
if (specific_intersections) {
not_in_known_map = NOT_IN_KNOWN_SETS
names(not_in_known_map) = NOT_IN_KNOWN_SETS
sanitizer_map = c(sanitized_labels, not_in_known_map)
intersections = sapply(intersections, function(intersection) {
paste0(sanitizer_map[intersection], collapse='-')
intersection_vector_to_id(
intersection,
sanitized_labels=sanitized_labels,
sets_ordering_in_ids=intersect
)
})
}

Expand Down
7 changes: 5 additions & 2 deletions R/upset.R
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,11 @@ intersect_queries = function(queries, data) {
if (length(sets) == 1 && is.na(sets)) {
NOT_IN_KNOWN_SETS
} else {
sets = unname(data$sanitized_labels[sets])
paste(data$sets_ordering_in_ids[data$sets_ordering_in_ids %in% sets], collapse='-')
intersection_vector_to_id(
sets,
sanitized_labels=data$sanitized_labels,
sets_ordering_in_ids=data$sets_ordering_in_ids
)
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion vignettes/Examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,7 @@
" 'Comedy',\n",
" 'Drama',\n",
" c('Comedy', 'Romance'),\n",
" c('Drama', 'Romance'),\n",
" c('Romance', 'Drama'),\n",
" 'Outside of known sets',\n",
" 'Action'\n",
" )\n",
Expand Down

0 comments on commit d0fa6ad

Please sign in to comment.