dataStackHelper.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 { each, isString } from 'zrender/lib/core/util.js';
  41. import { isSeriesDataSchema } from './SeriesDataSchema.js';
  42. /**
  43. * Note that it is too complicated to support 3d stack by value
  44. * (have to create two-dimension inverted index), so in 3d case
  45. * we just support that stacked by index.
  46. *
  47. * @param seriesModel
  48. * @param dimensionsInput The same as the input of <module:echarts/data/SeriesData>.
  49. * The input will be modified.
  50. * @param opt
  51. * @param opt.stackedCoordDimension Specify a coord dimension if needed.
  52. * @param opt.byIndex=false
  53. * @return calculationInfo
  54. * {
  55. * stackedDimension: string
  56. * stackedByDimension: string
  57. * isStackedByIndex: boolean
  58. * stackedOverDimension: string
  59. * stackResultDimension: string
  60. * }
  61. */
  62. export function enableDataStack(seriesModel, dimensionsInput, opt) {
  63. opt = opt || {};
  64. var byIndex = opt.byIndex;
  65. var stackedCoordDimension = opt.stackedCoordDimension;
  66. var dimensionDefineList;
  67. var schema;
  68. var store;
  69. if (isLegacyDimensionsInput(dimensionsInput)) {
  70. dimensionDefineList = dimensionsInput;
  71. } else {
  72. schema = dimensionsInput.schema;
  73. dimensionDefineList = schema.dimensions;
  74. store = dimensionsInput.store;
  75. } // Compatibal: when `stack` is set as '', do not stack.
  76. var mayStack = !!(seriesModel && seriesModel.get('stack'));
  77. var stackedByDimInfo;
  78. var stackedDimInfo;
  79. var stackResultDimension;
  80. var stackedOverDimension;
  81. each(dimensionDefineList, function (dimensionInfo, index) {
  82. if (isString(dimensionInfo)) {
  83. dimensionDefineList[index] = dimensionInfo = {
  84. name: dimensionInfo
  85. };
  86. }
  87. if (mayStack && !dimensionInfo.isExtraCoord) {
  88. // Find the first ordinal dimension as the stackedByDimInfo.
  89. if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) {
  90. stackedByDimInfo = dimensionInfo;
  91. } // Find the first stackable dimension as the stackedDimInfo.
  92. if (!stackedDimInfo && dimensionInfo.type !== 'ordinal' && dimensionInfo.type !== 'time' && (!stackedCoordDimension || stackedCoordDimension === dimensionInfo.coordDim)) {
  93. stackedDimInfo = dimensionInfo;
  94. }
  95. }
  96. });
  97. if (stackedDimInfo && !byIndex && !stackedByDimInfo) {
  98. // Compatible with previous design, value axis (time axis) only stack by index.
  99. // It may make sense if the user provides elaborately constructed data.
  100. byIndex = true;
  101. } // Add stack dimension, they can be both calculated by coordinate system in `unionExtent`.
  102. // That put stack logic in List is for using conveniently in echarts extensions, but it
  103. // might not be a good way.
  104. if (stackedDimInfo) {
  105. // Use a weird name that not duplicated with other names.
  106. // Also need to use seriesModel.id as postfix because different
  107. // series may share same data store. The stack dimension needs to be distinguished.
  108. stackResultDimension = '__\0ecstackresult_' + seriesModel.id;
  109. stackedOverDimension = '__\0ecstackedover_' + seriesModel.id; // Create inverted index to fast query index by value.
  110. if (stackedByDimInfo) {
  111. stackedByDimInfo.createInvertedIndices = true;
  112. }
  113. var stackedDimCoordDim_1 = stackedDimInfo.coordDim;
  114. var stackedDimType = stackedDimInfo.type;
  115. var stackedDimCoordIndex_1 = 0;
  116. each(dimensionDefineList, function (dimensionInfo) {
  117. if (dimensionInfo.coordDim === stackedDimCoordDim_1) {
  118. stackedDimCoordIndex_1++;
  119. }
  120. });
  121. var stackedOverDimensionDefine = {
  122. name: stackResultDimension,
  123. coordDim: stackedDimCoordDim_1,
  124. coordDimIndex: stackedDimCoordIndex_1,
  125. type: stackedDimType,
  126. isExtraCoord: true,
  127. isCalculationCoord: true,
  128. storeDimIndex: dimensionDefineList.length
  129. };
  130. var stackResultDimensionDefine = {
  131. name: stackedOverDimension,
  132. // This dimension contains stack base (generally, 0), so do not set it as
  133. // `stackedDimCoordDim` to avoid extent calculation, consider log scale.
  134. coordDim: stackedOverDimension,
  135. coordDimIndex: stackedDimCoordIndex_1 + 1,
  136. type: stackedDimType,
  137. isExtraCoord: true,
  138. isCalculationCoord: true,
  139. storeDimIndex: dimensionDefineList.length + 1
  140. };
  141. if (schema) {
  142. if (store) {
  143. stackedOverDimensionDefine.storeDimIndex = store.ensureCalculationDimension(stackedOverDimension, stackedDimType);
  144. stackResultDimensionDefine.storeDimIndex = store.ensureCalculationDimension(stackResultDimension, stackedDimType);
  145. }
  146. schema.appendCalculationDimension(stackedOverDimensionDefine);
  147. schema.appendCalculationDimension(stackResultDimensionDefine);
  148. } else {
  149. dimensionDefineList.push(stackedOverDimensionDefine);
  150. dimensionDefineList.push(stackResultDimensionDefine);
  151. }
  152. }
  153. return {
  154. stackedDimension: stackedDimInfo && stackedDimInfo.name,
  155. stackedByDimension: stackedByDimInfo && stackedByDimInfo.name,
  156. isStackedByIndex: byIndex,
  157. stackedOverDimension: stackedOverDimension,
  158. stackResultDimension: stackResultDimension
  159. };
  160. }
  161. function isLegacyDimensionsInput(dimensionsInput) {
  162. return !isSeriesDataSchema(dimensionsInput.schema);
  163. }
  164. export function isDimensionStacked(data, stackedDim) {
  165. // Each single series only maps to one pair of axis. So we do not need to
  166. // check stackByDim, whatever stacked by a dimension or stacked by index.
  167. return !!stackedDim && stackedDim === data.getCalculationInfo('stackedDimension');
  168. }
  169. export function getStackedDimension(data, targetDim) {
  170. return isDimensionStacked(data, targetDim) ? data.getCalculationInfo('stackResultDimension') : targetDim;
  171. }