Skip to content

Commit cebbf2e

Browse files
authored
Merge pull request #6632 from plotly/fix-arrayLen-in-minExtend
Fix minimal copying of arrays in `minExtend` function
2 parents 5c7bbea + 48c07e9 commit cebbf2e

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/components/legend/style.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,9 @@ module.exports = function style(s, gd, legend) {
506506
var cont = trace.marker || {};
507507
var lw = boundLineWidth(pieCastOption(cont.line.width, d0.pts), cont.line, MAX_MARKER_LINE_WIDTH, CST_MARKER_LINE_WIDTH);
508508

509-
var tMod = Lib.minExtend(trace, {marker: {line: {width: lw}}}, true);
510-
var d0Mod = Lib.minExtend(d0, {trace: tMod}, true);
509+
var opt = 'pieLike';
510+
var tMod = Lib.minExtend(trace, {marker: {line: {width: lw}}}, opt);
511+
var d0Mod = Lib.minExtend(d0, {trace: tMod}, opt);
511512

512513
stylePie(pts, d0Mod, tMod, gd);
513514
}

src/lib/index.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,12 @@ lib.getTargetArray = function(trace, transformOpts) {
698698
* because extend-like algorithms are hella slow
699699
* obj2 is assumed to already be clean of these things (including no arrays)
700700
*/
701-
lib.minExtend = function(obj1, obj2, isPie) {
701+
function minExtend(obj1, obj2, opt) {
702702
var objOut = {};
703703
if(typeof obj2 !== 'object') obj2 = {};
704-
var arrayLen = isPie = 3;
704+
705+
var arrayLen = opt === 'pieLike' ? -1 : 3;
706+
705707
var keys = Object.keys(obj1);
706708
var i, k, v;
707709

@@ -711,14 +713,18 @@ lib.minExtend = function(obj1, obj2, isPie) {
711713
if(k.charAt(0) === '_' || typeof v === 'function') continue;
712714
else if(k === 'module') objOut[k] = v;
713715
else if(Array.isArray(v)) {
714-
if(isPie || k === 'colorscale') {
716+
if(k === 'colorscale' || arrayLen === -1) {
715717
objOut[k] = v.slice();
716718
} else {
717719
objOut[k] = v.slice(0, arrayLen);
718720
}
719721
} else if(lib.isTypedArray(v)) {
720-
objOut[k] = v.subarray(0, arrayLen);
721-
} else if(v && (typeof v === 'object')) objOut[k] = lib.minExtend(obj1[k], obj2[k]);
722+
if(arrayLen === -1) {
723+
objOut[k] = v.subarray();
724+
} else {
725+
objOut[k] = v.subarray(0, arrayLen);
726+
}
727+
} else if(v && (typeof v === 'object')) objOut[k] = minExtend(obj1[k], obj2[k], opt);
722728
else objOut[k] = v;
723729
}
724730

@@ -732,7 +738,8 @@ lib.minExtend = function(obj1, obj2, isPie) {
732738
}
733739

734740
return objOut;
735-
};
741+
}
742+
lib.minExtend = minExtend;
736743

737744
lib.titleCase = function(s) {
738745
return s.charAt(0).toUpperCase() + s.substr(1);

0 commit comments

Comments
 (0)