CartesianAxisView.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 =
  51. /** @class */
  52. function (_super) {
  53. __extends(CartesianAxisView, _super);
  54. function CartesianAxisView() {
  55. var _this = _super !== null && _super.apply(this, arguments) || this;
  56. _this.type = CartesianAxisView.type;
  57. _this.axisPointerClass = 'CartesianAxisPointer';
  58. return _this;
  59. }
  60. /**
  61. * @override
  62. */
  63. CartesianAxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  64. this.group.removeAll();
  65. var oldAxisGroup = this._axisGroup;
  66. this._axisGroup = new graphic.Group();
  67. this.group.add(this._axisGroup);
  68. if (!axisModel.get('show')) {
  69. return;
  70. }
  71. var gridModel = axisModel.getCoordSysModel();
  72. var layout = cartesianAxisHelper.layout(gridModel, axisModel);
  73. var axisBuilder = new AxisBuilder(axisModel, zrUtil.extend({
  74. handleAutoShown: function (elementType) {
  75. var cartesians = gridModel.coordinateSystem.getCartesians();
  76. for (var i = 0; i < cartesians.length; i++) {
  77. if (isIntervalOrLogScale(cartesians[i].getOtherAxis(axisModel.axis).scale)) {
  78. // Still show axis tick or axisLine if other axis is value / log
  79. return true;
  80. }
  81. } // Not show axisTick or axisLine if other axis is category / time
  82. return false;
  83. }
  84. }, layout));
  85. zrUtil.each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  86. this._axisGroup.add(axisBuilder.getGroup());
  87. zrUtil.each(selfBuilderAttrs, function (name) {
  88. if (axisModel.get([name, 'show'])) {
  89. axisElementBuilders[name](this, this._axisGroup, axisModel, gridModel);
  90. }
  91. }, this); // 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 =
  207. /** @class */
  208. function (_super) {
  209. __extends(CartesianXAxisView, _super);
  210. function CartesianXAxisView() {
  211. var _this = _super !== null && _super.apply(this, arguments) || this;
  212. _this.type = CartesianXAxisView.type;
  213. return _this;
  214. }
  215. CartesianXAxisView.type = 'xAxis';
  216. return CartesianXAxisView;
  217. }(CartesianAxisView);
  218. export { CartesianXAxisView };
  219. var CartesianYAxisView =
  220. /** @class */
  221. function (_super) {
  222. __extends(CartesianYAxisView, _super);
  223. function CartesianYAxisView() {
  224. var _this = _super !== null && _super.apply(this, arguments) || this;
  225. _this.type = CartesianXAxisView.type;
  226. return _this;
  227. }
  228. CartesianYAxisView.type = 'yAxis';
  229. return CartesianYAxisView;
  230. }(CartesianAxisView);
  231. export { CartesianYAxisView };
  232. export default CartesianAxisView;