BaseBarSeries.js 6.0 KB

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