SingleAxisView.js 5.4 KB

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