whiskerBoxCommon.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 createSeriesDataSimply from './createSeriesDataSimply.js';
  41. import * as zrUtil from 'zrender/lib/core/util.js';
  42. import { getDimensionTypeByAxis } from '../../data/helper/dimensionHelper.js';
  43. import { makeSeriesEncodeForAxisCoordSys } from '../../data/helper/sourceHelper.js';
  44. import { SHAPE_CLIP_KIND_FULLY_CLIPPED, SHAPE_CLIP_KIND_NOT_CLIPPED, SHAPE_CLIP_KIND_PARTIALLY_CLIPPED } from './createClipPathFromCoordSys.js';
  45. var WhiskerBoxCommonMixin = /** @class */function () {
  46. function WhiskerBoxCommonMixin() {}
  47. /**
  48. * @private
  49. */
  50. WhiskerBoxCommonMixin.prototype._hasEncodeRule = function (key) {
  51. var encodeRules = this.getEncode();
  52. return encodeRules && encodeRules.get(key) != null;
  53. };
  54. /**
  55. * @override
  56. */
  57. WhiskerBoxCommonMixin.prototype.getInitialData = function (option, ecModel) {
  58. // When both types of xAxis and yAxis are 'value', layout is
  59. // needed to be specified by user. Otherwise, layout can be
  60. // judged by which axis is category.
  61. var ordinalMeta;
  62. var xAxisModel = ecModel.getComponent('xAxis', this.get('xAxisIndex'));
  63. var yAxisModel = ecModel.getComponent('yAxis', this.get('yAxisIndex'));
  64. var xAxisType = xAxisModel.get('type');
  65. var yAxisType = yAxisModel.get('type');
  66. var addOrdinal;
  67. // Theoretically, if `encode` and/or `layout` are not specified, they can be derived from
  68. // the specified one (also according to axis types). However, only the logic for deriving
  69. // `encode` from `layout` is implemented; the reverse direction is not implemented yet,
  70. // due to its complexity and low priority.
  71. var layout = option.layout;
  72. // 'category' axis has historically been enforcing `layout` regardless of its presence.
  73. // This behavior is preserved until it causes problems.
  74. if (xAxisType === 'category') {
  75. layout = 'horizontal';
  76. ordinalMeta = xAxisModel.getOrdinalMeta();
  77. addOrdinal = !this._hasEncodeRule('x');
  78. } else if (yAxisType === 'category') {
  79. layout = 'vertical';
  80. ordinalMeta = yAxisModel.getOrdinalMeta();
  81. addOrdinal = !this._hasEncodeRule('y');
  82. }
  83. if (!layout) {
  84. layout = yAxisType === 'time' ? 'vertical' : 'horizontal';
  85. // It is theoretically possible for an axis with type "time" to serve as the "value axis".
  86. // `layout` can be explicitly specified for that case.
  87. }
  88. // Do not assign the computed `layout` to `option.layout`, otherwise the idempotent may be broken.
  89. this._layout = layout;
  90. var coordDims = ['x', 'y'];
  91. var baseAxisDimIndex = layout === 'horizontal' ? 0 : 1;
  92. var baseAxisDim = this._baseAxisDim = coordDims[baseAxisDimIndex];
  93. var otherAxisDim = coordDims[1 - baseAxisDimIndex];
  94. var axisModels = [xAxisModel, yAxisModel];
  95. var baseAxisType = axisModels[baseAxisDimIndex].get('type');
  96. var otherAxisType = axisModels[1 - baseAxisDimIndex].get('type');
  97. var data = option.data;
  98. // Clone a new data for next setOption({}) usage.
  99. // Avoid modifying current data will affect further update.
  100. if (data && addOrdinal) {
  101. var newOptionData_1 = [];
  102. zrUtil.each(data, function (item, index) {
  103. var newItem;
  104. if (zrUtil.isArray(item)) {
  105. newItem = item.slice();
  106. // Modify current using data.
  107. item.unshift(index);
  108. } else if (zrUtil.isArray(item.value)) {
  109. newItem = zrUtil.extend({}, item);
  110. newItem.value = newItem.value.slice();
  111. // Modify current using data.
  112. item.value.unshift(index);
  113. } else {
  114. newItem = item;
  115. }
  116. newOptionData_1.push(newItem);
  117. });
  118. option.data = newOptionData_1;
  119. }
  120. var defaultValueDimensions = this.defaultValueDimensions;
  121. var coordDimensions = [{
  122. name: baseAxisDim,
  123. type: getDimensionTypeByAxis(baseAxisType),
  124. ordinalMeta: ordinalMeta,
  125. otherDims: {
  126. tooltip: false,
  127. itemName: 0
  128. },
  129. dimsDef: ['base']
  130. }, {
  131. name: otherAxisDim,
  132. type: getDimensionTypeByAxis(otherAxisType),
  133. dimsDef: defaultValueDimensions.slice()
  134. }];
  135. return createSeriesDataSimply(this, {
  136. coordDimensions: coordDimensions,
  137. dimensionsCount: defaultValueDimensions.length + 1,
  138. encodeDefaulter: zrUtil.curry(makeSeriesEncodeForAxisCoordSys, coordDimensions, this)
  139. });
  140. };
  141. /**
  142. * If horizontal, base axis is x, otherwise y.
  143. * @override
  144. */
  145. WhiskerBoxCommonMixin.prototype.getBaseAxis = function () {
  146. var dim = this._baseAxisDim;
  147. return this.ecModel.getComponent(dim + 'Axis', this.get(dim + 'AxisIndex')).axis;
  148. };
  149. WhiskerBoxCommonMixin.prototype.getWhiskerBoxesLayout = function () {
  150. return this._layout;
  151. };
  152. return WhiskerBoxCommonMixin;
  153. }();
  154. export { WhiskerBoxCommonMixin };
  155. ;
  156. /**
  157. * PENDING: We do not use zr Element clipPath due to performance consideration,
  158. * although it may be further optimized.
  159. */
  160. export function resolveNormalBoxClipping(clipArea, itemLayout) {
  161. var count = itemLayout.ends.length;
  162. var containCount = 0;
  163. for (var i = 0; i < count; i++) {
  164. // clip if any points is out of the area, otherwise the shape may partially
  165. // out of the coord sys area and overlap with axis labels.
  166. if (clipArea.contain(itemLayout.ends[i][0], itemLayout.ends[i][1])) {
  167. containCount++;
  168. }
  169. }
  170. return !containCount ? SHAPE_CLIP_KIND_FULLY_CLIPPED : containCount < count ? SHAPE_CLIP_KIND_PARTIALLY_CLIPPED : SHAPE_CLIP_KIND_NOT_CLIPPED;
  171. }