diff --git a/website/assets/js/models.js b/website/assets/js/models.js
index e05fabea0..8df49acc2 100644
--- a/website/assets/js/models.js
+++ b/website/assets/js/models.js
@@ -1,6 +1,6 @@
'use strict';
-import { Templater, handleResponse, convertNumber } from './util.js';
+import { Templater, handleResponse, convertNumber, abbrNumber } from './util.js';
/**
* Chart.js defaults
@@ -25,7 +25,7 @@ export const formats = {
license: (license, url) => url ? `${license}` : license,
sources: sources => (sources instanceof Array) ? sources.join(', ') : sources,
pipeline: pipes => (pipes && pipes.length) ? pipes.map(p => `${p}
`).join(', ') : '-',
- vectors: vec => vec ? `${convertNumber(vec.entries)} (${vec.width} dimensions)` : 'n/a',
+ vectors: vec => vec ? `${abbrNumber(vec.keys)} keys, ${abbrNumber(vec.vectors)} unique vectors (${vec.width} dimensions)` : 'n/a',
version: version => `v${version}
`
};
diff --git a/website/assets/js/util.js b/website/assets/js/util.js
index 6bf14f578..65d05774c 100644
--- a/website/assets/js/util.js
+++ b/website/assets/js/util.js
@@ -46,11 +46,24 @@ export const handleResponse = res => {
else return ({ ok: res.ok })
};
-
/**
* Convert a number to a string and add thousand separator.
* @param {number|string} num - The number to convert.
* @param {string} separator – Thousand separator.
*/
-export const convertNumber = (num, separator = ',') =>
+export const convertNumber = (num = 0, separator = ',') =>
num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
+
+/**
+ * Abbreviate a number, e.g. 14249930 --> 14.25m.
+ * @param {number|string} num - The number to convert.
+ * @param {number} fixed - Number of decimals.
+ */
+export const abbrNumber = (num = 0, fixed = 2) => {
+ const suffixes = ['', 'k', 'm', 'b', 't'];
+ if (num === null || num === 0) return 0;
+ const b = num.toPrecision(2).split('e');
+ const k = (b.length === 1) ? 0 : Math.floor(Math.min(b[1].slice(1), 14) / 3);
+ const c = (k < 1) ? num.toFixed(fixed) : (num / Math.pow(10, k * 3)).toFixed(fixed + 1);
+ return (c < 0 ? c : Math.abs(c)) + suffixes[k];
+}