提交 927d6315 编写于 作者: P pah100

add reset option

上级 352197d3
......@@ -7,7 +7,7 @@ define(function(require) {
echarts.registerAction(
{type: 'timelineChange', event: 'timelineChanged', update: 'reoption'},
{type: 'timelineChange', event: 'timelineChanged', update: 'prepareAndUpdate'},
function (payload, ecModel) {
......@@ -19,6 +19,8 @@ define(function(require) {
timelineModel.setPlayState(false);
}
}
ecModel.updateTimelineOption();
}
);
......
......@@ -14,7 +14,6 @@
define(function (require) {
var GlobalModel = require('./model/Global');
var OptionManager = require('./model/OptionManager');
var ExtensionAPI = require('./ExtensionAPI');
var CoordinateSystemManager = require('./CoordinateSystem');
......@@ -85,11 +84,6 @@ define(function (require) {
*/
this._theme = zrUtil.clone(theme, true);
/**
* @type {module:echarts/model/OptionManager}
*/
this._optionManager = new OptionManager();
/**
* @type {Array.<module:echarts/view/Chart>}
* @private
......@@ -163,40 +157,18 @@ define(function (require) {
* @param {boolean} [notRefreshImmediately=false] Useful when setOption frequently.
*/
echartsProto.setOption = function (option, notMerge, notRefreshImmediately) {
var baseOption = this._optionManager.updateRawOption(
option, optionPreprocessorFuncs
);
(!this._model || notMerge)
? (this._model = new GlobalModel(baseOption, null, this._theme))
: ecModelMerge.call(this, baseOption);
var partialOption = this._optionManager.getPartialOption(this._model);
if (partialOption) {
ecModelMerge.call(this, partialOption);
if (!this._model || notMerge) {
this._model = new GlobalModel(null, null, this._theme, optionPreprocessorFuncs);
}
prepareAndUpdate.call(this);
this._model.setOption(option);
updateMethods.prepareAndUpdate.call(this);
!notRefreshImmediately && this._zr.refreshImmediately();
};
function ecModelMerge(option) {
var ecModel = this._model;
ecModel.restoreData();
ecModel.mergeOption(option);
}
function prepareAndUpdate(payload) {
var ecModel = this._model;
prepareView.call(this, 'component', ecModel);
prepareView.call(this, 'chart', ecModel);
updateMethods.update.call(this, payload);
}
/**
* @DEPRECATED
*/
......@@ -456,17 +428,16 @@ define(function (require) {
/**
* @param {Object} payload
* @private
*/
reoption: function (payload) {
prepareAndUpdate: function (payload) {
var ecModel = this._model;
var optionManager = this._optionManager;
var partialOption = optionManager.getPartialOption(ecModel);
if (partialOption) {
ecModelMerge.call(this, partialOption);
}
prepareView.call(this, 'component', ecModel);
prepareView.call(this, 'chart', ecModel);
prepareAndUpdate.call(this, payload);
updateMethods.update.call(this, payload);
}
};
......
......@@ -9,6 +9,7 @@ define(function (require) {
var zrUtil = require('zrender/core/util');
var Model = require('./Model');
var OptionManager = require('./OptionManager');
var each = zrUtil.each;
var filter = zrUtil.filter;
var map = zrUtil.map;
......@@ -31,38 +32,51 @@ define(function (require) {
constructor: GlobalModel,
init: function (option, parentModel, theme) {
init: function (option, parentModel, theme, optionPreprocessorFuncs) {
theme = theme || {};
this.option = {};
this.option = null; // Mark as not initialized.
/**
* @type {Object.<string, Array.<module:echarts/model/Model>>}
* @type {module:echarts/model/Model}
* @private
*/
this._componentsMap = {};
this._theme = new Model(theme);
/**
* Mapping between filtered series list and raw series list.
* key: filtered series indices, value: raw series indices.
* @type {Array.<nubmer>}
* @private
* @type {module:echarts/model/OptionManager}
*/
this._seriesIndices;
this._optionManager = new OptionManager(optionPreprocessorFuncs);
},
/**
* @type {module:echarts/model/Model}
* @private
*/
this._theme = new Model(theme);
setOption: function (option) {
var optionManager = this._optionManager;
var baseOption = optionManager.setOption(option);
if (!this.option) {
initBase.call(this, baseOption);
}
else {
this.restoreData();
this.mergeOption(baseOption);
}
this.updateTimelineOption();
},
mergeTheme(option, theme);
resetOption: function () {
initBase.call(this, this._optionManager.resetOption());
// TODO Needs clone when merging to the unexisted property
zrUtil.merge(option, globalDefault, false);
this.updateTimelineOption();
},
this.mergeOption(option);
updateTimelineOption: function () {
var partialOption = this._optionManager.getTimelineOption(this);
if (partialOption) {
this.restoreData();
this.mergeOption(partialOption);
}
},
/**
......@@ -549,7 +563,6 @@ define(function (require) {
});
/**
* @inner
*/
......@@ -569,6 +582,33 @@ define(function (require) {
}
}
function initBase(baseOption) {
baseOption = baseOption;
this.option = {};
/**
* @type {Object.<string, Array.<module:echarts/model/Model>>}
* @private
*/
this._componentsMap = {};
/**
* Mapping between filtered series list and raw series list.
* key: filtered series indices, value: raw series indices.
* @type {Array.<nubmer>}
* @private
*/
this._seriesIndices = null;
mergeTheme(baseOption, this._theme.option);
// TODO Needs clone when merging to the unexisted property
zrUtil.merge(baseOption, globalDefault, false);
this.mergeOption(baseOption);
}
/**
* @inner
* @param {Array.<string>|string} types model types
......
......@@ -46,9 +46,6 @@ define(function (require) {
* {title: {...}, series: {data: [...]}},
* ...
* ],
* defaults: {
* {series: {x: 20}, dataRange: {show: false}}
* },
* media: [
* {
* query: {maxWidth: 320},
......@@ -65,14 +62,40 @@ define(function (require) {
* };
*
* @alias module:echarts/model/OptionManager
*
* @param {Array.<Function>} optionPreprocessorFuncs
*/
function OptionManager() {
function OptionManager(optionPreprocessorFuncs) {
/**
* @private
* @type {Array.<number>}
*/
this._timelineOptions = [];
this._timelineOptions;
/**
* @private
* @type {Array.<Object>}
*/
this._mediaList;
/**
* @private
* @type {Object}
*/
this._mediaDefault;
/**
* @private
* @type {Object}
*/
this._rawOptionBackup;
/**
* @private
* @type {Array.<Function>}
*/
this._optionPreprocessorFuncs = optionPreprocessorFuncs;
}
OptionManager.prototype = {
......@@ -82,25 +105,30 @@ define(function (require) {
/**
* @public
* @param {Object} rawOption Raw option.
* @param {Array.<Function>} optionPreprocessorFuncs
* @param {module:echarts/model/Global} ecModel
* @return {Object} Init option
*/
updateRawOption: function (rawOption, optionPreprocessorFuncs) {
setOption: function (rawOption) {
rawOption = zrUtil.clone(rawOption, true);
this._rawOptionBackup = shadowClone(rawOption);
// FIXME
// 如果 timeline options 或者 media 中设置了某个属性,而base中没有设置,则进行警告。
return settleRawOption.call(this, rawOption, optionPreprocessorFuncs);
return settleRawOption.call(this, rawOption, this._optionPreprocessorFuncs);
},
getPartialOption: function (ecModel) {
/**
* @param {module:echarts/model/Global} ecModel
* @return {Object}
*/
getTimelineOption: function (ecModel) {
var option;
var timelineOptions = this._timelineOptions;
if (timelineOptions.length) {
// getPartialOption can only be called after ecModel inited,
// getTimelineOption can only be called after ecModel inited,
// so we can get currentIndex from timelineModel.
var timelineModel = ecModel.getComponent('timeline');
if (timelineModel) {
......@@ -111,15 +139,22 @@ define(function (require) {
}
}
// FIXME
// and then merge media query option?
return option;
},
/**
* @param {module:echarts/model/Global} ecModel
* @return {Object}
*/
resetOption: function (optionPreprocessorFuncs) {
var rawOption = shadowClone(this._rawOptionBackup);
return settleRawOption.call(this, rawOption, this._optionPreprocessorFuncs);
}
};
function settleRawOption(rawOption, optionPreprocessorFuncs) {
var timelineOptions = [];
var mediaList = [];
var timelineOpt = rawOption.timeline;
var baseOption;
......@@ -129,19 +164,19 @@ define(function (require) {
timelineOptions = (rawOption.options || []).slice();
}
// For media query
else if (rawOption.media) {
if (rawOption.media) {
baseOption = rawOption.base || {};
var media = rawOption.media;
each(media, function (singleMedia) {
singleMedia
&& singleMedia.option
&& timelineOptions.push(singleMedia.option);
if (singleMedia && singleMedia.option) {
mediaList.push(singleMedia);
}
// else if (singleMedia && !singleMedia
});
}
// For normal option
else {
if (!baseOption) {
baseOption = rawOption;
timelineOptions.push(rawOption);
}
// Set timelineOpt to baseOption for convenience.
......@@ -168,5 +203,20 @@ define(function (require) {
return baseOption;
}
function applyMedia(ecModel, api) {
var result;
each(this._mediaList, function (singleMedia) {
});
return result;
}
function shadowClone(rawOption) {
// FIXME
return zrUtil.clone(rawOption, true);
}
return OptionManager;
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册