Skip to content

Commit

Permalink
Merge pull request #992 from antvis/fix-cat-ticks
Browse files Browse the repository at this point in the history
fix: 统一cat ticks 计算
  • Loading branch information
zengyue authored Aug 14, 2020
2 parents 8420dd7 + 2afe66f commit ab1a995
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/interaction/new/context.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTickMethod } from '@antv/scale';
import { getTickMethod } from '../../scale';
import { getRange } from '../../util/array';
import {
EVENT_AFTER_INIT,
Expand Down
7 changes: 5 additions & 2 deletions src/scale/timecat-tick.js → src/scale/cat-tick.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// timeCat平均算法,保头保尾
// cat平均算法,保头保尾
export default cfg => {

const { values, tickCount = 3 } = cfg;
const { values, tickCount } = cfg;
if (!tickCount) {
return values;
}
if (values.length <= 1) {
return values;
}
Expand Down
11 changes: 6 additions & 5 deletions src/scale/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Scale, getScale, registerTickMethod } from '@antv/scale';
import TimeCatTick from './timecat-tick';
import { Scale, getScale, registerTickMethod, getTickMethod } from '@antv/scale';
import CatTick from './cat-tick';
import LinearTick from './linear-tick';

const Linear = getScale('linear');
const Identity = getScale('identity');
const Category = getScale('category');
const TimeCat = getScale('timeCat');

// 覆盖0.3.x的 timecat scale算法
registerTickMethod('time-cat', TimeCatTick);
// 覆盖0.3.x的 cat 方法
registerTickMethod('cat', CatTick);
registerTickMethod('time-cat', CatTick);
// 覆盖linear 度量的tick算法
registerTickMethod('wilkinson-extended', LinearTick);

Expand All @@ -19,4 +20,4 @@ Scale.Cat = Category;
Scale.TimeCat = TimeCat;

export default Scale;
export { getScale };
export { getScale, getTickMethod };
1 change: 1 addition & 0 deletions test/unit/interaction/new/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('Interaction', () => {
const interactionContext = chart.get('interactionContext');
interactionContext.start();
interactionContext.doZoom(0.5, 0.5, 1.5);
interactionContext.updateTicks();

chart.get('canvas').emit('pinchstart', {});
expect(onStartCallback.mock.calls.length).toEqual(1);
Expand Down
10 changes: 5 additions & 5 deletions test/unit/scale/timecat-spec.js → test/unit/scale/cat-spec.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import timecatTick from '../../../src/scale/timecat-tick';
import catTick from '../../../src/scale/cat-tick';

describe('Scale controller', function() {
it('tickCount 3', () => {
const ticks = timecatTick({
const ticks = catTick({
tickCount: 3,
values: [ 1590076800000, 1590336000000, 1590422400000, 1590508800000, 1590595200000, 1590681600000, 1590940800000, 1591027200000, 1591113600000, 1591200000000, 1591286400000, 1591545600000, 1591632000000, 1591718400000, 1591804800000, 1591891200000, 1592150400000, 1592236800000, 1592323200000, 1592409600000, 1592496000000, 1592755200000, 1592841600000, 1592928000000 ]
});
expect(ticks).toEqual([ 1590076800000, 1591632000000, 1592928000000 ]);
});

it('tickCount 5', () => {
const ticks = timecatTick({
const ticks = catTick({
tickCount: 5,
values: [ 1590076800000, 1590336000000, 1590422400000, 1590508800000, 1590595200000, 1590681600000, 1590940800000, 1591027200000, 1591113600000, 1591200000000, 1591286400000, 1591545600000, 1591632000000, 1591718400000, 1591804800000, 1591891200000, 1592150400000, 1592236800000, 1592323200000, 1592409600000, 1592496000000, 1592755200000, 1592841600000, 1592928000000 ]
});
expect(ticks).toEqual([ 1590076800000, 1590940800000, 1591632000000, 1592323200000, 1592928000000 ]);
});

it('values 2', () => {
const ticks = timecatTick({
const ticks = catTick({
tickCount: 3,
values: [ 1590076800000, 1591632000000 ]
});
Expand All @@ -27,7 +27,7 @@ describe('Scale controller', function() {


it('values 1', () => {
const ticks = timecatTick({
const ticks = catTick({
tickCount: 3,
values: [ 1590076800000 ]
});
Expand Down

0 comments on commit ab1a995

Please sign in to comment.