MarkerModel.js 6.2 KB

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