Skip to content

Commit f80647f

Browse files
committed
Merge pull request #3893 from plotly/rm-jquery-extend
Replace jQuery extend
2 parents 5acd130 + a99c349 commit f80647f

File tree

14 files changed

+90
-92
lines changed

14 files changed

+90
-92
lines changed

shelly/plotlyjs/static/plotlyjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"alpha-shape": "^1.0.0",
1313
"arraytools": "^1.0.0",
1414
"browserify": "^6.1.0",
15+
"clone": "^1.0.2",
1516
"colormap": "^1.3.1",
1617
"convex-hull": "^1.0.3",
1718
"delaunay-triangulate": "^1.1.6",
@@ -29,7 +30,6 @@
2930
"ndarray-fill": "^1.0.1",
3031
"ndarray-homography": "^1.0.0",
3132
"ndarray-ops": "^1.2.2",
32-
"object-assign": "2.0.0",
3333
"promise": "6.1.0",
3434
"right-now": "^1.0.0",
3535
"superscript-text": "^1.0.0",

shelly/plotlyjs/static/plotlyjs/src/annotations.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,9 @@ annotations.draw = function(gd, index, opt, value) {
455455
else if(value==='add' || Plotly.Lib.isPlainObject(value)) {
456456
fullLayout.annotations.splice(index,0,{});
457457

458-
var rule = Plotly.Lib.isPlainObject(value) ? $.extend({},value) : {text: 'New text'};
458+
var rule = Plotly.Lib.isPlainObject(value) ?
459+
Plotly.Lib.extendFlat({}, value) :
460+
{text: 'New text'};
459461

460462
if (layout.annotations) {
461463
layout.annotations.splice(index, 0, rule);

shelly/plotlyjs/static/plotlyjs/src/boxes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ boxes.hoverPoints = function(pointData, xval, yval, hovermode) {
810810

811811
// copy out to a new object for each value to label
812812
val = valAxis.c2p(di[attr], true);
813-
pointData2 = $.extend({}, pointData);
813+
pointData2 = Plotly.Lib.extendFlat({}, pointData);
814814
pointData2[valLetter+'0'] = pointData2[valLetter+'1'] = val;
815815
pointData2[valLetter+'LabelVal'] = di[attr];
816816
pointData2.attr = attr;

shelly/plotlyjs/static/plotlyjs/src/colorbar.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,10 @@ var colorbar = module.exports = function(td, id) {
496496

497497
// setter - for multi-part properties,
498498
// set only the parts that are provided
499-
if(Plotly.Lib.isPlainObject(opts[name])) $.extend(opts[name],v);
500-
else opts[name] = v;
499+
opts[name] = Plotly.Lib.isPlainObject(opts[name]) ?
500+
Plotly.Lib.extendFlat(opts[name], v) :
501+
v;
502+
501503
return component;
502504
};
503505
});

shelly/plotlyjs/static/plotlyjs/src/drawing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ drawing.bBox = function(node) {
934934
// remeasure the same thing many times
935935
var saveNum = node.attributes['data-bb'];
936936
if(saveNum && saveNum.value) {
937-
return $.extend({}, savedBBoxes[saveNum.value]);
937+
return Plotly.Lib.extendFlat({}, savedBBoxes[saveNum.value]);
938938
}
939939

940940
var test3 = d3.select('#js-plotly-tester'),

shelly/plotlyjs/static/plotlyjs/src/graph_obj.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
var Plotly = require('./plotly'),
1212
m4FromQuat = require('gl-mat4/fromQuat'),
13-
isNumeric = require('./isnumeric');
13+
isNumeric = require('./isnumeric'),
14+
clone = require('clone');
1415

1516
var plots = module.exports = {};
1617
// Most of the generic plotting functions get put into Plotly.Plots,
@@ -290,7 +291,7 @@ plots.defaultConfig = {
290291
};
291292

292293
function setPlotContext(gd, config) {
293-
if(!gd._context) gd._context = $.extend({}, plots.defaultConfig);
294+
if(!gd._context) gd._context = Plotly.Lib.extendFlat(plots.defaultConfig);
294295
var context = gd._context;
295296

296297
if(config) {
@@ -554,9 +555,6 @@ Plotly.plot = function(gd, data, layout, config) {
554555
}
555556
else if(graphwasempty) makePlotFramework(gd);
556557

557-
// enable or disable formatting buttons
558-
$(gd).find('.data-only').attr('disabled', !hasData);
559-
560558
var fullLayout = gd._fullLayout;
561559

562560
// prepare the data and find the autorange
@@ -2243,7 +2241,7 @@ function getExtendProperties (gd, update, indices, maxPoints) {
22432241
}
22442242

22452243
/**
2246-
* A private function to keey Extend and Prepend traces DRY
2244+
* A private function to key Extend and Prepend traces DRY
22472245
*
22482246
* @param {Object|HTMLDivElement} gd
22492247
* @param {Object} update
@@ -2593,19 +2591,22 @@ Plotly.moveTraces = function moveTraces (gd, currentIndices, newIndices) {
25932591

25942592
// restyle: change styling of an existing plot
25952593
// can be called two ways:
2596-
// restyle(gd,astr,val[,traces])
2597-
// gd - graph div (dom element)
2594+
//
2595+
// restyle(gd, astr, val [,traces])
2596+
// gd - graph div (string id or dom element)
25982597
// astr - attribute string (like 'marker.symbol')
25992598
// val - value to give this attribute
26002599
// traces - integer or array of integers for the traces
26012600
// to alter (all if omitted)
2602-
// relayout(gd,aobj[,traces])
2601+
//
2602+
// restyle(gd, aobj [,traces])
26032603
// aobj - {astr1:val1, astr2:val2...} allows setting
26042604
// multiple attributes simultaneously
2605+
//
26052606
// val (or val1, val2... in the object form) can be an array,
2606-
// to apply different values to each trace
2607-
// if the array is too short, it will wrap around (useful for
2608-
// style files that want to specify cyclical default values)
2607+
// to apply different values to each trace.
2608+
// If the array is too short, it will wrap around (useful for
2609+
// style files that want to specify cyclical default values).
26092610
Plotly.restyle = function restyle(gd, astr, val, traces) {
26102611
gd = getGraphDiv(gd);
26112612

@@ -3085,9 +3086,9 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
30853086
var plotDone = Plotly.Lib.syncOrAsync(seq, gd);
30863087

30873088
if(!plotDone || !plotDone.then) plotDone = Promise.resolve();
3089+
30883090
return plotDone.then(function(){
3089-
$(gd).trigger('plotly_restyle',
3090-
$.extend(true, [], [redoit, traces]));
3091+
$(gd).trigger('plotly_restyle', clone([redoit, traces]));
30913092
});
30923093
};
30933094

@@ -3120,10 +3121,12 @@ function swapXYData(trace) {
31203121

31213122
// relayout: change layout in an existing plot
31223123
// can be called two ways:
3123-
// relayout(gd,astr,val)
3124-
// gd - graph div (dom element)
3124+
//
3125+
// relayout(gd, astr, val)
3126+
// gd - graph div (string id or dom element)
31253127
// astr - attribute string (like 'xaxis.range[0]')
31263128
// val - value to give this attribute
3129+
//
31273130
// relayout(gd,aobj)
31283131
// aobj - {astr1:val1, astr2:val2...}
31293132
// allows setting multiple attributes simultaneously
@@ -3443,8 +3446,9 @@ Plotly.relayout = function relayout(gd, astr, val) {
34433446
var plotDone = Plotly.Lib.syncOrAsync(seq, gd);
34443447

34453448
if(!plotDone || !plotDone.then) plotDone = Promise.resolve();
3449+
34463450
return plotDone.then(function(){
3447-
$(gd).trigger('plotly_relayout', $.extend(true, {}, redoit));
3451+
$(gd).trigger('plotly_relayout', clone(redoit));
34483452
});
34493453
};
34503454

shelly/plotlyjs/static/plotlyjs/src/heatmap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ heatmap.hoverPoints = function(pointData, xval, yval, hovermode, contour) {
11371137
text = trace.text[ny][nx];
11381138
}
11391139

1140-
return [$.extend(pointData,{
1140+
return [Plotly.Lib.extendFlat(pointData, {
11411141
index: [ny, nx],
11421142
// never let a 2D override 1D type as closest point
11431143
distance: Plotly.Fx.MAXDIST+10,

shelly/plotlyjs/static/plotlyjs/src/lib.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,9 +1701,9 @@ lib.mergeArray = function(traceAttr, cd, cdAttr) {
17011701
};
17021702

17031703
/**
1704-
* modified version of $.extend to strip out private objs and functions,
1704+
* modified version of jQuery's extend to strip out private objs and functions,
17051705
* and cut arrays down to first <arraylen> or 1 elements
1706-
* because $.extend is hella slow
1706+
* because extend-like algorithms are hella slow
17071707
* obj2 is assumed to already be clean of these things (including no arrays)
17081708
*/
17091709
lib.minExtend = function(obj1, obj2) {

shelly/plotlyjs/static/plotlyjs/src/plotschema.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use strict';
22

33
var Plotly = require('./plotly'),
4-
objectAssign = require('object-assign');
4+
clone = require('clone');
5+
6+
var extendFlat = Plotly.Lib.extendFlat;
57

68
var NESTED_MODULE = '_nestedModules',
79
COMPOSED_MODULE = '_composedModules',
@@ -24,6 +26,7 @@ var polarAreaAttrs = require('./polar/attributes/area'),
2426

2527
var PlotSchema = module.exports = {};
2628

29+
2730
PlotSchema.get = function() {
2831
Plotly.Plots.allTypes
2932
.concat('area') // FIXME polar 'area' attributes
@@ -69,19 +72,19 @@ function getTraceAttributes(type) {
6972

7073
// subplot attributes
7174
if(subplotRegistry.attributes !== undefined) {
72-
attributes = objectAssign(attributes, subplotRegistry.attributes);
75+
attributes = extendFlat(attributes, clone(subplotRegistry.attributes));
7376
}
7477

7578
// global attributes (same for all trace types)
76-
attributes = objectAssign(attributes, globalAttributes);
79+
attributes = extendFlat(attributes, clone(globalAttributes));
7780

7881
// 'type' gets overwritten by globalAttributes; reset it here
7982
attributes.type = type;
8083

8184
attributes = removeUnderscoreAttrs(attributes);
8285

8386
mergeValTypeAndRole(attributes);
84-
plotSchema.traces[type] = objectAssign(
87+
plotSchema.traces[type] = extendFlat(
8588
meta,
8689
{ attributes: attributes }
8790
);
@@ -152,7 +155,7 @@ function coupleAttrs(attrsIn, attrsOut, whichAttrs, type) {
152155
);
153156

154157
Plotly.Lib.nestedProperty(attrsOut, kk)
155-
.set(nestedReference);
158+
.set(clone(nestedReference));
156159
});
157160
return;
158161
}
@@ -169,14 +172,12 @@ function coupleAttrs(attrsIn, attrsOut, whichAttrs, type) {
169172
composedAttrs, {}, whichAttrs, type
170173
);
171174

172-
attrsOut = objectAssign(attrsOut, composedAttrs);
175+
attrsOut = extendFlat(attrsOut, clone(composedAttrs));
173176
});
174177
return;
175178
}
176179

177-
attrsOut[k] = Plotly.Lib.isPlainObject(attrsIn[k]) ?
178-
objectAssign({}, attrsIn[k]) :
179-
attrsIn[k]; // some underscore attributes are booleans
180+
attrsOut[k] = clone(attrsIn[k]);
180181
});
181182

182183
return attrsOut;
@@ -242,12 +243,12 @@ function getMeta(type) {
242243
}
243244

244245
function assignPolarLayoutAttrs(layoutAttributes) {
245-
layoutAttributes = objectAssign(layoutAttributes, {
246-
radialaxis: polarAxisAttrs.radialaxis,
247-
angularaxis: polarAxisAttrs.angularaxis
246+
layoutAttributes = extendFlat(layoutAttributes, {
247+
radialaxis: clone(polarAxisAttrs.radialaxis),
248+
angularaxis: clone(polarAxisAttrs.angularaxis)
248249
});
249250

250-
layoutAttributes = objectAssign(layoutAttributes, polarAxisAttrs.layout);
251+
layoutAttributes = extendFlat(layoutAttributes, clone(polarAxisAttrs.layout));
251252

252253
return layoutAttributes; // FIXME
253254
}

shelly/plotlyjs/static/plotlyjs/src/queue.js

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,6 @@
11
'use strict';
22

3-
/**
4-
* Copy arg array *without* removing `undefined` values from objects.
5-
*
6-
* `$.extend(true, *, *)` ignores `undefined` object properties, which we
7-
* depend on in relayout and restyle. This function exists *purely* to
8-
* conserve these undefined properties.
9-
*
10-
* Note, it doesn't bother with undefined properties inside an object in
11-
* an array. We don't have a use-case for this, so it doesn't matter.
12-
*
13-
* @param gd
14-
* @param args
15-
* @returns {Array}
16-
*/
17-
function copyArgArray (gd, args) {
18-
var copy = [],
19-
i,
20-
arg,
21-
ai;
22-
for (i = 0; i < args.length; i++) {
23-
arg = args[i];
24-
if (arg === gd) {
25-
copy[i] = arg;
26-
} else if (typeof arg === 'object') {
27-
if (Array.isArray(arg)) {
28-
copy[i] = $.extend(true, [], arg);
29-
} else {
30-
copy[i] = {};
31-
32-
// this is the important line! `undefined` things are kept!
33-
for(ai in arg) copy[i][ai] = arg[ai];
34-
}
35-
} else {
36-
copy[i] = arg;
37-
}
38-
}
39-
return copy;
40-
}
3+
var clone = require('clone');
414

425

436
// -----------------------------------------------------
@@ -124,7 +87,8 @@ queue.undo = function undo (gd) {
12487
var queueObj,
12588
i;
12689

127-
if (!gd) { gd = Tabs.get(); }
90+
if(!gd) gd = Tabs.get(); // FIXME
91+
12892
if(gd.framework && gd.framework.isPolar){
12993
gd.framework.undo();
13094
return;
@@ -159,7 +123,8 @@ queue.redo = function redo (gd) {
159123
var queueObj,
160124
i;
161125

162-
if (!gd) { gd = Tabs.get(); }
126+
if(!gd) gd = Tabs.get(); // FIXME
127+
163128
if(gd.framework && gd.framework.isPolar){
164129
gd.framework.redo();
165130
return;
@@ -197,11 +162,8 @@ queue.redo = function redo (gd) {
197162
queue.plotDo = function (gd, func, args) {
198163
gd.autoplay = true;
199164

200-
// this *won't* copy gd and it preserves `undefined` properties!
201-
args = copyArgArray(gd, args);
202-
203-
// call the supplied function
204-
func.apply(null, args);
165+
// call the supplied function with a cloned args
166+
func.apply(null, clone(args));
205167
};
206168

207169
module.exports = queue;

0 commit comments

Comments
 (0)