Model.js
4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* @module echarts/model/Model
*/
define(function (require) {
var zrUtil = require('zrender/core/util');
var clazzUtil = require('../util/clazz');
/**
* @alias module:echarts/model/Model
* @constructor
* @param {Object} option
* @param {module:echarts/model/Model} [parentModel]
* @param {module:echarts/model/Global} [ecModel]
* @param {Object} extraOpt
*/
function Model(option, parentModel, ecModel, extraOpt) {
/**
* @type {module:echarts/model/Model}
* @readOnly
*/
this.parentModel = parentModel;
/**
* @type {module:echarts/model/Global}
* @readOnly
*/
this.ecModel = ecModel;
/**
* @type {Object}
* @protected
*/
this.option = option;
// Simple optimization
if (this.init) {
if (arguments.length <= 4) {
this.init(option, parentModel, ecModel, extraOpt);
}
else {
this.init.apply(this, arguments);
}
}
}
Model.prototype = {
constructor: Model,
/**
* Model 的初始化函数
* @param {Object} option
*/
init: null,
/**
* 从新的 Option merge
*/
mergeOption: function (option) {
zrUtil.merge(this.option, option, true);
},
/**
* @param {string} path
* @param {boolean} [ignoreParent=false]
* @return {*}
*/
get: function (path, ignoreParent) {
if (!path) {
return this.option;
}
if (typeof path === 'string') {
path = path.split('.');
}
var obj = this.option;
var parentModel = this.parentModel;
for (var i = 0; i < path.length; i++) {
// Ignore empty
if (!path[i]) {
continue;
}
// obj could be number/string/... (like 0)
obj = (obj && typeof obj === 'object') ? obj[path[i]] : null;
if (obj == null) {
break;
}
}
if (obj == null && parentModel && !ignoreParent) {
obj = parentModel.get(path);
}
return obj;
},
/**
* @param {string} key
* @param {boolean} [ignoreParent=false]
* @return {*}
*/
getShallow: function (key, ignoreParent) {
var option = this.option;
var val = option && option[key];
var parentModel = this.parentModel;
if (val == null && parentModel && !ignoreParent) {
val = parentModel.getShallow(key);
}
return val;
},
/**
* @param {string} path
* @param {module:echarts/model/Model} [parentModel]
* @return {module:echarts/model/Model}
*/
getModel: function (path, parentModel) {
var obj = this.get(path, true);
var thisParentModel = this.parentModel;
var model = new Model(
obj, parentModel || (thisParentModel && thisParentModel.getModel(path)),
this.ecModel
);
return model;
},
/**
* If model has option
*/
isEmpty: function () {
return this.option == null;
},
restoreData: function () {},
// Pending
clone: function () {
var Ctor = this.constructor;
return new Ctor(zrUtil.clone(this.option));
},
setReadOnly: function (properties) {
clazzUtil.setReadOnly(this, properties);
}
};
// Enable Model.extend.
clazzUtil.enableClassExtend(Model);
var mixin = zrUtil.mixin;
mixin(Model, require('./mixin/lineStyle'));
mixin(Model, require('./mixin/areaStyle'));
mixin(Model, require('./mixin/textStyle'));
mixin(Model, require('./mixin/itemStyle'));
return Model;
});