axisStatisticsMetricsImpl.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 { createHashMap } from 'zrender/lib/core/util.js';
  41. import { asc, isNullableNumberFinite } from '../util/number.js';
  42. import { parseSanitizationFilter, passesSanitizationFilter } from '../data/helper/dataValueHelper.js';
  43. import { tryEnsureTypedArray, Float64ArrayCtor } from '../util/vendor.js';
  44. import { eachSeriesDealForAxisStat, LINEAR_POSITIVE_MIN_GAP_NO_VALID_VALUE, LINEAR_POSITIVE_MIN_GAP_SINGLE_VALID_VALUE, registerMetricImpl } from './axisStatistics.js';
  45. export function registerMetricImplLiPosMinGap() {
  46. registerMetricImpl('liPosMinGap', metricLiPosMinGapImpl);
  47. }
  48. function metricLiPosMinGapImpl(ecModel, perKeyPerAxis, ecPreparePerKeyPerAxis) {
  49. var newSerUids = createHashMap();
  50. var ecPrepareSerUids = ecPreparePerKeyPerAxis.serUids;
  51. var ecPrepareLiPosMinGap = ecPreparePerKeyPerAxis.liPosMinGap;
  52. var ecPrepareCacheMiss;
  53. var axis = perKeyPerAxis.axis;
  54. var scale = axis.scale;
  55. // const linearValueExtent = initExtentForUnion();
  56. var needTransform = scale.needTransform();
  57. var filter = scale.getFilter ? scale.getFilter() : null;
  58. var filterParsed = parseSanitizationFilter(filter);
  59. // const timeRetrieve: number[] = []; // _EC_PERF_
  60. // const timeSort: number[] = []; // _EC_PERF_
  61. // const timeAll: number[] = []; // _EC_PERF_
  62. // timeAll[0] = Date.now(); // _EC_PERF_
  63. function eachSeries(cb) {
  64. eachSeriesDealForAxisStat(ecModel, perKeyPerAxis.sers, function (seriesModel) {
  65. var rawData = seriesModel.getRawData();
  66. // NOTE: Currently there is no series that a "base axis" can map to multiple dimensions.
  67. var dimStoreIdx = rawData.getDimensionIndex(rawData.mapDimension(axis.dim));
  68. if (dimStoreIdx >= 0) {
  69. cb(dimStoreIdx, seriesModel, rawData.getStore());
  70. }
  71. });
  72. }
  73. var bufferCapacity = 0;
  74. eachSeries(function (dimStoreIdx, seriesModel, rawDataStore) {
  75. newSerUids.set(seriesModel.uid, 1);
  76. if (!ecPrepareSerUids || !ecPrepareSerUids.hasKey(seriesModel.uid)) {
  77. ecPrepareCacheMiss = true;
  78. }
  79. bufferCapacity += rawDataStore.count();
  80. });
  81. if (!ecPrepareSerUids || ecPrepareSerUids.keys().length !== newSerUids.keys().length) {
  82. ecPrepareCacheMiss = true;
  83. }
  84. if (!ecPrepareCacheMiss && ecPrepareLiPosMinGap != null) {
  85. // Consider the fact in practice:
  86. // - Series data can only be changed in EC_PREPARE.
  87. // - The relationship between series and axes can only be changed in EC_PREPARE and
  88. // SERIES_FILTER.
  89. // (See EC_CYCLE for more info)
  90. // Therefore, some statistics results can be cached in `GlobalModelCachePerECPrepare` to avoid
  91. // repeated time-consuming calculation for large data (e.g., over 1e5 data items).
  92. perKeyPerAxis.liPosMinGap = ecPrepareLiPosMinGap;
  93. return;
  94. }
  95. tryEnsureTypedArray(tmpValueBuffer, bufferCapacity);
  96. // timeRetrieve[0] = Date.now(); // _EC_PERF_
  97. var writeIdx = 0;
  98. eachSeries(function (dimStoreIdx, seriesModel, store) {
  99. // NOTE: It appears to be optimized by traveling only in a specific window (e.g., the current window)
  100. // instead of the entire data, but that would likely generate inconsistent result and bring
  101. // jitter when dataZoom roaming.
  102. for (var i = 0, cnt = store.count(); i < cnt; ++i) {
  103. // Manually inline some code for performance, since no other optimization
  104. // (such as, progressive) can be applied here.
  105. var val = store.get(dimStoreIdx, i);
  106. // NOTE: in most cases, filter does not exist.
  107. if (isFinite(val) && (!filter || passesSanitizationFilter(filterParsed, val))) {
  108. if (needTransform) {
  109. // PENDING: time-consuming if axis break is applied.
  110. val = scale.transformIn(val, null);
  111. }
  112. tmpValueBuffer.arr[writeIdx++] = val;
  113. // val < linearValueExtent[0] && (linearValueExtent[0] = val);
  114. // val > linearValueExtent[1] && (linearValueExtent[1] = val);
  115. }
  116. }
  117. });
  118. // Indicatively, retrieving values above costs 40ms for 1e6 values in a certain platform.
  119. // timeRetrieve[1] = Date.now(); // _EC_PERF_
  120. var tmpValueBufferView = tmpValueBuffer.typed ? tmpValueBuffer.arr.subarray(0, writeIdx) : (tmpValueBuffer.arr.length = writeIdx, tmpValueBuffer.arr);
  121. // timeSort[0] = Date.now(); // _EC_PERF_
  122. // Sort axis values into ascending order to calculate gaps.
  123. if (tmpValueBuffer.typed) {
  124. // Indicatively, 5ms for 1e6 values in a certain platform.
  125. tmpValueBufferView.sort();
  126. } else {
  127. asc(tmpValueBufferView);
  128. }
  129. // timeAll[1] = timeSort[1] = Date.now(); // _EC_PERF_
  130. // console.log('axisStatistics_minGap_retrieve', timeRetrieve[1] - timeRetrieve[0]); // _EC_PERF_
  131. // console.log('axisStatistics_minGap_sort', timeSort[1] - timeSort[0]); // _EC_PERF_
  132. // console.log('axisStatistics_minGap_all', timeAll[1] - timeAll[0]); // _EC_PERF_
  133. var min = Infinity;
  134. for (var j = 1; j < writeIdx; ++j) {
  135. var delta = tmpValueBufferView[j] - tmpValueBufferView[j - 1];
  136. if (
  137. // - Different series normally have the same values (e.g., barA, barB, barC),
  138. // which should be ignored.
  139. // - A single series with multiple same values is often not meaningful to
  140. // create `bandWidth`, so it is also ignored.
  141. delta > 0 && delta < min) {
  142. min = delta;
  143. }
  144. }
  145. ecPreparePerKeyPerAxis.liPosMinGap = perKeyPerAxis.liPosMinGap = isNullableNumberFinite(min) ? min : writeIdx > 0 ? LINEAR_POSITIVE_MIN_GAP_SINGLE_VALID_VALUE : LINEAR_POSITIVE_MIN_GAP_NO_VALID_VALUE;
  146. ecPreparePerKeyPerAxis.serUids = newSerUids;
  147. }
  148. // For performance optimization.
  149. var tmpValueBuffer = tryEnsureTypedArray({
  150. ctor: Float64ArrayCtor
  151. }, 50 // An arbitrary initial capability.
  152. );