SingleAxisView.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 AxisBuilder from './AxisBuilder.js';
  43. import * as graphic from '../../util/graphic.js';
  44. import * as singleAxisHelper from '../../coord/single/singleAxisHelper.js';
  45. import AxisView from './AxisView.js';
  46. import { rectCoordAxisBuildSplitArea, rectCoordAxisHandleRemove } from './axisSplitHelper.js';
  47. var axisBuilderAttrs = ['axisLine', 'axisTickLabel', 'axisName'];
  48. var selfBuilderAttrs = ['splitArea', 'splitLine'];
  49. var SingleAxisView = /** @class */function (_super) {
  50. __extends(SingleAxisView, _super);
  51. function SingleAxisView() {
  52. var _this = _super !== null && _super.apply(this, arguments) || this;
  53. _this.type = SingleAxisView.type;
  54. _this.axisPointerClass = 'SingleAxisPointer';
  55. return _this;
  56. }
  57. SingleAxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  58. var group = this.group;
  59. group.removeAll();
  60. var oldAxisGroup = this._axisGroup;
  61. this._axisGroup = new graphic.Group();
  62. var layout = singleAxisHelper.layout(axisModel);
  63. var axisBuilder = new AxisBuilder(axisModel, layout);
  64. zrUtil.each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  65. group.add(this._axisGroup);
  66. group.add(axisBuilder.getGroup());
  67. zrUtil.each(selfBuilderAttrs, function (name) {
  68. if (axisModel.get([name, 'show'])) {
  69. axisElementBuilders[name](this, this.group, this._axisGroup, axisModel);
  70. }
  71. }, this);
  72. graphic.groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  73. _super.prototype.render.call(this, axisModel, ecModel, api, payload);
  74. };
  75. SingleAxisView.prototype.remove = function () {
  76. rectCoordAxisHandleRemove(this);
  77. };
  78. SingleAxisView.type = 'singleAxis';
  79. return SingleAxisView;
  80. }(AxisView);
  81. var axisElementBuilders = {
  82. splitLine: function (axisView, group, axisGroup, axisModel) {
  83. var axis = axisModel.axis;
  84. if (axis.scale.isBlank()) {
  85. return;
  86. }
  87. var splitLineModel = axisModel.getModel('splitLine');
  88. var lineStyleModel = splitLineModel.getModel('lineStyle');
  89. var lineColors = lineStyleModel.get('color');
  90. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  91. var lineWidth = lineStyleModel.get('width');
  92. var gridRect = axisModel.coordinateSystem.getRect();
  93. var isHorizontal = axis.isHorizontal();
  94. var splitLines = [];
  95. var lineCount = 0;
  96. var ticksCoords = axis.getTicksCoords({
  97. tickModel: splitLineModel
  98. });
  99. var p1 = [];
  100. var p2 = [];
  101. for (var i = 0; i < ticksCoords.length; ++i) {
  102. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  103. if (isHorizontal) {
  104. p1[0] = tickCoord;
  105. p1[1] = gridRect.y;
  106. p2[0] = tickCoord;
  107. p2[1] = gridRect.y + gridRect.height;
  108. } else {
  109. p1[0] = gridRect.x;
  110. p1[1] = tickCoord;
  111. p2[0] = gridRect.x + gridRect.width;
  112. p2[1] = tickCoord;
  113. }
  114. var line = new graphic.Line({
  115. shape: {
  116. x1: p1[0],
  117. y1: p1[1],
  118. x2: p2[0],
  119. y2: p2[1]
  120. },
  121. silent: true
  122. });
  123. graphic.subPixelOptimizeLine(line.shape, lineWidth);
  124. var colorIndex = lineCount++ % lineColors.length;
  125. splitLines[colorIndex] = splitLines[colorIndex] || [];
  126. splitLines[colorIndex].push(line);
  127. }
  128. var lineStyle = lineStyleModel.getLineStyle(['color']);
  129. for (var i = 0; i < splitLines.length; ++i) {
  130. group.add(graphic.mergePath(splitLines[i], {
  131. style: zrUtil.defaults({
  132. stroke: lineColors[i % lineColors.length]
  133. }, lineStyle),
  134. silent: true
  135. }));
  136. }
  137. },
  138. splitArea: function (axisView, group, axisGroup, axisModel) {
  139. rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, axisModel);
  140. }
  141. };
  142. export default SingleAxisView;