Package 'jointjs'

Title: Interactive JointJS Diagrams
Description: Create interactive 'JointJS' diagrams. Wraps the JavaScript library 'JointJS' to create interactive html widgets. It will let the user draw and interact with diagrams.
Authors: Pepijn de Vries [aut, cre, dtc] (ORCID: <https://orcid.org/0000-0002-7961-6646>), clientIO [cph] (Authors of the bundled JointJS library)
Maintainer: Pepijn de Vries <[email protected]>
License: GPL (>= 3)
Version: 0.0.0.9002
Built: 2026-11-14 16:29:38 UTC
Source: https://github.com/pepijn-devries/jointjs

Help Index


Create an Interactive JointJS Diagram

Description

A wrapper around the JavaScript JointJS library to create an interactive html widget. It can be used to draw and edit diagrams.

Usage

jointjs(
  paper = jointjs_paper$new(),
  graph = NULL,
  width = NULL,
  height = NULL,
  elementId = NULL
)

Arguments

paper

Either a named list with paper properties, or a jointjs_paper class object.

graph

Either a named list of cells to draw, or a jointjs_graph class object

width

Fixed width for widget (in css units). The default is NULL, which results in intelligent automatic sizing based on the widget's container.

height

Fixed height for widget (in css units). The default is NULL, which results in intelligent automatic sizing based on the widget's container.

elementId

Use an explicit element ID for the widget (rather than an automatically generated one). Useful if you have other JavaScript that needs to explicitly discover and interact with a specific widget instance.

Value

An object of class htmlwidget that will intelligently print itself into HTML in a variety of contexts including the R console, within R Markdown documents, and within Shiny output bindings.

See Also

Other widgets: jointjs-shiny

Examples

if (interactive()) {
  graph <-
    jointjs_graph$new()$
      add_elements(
        jointjs_rectangle$new(id = "hello", label = list(text = "Hello"))$
          set_position(5, 5),
        jointjs_circle$new(id = "world", label = list(text = "World"))$
          set_position(70, 5),
        jointjs_doubleLink$new(source = list(id = "hello"),
                               target = list(id = "world"))
      )
  jointjs(graph = graph)
}

A Bordered Image Element

Description

An image with a border and label.

Super classes

jointjs_cell -> jointjs_element -> jointjs_image -> jointjs_borderedImage

Methods

Public methods

Inherited methods

jointjs_borderedImage$new()

Initialise the object

Usage
jointjs_borderedImage$new(href, ...)
Arguments
href

A Uniform Resource Identifier (URI) to locate the image

...

Arguments passed to parent class initialiser


jointjs_borderedImage$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_borderedImage$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


The Backbone of JointJS Elements

Description

It is a backbone structure used by jointjs to construct elements for a diagram. Usually you don't initiate cells directly. Rather, it is more efficient to create its children and grandchildren, e.g.: jointjs_circle, jointjs_image, jointjs_rectangle, etc.

Methods

Public methods


jointjs_cell$new()

Initialise a jointjs_cell class object.

Usage
jointjs_cell$new(id, type, z, ...)
Arguments
id

A unique identifier (character) used to identify the cell. It can be used to link cells together, by referring to these ids. By default a 16 character random hexadecimal code is generated as an id.

type

Specifies the type of cell this object represents. Its advised to create cells using its or grand-children (e.g. jointjs_circle, jointjs_rectangle, etc.). They will automatically assign the correct type for you. By default it will be set to "standard.Rectangle" (a rectangle).

z

A depth index. It will determine the plotting order on its parent container.

...

Parameters that will be set as SVG attributes to this object.


jointjs_cell$set_attrs()

Set attributes to the cell

Usage
jointjs_cell$set_attrs(...)
Arguments
...

Any valid attributes to a JointJS cell.


jointjs_cell$get_list()

Coerce the jointjs_cell object to a named list.

Usage
jointjs_cell$get_list()

jointjs_cell$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_cell$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other root-classes: jointjs_graph, jointjs_paper


A Cylinder Element

Description

A cylinder with a vertical base and an elliptical top.

Super classes

jointjs_cell -> jointjs_element -> jointjs_cylinder

Methods

Public methods

Inherited methods

jointjs_cylinder$new()

Initialise the object

Usage
jointjs_cylinder$new(...)
Arguments
...

Arguments passed to parent class initialiser


jointjs_cylinder$set_body()

Set body attributes for the element.

Usage
jointjs_cylinder$set_body(fill, stroke, strokeWidth, magnet, topRy, ...)
Arguments
fill

Fill colour

stroke

Stroke colour

strokeWidth

Width of the stroke line

magnet

When set to TRUE, the element can be used as source or target for a jointjs_link.

topRy

The vertical radius of the exposed area of the cylinder base, as an absolute value or a percentage.

...

Arguments passed to parent class initialiser


jointjs_cylinder$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_cylinder$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other elements: jointjs_circle, jointjs_element, jointjs_ellipse, jointjs_headeredRectangle, jointjs_image, jointjs_inscribedImage, jointjs_path, jointjs_polygon, jointjs_polyline, jointjs_rectangle, jointjs_textBlock


Elements to Build a JointJS Diagram

Description

A generic template to create shapes for a jointjs_graph. Shapes are visualised by https://www.w3.org/groups/wg/svg/ elements. jointjs_element objects are R's representation of such elements. This R class specifies the elements such that they can be used to construct a jointjs_graph. It's usually more effective to initialise a child class, such as jointjs_rectangle, jointjs_image, jointjs_circle, etc.

Parameters are all based on SVG attributes, you can use the ... arguments to pass other valid attributes. Note that the attributes are renamed in camel-case conform the JointJS spefications. So, SVG attribute font-family becomes fontFamily, stroke-width becomes strokeWidth, etc.

Super class

jointjs_cell -> jointjs_element

Methods

Public methods

Inherited methods

jointjs_element$set_position()

Set the element's position relative to its parent container.

Usage
jointjs_element$set_position(x, y)
Arguments
x, y

Coordinates relative to its parent container.


jointjs_element$set_image()

Set image attributes for the element.

Usage
jointjs_element$set_image(href, ...)
Arguments
href

A Uniform Resource Identifier (URI) to locate a resource (e.g. image)

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$set_border()

Set border attributes for the element.

Usage
jointjs_element$set_border(fill, stroke, strokeWidth, ...)
Arguments
fill

Fill colour

stroke

Stroke colour

strokeWidth

Width of the stroke line

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$set_background()

Set background attributes for the element.

Usage
jointjs_element$set_background(fill, stroke, strokeWidth, ...)
Arguments
fill

Fill colour

stroke

Stroke colour

strokeWidth

Width of the stroke line

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$set_top()

Set top attributes for the element (used to visualise the top of a cylinder base).

Usage
jointjs_element$set_top(fill, stroke, strokeWidth, ...)
Arguments
fill

Fill colour

stroke

Stroke colour

strokeWidth

Width of the stroke line

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$set_line()

Set line attributes for the element.

Usage
jointjs_element$set_line(stroke, strokeWidth, ...)
Arguments
stroke

Stroke colour

strokeWidth

Width of the stroke line

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$set_shadow()

Set shadow attributes for the element.

Usage
jointjs_element$set_shadow(stroke, strokeWidth, ...)
Arguments
stroke

Stroke colour

strokeWidth

Width of the stroke line

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$set_outline()

Set outline attributes for the element.

Usage
jointjs_element$set_outline(stroke, strokeWidth, ...)
Arguments
stroke

Stroke colour

strokeWidth

Width of the stroke line

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$set_wrapper()

Set wrapper attributes for the element.

Usage
jointjs_element$set_wrapper(stroke, strokeWidth, ...)
Arguments
stroke

Stroke colour

strokeWidth

Width of the stroke line

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$set_header()

Set header attributes for the element.

Usage
jointjs_element$set_header(fill, stroke, strokeWidth, ...)
Arguments
fill

Fill colour

stroke

Stroke colour

strokeWidth

Width of the stroke line

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$set_headerText()

Set headerText attributes for the element.

Usage
jointjs_element$set_headerText(text, color, fontFamily, fontSize, ...)
Arguments
text

A text to display

color

Colour of the element

fontFamily

Font family for the text to display

fontSize

Font size for the text to display

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$set_bodyText()

Set bodyText attributes for the element.

Usage
jointjs_element$set_bodyText(text, color, fontFamily, fontSize, ...)
Arguments
text

A text to display

color

Colour of the element

fontFamily

Font family for the text to display

fontSize

Font size for the text to display

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$set_body()

Set body attributes for the element.

Usage
jointjs_element$set_body(fill, stroke, strokeWidth, magnet, ...)
Arguments
fill

Fill colour

stroke

Stroke colour

strokeWidth

Width of the stroke line

magnet

When set to TRUE, the element can be used as source or target for a jointjs_link.

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$set_label()

Set label attributes for the element.

Usage
jointjs_element$set_label(text, color, fontFamily, fontSize, ...)
Arguments
text

A text to display

color

Colour of the element

fontFamily

Font family for the text to display

fontSize

Font size for the text to display

...

Additional SVG attributes accepted by the specific SVG element


jointjs_element$get_list()

Returns a named list representation of the element.

Usage
jointjs_element$get_list()

jointjs_element$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_element$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other elements: jointjs_circle, jointjs_cylinder, jointjs_ellipse, jointjs_headeredRectangle, jointjs_image, jointjs_inscribedImage, jointjs_path, jointjs_polygon, jointjs_polyline, jointjs_rectangle, jointjs_textBlock


An Ellipse Element

Description

An elliptical shape.

Super classes

jointjs_cell -> jointjs_element -> jointjs_ellipse

Methods

Public methods

Inherited methods

jointjs_ellipse$new()

Initialise the object

Usage
jointjs_ellipse$new(...)
Arguments
...

Arguments passed to parent class initialiser


jointjs_ellipse$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_ellipse$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other elements: jointjs_circle, jointjs_cylinder, jointjs_element, jointjs_headeredRectangle, jointjs_image, jointjs_inscribedImage, jointjs_path, jointjs_polygon, jointjs_polyline, jointjs_rectangle, jointjs_textBlock


A Embedded Image Element

Description

An image embedded into a rectangle with a label.

Super classes

jointjs_cell -> jointjs_element -> jointjs_image -> jointjs_embeddedImage

Methods

Public methods

Inherited methods

jointjs_embeddedImage$new()

Initialise the object

Usage
jointjs_embeddedImage$new(href, ...)
Arguments
href

A Uniform Resource Identifier (URI) to locate the image

...

Arguments passed to parent class initialiser


jointjs_embeddedImage$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_embeddedImage$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


Create A JointJS Graph

Description

Use the jointjs_graph class to define a diagram that can be rendered with jointjs().

Methods

Public methods


jointjs_graph$new()

Initialise a JointJS Graph

Usage
jointjs_graph$new(x, ...)
Arguments
x

A named list of cell objects represented as lists. You can use the graph state object returned by a Shiny widget to initiate a graph class object.

...

Ignored


jointjs_graph$add_elements()

Add elements to the graph. These can be any object that inherit from the jointjs_cell class. So, these can be shapes like jointjs_rectangle and jointjs_image, but also links like jointjs_doubleLink.

Usage
jointjs_graph$add_elements(...)
Arguments
...

Pass any number of items to be added to the graph here.


jointjs_graph$get_widget()

This is just short for jointjs(graph = x), where x is a jointjs_graph class object.

Usage
jointjs_graph$get_widget(...)
Arguments
...

Arguments passed to jointjs()


jointjs_graph$get_list()

Returns the list of cells that define the graph.

Usage
jointjs_graph$get_list()

jointjs_graph$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_graph$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other root-classes: jointjs_cell, jointjs_paper


A Headered Rectangle Element

Description

A rectangle with a header.

Super classes

jointjs_cell -> jointjs_element -> jointjs_headeredRectangle

Methods

Public methods

Inherited methods

jointjs_headeredRectangle$new()

Initialise the object

Usage
jointjs_headeredRectangle$new(header, headerText, bodyText, ...)
Arguments
header

Either a jointjs_rectangle or a named list with SVG rectangle attributes.

headerText

A named list with SVG text element properties

bodyText

A named list with SVG text element properties

...

Arguments passed to parent class initialiser


jointjs_headeredRectangle$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_headeredRectangle$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other elements: jointjs_circle, jointjs_cylinder, jointjs_element, jointjs_ellipse, jointjs_image, jointjs_inscribedImage, jointjs_path, jointjs_polygon, jointjs_polyline, jointjs_rectangle, jointjs_textBlock


An Image Element

Description

An image with a label.

Super classes

jointjs_cell -> jointjs_element -> jointjs_image

Methods

Public methods

Inherited methods

jointjs_image$new()

Initialise the object

Usage
jointjs_image$new(href, ...)
Arguments
href

A Uniform Resource Identifier (URI) to locate the image

...

Arguments passed to parent class initialiser


jointjs_image$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_image$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other elements: jointjs_circle, jointjs_cylinder, jointjs_element, jointjs_ellipse, jointjs_headeredRectangle, jointjs_inscribedImage, jointjs_path, jointjs_polygon, jointjs_polyline, jointjs_rectangle, jointjs_textBlock


An Inscribed Image Element

Description

An image inscribed in an ellipse with a label.

Super classes

jointjs_cell -> jointjs_element -> jointjs_image -> jointjs_inscribedImage

Methods

Public methods

Inherited methods

jointjs_inscribedImage$new()

Initialise the object

Usage
jointjs_inscribedImage$new(href, ...)
Arguments
href

A Uniform Resource Identifier (URI) to locate the image

...

Arguments passed to parent class initialiser


jointjs_inscribedImage$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_inscribedImage$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other elements: jointjs_circle, jointjs_cylinder, jointjs_element, jointjs_ellipse, jointjs_headeredRectangle, jointjs_image, jointjs_path, jointjs_polygon, jointjs_polyline, jointjs_rectangle, jointjs_textBlock


A Paper to Draw JointJS Diagrams on

Description

Set up a sheet of paper to draw jointjs diagrams on. This class can be used to define the paper specifications. These specifications are needed when creating a widget with jointjs().

Methods

Public methods


jointjs_paper$new()

Initiate a paper object

Usage
jointjs_paper$new(
  width,
  height,
  background = list(color = "#E9ECEF"),
  gridSize = 20,
  drawGrid = list(name = "dot", args = list(color = "#808080", thickness = 1)),
  interactive = TRUE,
  snapLinks = list(radius = 20),
  defaultLink = jointjs::jointjs_cell$new(NULL, "standard.Link", .connection =
    list(stroke = "#2C3E50", strokeWidth = 2), `.marker-target` = list(fill = "#2C3E50",
    d = "M 10 0 L 0 5 L 10 10 z")),
  validateConnection =
    htmlwidgets::JS("\n        function(cellViewS, magnetS, cellViewT, magnetT, end, linkView) {\n          if (cellViewS === cellViewT) return false;\n          return cellViewT && cellViewT.model.isElement();\n        }\n      "),
  ...
)
Arguments
width

Paper width in CSS units.

height

Paper height in CSS units.

background

A named list with background properties. The list can contain the elements color, image (an URL for a background image), position (x and y coordinate for the image), size of the background image (width and height), repeat a CSS ⁠background-repeat⁠ property, quality coefficient for image quality, opacity in the range of 0-1, watermarkAngle in degrees. If set to FALSE no background is drawn.

gridSize

gridSize in CSS units

drawGrid

A named list specifying how to draw a grid on the paper. An element name can use any of these predefined grid patterns: "dot" (default), "fixedDot", "mesh", or "doubleMesh". Use an element named args to specify pattern properties. If set to FALSE, no grid is drawn.

interactive

Use a logical value to enable or disable all interactive elements. Or use a named list of interactions with logical values to enable or disable specific interactions

snapLinks

A logical value indicating if links should be snapped to magnets. Or a named list with element radius in pixels, giving the distance for snapping links.

defaultLink

Default properties for links. A jointjs_link class object.

validateConnection

A JavaScript function that validates if a connection between a specific source and target is allowed. It should return a logical value.

...

Other options passed to the JointJS JavaScript library.


jointjs_paper$get_list()

Coerce JointJS paper options to a named list.

Usage
jointjs_paper$get_list()

jointjs_paper$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_paper$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other root-classes: jointjs_cell, jointjs_graph


A Path Element

Description

A vector of vertices connected by lines.

Super classes

jointjs_cell -> jointjs_element -> jointjs_path

Methods

Public methods

Inherited methods

jointjs_path$new()

Initialise the object

Usage
jointjs_path$new(refD, ...)
Arguments
refD

A character string that is used to set the d attribute of an SVG path element.

...

Arguments passed to parent class initialiser


jointjs_path$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_path$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other elements: jointjs_circle, jointjs_cylinder, jointjs_element, jointjs_ellipse, jointjs_headeredRectangle, jointjs_image, jointjs_inscribedImage, jointjs_polygon, jointjs_polyline, jointjs_rectangle, jointjs_textBlock

Examples

jointjs_path$new('M 0 5 10 0 C 20 0 20 20 10 20 L 0 15 Z')

A Polygon Element

Description

A vector of vertices connected as a polygon.

Super classes

jointjs_cell -> jointjs_element -> jointjs_polygon

Methods

Public methods

Inherited methods

jointjs_polygon$new()

Initialise the object

Usage
jointjs_polygon$new(refPoints, ...)
Arguments
refPoints

A character string of coordinates that is used to set the SVG points attribute of polygon or polyline elements.

...

Arguments passed to parent class initialiser


jointjs_polygon$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_polygon$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other elements: jointjs_circle, jointjs_cylinder, jointjs_element, jointjs_ellipse, jointjs_headeredRectangle, jointjs_image, jointjs_inscribedImage, jointjs_path, jointjs_polyline, jointjs_rectangle, jointjs_textBlock

Examples

jointjs_polygon$new("10,10 30,10 30,30")

A Polyline Element

Description

A polyline with a label.

Super classes

jointjs_cell -> jointjs_element -> jointjs_polyline

Methods

Public methods

Inherited methods

jointjs_polyline$new()

Initialise the object

Usage
jointjs_polyline$new(refPoints, ...)
Arguments
refPoints

A character string of coordinates that is used to set the SVG points attribute of polygon or polyline elements.

...

Arguments passed to parent class initialiser


jointjs_polyline$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_polyline$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other elements: jointjs_circle, jointjs_cylinder, jointjs_element, jointjs_ellipse, jointjs_headeredRectangle, jointjs_image, jointjs_inscribedImage, jointjs_path, jointjs_polygon, jointjs_rectangle, jointjs_textBlock

Examples

jointjs_polyline$new("10,10 30,10 30,30")

A Rectangle Element

Description

A Rectangle shape.

Super classes

jointjs_cell -> jointjs_element -> jointjs_rectangle

Methods

Public methods

Inherited methods

jointjs_rectangle$new()

Initialise the object

Usage
jointjs_rectangle$new(...)
Arguments
...

Arguments passed to parent class initialiser


jointjs_rectangle$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_rectangle$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other elements: jointjs_circle, jointjs_cylinder, jointjs_element, jointjs_ellipse, jointjs_headeredRectangle, jointjs_image, jointjs_inscribedImage, jointjs_path, jointjs_polygon, jointjs_polyline, jointjs_textBlock


A Text Block Element

Description

A rectangle shape with text.

Super classes

jointjs_cell -> jointjs_element -> jointjs_textBlock

Methods

Public methods

Inherited methods

jointjs_textBlock$new()

Initialise the object

Usage
jointjs_textBlock$new(text, ...)
Arguments
text

A character string to be displayed.

...

Arguments passed to parent class initialiser


jointjs_textBlock$clone()

The objects of this class are cloneable with this method.

Usage
jointjs_textBlock$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other elements: jointjs_circle, jointjs_cylinder, jointjs_element, jointjs_ellipse, jointjs_headeredRectangle, jointjs_image, jointjs_inscribedImage, jointjs_path, jointjs_polygon, jointjs_polyline, jointjs_rectangle


Shiny bindings for jointjs

Description

Output and render functions for using jointjs within Shiny applications and interactive Rmd documents.

Usage

jointjsOutput(outputId, width = "100%", height = "400px")

renderJointjs(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width, height

Must be a valid CSS unit (like "100\%", "400px", "auto") or a number, which will be coerced to a string and have "px" appended.

expr

An expression that generates a jointjs

env

The environment in which to evaluate expr.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.

See Also

Other widgets: jointjs()