axisSplitHelper.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 * as zrUtil from 'zrender/lib/core/util.js';
  41. import * as graphic from '../../util/graphic.js';
  42. import { makeInner } from '../../util/model.js';
  43. var inner = makeInner();
  44. export function rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel) {
  45. var axis = axisModel.axis;
  46. if (axis.scale.isBlank()) {
  47. return;
  48. }
  49. // TODO: TYPE
  50. var splitAreaModel = axisModel.getModel('splitArea');
  51. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  52. var areaColors = areaStyleModel.get('color');
  53. var gridRect = gridModel.coordinateSystem.getRect();
  54. var ticksCoords = axis.getTicksCoords({
  55. tickModel: splitAreaModel,
  56. clamp: true,
  57. breakTicks: 'none',
  58. pruneByBreak: 'preserve_extent_bound'
  59. });
  60. if (!ticksCoords.length) {
  61. return;
  62. }
  63. // For Making appropriate splitArea animation, the color and anid
  64. // should be corresponding to previous one if possible.
  65. var areaColorsLen = areaColors.length;
  66. var lastSplitAreaColors = inner(axisView).splitAreaColors;
  67. var newSplitAreaColors = zrUtil.createHashMap();
  68. var colorIndex = 0;
  69. if (lastSplitAreaColors) {
  70. for (var i = 0; i < ticksCoords.length; i++) {
  71. var cIndex = lastSplitAreaColors.get(ticksCoords[i].tickValue);
  72. if (cIndex != null) {
  73. colorIndex = (cIndex + (areaColorsLen - 1) * i) % areaColorsLen;
  74. break;
  75. }
  76. }
  77. }
  78. var prev = axis.toGlobalCoord(ticksCoords[0].coord);
  79. var areaStyle = areaStyleModel.getAreaStyle();
  80. areaColors = zrUtil.isArray(areaColors) ? areaColors : [areaColors];
  81. for (var i = 1; i < ticksCoords.length; i++) {
  82. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  83. var x = void 0;
  84. var y = void 0;
  85. var width = void 0;
  86. var height = void 0;
  87. if (axis.isHorizontal()) {
  88. x = prev;
  89. y = gridRect.y;
  90. width = tickCoord - x;
  91. height = gridRect.height;
  92. prev = x + width;
  93. } else {
  94. x = gridRect.x;
  95. y = prev;
  96. width = gridRect.width;
  97. height = tickCoord - y;
  98. prev = y + height;
  99. }
  100. var tickValue = ticksCoords[i - 1].tickValue;
  101. tickValue != null && newSplitAreaColors.set(tickValue, colorIndex);
  102. axisGroup.add(new graphic.Rect({
  103. anid: tickValue != null ? 'area_' + tickValue : null,
  104. shape: {
  105. x: x,
  106. y: y,
  107. width: width,
  108. height: height
  109. },
  110. style: zrUtil.defaults({
  111. fill: areaColors[colorIndex]
  112. }, areaStyle),
  113. autoBatch: true,
  114. silent: true
  115. }));
  116. colorIndex = (colorIndex + 1) % areaColorsLen;
  117. }
  118. inner(axisView).splitAreaColors = newSplitAreaColors;
  119. }
  120. export function rectCoordAxisHandleRemove(axisView) {
  121. inner(axisView).splitAreaColors = null;
  122. }