MarkerModel.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. } // { [componentType]: MarkerModel }
  50. var inner = makeInner();
  51. var MarkerModel =
  52. /** @class */
  53. function (_super) {
  54. __extends(MarkerModel, _super);
  55. function MarkerModel() {
  56. var _this = _super !== null && _super.apply(this, arguments) || this;
  57. _this.type = MarkerModel.type;
  58. /**
  59. * If marker model is created by self from series
  60. */
  61. _this.createdBySelf = false;
  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); // 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.getMarkerModelFromSeries = function (seriesModel, // Support three types of markers. Strict check.
  153. componentType) {
  154. return inner(seriesModel)[componentType];
  155. };
  156. MarkerModel.type = 'marker';
  157. MarkerModel.dependencies = ['series', 'grid', 'polar', 'geo'];
  158. return MarkerModel;
  159. }(ComponentModel);
  160. zrUtil.mixin(MarkerModel, DataFormatMixin.prototype);
  161. export default MarkerModel;