Skip to content

Commit

Permalink
added HCL image again, todo: fix selected colors in matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Oct 2, 2024
1 parent 3e7146f commit b88028c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
3 changes: 2 additions & 1 deletion R/c4a_gui.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ c4a_gui = function(type = "cat", n = NA, series = "all") {
shiny::fluidRow(
shiny::column(width = 4,
infoBoxUI(title = "HCL space"),
shiny::img(src = "imgResources/hcl_spacex1.png", srcset = "imgResources/hcl_spacex1.png 1x, imgResources/hcl_spacex2.png 2x"),
shiny::sliderInput("rangeH", min = 0, max = 360, value = c(0, 360), step = 10, label = "Hue"),
shiny::sliderInput("rangeC", min = 0, max = 180, value = c(0, 180), step = 10, label = "Chroma"),
shiny::sliderInput("rangeL", min = 0, max = 100, value = c(0, 100), step = 10, label = "Luminance"),
Expand Down Expand Up @@ -661,7 +662,7 @@ c4a_gui = function(type = "cat", n = NA, series = "all") {
filters_type = if (type == "cat") {
filters
} else if (type %in% c("seq", "div", "cyc", "bivc", "bivs", "bivd", "bivg")) {
filters[c(1, 2, 4, 5)]
filters[c(1, 2, 3, 4, 5)]
}


Expand Down
4 changes: 2 additions & 2 deletions R/c4a_cl_plot.R → R/c4a_plot_CL.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ c4a_plot_CL = function(cols, Lrange = FALSE, dark = FALSE) {

grid::pushViewport(grid::viewport(width = grid::unit(1, "snpc"), height = grid::unit(1, "snpc"), clip = TRUE))
grid::pushViewport(grid::viewport(layout = grid::grid.layout(3, 3,
widths = grid::unit(c(2,1,2), c("lines", "null", "lines")),
heights = grid::unit(c(2,1,2), c("lines", "null", "lines")))))
widths = grid::unit(c(2.5,1,1), c("lines", "null", "lines")),
heights = grid::unit(c(1,1,2.5), c("lines", "null", "lines")))))

sq = 2
marg = 1.5
Expand Down
50 changes: 31 additions & 19 deletions R/c4a_plot_fair.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ get_fairness = function(dL, dC, round = TRUE) {
}


c4a_plot_fair = function(pal, type = c("LC", "C"), dark = FALSE, contours = seq(10, 90, by = 10)) {
c4a_plot_fair = function(pal = NULL, type = c("LC", "C"), dark = FALSE, contours = seq(10, 90, by = 10)) {
grid::grid.newpage()

type = match.arg(type)
Expand All @@ -48,11 +48,13 @@ c4a_plot_fair = function(pal, type = c("LC", "C"), dark = FALSE, contours = seq(
grid::grid.rect(gp=grid::gpar(fill = bc, col = NA))
grid::pushViewport(grid::viewport(width = grid::unit(1, "snpc"), height = grid::unit(1, "snpc"), clip = TRUE))
grid::pushViewport(grid::viewport(layout = grid::grid.layout(3, 3,
widths = grid::unit(c(2,1,2), c("lines", "null", "lines")),
heights = grid::unit(c(2,1,2), c("lines", "null", "lines")))))
widths = grid::unit(c(2.5,1,1), c("lines", "null", "lines")),
heights = grid::unit(c(1,1,2.5), c("lines", "null", "lines")))))

hcl = get_hcl_matrix(pal)
cr = diff(range(hcl[,2]))
if (!is.null(pal)) {
hcl = get_hcl_matrix(pal)
cr = diff(range(hcl[,2]))
}

if (type == "LC") {
dL = seq(0,100, by = 1)[2:100]
Expand All @@ -76,14 +78,18 @@ c4a_plot_fair = function(pal, type = c("LC", "C"), dark = FALSE, contours = seq(
sq = 2
marg = 1.5

lr = diff(range(hcl[,3]))
LC = get_fairness(lr, cr)
if (!is.null(pal)) {
lr = diff(range(hcl[,3]))
LC = get_fairness(lr, cr)
}
} else {
sq = 2
marg = 1.5
dC = seq(0,160, by = .1)
Fs = get_fairness(0, dC, round = FALSE)
LC = get_fairness(0, cr)
if (!is.null(pal)) {
LC = get_fairness(0, cr)
}
}


Expand All @@ -109,20 +115,23 @@ c4a_plot_fair = function(pal, type = c("LC", "C"), dark = FALSE, contours = seq(
#
# grid::grid.text(contours, x = grid::unit(dC[contourTextIds], "native"), y= grid::unit(dL[contourTextIds], "native"))

if (!is.null(pal)) {
if (cr < marg*1.8) cr = marg*1.8
if (lr < marg) lr = marg

if (cr < marg*1.8) cr = marg*1.8
if (lr < marg) lr = marg

cr2 = cr + c(-marg, marg) * 1.8
lr2 = lr + c(-marg, marg)
cr2 = cr + c(-marg, marg) * 1.8
lr2 = lr + c(-marg, marg)
}



#grid::grid.points(m[,2], m[,3], pch = 15, gp = grid::gpar(col = cols))
grid::grid.rect(grid::unit(cr, "native"), grid::unit(lr, "native"), width = grid::unit(sq * 1.8, "native"), height = grid::unit(sq, "native"), gp = grid::gpar(col = bc, fill = fc))
if (!is.null(pal)) {
grid::grid.rect(grid::unit(cr, "native"), grid::unit(lr, "native"), width = grid::unit(sq * 1.8, "native"), height = grid::unit(sq, "native"), gp = grid::gpar(col = bc, fill = fc))

grid::grid.rect(x = grid::unit(cr, "native") + grid::unit(0.75, "lines"), y = grid::unit(lr, "native"), width = grid::unit(1, "lines"), height = grid::unit(1, "lines"), gp = grid::gpar(col = NA, fill = gc), just = "left")
grid::grid.text(round(LC), x = grid::unit(cr, "native") + grid::unit(0.75, "lines"), y = grid::unit(lr, "native"), gp = grid::gpar(col = fc), just = "left")
grid::grid.rect(x = grid::unit(cr, "native") + grid::unit(0.75, "lines"), y = grid::unit(lr, "native"), width = grid::unit(1, "lines"), height = grid::unit(1, "lines"), gp = grid::gpar(col = NA, fill = gc), just = "left")
grid::grid.text(round(LC), x = grid::unit(cr, "native") + grid::unit(0.75, "lines"), y = grid::unit(lr, "native"), gp = grid::gpar(col = fc), just = "left")
}
}, yscale = c(0,100), xscale = c(0,180))

cellplot(2, 1, {
Expand All @@ -149,10 +158,13 @@ c4a_plot_fair = function(pal, type = c("LC", "C"), dark = FALSE, contours = seq(
grid::grid.polyline(x = grid::unit(dC, "native"), y = grid::unit(Fs, "native"))

#grid::grid.points(m[,2], m[,3], pch = 15, gp = grid::gpar(col = cols))
grid::grid.rect(grid::unit(cr, "native"), grid::unit(LC, "native"), width = grid::unit(sq * 1.8, "native"), height = grid::unit(sq, "native"), gp = grid::gpar(col = bc, fill = fc))
if (!is.null(pal)) {
grid::grid.rect(grid::unit(cr, "native"), grid::unit(LC, "native"), width = grid::unit(sq * 1.8, "native"), height = grid::unit(sq, "native"), gp = grid::gpar(col = bc, fill = fc))

grid::grid.rect(x = grid::unit(cr, "native") + grid::unit(0.75, "lines"), y = grid::unit(LC, "native"), width = grid::unit(1, "lines"), height = grid::unit(1, "lines"), gp = grid::gpar(col = NA, fill = gc), just = "left")
grid::grid.text(round(LC), x = grid::unit(cr, "native") + grid::unit(0.75, "lines"), y = grid::unit(LC, "native"), gp = grid::gpar(col = fc), just = "left") }


grid::grid.rect(x = grid::unit(cr, "native") + grid::unit(0.75, "lines"), y = grid::unit(LC, "native"), width = grid::unit(1, "lines"), height = grid::unit(1, "lines"), gp = grid::gpar(col = NA, fill = gc), just = "left")
grid::grid.text(round(LC), x = grid::unit(cr, "native") + grid::unit(0.75, "lines"), y = grid::unit(LC, "native"), gp = grid::gpar(col = fc), just = "left")
}, yscale = c(0,100), xscale = c(0,180))

cellplot(2, 1, {
Expand Down

0 comments on commit b88028c

Please sign in to comment.