Skip to content

Commit

Permalink
drop edge working
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoene committed Aug 7, 2018
1 parent 2eb9b85 commit 8c6d912
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 43 deletions.
22 changes: 8 additions & 14 deletions R/graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ sg_add_nodes <- function(sg, data, delay, ..., cumsum = TRUE) {
delay_col <- eval(substitute(delay), df) # subset delay
if (isTRUE(cumsum))
delay_col <- cumsum(delay_col) # cumul for setTimeout

delay_table <- dplyr::tibble(sigmajsdelay = delay_col) # build delay tibble

# build data
nodes <- .build_data(df, ...) %>%
dplyr::bind_cols(delay_table) %>% # bind delay
.check_ids() %>%
.check_x_y() %>%
dplyr::mutate(id = as.character(id)) %>%
dplyr::arrange(sigmajsdelay) %>%
.as_list()

Expand All @@ -191,12 +193,14 @@ sg_add_edges <- function(sg, data, delay, ..., cumsum = TRUE, refresh = FALSE) {
delay_col <- eval(substitute(delay), data) # subset delay
if (isTRUE(cumsum))
delay_col <- cumsum(delay_col) # cumul for setTimeout

delay_table <- dplyr::tibble(sigmajsdelay = delay_col) # build delay tibble

# build data
nodes <- .build_data(data, ...) %>%
dplyr::bind_cols(delay_table) %>% # bind delay
.check_ids() %>%
dplyr::mutate(id = as.character(id)) %>%
dplyr::arrange(sigmajsdelay) %>%
.as_list()

Expand Down Expand Up @@ -248,12 +252,7 @@ sg_drop_nodes <- function(sg, data, ids, delay, cumsum = TRUE) {
ids <- eval(substitute(ids), data) # subset ids

to_drop <- dplyr::tibble(
id = ids,
sigmajsdelay = delay_col
)

to_drop <- dplyr::tibble(
id = ids,
id = as.character(ids),
sigmajsdelay = delay_col
) %>%
dplyr::arrange(sigmajsdelay) %>%
Expand All @@ -277,19 +276,14 @@ sg_drop_edges <- function(sg, data, ids, delay, cumsum = TRUE, refresh = FALSE)
delay_col <- cumsum(delay_col) # cumul for setTimeout

ids <- eval(substitute(ids), data) # subset ids

to_drop <- dplyr::tibble(
id = ids,
sigmajsdelay = delay_col
)


to_drop <- dplyr::tibble(
id = ids,
id = as.character(ids),
sigmajsdelay = delay_col
) %>%
dplyr::arrange(sigmajsdelay) %>%
.as_list()

sg$x$dropEdgesDelay <- append(sg$x$dropEdges, list(data = to_drop, refresh = refresh))
sg$x$dropEdgesDelay <- list(data = to_drop, refresh = refresh)
sg
}
57 changes: 28 additions & 29 deletions inst/htmlwidgets/sigmajs.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,66 +311,65 @@ HTMLWidgets.widget({
}
}

if(x.hasOwnProperty("dropNodesDelay")){

if(x.button.event.indexOf('drop_nodes') > -1){
button.addEventListener("click", function(event) {
x.dropNodesDelay.forEach((element) => {
setTimeout(function () {
s.graph.dropNode(element.id);
s.refresh();
}, element.sigmajsdelay);
});
});
} else {
x.dropNodesDelay.forEach((element) => {
setTimeout(function () {
s.graph.dropNode(element.id);
s.refresh();
}, element.sigmajsdelay);
});
}
}

if(x.hasOwnProperty("dropEdgesDelay")){
var is_running = s.isForceAtlas2Running();

if(x.button.event.indexOf('drop_edges') > -1){
button.addEventListener("click", function(event) {
x.dropEdgesDelay.data.forEach((element, index) => {
x.dropEdgesDelay.data.forEach((drop_edg, index) => {
setTimeout(function () {
if (x.dropEdgesDelay.refresh === true && is_running === true) {
s.killForceAtlas2();
}
s.graph.dropEdge(element);
s.graph.dropEdge(drop_edg.id);
if (x.dropEdgesDelay.refresh === true && is_running === true) {
s.startForceAtlas2();
}
if (x.dropEdgesDelay.refresh === true) {
s.refresh();
}
}, element.sigmajsdelay);
}, drop_edg.sigmajsdelay);
});
});
} else {
x.dropEdgesDelay.data.forEach((element, index) => {
x.dropEdgesDelay.data.forEach((drop_edg, index) => {
setTimeout(function () {
if (x.dropEdgesDelay.refresh === true && running === true) {
if (x.dropEdgesDelay.refresh === true && is_running === true) {
s.killForceAtlas2();
}
s.graph.dropEdge(element);
if (x.dropEdgesDelay.refresh === true && running === true) {
s.graph.dropEdge(drop_edg.id);
if (x.dropEdgesDelay.refresh === true && is_running === true) {
s.startForceAtlas2();
}
if (x.dropEdgesDelay.refresh === true) {
s.refresh();
}
}, drop_edg.sigmajsdelay);
});
}
}

if(x.hasOwnProperty("dropNodesDelay")){

if(x.button.event.indexOf('drop_nodes') > -1){
button.addEventListener("click", function(event) {
x.dropNodesDelay.forEach((element) => {
setTimeout(function () {
s.graph.dropNode(element.id);
s.refresh();
}, element.sigmajsdelay);
});
});
} else {
x.dropNodesDelay.forEach((element) => {
setTimeout(function () {
s.graph.dropNode(element.id);
s.refresh();
}, element.sigmajsdelay);
});
}
}


// events
if (HTMLWidgets.shinyMode) {
// click node
Expand Down

0 comments on commit 8c6d912

Please sign in to comment.