Permalink
Browse files

Added gitignore for mac

Added abbreviate option, defaulted to true
Refactored abbreviation logic into it's own method
  • Loading branch information...
1 parent b3ecaf3 commit c70925e599e4f465328ab5d746bcdede5e22fe9f @tommoor committed Aug 25, 2012
Showing with 24 additions and 14 deletions.
  1. +1 −0 .gitignore
  2. +1 −2 examples/index.html
  3. +22 −12 tinycon.js
View
@@ -0,0 +1 @@
+.DS_Store
View
@@ -8,8 +8,7 @@
(function(){
var count = 0;
setInterval(function(){
-
- if (++count > 99) count = 0;
+ ++count;
Tinycon.setBubble(count);
}, 1000);
View
@@ -21,7 +21,8 @@
font: '10px arial',
colour: '#ffffff',
background: '#F03D25',
- fallback: true
+ fallback: true,
+ abbreviate: true
};
var ua = (function () {
@@ -150,18 +151,10 @@
};
var drawBubble = function(context, label, colour) {
+
// automatic abbreviation for long (>2 digits) numbers
- if(typeof label == 'number' && label > 99) {
- var metricPrefixes = [
- ['G', 1000000000],
- ['M', 1000000],
- ['k', 1000]
- ];
- for(var i = 0; i < metricPrefixes.length; ++i)
- if(label >= metricPrefixes[i][1]) {
- label = round(label / metricPrefixes[i][1]) + metricPrefixes[i][0];
- break;
- }
+ if (typeof label == 'number' && label > 99 && options.abbreviate) {
+ label = abbreviateNumber(label);
}
// bubble needs to be larger for double digits
@@ -214,6 +207,23 @@
setFaviconTag(getCanvas().toDataURL());
};
+ var abbreviateNumber = function(label) {
+ var metricPrefixes = [
+ ['G', 1000000000],
+ ['M', 1000000],
+ ['k', 1000]
+ ];
+
+ for(var i = 0; i < metricPrefixes.length; ++i) {
+ if (label >= metricPrefixes[i][1]) {
+ label = round(label / metricPrefixes[i][1]) + metricPrefixes[i][0];
+ break;
+ }
+ }
+
+ return label;
+ };
+
var round = function (value, precision) {
var number = new Number(value);
return number.toFixed(precision);

0 comments on commit c70925e

Please sign in to comment.