lineAnimationDiff.js 6.2 KB

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