Skip to content

Commit

Permalink
force: enable specifying the column with the node_label
Browse files Browse the repository at this point in the history
  • Loading branch information
cjyetman committed Feb 20, 2024
1 parent 582311b commit 2ab5d83
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions R/force_explorer.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ force_explorer <- function(data) {
max = 80,
step = 1
),
shiny::textInput(
inputId = "node_label",
label = "node_label:",
value = "id",
placeholder = "id [default]"
),
shiny::numericInput(
inputId = "strength",
label = "strength:",
Expand Down Expand Up @@ -122,6 +128,7 @@ force_explorer <- function(data) {
width = input$width,
height = input$height,
node_size = input$node_size,
node_label = input$node_label,
strength = input$strength,
distanceMin = input$distanceMin,
distanceMax = input$distanceMax,
Expand All @@ -145,6 +152,7 @@ force_explorer <- function(data) {
width = input$width,
height = input$height,
node_size = input$node_size,
node_label = input$node_label,
strength = input$strength,
distanceMin = input$distanceMin,
distanceMax = input$distanceMax,
Expand Down
5 changes: 3 additions & 2 deletions inst/force_network.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var node_color = eval(options.node_color) || d3.scaleOrdinal(d3.schemeCategory10),
node_size = options.node_size || 4,
node_label = options.node_label || "id",
link_color = options.link_color || "grey",
strength = options.strength || -300,
distanceMin = options.distanceMin || 1,
Expand Down Expand Up @@ -101,12 +102,12 @@ function ticked(transform) {
context.font = font;
context.fillStyle = d_color;
context.strokeStyle = "white";
context.strokeText(d.id, dx, dy);
context.strokeText(d[node_label], dx, dy);
context.shadowColor = shadow_color;
context.shadowOffsetX = 2;
context.shadowOffsetY = 2;
context.shadowBlur = 6;
context.fillText(d.id, dx, dy);
context.fillText(d[node_label], dx, dy);
});
}

Expand Down

0 comments on commit 2ab5d83

Please sign in to comment.