MCPcopy
hub / github.com/tdewolff/minify / mergeLayoutParam

Function mergeLayoutParam

_benchmarks/sample_echarts.js:17007–17082  ·  view source on GitHub ↗

* Consider Case: * When default option has {left: 0, width: 100}, and we set {right: 0} * through setOption or media query, using normal zrUtil.merge will cause * {right: 0} does not take effect. * * @example * ComponentModel.extend({ * init: function () {

(targetOption, newOption, opt)

Source from the content-addressed store, hash-verified

17005 */
17006
17007 function mergeLayoutParam(targetOption, newOption, opt) {
17008 var ignoreSize = opt && opt.ignoreSize;
17009 !isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
17010 var hResult = merge(HV_NAMES[0], 0);
17011 var vResult = merge(HV_NAMES[1], 1);
17012 copy(HV_NAMES[0], targetOption, hResult);
17013 copy(HV_NAMES[1], targetOption, vResult);
17014
17015 function merge(names, hvIdx) {
17016 var newParams = {};
17017 var newValueCount = 0;
17018 var merged = {};
17019 var mergedValueCount = 0;
17020 var enoughParamNumber = 2;
17021 each$1(names, function (name) {
17022 merged[name] = targetOption[name];
17023 });
17024 each$1(names, function (name) {
17025 // Consider case: newOption.width is null, which is
17026 // set by user for removing width setting.
17027 hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
17028 hasValue(newParams, name) && newValueCount++;
17029 hasValue(merged, name) && mergedValueCount++;
17030 });
17031
17032 if (ignoreSize[hvIdx]) {
17033 // Only one of left/right is premitted to exist.
17034 if (hasValue(newOption, names[1])) {
17035 merged[names[2]] = null;
17036 } else if (hasValue(newOption, names[2])) {
17037 merged[names[1]] = null;
17038 }
17039
17040 return merged;
17041 } // Case: newOption: {width: ..., right: ...},
17042 // or targetOption: {right: ...} and newOption: {width: ...},
17043 // There is no conflict when merged only has params count
17044 // little than enoughParamNumber.
17045
17046
17047 if (mergedValueCount === enoughParamNumber || !newValueCount) {
17048 return merged;
17049 } // Case: newOption: {width: ..., right: ...},
17050 // Than we can make sure user only want those two, and ignore
17051 // all origin params in targetOption.
17052 else if (newValueCount >= enoughParamNumber) {
17053 return newParams;
17054 } else {
17055 // Chose another param from targetOption by priority.
17056 for (var i = 0; i < names.length; i++) {
17057 var name_1 = names[i];
17058
17059 if (!hasProp(newParams, name_1) && hasProp(targetOption, name_1)) {
17060 newParams[name_1] = targetOption[name_1];
17061 break;
17062 }
17063 }
17064

Callers 5

sample_echarts.jsFile · 0.85
axisModelCreatorFunction · 0.85
mergeNewElOptionToExistFunction · 0.85

Calls 3

isArrayFunction · 0.70
mergeFunction · 0.70
copyFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…