singleAxisHelper.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. var zrUtil = require("zrender/lib/core/util");
  20. /*
  21. * Licensed to the Apache Software Foundation (ASF) under one
  22. * or more contributor license agreements. See the NOTICE file
  23. * distributed with this work for additional information
  24. * regarding copyright ownership. The ASF licenses this file
  25. * to you under the Apache License, Version 2.0 (the
  26. * "License"); you may not use this file except in compliance
  27. * with the License. You may obtain a copy of the License at
  28. *
  29. * http://www.apache.org/licenses/LICENSE-2.0
  30. *
  31. * Unless required by applicable law or agreed to in writing,
  32. * software distributed under the License is distributed on an
  33. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34. * KIND, either express or implied. See the License for the
  35. * specific language governing permissions and limitations
  36. * under the License.
  37. */
  38. /**
  39. * @param {Object} opt {labelInside}
  40. * @return {Object} {
  41. * position, rotation, labelDirection, labelOffset,
  42. * tickDirection, labelRotate, z2
  43. * }
  44. */
  45. function layout(axisModel, opt) {
  46. opt = opt || {};
  47. var single = axisModel.coordinateSystem;
  48. var axis = axisModel.axis;
  49. var layout = {};
  50. var axisPosition = axis.position;
  51. var orient = axis.orient;
  52. var rect = single.getRect();
  53. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  54. var positionMap = {
  55. horizontal: {
  56. top: rectBound[2],
  57. bottom: rectBound[3]
  58. },
  59. vertical: {
  60. left: rectBound[0],
  61. right: rectBound[1]
  62. }
  63. };
  64. layout.position = [orient === 'vertical' ? positionMap.vertical[axisPosition] : rectBound[0], orient === 'horizontal' ? positionMap.horizontal[axisPosition] : rectBound[3]];
  65. var r = {
  66. horizontal: 0,
  67. vertical: 1
  68. };
  69. layout.rotation = Math.PI / 2 * r[orient];
  70. var directionMap = {
  71. top: -1,
  72. bottom: 1,
  73. right: 1,
  74. left: -1
  75. };
  76. layout.labelDirection = layout.tickDirection = layout.nameDirection = directionMap[axisPosition];
  77. if (axisModel.get('axisTick.inside')) {
  78. layout.tickDirection = -layout.tickDirection;
  79. }
  80. if (zrUtil.retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
  81. layout.labelDirection = -layout.labelDirection;
  82. }
  83. var labelRotation = opt.rotate;
  84. labelRotation == null && (labelRotation = axisModel.get('axisLabel.rotate'));
  85. layout.labelRotation = axisPosition === 'top' ? -labelRotation : labelRotation;
  86. layout.z2 = 1;
  87. return layout;
  88. }
  89. exports.layout = layout;