Permalink
Browse files

chore: publich module @antv/scale and @antv/adjust.

  • Loading branch information...
simaQ committed Jun 25, 2018
1 parent 357679b commit 84e9a90f8614967abab393ac287af9142eea8ce2
@@ -89,9 +89,10 @@
"silent": false
},
"dependencies": {
"@antv/attr": "0.0.1-beta.2",
"@antv/attr": "0.0.1",
"@antv/scale": "0.0.1",
"@antv/adjust": "0.0.1",
"@antv/util": "~1.0.6",
"fecha": "~2.3.1",
"hammerjs": "^2.0.8"
}
}
@@ -69,6 +69,7 @@ class ScaleController {
const { min, max } = getRange(values);
cfg.min = min;
cfg.max = max;
cfg.nice = true; // 默认数值类型 linear 开启 nice
}
return cfg;
}

This file was deleted.

Oops, something went wrong.
@@ -1,59 +1,2 @@
/**
* @fileOverview 数据分组
* @author dxq613@gmail.com
*/
const Util = require('../../util/common');
const Adjust = require('./base');
const Global = require('../../global');
class Dodge extends Adjust {
_initDefaultCfg() {
/**
* 调整过程中,2个数据的间距
* @type {Number}
*/
this.marginRatio = Global.widthRatio.dodgeMargin;
/**
* 调整占单位宽度的比例,例如:占2个分类间距的 1/2
* @type {Number}
*/
this.dodgeRatio = Global.widthRatio.column;
}
getDodgeOffset(range, index, count) {
const self = this;
const pre = range.pre;
const next = range.next;
const tickLength = next - pre;
const width = (tickLength * self.dodgeRatio) / count;
const margin = self.marginRatio * width;
const offset = 1 / 2 * (tickLength - (count) * width - (count - 1) * margin) +
((index + 1) * width + index * margin) -
1 / 2 * width - 1 / 2 * tickLength;
return (pre + next) / 2 + offset;
}
processAdjust(dataArray) {
const self = this;
const count = dataArray.length;
const xField = self.xField;
Util.each(dataArray, function(data, index) {
for (let i = 0, len = data.length; i < len; i++) {
const obj = data[i];
const value = obj[xField];
const range = {
pre: value - 0.5,
next: value + 0.5
};
const dodgeValue = self.getDodgeOffset(range, index, count);
obj[xField] = dodgeValue;
}
});
}
}
Adjust.Dodge = Dodge;
const Dodge = require('@antv/adjust/src/dodge');
module.exports = Dodge;
@@ -1,6 +1,4 @@
const Adjust = require('./base');
require('./dodge');
require('./stack');
module.exports = Adjust;
module.exports = {
Stack: require('./stack'),
Dodge: require('./dodge')
};
@@ -1,45 +1,2 @@
/**
* @fileOverview Stack data
* @author dxq613@gmail.com
*/
const Util = require('../../util/common');
const Adjust = require('./base');
class Stack extends Adjust {
_initDefaultCfg() {
this.xField = null;
this.yField = null;
}
processAdjust(dataArray) {
const self = this;
const xField = self.xField;
const yField = self.yField;
const count = dataArray.length;
const stackCache = {
positive: {},
negative: {}
};
for (let i = 0; i < count; i++) {
const data = dataArray[i];
for (let j = 0, len = data.length; j < len; j++) {
const item = data[j];
const x = item[xField];
let y = item[yField];
const xkey = x.toString();
y = Util.isArray(y) ? y[1] : y;
const direction = y >= 0 ? 'positive' : 'negative';
if (!stackCache[direction][xkey]) {
stackCache[direction][xkey] = 0;
}
item[yField] = [ stackCache[direction][xkey], y + stackCache[direction][xkey] ];
stackCache[direction][xkey] += y;
}
}
}
}
Adjust.Stack = Stack;
const Stack = require('@antv/adjust/src/stack');
module.exports = Stack;
@@ -6,7 +6,7 @@ const FIELD_ORIGIN_Y = '_originY';
const Global = require('../global');
const Attr = require('../attr/index');
const GeometryShape = require('./shape/shape');
const Adjust = require('./adjust/base');
const Adjust = require('@antv/adjust/src/base');
function parseFields(field) {
if (Util.isArray(field)) {
@@ -6,15 +6,12 @@ const Util = require('./util/common');
*/
const Global = {
// 预先定义的度量
scales: {
nice: true
},
scales: {},
// 宽度
widthRatio: { // 宽度所占的分类的比例
column: 1 / 2, // 一般的柱状图占比 1/2
rose: 0.999999,
multiplePie: 3 / 4,
dodgeMargin: 0
multiplePie: 3 / 4
},
// 虚线配置
lineDash: [ 4, 4 ]

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 84e9a90

Please sign in to comment.