Model.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import env from 'zrender/lib/core/env.js';
  41. import { enableClassExtend, enableClassCheck } from '../util/clazz.js';
  42. import { AreaStyleMixin } from './mixin/areaStyle.js';
  43. import TextStyleMixin from './mixin/textStyle.js';
  44. import { LineStyleMixin } from './mixin/lineStyle.js';
  45. import { ItemStyleMixin } from './mixin/itemStyle.js';
  46. import { mixin, clone, merge } from 'zrender/lib/core/util.js';
  47. var Model =
  48. /** @class */
  49. function () {
  50. function Model(option, parentModel, ecModel) {
  51. this.parentModel = parentModel;
  52. this.ecModel = ecModel;
  53. this.option = option; // Simple optimization
  54. // if (this.init) {
  55. // if (arguments.length <= 4) {
  56. // this.init(option, parentModel, ecModel, extraOpt);
  57. // }
  58. // else {
  59. // this.init.apply(this, arguments);
  60. // }
  61. // }
  62. }
  63. Model.prototype.init = function (option, parentModel, ecModel) {
  64. var rest = [];
  65. for (var _i = 3; _i < arguments.length; _i++) {
  66. rest[_i - 3] = arguments[_i];
  67. }
  68. };
  69. /**
  70. * Merge the input option to me.
  71. */
  72. Model.prototype.mergeOption = function (option, ecModel) {
  73. merge(this.option, option, true);
  74. }; // `path` can be 'a.b.c', so the return value type have to be `ModelOption`
  75. // TODO: TYPE strict key check?
  76. // get(path: string | string[], ignoreParent?: boolean): ModelOption;
  77. Model.prototype.get = function (path, ignoreParent) {
  78. if (path == null) {
  79. return this.option;
  80. }
  81. return this._doGet(this.parsePath(path), !ignoreParent && this.parentModel);
  82. };
  83. Model.prototype.getShallow = function (key, ignoreParent) {
  84. var option = this.option;
  85. var val = option == null ? option : option[key];
  86. if (val == null && !ignoreParent) {
  87. var parentModel = this.parentModel;
  88. if (parentModel) {
  89. // FIXME:TS do not know how to make it works
  90. val = parentModel.getShallow(key);
  91. }
  92. }
  93. return val;
  94. }; // `path` can be 'a.b.c', so the return value type have to be `Model<ModelOption>`
  95. // getModel(path: string | string[], parentModel?: Model): Model;
  96. // TODO 'a.b.c' is deprecated
  97. Model.prototype.getModel = function (path, parentModel) {
  98. var hasPath = path != null;
  99. var pathFinal = hasPath ? this.parsePath(path) : null;
  100. var obj = hasPath ? this._doGet(pathFinal) : this.option;
  101. parentModel = parentModel || this.parentModel && this.parentModel.getModel(this.resolveParentPath(pathFinal));
  102. return new Model(obj, parentModel, this.ecModel);
  103. };
  104. /**
  105. * If model has option
  106. */
  107. Model.prototype.isEmpty = function () {
  108. return this.option == null;
  109. };
  110. Model.prototype.restoreData = function () {}; // Pending
  111. Model.prototype.clone = function () {
  112. var Ctor = this.constructor;
  113. return new Ctor(clone(this.option));
  114. }; // setReadOnly(properties): void {
  115. // clazzUtil.setReadOnly(this, properties);
  116. // }
  117. // If path is null/undefined, return null/undefined.
  118. Model.prototype.parsePath = function (path) {
  119. if (typeof path === 'string') {
  120. return path.split('.');
  121. }
  122. return path;
  123. }; // Resolve path for parent. Perhaps useful when parent use a different property.
  124. // Default to be a identity resolver.
  125. // Can be modified to a different resolver.
  126. Model.prototype.resolveParentPath = function (path) {
  127. return path;
  128. }; // FIXME:TS check whether put this method here
  129. Model.prototype.isAnimationEnabled = function () {
  130. if (!env.node && this.option) {
  131. if (this.option.animation != null) {
  132. return !!this.option.animation;
  133. } else if (this.parentModel) {
  134. return this.parentModel.isAnimationEnabled();
  135. }
  136. }
  137. };
  138. Model.prototype._doGet = function (pathArr, parentModel) {
  139. var obj = this.option;
  140. if (!pathArr) {
  141. return obj;
  142. }
  143. for (var i = 0; i < pathArr.length; i++) {
  144. // Ignore empty
  145. if (!pathArr[i]) {
  146. continue;
  147. } // obj could be number/string/... (like 0)
  148. obj = obj && typeof obj === 'object' ? obj[pathArr[i]] : null;
  149. if (obj == null) {
  150. break;
  151. }
  152. }
  153. if (obj == null && parentModel) {
  154. obj = parentModel._doGet(this.resolveParentPath(pathArr), parentModel.parentModel);
  155. }
  156. return obj;
  157. };
  158. return Model;
  159. }();
  160. ; // Enable Model.extend.
  161. enableClassExtend(Model);
  162. enableClassCheck(Model);
  163. mixin(Model, LineStyleMixin);
  164. mixin(Model, ItemStyleMixin);
  165. mixin(Model, AreaStyleMixin);
  166. mixin(Model, TextStyleMixin);
  167. export default Model;