Skip to content

Commit fcccf0e

Browse files
committed
drag_element_force only works when animation is enabled. Missing autoFit in manual layout example.
1 parent 011fba7 commit fcccf0e

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Fix [#22](<https://github.com/cynkra/g6R/issues/22>): internal typo in JS function when an error was caught in the graph.
55
- Add `input$<graph_ID>-contextmenu` to extract the type and id of element which was clicked in the context menu.
66
This can be listened to from the Shiny server function.
7+
- Fix layout and behavior issues in some examples: `drag_element_force` only works when `animation` is TRUE. Also added `autoFit = TRUE` wherever required (manual layout vignette).
78

89
# g6R 0.1.0
910

inst/examples/dataframe/app.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ server <- function(input, output, session) {
3535
output$graph <- renderG6({
3636
g6(nodes, edges) |>
3737
g6_options(
38-
animation = FALSE,
38+
autoFit = "view",
3939
node = list(
4040
style = list(
4141
labelBackground = TRUE,
@@ -54,7 +54,7 @@ server <- function(input, output, session) {
5454
g6_layout() |>
5555
g6_behaviors(
5656
"zoom-canvas",
57-
drag_element_force(fixed = TRUE),
57+
drag_element_force(),
5858
click_select(multiple = TRUE),
5959
brush_select(),
6060
create_edge()

vignettes/articles/behaviors.Rmd

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,19 @@ g6(nodes, combos = data.frame(id = 1)) |>
223223

224224
## Drag element force
225225

226-
Combines element dragging with force simulation for dynamic positioning.
226+
Combines element dragging with force simulation for dynamic positioning. This requires animation to be enabled in `g6_options()`.
227227

228228
```{r}
229229
nodes <- data.frame(id = letters[1:5])
230230
231-
g6(nodes) |>
231+
g6(
232+
nodes,
233+
edges = data.frame(
234+
source = c("a", "b", "c", "d"),
235+
target = c("b", "c", "d", "e")
236+
)
237+
) |>
232238
g6_options(
233-
animation = FALSE,
234239
nodes = nodes_options
235240
) |>
236241
g6_layout(d3_force_layout()) |>
@@ -245,4 +250,4 @@ TBD?
245250

246251
### Update
247252

248-
To update behavior from the server of a Shiny app, you can use the `g6_update_behavior()` function. This function allows you to modify the behaviors of an existing G6 graph.
253+
To update behavior from the server of a Shiny app, you can use the `g6_update_behavior()` function. This function allows you to modify the behaviors of an existing G6 graph.

vignettes/articles/layouts.Rmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ The most straightforward way to do this is to add the coordinates to the nodes d
173173
```{r}
174174
g6(lesmis$nodes, lesmis$edges) |>
175175
g6_options(
176+
autoFit = "view",
177+
autoResize = TRUE,
176178
node = list(
177179
style = list(
178180
x = JS("(d) => {return 500*d.x}"),

0 commit comments

Comments
 (0)