CartesianAxisView.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 * as graphic from '../../util/graphic.js';
  43. import AxisBuilder from './AxisBuilder.js';
  44. import AxisView from './AxisView.js';
  45. import * as cartesianAxisHelper from '../../coord/cartesian/cartesianAxisHelper.js';
  46. import { rectCoordAxisBuildSplitArea, rectCoordAxisHandleRemove } from './axisSplitHelper.js';
  47. import { isIntervalOrLogScale } from '../../scale/helper.js';
  48. var axisBuilderAttrs = ['axisLine', 'axisTickLabel', 'axisName'];
  49. var selfBuilderAttrs = ['splitArea', 'splitLine', 'minorSplitLine'];
  50. var CartesianAxisView = /** @class */function (_super) {
  51. __extends(CartesianAxisView, _super);
  52. function CartesianAxisView() {
  53. var _this = _super !== null && _super.apply(this, arguments) || this;
  54. _this.type = CartesianAxisView.type;
  55. _this.axisPointerClass = 'CartesianAxisPointer';
  56. return _this;
  57. }
  58. /**
  59. * @override
  60. */
  61. CartesianAxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  62. this.group.removeAll();
  63. var oldAxisGroup = this._axisGroup;
  64. this._axisGroup = new graphic.Group();
  65. this.group.add(this._axisGroup);
  66. if (!axisModel.get('show')) {
  67. return;
  68. }
  69. var gridModel = axisModel.getCoordSysModel();
  70. var layout = cartesianAxisHelper.layout(gridModel, axisModel);
  71. var axisBuilder = new AxisBuilder(axisModel, zrUtil.extend({
  72. handleAutoShown: function (elementType) {
  73. var cartesians = gridModel.coordinateSystem.getCartesians();
  74. for (var i = 0; i < cartesians.length; i++) {
  75. if (isIntervalOrLogScale(cartesians[i].getOtherAxis(axisModel.axis).scale)) {
  76. // Still show axis tick or axisLine if other axis is value / log
  77. return true;
  78. }
  79. }
  80. // Not show axisTick or axisLine if other axis is category / time
  81. return false;
  82. }
  83. }, layout));
  84. zrUtil.each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  85. this._axisGroup.add(axisBuilder.getGroup());
  86. zrUtil.each(selfBuilderAttrs, function (name) {
  87. if (axisModel.get([name, 'show'])) {
  88. axisElementBuilders[name](this, this._axisGroup, axisModel, gridModel);
  89. }
  90. }, this);
  91. // THIS is a special case for bar racing chart.
  92. // Update the axis label from the natural initial layout to
  93. // sorted layout should has no animation.
  94. var isInitialSortFromBarRacing = payload && payload.type === 'changeAxisOrder' && payload.isInitSort;
  95. if (!isInitialSortFromBarRacing) {
  96. graphic.groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  97. }
  98. _super.prototype.render.call(this, axisModel, ecModel, api, payload);
  99. };
  100. CartesianAxisView.prototype.remove = function () {
  101. rectCoordAxisHandleRemove(this);
  102. };
  103. CartesianAxisView.type = 'cartesianAxis';
  104. return CartesianAxisView;
  105. }(AxisView);
  106. var axisElementBuilders = {
  107. splitLine: function (axisView, axisGroup, axisModel, gridModel) {
  108. var axis = axisModel.axis;
  109. if (axis.scale.isBlank()) {
  110. return;
  111. }
  112. var splitLineModel = axisModel.getModel('splitLine');
  113. var lineStyleModel = splitLineModel.getModel('lineStyle');
  114. var lineColors = lineStyleModel.get('color');
  115. lineColors = zrUtil.isArray(lineColors) ? lineColors : [lineColors];
  116. var gridRect = gridModel.coordinateSystem.getRect();
  117. var isHorizontal = axis.isHorizontal();
  118. var lineCount = 0;
  119. var ticksCoords = axis.getTicksCoords({
  120. tickModel: splitLineModel
  121. });
  122. var p1 = [];
  123. var p2 = [];
  124. var lineStyle = lineStyleModel.getLineStyle();
  125. for (var i = 0; i < ticksCoords.length; i++) {
  126. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  127. if (isHorizontal) {
  128. p1[0] = tickCoord;
  129. p1[1] = gridRect.y;
  130. p2[0] = tickCoord;
  131. p2[1] = gridRect.y + gridRect.height;
  132. } else {
  133. p1[0] = gridRect.x;
  134. p1[1] = tickCoord;
  135. p2[0] = gridRect.x + gridRect.width;
  136. p2[1] = tickCoord;
  137. }
  138. var colorIndex = lineCount++ % lineColors.length;
  139. var tickValue = ticksCoords[i].tickValue;
  140. var line = new graphic.Line({
  141. anid: tickValue != null ? 'line_' + ticksCoords[i].tickValue : null,
  142. autoBatch: true,
  143. shape: {
  144. x1: p1[0],
  145. y1: p1[1],
  146. x2: p2[0],
  147. y2: p2[1]
  148. },
  149. style: zrUtil.defaults({
  150. stroke: lineColors[colorIndex]
  151. }, lineStyle),
  152. silent: true
  153. });
  154. graphic.subPixelOptimizeLine(line.shape, lineStyle.lineWidth);
  155. axisGroup.add(line);
  156. }
  157. },
  158. minorSplitLine: function (axisView, axisGroup, axisModel, gridModel) {
  159. var axis = axisModel.axis;
  160. var minorSplitLineModel = axisModel.getModel('minorSplitLine');
  161. var lineStyleModel = minorSplitLineModel.getModel('lineStyle');
  162. var gridRect = gridModel.coordinateSystem.getRect();
  163. var isHorizontal = axis.isHorizontal();
  164. var minorTicksCoords = axis.getMinorTicksCoords();
  165. if (!minorTicksCoords.length) {
  166. return;
  167. }
  168. var p1 = [];
  169. var p2 = [];
  170. var lineStyle = lineStyleModel.getLineStyle();
  171. for (var i = 0; i < minorTicksCoords.length; i++) {
  172. for (var k = 0; k < minorTicksCoords[i].length; k++) {
  173. var tickCoord = axis.toGlobalCoord(minorTicksCoords[i][k].coord);
  174. if (isHorizontal) {
  175. p1[0] = tickCoord;
  176. p1[1] = gridRect.y;
  177. p2[0] = tickCoord;
  178. p2[1] = gridRect.y + gridRect.height;
  179. } else {
  180. p1[0] = gridRect.x;
  181. p1[1] = tickCoord;
  182. p2[0] = gridRect.x + gridRect.width;
  183. p2[1] = tickCoord;
  184. }
  185. var line = new graphic.Line({
  186. anid: 'minor_line_' + minorTicksCoords[i][k].tickValue,
  187. autoBatch: true,
  188. shape: {
  189. x1: p1[0],
  190. y1: p1[1],
  191. x2: p2[0],
  192. y2: p2[1]
  193. },
  194. style: lineStyle,
  195. silent: true
  196. });
  197. graphic.subPixelOptimizeLine(line.shape, lineStyle.lineWidth);
  198. axisGroup.add(line);
  199. }
  200. }
  201. },
  202. splitArea: function (axisView, axisGroup, axisModel, gridModel) {
  203. rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel);
  204. }
  205. };
  206. var CartesianXAxisView = /** @class */function (_super) {
  207. __extends(CartesianXAxisView, _super);
  208. function CartesianXAxisView() {
  209. var _this = _super !== null && _super.apply(this, arguments) || this;
  210. _this.type = CartesianXAxisView.type;
  211. return _this;
  212. }
  213. CartesianXAxisView.type = 'xAxis';
  214. return CartesianXAxisView;
  215. }(CartesianAxisView);
  216. export { CartesianXAxisView };
  217. var CartesianYAxisView = /** @class */function (_super) {
  218. __extends(CartesianYAxisView, _super);
  219. function CartesianYAxisView() {
  220. var _this = _super !== null && _super.apply(this, arguments) || this;
  221. _this.type = CartesianXAxisView.type;
  222. return _this;
  223. }
  224. CartesianYAxisView.type = 'yAxis';
  225. return CartesianYAxisView;
  226. }(CartesianAxisView);
  227. export { CartesianYAxisView };
  228. export default CartesianAxisView;