helper.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 { isDimensionStacked } from '../../data/helper/dataStackHelper.js';
  41. import { isNumber, map } from 'zrender/lib/core/util.js';
  42. export function prepareDataCoordInfo(coordSys, data, valueOrigin) {
  43. var baseAxis = coordSys.getBaseAxis();
  44. var valueAxis = coordSys.getOtherAxis(baseAxis);
  45. var valueStart = getValueStart(valueAxis, valueOrigin);
  46. var baseAxisDim = baseAxis.dim;
  47. var valueAxisDim = valueAxis.dim;
  48. var valueDim = data.mapDimension(valueAxisDim);
  49. var baseDim = data.mapDimension(baseAxisDim);
  50. var baseDataOffset = valueAxisDim === 'x' || valueAxisDim === 'radius' ? 1 : 0;
  51. var dims = map(coordSys.dimensions, function (coordDim) {
  52. return data.mapDimension(coordDim);
  53. });
  54. var stacked = false;
  55. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  56. if (isDimensionStacked(data, dims[0]
  57. /*, dims[1]*/
  58. )) {
  59. // jshint ignore:line
  60. stacked = true;
  61. dims[0] = stackResultDim;
  62. }
  63. if (isDimensionStacked(data, dims[1]
  64. /*, dims[0]*/
  65. )) {
  66. // jshint ignore:line
  67. stacked = true;
  68. dims[1] = stackResultDim;
  69. }
  70. return {
  71. dataDimsForPoint: dims,
  72. valueStart: valueStart,
  73. valueAxisDim: valueAxisDim,
  74. baseAxisDim: baseAxisDim,
  75. stacked: !!stacked,
  76. valueDim: valueDim,
  77. baseDim: baseDim,
  78. baseDataOffset: baseDataOffset,
  79. stackedOverDimension: data.getCalculationInfo('stackedOverDimension')
  80. };
  81. }
  82. function getValueStart(valueAxis, valueOrigin) {
  83. var valueStart = 0;
  84. var extent = valueAxis.scale.getExtent();
  85. if (valueOrigin === 'start') {
  86. valueStart = extent[0];
  87. } else if (valueOrigin === 'end') {
  88. valueStart = extent[1];
  89. } // If origin is specified as a number, use it as
  90. // valueStart directly
  91. else if (isNumber(valueOrigin) && !isNaN(valueOrigin)) {
  92. valueStart = valueOrigin;
  93. } // auto
  94. else {
  95. // Both positive
  96. if (extent[0] > 0) {
  97. valueStart = extent[0];
  98. } // Both negative
  99. else if (extent[1] < 0) {
  100. valueStart = extent[1];
  101. } // If is one positive, and one negative, onZero shall be true
  102. }
  103. return valueStart;
  104. }
  105. export function getStackedOnPoint(dataCoordInfo, coordSys, data, idx) {
  106. var value = NaN;
  107. if (dataCoordInfo.stacked) {
  108. value = data.get(data.getCalculationInfo('stackedOverDimension'), idx);
  109. }
  110. if (isNaN(value)) {
  111. value = dataCoordInfo.valueStart;
  112. }
  113. var baseDataOffset = dataCoordInfo.baseDataOffset;
  114. var stackedData = [];
  115. stackedData[baseDataOffset] = data.get(dataCoordInfo.baseDim, idx);
  116. stackedData[1 - baseDataOffset] = value;
  117. return coordSys.dataToPoint(stackedData);
  118. }