jointjs

Create interactive JointJS diagrams. This package wraps the JointJS JavaScript library to create interactive html widgets. It will let the user draw and interact with diagrams.

Installation

You can install the development version of jointjs from GitHub with:

# install.packages("pak")
# pak::pak("pepijn-devries/jointjs")
install.packages("jointjs", repos = c('https://pepijn-devries.r-universe.dev', 'https://cloud.r-project.org'))

Example

This package uses R6 class objects to create graphs and define its elements:

library(jointjs)
graph <-
  jointjs_graph$
  ## Create a new graph:
  new()$
  ## Add elements:
  add_elements(
    ## Add a rectangle:
    jointjs_rectangle$new(id = "hello")$
      set_body(rx = 5, ry = 5)$
      set_label("Hello")$
      set_position(10, 10),
    ## Add a circle:
    jointjs_circle$new(id = "world")$
      set_body("white", "black")$
      set_label("world")$
      set_position(100, 10),
    ## Add a link, joining the rectangle and circle:
    jointjs_doubleLink$new(list(id = "hello"), list(id = "world"))
  )
## Get and show widget:
my_widget <- graph$get_widget(width = 170, height = 70)
Widget Preview Example

Note that this page cannot render interactive diagrams. Therefore, it only shows a static screenshot of the widget generated by the code chunk. For an interactive example you can check out vignette("gallery")

Alternatives

Why use jointjs?

Alternatives listed above are good at rendering predefined graphs. But most of them don’t let the user draw a graph and connect nodes on the fly. If you need such user interaction, jointjs is for you.