createSeriesData.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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(); // Is series.data. not dataset.
  112. isOriginalSource = source.sourceFormat === SOURCE_FORMAT_ORIGINAL;
  113. }
  114. var coordSysInfo = getCoordSysInfoBySeries(seriesModel);
  115. var coordSysDimDefs = getCoordSysDimDefs(seriesModel, coordSysInfo);
  116. var useEncodeDefaulter = opt.useEncodeDefaulter;
  117. var encodeDefaulter = zrUtil.isFunction(useEncodeDefaulter) ? useEncodeDefaulter : useEncodeDefaulter ? zrUtil.curry(makeSeriesEncodeForAxisCoordSys, coordSysDimDefs, seriesModel) : null;
  118. var createDimensionOptions = {
  119. coordDimensions: coordSysDimDefs,
  120. generateCoord: opt.generateCoord,
  121. encodeDefine: seriesModel.getEncode(),
  122. encodeDefaulter: encodeDefaulter,
  123. canOmitUnusedDimensions: !isOriginalSource
  124. };
  125. var schema = prepareSeriesDataSchema(source, createDimensionOptions);
  126. var firstCategoryDimIndex = injectOrdinalMeta(schema.dimensions, opt.createInvertedIndices, coordSysInfo);
  127. var store = !isOriginalSource ? sourceManager.getSharedDataStore(schema) : null;
  128. var stackCalculationInfo = enableDataStack(seriesModel, {
  129. schema: schema,
  130. store: store
  131. });
  132. var data = new SeriesData(schema, seriesModel);
  133. data.setCalculationInfo(stackCalculationInfo);
  134. var dimValueGetter = firstCategoryDimIndex != null && isNeedCompleteOrdinalData(source) ? function (itemOpt, dimName, dataIndex, dimIndex) {
  135. // Use dataIndex as ordinal value in categoryAxis
  136. return dimIndex === firstCategoryDimIndex ? dataIndex : this.defaultDimValueGetter(itemOpt, dimName, dataIndex, dimIndex);
  137. } : null;
  138. data.hasItemOption = false;
  139. data.initData( // Try to reuse the data store in sourceManager if using dataset.
  140. isOriginalSource ? source : store, null, dimValueGetter);
  141. return data;
  142. }
  143. function isNeedCompleteOrdinalData(source) {
  144. if (source.sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  145. var sampleItem = firstDataNotNull(source.data || []);
  146. return !zrUtil.isArray(getDataItemValue(sampleItem));
  147. }
  148. }
  149. function firstDataNotNull(arr) {
  150. var i = 0;
  151. while (i < arr.length && arr[i] == null) {
  152. i++;
  153. }
  154. return arr[i];
  155. }
  156. export default createSeriesData;