From 0f0124a60dcb2d848b915fd5c14a374bd75a2271 Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Wed, 26 Jun 2019 23:34:28 +0300 Subject: [PATCH] Fix some CC issues --- src/core/core.controller.js | 20 ++++++++++---------- src/scales/scale.linear.js | 9 ++------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/core/core.controller.js b/src/core/core.controller.js index e3382081dbe..d34d36bdb1a 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -154,6 +154,14 @@ function positionIsHorizontal(position) { return position === 'top' || position === 'bottom'; } +function compare2Level(l1, l2) { + return function(a, b) { + return a[l1] === b[l1] + ? a[l2] - b[l2] + : a[l1] - b[l1]; + }; +} + var Chart = function(item, config) { this.construct(item, config); return this; @@ -515,11 +523,7 @@ helpers.extend(Chart.prototype, /** @lends Chart */ { // Do this before render so that any plugins that need final scale updates can use it plugins.notify(me, 'afterUpdate'); - me._layers.sort(function(a, b) { - return a.z === b.z - ? a._idx - b._idx - : a.z - b.z; - }); + me._layers.sort(compare2Level('z', '_idx')); if (me._bufferedRender) { me._bufferedRequest = { @@ -729,11 +733,7 @@ helpers.extend(Chart.prototype, /** @lends Chart */ { } } - result.sort(function(a, b) { - return a.order === b.order - ? a.index - b.index - : a.order - b.order; - }); + result.sort(compare2Level('order', 'index')); return result; }, diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 63eff8aa266..88ad8b365ea 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -80,13 +80,8 @@ function updateMinMax(scale, meta, data) { continue; } - if (value.min < scale.min) { - scale.min = value.min; - } - - if (value.max > scale.max) { - scale.max = value.max; - } + scale.min = Math.min(scale.min, value.min); + scale.max = Math.max(scale.max, value.max); } }