@antv/adjust
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,10 +0,13 @@ | ||
const mix = require('@antv/util/src/mix'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class Adjust { | ||
var mix = require('@antv/util/src/mix'); | ||
_initDefaultCfg() { | ||
var Adjust = function () { | ||
Adjust.prototype._initDefaultCfg = function _initDefaultCfg() { | ||
this.adjustNames = ['x', 'y']; // 调整的维度,默认,x,y都做调整 | ||
} | ||
}; | ||
constructor(cfg) { | ||
function Adjust(cfg) { | ||
_classCallCheck(this, Adjust); | ||
this._initDefaultCfg(); | ||
@@ -17,5 +20,9 @@ mix(this, cfg); | ||
*/ | ||
processAdjust() /* dataArray */{} | ||
} | ||
Adjust.prototype.processAdjust = function processAdjust() /* dataArray */{}; | ||
return Adjust; | ||
}(); | ||
module.exports = Adjust; |
@@ -1,10 +0,23 @@ | ||
const Adjust = require('./base'); | ||
const each = require('@antv/util/src/each'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
const MARGIN_RATIO = 1 / 2; | ||
const DODGE_RATIO = 1 / 2; | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
class Dodge extends Adjust { | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
_initDefaultCfg() { | ||
var Adjust = require('./base'); | ||
var each = require('@antv/util/src/each'); | ||
var MARGIN_RATIO = 1 / 2; | ||
var DODGE_RATIO = 1 / 2; | ||
var Dodge = function (_Adjust) { | ||
_inherits(Dodge, _Adjust); | ||
function Dodge() { | ||
_classCallCheck(this, Dodge); | ||
return _possibleConstructorReturn(this, _Adjust.apply(this, arguments)); | ||
} | ||
Dodge.prototype._initDefaultCfg = function _initDefaultCfg() { | ||
/** | ||
@@ -21,35 +34,37 @@ * 调整过程中,2个数据的间距 | ||
this.adjustNames = ['x', 'y']; // 调整的维度,默认,x,y都做调整 | ||
} | ||
}; | ||
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; | ||
Dodge.prototype.getDodgeOffset = function getDodgeOffset(range, index, count) { | ||
var self = this; | ||
var pre = range.pre; | ||
var next = range.next; | ||
var tickLength = next - pre; | ||
var width = tickLength * self.dodgeRatio / count; | ||
var margin = self.marginRatio * width; | ||
var 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; | ||
Dodge.prototype.processAdjust = function processAdjust(dataArray) { | ||
var self = this; | ||
var count = dataArray.length; | ||
var xField = self.xField; | ||
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 = { | ||
for (var i = 0, len = data.length; i < len; i++) { | ||
var obj = data[i]; | ||
var value = obj[xField]; | ||
var range = { | ||
pre: value - 0.5, | ||
next: value + 0.5 | ||
}; | ||
const dodgeValue = self.getDodgeOffset(range, index, count); | ||
var dodgeValue = self.getDodgeOffset(range, index, count); | ||
obj[xField] = dodgeValue; | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
return Dodge; | ||
}(Adjust); | ||
Adjust.Dodge = Dodge; | ||
module.exports = Dodge; |
// 完整版下使用支持按照某个字段进行分组的 dodge | ||
const mix = require('@antv/util/src/mix'); | ||
const Adjust = require('./base'); | ||
const Dodge = require('./dodge'); | ||
const Stack = require('./stack'); | ||
const AdjustMixin = require('./mixin/adjust'); | ||
const DodgeMixin = require('./mixin/dodge'); | ||
const StackMixin = require('./mixin/stack'); | ||
var mix = require('@antv/util/src/mix'); | ||
var Adjust = require('./base'); | ||
var Dodge = require('./dodge'); | ||
var Stack = require('./stack'); | ||
var AdjustMixin = require('./mixin/adjust'); | ||
var DodgeMixin = require('./mixin/dodge'); | ||
var StackMixin = require('./mixin/stack'); | ||
mix(Adjust.prototype, AdjustMixin); | ||
@@ -10,0 +10,0 @@ mix(Dodge.prototype, AdjustMixin, DodgeMixin); |
@@ -1,4 +0,10 @@ | ||
const each = require('@antv/util/src/each'); | ||
const mix = require('@antv/util/src/mix'); | ||
const ArrayUtil = { | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var each = require('@antv/util/src/each'); | ||
var mix = require('@antv/util/src/mix'); | ||
var ArrayUtil = { | ||
merge: require('@antv/util/src/array/merge'), | ||
@@ -8,8 +14,15 @@ values: require('@antv/util/src/array/values') | ||
const Adjust = require('./base'); | ||
const AdjustMixin = require('./mixin/adjust'); | ||
var Adjust = require('./base'); | ||
var AdjustMixin = require('./mixin/adjust'); | ||
class Jitter extends Adjust { | ||
var Jitter = function (_Adjust) { | ||
_inherits(Jitter, _Adjust); | ||
_initDefaultCfg() { | ||
function Jitter() { | ||
_classCallCheck(this, Jitter); | ||
return _possibleConstructorReturn(this, _Adjust.apply(this, arguments)); | ||
} | ||
Jitter.prototype._initDefaultCfg = function _initDefaultCfg() { | ||
this.xField = null; // 调整对应的 x 方向对应的字段名称 | ||
@@ -19,7 +32,7 @@ this.yField = null; // 调整对应的 y 方向对应的字段名称 | ||
this.groupFields = null; // 参与分组的数据维度 | ||
} | ||
}; | ||
processAdjust(dataArray) { | ||
const self = this; | ||
const mergeData = ArrayUtil.merge(dataArray); | ||
Jitter.prototype.processAdjust = function processAdjust(dataArray) { | ||
var self = this; | ||
var mergeData = ArrayUtil.merge(dataArray); | ||
@@ -31,24 +44,26 @@ self.adjDataArray = dataArray; | ||
self.mergeData = null; | ||
} | ||
}; | ||
getAdjustOffset(pre, next) { | ||
const r = Math.random(); // 随机位置,均匀分布 | ||
const avg = next - pre; // * length | ||
const append = avg * 0.05; | ||
Jitter.prototype.getAdjustOffset = function getAdjustOffset(pre, next) { | ||
var r = Math.random(); // 随机位置,均匀分布 | ||
var avg = next - pre; // * length | ||
var append = avg * 0.05; | ||
return pre + append + avg * 0.9 * r; | ||
} | ||
}; | ||
// adjust group data | ||
_adjustGroup(group, dim, key, values) { | ||
const self = this; | ||
const range = self.getAdjustRange(dim, key, values); | ||
Jitter.prototype._adjustGroup = function _adjustGroup(group, dim, key, values) { | ||
var self = this; | ||
var range = self.getAdjustRange(dim, key, values); | ||
each(group, function (record) { | ||
record[dim] = self.getAdjustOffset(range.pre, range.next); // 获取调整的位置 | ||
}); | ||
} | ||
}; | ||
adjustDim(dim, values, data) { | ||
const self = this; | ||
const groupData = self.groupData(data, dim); | ||
Jitter.prototype.adjustDim = function adjustDim(dim, values, data) { | ||
var self = this; | ||
var groupData = self.groupData(data, dim); | ||
each(groupData, function (group, key) { | ||
@@ -58,5 +73,7 @@ key = parseFloat(key); | ||
}); | ||
} | ||
} | ||
}; | ||
return Jitter; | ||
}(Adjust); | ||
mix(Jitter.prototype, AdjustMixin); | ||
@@ -63,0 +80,0 @@ |
@@ -1,4 +0,4 @@ | ||
const DEFAULT_Y = 0; // 默认的y的值 | ||
const each = require('@antv/util/src/each'); | ||
const ArrayUtil = { | ||
var DEFAULT_Y = 0; // 默认的y的值 | ||
var each = require('@antv/util/src/each'); | ||
var ArrayUtil = { | ||
values: require('@antv/util/src/array/values') | ||
@@ -13,5 +13,6 @@ }; | ||
*/ | ||
isAdjust(dimName) { | ||
isAdjust: function isAdjust(dimName) { | ||
return this.adjustNames.indexOf(dimName) >= 0; | ||
}, | ||
/** | ||
@@ -23,6 +24,6 @@ * @protected | ||
*/ | ||
_getDimValues(mergeData) { | ||
const self = this; | ||
const valuesMap = {}; | ||
const dims = []; | ||
_getDimValues: function _getDimValues(mergeData) { | ||
var self = this; | ||
var valuesMap = {}; | ||
var dims = []; | ||
if (self.xField && self.isAdjust('x')) { | ||
@@ -35,3 +36,3 @@ dims.push(self.xField); | ||
each(dims, function (dim) { | ||
const values = ArrayUtil.values(mergeData, dim); | ||
var values = ArrayUtil.values(mergeData, dim); | ||
values.sort(function (v1, v2) { | ||
@@ -44,4 +45,4 @@ return v1 - v2; | ||
// 只有一维的情况下,同时调整y | ||
const dim = 'y'; | ||
const values = [DEFAULT_Y, 1]; // 默认分布在y轴的 0.1 与 0.2 之间 | ||
var dim = 'y'; | ||
var values = [DEFAULT_Y, 1]; // 默认分布在y轴的 0.1 与 0.2 之间 | ||
valuesMap[dim] = values; | ||
@@ -51,5 +52,5 @@ } | ||
}, | ||
adjustData(dataArray, mergeData) { | ||
const self = this; | ||
const valuesMap = self._getDimValues(mergeData); | ||
adjustData: function adjustData(dataArray, mergeData) { | ||
var self = this; | ||
var valuesMap = self._getDimValues(mergeData); | ||
each(dataArray, function (data, index) { | ||
@@ -63,8 +64,8 @@ // 遍历所有数据集合 | ||
}, | ||
getAdjustRange(dim, key, values) { | ||
const self = this; | ||
const index = values.indexOf(key); | ||
const length = values.length; | ||
let pre; | ||
let next; | ||
getAdjustRange: function getAdjustRange(dim, key, values) { | ||
var self = this; | ||
var index = values.indexOf(key); | ||
var length = values.length; | ||
var pre = void 0; | ||
var next = void 0; | ||
if (!self.yField && self.isAdjust('y')) { | ||
@@ -93,6 +94,7 @@ pre = 0; | ||
return { | ||
pre, | ||
next | ||
pre: pre, | ||
next: next | ||
}; | ||
}, | ||
/** | ||
@@ -104,7 +106,7 @@ * 对数据进行分组 | ||
*/ | ||
groupData(data, dim) { | ||
const groups = {}; | ||
groupData: function groupData(data, dim) { | ||
var groups = {}; | ||
each(data, function (record) { | ||
let value = record[dim]; | ||
var value = record[dim]; | ||
if (value === undefined) { | ||
@@ -111,0 +113,0 @@ value = record[dim] = DEFAULT_Y; |
@@ -1,2 +0,2 @@ | ||
const ArrayUtil = { | ||
var ArrayUtil = { | ||
merge: require('@antv/util/src/array/merge'), | ||
@@ -6,4 +6,4 @@ values: require('@antv/util/src/array/values') | ||
const group = require('@antv/util/src/group'); | ||
const each = require('@antv/util/src/each'); | ||
var group = require('@antv/util/src/group'); | ||
var each = require('@antv/util/src/each'); | ||
@@ -15,7 +15,7 @@ module.exports = { | ||
*/ | ||
processAdjust(dataArray) { | ||
const self = this; | ||
const mergeData = ArrayUtil.merge(dataArray); | ||
const dodgeDim = self.dodgeBy; | ||
let adjDataArray = dataArray; | ||
processAdjust: function processAdjust(dataArray) { | ||
var self = this; | ||
var mergeData = ArrayUtil.merge(dataArray); | ||
var dodgeDim = self.dodgeBy; | ||
var adjDataArray = dataArray; | ||
if (dodgeDim) { | ||
@@ -33,11 +33,11 @@ // 如果指定了分组dim的字段 | ||
}, | ||
getDistribution(dim) { | ||
const self = this; | ||
const dataArray = self.adjDataArray; | ||
const cacheMap = self.cacheMap; | ||
let map = cacheMap[dim]; | ||
getDistribution: function getDistribution(dim) { | ||
var self = this; | ||
var dataArray = self.adjDataArray; | ||
var cacheMap = self.cacheMap; | ||
var map = cacheMap[dim]; | ||
if (!map) { | ||
map = {}; | ||
each(dataArray, function (data, index) { | ||
const values = ArrayUtil.values(data, dim); | ||
var values = ArrayUtil.values(data, dim); | ||
if (!values.length) { | ||
@@ -58,10 +58,10 @@ values.push(0); | ||
}, | ||
adjustDim(dim, values, data, frameCount, frameIndex) { | ||
const self = this; | ||
const map = self.getDistribution(dim); | ||
const groupData = self.groupData(data, dim); // 根据值分组 | ||
adjustDim: function adjustDim(dim, values, data, frameCount, frameIndex) { | ||
var self = this; | ||
var map = self.getDistribution(dim); | ||
var groupData = self.groupData(data, dim); // 根据值分组 | ||
each(groupData, function (group, key) { | ||
key = parseFloat(key); | ||
let range; | ||
var range = void 0; | ||
if (values.length === 1) { | ||
@@ -76,5 +76,5 @@ range = { | ||
each(group, function (record) { | ||
const value = record[dim]; | ||
const valueArr = map[value]; | ||
const valIndex = valueArr.indexOf(frameIndex); | ||
var value = record[dim]; | ||
var valueArr = map[value]; | ||
var valIndex = valueArr.indexOf(frameIndex); | ||
record[dim] = self.getDodgeOffset(range, valIndex, valueArr.length); | ||
@@ -81,0 +81,0 @@ }); |
module.exports = { | ||
_initDefaultCfg() { | ||
_initDefaultCfg: function _initDefaultCfg() { | ||
this.xField = null; // 调整对应的 x 方向对应的字段名称 | ||
@@ -10,9 +10,9 @@ this.yField = null; // 调整对应的 y 方向对应的字段名称 | ||
}, | ||
processOneDimStack(dataArray) { | ||
const self = this; | ||
const xField = self.xField; | ||
const yField = self.yField || 'y'; | ||
const height = self.height; | ||
processOneDimStack: function processOneDimStack(dataArray) { | ||
var self = this; | ||
var xField = self.xField; | ||
var yField = self.yField || 'y'; | ||
var height = self.height; | ||
const stackY = {}; | ||
var stackY = {}; | ||
// 如果层叠的顺序翻转 | ||
@@ -22,10 +22,10 @@ if (self.reverseOrder) { | ||
} | ||
for (let i = 0, len = dataArray.length; i < len; i++) { | ||
const data = dataArray[i]; | ||
for (var i = 0, len = dataArray.length; i < len; i++) { | ||
var data = dataArray[i]; | ||
// cates | ||
for (let j = 0, dataLen = data.length; j < dataLen; j++) { | ||
const item = data[j]; | ||
const size = item.size || self.size; | ||
const stackHeight = size * 2 / height; | ||
const x = item[xField]; | ||
for (var j = 0, dataLen = data.length; j < dataLen; j++) { | ||
var item = data[j]; | ||
var size = item.size || self.size; | ||
var stackHeight = size * 2 / height; | ||
var x = item[xField]; | ||
if (!stackY[x]) { | ||
@@ -39,3 +39,3 @@ stackY[x] = stackHeight / 2; | ||
}, | ||
processAdjust(dataArray) { | ||
processAdjust: function processAdjust(dataArray) { | ||
if (this.yField) { | ||
@@ -42,0 +42,0 @@ this.processStack(dataArray); |
@@ -1,22 +0,35 @@ | ||
const isArray = require('@antv/util/src/type/isArray'); | ||
const isNil = require('@antv/util/src/type/isNil'); | ||
const Adjust = require('./base'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class Stack extends Adjust { | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
_initDefaultCfg() { | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var isArray = require('@antv/util/src/type/isArray'); | ||
var isNil = require('@antv/util/src/type/isNil'); | ||
var Adjust = require('./base'); | ||
var Stack = function (_Adjust) { | ||
_inherits(Stack, _Adjust); | ||
function Stack() { | ||
_classCallCheck(this, Stack); | ||
return _possibleConstructorReturn(this, _Adjust.apply(this, arguments)); | ||
} | ||
Stack.prototype._initDefaultCfg = function _initDefaultCfg() { | ||
this.xField = null; // 调整对应的 x 方向对应的字段名称 | ||
this.yField = null; // 调整对应的 y 方向对应的字段名称 | ||
} | ||
}; | ||
processAdjust(dataArray) { | ||
Stack.prototype.processAdjust = function processAdjust(dataArray) { | ||
this.processStack(dataArray); | ||
} | ||
}; | ||
processStack(dataArray) { | ||
const self = this; | ||
const xField = self.xField; | ||
const yField = self.yField; | ||
const count = dataArray.length; | ||
const stackCache = { | ||
Stack.prototype.processStack = function processStack(dataArray) { | ||
var self = this; | ||
var xField = self.xField; | ||
var yField = self.yField; | ||
var count = dataArray.length; | ||
var stackCache = { | ||
positive: {}, | ||
@@ -29,12 +42,12 @@ 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] || 0; | ||
let y = item[yField]; | ||
const xkey = x.toString(); | ||
for (var i = 0; i < count; i++) { | ||
var data = dataArray[i]; | ||
for (var j = 0, len = data.length; j < len; j++) { | ||
var item = data[j]; | ||
var x = item[xField] || 0; | ||
var y = item[yField]; | ||
var xkey = x.toString(); | ||
y = isArray(y) ? y[1] : y; | ||
if (!isNil(y)) { | ||
const direction = y >= 0 ? 'positive' : 'negative'; | ||
var direction = y >= 0 ? 'positive' : 'negative'; | ||
if (!stackCache[direction][xkey]) { | ||
@@ -48,6 +61,8 @@ stackCache[direction][xkey] = 0; | ||
} | ||
} | ||
} | ||
}; | ||
return Stack; | ||
}(Adjust); | ||
Adjust.Stack = Stack; | ||
module.exports = Stack; |
@@ -1,13 +0,26 @@ | ||
const each = require('@antv/util/src/each'); | ||
const maxBy = require('@antv/util/src/math/maxBy'); | ||
const isArray = require('@antv/util/src/type/isArray'); | ||
const ArrayUtil = { | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var each = require('@antv/util/src/each'); | ||
var maxBy = require('@antv/util/src/math/maxBy'); | ||
var isArray = require('@antv/util/src/type/isArray'); | ||
var ArrayUtil = { | ||
merge: require('@antv/util/src/array/merge'), | ||
values: require('@antv/util/src/array/values') | ||
}; | ||
const Adjust = require('./base'); | ||
var Adjust = require('./base'); | ||
class Symmetric extends Adjust { | ||
var Symmetric = function (_Adjust) { | ||
_inherits(Symmetric, _Adjust); | ||
_initDefaultCfg() { | ||
function Symmetric() { | ||
_classCallCheck(this, Symmetric); | ||
return _possibleConstructorReturn(this, _Adjust.apply(this, arguments)); | ||
} | ||
Symmetric.prototype._initDefaultCfg = function _initDefaultCfg() { | ||
this.xField = null; // 调整对应的 x 方向对应的字段名称 | ||
@@ -18,10 +31,12 @@ this.yField = null; // 调整对应的 y 方向对应的字段名称 | ||
this.groupFields = null; // 参与分组的数据维度 | ||
} | ||
}; | ||
// 获取最大的y值 | ||
_getMax(dim) { | ||
const self = this; | ||
const mergeData = self.mergeData; | ||
const maxRecord = maxBy(mergeData, obj => { | ||
const value = obj[dim]; | ||
Symmetric.prototype._getMax = function _getMax(dim) { | ||
var self = this; | ||
var mergeData = self.mergeData; | ||
var maxRecord = maxBy(mergeData, function (obj) { | ||
var value = obj[dim]; | ||
if (isArray(value)) { | ||
@@ -32,18 +47,20 @@ return Math.max.apply(null, value); | ||
}); | ||
const maxValue = maxRecord[dim]; | ||
const max = isArray(maxValue) ? Math.max.apply(null, maxValue) : maxValue; | ||
var maxValue = maxRecord[dim]; | ||
var max = isArray(maxValue) ? Math.max.apply(null, maxValue) : maxValue; | ||
return max; | ||
} | ||
}; | ||
// 获取每个字段最大的值 | ||
_getXValuesMax() { | ||
const self = this; | ||
const yField = self.yField; | ||
const xField = self.xField; | ||
const cache = {}; | ||
const mergeData = self.mergeData; | ||
Symmetric.prototype._getXValuesMax = function _getXValuesMax() { | ||
var self = this; | ||
var yField = self.yField; | ||
var xField = self.xField; | ||
var cache = {}; | ||
var mergeData = self.mergeData; | ||
each(mergeData, function (obj) { | ||
const xValue = obj[xField]; | ||
const yValue = obj[yField]; | ||
const max = isArray(yValue) ? Math.max.apply(null, yValue) : yValue; | ||
var xValue = obj[xField]; | ||
var yValue = obj[yField]; | ||
var max = isArray(yValue) ? Math.max.apply(null, yValue) : yValue; | ||
cache[xValue] = cache[xValue] || 0; | ||
@@ -55,22 +72,26 @@ if (cache[xValue] < max) { | ||
return cache; | ||
} | ||
}; | ||
// 入口函数 | ||
processAdjust(dataArray) { | ||
const self = this; | ||
const mergeData = ArrayUtil.merge(dataArray); | ||
Symmetric.prototype.processAdjust = function processAdjust(dataArray) { | ||
var self = this; | ||
var mergeData = ArrayUtil.merge(dataArray); | ||
self.mergeData = mergeData; | ||
self._processSymmetric(dataArray); | ||
self.mergeData = null; | ||
} | ||
}; | ||
// 处理对称 | ||
_processSymmetric(dataArray) { | ||
const self = this; | ||
const xField = self.xField; | ||
const yField = self.yField; | ||
const max = self._getMax(yField); | ||
const first = dataArray[0][0]; | ||
let cache; | ||
Symmetric.prototype._processSymmetric = function _processSymmetric(dataArray) { | ||
var self = this; | ||
var xField = self.xField; | ||
var yField = self.yField; | ||
var max = self._getMax(yField); | ||
var first = dataArray[0][0]; | ||
var cache = void 0; | ||
if (first && isArray(first[yField])) { | ||
@@ -81,9 +102,9 @@ cache = self._getXValuesMax(); | ||
each(data, function (obj) { | ||
const value = obj[yField]; | ||
let offset; | ||
var value = obj[yField]; | ||
var offset = void 0; | ||
if (isArray(value)) { | ||
const xValue = obj[xField]; | ||
const valueMax = cache[xValue]; | ||
var xValue = obj[xField]; | ||
var valueMax = cache[xValue]; | ||
offset = (max - valueMax) / 2; | ||
const tmp = []; | ||
var tmp = []; | ||
/* eslint-disable no-loop-func */ | ||
@@ -102,6 +123,8 @@ each(value, function (subVal) { | ||
}); | ||
} | ||
} | ||
}; | ||
return Symmetric; | ||
}(Adjust); | ||
Adjust.Symmetric = Symmetric; | ||
module.exports = Symmetric; |
{ | ||
"name": "@antv/adjust", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Data Adjust module for G2, F2.", | ||
@@ -5,0 +5,0 @@ "browser": "build/adjust.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
146450
41
2264