helper.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 _dataStackHelper = require("../../data/helper/dataStackHelper");
  20. var isDimensionStacked = _dataStackHelper.isDimensionStacked;
  21. var _util = require("zrender/lib/core/util");
  22. var map = _util.map;
  23. /*
  24. * Licensed to the Apache Software Foundation (ASF) under one
  25. * or more contributor license agreements. See the NOTICE file
  26. * distributed with this work for additional information
  27. * regarding copyright ownership. The ASF licenses this file
  28. * to you under the Apache License, Version 2.0 (the
  29. * "License"); you may not use this file except in compliance
  30. * with the License. You may obtain a copy of the License at
  31. *
  32. * http://www.apache.org/licenses/LICENSE-2.0
  33. *
  34. * Unless required by applicable law or agreed to in writing,
  35. * software distributed under the License is distributed on an
  36. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37. * KIND, either express or implied. See the License for the
  38. * specific language governing permissions and limitations
  39. * under the License.
  40. */
  41. /**
  42. * @param {Object} coordSys
  43. * @param {module:echarts/data/List} data
  44. * @param {string} valueOrigin lineSeries.option.areaStyle.origin
  45. */
  46. function prepareDataCoordInfo(coordSys, data, valueOrigin) {
  47. var baseAxis = coordSys.getBaseAxis();
  48. var valueAxis = coordSys.getOtherAxis(baseAxis);
  49. var valueStart = getValueStart(valueAxis, valueOrigin);
  50. var baseAxisDim = baseAxis.dim;
  51. var valueAxisDim = valueAxis.dim;
  52. var valueDim = data.mapDimension(valueAxisDim);
  53. var baseDim = data.mapDimension(baseAxisDim);
  54. var baseDataOffset = valueAxisDim === 'x' || valueAxisDim === 'radius' ? 1 : 0;
  55. var dims = map(coordSys.dimensions, function (coordDim) {
  56. return data.mapDimension(coordDim);
  57. });
  58. var stacked;
  59. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  60. if (stacked |= isDimensionStacked(data, dims[0]
  61. /*, dims[1]*/
  62. )) {
  63. // jshint ignore:line
  64. dims[0] = stackResultDim;
  65. }
  66. if (stacked |= isDimensionStacked(data, dims[1]
  67. /*, dims[0]*/
  68. )) {
  69. // jshint ignore:line
  70. dims[1] = stackResultDim;
  71. }
  72. return {
  73. dataDimsForPoint: dims,
  74. valueStart: valueStart,
  75. valueAxisDim: valueAxisDim,
  76. baseAxisDim: baseAxisDim,
  77. stacked: !!stacked,
  78. valueDim: valueDim,
  79. baseDim: baseDim,
  80. baseDataOffset: baseDataOffset,
  81. stackedOverDimension: data.getCalculationInfo('stackedOverDimension')
  82. };
  83. }
  84. function getValueStart(valueAxis, valueOrigin) {
  85. var valueStart = 0;
  86. var extent = valueAxis.scale.getExtent();
  87. if (valueOrigin === 'start') {
  88. valueStart = extent[0];
  89. } else if (valueOrigin === 'end') {
  90. valueStart = extent[1];
  91. } // auto
  92. else {
  93. // Both positive
  94. if (extent[0] > 0) {
  95. valueStart = extent[0];
  96. } // Both negative
  97. else if (extent[1] < 0) {
  98. valueStart = extent[1];
  99. } // If is one positive, and one negative, onZero shall be true
  100. }
  101. return valueStart;
  102. }
  103. function getStackedOnPoint(dataCoordInfo, coordSys, data, idx) {
  104. var value = NaN;
  105. if (dataCoordInfo.stacked) {
  106. value = data.get(data.getCalculationInfo('stackedOverDimension'), idx);
  107. }
  108. if (isNaN(value)) {
  109. value = dataCoordInfo.valueStart;
  110. }
  111. var baseDataOffset = dataCoordInfo.baseDataOffset;
  112. var stackedData = [];
  113. stackedData[baseDataOffset] = data.get(dataCoordInfo.baseDim, idx);
  114. stackedData[1 - baseDataOffset] = value;
  115. return coordSys.dataToPoint(stackedData);
  116. }
  117. exports.prepareDataCoordInfo = prepareDataCoordInfo;
  118. exports.getStackedOnPoint = getStackedOnPoint;