提交 0dd3eee7 编写于 作者: P pah100

tweak link list

上级 c9fa43d1
......@@ -303,12 +303,10 @@ define(function(require) {
nodes[data.getRawIndex(i)].dataIndex = i;
}
edgeData.silent = true;
edgeData.filterSelf(function (idx) {
var edge = edges[edgeData.getRawIndex(idx)];
return edge.node1.dataIndex >= 0 && edge.node2.dataIndex >= 0;
});
edgeData.silent = false;
// Update edge
for (var i = 0, len = edges.length; i < len; i++) {
......
......@@ -98,11 +98,6 @@ define(function (require) {
*/
this.dataType;
/**
* @type {boolean}
*/
this.silent = false;
/**
* Indices stores the indices of data subset after filtered.
* This data subset will be used in chart.
......@@ -668,8 +663,6 @@ define(function (require) {
// Reset data extent
this._extent = {};
!this.silent && this.__onChange();
return this;
};
......@@ -765,8 +758,6 @@ define(function (require) {
}
}, stack, context);
!this.silent && this.__onTransfer(list);
return list;
};
......@@ -813,8 +804,6 @@ define(function (require) {
indices.push(idx);
}
!this.silent && this.__onTransfer(list);
return list;
};
......@@ -1038,8 +1027,6 @@ define(function (require) {
list.indices = this.indices.slice();
!this.silent && this.__onTransfer(list);
return list;
};
......@@ -1061,7 +1048,11 @@ define(function (require) {
};
};
listProto.__onTransfer = listProto.__onChange = zrUtil.noop;
// Methods that create a new list based on this list should be listed here.
// Notice that those method should `RETURN` the new list.
listProto.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'map'];
// Methods that change indices of this list should be listed here.
listProto.CHANGABLE_METHODS = ['filterSelf'];
return List;
});
\ No newline at end of file
......@@ -41,45 +41,54 @@ define(function (require) {
// Porxy data original methods.
each(datas, function (data) {
each(injections, function (injection, methodName) {
data.wrapMethod(methodName, zrUtil.curry(injection, opt));
each(mainData.TRANSFERABLE_METHODS, function (methodName) {
data.wrapMethod(methodName, zrUtil.curry(transferInjection, opt));
});
});
// Beyond transfer, additional features should be added to `cloneShallow`.
mainData.wrapMethod('cloneShallow', zrUtil.curry(cloneShallowInjection, opt));
// Only mainData trigger change, because struct.update may trigger
// another changable methods, which may bring about dead lock.
each(mainData.CHANGABLE_METHODS, function (methodName) {
mainData.wrapMethod(methodName, zrUtil.curry(changeInjection, opt));
});
// Make sure datas contains mainData.
zrUtil.assert(datas[mainData.dataType] === mainData);
}
var injections = {
__onTransfer: function (opt, res, newData) {
if (isMainData(this)) {
// Transfer datas to new main data.
var datas = zrUtil.extend({}, this[DATAS]);
datas[this.dataType] = newData;
linkAll(newData, datas, opt);
}
else {
// Modify the reference in main data to point newData.
linkSingle(newData, this.dataType, this[MAIN_DATA], opt);
}
},
__onChange: function (opt) {
opt.struct && opt.struct.update(this);
},
cloneShallow: function (opt, newData) {
// cloneShallow, which brings about some fragilities, may be inappropriate
// to be exposed as an API. So for implementation simplicity we can make
// the restriction that cloneShallow of not-mainData should not be invoked
// outside, but only be invoked here.
isMainData(this) && each(newData[DATAS], function (data, dataType) {
data !== newData && linkSingle(data.cloneShallow(), dataType, newData, opt);
});
return newData;
function transferInjection(opt, res) {
if (isMainData(this)) {
// Transfer datas to new main data.
var datas = zrUtil.extend({}, this[DATAS]);
datas[this.dataType] = res;
linkAll(res, datas, opt);
}
else {
// Modify the reference in main data to point newData.
linkSingle(res, this.dataType, this[MAIN_DATA], opt);
}
};
return res;
}
function changeInjection(opt, res) {
opt.struct && opt.struct.update(this);
return res;
}
function cloneShallowInjection(opt, res) {
// cloneShallow, which brings about some fragilities, may be inappropriate
// to be exposed as an API. So for implementation simplicity we can make
// the restriction that cloneShallow of not-mainData should not be invoked
// outside, but only be invoked here.
each(res[DATAS], function (data, dataType) {
data !== res && linkSingle(data.cloneShallow(), dataType, res, opt);
});
return res;
}
/**
* Supplement method to List.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册