Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions R/utils_getSubnetworkFromIndra.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,10 @@
} else {
edge$site = NA_character_
}
if (key %in% keys(edgeToMetadataMapping)) {
edgeToMetadataMapping[[key]]$data$evidence_count <-
edgeToMetadataMapping[[key]]$data$evidence_count +
edge$data$evidence_count
edgeToMetadataMapping[[key]]$data$paper_count <-
edgeToMetadataMapping[[key]]$data$paper_count + 1
} else {
if (!key %in% keys(edgeToMetadataMapping) ||
edge$data$evidence_count > edgeToMetadataMapping[[key]]$data$evidence_count) {
edge <- .addAdditionalMetadataToIndraEdge(edge, input)
edge$data$paper_count <- 1
edge$data$paper_count <- 1 # TODO: fix paper count
edgeToMetadataMapping[[key]] <- edge
}
}
Expand Down Expand Up @@ -305,6 +300,9 @@
sourceCounts = vapply(keys(res), function(x) {
query(res, x)$data$source_counts
}, ""),
stmt_hash = vapply(keys(res), function(x) {
as.character(query(res, x)$data$stmt_hash)
}, ""),
stringsAsFactors = FALSE
)
# add correlation - maybe create a separate function
Expand Down
50 changes: 48 additions & 2 deletions R/visualizeNetworksWithHTML.R
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,23 @@ exportCytoscapeToHTML <- function(config,
<script src="https://cdnjs.cloudflare.com/ajax/libs/graphlib/2.1.8/graphlib.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dagre/0.8.5/dagre.min.js"></script>
<script src="https://unpkg.com/cytoscape-dagre@2.3.0/cytoscape-dagre.js"></script>
<script>
function openLinkInNewTab(url) {
try {
if (!url || typeof url !== "string") return;
url = url.trim();
if (!url || url === "NA" || url === "") return;
if (!/^https?:\\/\\//i.test(url)) {
console.warn("Blocked non-http(s) URL:", url);
return;
}
var win = window.open(url, "_blank", "noopener,noreferrer");
if (win) { win.opener = null; }
} catch (err) {
console.error("Error opening link:", err);
}
}
</script>

<style>
body {
Expand Down Expand Up @@ -1102,6 +1119,19 @@ exportCytoscapeToHTML <- function(config,
invisible(normalizePath(filename))
}

#' @noRd
createEdgeClickHandler <- function() {
list(
edge_click = "function(evt) {
var edge = evt.target;
var evidenceLink = edge.data('evidenceLink');
if (evidenceLink && evidenceLink !== '' && evidenceLink !== 'NA') {
openLinkInNewTab(evidenceLink);
}
}"
)
}

#' Export network data with Cytoscape visualization
#'
#' Convenience function that takes nodes and edges data directly and creates
Expand All @@ -1120,8 +1150,16 @@ exportNetworkToHTML <- function(nodes, edges,
nodeFontSize = 12,
...) {

event_handlers <- createEdgeClickHandler()

# Generate configuration
config <- generateCytoscapeConfig(nodes, edges, display_label_type = displayLabelType, node_font_size = nodeFontSize)
config <- generateCytoscapeConfig(
nodes,
edges,
display_label_type = displayLabelType,
node_font_size = nodeFontSize,
event_handlers = event_handlers
)

# Export to HTML
exportCytoscapeToHTML(config, filename, ...)
Expand All @@ -1141,8 +1179,16 @@ previewNetworkInBrowser <- function(nodes, edges,
nodeFontSize = 12,
...) {

event_handlers <- createEdgeClickHandler()

# Generate configuration
config <- generateCytoscapeConfig(nodes, edges, display_label_type = displayLabelType, node_font_size = nodeFontSize)
config <- generateCytoscapeConfig(
nodes,
edges,
display_label_type = displayLabelType,
node_font_size = nodeFontSize,
event_handlers = event_handlers
)

# Create temporary filename
temp_file <- tempfile(fileext = ".html")
Expand Down
Loading