helper.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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] /* , dims[1] */)) {
  57. // jshint ignore:line
  58. stacked = true;
  59. dims[0] = stackResultDim;
  60. }
  61. if (isDimensionStacked(data, dims[1] /* , dims[0] */)) {
  62. // jshint ignore:line
  63. stacked = true;
  64. dims[1] = stackResultDim;
  65. }
  66. return {
  67. dataDimsForPoint: dims,
  68. valueStart: valueStart,
  69. valueAxisDim: valueAxisDim,
  70. baseAxisDim: baseAxisDim,
  71. stacked: !!stacked,
  72. valueDim: valueDim,
  73. baseDim: baseDim,
  74. baseDataOffset: baseDataOffset,
  75. stackedOverDimension: data.getCalculationInfo('stackedOverDimension')
  76. };
  77. }
  78. function getValueStart(valueAxis, valueOrigin) {
  79. var valueStart = 0;
  80. var extent = valueAxis.scale.getExtent();
  81. if (valueOrigin === 'start') {
  82. valueStart = extent[0];
  83. } else if (valueOrigin === 'end') {
  84. valueStart = extent[1];
  85. }
  86. // If origin is specified as a number, use it as
  87. // valueStart directly
  88. else if (isNumber(valueOrigin) && !isNaN(valueOrigin)) {
  89. valueStart = valueOrigin;
  90. }
  91. // auto
  92. else {
  93. // Both positive
  94. if (extent[0] > 0) {
  95. valueStart = extent[0];
  96. }
  97. // Both negative
  98. else if (extent[1] < 0) {
  99. valueStart = extent[1];
  100. }
  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. }