From edcb3869d135b750da7c416bb6d48cf060750e60 Mon Sep 17 00:00:00 2001 From: Loan Vulliard Date: Fri, 8 Feb 2019 09:17:49 +0100 Subject: [PATCH] Add orientation parameter for genome labels --- DESCRIPTION | 4 ++-- R/BioCircos.R | 7 ++++--- README.md | 2 ++ inst/htmlwidgets/BioCircos.js | 3 ++- inst/htmlwidgets/lib/biocircos-1.1.2.js | 19 +++++++++++++------ vignettes/BioCircos.Rmd | 2 +- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 47f806a..a717e88 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: BioCircos Title: Interactive Circular Visualization of Genomic Data using 'htmlwidgets' and 'BioCircos.js' -Version: 0.3.3 +Version: 0.3.4 Authors@R: c(person("Loan", "Vulliard", email = "lvulliard@cemm.at", role = c("trl", "cre")), person("Xiaowei", "Chen", email = "chenxiaowei@moon.ibp.ac.cn", role = c("aut")), person("Ya", "Cui", email = "cui_ya@163.com", role = c("aut"))) @@ -14,7 +14,7 @@ License: GPL-2 | file LICENSE Encoding: UTF-8 URL: https://github.com/lvulliard/BioCircos.R LazyData: true -RoxygenNote: 6.0.1 +RoxygenNote: 6.1.1 Suggests: knitr, rmarkdown VignetteBuilder: knitr Imports: RColorBrewer, htmlwidgets, jsonlite, plyr, grDevices diff --git a/R/BioCircos.R b/R/BioCircos.R index 0162ae6..445a3c0 100644 --- a/R/BioCircos.R +++ b/R/BioCircos.R @@ -29,9 +29,9 @@ #' @param genomeTicksDisplay,genomeTicksLen,genomeTicksColor,genomeTicksTextSize,genomeTicksTextColor,genomeTicksScale #' Should the refence genome have ticks, of which length, color (in hexadecimal RGB format), with labels in which font #' size and color, and spaced by how many bases? -#' @param genomeLabelDisplay,genomeLabelTextSize,genomeLabelTextColor,genomeLabelDx,genomeLabelDy +#' @param genomeLabelDisplay,genomeLabelTextSize,genomeLabelTextColor,genomeLabelDx,genomeLabelDy,genomeLabelOrientation #' Should the reference genome have labels on each chromosome, in which font size and color? Moreover rotation -#' and radius shifts for the label texts can be adde +#' and radius shifts for the label texts can be added, and the angle between the radius and the label changed. #' #' @param zoom Is zooming and moving in the visualization allowed? #' @@ -164,7 +164,7 @@ BioCircos <- function(tracklist = BioCircosTracklist(), genomeTicksDisplay = TRUE, genomeTicksLen = 5, genomeTicksColor = "#000", genomeTicksTextSize = "0.6em", genomeTicksTextColor = "#000", genomeTicksScale = 30000000, genomeLabelDisplay = TRUE, genomeLabelTextSize = "10pt", genomeLabelTextColor = "#000", - genomeLabelDx = 0.028, genomeLabelDy = "-0.55em", + genomeLabelDx = 0.0, genomeLabelDy = 10, genomeLabelOrientation = 0, zoom = TRUE, TEXTModuleDragEvent = FALSE, SNPMouseOverDisplay = TRUE, SNPMouseOverColor = "#FF0000", SNPMouseOverCircleSize = 3, SNPMouseOverCircleOpacity = 0.9, @@ -261,6 +261,7 @@ BioCircos <- function(tracklist = BioCircosTracklist(), genomeLabelTextColor = genomeLabelTextColor, genomeLabelDx = genomeLabelDx, genomeLabelDy = genomeLabelDy, + genomeLabelOrientation = genomeLabelOrientation, SNPMouseEvent = T, SNPMouseClickDisplay = F, SNPMouseClickColor = "red", diff --git a/README.md b/README.md index da47f7b..f666a0f 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Since the visualizations are powered by JavaScript, they are affected by the env * If nothing shows up in the Rstudio viewer pane, try displaying the plot you generated in your browser instead. You can export the figure using the *Save as Web Page...* option in the *Export* tab of the viewer pane. * If nothing shows up in a shiny application or an Rmarkdown document, try to update your web browser. See the vignettes for examples of BioCircos plots that should be correctly displayed. +* Rotation of labels using the *genomeLabelOrientation* parameter leads to a slight offset of the text when displayed in Firefox because some recent CSS options are not yet implemented. ### Obseved behavior @@ -78,6 +79,7 @@ The following features have been added to the original BioCircos.js library, bas * Parameter *snp_value_maxmin_instance* set by *SNPsettings.range* when provided, to allow the use of a pre-defined range of values for the SNP track. * Similar parameters added for the range of Histogram/Bar tracks, Line tracks, CNV tracks and Heatmap tracks (for the range to be used for color mapping). * Parameter *opacity* added to each elements of SNP and Arc tracks. +* Changes were made in order to allow rotation of genome labels with the new parameter *genomeLabelOrientation* and the radial offset *dy* is now directly integrated in the label translation. ## Contact diff --git a/inst/htmlwidgets/BioCircos.js b/inst/htmlwidgets/BioCircos.js index 914d5c2..3211ed5 100644 --- a/inst/htmlwidgets/BioCircos.js +++ b/inst/htmlwidgets/BioCircos.js @@ -451,7 +451,8 @@ HTMLWidgets.widget({ textSize : opts.genomeLabelTextSize, textColor : opts.genomeLabelTextColor, dx : opts.genomeLabelDx, - dy : opts.genomeLabelDy + dy : opts.genomeLabelDy, + rotation : opts.genomeLabelOrientation }, TEXTModuleDragEvent : opts.TEXTModuleDragEvent }); diff --git a/inst/htmlwidgets/lib/biocircos-1.1.2.js b/inst/htmlwidgets/lib/biocircos-1.1.2.js index 9b46204..d2eba15 100644 --- a/inst/htmlwidgets/lib/biocircos-1.1.2.js +++ b/inst/htmlwidgets/lib/biocircos-1.1.2.js @@ -628,7 +628,8 @@ var BioCircos; "textSize" : 15, "textColor" : "#000", "dx" : 0.028, - "dy" : "-0.55em" + "dy" : 15, + "rotation" : 0 } }; @@ -761,6 +762,7 @@ var BioCircos; self.genomeTextColor=self.settings.genomeLabel.textColor; self.genomeTextDx=self.settings.genomeLabel.dx; self.genomeTextDy=self.settings.genomeLabel.dy; + self.genomeTextRotation=self.settings.genomeLabel.rotation; var labeli= self.genomeLabel.length; var initGenome = new Object(); @@ -1164,12 +1166,17 @@ var BioCircos; .each( function(d,i) { d.angle = (d.startAngle + d.endAngle) / 2 - self.genomeTextDx; d.name = self.genomeLabel[i]; + d.rotation = self.genomeTextRotation; + d.dy = self.genomeTextDy; }) - .attr("dy",self.genomeTextDy) + .attr("text-anchor", "middle") // Rotate around horizontal center of text box + .attr("alignment-baseline", "middle") // Rotate around vertical center of text box + .attr("vertical-align", "middle") .attr("transform", function(d){ - return "rotate(" + ( d.angle * 180 / Math.PI ) + ")" + - "translate(0,"+ -1.0*(outerRadius+10) +")" + - ( ( d.angle > Math.PI*2 && d.angle < Math.PI*0 ) ? "rotate(180)" : ""); + return "rotate(" + (d.angle * 180 / Math.PI ) + ")" + + "translate(0,"+ -1.0*(outerRadius+10+d.dy) +")" + + ( ( d.angle > Math.PI*2 && d.angle < Math.PI*0 ) ? "rotate(180)" : "") + + "rotate(" + d.rotation +")"; }) .text(function(d){ return d.name; @@ -1206,7 +1213,7 @@ var BioCircos; ticks.append("text") .attr("x", 8) - .attr("dy", ".35em") + .attr("dy", "0.35em") .style("font-size", self.ticksTextSize) .style("fill", self.ticksTextColor) .attr("transform", function(d) { return d.angle > Math.PI ? "rotate(180)translate(-16)" : null; }) diff --git a/vignettes/BioCircos.Rmd b/vignettes/BioCircos.Rmd index 04fa4ab..6a8d610 100644 --- a/vignettes/BioCircos.Rmd +++ b/vignettes/BioCircos.Rmd @@ -7,7 +7,7 @@ output: vignette: > %\VignetteIndexEntry{BioCircos: Generating circular multi-track plots} %\VignetteEngine{knitr::rmarkdown} - \usepackage[utf8]{inputenc} + %\usepackage[utf8]{inputenc} date: "`r Sys.Date()`" author: "Loan Vulliard" ---