axisSplitHelper.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. });
  58. if (!ticksCoords.length) {
  59. return;
  60. }
  61. // For Making appropriate splitArea animation, the color and anid
  62. // should be corresponding to previous one if possible.
  63. var areaColorsLen = areaColors.length;
  64. var lastSplitAreaColors = inner(axisView).splitAreaColors;
  65. var newSplitAreaColors = zrUtil.createHashMap();
  66. var colorIndex = 0;
  67. if (lastSplitAreaColors) {
  68. for (var i = 0; i < ticksCoords.length; i++) {
  69. var cIndex = lastSplitAreaColors.get(ticksCoords[i].tickValue);
  70. if (cIndex != null) {
  71. colorIndex = (cIndex + (areaColorsLen - 1) * i) % areaColorsLen;
  72. break;
  73. }
  74. }
  75. }
  76. var prev = axis.toGlobalCoord(ticksCoords[0].coord);
  77. var areaStyle = areaStyleModel.getAreaStyle();
  78. areaColors = zrUtil.isArray(areaColors) ? areaColors : [areaColors];
  79. for (var i = 1; i < ticksCoords.length; i++) {
  80. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  81. var x = void 0;
  82. var y = void 0;
  83. var width = void 0;
  84. var height = void 0;
  85. if (axis.isHorizontal()) {
  86. x = prev;
  87. y = gridRect.y;
  88. width = tickCoord - x;
  89. height = gridRect.height;
  90. prev = x + width;
  91. } else {
  92. x = gridRect.x;
  93. y = prev;
  94. width = gridRect.width;
  95. height = tickCoord - y;
  96. prev = y + height;
  97. }
  98. var tickValue = ticksCoords[i - 1].tickValue;
  99. tickValue != null && newSplitAreaColors.set(tickValue, colorIndex);
  100. axisGroup.add(new graphic.Rect({
  101. anid: tickValue != null ? 'area_' + tickValue : null,
  102. shape: {
  103. x: x,
  104. y: y,
  105. width: width,
  106. height: height
  107. },
  108. style: zrUtil.defaults({
  109. fill: areaColors[colorIndex]
  110. }, areaStyle),
  111. autoBatch: true,
  112. silent: true
  113. }));
  114. colorIndex = (colorIndex + 1) % areaColorsLen;
  115. }
  116. inner(axisView).splitAreaColors = newSplitAreaColors;
  117. }
  118. export function rectCoordAxisHandleRemove(axisView) {
  119. inner(axisView).splitAreaColors = null;
  120. }