diff --git a/packages/f2/src/components/geometry/index.tsx b/packages/f2/src/components/geometry/index.tsx index 3edaf746c..03d1d9c1a 100644 --- a/packages/f2/src/components/geometry/index.tsx +++ b/packages/f2/src/components/geometry/index.tsx @@ -330,7 +330,7 @@ class Geometry< if (scale.isCategory) { const field = scale.field; const value = scale.translate(obj.origin[field]); - obj[field] = isNaN(value) ? 0 : value; + obj[field] = value; } } } diff --git a/packages/f2/src/components/zoom/index.tsx b/packages/f2/src/components/zoom/index.tsx index 522b7faf5..44ba0f1cd 100644 --- a/packages/f2/src/components/zoom/index.tsx +++ b/packages/f2/src/components/zoom/index.tsx @@ -13,6 +13,7 @@ function lerp(min, max, fraction) { } function isNumberEqualRange(aRange: number[], bRange: number[]) { + if (!bRange) return false; for (let i = 0, len = aRange.length; i < len; i++) { if (!isNumberEqual(aRange[i], bRange[i])) return false; } @@ -20,6 +21,7 @@ function isNumberEqualRange(aRange: number[], bRange: number[]) { } function isEqualRange(aRange, bRange) { + if (!bRange) return false; if (isArray(aRange)) { return isNumberEqualRange(aRange, bRange); } @@ -174,9 +176,8 @@ export default (View) => { // 图表上最少显示 MIN_COUNT 个数据 this.minScale = minCount / valueLength; - this.state = { - range: cacheRange, - } as S; + + this.renderRange(cacheRange); } willUpdate(): void { diff --git a/packages/f2/src/components/zoom/zoomUtil.ts b/packages/f2/src/components/zoom/zoomUtil.ts index 995147b50..ba2c5cf03 100644 --- a/packages/f2/src/components/zoom/zoomUtil.ts +++ b/packages/f2/src/components/zoom/zoomUtil.ts @@ -21,8 +21,10 @@ function updateCategoryRange(scale: Scale, originScale: Scale, range: ZoomRange) const valueEnd = end * len; // 保持滑动时个数的稳定 - const count = Math.ceil(valueEnd - valueStart); - const sliceSatrt = Math.round(valueStart); + const diff = valueEnd - valueStart; + const precision = parseFloat(diff.toFixed(3)); // js 计算精度问题 + const count = Math.round(precision); + const sliceSatrt = Math.min(Math.round(valueStart), len - count); // 从原始数据里截取需要显示的数据 const newValues = originValues.slice(sliceSatrt, sliceSatrt + count); diff --git a/packages/f2/src/controller/scale.ts b/packages/f2/src/controller/scale.ts index a849f1a36..4491a17c6 100644 --- a/packages/f2/src/controller/scale.ts +++ b/packages/f2/src/controller/scale.ts @@ -164,6 +164,14 @@ class ScaleController { const scale = scales[field]; if (scale) { + // for adjust=dodge, 需要更新 range + const option = this._getOption({ + ...options[field], + values: scale.values, + }); + if (option.range) { + scale.range = option.range; + } return scale; } const option = options[field]; diff --git a/packages/f2/src/deps/f2-adjust/src/adjusts/adjust.ts b/packages/f2/src/deps/f2-adjust/src/adjusts/adjust.ts index 0c7634b78..fe3a5512a 100644 --- a/packages/f2/src/deps/f2-adjust/src/adjusts/adjust.ts +++ b/packages/f2/src/deps/f2-adjust/src/adjusts/adjust.ts @@ -174,7 +174,9 @@ export default abstract class Adjust { return; } // 在每个维度上,所有的值 - dimValuesMap[dim] = valuesOfKey(mergedData, dim).sort((v1, v2) => v1 - v2) as number[]; + dimValuesMap[dim] = valuesOfKey(mergedData, dim) + .sort((v1, v2) => v1 - v2) + .filter((v) => !isNaN(v)) as number[]; }); // 只有一维的情况下,同时调整 y,赋予默认值 diff --git a/packages/f2/test/components/candlestick/__image_snapshots__/pan-test-tsx-candlestick-swipe-1-snap.png b/packages/f2/test/components/candlestick/__image_snapshots__/pan-test-tsx-candlestick-swipe-1-snap.png index 60c816787..2af815bf7 100644 Binary files a/packages/f2/test/components/candlestick/__image_snapshots__/pan-test-tsx-candlestick-swipe-1-snap.png and b/packages/f2/test/components/candlestick/__image_snapshots__/pan-test-tsx-candlestick-swipe-1-snap.png differ diff --git a/packages/f2/test/components/candlestick/__image_snapshots__/pan-test-tsx-candlestick-swipe-2-snap.png b/packages/f2/test/components/candlestick/__image_snapshots__/pan-test-tsx-candlestick-swipe-2-snap.png index 879338cc4..428b2d766 100644 Binary files a/packages/f2/test/components/candlestick/__image_snapshots__/pan-test-tsx-candlestick-swipe-2-snap.png and b/packages/f2/test/components/candlestick/__image_snapshots__/pan-test-tsx-candlestick-swipe-2-snap.png differ diff --git a/packages/f2/test/components/candlestick/__image_snapshots__/pan-test-tsx-candlestick-swipe-3-snap.png b/packages/f2/test/components/candlestick/__image_snapshots__/pan-test-tsx-candlestick-swipe-3-snap.png index 4c9c76290..46434a41f 100644 Binary files a/packages/f2/test/components/candlestick/__image_snapshots__/pan-test-tsx-candlestick-swipe-3-snap.png and b/packages/f2/test/components/candlestick/__image_snapshots__/pan-test-tsx-candlestick-swipe-3-snap.png differ diff --git a/packages/f2/test/components/geometry/__image_snapshots__/empty-data-test-tsx-empty-data-data-array-is-empty-1-snap.png b/packages/f2/test/components/geometry/__image_snapshots__/empty-data-test-tsx-empty-data-data-array-is-empty-1-snap.png index b648597fa..16ea57419 100644 Binary files a/packages/f2/test/components/geometry/__image_snapshots__/empty-data-test-tsx-empty-data-data-array-is-empty-1-snap.png and b/packages/f2/test/components/geometry/__image_snapshots__/empty-data-test-tsx-empty-data-data-array-is-empty-1-snap.png differ diff --git a/packages/f2/test/components/interaction/__image_snapshots__/dodge-pan-test-tsx-dodge-pan-init-1-snap.png b/packages/f2/test/components/interaction/__image_snapshots__/dodge-pan-test-tsx-dodge-pan-init-1-snap.png new file mode 100644 index 000000000..f18d7ce13 Binary files /dev/null and b/packages/f2/test/components/interaction/__image_snapshots__/dodge-pan-test-tsx-dodge-pan-init-1-snap.png differ diff --git a/packages/f2/test/components/interaction/__image_snapshots__/dodge-pan-test-tsx-dodge-pan-pan-1-snap.png b/packages/f2/test/components/interaction/__image_snapshots__/dodge-pan-test-tsx-dodge-pan-pan-1-snap.png new file mode 100644 index 000000000..bc072a61f Binary files /dev/null and b/packages/f2/test/components/interaction/__image_snapshots__/dodge-pan-test-tsx-dodge-pan-pan-1-snap.png differ diff --git "a/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-cate\347\261\273\345\236\213-pan-\344\272\213\344\273\266-1-snap.png" "b/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-cate\347\261\273\345\236\213-pan-\344\272\213\344\273\266-1-snap.png" index ddc626e17..76a4b2231 100644 Binary files "a/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-cate\347\261\273\345\236\213-pan-\344\272\213\344\273\266-1-snap.png" and "b/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-cate\347\261\273\345\236\213-pan-\344\272\213\344\273\266-1-snap.png" differ diff --git "a/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-cate\347\261\273\345\236\213-\345\210\235\345\247\213\347\212\266\346\200\201-1-snap.png" "b/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-cate\347\261\273\345\236\213-\345\210\235\345\247\213\347\212\266\346\200\201-1-snap.png" index d87d8da39..4494e1c1c 100644 Binary files "a/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-cate\347\261\273\345\236\213-\345\210\235\345\247\213\347\212\266\346\200\201-1-snap.png" and "b/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-cate\347\261\273\345\236\213-\345\210\235\345\247\213\347\212\266\346\200\201-1-snap.png" differ diff --git "a/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-cate\347\261\273\345\236\213-\346\224\276\345\244\247-1-snap.png" "b/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-cate\347\261\273\345\236\213-\346\224\276\345\244\247-1-snap.png" index 18f62fb9d..8d6142e75 100644 Binary files "a/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-cate\347\261\273\345\236\213-\346\224\276\345\244\247-1-snap.png" and "b/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-cate\347\261\273\345\236\213-\346\224\276\345\244\247-1-snap.png" differ diff --git "a/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-dodge-\347\261\273\345\236\213-pan-\344\272\213\344\273\266-1-snap.png" "b/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-dodge-\347\261\273\345\236\213-pan-\344\272\213\344\273\266-1-snap.png" index fe86593b0..2174337c9 100644 Binary files "a/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-dodge-\347\261\273\345\236\213-pan-\344\272\213\344\273\266-1-snap.png" and "b/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-dodge-\347\261\273\345\236\213-pan-\344\272\213\344\273\266-1-snap.png" differ diff --git "a/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-dodge-\347\261\273\345\236\213-\345\210\235\345\247\213\345\214\226-1-snap.png" "b/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-dodge-\347\261\273\345\236\213-\345\210\235\345\247\213\345\214\226-1-snap.png" index 04b04e964..7f561dd11 100644 Binary files "a/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-dodge-\347\261\273\345\236\213-\345\210\235\345\247\213\345\214\226-1-snap.png" and "b/packages/f2/test/components/interaction/__image_snapshots__/pan-test-tsx-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-\345\271\263\347\247\273\345\222\214\347\274\251\346\224\276-dodge-\347\261\273\345\236\213-\345\210\235\345\247\213\345\214\226-1-snap.png" differ diff --git "a/packages/f2/test/components/interaction/__image_snapshots__/roam-test-tsx-\345\205\250\345\261\200\346\274\253\346\270\270\346\250\241\345\274\217-swip-\345\210\235\345\247\213\345\214\226-1-snap.png" "b/packages/f2/test/components/interaction/__image_snapshots__/roam-test-tsx-\345\205\250\345\261\200\346\274\253\346\270\270\346\250\241\345\274\217-swip-\345\210\235\345\247\213\345\214\226-1-snap.png" index 9f663dd1d..672c0f82a 100644 Binary files "a/packages/f2/test/components/interaction/__image_snapshots__/roam-test-tsx-\345\205\250\345\261\200\346\274\253\346\270\270\346\250\241\345\274\217-swip-\345\210\235\345\247\213\345\214\226-1-snap.png" and "b/packages/f2/test/components/interaction/__image_snapshots__/roam-test-tsx-\345\205\250\345\261\200\346\274\253\346\270\270\346\250\241\345\274\217-swip-\345\210\235\345\247\213\345\214\226-1-snap.png" differ diff --git "a/packages/f2/test/components/interaction/__image_snapshots__/roam-test-tsx-\345\205\250\345\261\200\346\274\253\346\270\270\346\250\241\345\274\217-\346\226\234\347\247\273\345\222\214\347\274\251\346\224\276-linear-\347\261\273\345\236\213-\345\210\235\345\247\213\345\214\226-1-snap.png" "b/packages/f2/test/components/interaction/__image_snapshots__/roam-test-tsx-\345\205\250\345\261\200\346\274\253\346\270\270\346\250\241\345\274\217-\346\226\234\347\247\273\345\222\214\347\274\251\346\224\276-linear-\347\261\273\345\236\213-\345\210\235\345\247\213\345\214\226-1-snap.png" index 3632351b3..6649ccdbd 100644 Binary files "a/packages/f2/test/components/interaction/__image_snapshots__/roam-test-tsx-\345\205\250\345\261\200\346\274\253\346\270\270\346\250\241\345\274\217-\346\226\234\347\247\273\345\222\214\347\274\251\346\224\276-linear-\347\261\273\345\236\213-\345\210\235\345\247\213\345\214\226-1-snap.png" and "b/packages/f2/test/components/interaction/__image_snapshots__/roam-test-tsx-\345\205\250\345\261\200\346\274\253\346\270\270\346\250\241\345\274\217-\346\226\234\347\247\273\345\222\214\347\274\251\346\224\276-linear-\347\261\273\345\236\213-\345\210\235\345\247\213\345\214\226-1-snap.png" differ diff --git "a/packages/f2/test/components/interaction/__image_snapshots__/roam-test-tsx-\345\205\250\345\261\200\346\274\253\346\270\270\346\250\241\345\274\217-\346\226\234\347\247\273\345\222\214\347\274\251\346\224\276-sensitive-\347\201\265\346\230\216\345\272\246-\345\210\235\345\247\213\345\214\226-1-snap.png" "b/packages/f2/test/components/interaction/__image_snapshots__/roam-test-tsx-\345\205\250\345\261\200\346\274\253\346\270\270\346\250\241\345\274\217-\346\226\234\347\247\273\345\222\214\347\274\251\346\224\276-sensitive-\347\201\265\346\230\216\345\272\246-\345\210\235\345\247\213\345\214\226-1-snap.png" index 9f663dd1d..672c0f82a 100644 Binary files "a/packages/f2/test/components/interaction/__image_snapshots__/roam-test-tsx-\345\205\250\345\261\200\346\274\253\346\270\270\346\250\241\345\274\217-\346\226\234\347\247\273\345\222\214\347\274\251\346\224\276-sensitive-\347\201\265\346\230\216\345\272\246-\345\210\235\345\247\213\345\214\226-1-snap.png" and "b/packages/f2/test/components/interaction/__image_snapshots__/roam-test-tsx-\345\205\250\345\261\200\346\274\253\346\270\270\346\250\241\345\274\217-\346\226\234\347\247\273\345\222\214\347\274\251\346\224\276-sensitive-\347\201\265\346\230\216\345\272\246-\345\210\235\345\247\213\345\214\226-1-snap.png" differ diff --git a/packages/f2/test/components/interaction/dodge-pan.test.tsx b/packages/f2/test/components/interaction/dodge-pan.test.tsx new file mode 100644 index 000000000..e3dfb44f8 --- /dev/null +++ b/packages/f2/test/components/interaction/dodge-pan.test.tsx @@ -0,0 +1,188 @@ +import { jsx } from '../../../src'; +import { Canvas, Chart, Axis, ScrollBar, Legend, Interval, Tooltip } from '../../../src'; +import { createContext, delay, gestureSimulator } from '../../util'; +const context = createContext(); + +const data = [ + { + name: '今日数据', + time: '0:00', + value: 18900, + }, + { + name: '昨日数据', + time: '0:00', + value: 2890, + }, + { + name: '今日数据', + time: '01:00', + value: 18900, + }, + { + name: '昨日数据', + time: '01:00', + value: 2890, + }, + { + name: '今日数据', + time: '02:00', + value: 18900, + }, + { + name: '昨日数据', + time: '02:00', + value: 2890, + }, + { + name: '今日数据', + time: '03:00', + value: 18900, + }, + { + name: '昨日数据', + time: '03:00', + value: 2890, + }, + { + name: '今日数据', + time: '04:00', + value: 18900, + }, + + { + name: '昨日数据', + time: '04:00', + value: 28910, + }, + { + name: '昨日数据', + time: '05:00', + value: 28910, + }, + { + name: '今日数据', + time: '05:00', + value: 18900, + }, + { + name: '今日数据', + time: '06:00', + value: 1900, + }, + + { + name: '昨日数据', + time: '06:00', + value: 280, + }, + { + name: '昨日数据', + time: '07:00', + value: 280, + }, + { + name: '今日数据', + time: '07:00', + value: 1900, + }, + { + name: '今日数据', + time: '08:00', + value: 10900, + }, + { + name: '昨日数据', + time: '08:00', + value: 22890, + }, + { + name: '今日数据', + time: '09:00', + value: 10900, + }, + { + name: '昨日数据', + time: '09:00', + value: 22890, + }, + { + name: '今日数据', + time: '10:00', + value: 10900, + }, + { + name: '昨日数据', + time: '10:00', + value: 22890, + }, +]; + +describe('dodge pan', () => { + it('init', async () => { + const { props } = ( + + + + + + + + + + + ); + + const canvas = new Canvas(props); + await canvas.render(); + await delay(1000); + expect(context).toMatchImageSnapshot(); + }); + + it('pan', async () => { + await delay(20); + await gestureSimulator(context.canvas, 'touchstart', { x: 10, y: 169 }); + await delay(20); + await gestureSimulator(context.canvas, 'touchmove', { x: 100, y: 169 }); + await delay(20); + await gestureSimulator(context.canvas, 'touchend', { x: 100, y: 169 }); + await delay(300); + expect(context).toMatchImageSnapshot(); + }); +});