mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-07 03:00:20 -04:00
Round brush coordinates to 14 digits. Fixes #1634
This commit is contained in:
@@ -1119,6 +1119,9 @@ imageutils.createBrush = function($el, opts, coordmap, expandPixels) {
|
||||
// For reversed scales, the min and max can be reversed, so use findBox
|
||||
// to ensure correct order.
|
||||
state.boundsData = coordmap.findBox(minData, maxData);
|
||||
// Round to 14 significant digits to avoid spurious changes in FP values
|
||||
// (#1634).
|
||||
state.boundsData = mapValues(state.boundsData, val => roundSignif(val, 14));
|
||||
|
||||
// We also need to attach the data bounds and panel as data attributes, so
|
||||
// that if the image is re-sent, we can grab the data bounds to create a new
|
||||
|
||||
@@ -56,6 +56,17 @@ function padZeros(n, digits) {
|
||||
return str;
|
||||
}
|
||||
|
||||
// Round to a specified number of significant digits.
|
||||
function roundSignif(x, digits = 1) {
|
||||
if (digits < 1)
|
||||
throw "Significant digits must be at least 1.";
|
||||
|
||||
// This converts to a string and back to a number, which is inelegant, but
|
||||
// is less prone to FP rounding error than an alternate method which used
|
||||
// Math.round().
|
||||
return parseFloat(x.toPrecision(digits));
|
||||
}
|
||||
|
||||
// Take a string with format "YYYY-MM-DD" and return a Date object.
|
||||
// IE8 and QTWebKit don't support YYYY-MM-DD, but they support YYYY/MM/DD
|
||||
function parseDate(dateString) {
|
||||
|
||||
Reference in New Issue
Block a user