whiskerBoxCommon.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. var WhiskerBoxCommonMixin = /** @class */function () {
  45. function WhiskerBoxCommonMixin() {}
  46. /**
  47. * @override
  48. */
  49. WhiskerBoxCommonMixin.prototype.getInitialData = function (option, ecModel) {
  50. // When both types of xAxis and yAxis are 'value', layout is
  51. // needed to be specified by user. Otherwise, layout can be
  52. // judged by which axis is category.
  53. var ordinalMeta;
  54. var xAxisModel = ecModel.getComponent('xAxis', this.get('xAxisIndex'));
  55. var yAxisModel = ecModel.getComponent('yAxis', this.get('yAxisIndex'));
  56. var xAxisType = xAxisModel.get('type');
  57. var yAxisType = yAxisModel.get('type');
  58. var addOrdinal;
  59. // FIXME
  60. // Consider time axis.
  61. if (xAxisType === 'category') {
  62. option.layout = 'horizontal';
  63. ordinalMeta = xAxisModel.getOrdinalMeta();
  64. addOrdinal = true;
  65. } else if (yAxisType === 'category') {
  66. option.layout = 'vertical';
  67. ordinalMeta = yAxisModel.getOrdinalMeta();
  68. addOrdinal = true;
  69. } else {
  70. option.layout = option.layout || 'horizontal';
  71. }
  72. var coordDims = ['x', 'y'];
  73. var baseAxisDimIndex = option.layout === 'horizontal' ? 0 : 1;
  74. var baseAxisDim = this._baseAxisDim = coordDims[baseAxisDimIndex];
  75. var otherAxisDim = coordDims[1 - baseAxisDimIndex];
  76. var axisModels = [xAxisModel, yAxisModel];
  77. var baseAxisType = axisModels[baseAxisDimIndex].get('type');
  78. var otherAxisType = axisModels[1 - baseAxisDimIndex].get('type');
  79. var data = option.data;
  80. // Clone a new data for next setOption({}) usage.
  81. // Avoid modifying current data will affect further update.
  82. if (data && addOrdinal) {
  83. var newOptionData_1 = [];
  84. zrUtil.each(data, function (item, index) {
  85. var newItem;
  86. if (zrUtil.isArray(item)) {
  87. newItem = item.slice();
  88. // Modify current using data.
  89. item.unshift(index);
  90. } else if (zrUtil.isArray(item.value)) {
  91. newItem = zrUtil.extend({}, item);
  92. newItem.value = newItem.value.slice();
  93. // Modify current using data.
  94. item.value.unshift(index);
  95. } else {
  96. newItem = item;
  97. }
  98. newOptionData_1.push(newItem);
  99. });
  100. option.data = newOptionData_1;
  101. }
  102. var defaultValueDimensions = this.defaultValueDimensions;
  103. var coordDimensions = [{
  104. name: baseAxisDim,
  105. type: getDimensionTypeByAxis(baseAxisType),
  106. ordinalMeta: ordinalMeta,
  107. otherDims: {
  108. tooltip: false,
  109. itemName: 0
  110. },
  111. dimsDef: ['base']
  112. }, {
  113. name: otherAxisDim,
  114. type: getDimensionTypeByAxis(otherAxisType),
  115. dimsDef: defaultValueDimensions.slice()
  116. }];
  117. return createSeriesDataSimply(this, {
  118. coordDimensions: coordDimensions,
  119. dimensionsCount: defaultValueDimensions.length + 1,
  120. encodeDefaulter: zrUtil.curry(makeSeriesEncodeForAxisCoordSys, coordDimensions, this)
  121. });
  122. };
  123. /**
  124. * If horizontal, base axis is x, otherwise y.
  125. * @override
  126. */
  127. WhiskerBoxCommonMixin.prototype.getBaseAxis = function () {
  128. var dim = this._baseAxisDim;
  129. return this.ecModel.getComponent(dim + 'Axis', this.get(dim + 'AxisIndex')).axis;
  130. };
  131. return WhiskerBoxCommonMixin;
  132. }();
  133. ;
  134. export { WhiskerBoxCommonMixin };