Skip to content

Commit

Permalink
feat(transformations): remove polar.theta and polar.rho
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Jun 2, 2021
1 parent 22c367d commit 7cc03e8
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 151 deletions.
46 changes: 1 addition & 45 deletions __tests__/unit/transforms/polar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Polar', () => {
test('polar() inverts correctly if angle range is not [-pi, pi]', () => {
const coord = new Coordinate().transform('polar', -Math.PI / 2, (Math.PI * 3) / 2, 0, 1);

let from = [0.6, 0.5];
let from = [0.8, 0.5];
let to = coord.map(from);
expect(coord.invert(to)[0]).toBeCloseTo(from[0]);
expect(coord.invert(to)[1]).toBeCloseTo(from[1]);
Expand All @@ -78,48 +78,4 @@ describe('Polar', () => {
expect(v1).toBe(100);
expect(v2).toBeCloseTo(20);
});

test('polar.theta() fixes radius greater than 0 to 1', () => {
const coord1 = new Coordinate({
width: 200,
height: 200,
transformations: [['polar', -Math.PI / 2, (Math.PI * 3) / 2, 0.2, 0.8], ['cartesian']],
});

const coord2 = new Coordinate({
width: 200,
height: 200,
transformations: [['polar.theta', -Math.PI / 2, (Math.PI * 3) / 2, 0.2, 0.8], ['cartesian']],
});

expect(coord1.map([0.5, 1])).toEqual(coord2.map([0.5, 0.5]));
expect(coord1.map([0, 1])).toEqual(coord2.map([0, 0.6]));

const v = coord2.map([0.5, 0.5]);
expect(coord2.invert(v)).toEqual([0.5, 1]);

expect(coord1.map([0, 0])).toEqual(coord2.map([0, 0]));
});

test('polar.rho() fixes angle getter than 0 to 1', () => {
const coord1 = new Coordinate({
width: 200,
height: 200,
transformations: [['polar', -Math.PI / 2, (Math.PI * 3) / 2, 0.2, 0.8], ['cartesian']],
});

const coord2 = new Coordinate({
width: 200,
height: 200,
transformations: [['polar.rho', -Math.PI / 2, (Math.PI * 3) / 2, 0.2, 0.8], ['cartesian']],
});

expect(coord1.map([1, 0.5])).toEqual(coord2.map([0.5, 0.5]));
expect(coord1.map([1, 0.6])).toEqual(coord2.map([0, 0.6]));

const v = coord2.map([0.5, 0.5]);
const [v1, v2] = coord2.invert(v);
expect(v1).toBeCloseTo(1);
expect(v2).toBeCloseTo(0.5);
});
});
2 changes: 0 additions & 2 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ Built-in transformations can applied to the input vector.

- [cartesian](./transformations.md#cartesian) - Transforms points in normalized cartesian system to the bounding box of the coordinate.
- [polar](./transformations.md#polar) - Transforms points in normalized polar system to normalized cartesian system.
- [polar.theta](./transformations.md#polar.theta) - Transforms points in normalized polar system which radius dimension fixed to 1 to normalized cartesian system.
- [polar.rho](./transformations.md#polar.rho) - Transforms points in normalized polar system which angle dimension fixed to 1 to normalized cartesian system.
- [helix](./transformations.md#helix) - Transforms points in normalized helix system to normalized cartesian system.
- [parallel](./transformations.md#parallel) - Transforms points in normalized parallel system to normalized cartesian system.

Expand Down
58 changes: 0 additions & 58 deletions docs/api/transformations.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,64 +183,6 @@ const coord = new Coordinate({
coord.map([0, 1]); // [100, 50]
```

<a name="polar.theta" href="#polar.theta">#</a> **transform**<i>('polar.theta', startAngle: number, endAngle: number, innerRadius: number, outerRadius: number) : Coordinate</i>

Transforms points in normalized polar system which radius dimension fixed to 1 to normalized cartesian system.

```ts
import { Coordinate } from '@antv/coord';

const coord1 = new Coordinate({
width: 200,
height: 200,
transformations: [['polar', -Math.PI / 2, (Math.PI * 3) / 2, 0.2, 0.8], ['cartesian']],
});

const coord2 = new Coordinate({
width: 200,
height: 200,
transformations: [['polar.theta', -Math.PI / 2, (Math.PI * 3) / 2, 0.2, 0.8], ['cartesian']],
});

const v1 = coord1.map([0.5, 1]);
const v2 = coord2.map([0.5, 0.5]);

v1[0] === v1[0]; // true
v2[0] === v2[0]; // true

const v = coord2.map([0.5, 0.5]);
coord2.invert(v); // [0.5, 1]
```

<a name="polar.rho" href="#polar.rho">#</a> **transform**<i>('polar.rho', startAngle: number, endAngle: number, innerRadius: number, outerRadius: number) : Coordinate</i>

Transforms points in normalized polar system which angle dimension fixed to 1 to normalized cartesian system.

```ts
import { Coordinate } from '@antv/coord';

const coord1 = new Coordinate({
width: 200,
height: 200,
transformations: [['polar', -Math.PI / 2, (Math.PI * 3) / 2, 0.2, 0.8], ['cartesian']],
});

const coord2 = new Coordinate({
width: 200,
height: 200,
transformations: [['polar.rho', -Math.PI / 2, (Math.PI * 3) / 2, 0.2, 0.8], ['cartesian']],
});

const v1 = coord1.map([1, 0.5]);
const v2 = coord2.map([0.5, 0.5]);

v1[0] === v1[0]; // true
v2[0] === v2[0]; // true

const v = coord2.map([0.5, 0.5]);
coord2.invert(v); // [1, 0.5]
```

<a name="helix" href="#helix">#</a> **transform**<i>('helix', startAngle: number, endAngle: number, innerRadius: number, outerRadius: number) : Coordinate</i>

Transforms points in normalized helix system to normalized cartesian system.
Expand Down
4 changes: 0 additions & 4 deletions src/coordinate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
custom,
matrix,
polar,
polarTheta,
polarRho,
transpose,
scale,
shearX,
Expand Down Expand Up @@ -43,8 +41,6 @@ export class Coordinate {
custom,
matrix,
polar,
'polar.theta': polarTheta,
'polar.rho': polarRho,
transpose,
scale,
'shear.x': shearX,
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { translate } from './translate';
export { cartesian } from './cartesian';
export { custom } from './custom';
export { matrix } from './matrix';
export { polar, polarRho, polarTheta } from './polar';
export { polar } from './polar';
export { transpose } from './transpose';
export { scale } from './scale';
export { reflect, reflectX, reflectY } from './reflect';
Expand Down
37 changes: 0 additions & 37 deletions src/transforms/polar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,3 @@ export const polar: CreateTransformer = (params, x, y, width, height) => {
},
};
};

/**
* Maps normalized value to normalized polar coordinate at the center of the bounding box.
* The radius dimension is fixed to 1.
* It is used for Pie Chart.
* @param args same as polar
* @returns transformer
*/
export const polarTheta: CreateTransformer = (...args) => {
const { transform, untransform } = polar(...args) as Transformer;
return {
transform(vector: Vector2) {
const theta = vector[0];
const radius = vector[1] === 0 ? 0 : 1;
return transform([theta, radius]);
},
untransform,
};
};

/**
* Maps normalized value to normalized polar coordinate at the center of the bounding box.
* The angle dimension is fixed to 1.
* It is used for Concentric Circles.
* @param args same as polar
* @returns transformer
*/
export const polarRho: CreateTransformer = (...args) => {
const { transform, untransform } = polar(...args) as Transformer;
return {
transform(vector: Vector2) {
const [, r] = vector;
return transform([1, r]); // 角度永远都是 1
},
untransform,
};
};
4 changes: 0 additions & 4 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ type Cartesian = ['cartesian'];
type Custom = ['custom', TransformCallback];
type Matrix = ['matrix', Matrix3];
type Polar = ['polar', number, number, number, number];
type PolarTheta = ['polar.theta', number, number, number, number];
type PolarRho = ['polar.rho', number, number, number, number];
type Transpose = ['transpose'];
type Scale = ['scale', number, number];
type ShearX = ['shear.x', number];
Expand All @@ -30,8 +28,6 @@ export type Transformation =
| Custom
| Matrix
| Polar
| PolarTheta
| PolarRho
| Transpose
| Scale
| ShearX
Expand Down

0 comments on commit 7cc03e8

Please sign in to comment.