Skip to content

Commit

Permalink
simplify noExponent function
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Dec 18, 2024
1 parent 17a15aa commit 97ed0dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/charts/common/bar/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class Helpers {

x =
w.globals.padHorizontal +
(xDivision - barWidth * this.barCtx.seriesLen) / 2
Utils.noExponents(xDivision - barWidth * this.barCtx.seriesLen) / 2
}

w.globals.barHeight = barHeight
Expand Down
21 changes: 5 additions & 16 deletions src/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,12 @@ class Utils {
return (Math.random() + 1).toString(36).substring(4)
}

static noExponents(val) {
let data = String(val).split(/[eE]/)
if (data.length === 1) return data[0]

let z = '',
sign = val < 0 ? '-' : '',
str = data[0].replace('.', ''),
mag = Number(data[1]) + 1

if (mag < 0) {
z = sign + '0.'
while (mag++) z += '0'
return z + str.replace(/^-/, '')
static noExponents(num) {
// Check if the number contains 'e' (exponential notation)
if (num.toString().includes('e')) {
return Math.round(num) // Round the number
}
mag -= str.length
while (mag--) z += '0'
return str + z
return num // Return as-is if no exponential notation
}

static elementExists(element) {
Expand Down

0 comments on commit 97ed0dc

Please sign in to comment.