Learn R Programming

dm (version 0.0.5.9000)

cdm_draw: Draw a diagram of a dm-object's data model

Description

cdm_draw() uses DiagrammeR to draw diagrams.

cdm_set_colors() allows to define the colors that will be used to display the tables of the data model.

cdm_get_colors() returns the colors defined for a data model.

cdm_get_available_colors() returns an overview of the available colors and their names as a tibble.

Usage

cdm_draw(
  dm,
  rankdir = "LR",
  col_attr = "column",
  view_type = "keys_only",
  columnArrows = TRUE,
  graph_attrs = "",
  node_attrs = "",
  edge_attrs = "",
  focus = NULL,
  graph_name = "Data Model"
)

cdm_set_colors(dm, ...)

cdm_get_colors(dm)

cdm_get_available_colors()

Arguments

dm

A dm object.

rankdir

Graph attribute for direction (e.g., 'BT' = bottom --> top).

col_attr

Column atributes to display. By default only the column name ("column") is displayed.

view_type

Can be "keys_only" (default), "all" or "title_only". It defines the level of details for rendering tables (only primary and foreign keys, all columns, or no columns).

columnArrows

Edges from columns to columns (default: TRUE).

graph_attrs

Additional graph attributes.

node_attrs

Additional node attributes.

edge_attrs

Additional edge attributes.

focus

A list of parameters for rendering (table filter).

graph_name

The name of the graph.

...

Colors to set in the form table = "<color>" . Fall-through syntax similarly to switch() is supported: table1 = , table2 = "<color>" sets the color for both table1 and table2 . This argument supports splicing.

Value

For cdm_set_colors(): the updated data model.

For cdm_get_colors(), a two-column tibble with one row per table.

For cdm_get_available_colors(), a tibble with the color in the first column and auxiliary information in other columns.

Examples

Run this code
# NOT RUN {
library(dplyr)
cdm_draw(cdm_nycflights13())
cdm_draw(cdm_nycflights13(cycle = TRUE))
cdm_nycflights13(color = FALSE) %>%
  cdm_set_colors(
    airports = ,
    airlines = ,
    planes = "yellow",
    weather = "dark_blue"
  ) %>%
  cdm_draw()

# Splicing is supported:
new_colors <- c(
  airports = "yellow", airlines = "yellow", planes = "yellow",
  weather = "dark_blue"
)
cdm_nycflights13(color = FALSE) %>%
  cdm_set_colors(!!!new_colors) %>%
  cdm_draw()
# }

Run the code above in your browser using DataLab