BaseBarSeries.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 SeriesModel from '../../model/Series.js';
  42. import createSeriesData from '../helper/createSeriesData.js';
  43. import { each } from 'zrender/lib/core/util.js';
  44. var BaseBarSeriesModel = /** @class */function (_super) {
  45. __extends(BaseBarSeriesModel, _super);
  46. function BaseBarSeriesModel() {
  47. var _this = _super !== null && _super.apply(this, arguments) || this;
  48. _this.type = BaseBarSeriesModel.type;
  49. return _this;
  50. }
  51. BaseBarSeriesModel.prototype.getInitialData = function (option, ecModel) {
  52. return createSeriesData(null, this, {
  53. useEncodeDefaulter: true
  54. });
  55. };
  56. BaseBarSeriesModel.prototype.getMarkerPosition = function (value, dims, startingAtTick) {
  57. var coordSys = this.coordinateSystem;
  58. if (coordSys && coordSys.clampData) {
  59. // PENDING if clamp ?
  60. var clampData_1 = coordSys.clampData(value);
  61. var pt_1 = coordSys.dataToPoint(clampData_1);
  62. if (startingAtTick) {
  63. each(coordSys.getAxes(), function (axis, idx) {
  64. // If axis type is category, use tick coords instead
  65. if (axis.type === 'category' && dims != null) {
  66. var tickCoords = axis.getTicksCoords();
  67. var alignTicksWithLabel = axis.getTickModel().get('alignWithLabel');
  68. var targetTickId = clampData_1[idx];
  69. // The index of rightmost tick of markArea is 1 larger than x1/y1 index
  70. var isEnd = dims[idx] === 'x1' || dims[idx] === 'y1';
  71. if (isEnd && !alignTicksWithLabel) {
  72. targetTickId += 1;
  73. }
  74. // The only contains one tick, tickCoords is
  75. // like [{coord: 0, tickValue: 0}, {coord: 0}]
  76. // to the length should always be larger than 1
  77. if (tickCoords.length < 2) {
  78. return;
  79. } else if (tickCoords.length === 2) {
  80. // The left value and right value of the axis are
  81. // the same. coord is 0 in both items. Use the max
  82. // value of the axis as the coord
  83. pt_1[idx] = axis.toGlobalCoord(axis.getExtent()[isEnd ? 1 : 0]);
  84. return;
  85. }
  86. var leftCoord = void 0;
  87. var coord = void 0;
  88. var stepTickValue = 1;
  89. for (var i = 0; i < tickCoords.length; i++) {
  90. var tickCoord = tickCoords[i].coord;
  91. // The last item of tickCoords doesn't contain
  92. // tickValue
  93. var tickValue = i === tickCoords.length - 1 ? tickCoords[i - 1].tickValue + stepTickValue : tickCoords[i].tickValue;
  94. if (tickValue === targetTickId) {
  95. coord = tickCoord;
  96. break;
  97. } else if (tickValue < targetTickId) {
  98. leftCoord = tickCoord;
  99. } else if (leftCoord != null && tickValue > targetTickId) {
  100. coord = (tickCoord + leftCoord) / 2;
  101. break;
  102. }
  103. if (i === 1) {
  104. // Here we assume the step of category axes is
  105. // the same
  106. stepTickValue = tickValue - tickCoords[0].tickValue;
  107. }
  108. }
  109. if (coord == null) {
  110. if (!leftCoord) {
  111. // targetTickId is smaller than all tick ids in the
  112. // visible area, use the leftmost tick coord
  113. coord = tickCoords[0].coord;
  114. } else if (leftCoord) {
  115. // targetTickId is larger than all tick ids in the
  116. // visible area, use the rightmost tick coord
  117. coord = tickCoords[tickCoords.length - 1].coord;
  118. }
  119. }
  120. pt_1[idx] = axis.toGlobalCoord(coord);
  121. }
  122. });
  123. } else {
  124. var data = this.getData();
  125. var offset = data.getLayout('offset');
  126. var size = data.getLayout('size');
  127. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  128. pt_1[offsetIndex] += offset + size / 2;
  129. }
  130. return pt_1;
  131. }
  132. return [NaN, NaN];
  133. };
  134. BaseBarSeriesModel.type = 'series.__base_bar__';
  135. BaseBarSeriesModel.defaultOption = {
  136. // zlevel: 0,
  137. z: 2,
  138. coordinateSystem: 'cartesian2d',
  139. legendHoverLink: true,
  140. // stack: null
  141. // Cartesian coordinate system
  142. // xAxisIndex: 0,
  143. // yAxisIndex: 0,
  144. barMinHeight: 0,
  145. barMinAngle: 0,
  146. // cursor: null,
  147. large: false,
  148. largeThreshold: 400,
  149. progressive: 3e3,
  150. progressiveChunkMode: 'mod'
  151. };
  152. return BaseBarSeriesModel;
  153. }(SeriesModel);
  154. SeriesModel.registerClass(BaseBarSeriesModel);
  155. export default BaseBarSeriesModel;