Skip to content

feat: allow setting node XY coordinates when layout="none"#599

Merged
JohnCoene merged 3 commits intoJohnCoene:masterfrom
teofiln:feature/no-ref/graph-layout-none
Dec 6, 2023
Merged

feat: allow setting node XY coordinates when layout="none"#599
JohnCoene merged 3 commits intoJohnCoene:masterfrom
teofiln:feature/no-ref/graph-layout-none

Conversation

@teofiln
Copy link
Copy Markdown
Contributor

@teofiln teofiln commented Dec 2, 2023

Hi! I was trying to create a graph similar to this: https://echarts.apache.org/examples/en/editor.html?c=graph-simple, where the user passes X and Y coordinates for the nodes. But, it seems that e_graph() does not have this feature. Looks like it does not render anything when layout = "none". After some poking around, it seemed like there was no way to pass X and Y coordinates, so I tried to implement it by updating the e_graph_nodes functions and the associated . helpers from utils.R.

With this update, a user can now set fixed node positions with a call like:

nn <- data.frame(
    name = c("A", "B", "C", "D", "E"),
    value = c("A", "B", "C", "D", "E"),
    group = c("gr1", "gr1", "gr2", "gr2", "gr3"),
    size = 3:7 * 10,
    x = c(0, 200, 400, 600, 800),
    y = c(100, 100, 200, 200, 0)
)

ee <- data.frame(
    source = c("A", "B", "C", "D", "E"),
    target = c("B", "C", "D", "E", "D")
)

devtools::load_all()
e_charts() |>
    e_graph(layout = "none", autoCurveness = TRUE) |>
    e_graph_nodes(nn, name, value, size, category = group, xpos = x, ypos = y) |>
    e_graph_edges(ee, source, target) |>
    e_tooltip()

image

@JohnCoene
Copy link
Copy Markdown
Owner

Thanks, LGTM. Could you add yourself as ctb in the DESCRIPTION?

@teofiln
Copy link
Copy Markdown
Contributor Author

teofiln commented Dec 6, 2023

@JohnCoene I added my self as ctb. Thanks!

@JohnCoene
Copy link
Copy Markdown
Owner

Thanks!

@JohnCoene JohnCoene merged commit a40cb70 into JohnCoene:master Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants