CartesianAxisView.js 8.3 KB

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