Skip to content

Commit

Permalink
fix(band): computed wrong length of adjustRange
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Jul 6, 2021
1 parent 5cc43d0 commit 2bc6f8e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 49 deletions.
10 changes: 10 additions & 0 deletions __tests__/unit/scales/band.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ describe('band scale', () => {
expect(bandScale.getStep()).toBeCloseTo(147.059, 3);
});

test('test padding-inner and padding-outer options', () => {
const scale = new Band({
domain: ['A', 'B', 'C'],
paddingInner: 1,
});
expect(scale.map('C')).toBe(1);
// @ts-ignore
expect(scale.adjustedRange).toEqual([0, 0.5, 1]);
});

test('test round option', () => {
// 取整测试
const bandScale = new Band({
Expand Down
24 changes: 0 additions & 24 deletions __tests__/unit/utils/sequence.spec.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/scales/band.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BandOptions } from '../types';
import { Ordinal } from './ordinal';
import { sequence } from '../utils/sequence';

interface BandStateOptions {
/** step 的数目。一般是 domain 的长度 */
Expand Down Expand Up @@ -78,7 +77,7 @@ function getBandState(opt: BandStateOptions) {
}

// 转化后的 range
const adjustedRange = sequence(rangeStart, rangeEnd, step);
const adjustedRange = new Array(stepAmount).fill(0).map((_, i) => rangeStart + i * step);

return {
step,
Expand Down
23 changes: 0 additions & 23 deletions src/utils/sequence.ts

This file was deleted.

0 comments on commit 2bc6f8e

Please sign in to comment.