SHARE
TWEET

Untitled

a guest Apr 22nd, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // figures out a good scope to use based on the data
  2. // this is pretty basic, but does an ok job
  3.  
  4. var data = [
  5.     { "label": "first", "value": 30 },
  6.     { "label": "second", "value": 86 },
  7.     { "label": "third", "value": 168 },
  8.     { "label": "fourth", "value": 281 },
  9.     { "label": "fifth", "value": 303 },
  10.     { "label": "sixth", "value": 365 },
  11. ];
  12.  
  13. var scope = 0;
  14. data.forEach(function(element) {
  15.     if (element.value > scope) {
  16.         scope = element.value;
  17.     }
  18. });
  19.  
  20. // factor = "1".padEnd((scope.toString().length), "0");
  21. // var temp = scope / factor;
  22. // var temp2 = Math.ceil(temp);
  23. // var temp3 = temp2 * "1".padEnd((scope.toString().length), "0");
  24. // console.log({ scope, factor, temp, temp2, temp3 });
  25.  
  26. // simplified version of above:          
  27. scope = (Math.ceil(scope / ("1".padEnd((scope.toString().length), "0")))) * "1".padEnd((scope.toString().length), "0");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top