Skip to content

Commit 71c77e0

Browse files
gogonzoasbates
andauthored
Style2@174 checkbox counts@filter panel refactor@main (#199)
thanks @asbates --------- Co-authored-by: Andrew Bates <andrew.bates@atorusresearch.com>
1 parent f67175d commit 71c77e0

File tree

10 files changed

+133
-264
lines changed

10 files changed

+133
-264
lines changed

R/FilterState.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,13 @@ FilterState <- R6::R6Class( # nolint
535535
uiOutput(ns("empty"), inline = TRUE),
536536
checkboxInput(
537537
inputId = ns("value"),
538-
label = countLabel(
539-
inputId = ns("count_label"),
540-
label = "Keep NA",
541-
countmax = countmax,
542-
countnow = countnow
538+
label = tags$span(
539+
id = ns("count_label"),
540+
make_count_text(
541+
label = "Keep NA",
542+
countmax = countmax,
543+
countnow = countnow
544+
)
543545
),
544546
value = isolate(self$get_keep_na())
545547
)
@@ -561,7 +563,7 @@ FilterState <- R6::R6Class( # nolint
561563
# and if the reactive changes - reactive triggers only if the output is visible.
562564
# 2. We want to trigger change of the labels only if reactive count changes (not underlying data)
563565
output$empty <- renderUI({
564-
updateCountLabel(
566+
updateCountText(
565567
inputId = "count_label",
566568
label = "Keep NA",
567569
countmax = private$na_count,

R/FilterStateChoices.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ ChoicesFilterState <- R6::R6Class( # nolint
205205
countsnow <- isolate(unname(table(factor(private$x_reactive(), levels = private$choices))))
206206

207207
ui_input <- if (private$is_checkboxgroup()) {
208-
labels <- countBarLabels(
208+
labels <- countBars(
209209
inputId = ns("labels"),
210210
choices = as.character(private$choices),
211211
countsnow = countsnow,
@@ -271,7 +271,7 @@ ChoicesFilterState <- R6::R6Class( # nolint
271271
private$dataname
272272
))
273273
if (private$is_checkboxgroup()) {
274-
updateCountBarLabels(
274+
updateCountBars(
275275
inputId = "labels",
276276
choices = as.character(private$choices),
277277
countsmax = as.numeric(names(private$choices)),

R/FilterStateLogical.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ LogicalFilterState <- R6::R6Class( # nolint
179179
countsmax <- as.numeric(names(private$choices))
180180
countsnow <- isolate(unname(table(factor(private$x_reactive(), levels = private$choices))))
181181

182-
labels <- countBarLabels(
182+
labels <- countBars(
183183
inputId = ns("labels"),
184184
choices = as.character(private$choices),
185185
countsnow = countsnow,
@@ -222,7 +222,7 @@ LogicalFilterState <- R6::R6Class( # nolint
222222
private$varname,
223223
private$dataname
224224
))
225-
updateCountBarLabels(
225+
updateCountBars(
226226
inputId = "labels",
227227
choices = as.character(private$choices),
228228
countsmax = as.numeric(names(private$choices)),

R/FilterStateRange.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,13 @@ RangeFilterState <- R6::R6Class( # nolint
434434
uiOutput(ns("empty"), inline = TRUE),
435435
checkboxInput(
436436
inputId = ns("value"),
437-
label = countLabel(
438-
inputId = ns("count_label"),
439-
label = "Keep Inf",
440-
countmax = countmax,
441-
countnow = countnow
437+
label = tags$span(
438+
id = ns("count_label"),
439+
make_count_text(
440+
label = "Keep Inf",
441+
countmax = countmax,
442+
countnow = countnow
443+
)
442444
),
443445
value = isolate(self$get_keep_inf())
444446
)
@@ -461,7 +463,7 @@ RangeFilterState <- R6::R6Class( # nolint
461463
# and if the reactive changes - reactive triggers only if the output is visible.
462464
# 2. We want to trigger change of the labels only if reactive count changes (not underlying data)
463465
output$empty <- renderUI({
464-
updateCountLabel(
466+
updateCountText(
465467
inputId = "count_label",
466468
label = "Keep Inf",
467469
countmax = private$inf_count,

R/count_labels.R

Lines changed: 28 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#'
2020
#' choices <- sample(as.factor(c("a", "b", "c")), size = 20, replace = TRUE)
2121
#' counts <- table(choices)
22-
#' labels <- countBarLabels(
22+
#' labels <- countBars(
2323
#' inputId = "counts",
2424
#' choices = c("a", "b", "c"),
2525
#' countsmax = c(20, 20, 20),
@@ -46,7 +46,7 @@
4646
#' new_counts <- counts
4747
#' new_counts[!names(new_counts) %in% input$choices] <- 0
4848
#'
49-
#' updateCountBarLabels(
49+
#' updateCountBars(
5050
#' inputId = "counts",
5151
#' choices = levels(choices),
5252
#' countsmax = c(20, 20, 20),
@@ -56,7 +56,7 @@
5656
#' }
5757
#' )
5858
#' @keywords internal
59-
countBarLabels <- function(inputId, choices, countsmax, countsnow = NULL) {
59+
countBars <- function(inputId, choices, countsmax, countsnow = NULL) {
6060
checkmate::assert_string(inputId)
6161
checkmate::assert_vector(choices)
6262
checkmate::assert_numeric(countsmax, len = length(choices))
@@ -73,7 +73,7 @@ countBarLabels <- function(inputId, choices, countsmax, countsnow = NULL) {
7373
countmax <- countsmax[i]
7474
countnow <- if (is.null(countsnow)) 0 else countsnow[i]
7575

76-
countBarLabel(
76+
countBar(
7777
inputId = ns(i),
7878
label = choice,
7979
countmax = countmax,
@@ -96,27 +96,14 @@ countBarLabels <- function(inputId, choices, countsmax, countsnow = NULL) {
9696
#' determines `<style="width: <countmax / counttotal>%""`.
9797
#' @return `shiny.tag` object with a progress bar and a label.
9898
#' @keywords internal
99-
countBarLabel <- function(inputId, label, countmax, countnow = NULL, counttotal = countmax) {
99+
countBar <- function(inputId, label, countmax, countnow = NULL, counttotal = countmax) {
100100
checkmate::assert_string(inputId)
101101
checkmate::assert_string(label)
102102
checkmate::assert_number(countmax)
103103
checkmate::assert_number(countnow, null.ok = TRUE, upper = countmax)
104104
checkmate::assert_number(counttotal, lower = countmax)
105105

106-
107-
label_html <- countLabel(inputId = inputId, label = label, countmax = countmax, countnow = countnow)
108-
progress_html <- countBar(inputId = inputId, countmax = countmax, countnow = countnow, counttotal = counttotal)
109-
tags$div(progress_html, label_html)
110-
}
111-
112-
113-
#' @rdname countBarLabel
114-
countBar <- function(inputId, countmax, countnow = NULL, counttotal) {
115-
checkmate::assert_string(inputId)
116-
checkmate::assert_number(countmax)
117-
checkmate::assert_number(countnow, null.ok = TRUE)
118-
checkmate::assert_number(counttotal)
119-
106+
label <- make_count_text(label, countmax = countmax, countnow = countnow)
120107
ns <- NS(inputId)
121108
tags$div(
122109
class = "progress state-count-container",
@@ -125,7 +112,8 @@ countBar <- function(inputId, countmax, countnow = NULL, counttotal) {
125112
id = ns("count_bar_filtered"),
126113
class = "progress-bar state-count-bar-filtered",
127114
style = sprintf("width: %s%%", countnow / counttotal * 100),
128-
role = "progressbar"
115+
role = "progressbar",
116+
label
129117
),
130118
tags$div(
131119
id = ns("count_bar_unfiltered"),
@@ -136,20 +124,8 @@ countBar <- function(inputId, countmax, countnow = NULL, counttotal) {
136124
)
137125
}
138126

139-
#' @rdname countBarLabel
140-
countLabel <- function(inputId, label, countmax, countnow = NULL) {
141-
checkmate::assert_string(inputId)
142-
checkmate::assert_string(label)
143-
checkmate::assert_number(countmax)
144-
checkmate::assert_number(countnow, null.ok = TRUE)
145-
146-
ns <- NS(inputId)
147-
label <- make_count_text(label = label, countmax = countmax, countnow = countnow)
148-
label_html <- tags$div(id = ns("count_text"), class = "state-count-text", label)
149-
}
150-
151-
#' @rdname countBarLabels
152-
updateCountBarLabels <- function(session = getDefaultReactiveDomain(), inputId, choices,
127+
#' @rdname countBars
128+
updateCountBars <- function(session = getDefaultReactiveDomain(), inputId, choices,
153129
countsmax, countsnow = NULL) {
154130
checkmate::assert_string(inputId)
155131
checkmate::assert_vector(choices)
@@ -162,14 +138,9 @@ updateCountBarLabels <- function(session = getDefaultReactiveDomain(), inputId,
162138
choice <- choices[i]
163139
countmax <- countsmax[i]
164140
countnow <- if (is.null(countsnow)) countmax else countsnow[i]
165-
updateCountLabel(
166-
inputId = ns(i),
167-
label = choice,
168-
countmax = countmax,
169-
countnow = countnow
170-
)
171141
updateCountBar(
172142
inputId = ns(i),
143+
label = choice,
173144
countmax = countmax,
174145
countnow = countnow,
175146
counttotal = counttotal
@@ -178,61 +149,46 @@ updateCountBarLabels <- function(session = getDefaultReactiveDomain(), inputId,
178149
invisible(NULL)
179150
}
180151

181-
#' @rdname countBarLabel
182-
updateCountBarLabel <- function(session = getDefaultReactiveDomain(), inputId, label,
152+
#' @rdname countBar
153+
updateCountBar <- function(session = getDefaultReactiveDomain(), inputId, label,
183154
countmax, countnow = NULL, counttotal) {
184155
checkmate::assert_string(inputId)
185156
checkmate::assert_string(label)
186157
checkmate::assert_number(countmax)
187158
checkmate::assert_number(countnow, null.ok = TRUE)
188159
checkmate::assert_number(counttotal)
189160

190-
label <- make_count_label(label, countmax = countmax, countnow = countnow)
191161
if (is.null(countnow)) countnow <- countmax
192-
193-
updateCountLabel(inputId = inputId, label = label, countmax = countmax, countnow = countnow)
194-
updateCountBar(inputId = inputId, countmax = countmax, countnow = countnow, counttotal = counttotal)
195-
196-
invisible(NULL)
197-
}
198-
199-
#' @rdname countBarLabel
200-
updateCountLabel <- function(session = getDefaultReactiveDomain(), inputId, label, countmax, countnow) {
201-
checkmate::assert_string(inputId)
202-
checkmate::assert_string(label)
203-
checkmate::assert_number(countmax)
204-
checkmate::assert_number(countnow, null.ok = TRUE)
205-
206-
label <- make_count_text(label = label, countmax = countmax, countnow = countnow)
207-
162+
label <- make_count_text(label, countmax = countmax, countnow = countnow)
208163
session$sendCustomMessage(
209-
type = "updateCountLabel",
164+
type = "updateCountBar",
210165
message = list(
211166
id = session$ns(inputId),
212-
label = label
167+
label = label,
168+
countmax = countmax,
169+
countnow = countnow,
170+
counttotal = counttotal
213171
)
214172
)
173+
174+
invisible(NULL)
215175
}
216176

217-
#' @rdname countBarLabel
218-
updateCountBar <- function(session = getDefaultReactiveDomain(), inputId, countmax, countnow, counttotal) {
177+
updateCountText <- function(session = getDefaultReactiveDomain(), inputId, label, countmax, countnow) {
219178
checkmate::assert_string(inputId)
179+
checkmate::assert_string(label)
220180
checkmate::assert_number(countmax)
221181
checkmate::assert_number(countnow, null.ok = TRUE)
222-
checkmate::assert_number(counttotal)
223-
182+
label <- make_count_text(label, countmax = countmax, countnow = countnow)
224183
session$sendCustomMessage(
225-
type = "updateCountBar",
184+
type = "updateCountText",
226185
message = list(
227186
id = session$ns(inputId),
228-
countmax = countmax,
229-
countnow = countnow,
230-
counttotal = counttotal
187+
label = label
188+
)
231189
)
232-
)
233190
}
234191

235-
236192
#' Make a count text
237193
#'
238194
#' Returns a text describing filtered counts. Text is composed in following way:
@@ -253,4 +209,4 @@ make_count_text <- function(label, countmax, countnow = NULL) {
253209
if (is.null(countnow)) "" else sprintf("%s/", countnow),
254210
countmax
255211
)
256-
}
212+
}

inst/css/filter-panel.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ a.remove_all:hover {
255255
.state-count-container {
256256
height: 1.75em;
257257
width: 90%;
258-
position: absolute;
259258
background-color: white;
259+
margin: 0px;
260260
}
261261

262262
.state-count-bar-filtered {
@@ -271,3 +271,10 @@ a.remove_all:hover {
271271
position: absolute;
272272
width: 100%;
273273
}
274+
275+
.progress-bar.state-count-bar-filtered {
276+
color: var(--bs-body-color, var(--dark, #333333));
277+
overflow: visible;
278+
text-align: left;
279+
white-space: nowrap;
280+
}

inst/js/count-bar-labels.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ Shiny.addCustomMessageHandler("updateCountBar",
66

77
bar1.style.width = message.countnow / message.counttotal * 100 + "%";
88
bar2.style.width = (message.countmax - message.countnow) / message.counttotal * 100 + "%";
9+
bar1.textContent = message.label;
910
}
1011
);
1112

12-
Shiny.addCustomMessageHandler("updateCountLabel",
13+
Shiny.addCustomMessageHandler("updateCountText",
1314
function(message) {
14-
/* updates Text */
15-
let e1 = document.getElementById(message.id + "-count_text");
16-
e1.textContent = message.label;
15+
let el = document.getElementById(message.id)
16+
el.textContent = message.label
1717
}
1818
);

man/countBarLabel.Rd

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/countBarLabels.Rd

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)