format numbers

This commit is contained in:
2020-06-08 16:30:37 +02:00
parent 4a7a60f5d2
commit 3118566710
3 changed files with 30 additions and 1 deletions

View File

@@ -49,7 +49,8 @@ var graph = new Chart(
ticks: { ticks: {
callback: function(value, index, values) { callback: function(value, index, values) {
return formatDataVolume(value, 3); return formatDataVolume(value, 3);
} },
beginAtZero: true
}, },
gridLines: { gridLines: {
color: "rgba(100, 255, 100, .05)" color: "rgba(100, 255, 100, .05)"
@@ -63,6 +64,12 @@ var graph = new Chart(
display: true, display: true,
labelString: "Views" labelString: "Views"
}, },
ticks: {
callback: function(value, index, values) {
return formatNumber(value, 3);
},
beginAtZero: true
},
gridLines: { gridLines: {
color: "rgba(128, 128, 255, .05)" color: "rgba(128, 128, 255, .05)"
} }

View File

@@ -57,6 +57,16 @@ function domainURL() {
return url; return url;
} }
function formatNumber(amt, precision) {
if (precision < 3) { precision = 3; }
if (amt >= 1e6) {
return (amt/1e6).toPrecision(precision) + "M";
} else if (amt >= 1e3) {
return (amt/1e3).toPrecision(precision) + "k";
}
return amt
}
function formatDataVolume(amt, precision) { function formatDataVolume(amt, precision) {
if (precision < 3) { precision = 3; } if (precision < 3) { precision = 3; }
if (amt >= 1e12) { if (amt >= 1e12) {

View File

@@ -124,6 +124,12 @@ DetailsWindow.prototype.renderGraph = function() {
display: true, display: true,
labelString: "Downloads" labelString: "Downloads"
}, },
ticks: {
callback: function(value, index, values) {
return formatNumber(value, 3);
},
beginAtZero: true
},
gridLines: { gridLines: {
color: "rgba(100, 255, 100, .05)" color: "rgba(100, 255, 100, .05)"
} }
@@ -136,6 +142,12 @@ DetailsWindow.prototype.renderGraph = function() {
display: true, display: true,
labelString: "Views" labelString: "Views"
}, },
ticks: {
callback: function(value, index, values) {
return formatNumber(value, 3);
},
beginAtZero: true
},
gridLines: { gridLines: {
color: "rgba(128, 128, 255, .05)" color: "rgba(128, 128, 255, .05)"
} }