axisSplitHelper.js 4.2 KB

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