singleAxisHelper.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var zrUtil = require("zrender/lib/core/util");
  2. /**
  3. * @param {Object} opt {labelInside}
  4. * @return {Object} {
  5. * position, rotation, labelDirection, labelOffset,
  6. * tickDirection, labelRotate, labelInterval, z2
  7. * }
  8. */
  9. function layout(axisModel, opt) {
  10. opt = opt || {};
  11. var single = axisModel.coordinateSystem;
  12. var axis = axisModel.axis;
  13. var layout = {};
  14. var axisPosition = axis.position;
  15. var orient = axis.orient;
  16. var rect = single.getRect();
  17. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  18. var positionMap = {
  19. horizontal: {
  20. top: rectBound[2],
  21. bottom: rectBound[3]
  22. },
  23. vertical: {
  24. left: rectBound[0],
  25. right: rectBound[1]
  26. }
  27. };
  28. layout.position = [orient === 'vertical' ? positionMap.vertical[axisPosition] : rectBound[0], orient === 'horizontal' ? positionMap.horizontal[axisPosition] : rectBound[3]];
  29. var r = {
  30. horizontal: 0,
  31. vertical: 1
  32. };
  33. layout.rotation = Math.PI / 2 * r[orient];
  34. var directionMap = {
  35. top: -1,
  36. bottom: 1,
  37. right: 1,
  38. left: -1
  39. };
  40. layout.labelDirection = layout.tickDirection = layout.nameDirection = directionMap[axisPosition];
  41. if (axisModel.get('axisTick.inside')) {
  42. layout.tickDirection = -layout.tickDirection;
  43. }
  44. if (zrUtil.retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
  45. layout.labelDirection = -layout.labelDirection;
  46. }
  47. var labelRotation = opt.rotate;
  48. labelRotation == null && (labelRotation = axisModel.get('axisLabel.rotate'));
  49. layout.labelRotation = axisPosition === 'top' ? -labelRotation : labelRotation;
  50. layout.labelInterval = axis.getLabelInterval();
  51. layout.z2 = 1;
  52. return layout;
  53. }
  54. exports.layout = layout;