Skip to content

Commit

Permalink
fix: sample func (#2004)
Browse files Browse the repository at this point in the history
Co-authored-by: xuying.xu <[email protected]>
  • Loading branch information
tangying1027 and xuying.xu authored Oct 9, 2024
1 parent cd44a23 commit 41045d2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/f2-algorithm/src/lttbDownSample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export default function lttbDownSample(data, options?: OptionsProps) {
const len = data.length;
const targetCount = len / rate;

if (rate >= len || targetCount === 0) {
if (rate >= len || targetCount < 2) {
return data;
}

const sampled = [];
let sampledIndex = 0;
// Bucket size
// Bucket size targetCount需大于2
const bucketSize = Math.floor((len - 2) / (targetCount - 2));

// A is the first point in the triangle
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion packages/f2-algorithm/test/sample.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('sample', () => {
expect(context).toMatchImageSnapshot();
});

it('rate 小于 data个数', async () => {
it('rate 小于可抽个数', async () => {
const res = await fetch(url);
const result = [
{ value: { value: '0.516' }, updateTime: '2023-10-26T16:00:00.000Z', extInfo: null },
Expand All @@ -70,6 +70,9 @@ describe('sample', () => {
{ value: { value: '0.516' }, updateTime: '2023-10-29T16:00:00.000Z', extInfo: null },
{ value: { value: '0.472' }, updateTime: '2023-10-30T16:00:00.000Z', extInfo: null },
{ value: { value: '0.448' }, updateTime: '2023-10-31T16:00:00.000Z', extInfo: null },
{ value: { value: '0.478' }, updateTime: '2023-10-32T16:00:00.000Z', extInfo: null },
{ value: { value: '0.458' }, updateTime: '2023-10-33T16:00:00.000Z', extInfo: null },
{ value: { value: '0.455' }, updateTime: '2023-10-34T16:00:00.000Z', extInfo: null },
];
const data = result.map((d) => {
return {
Expand Down

0 comments on commit 41045d2

Please sign in to comment.