createSeriesData.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 * as zrUtil from 'zrender/lib/core/util.js';
  41. import SeriesData from '../../data/SeriesData.js';
  42. import prepareSeriesDataSchema from '../../data/helper/createDimensions.js';
  43. import { getDimensionTypeByAxis } from '../../data/helper/dimensionHelper.js';
  44. import { getDataItemValue } from '../../util/model.js';
  45. import CoordinateSystem from '../../core/CoordinateSystem.js';
  46. import { getCoordSysInfoBySeries } from '../../model/referHelper.js';
  47. import { createSourceFromSeriesDataOption } from '../../data/Source.js';
  48. import { enableDataStack } from '../../data/helper/dataStackHelper.js';
  49. import { makeSeriesEncodeForAxisCoordSys } from '../../data/helper/sourceHelper.js';
  50. import { SOURCE_FORMAT_ORIGINAL } from '../../util/types.js';
  51. function getCoordSysDimDefs(seriesModel, coordSysInfo) {
  52. var coordSysName = seriesModel.get('coordinateSystem');
  53. var registeredCoordSys = CoordinateSystem.get(coordSysName);
  54. var coordSysDimDefs;
  55. if (coordSysInfo && coordSysInfo.coordSysDims) {
  56. coordSysDimDefs = zrUtil.map(coordSysInfo.coordSysDims, function (dim) {
  57. var dimInfo = {
  58. name: dim
  59. };
  60. var axisModel = coordSysInfo.axisMap.get(dim);
  61. if (axisModel) {
  62. var axisType = axisModel.get('type');
  63. dimInfo.type = getDimensionTypeByAxis(axisType);
  64. }
  65. return dimInfo;
  66. });
  67. }
  68. if (!coordSysDimDefs) {
  69. // Get dimensions from registered coordinate system
  70. coordSysDimDefs = registeredCoordSys && (registeredCoordSys.getDimensionsInfo ? registeredCoordSys.getDimensionsInfo() : registeredCoordSys.dimensions.slice()) || ['x', 'y'];
  71. }
  72. return coordSysDimDefs;
  73. }
  74. function injectOrdinalMeta(dimInfoList, createInvertedIndices, coordSysInfo) {
  75. var firstCategoryDimIndex;
  76. var hasNameEncode;
  77. coordSysInfo && zrUtil.each(dimInfoList, function (dimInfo, dimIndex) {
  78. var coordDim = dimInfo.coordDim;
  79. var categoryAxisModel = coordSysInfo.categoryAxisMap.get(coordDim);
  80. if (categoryAxisModel) {
  81. if (firstCategoryDimIndex == null) {
  82. firstCategoryDimIndex = dimIndex;
  83. }
  84. dimInfo.ordinalMeta = categoryAxisModel.getOrdinalMeta();
  85. if (createInvertedIndices) {
  86. dimInfo.createInvertedIndices = true;
  87. }
  88. }
  89. if (dimInfo.otherDims.itemName != null) {
  90. hasNameEncode = true;
  91. }
  92. });
  93. if (!hasNameEncode && firstCategoryDimIndex != null) {
  94. dimInfoList[firstCategoryDimIndex].otherDims.itemName = 0;
  95. }
  96. return firstCategoryDimIndex;
  97. }
  98. /**
  99. * Caution: there are side effects to `sourceManager` in this method.
  100. * Should better only be called in `Series['getInitialData']`.
  101. */
  102. function createSeriesData(sourceRaw, seriesModel, opt) {
  103. opt = opt || {};
  104. var sourceManager = seriesModel.getSourceManager();
  105. var source;
  106. var isOriginalSource = false;
  107. if (sourceRaw) {
  108. isOriginalSource = true;
  109. source = createSourceFromSeriesDataOption(sourceRaw);
  110. } else {
  111. source = sourceManager.getSource();
  112. // Is series.data. not dataset.
  113. isOriginalSource = source.sourceFormat === SOURCE_FORMAT_ORIGINAL;
  114. }
  115. var coordSysInfo = getCoordSysInfoBySeries(seriesModel);
  116. var coordSysDimDefs = getCoordSysDimDefs(seriesModel, coordSysInfo);
  117. var useEncodeDefaulter = opt.useEncodeDefaulter;
  118. var encodeDefaulter = zrUtil.isFunction(useEncodeDefaulter) ? useEncodeDefaulter : useEncodeDefaulter ? zrUtil.curry(makeSeriesEncodeForAxisCoordSys, coordSysDimDefs, seriesModel) : null;
  119. var createDimensionOptions = {
  120. coordDimensions: coordSysDimDefs,
  121. generateCoord: opt.generateCoord,
  122. encodeDefine: seriesModel.getEncode(),
  123. encodeDefaulter: encodeDefaulter,
  124. canOmitUnusedDimensions: !isOriginalSource
  125. };
  126. var schema = prepareSeriesDataSchema(source, createDimensionOptions);
  127. var firstCategoryDimIndex = injectOrdinalMeta(schema.dimensions, opt.createInvertedIndices, coordSysInfo);
  128. var store = !isOriginalSource ? sourceManager.getSharedDataStore(schema) : null;
  129. var stackCalculationInfo = enableDataStack(seriesModel, {
  130. schema: schema,
  131. store: store
  132. });
  133. var data = new SeriesData(schema, seriesModel);
  134. data.setCalculationInfo(stackCalculationInfo);
  135. var dimValueGetter = firstCategoryDimIndex != null && isNeedCompleteOrdinalData(source) ? function (itemOpt, dimName, dataIndex, dimIndex) {
  136. // Use dataIndex as ordinal value in categoryAxis
  137. return dimIndex === firstCategoryDimIndex ? dataIndex : this.defaultDimValueGetter(itemOpt, dimName, dataIndex, dimIndex);
  138. } : null;
  139. data.hasItemOption = false;
  140. data.initData(
  141. // Try to reuse the data store in sourceManager if using dataset.
  142. isOriginalSource ? source : store, null, dimValueGetter);
  143. return data;
  144. }
  145. function isNeedCompleteOrdinalData(source) {
  146. if (source.sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  147. var sampleItem = firstDataNotNull(source.data || []);
  148. return !zrUtil.isArray(getDataItemValue(sampleItem));
  149. }
  150. }
  151. function firstDataNotNull(arr) {
  152. var i = 0;
  153. while (i < arr.length && arr[i] == null) {
  154. i++;
  155. }
  156. return arr[i];
  157. }
  158. export default createSeriesData;