From af7eede8ea08322def500ac732d4d90b35d30685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B2=9A=E6=B7=87?= Date: Thu, 10 Aug 2023 17:36:45 +0800 Subject: [PATCH] feat: add data custom sort --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 7be341e..df50186 100644 --- a/index.js +++ b/index.js @@ -30,6 +30,7 @@ module.exports = function() { random = Math.random, cloud = {}, canvas = cloudCanvas; + sort = 'size'; cloud.canvas = function(_) { return arguments.length ? (canvas = functor(_), cloud) : canvas; @@ -51,7 +52,7 @@ module.exports = function() { d.size = ~~fontSize.call(this, d, i); d.padding = padding.call(this, d, i); return d; - }).sort(function(a, b) { return b.size - a.size; }); + }).sort(function(a, b) { return b[sort] - a[sort]; }); if (timer) clearInterval(timer); timer = setInterval(step, 0); @@ -209,6 +210,10 @@ module.exports = function() { return value === event ? cloud : value; }; + cloud.sort = function(_) { + return arguments.length ? (sort = _, cloud) : sort; + } + return cloud; };