whiskerBoxCommon.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. var createListSimply = require("../helper/createListSimply");
  20. var zrUtil = require("zrender/lib/core/util");
  21. var _dimensionHelper = require("../../data/helper/dimensionHelper");
  22. var getDimensionTypeByAxis = _dimensionHelper.getDimensionTypeByAxis;
  23. var _sourceHelper = require("../../data/helper/sourceHelper");
  24. var makeSeriesEncodeForAxisCoordSys = _sourceHelper.makeSeriesEncodeForAxisCoordSys;
  25. /*
  26. * Licensed to the Apache Software Foundation (ASF) under one
  27. * or more contributor license agreements. See the NOTICE file
  28. * distributed with this work for additional information
  29. * regarding copyright ownership. The ASF licenses this file
  30. * to you under the Apache License, Version 2.0 (the
  31. * "License"); you may not use this file except in compliance
  32. * with the License. You may obtain a copy of the License at
  33. *
  34. * http://www.apache.org/licenses/LICENSE-2.0
  35. *
  36. * Unless required by applicable law or agreed to in writing,
  37. * software distributed under the License is distributed on an
  38. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39. * KIND, either express or implied. See the License for the
  40. * specific language governing permissions and limitations
  41. * under the License.
  42. */
  43. var seriesModelMixin = {
  44. /**
  45. * @private
  46. * @type {string}
  47. */
  48. _baseAxisDim: null,
  49. /**
  50. * @override
  51. */
  52. getInitialData: function (option, ecModel) {
  53. // When both types of xAxis and yAxis are 'value', layout is
  54. // needed to be specified by user. Otherwise, layout can be
  55. // judged by which axis is category.
  56. var ordinalMeta;
  57. var xAxisModel = ecModel.getComponent('xAxis', this.get('xAxisIndex'));
  58. var yAxisModel = ecModel.getComponent('yAxis', this.get('yAxisIndex'));
  59. var xAxisType = xAxisModel.get('type');
  60. var yAxisType = yAxisModel.get('type');
  61. var addOrdinal; // FIXME
  62. // Consider time axis.
  63. if (xAxisType === 'category') {
  64. option.layout = 'horizontal';
  65. ordinalMeta = xAxisModel.getOrdinalMeta();
  66. addOrdinal = true;
  67. } else if (yAxisType === 'category') {
  68. option.layout = 'vertical';
  69. ordinalMeta = yAxisModel.getOrdinalMeta();
  70. addOrdinal = true;
  71. } else {
  72. option.layout = option.layout || 'horizontal';
  73. }
  74. var coordDims = ['x', 'y'];
  75. var baseAxisDimIndex = option.layout === 'horizontal' ? 0 : 1;
  76. var baseAxisDim = this._baseAxisDim = coordDims[baseAxisDimIndex];
  77. var otherAxisDim = coordDims[1 - baseAxisDimIndex];
  78. var axisModels = [xAxisModel, yAxisModel];
  79. var baseAxisType = axisModels[baseAxisDimIndex].get('type');
  80. var otherAxisType = axisModels[1 - baseAxisDimIndex].get('type');
  81. var data = option.data; // ??? FIXME make a stage to perform data transfrom.
  82. // MUST create a new data, consider setOption({}) again.
  83. if (data && addOrdinal) {
  84. var newOptionData = [];
  85. zrUtil.each(data, function (item, index) {
  86. var newItem;
  87. if (item.value && zrUtil.isArray(item.value)) {
  88. newItem = item.value.slice();
  89. item.value.unshift(index);
  90. } else if (zrUtil.isArray(item)) {
  91. newItem = item.slice();
  92. item.unshift(index);
  93. } else {
  94. newItem = item;
  95. }
  96. newOptionData.push(newItem);
  97. });
  98. option.data = newOptionData;
  99. }
  100. var defaultValueDimensions = this.defaultValueDimensions;
  101. var coordDimensions = [{
  102. name: baseAxisDim,
  103. type: getDimensionTypeByAxis(baseAxisType),
  104. ordinalMeta: ordinalMeta,
  105. otherDims: {
  106. tooltip: false,
  107. itemName: 0
  108. },
  109. dimsDef: ['base']
  110. }, {
  111. name: otherAxisDim,
  112. type: getDimensionTypeByAxis(otherAxisType),
  113. dimsDef: defaultValueDimensions.slice()
  114. }];
  115. return createListSimply(this, {
  116. coordDimensions: coordDimensions,
  117. dimensionsCount: defaultValueDimensions.length + 1,
  118. encodeDefaulter: zrUtil.curry(makeSeriesEncodeForAxisCoordSys, coordDimensions, this)
  119. });
  120. },
  121. /**
  122. * If horizontal, base axis is x, otherwise y.
  123. * @override
  124. */
  125. getBaseAxis: function () {
  126. var dim = this._baseAxisDim;
  127. return this.ecModel.getComponent(dim + 'Axis', this.get(dim + 'AxisIndex')).axis;
  128. }
  129. };
  130. exports.seriesModelMixin = seriesModelMixin;