提交 63eb7b5b 编写于 作者: P pah100

change mergeoption, mapping

上级 e712f352
......@@ -23,12 +23,6 @@ define(function (require) {
var VISUAL_CODING_STAGES = ['echarts', 'chart', 'component'];
/**
* @inner
*/
function getSeriesId(series, seriesIndex) {
return series.type + '_' + (series.name || seriesIndex);
}
/**
* @module echarts~ECharts
*/
......@@ -231,7 +225,7 @@ define(function (require) {
}
ecModel.eachSeries(function (seriesModel, idx) {
var id = getSeriesId(seriesModel.option, idx);
var id = seriesModel.uid;
var chart = chartsMap[id];
if (!chart) {
......@@ -277,16 +271,18 @@ define(function (require) {
componentsList[i].__keepAlive = true;
}
ecModel.eachComponent(function (componentType, componentModel, idx) {
ecModel.eachComponent(function (componentType, componentModel) {
if (componentType === 'series') {
return;
}
var id = componentType + '_' + idx;
var id = componentModel.uid;
var component = componentsMap[id];
if (!component) {
// Create and add component
var Clazz = ComponentView.getClass(componentType, componentModel.option);
var Clazz = ComponentView.getClass(
componentType, componentModel.option.type
);
if (Clazz) {
component = new Clazz();
......@@ -392,7 +388,7 @@ define(function (require) {
// Render all charts
ecModel.eachSeries(function (seriesModel, idx) {
var id = getSeriesId(seriesModel.option, idx);
var id = seriesModel.uid;
var chart = this._chartsMap[id];
chart.__keepAlive = true;
chart.render(seriesModel, ecModel, api, event);
......
......@@ -5,8 +5,6 @@
*/
define(function(require) {
'use strict';
var Model = require('./Model');
var zrUtil = require('zrender/core/util');
var arrayPush = Array.prototype.push;
......@@ -30,7 +28,7 @@ define(function(require) {
defaultOption: null,
/**
* @type {Object}
* @type {module:echarts/model/Global}
* @readOnly
*/
ecModel: null,
......@@ -41,7 +39,13 @@ define(function(require) {
* @type {Object.<string, Array.<module:echarts/model/Model>>}
* @readOnly
*/
dependentModel: null,
dependentModels: null,
/**
* @type {string}
* @readOnly
*/
uid: null,
init: function () {
this.mergeDefaultAndTheme(this.option, this.ecModel);
......@@ -73,35 +77,19 @@ define(function(require) {
});
ComponentModel.extend = function (proto) {
var SubComponentModel = function (option, parentModel, ecModel, dependentModels) {
this.ecModel = ecModel;
this.dependentModels = dependentModels;
/**
* @type {string}
* @public
* @readOnly
*/
this.uid = componentUtil.getUID('componentModel');
ComponentModel.apply(this, arguments);
};
zrUtil.extend(SubComponentModel.prototype, proto);
var Super = this;
SubComponentModel.extend = Super.extend;
zrUtil.inherits(SubComponentModel, Super);
return SubComponentModel;
};
// Reset ComponentModel.extend, add preConstruct.
componentUtil.enableClassExtend(ComponentModel, function (option, parentModel, ecModel, dependentModels) {
this.ecModel = ecModel;
this.dependentModels = dependentModels;
this.uid = componentUtil.getUID('componentModel');
});
// And capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
// Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
componentUtil.enableClassManagement(
ComponentModel,
{subTypeDefaulter: true, registerWhenExtend: true}
ComponentModel, {subTypeDefaulter: true, registerWhenExtend: true}
);
// Add capability of ComponentModel.topologicalTravel.
componentUtil.enableTopologicalTravel(ComponentModel, getDependencies);
function getDependencies(componentType) {
......
......@@ -119,32 +119,36 @@ define(function (require) {
// FIXME 这里 componentTypes 是新的 Option,在依赖处理上是否会有问题
// FIXME OPTION 同步是否要改回原来的
ComponentModel.topologicalTravel(componentTypes, function (componentType, dependencies) {
var componentOption = newOption[componentType];
var newCptOptionList = newOption[componentType];
// Normalize
if (!(zrUtil.isArray(componentOption))) {
componentOption = [componentOption];
if (!(zrUtil.isArray(newCptOptionList))) {
newCptOptionList = [newCptOptionList];
}
if (!componentsMap[componentType]) {
componentsMap[componentType] = [];
}
for (var i = 0; i < componentOption.length; i++) {
var componentModel = componentsMap[componentType][i];
var existComponents = this._mappingToExists(componentType, newCptOptionList);
ComponentModel.completeSubType(componentType, componentOption[i]);
for (var i = 0; i < newCptOptionList.length; i++) {
var componentModel = existComponents[i];
var newCptOption = newCptOptionList[i];
var subType = this._determineSubType(
componentType, newCptOption, existComponents[i]
);
var ComponentModelClass = ComponentModel.getClass(
componentType, componentOption[i], true
componentType, subType, true
);
if (componentModel && componentModel instanceof ComponentModelClass) {
componentModel.mergeOption(componentOption[i], this);
componentModel.mergeOption(newCptOption, this);
}
else {
// PENDING Global as parent ?
componentModel = new ComponentModelClass(
componentOption[i], this, this,
newCptOptionList[i], this, this,
this._getComponentsByTypes(dependencies), i
);
componentsMap[componentType][i] = componentModel;
......@@ -162,6 +166,48 @@ define(function (require) {
}, this);
},
/**
* @private
*/
_determineSubType: function (componentType, newCptOption, existComponent) {
return newCptOption.type
? newCptOption.type
: existComponent
? existComponent.option.type
// Use determinSubType only when there is no existComponent.
: ComponentModel.determineSubType(componentType, newCptOption);
},
/**
* @private
*/
_mappingToExists: function (componentType, newComponentOptionList) {
var result = [];
var existComponents = (this._componentsMap[componentType] || []).slice();
// Mapping by name if specified.
zrUtil.each(newComponentOptionList, function (componentOption, index) {
if (!componentOption.name) {
return;
}
for (var i = 0, len = existComponents.length; i < len; i++) {
if (existComponents[i].name === componentOption.name) {
result[index] = existComponents.splice(i, 1)[0];
break;
}
}
});
// Otherwise mapping by index.
zrUtil.each(newComponentOptionList, function (componentOption, index) {
if (!result[index]) {
result[index] = existComponents[index];
}
});
return result;
},
/**
* @return {module:echarts/model/Model}
*/
......
......@@ -47,9 +47,10 @@ define(function(require) {
/**
* @public
*/
util.enableClassExtend = function (RootClass) {
util.enableClassExtend = function (RootClass, preConstruct) {
RootClass.extend = function (proto) {
var ExtendedClass = function () {
preConstruct && preConstruct.apply(this, arguments);
RootClass.apply(this, arguments);
};
......@@ -99,12 +100,11 @@ define(function(require) {
return Clazz;
};
entity.getClass = function (componentTypeMain, option, throwWhenNotFound) {
entity.getClass = function (componentTypeMain, subType, throwWhenNotFound) {
var Clazz = storage[componentTypeMain];
var subType = option && option.type;
if (Clazz && Clazz[IS_CONTAINER] && subType) {
Clazz = Clazz[subType];
if (Clazz && Clazz[IS_CONTAINER]) {
Clazz = subType ? Clazz[subType] : null;
}
if (throwWhenNotFound && !Clazz) {
......@@ -182,8 +182,9 @@ define(function(require) {
subTypeDefaulters[componentType.main] = defaulter;
};
entity.completeSubType = function (componentType, option) {
if (!option.type) {
entity.determineSubType = function (componentType, option) {
var type = option.type;
if (!type) {
var componentTypeMain = parseComponentType(componentType).main;
var Clazz = storage[componentTypeMain];
Clazz
......@@ -191,6 +192,7 @@ define(function(require) {
&& subTypeDefaulters[componentTypeMain]
&& subTypeDefaulters[componentTypeMain](option);
}
return type;
};
return entity;
......
......@@ -37,7 +37,7 @@ define(function (require) {
// Enable Chart.extend.
componentUtil.enableClassExtend(Chart);
// And capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
// Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
componentUtil.enableClassManagement(Chart, {registerWhenExtend: true});
return Chart;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册