Comparing changes
Open a pull request
- 7 commits
- 5 files changed
- 0 comments
- 1 contributor
- Reset invalid values (out of range, decimal, nonsense) to 0 - Rewrite scientific notation to fixed notation
- +1 −1 DESCRIPTION
- +9 −2 CHANGELOG.md → NEWS.md
- +5 −8 R/input-time.R
- +1 −11 cran-comments.md
- +31 −1 inst/www/input_binding_time.js
| @@ -1,7 +1,7 @@ | ||
| Package: shinyTime | ||
| Type: Package | ||
| Title: A Time Input Widget for Shiny | ||
| Version: 0.2.0 | ||
| Version: 0.2.1 | ||
| Authors@R: person("Gerhard", "Burger", email = "burger.ga@gmail.com", role = c("aut", "cre")) | ||
| Description: Provides a time input widget for Shiny. This widget allows intuitive time input in the | ||
| '[hh]:[mm]:[ss]' or '[hh]:[mm]' (24H) format by using a separate numeric input for each time | ||
| @@ -5,6 +5,12 @@ Also [Keep a CHANGELOG](http://keepachangelog.com/). | ||
|
|
||
| ## [Unreleased] | ||
|
|
||
| ## [0.2.1] - 2016-10-07 | ||
| ### Added | ||
| - Updated style to match other shiny inputs | ||
| - Added input validation so that the time returned is always a valid | ||
| time (invalid values are set to 0) | ||
|
|
||
| ## [0.2.0] - 2016-07-20 | ||
| ### Added | ||
| - Support for input in the %H:%M format (without seconds) | ||
| @@ -17,5 +23,6 @@ Also [Keep a CHANGELOG](http://keepachangelog.com/). | ||
| ### Added | ||
| - Initial release | ||
|
|
||
| [Unreleased]: https://github.com/burgerga/shinyTime/compare/v0.2.0...HEAD | ||
| [0.2.0]: https://github.com/burgerga/shinyTime/compare/v0.1.0...v0.2.0 | ||
| [Unreleased]: https://github.com/burgerga/shinyTime/compare/v0.2.0...HEAD | ||
| [0.2.0]: https://github.com/burgerga/shinyTime/compare/v0.1.0...v0.2.0 | ||
| [0.2.1]: https://github.com/burgerga/shinyTime/compare/v0.2.0...v0.2.1 | ||
| @@ -49,8 +49,8 @@ NULL | ||
| timeInput <- function(inputId, label, value = NULL, seconds = TRUE) { | ||
| if(is.null(value)) value <- getDefaultTime() | ||
| value_list <- parseTimeFromValue(value) | ||
| style <- "width: 5ch" | ||
| onchange <- "var value = (+this.value); this.value = value < 10 ? '0' + value: value;" | ||
| style <- "width: 8ch" | ||
| input.class <- "form-control" | ||
| tagList( | ||
| singleton(tags$head( | ||
| tags$script(src = "shinyTime/input_binding_time.js") | ||
| @@ -59,14 +59,11 @@ timeInput <- function(inputId, label, value = NULL, seconds = TRUE) { | ||
| controlLabel(inputId, label), | ||
| tags$div(class = "input-group", | ||
| tags$input(type="number", min="0", max="23", step="1", value = value_list$hour, | ||
| style = style, onchange = onchange), | ||
| tags$b(":"), | ||
| style = style, class = paste(c(input.class, 'shinytime-hours'), collapse = " ")), | ||
| tags$input(type="number", min="0", max="59", step="1", value = value_list$min, | ||
| style = style, onchange = onchange), | ||
|
|
||
| if(seconds) tags$b(":") else NULL, | ||
| style = style, class = paste(c(input.class, 'shinytime-mins'), collapse = " ")), | ||
| if(seconds) tags$input(type="number", min="0", max="59", step="1", value = value_list$sec, | ||
| style = style, onchange = onchange) else NULL | ||
| style = style, class = paste(c(input.class, 'shinytime-secs'), collapse = " ")) else NULL | ||
| ) | ||
| ) | ||
| ) | ||
| @@ -1,17 +1,7 @@ | ||
| ## Test environments | ||
| * Local Ubuntu 16.04, R 3.3.1 | ||
| * travis-ci, Ubuntu 12.04, R 3.3.1 | ||
| * win-builder (devel and release) | ||
|
|
||
| ## R CMD check results | ||
| There were no ERRORs or WARNINGs. | ||
|
|
||
| There was 1 NOTE: | ||
|
|
||
| * checking CRAN incoming feasibility ... NOTE | ||
| Maintainer: ‘Gerhard Burger <burger.ga@gmail.com>’ | ||
|
|
||
| Days since last update: 1 | ||
|
|
||
| Terribly sorry, the package turned out to have a usability bug | ||
| There were no ERRORs, NOTEs or WARNINGs. | ||
|
|
| @@ -1,4 +1,5 @@ | ||
|
|
||
| // Enclose in IEFE | ||
| (function() { | ||
| // Escape jQuery selector metacharacters: !"#$%&'()*+,./:;<=>?@[\]^`{|}~ | ||
| // Copied from shiny/srcjs/utils.js | ||
| var $escape = function(val) { | ||
| @@ -9,6 +10,33 @@ var findLabelForElement = function(el) { | ||
| return($(el).parent().find('label[for="' + $escape(el.id) + '"]')); | ||
| }; | ||
|
|
||
| var clamp = function(num, min, max) { | ||
| return Math.min(Math.max(num, min), max); | ||
| }; | ||
|
|
||
| var inRange = function(num, min, max) { | ||
| return (num >= min && num <= max); | ||
| }; | ||
|
|
||
| var zeroPad = function(num) { | ||
| return (num < 10 ? '0' + num: num); | ||
| }; | ||
|
|
||
| var correctInputValue = function(el) { | ||
| var $el = $(el); | ||
| var val = parseFloat($el.val()); | ||
| // Check if number is integer, if so put to fixed form (0.1e1 will become 1), else make 0 | ||
| var newVal = (val % 1 == 0) ? val.toFixed() : 0; | ||
| // Make 0 if out of range, alternative would be clamping. | ||
| if($el.hasClass('shinytime-hours')) { | ||
| newVal = inRange(newVal, 0, 23) ? newVal : 0; | ||
| } else { | ||
| newVal = inRange(newVal, 0, 59) ? newVal : 0; | ||
| } | ||
| // Zero pad and update value | ||
| $el.val(zeroPad(newVal)); | ||
| }; | ||
|
|
||
| var timeInputBinding = new Shiny.InputBinding(); | ||
|
|
||
| $.extend(timeInputBinding, { | ||
| @@ -58,6 +86,7 @@ $.extend(timeInputBinding, { | ||
| }, | ||
| subscribe: function(el, callback) { | ||
| $(el).on("change.timeInputBinding", function(e) { | ||
| correctInputValue(e.target); | ||
| callback(); | ||
| }); | ||
| }, | ||
| @@ -67,3 +96,4 @@ $.extend(timeInputBinding, { | ||
| }); | ||
|
|
||
| Shiny.inputBindings.register(timeInputBinding, 'my.shiny.timeInput'); | ||
| })(); | ||