MarkerModel.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 { __extends } from "tslib";
  41. import * as zrUtil from 'zrender/lib/core/util.js';
  42. import env from 'zrender/lib/core/env.js';
  43. import { DataFormatMixin } from '../../model/mixin/dataFormat.js';
  44. import ComponentModel from '../../model/Component.js';
  45. import { makeInner, defaultEmphasis } from '../../util/model.js';
  46. import { createTooltipMarkup } from '../tooltip/tooltipMarkup.js';
  47. function fillLabel(opt) {
  48. defaultEmphasis(opt, 'label', ['show']);
  49. }
  50. // { [componentType]: MarkerModel }
  51. var inner = makeInner();
  52. var MarkerModel = /** @class */function (_super) {
  53. __extends(MarkerModel, _super);
  54. function MarkerModel() {
  55. var _this = _super !== null && _super.apply(this, arguments) || this;
  56. _this.type = MarkerModel.type;
  57. /**
  58. * If marker model is created by self from series
  59. */
  60. _this.createdBySelf = false;
  61. _this.preventAutoZ = true;
  62. return _this;
  63. }
  64. /**
  65. * @overrite
  66. */
  67. MarkerModel.prototype.init = function (option, parentModel, ecModel) {
  68. if (process.env.NODE_ENV !== 'production') {
  69. if (this.type === 'marker') {
  70. throw new Error('Marker component is abstract component. Use markLine, markPoint, markArea instead.');
  71. }
  72. }
  73. this.mergeDefaultAndTheme(option, ecModel);
  74. this._mergeOption(option, ecModel, false, true);
  75. };
  76. MarkerModel.prototype.isAnimationEnabled = function () {
  77. if (env.node) {
  78. return false;
  79. }
  80. var hostSeries = this.__hostSeries;
  81. return this.getShallow('animation') && hostSeries && hostSeries.isAnimationEnabled();
  82. };
  83. /**
  84. * @overrite
  85. */
  86. MarkerModel.prototype.mergeOption = function (newOpt, ecModel) {
  87. this._mergeOption(newOpt, ecModel, false, false);
  88. };
  89. MarkerModel.prototype._mergeOption = function (newOpt, ecModel, createdBySelf, isInit) {
  90. var componentType = this.mainType;
  91. if (!createdBySelf) {
  92. ecModel.eachSeries(function (seriesModel) {
  93. // mainType can be markPoint, markLine, markArea
  94. var markerOpt = seriesModel.get(this.mainType, true);
  95. var markerModel = inner(seriesModel)[componentType];
  96. if (!markerOpt || !markerOpt.data) {
  97. inner(seriesModel)[componentType] = null;
  98. return;
  99. }
  100. if (!markerModel) {
  101. if (isInit) {
  102. // Default label emphasis `position` and `show`
  103. fillLabel(markerOpt);
  104. }
  105. zrUtil.each(markerOpt.data, function (item) {
  106. // FIXME Overwrite fillLabel method ?
  107. if (item instanceof Array) {
  108. fillLabel(item[0]);
  109. fillLabel(item[1]);
  110. } else {
  111. fillLabel(item);
  112. }
  113. });
  114. markerModel = this.createMarkerModelFromSeries(markerOpt, this, ecModel);
  115. // markerModel = new ImplementedMarkerModel(
  116. // markerOpt, this, ecModel
  117. // );
  118. zrUtil.extend(markerModel, {
  119. mainType: this.mainType,
  120. // Use the same series index and name
  121. seriesIndex: seriesModel.seriesIndex,
  122. name: seriesModel.name,
  123. createdBySelf: true
  124. });
  125. markerModel.__hostSeries = seriesModel;
  126. } else {
  127. markerModel._mergeOption(markerOpt, ecModel, true);
  128. }
  129. inner(seriesModel)[componentType] = markerModel;
  130. }, this);
  131. }
  132. };
  133. MarkerModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  134. var data = this.getData();
  135. var value = this.getRawValue(dataIndex);
  136. var itemName = data.getName(dataIndex);
  137. return createTooltipMarkup('section', {
  138. header: this.name,
  139. blocks: [createTooltipMarkup('nameValue', {
  140. name: itemName,
  141. value: value,
  142. noName: !itemName,
  143. noValue: value == null
  144. })]
  145. });
  146. };
  147. MarkerModel.prototype.getData = function () {
  148. return this._data;
  149. };
  150. MarkerModel.prototype.setData = function (data) {
  151. this._data = data;
  152. };
  153. MarkerModel.prototype.getDataParams = function (dataIndex, dataType) {
  154. var params = DataFormatMixin.prototype.getDataParams.call(this, dataIndex, dataType);
  155. var hostSeries = this.__hostSeries;
  156. if (hostSeries) {
  157. params.seriesId = hostSeries.id;
  158. params.seriesName = hostSeries.name;
  159. params.seriesType = hostSeries.subType;
  160. }
  161. return params;
  162. };
  163. MarkerModel.getMarkerModelFromSeries = function (seriesModel,
  164. // Support three types of markers. Strict check.
  165. componentType) {
  166. return inner(seriesModel)[componentType];
  167. };
  168. MarkerModel.type = 'marker';
  169. MarkerModel.dependencies = ['series', 'grid', 'polar', 'geo'];
  170. return MarkerModel;
  171. }(ComponentModel);
  172. zrUtil.mixin(MarkerModel, DataFormatMixin.prototype);
  173. export default MarkerModel;