CartesianAxisView.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. var showMinLine = splitLineModel.get('showMinLine') !== false;
  116. var showMaxLine = splitLineModel.get('showMaxLine') !== false;
  117. lineColors = zrUtil.isArray(lineColors) ? lineColors : [lineColors];
  118. var gridRect = gridModel.coordinateSystem.getRect();
  119. var isHorizontal = axis.isHorizontal();
  120. var lineCount = 0;
  121. var ticksCoords = axis.getTicksCoords({
  122. tickModel: splitLineModel
  123. });
  124. var p1 = [];
  125. var p2 = [];
  126. var lineStyle = lineStyleModel.getLineStyle();
  127. for (var i = 0; i < ticksCoords.length; i++) {
  128. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  129. if (i === 0 && !showMinLine || i === ticksCoords.length - 1 && !showMaxLine) {
  130. continue;
  131. }
  132. var tickValue = ticksCoords[i].tickValue;
  133. if (isHorizontal) {
  134. p1[0] = tickCoord;
  135. p1[1] = gridRect.y;
  136. p2[0] = tickCoord;
  137. p2[1] = gridRect.y + gridRect.height;
  138. } else {
  139. p1[0] = gridRect.x;
  140. p1[1] = tickCoord;
  141. p2[0] = gridRect.x + gridRect.width;
  142. p2[1] = tickCoord;
  143. }
  144. var colorIndex = lineCount++ % lineColors.length;
  145. var line = new graphic.Line({
  146. anid: tickValue != null ? 'line_' + tickValue : null,
  147. autoBatch: true,
  148. shape: {
  149. x1: p1[0],
  150. y1: p1[1],
  151. x2: p2[0],
  152. y2: p2[1]
  153. },
  154. style: zrUtil.defaults({
  155. stroke: lineColors[colorIndex]
  156. }, lineStyle),
  157. silent: true
  158. });
  159. graphic.subPixelOptimizeLine(line.shape, lineStyle.lineWidth);
  160. axisGroup.add(line);
  161. }
  162. },
  163. minorSplitLine: function (axisView, axisGroup, axisModel, gridModel) {
  164. var axis = axisModel.axis;
  165. var minorSplitLineModel = axisModel.getModel('minorSplitLine');
  166. var lineStyleModel = minorSplitLineModel.getModel('lineStyle');
  167. var gridRect = gridModel.coordinateSystem.getRect();
  168. var isHorizontal = axis.isHorizontal();
  169. var minorTicksCoords = axis.getMinorTicksCoords();
  170. if (!minorTicksCoords.length) {
  171. return;
  172. }
  173. var p1 = [];
  174. var p2 = [];
  175. var lineStyle = lineStyleModel.getLineStyle();
  176. for (var i = 0; i < minorTicksCoords.length; i++) {
  177. for (var k = 0; k < minorTicksCoords[i].length; k++) {
  178. var tickCoord = axis.toGlobalCoord(minorTicksCoords[i][k].coord);
  179. if (isHorizontal) {
  180. p1[0] = tickCoord;
  181. p1[1] = gridRect.y;
  182. p2[0] = tickCoord;
  183. p2[1] = gridRect.y + gridRect.height;
  184. } else {
  185. p1[0] = gridRect.x;
  186. p1[1] = tickCoord;
  187. p2[0] = gridRect.x + gridRect.width;
  188. p2[1] = tickCoord;
  189. }
  190. var line = new graphic.Line({
  191. anid: 'minor_line_' + minorTicksCoords[i][k].tickValue,
  192. autoBatch: true,
  193. shape: {
  194. x1: p1[0],
  195. y1: p1[1],
  196. x2: p2[0],
  197. y2: p2[1]
  198. },
  199. style: lineStyle,
  200. silent: true
  201. });
  202. graphic.subPixelOptimizeLine(line.shape, lineStyle.lineWidth);
  203. axisGroup.add(line);
  204. }
  205. }
  206. },
  207. splitArea: function (axisView, axisGroup, axisModel, gridModel) {
  208. rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel);
  209. }
  210. };
  211. var CartesianXAxisView = /** @class */function (_super) {
  212. __extends(CartesianXAxisView, _super);
  213. function CartesianXAxisView() {
  214. var _this = _super !== null && _super.apply(this, arguments) || this;
  215. _this.type = CartesianXAxisView.type;
  216. return _this;
  217. }
  218. CartesianXAxisView.type = 'xAxis';
  219. return CartesianXAxisView;
  220. }(CartesianAxisView);
  221. export { CartesianXAxisView };
  222. var CartesianYAxisView = /** @class */function (_super) {
  223. __extends(CartesianYAxisView, _super);
  224. function CartesianYAxisView() {
  225. var _this = _super !== null && _super.apply(this, arguments) || this;
  226. _this.type = CartesianXAxisView.type;
  227. return _this;
  228. }
  229. CartesianYAxisView.type = 'yAxis';
  230. return CartesianYAxisView;
  231. }(CartesianAxisView);
  232. export { CartesianYAxisView };
  233. export default CartesianAxisView;