Skip to content

Commit a01a3a2

Browse files
authored
Merge pull request #149 from z267xu/master
loonGrob size adjustment
2 parents 097a5f7 + e4191c7 commit a01a3a2

4 files changed

+76
-62
lines changed

R/R/as_r_size.R

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
as_r_polygon_size <- function(size){
2+
if (is.numeric(size)) {
3+
# trial and error to choose scale for size
4+
size <- (size/as.numeric(l_getOption("size")))^(1/2) * 2
5+
size[size < 0.5] <- 0.5
6+
size
7+
}
8+
size
9+
}
10+
11+
as_r_serialaxes_size <- function(size, coord, axesLayout){
12+
if (is.numeric(size)) {
13+
# trial and error to choose scale for size
14+
if (axesLayout == "radial") {
15+
size <- (size/as.numeric(l_getOption("size")))^(1/2) * 6
16+
} else if (axesLayout == "parallel") {
17+
if (coord == "x") {
18+
size <- (size/as.numeric(l_getOption("size")))^(1/2) * 8
19+
} else if (coord == "y") {
20+
size <- (size/as.numeric(l_getOption("size")))^(1/2) * 4
21+
} else size <- NA
22+
} else size <- NA
23+
size[size < 1] <- 1
24+
}
25+
size
26+
}
27+
28+
as_r_image_size <- function(size){
29+
if (is.numeric(size)) {
30+
# trial and error to choose scale for size
31+
size <- (size/as.numeric(l_getOption("size"))) /1.5
32+
size[size < 0.1] <- 0.1
33+
size
34+
}
35+
size
36+
}
37+
38+
# see optionDatabase.tcl
39+
as_r_point_size <- function(size) {
40+
41+
if (is.numeric(size)) {
42+
# trial and error to choose scale for size
43+
size <- sqrt(size / 12)
44+
size[size < 0.1] <- 0.1
45+
}
46+
size
47+
}
48+
49+
as_r_text_size <- function(size){
50+
if (is.numeric(size)) {
51+
# trial and error to choose scale for size
52+
size <- 1 + 1.2 * (1 + size)^0.88
53+
}
54+
size
55+
}

R/R/loonGrob.R

-20
Original file line numberDiff line numberDiff line change
@@ -926,26 +926,6 @@ glyph_to_pch <- function(glyph) {
926926

927927
}
928928

929-
930-
# see optionDatabase.tcl
931-
as_r_point_size <- function(size) {
932-
933-
if (is.numeric(size)) {
934-
# trial and error to choose scale for size
935-
size <- sqrt(size / 12)
936-
size[size < 0.1] <- 0.1
937-
}
938-
size
939-
}
940-
941-
as_r_text_size <- function(size){
942-
if (is.numeric(size)) {
943-
# trial and error to choose scale for size
944-
size <- 1 + 1.2 * (1 + size)^0.88
945-
}
946-
size
947-
}
948-
949929
pixels_2_lines <- function(x) {
950930
x / 20
951931
}

R/R/loonGrob_l_layer_scatterplot.R

+10-41
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ loonGlyphGrob.image <- function(widget, x, glyph_info) {
192192
tcl_img_i <- gh['images'][glyph_info$index]
193193
size_i <- glyph_info$size
194194

195-
196195
# get the scaled_image
197196
height <- as.numeric(tcl("image", "height", tcl_img_i))
198197
width <- as.numeric(tcl("image", "width", tcl_img_i))
@@ -211,10 +210,8 @@ loonGlyphGrob.image <- function(widget, x, glyph_info) {
211210

212211
tcl("image", "delete", scaled_img)
213212

214-
215-
216-
width_p = unit(image_w/40, "cm")
217-
height_p = unit(image_h/40, "cm")
213+
width_p <- unit(as_r_image_size(image_w), "mm")
214+
height_p <- unit(as_r_image_size(image_h), "mm")
218215

219216
gTree(
220217
children = gList(
@@ -274,9 +271,7 @@ loonGlyphGrob.pointrange <- function(widget, x, glyph_info) {
274271
gp = gpar(col = glyph_info$color,
275272
cex = as_r_point_size(glyph_info$size)),
276273
pch = if (showArea) 21 else 19,
277-
name = "point"
278-
279-
),
274+
name = "point"),
280275
linesGrob(x = rep(glyph_info$x, 2),
281276
y = unit(c(gh['ymin'][glyph_info$index],
282277
gh['ymax'][glyph_info$index]),
@@ -299,8 +294,8 @@ loonGlyphGrob.polygon <- function(widget, x, glyph_info) {
299294
color <- glyph_info$color
300295
size <- glyph_info$size
301296

302-
poly_x <- gh['x'][[glyph_info$index]] * as_r_polygonGlyph_size(size)
303-
poly_y <- - gh['y'][[glyph_info$index]] * as_r_polygonGlyph_size(size)
297+
poly_x <- gh['x'][[glyph_info$index]] * as_r_polygon_size(size)
298+
poly_y <- - gh['y'][[glyph_info$index]] * as_r_polygon_size(size)
304299

305300
x <- glyph_info$x
306301
y <- glyph_info$y
@@ -328,15 +323,7 @@ loonGlyphGrob.polygon <- function(widget, x, glyph_info) {
328323
}
329324
}
330325

331-
as_r_polygonGlyph_size <- function(size){
332-
if (is.numeric(size)) {
333-
# trial and error to choose scale for size
334-
size <- size/1.25
335-
size[size < 0.01] <- 0.01
336-
size
337-
}
338-
size
339-
}
326+
340327

341328
loonGlyphGrob.serialaxes <- function(widget, x, glyph_info) {
342329

@@ -372,8 +359,8 @@ loonGlyphGrob.serialaxes <- function(widget, x, glyph_info) {
372359
ypos <- glyph_info$y
373360

374361
if(axesLayout == "parallel"){
375-
scaleX <- as_r_serialaxesGlyph_size(size, "x", "parallel")
376-
scaleY <- as_r_serialaxesGlyph_size(size, "y", "parallel")
362+
scaleX <- as_r_serialaxes_size(size, "x", "parallel")
363+
scaleY <- as_r_serialaxes_size(size, "y", "parallel")
377364

378365
lineXaxis <- seq(-0.5 * scaleX, 0.5 * scaleX, length.out = dimension)
379366
lineYaxis <- (scaledData[glyph_info$index, ] - 0.5) * scaleY
@@ -418,8 +405,8 @@ loonGlyphGrob.serialaxes <- function(widget, x, glyph_info) {
418405
), name = paste0("serialaxes_glyph: parallel ", glyph_info$index)
419406
)
420407
} else {
421-
scaleX <- as_r_serialaxesGlyph_size(size, "x", "radial")
422-
scaleY <- as_r_serialaxesGlyph_size(size, "y", "radial")
408+
scaleX <- as_r_serialaxes_size(size, "x", "radial")
409+
scaleY <- as_r_serialaxes_size(size, "y", "radial")
423410

424411
angle <- seq(0, 2*pi, length.out = dimension + 1)[1:dimension]
425412
radialxaxis <- scaleX * scaledData[glyph_info$index,] * cos(angle)
@@ -541,21 +528,3 @@ get_glyph_scale_info <- function(widget){
541528
names(scaleInfo) <- paste(name, unique_glyph)
542529
scaleInfo
543530
}
544-
545-
546-
as_r_serialaxesGlyph_size <- function(size, coord, axesLayout){
547-
if (is.numeric(size)) {
548-
# trial and error to choose scale for size
549-
if (axesLayout == "radial") {
550-
size <- sqrt(size) * 5
551-
} else if (axesLayout == "parallel"){
552-
if (coord == "x") {
553-
size <- sqrt(size) * 6.4
554-
} else if (coord == "y"){
555-
size <- sqrt(size) * 3.2
556-
} else size <- NA
557-
} else size <- NA
558-
size[size == 0] <- 0.01
559-
}
560-
size
561-
}

R/R/loonGrob_l_serialaxes.R

+11-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,17 @@ axesGrobTree <- function(data = NULL,
417417
# returned by widget['data'] from characters to numeric.
418418
char2num.data.frame <- function(chardataframe){
419419

420-
dat <- as.data.frame(suppressWarnings(sapply(chardataframe, as.numeric)))
420+
if(nrow(chardataframe) == 1) {
421+
cols <- colnames(chardataframe)
422+
dat <- as.data.frame(
423+
matrix(suppressWarnings(sapply(chardataframe, as.numeric)),
424+
nrow = 1)
425+
)
426+
colnames(dat) <- cols
427+
} else {
428+
dat <- as.data.frame(suppressWarnings(sapply(chardataframe, as.numeric)))
429+
}
430+
421431
NAcolumn <- which(
422432
apply(dat, 2,
423433
function(column){

0 commit comments

Comments
 (0)