Skip to content

Commit

Permalink
refactor(ticks): rename d3Linear to d3Ticks (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed May 8, 2021
1 parent 0fc7053 commit 67d6936
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ x.getTicks(); // [0, 5, 10]

- [x] [Wilkinson Extended](docs/tick-methods/wilkinson-extended.md) An extension of Wilkinson's algorithm for positioning tick labels on axes.
- [x] [R Pretty](docs/tick-methods/r-pretty.md) An algorithm for positioning tick labels on axes in R language.
- [x] [D3 Linear](docs/tick-methods/d3-linear.md) Linear scale ticks algorithm for d3-scale.
- [x] [D3 Linear](docs/tick-methods/d3-ticks.md) Linear scale ticks algorithm for d3-scale.

## Contribution

Expand Down
4 changes: 2 additions & 2 deletions __tests__/unit/scales/linear.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Linear, TickMethod } from '../../../src';
import { d3Linear } from '../../../src/tick-methods/d3-linear';
import { d3Ticks } from '../../../src/tick-methods/d3-ticks';

describe('Linear Scale Test', () => {
test('test default options', () => {
Expand All @@ -13,7 +13,7 @@ describe('Linear Scale Test', () => {
expect(nice).toBeFalsy();
expect(clamp).toBeFalsy();
expect(unknown).toBeUndefined();
expect(tickMethod).toBe(d3Linear);
expect(tickMethod).toBe(d3Ticks);
});

test('test map fn', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/unit/scales/pow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Pow } from '../../../src';
import { d3Linear } from '../../../src/tick-methods/d3-linear';
import { d3Ticks } from '../../../src/tick-methods/d3-ticks';

describe('pow scales', () => {
test('test default options', () => {
Expand All @@ -14,7 +14,7 @@ describe('pow scales', () => {
expect(nice).toBeFalsy();
expect(clamp).toBeFalsy();
expect(unknown).toBeUndefined();
expect(tickMethod).toBe(d3Linear);
expect(tickMethod).toBe(d3Ticks);
});

test('test when exponent is 0.5, we use Math.sqrt API, not Math.pow', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { d3Linear as fn } from '../../../src';
import { d3Ticks as fn } from '../../../src';

describe('linear ticks', () => {
test('common usage', () => {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export { Time } from './scales/time';
export { Base } from './scales/base';

// tick-methods
export { d3Linear } from './tick-methods/d3-linear';
export { d3Ticks } from './tick-methods/d3-ticks';
export { rPretty } from './tick-methods/r-pretty';
export { wilkinsonExtended } from './tick-methods/wilkinson-extended';

Expand Down
4 changes: 2 additions & 2 deletions src/scales/linear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Continuous, Transform } from './continuous';
import { LinearOptions } from '../types';
import { Base } from './base';
import { createInterpolate } from '../utils';
import { d3Linear } from '../tick-methods/d3-linear';
import { d3Ticks } from '../tick-methods/d3-ticks';

/**
* Linear 比例尺
Expand All @@ -20,7 +20,7 @@ export class Linear extends Continuous<LinearOptions> {
clamp: false,
round: false,
interpolate: createInterpolate,
tickMethod: d3Linear,
tickMethod: d3Ticks,
tickCount: 5,
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/scales/pow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Continuous, Transform } from './continuous';
import { PowOptions } from '../types';
import { Base } from './base';
import { createInterpolate } from '../utils';
import { d3Linear } from '../tick-methods/d3-linear';
import { d3Ticks } from '../tick-methods/d3-ticks';

const transformPow = (exponent: number) => {
return (x: number) => {
Expand Down Expand Up @@ -37,7 +37,7 @@ export class Pow<O extends PowOptions> extends Continuous<O> {
round: false,
exponent: 2,
interpolate: createInterpolate,
tickMethod: d3Linear,
tickMethod: d3Ticks,
tickCount: 5,
} as O;
}
Expand Down
6 changes: 3 additions & 3 deletions src/tick-methods/d3-log.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TickMethod } from 'types';
import { d3Linear } from './d3-linear';
import { d3Ticks } from './d3-ticks';
import { pows, logs } from '../utils';

export const d3Log: TickMethod = (a, b, n, base = 10) => {
Expand Down Expand Up @@ -37,9 +37,9 @@ export const d3Log: TickMethod = (a, b, n, base = 10) => {
}
}
}
if (ticks.length * 2 < n) ticks = d3Linear(min, max, n);
if (ticks.length * 2 < n) ticks = d3Ticks(min, max, n);
} else {
ticks = d3Linear(i, j, Math.min(j - i, n)).map(pow);
ticks = d3Ticks(i, j, Math.min(j - i, n)).map(pow);
}

return r ? ticks.reverse() : ticks;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TickMethod } from '../types';
import { tickIncrement } from '../utils';

export const d3Linear: TickMethod = (begin: number, end: number, count: number) => {
export const d3Ticks: TickMethod = (begin: number, end: number, count: number) => {
let n;
let ticks;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/d3-linear-nice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 参考 d3-linear nice 的实现
// 参考 d3-ticks nice 的实现
// https://github.com/d3/d3-scale

import { tickIncrement } from './ticks';
Expand Down

0 comments on commit 67d6936

Please sign in to comment.