Skip to content

Commit

Permalink
feat: png export
Browse files Browse the repository at this point in the history
- require: shinyjs
- code coverage (TRIAL)
  • Loading branch information
jhk0530 committed Aug 18, 2024
1 parent 4e8c5df commit d1158da
Show file tree
Hide file tree
Showing 52 changed files with 1,997 additions and 149 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
^vignettes/Tooltip-On-Hovering-Node\.Rmd$
^CRAN-SUBMISSION$
^vignettes/articles$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
61 changes: 61 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage.yaml

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shinyCyJS
Title: Create Interactive Network Visualizations in R and 'shiny'
Version: 1.1.0
Version: 1.2.0
Authors@R:
c(
person("Jinhwan", "Kim", , email = "hwanistic@gmail.com", role = c("aut", "cre", "cph"))
Expand All @@ -14,11 +14,13 @@ URL: https://github.com/jhk0530/shinyCyJS
BugReports: https://github.com/jhk0530/shinyCyJS/issues
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Imports:
htmlwidgets
htmlwidgets,
shinyjs
Suggests:
testthat (>= 2.1.0),
testthat (>= 3.0.0),
rmarkdown,
knitr
VignetteBuilder: knitr
Config/testthat/edition: 3
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export(buildElems)
export(buildIOptions)
export(buildNode)
export(buildROptions)
export(getPNG)
export(renderShinyCyJS)
export(shinyCyJS)
import(htmlwidgets)
import(shinyjs)
102 changes: 62 additions & 40 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# shinyCyJS 1.2.0

## New Feature

- getPNG: now supports `getPNG` (in shiny application only) to export graph as PNG. see [Article](../articles/export-png.html)

## Dependency

- now requires shinyjs.

## Dev

- Add badge with code coverage

# shinyCyJS 1.1.0

## New Feature

- buildNode: now supports `textWrap` to multiline label, see Multiline label example in Articles
- buildNode: now supports `textAlign` to align label, see Align label example in Articles

# shinyCyJS 1.0.0

## New Feature
Expand All @@ -11,46 +32,37 @@

---

# shinyCyJS 0.0.2
# shinyCyJS 0.0.12

## New Feature
## Package

- Added Pie background. (Supports only `Size` and `Color`)
- Added a `NEWS.md` file to track changes to the package.
- Build [package site](https://jhk0530.github.io/shinyCyJS/) with `pkgdown`.
- Vignette added.
- Rebuild hexSticker

# shinyCyJS 0.0.3
# shinyCyJS 0.0.11

## Bug fix

- Pre-built elements didn't clear when using `rendershinyCyJS`

# shinyCyJS 0.0.4

## New Feature
- `Label` for Node can be independent with Node's `id`

- Tooltip available on Node elements.
## Package

# shinyCyJS 0.0.5
- Now `shinyCyJS` available with CRAN

## New Feature

- Selected elements will have different color.
- Node : ![#ff00ff](https://placehold.it/15/ff00ff/000000?text=+)
- Edge : ![#000000](https://placehold.it/15/000000/000000?text=+)

# shinyCyJS 0.0.6
# shinyCyJS 0.0.10

## New Feature

- New layout added
- [fcose](https://github.com/iVis-at-Bilkent/cytoscape.js-fcose)
- [spread](https://github.com/cytoscape/cytoscape.js-spread)
- [dagre](https://github.com/cytoscape/cytoscape.js-dagre)
- Now `Label` for Edge also available.

# shinyCyJS 0.0.7
# shinyCyJS 0.0.9

## New Feature
## Updated

- Multiple element can be declared with `buildElems`
- Manual for each function are added

# shinyCyJS 0.0.8

Expand All @@ -62,33 +74,43 @@

- Now available with `Taxi` edge

# shinyCyJS 0.0.9
# shinyCyJS 0.0.7

## Updated
## New Feature

- Manual for each function are added
- Multiple element can be declared with `buildElems`

# shinyCyJS 0.0.10
# shinyCyJS 0.0.6

## New Feature

- Now `Label` for Edge also available.
- New layout added
- [fcose](https://github.com/iVis-at-Bilkent/cytoscape.js-fcose)
- [spread](https://github.com/cytoscape/cytoscape.js-spread)
- [dagre](https://github.com/cytoscape/cytoscape.js-dagre)

# shinyCyJS 0.0.11
# shinyCyJS 0.0.5

## Bug fix
## New Feature

- `Label` for Node can be independent with Node's `id`
- Selected elements will have different color.
- Node : ![#ff00ff](https://placehold.it/15/ff00ff/000000?text=+)
- Edge : ![#000000](https://placehold.it/15/000000/000000?text=+)

## Package
# shinyCyJS 0.0.4

- Now `shinyCyJS` available with CRAN
## New Feature

# shinyCyJS 0.0.12
- Tooltip available on Node elements.

## Package
# shinyCyJS 0.0.3

- Added a `NEWS.md` file to track changes to the package.
- Build [package site](https://jhk0530.github.io/shinyCyJS/) with `pkgdown`.
- Vignette added.
- Rebuild hexSticker
## Bug fix

- Pre-built elements didn't clear when using `rendershinyCyJS`

# shinyCyJS 0.0.2

## New Feature

- Added Pie background. (Supports only `Size` and `Color`)
11 changes: 10 additions & 1 deletion R/buildNode.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ buildNode <- function(
textOutlineWidth = 0, textbgColor = "#FFF", textbgOpacity = 0, textBorderColor = "#222f3e",
textBorderOpacity = 0, textBorderWidth = 0, parent = NULL, opacity = 1, pieSize = rep("0%", 16), pieColor = rep("#000", 16), tooltip = "",
position.x = 0, position.y = 0, textWrap = "none", textAlign = 'auto') {

## TESTINGS
if (is.null(id)) stop("id must given")
if (!is.character(id)) stop("id must be string")


if (!shape %in% c(
"ellipse", "triangle", "round-triangle", "rectangle",
"round-rectangle", "bottom-round-rectangle", "cut-rectagnel", "barrel", "rhomboid",
Expand All @@ -67,6 +68,14 @@ buildNode <- function(

l <- list(group = "nodes")

if(!textWrap %in% c('none', 'wrap', 'ellipsis')){
stop("wrong textWrap, possible value is none, wrap, or ellipsis")
}

if(!textAlign %in% c('auto', 'left', 'center', 'right')){
stop("wrong textAlign, possible value is auto, left, center, or right")
}

options <- list(
width = width, height = height, label = label, id = id, shape = shape,
bgColor = bgColor, bgOpacity = bgOpacity, bgFill = bgFill, bgBlacken = bgBlacken,
Expand Down
21 changes: 21 additions & 0 deletions R/getPNG.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' @import shinyjs
#' @title Export cytoscape image as PNG
#'
#' @description This function is used to download cytoscape image as png.
#'
#' @return NULL
#' @export
getPNG <- function() {
shinyjs::runjs(
"
pngblob = cy.png({output: 'blob'});
const blobURL = URL.createObjectURL(pngblob);
const link = document.createElement('a');
link.href = blobURL;
link.download = 'cy.png';
link.click();
"
)
return(NULL)
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<!-- badges: start -->
[![CRAN status badge](https://www.r-pkg.org/badges/version/shinyCyJS)](https://cran.r-project.org/web/packages/shinyCyJS/index.html)
[![shinyCyJS status badge](https://jhk0530.r-universe.dev/badges/shinyCyJS)](https://jhk0530.r-universe.dev/shinyCyJS)
<!-- badges:: end -->
[![Codecov test coverage](https://codecov.io/gh/jhk0530/shinyCyJS/graph/badge.svg)](https://app.codecov.io/gh/jhk0530/shinyCyJS)
<!-- badges: end -->

shinyCyJS is R/Shiny Package to use cytoscape.js in R environment. <br>

Expand All @@ -18,7 +19,7 @@ From CRAN (1.0.0)
install.packages('shinyCyJS')
```

From r-universe (1.0.1)
From r-universe (1.2.0)
```r
install.packages(
"shinyCyJS",
Expand Down
3 changes: 2 additions & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion docs/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions docs/articles/Build-Many-Element-With-Data-frame.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d1158da

Please # to comment.