From b1a9bd6e73b83430a6488ea9c7b15a9d87b7b65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 3 May 2020 17:21:16 +0200 Subject: [PATCH] - Fix visualization of column that acts as a foreign key more than once (#37). Closes #37. --- R/datamodelr-code.R | 4 +- tests/testthat/out/nycflights13-multi-fk.svg | 97 ++++++++++++++++++++ tests/testthat/test-draw-dm.R | 11 +++ 3 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 tests/testthat/out/nycflights13-multi-fk.svg diff --git a/R/datamodelr-code.R b/R/datamodelr-code.R index c43d4bb0d2..3621eb893e 100644 --- a/R/datamodelr-code.R +++ b/R/datamodelr-code.R @@ -320,7 +320,7 @@ to_html_table <- function(x, ) ), # rows - sapply(seq_len(nrow(x)), function(r) { + unique(sapply(seq_len(nrow(x)), function(r) { html_tr(c( # cells sapply(cols, function(col_name) { @@ -329,7 +329,7 @@ to_html_table <- function(x, html_td(value, if (is.null(attr_td)) NULL else attr_td(col_name, x[r, ], value)) }) )) - }) + })) )) } diff --git a/tests/testthat/out/nycflights13-multi-fk.svg b/tests/testthat/out/nycflights13-multi-fk.svg new file mode 100644 index 0000000000..b0424340cf --- /dev/null +++ b/tests/testthat/out/nycflights13-multi-fk.svg @@ -0,0 +1,97 @@ + + + + + + +%0 + + + + + + +airlines + +airlines + +carrier + + + + +airports + +airports + +faa + + + + +flights + +flights + +carrier + +tailnum + +origin + + + + +flights:carrier->airlines:carrier + + + + + +flights:origin->airports:faa + + + + + +planes + +planes + +tailnum + + + + +flights:tailnum->planes:tailnum + + + + + +planes_copy + +planes_copy + +tailnum + + + + +flights:tailnum->planes_copy:tailnum + + + + + +weather + +weather + + + + + diff --git a/tests/testthat/test-draw-dm.R b/tests/testthat/test-draw-dm.R index 229ed448b7..d92528796c 100644 --- a/tests/testthat/test-draw-dm.R +++ b/tests/testthat/test-draw-dm.R @@ -165,4 +165,15 @@ test_that("output", { cli::cat_line(), "out/nycflights13.svg" ) + + # Multi-fk (#37) + expect_known_output( + dm_nycflights13() %>% + dm_zoom_to(planes) %>% + dm_insert_zoomed("planes_copy") %>% + dm_draw() %>% + DiagrammeRsvg::export_svg() %>% + cli::cat_line(), + "out/nycflights13-multi-fk.svg" + ) })