lineAnimationDiff.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 { prepareDataCoordInfo, getStackedOnPoint } from './helper.js';
  41. import { createFloat32Array } from '../../util/vendor.js';
  42. function diffData(oldData, newData) {
  43. var diffResult = [];
  44. newData.diff(oldData).add(function (idx) {
  45. diffResult.push({
  46. cmd: '+',
  47. idx: idx
  48. });
  49. }).update(function (newIdx, oldIdx) {
  50. diffResult.push({
  51. cmd: '=',
  52. idx: oldIdx,
  53. idx1: newIdx
  54. });
  55. }).remove(function (idx) {
  56. diffResult.push({
  57. cmd: '-',
  58. idx: idx
  59. });
  60. }).execute();
  61. return diffResult;
  62. }
  63. export default function lineAnimationDiff(oldData, newData, oldStackedOnPoints, newStackedOnPoints, oldCoordSys, newCoordSys, oldValueOrigin, newValueOrigin) {
  64. var diff = diffData(oldData, newData);
  65. // let newIdList = newData.mapArray(newData.getId);
  66. // let oldIdList = oldData.mapArray(oldData.getId);
  67. // convertToIntId(newIdList, oldIdList);
  68. // // FIXME One data ?
  69. // diff = arrayDiff(oldIdList, newIdList);
  70. var currPoints = [];
  71. var nextPoints = [];
  72. // Points for stacking base line
  73. var currStackedPoints = [];
  74. var nextStackedPoints = [];
  75. var status = [];
  76. var sortedIndices = [];
  77. var rawIndices = [];
  78. var newDataOldCoordInfo = prepareDataCoordInfo(oldCoordSys, newData, oldValueOrigin);
  79. // const oldDataNewCoordInfo = prepareDataCoordInfo(newCoordSys, oldData, newValueOrigin);
  80. var oldPoints = oldData.getLayout('points') || [];
  81. var newPoints = newData.getLayout('points') || [];
  82. for (var i = 0; i < diff.length; i++) {
  83. var diffItem = diff[i];
  84. var pointAdded = true;
  85. var oldIdx2 = void 0;
  86. var newIdx2 = void 0;
  87. // FIXME, animation is not so perfect when dataZoom window moves fast
  88. // Which is in case remvoing or add more than one data in the tail or head
  89. switch (diffItem.cmd) {
  90. case '=':
  91. oldIdx2 = diffItem.idx * 2;
  92. newIdx2 = diffItem.idx1 * 2;
  93. var currentX = oldPoints[oldIdx2];
  94. var currentY = oldPoints[oldIdx2 + 1];
  95. var nextX = newPoints[newIdx2];
  96. var nextY = newPoints[newIdx2 + 1];
  97. // If previous data is NaN, use next point directly
  98. if (isNaN(currentX) || isNaN(currentY)) {
  99. currentX = nextX;
  100. currentY = nextY;
  101. }
  102. currPoints.push(currentX, currentY);
  103. nextPoints.push(nextX, nextY);
  104. currStackedPoints.push(oldStackedOnPoints[oldIdx2], oldStackedOnPoints[oldIdx2 + 1]);
  105. nextStackedPoints.push(newStackedOnPoints[newIdx2], newStackedOnPoints[newIdx2 + 1]);
  106. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  107. break;
  108. case '+':
  109. var newIdx = diffItem.idx;
  110. var newDataDimsForPoint = newDataOldCoordInfo.dataDimsForPoint;
  111. var oldPt = oldCoordSys.dataToPoint([newData.get(newDataDimsForPoint[0], newIdx), newData.get(newDataDimsForPoint[1], newIdx)]);
  112. newIdx2 = newIdx * 2;
  113. currPoints.push(oldPt[0], oldPt[1]);
  114. nextPoints.push(newPoints[newIdx2], newPoints[newIdx2 + 1]);
  115. var stackedOnPoint = getStackedOnPoint(newDataOldCoordInfo, oldCoordSys, newData, newIdx);
  116. currStackedPoints.push(stackedOnPoint[0], stackedOnPoint[1]);
  117. nextStackedPoints.push(newStackedOnPoints[newIdx2], newStackedOnPoints[newIdx2 + 1]);
  118. rawIndices.push(newData.getRawIndex(newIdx));
  119. break;
  120. case '-':
  121. pointAdded = false;
  122. }
  123. // Original indices
  124. if (pointAdded) {
  125. status.push(diffItem);
  126. sortedIndices.push(sortedIndices.length);
  127. }
  128. }
  129. // Diff result may be crossed if all items are changed
  130. // Sort by data index
  131. sortedIndices.sort(function (a, b) {
  132. return rawIndices[a] - rawIndices[b];
  133. });
  134. var len = currPoints.length;
  135. var sortedCurrPoints = createFloat32Array(len);
  136. var sortedNextPoints = createFloat32Array(len);
  137. var sortedCurrStackedPoints = createFloat32Array(len);
  138. var sortedNextStackedPoints = createFloat32Array(len);
  139. var sortedStatus = [];
  140. for (var i = 0; i < sortedIndices.length; i++) {
  141. var idx = sortedIndices[i];
  142. var i2 = i * 2;
  143. var idx2 = idx * 2;
  144. sortedCurrPoints[i2] = currPoints[idx2];
  145. sortedCurrPoints[i2 + 1] = currPoints[idx2 + 1];
  146. sortedNextPoints[i2] = nextPoints[idx2];
  147. sortedNextPoints[i2 + 1] = nextPoints[idx2 + 1];
  148. sortedCurrStackedPoints[i2] = currStackedPoints[idx2];
  149. sortedCurrStackedPoints[i2 + 1] = currStackedPoints[idx2 + 1];
  150. sortedNextStackedPoints[i2] = nextStackedPoints[idx2];
  151. sortedNextStackedPoints[i2 + 1] = nextStackedPoints[idx2 + 1];
  152. sortedStatus[i] = status[idx];
  153. }
  154. return {
  155. current: sortedCurrPoints,
  156. next: sortedNextPoints,
  157. stackedOnCurrent: sortedCurrStackedPoints,
  158. stackedOnNext: sortedNextStackedPoints,
  159. status: sortedStatus
  160. };
  161. }