Skip to content

Commit

Permalink
Merge pull request #429 from VEuPathDB/bubble-legend-rounding-fix
Browse files Browse the repository at this point in the history
Change rounding algorithm in bubble size legend
  • Loading branch information
bobular authored Aug 25, 2023
2 parents 1d13ea4 + 73ee18a commit c1a52d0
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ export default function PlotBubbleLegend({
// The largest circle's value will be the first number that's larger than
// legendMax and has only one significant digit. Each smaller circle will
// be half the size of the last (rounded and >= 1)
const legendMaxLog10 = Math.floor(Math.log10(legendMax));
const roundedOneSigFig = Number(legendMax.toPrecision(1));
const largestCircleValue =
legendMax <= 10
? legendMax
: (Number(legendMax.toPrecision(1)[0]) + 1) * 10 ** legendMaxLog10;
: roundedOneSigFig < legendMax
? roundedOneSigFig + 10 ** Math.floor(Math.log10(legendMax)) // effectively rounding up
: roundedOneSigFig; // no need to adjust - already rounded up
const circleValues = _.uniq(
range(numCircles)
.map((i) => Math.round(largestCircleValue / 2 ** i))
Expand Down

0 comments on commit c1a52d0

Please sign in to comment.