Skip to content

Commit

Permalink
deps: 升级@antv/scale
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Jul 14, 2020
1 parent 70748e5 commit 41074d5
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
},
"dependencies": {
"@antv/adjust": "~0.1.1",
"@antv/scale": "0.1.3",
"@antv/scale": "^0.3.1",
"@antv/util": "~2.0.6",
"@babel/runtime": "^7.7.7",
"@types/hammerjs": "^2.0.36",
Expand Down
22 changes: 8 additions & 14 deletions src/chart/controller/scale.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { getScale } from '@antv/scale';
import { isNil, mix, isObject, each, isArray, isString, isNumber, Array } from '../../util/common';
import Global from '../../global';
import Scale from '../../scale/index';

const SCALE_TYPES_MAP = {
linear: 'Linear',
cat: 'Cat',
timeCat: 'TimeCat',
identity: 'Identity'
};

function isFullCircle(coord) {
if (!coord.isPolar) {
Expand Down Expand Up @@ -144,12 +137,12 @@ class ScaleController {
if (def && def.type) {
def.field = field;
return {
type: SCALE_TYPES_MAP[def.type],
type: def.type,
cfg: def
};
}
return {
type: 'Identity',
type: 'identity',
cfg: {
value: field,
field: field.toString(),
Expand All @@ -165,7 +158,7 @@ class ScaleController {

if (isNumber(field) || (isNil(firstValue)) && !def) {
return {
type: 'Identity',
type: 'identity',
cfg: {
value: field,
field: field.toString(),
Expand All @@ -178,7 +171,7 @@ class ScaleController {
def && mix(cfg, def);
cfg = this._adjustRange(type, cfg);
return {
type: SCALE_TYPES_MAP[type],
type,
cfg
};
}
Expand All @@ -188,11 +181,12 @@ class ScaleController {
const { type, cfg } = this._getScaleCfg(field, data);
const scale = scales[field];
// 如果已经存在,且类型相等时直接返回
if (scale && SCALE_TYPES_MAP[scale.type] === type) {
if (scale && scale.type === type) {
scale.change(cfg);
return scale;
}
const newScale = new Scale[type](cfg);
const Scale = getScale(type);
const newScale = new Scale(cfg);
scales[field] = newScale;
return newScale;
}
Expand Down
2 changes: 0 additions & 2 deletions src/index-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import './geom/adjust/';
import './coord/polar'; // polar coordinate
import './component/axis/circle'; // the axis for polar coordinate

import './scale/time-cat'; // timeCat scale

import './component/guide'; // guide components

import * as Tooltip from './plugin/tooltip';
Expand Down
2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import './geom/adjust/';
import './coord/polar'; // polar coordinate
import './component/axis/circle'; // the axis for polar coordinate

import './scale/time-cat'; // timeCat scale

import './component/guide/arc';
import './component/guide/html';
import './component/guide/line';
Expand Down
3 changes: 1 addition & 2 deletions src/interaction/helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { toTimeStamp } from '@antv/scale/lib/time-util';
import { Array, each } from '../util/common';
import { Array, each, toTimeStamp } from '../util/common';

function getColDef(chart, field) {
let colDef;
Expand Down
14 changes: 6 additions & 8 deletions src/interaction/new/context.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { getTickMethod } from '@antv/scale';
import { getRange } from '../../util/array';
import {
EVENT_AFTER_INIT,
EVENT_AFTER_DATA_CHANGE
} from '../../chart/const';

import autoCat from '@antv/scale/lib/auto/cat';

// 判断新老values是否相等,这里只要判断前后是否相等即可
function isValuesEqual(values, newValues) {
if (values.length !== newValues.length) {
Expand Down Expand Up @@ -206,16 +205,15 @@ class Context {
const { chart, values } = this;
const scale = this.getPinchScale();

const { values: currentValues, tickCount, isRounding } = scale;
const { values: currentValues, tickCount } = scale;
// 根据当前数据的比例,和定义的tickCount计算应该需要多少个ticks
const newTickCount = Math.round(tickCount * values.length / currentValues.length);

const cat = autoCat({
maxCount: newTickCount,
data: values,
isRounding
const catTicks = getTickMethod('cat');
const ticks = catTicks({
tickCount: newTickCount,
values
});
const ticks = cat.ticks;
this.updateScale(scale, { ticks, values: currentValues });

// 更新完后,需要重新绘制一次
Expand Down
5 changes: 2 additions & 3 deletions src/plugin/filter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* filter the data out of scale' range
*/
import { each, isNumber } from '../util/common';
import TimeUtil from '@antv/scale/lib/time-util';
import { each, isNumber, toTimeStamp } from '../util/common';

function beforeGeomInit(chart) {
chart.set('limitInPlot', true);
Expand Down Expand Up @@ -42,7 +41,7 @@ function beforeGeomInit(chart) {
if (colDef.type === 'timeCat') {
const values = colDef.values;
if (isNumber(values[0])) {
value = TimeUtil.toTimeStamp(value);
value = toTimeStamp(value);
}
}

Expand Down
15 changes: 11 additions & 4 deletions src/scale/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import Scale from '@antv/scale/lib/base';
import { Scale, getScale } from '@antv/scale';

import '@antv/scale/lib/linear';
import '@antv/scale/lib/identity';
import '@antv/scale/lib/category';
const Linear = getScale('linear');
const Identity = getScale('identity');
const Category = getScale('category');
const TimeCat = getScale('timeCat');

Scale.Linear = Linear;
Scale.Identity = Identity;
Scale.Category = Category;
Scale.Cat = Category;
Scale.TimeCat = TimeCat;

export default Scale;
3 changes: 0 additions & 3 deletions src/scale/time-cat.js

This file was deleted.

20 changes: 19 additions & 1 deletion src/util/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ function directionEnabled(mode, dir) {
return false;
}

function toTimeStamp(value) {
if (isString(value)) {
if (value.indexOf('T') > 0) {
value = new Date(value).getTime();
} else {
// new Date('2010/01/10') 和 new Date('2010-01-10') 的差别在于:
// 如果仅有年月日时,前者是带有时区的: Fri Jan 10 2020 02:40:13 GMT+0800 (中国标准时间)
// 后者会格式化成 Sun Jan 10 2010 08:00:00 GMT+0800 (中国标准时间)
value = new Date(value.replace(/-/gi, '/')).getTime();
}
}
if (isDate(value)) {
value = value.getTime();
}
return value;
}

export { ArrayUtil as Array };
export * from './dom';
export {
Expand All @@ -95,5 +112,6 @@ export {
find,
isObjectValueEqual,
parsePadding,
directionEnabled
directionEnabled,
toTimeStamp
};
1 change: 0 additions & 1 deletion test/bug/issue-151-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { expect } from 'chai';
import * as F2 from '../../src/core';
import '../../src/geom/interval';
import '../../src/geom/adjust/dodge';
import '../../src/scale/time-cat';

const canvas = document.createElement('canvas');
canvas.width = 500;
Expand Down
1 change: 0 additions & 1 deletion test/bug/issue-216-spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from 'chai';
import * as F2 from '../../src/core';
import '../../src/geom/line';
import '../../src/scale/time-cat';
import * as Tooltip from '../../src/plugin/tooltip';

const canvas = document.createElement('canvas');
Expand Down
1 change: 0 additions & 1 deletion test/bug/issue-550-spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from 'chai';
import * as F2 from '../../src/core';
import '../../src/geom';
import '../../src/scale/time-cat';

describe('Issue 550', () => {
let canvas;
Expand Down
1 change: 0 additions & 1 deletion test/unit/interaction/pan-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { expect } from 'chai';
import Pan from '../../../src/interaction/pan';
import * as F2 from '../../../src/core';
import '../../../src/geom/line';
import '../../../src/scale/time-cat';
import ScrollBar from '../../../src/plugin/scroll-bar';

function snapEqual(v1, v2) {
Expand Down
1 change: 0 additions & 1 deletion test/unit/interaction/pinch-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Pinch from '../../../src/interaction/pinch';
import * as F2 from '../../../src/core';
import '../../../src/geom/line';
import '../../../src/geom/interval';
import '../../../src/scale/time-cat';

const canvas = document.createElement('canvas');
canvas.width = 375;
Expand Down
1 change: 0 additions & 1 deletion test/unit/plugin/guide-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import '../../../src/geom/';
import '../../../src/geom/adjust/';
import '../../../src/coord/polar'; // 极坐标系
import '../../../src/component/axis/circle'; // 极坐标系下的弧长坐标轴
import '../../../src/scale/time-cat'; // timeCat 类型的度量
import '../../../src/component/guide'; // 加载 guide 组件

F2.Global.guide = {
Expand Down

0 comments on commit 41074d5

Please sign in to comment.