Skip to content

Commit 9804a79

Browse files
authored
Merge pull request rstudio#1641 from rstudio/fix-plot-rounding
Round brush coordinates
2 parents 2e80ecf + 0344645 commit 9804a79

File tree

7 files changed

+38
-5
lines changed

7 files changed

+38
-5
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ in shiny apps. For more info, see the documentation (`?updateQueryString` and `?
6262

6363
* Fixed [#1621](https://github.com/rstudio/shiny/issues/1621): if a `reactiveTimer`'s session was closed before the first time that the `reactiveTimer` fired, then the `reactiveTimer` would not get cleared and would keep firing indefinitely. ([#1623](https://github.com/rstudio/shiny/pull/1623))
6464

65+
* Fixed [#1634](https://github.com/rstudio/shiny/issues/1634): If brushing on a plot causes the plot to redraw, then the redraw could in turn trigger the plot to redraw again and again. This was due to spurious changes in values of floating point numbers. ([#1641](https://github.com/rstudio/shiny/pull/1641))
66+
6567
### Library updates
6668

6769
* Closed [#1500](https://github.com/rstudio/shiny/issues/1500): Updated ion.rangeSlider to 2.1.6. ([#1540](https://github.com/rstudio/shiny/pull/1540))

inst/www/shared/shiny.js

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

inst/www/shared/shiny.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.min.js

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

inst/www/shared/shiny.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

srcjs/output_binding_image.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,9 @@ imageutils.createBrush = function($el, opts, coordmap, expandPixels) {
11191119
// For reversed scales, the min and max can be reversed, so use findBox
11201120
// to ensure correct order.
11211121
state.boundsData = coordmap.findBox(minData, maxData);
1122+
// Round to 14 significant digits to avoid spurious changes in FP values
1123+
// (#1634).
1124+
state.boundsData = mapValues(state.boundsData, val => roundSignif(val, 14));
11221125

11231126
// We also need to attach the data bounds and panel as data attributes, so
11241127
// that if the image is re-sent, we can grab the data bounds to create a new

srcjs/utils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ function padZeros(n, digits) {
5656
return str;
5757
}
5858

59+
// Round to a specified number of significant digits.
60+
function roundSignif(x, digits = 1) {
61+
if (digits < 1)
62+
throw "Significant digits must be at least 1.";
63+
64+
// This converts to a string and back to a number, which is inelegant, but
65+
// is less prone to FP rounding error than an alternate method which used
66+
// Math.round().
67+
return parseFloat(x.toPrecision(digits));
68+
}
69+
5970
// Take a string with format "YYYY-MM-DD" and return a Date object.
6071
// IE8 and QTWebKit don't support YYYY-MM-DD, but they support YYYY/MM/DD
6172
function parseDate(dateString) {

0 commit comments

Comments
 (0)