From 48c07e9ef60036d001f8ca574313461491435e39 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Wed, 7 Jun 2023 11:53:05 -0400 Subject: [PATCH] fix arrayLen in minExtend --- src/components/legend/style.js | 5 +++-- src/lib/index.js | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/components/legend/style.js b/src/components/legend/style.js index ab86b2dfe96..8a15c6db0ea 100644 --- a/src/components/legend/style.js +++ b/src/components/legend/style.js @@ -506,8 +506,9 @@ module.exports = function style(s, gd, legend) { var cont = trace.marker || {}; var lw = boundLineWidth(pieCastOption(cont.line.width, d0.pts), cont.line, MAX_MARKER_LINE_WIDTH, CST_MARKER_LINE_WIDTH); - var tMod = Lib.minExtend(trace, {marker: {line: {width: lw}}}, true); - var d0Mod = Lib.minExtend(d0, {trace: tMod}, true); + var opt = 'pieLike'; + var tMod = Lib.minExtend(trace, {marker: {line: {width: lw}}}, opt); + var d0Mod = Lib.minExtend(d0, {trace: tMod}, opt); stylePie(pts, d0Mod, tMod, gd); } diff --git a/src/lib/index.js b/src/lib/index.js index efc9022ff4a..583eef95615 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -698,10 +698,12 @@ lib.getTargetArray = function(trace, transformOpts) { * because extend-like algorithms are hella slow * obj2 is assumed to already be clean of these things (including no arrays) */ -lib.minExtend = function(obj1, obj2, isPie) { +function minExtend(obj1, obj2, opt) { var objOut = {}; if(typeof obj2 !== 'object') obj2 = {}; - var arrayLen = isPie = 3; + + var arrayLen = opt === 'pieLike' ? -1 : 3; + var keys = Object.keys(obj1); var i, k, v; @@ -711,14 +713,18 @@ lib.minExtend = function(obj1, obj2, isPie) { if(k.charAt(0) === '_' || typeof v === 'function') continue; else if(k === 'module') objOut[k] = v; else if(Array.isArray(v)) { - if(isPie || k === 'colorscale') { + if(k === 'colorscale' || arrayLen === -1) { objOut[k] = v.slice(); } else { objOut[k] = v.slice(0, arrayLen); } } else if(lib.isTypedArray(v)) { - objOut[k] = v.subarray(0, arrayLen); - } else if(v && (typeof v === 'object')) objOut[k] = lib.minExtend(obj1[k], obj2[k]); + if(arrayLen === -1) { + objOut[k] = v.subarray(); + } else { + objOut[k] = v.subarray(0, arrayLen); + } + } else if(v && (typeof v === 'object')) objOut[k] = minExtend(obj1[k], obj2[k], opt); else objOut[k] = v; } @@ -732,7 +738,8 @@ lib.minExtend = function(obj1, obj2, isPie) { } return objOut; -}; +} +lib.minExtend = minExtend; lib.titleCase = function(s) { return s.charAt(0).toUpperCase() + s.substr(1);