Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@antv/adjust

Package Overview
Dependencies
Maintainers
29
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antv/adjust - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

16

esm/adjusts/adjust.d.ts

@@ -22,2 +22,18 @@ import { AdjustCfg, Data, Range } from '../interface';

reverseOrder: boolean;
/** 像素级组间距 */
intervalPadding: number;
/** 像素级组内间距 */
dodgePadding: number;
/** x维度长度,计算归一化padding使用 */
xDimensionLegenth: number;
/** 分组数 */
groupNum: number;
/** 用户配置宽度 */
defaultSize: number;
/** 最大宽度约束 */
maxColumnWidth: number;
/** 最小宽度约束 */
minColumnWidth: number;
/** 宽度比例 */
columnWidthRatio: number;
constructor(cfg: AdjustCfg);

@@ -24,0 +40,0 @@ abstract process(dataArray: Data[][]): Data[][];

3

esm/adjusts/dodge.d.ts

@@ -11,3 +11,6 @@ import { Data, DodgeCfg } from '../interface';

private getDodgeOffset;
private getIntervalOnlyOffset;
private getDodgeOnlyOffset;
private getIntervalAndDodgeOffset;
private getDistribution;
}

@@ -12,6 +12,14 @@ import { __extends } from "tslib";

_this.mergeData = [];
var _a = cfg.marginRatio, marginRatio = _a === void 0 ? MARGIN_RATIO : _a, _b = cfg.dodgeRatio, dodgeRatio = _b === void 0 ? DODGE_RATIO : _b, dodgeBy = cfg.dodgeBy;
var _a = cfg.marginRatio, marginRatio = _a === void 0 ? MARGIN_RATIO : _a, _b = cfg.dodgeRatio, dodgeRatio = _b === void 0 ? DODGE_RATIO : _b, dodgeBy = cfg.dodgeBy, intervalPadding = cfg.intervalPadding, dodgePadding = cfg.dodgePadding, xDimensionLength = cfg.xDimensionLength, groupNum = cfg.groupNum, defaultSize = cfg.defaultSize, maxColumnWidth = cfg.maxColumnWidth, minColumnWidth = cfg.minColumnWidth, columnWidthRatio = cfg.columnWidthRatio;
_this.marginRatio = marginRatio;
_this.dodgeRatio = dodgeRatio;
_this.dodgeBy = dodgeBy;
_this.intervalPadding = intervalPadding;
_this.dodgePadding = dodgePadding;
_this.xDimensionLegenth = xDimensionLength;
_this.groupNum = groupNum;
_this.defaultSize = defaultSize;
_this.maxColumnWidth = maxColumnWidth;
_this.minColumnWidth = minColumnWidth;
_this.columnWidthRatio = columnWidthRatio;
return _this;

@@ -61,13 +69,93 @@ }

Dodge.prototype.getDodgeOffset = function (range, idx, len) {
var _a = this, dodgeRatio = _a.dodgeRatio, marginRatio = _a.marginRatio;
var _a = this, dodgeRatio = _a.dodgeRatio, marginRatio = _a.marginRatio, intervalPadding = _a.intervalPadding, dodgePadding = _a.dodgePadding;
var pre = range.pre, next = range.next;
var tickLength = next - pre;
var width = (tickLength * dodgeRatio) / len;
var margin = marginRatio * width;
var offset = (1 / 2) * (tickLength - len * width - (len - 1) * margin) +
((idx + 1) * width + idx * margin) -
(1 / 2) * width -
(1 / 2) * tickLength;
return (pre + next) / 2 + offset;
var position;
// 分多种输入情况
if (!_.isNil(intervalPadding) && _.isNil(dodgePadding) && intervalPadding >= 0) {
// 仅配置intervalPadding
var offset = this.getIntervalOnlyOffset(len, idx);
position = pre + offset;
}
else if (!_.isNil(dodgePadding) && _.isNil(intervalPadding) && dodgePadding >= 0) {
// 仅配置dodgePadding
var offset = this.getDodgeOnlyOffset(len, idx);
position = pre + offset;
}
else if (!_.isNil(intervalPadding) &&
!_.isNil(dodgePadding) &&
intervalPadding >= 0 &&
dodgePadding >= 0) {
// 同时配置intervalPadding和dodgePadding
var offset = this.getIntervalAndDodgeOffset(len, idx);
position = pre + offset;
}
else {
// 默认情况
var width = (tickLength * dodgeRatio) / len;
var margin = marginRatio * width;
var offset = (1 / 2) * (tickLength - len * width - (len - 1) * margin) +
((idx + 1) * width + idx * margin) -
(1 / 2) * width -
(1 / 2) * tickLength;
position = (pre + next) / 2 + offset;
}
return position;
};
Dodge.prototype.getIntervalOnlyOffset = function (len, idx) {
var _a = this, defaultSize = _a.defaultSize, intervalPadding = _a.intervalPadding, xDimensionLegenth = _a.xDimensionLegenth, groupNum = _a.groupNum, dodgeRatio = _a.dodgeRatio, maxColumnWidth = _a.maxColumnWidth, minColumnWidth = _a.minColumnWidth, columnWidthRatio = _a.columnWidthRatio;
var normalizedIntervalPadding = intervalPadding / xDimensionLegenth;
var normalizedDodgePadding = (1 - (groupNum - 1) * normalizedIntervalPadding) / groupNum * dodgeRatio / (len - 1);
var geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
// 根据columnWidthRatio/defaultSize/maxColumnWidth/minColumnWidth调整宽度
geomWidth = (!_.isNil(columnWidthRatio)) ? 1 / groupNum / len * columnWidthRatio : geomWidth;
if (!_.isNil(maxColumnWidth)) {
var normalizedMaxWidht = maxColumnWidth / xDimensionLegenth;
geomWidth = Math.min(geomWidth, normalizedMaxWidht);
}
if (!_.isNil(minColumnWidth)) {
var normalizedMinWidht = minColumnWidth / xDimensionLegenth;
geomWidth = Math.max(geomWidth, normalizedMinWidht);
}
geomWidth = defaultSize ? (defaultSize / xDimensionLegenth) : geomWidth;
// 调整组内间隔
normalizedDodgePadding = ((1 - (groupNum - 1) * normalizedIntervalPadding) / groupNum - len * geomWidth) / (len - 1);
var offset = ((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
(1 / 2) * normalizedIntervalPadding) * groupNum -
normalizedIntervalPadding / 2;
return offset;
};
Dodge.prototype.getDodgeOnlyOffset = function (len, idx) {
var _a = this, defaultSize = _a.defaultSize, dodgePadding = _a.dodgePadding, xDimensionLegenth = _a.xDimensionLegenth, groupNum = _a.groupNum, marginRatio = _a.marginRatio, maxColumnWidth = _a.maxColumnWidth, minColumnWidth = _a.minColumnWidth, columnWidthRatio = _a.columnWidthRatio;
var normalizedDodgePadding = dodgePadding / xDimensionLegenth;
var normalizedIntervalPadding = 1 * marginRatio / (groupNum - 1);
var geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
// 根据columnWidthRatio/defaultSize/maxColumnWidth/minColumnWidth调整宽度
geomWidth = columnWidthRatio ? 1 / groupNum / len * columnWidthRatio : geomWidth;
if (!_.isNil(maxColumnWidth)) {
var normalizedMaxWidht = maxColumnWidth / xDimensionLegenth;
geomWidth = Math.min(geomWidth, normalizedMaxWidht);
}
if (!_.isNil(minColumnWidth)) {
var normalizedMinWidht = minColumnWidth / xDimensionLegenth;
geomWidth = Math.max(geomWidth, normalizedMinWidht);
}
geomWidth = defaultSize ? (defaultSize / xDimensionLegenth) : geomWidth;
// 调整组间距
normalizedIntervalPadding = (1 - (geomWidth * len + normalizedDodgePadding * (len - 1)) * groupNum) / (groupNum - 1);
var offset = ((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
(1 / 2) * normalizedIntervalPadding) * groupNum -
normalizedIntervalPadding / 2;
return offset;
};
Dodge.prototype.getIntervalAndDodgeOffset = function (len, idx) {
var _a = this, intervalPadding = _a.intervalPadding, dodgePadding = _a.dodgePadding, xDimensionLegenth = _a.xDimensionLegenth, groupNum = _a.groupNum;
var normalizedIntervalPadding = intervalPadding / xDimensionLegenth;
var normalizedDodgePadding = dodgePadding / xDimensionLegenth;
var geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
var offset = ((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
(1 / 2) * normalizedIntervalPadding) * groupNum -
normalizedIntervalPadding / 2;
return offset;
};
Dodge.prototype.getDistribution = function (dim) {

@@ -74,0 +162,0 @@ var groupedDataArray = this.adjustDataArray;

2

esm/adjusts/stack.js

@@ -41,3 +41,3 @@ import { __assign, __extends } from "tslib";

var x = _.get(data, xField, 0);
var y = _.get(data, yField);
var y = _.get(data, [yField]);
var xKey = x.toString();

@@ -44,0 +44,0 @@ // todo 是否应该取 _origin?因为 y 可能取到的值不正确,比如先 symmetric,再 stack!

@@ -24,2 +24,3 @@ import Adjust from './adjusts/adjust';

export { getAdjust, registerAdjust, Adjust };
export * from './interface';
//# sourceMappingURL=factory.js.map

@@ -14,2 +14,3 @@ import { getAdjust, registerAdjust } from './factory';

export { getAdjust, registerAdjust, Adjust };
export * from './interface';
//# sourceMappingURL=index.js.map

@@ -19,2 +19,10 @@ export interface AdjustCfg {

readonly dodgeBy?: string;
readonly intervalPadding?: number;
readonly dodgePadding?: number;
readonly xDimensionLength?: number;
readonly groupNum?: number;
readonly defaultSize?: number;
readonly maxColumnWidth?: number;
readonly minColumnWidth?: number;
readonly columnWidthRatio?: number;
}

@@ -21,0 +29,0 @@ export interface StackCfg {

@@ -22,2 +22,18 @@ import { AdjustCfg, Data, Range } from '../interface';

reverseOrder: boolean;
/** 像素级组间距 */
intervalPadding: number;
/** 像素级组内间距 */
dodgePadding: number;
/** x维度长度,计算归一化padding使用 */
xDimensionLegenth: number;
/** 分组数 */
groupNum: number;
/** 用户配置宽度 */
defaultSize: number;
/** 最大宽度约束 */
maxColumnWidth: number;
/** 最小宽度约束 */
minColumnWidth: number;
/** 宽度比例 */
columnWidthRatio: number;
constructor(cfg: AdjustCfg);

@@ -24,0 +40,0 @@ abstract process(dataArray: Data[][]): Data[][];

@@ -11,3 +11,6 @@ import { Data, DodgeCfg } from '../interface';

private getDodgeOffset;
private getIntervalOnlyOffset;
private getDodgeOnlyOffset;
private getIntervalAndDodgeOffset;
private getDistribution;
}

@@ -14,6 +14,14 @@ "use strict";

_this.mergeData = [];
var _a = cfg.marginRatio, marginRatio = _a === void 0 ? constant_1.MARGIN_RATIO : _a, _b = cfg.dodgeRatio, dodgeRatio = _b === void 0 ? constant_1.DODGE_RATIO : _b, dodgeBy = cfg.dodgeBy;
var _a = cfg.marginRatio, marginRatio = _a === void 0 ? constant_1.MARGIN_RATIO : _a, _b = cfg.dodgeRatio, dodgeRatio = _b === void 0 ? constant_1.DODGE_RATIO : _b, dodgeBy = cfg.dodgeBy, intervalPadding = cfg.intervalPadding, dodgePadding = cfg.dodgePadding, xDimensionLength = cfg.xDimensionLength, groupNum = cfg.groupNum, defaultSize = cfg.defaultSize, maxColumnWidth = cfg.maxColumnWidth, minColumnWidth = cfg.minColumnWidth, columnWidthRatio = cfg.columnWidthRatio;
_this.marginRatio = marginRatio;
_this.dodgeRatio = dodgeRatio;
_this.dodgeBy = dodgeBy;
_this.intervalPadding = intervalPadding;
_this.dodgePadding = dodgePadding;
_this.xDimensionLegenth = xDimensionLength;
_this.groupNum = groupNum;
_this.defaultSize = defaultSize;
_this.maxColumnWidth = maxColumnWidth;
_this.minColumnWidth = minColumnWidth;
_this.columnWidthRatio = columnWidthRatio;
return _this;

@@ -63,13 +71,93 @@ }

Dodge.prototype.getDodgeOffset = function (range, idx, len) {
var _a = this, dodgeRatio = _a.dodgeRatio, marginRatio = _a.marginRatio;
var _a = this, dodgeRatio = _a.dodgeRatio, marginRatio = _a.marginRatio, intervalPadding = _a.intervalPadding, dodgePadding = _a.dodgePadding;
var pre = range.pre, next = range.next;
var tickLength = next - pre;
var width = (tickLength * dodgeRatio) / len;
var margin = marginRatio * width;
var offset = (1 / 2) * (tickLength - len * width - (len - 1) * margin) +
((idx + 1) * width + idx * margin) -
(1 / 2) * width -
(1 / 2) * tickLength;
return (pre + next) / 2 + offset;
var position;
// 分多种输入情况
if (!_.isNil(intervalPadding) && _.isNil(dodgePadding) && intervalPadding >= 0) {
// 仅配置intervalPadding
var offset = this.getIntervalOnlyOffset(len, idx);
position = pre + offset;
}
else if (!_.isNil(dodgePadding) && _.isNil(intervalPadding) && dodgePadding >= 0) {
// 仅配置dodgePadding
var offset = this.getDodgeOnlyOffset(len, idx);
position = pre + offset;
}
else if (!_.isNil(intervalPadding) &&
!_.isNil(dodgePadding) &&
intervalPadding >= 0 &&
dodgePadding >= 0) {
// 同时配置intervalPadding和dodgePadding
var offset = this.getIntervalAndDodgeOffset(len, idx);
position = pre + offset;
}
else {
// 默认情况
var width = (tickLength * dodgeRatio) / len;
var margin = marginRatio * width;
var offset = (1 / 2) * (tickLength - len * width - (len - 1) * margin) +
((idx + 1) * width + idx * margin) -
(1 / 2) * width -
(1 / 2) * tickLength;
position = (pre + next) / 2 + offset;
}
return position;
};
Dodge.prototype.getIntervalOnlyOffset = function (len, idx) {
var _a = this, defaultSize = _a.defaultSize, intervalPadding = _a.intervalPadding, xDimensionLegenth = _a.xDimensionLegenth, groupNum = _a.groupNum, dodgeRatio = _a.dodgeRatio, maxColumnWidth = _a.maxColumnWidth, minColumnWidth = _a.minColumnWidth, columnWidthRatio = _a.columnWidthRatio;
var normalizedIntervalPadding = intervalPadding / xDimensionLegenth;
var normalizedDodgePadding = (1 - (groupNum - 1) * normalizedIntervalPadding) / groupNum * dodgeRatio / (len - 1);
var geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
// 根据columnWidthRatio/defaultSize/maxColumnWidth/minColumnWidth调整宽度
geomWidth = (!_.isNil(columnWidthRatio)) ? 1 / groupNum / len * columnWidthRatio : geomWidth;
if (!_.isNil(maxColumnWidth)) {
var normalizedMaxWidht = maxColumnWidth / xDimensionLegenth;
geomWidth = Math.min(geomWidth, normalizedMaxWidht);
}
if (!_.isNil(minColumnWidth)) {
var normalizedMinWidht = minColumnWidth / xDimensionLegenth;
geomWidth = Math.max(geomWidth, normalizedMinWidht);
}
geomWidth = defaultSize ? (defaultSize / xDimensionLegenth) : geomWidth;
// 调整组内间隔
normalizedDodgePadding = ((1 - (groupNum - 1) * normalizedIntervalPadding) / groupNum - len * geomWidth) / (len - 1);
var offset = ((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
(1 / 2) * normalizedIntervalPadding) * groupNum -
normalizedIntervalPadding / 2;
return offset;
};
Dodge.prototype.getDodgeOnlyOffset = function (len, idx) {
var _a = this, defaultSize = _a.defaultSize, dodgePadding = _a.dodgePadding, xDimensionLegenth = _a.xDimensionLegenth, groupNum = _a.groupNum, marginRatio = _a.marginRatio, maxColumnWidth = _a.maxColumnWidth, minColumnWidth = _a.minColumnWidth, columnWidthRatio = _a.columnWidthRatio;
var normalizedDodgePadding = dodgePadding / xDimensionLegenth;
var normalizedIntervalPadding = 1 * marginRatio / (groupNum - 1);
var geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
// 根据columnWidthRatio/defaultSize/maxColumnWidth/minColumnWidth调整宽度
geomWidth = columnWidthRatio ? 1 / groupNum / len * columnWidthRatio : geomWidth;
if (!_.isNil(maxColumnWidth)) {
var normalizedMaxWidht = maxColumnWidth / xDimensionLegenth;
geomWidth = Math.min(geomWidth, normalizedMaxWidht);
}
if (!_.isNil(minColumnWidth)) {
var normalizedMinWidht = minColumnWidth / xDimensionLegenth;
geomWidth = Math.max(geomWidth, normalizedMinWidht);
}
geomWidth = defaultSize ? (defaultSize / xDimensionLegenth) : geomWidth;
// 调整组间距
normalizedIntervalPadding = (1 - (geomWidth * len + normalizedDodgePadding * (len - 1)) * groupNum) / (groupNum - 1);
var offset = ((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
(1 / 2) * normalizedIntervalPadding) * groupNum -
normalizedIntervalPadding / 2;
return offset;
};
Dodge.prototype.getIntervalAndDodgeOffset = function (len, idx) {
var _a = this, intervalPadding = _a.intervalPadding, dodgePadding = _a.dodgePadding, xDimensionLegenth = _a.xDimensionLegenth, groupNum = _a.groupNum;
var normalizedIntervalPadding = intervalPadding / xDimensionLegenth;
var normalizedDodgePadding = dodgePadding / xDimensionLegenth;
var geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
var offset = ((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
(1 / 2) * normalizedIntervalPadding) * groupNum -
normalizedIntervalPadding / 2;
return offset;
};
Dodge.prototype.getDistribution = function (dim) {

@@ -76,0 +164,0 @@ var groupedDataArray = this.adjustDataArray;

@@ -43,3 +43,3 @@ "use strict";

var x = _.get(data, xField, 0);
var y = _.get(data, yField);
var y = _.get(data, [yField]);
var xKey = x.toString();

@@ -46,0 +46,0 @@ // todo 是否应该取 _origin?因为 y 可能取到的值不正确,比如先 symmetric,再 stack!

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GAP = exports.DODGE_RATIO = exports.MARGIN_RATIO = exports.DEFAULT_Y = void 0;
exports.DEFAULT_Y = 0; // 默认的 y 的值

@@ -4,0 +5,0 @@ // 偏移之后,间距

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Adjust = exports.registerAdjust = exports.getAdjust = void 0;
var tslib_1 = require("tslib");
var adjust_1 = require("./adjusts/adjust");

@@ -28,2 +30,3 @@ exports.Adjust = adjust_1.default;

exports.registerAdjust = registerAdjust;
tslib_1.__exportStar(require("./interface"), exports);
//# sourceMappingURL=factory.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Adjust = exports.registerAdjust = exports.getAdjust = void 0;
var tslib_1 = require("tslib");
var factory_1 = require("./factory");
exports.getAdjust = factory_1.getAdjust;
exports.registerAdjust = factory_1.registerAdjust;
Object.defineProperty(exports, "getAdjust", { enumerable: true, get: function () { return factory_1.getAdjust; } });
Object.defineProperty(exports, "registerAdjust", { enumerable: true, get: function () { return factory_1.registerAdjust; } });
var adjust_1 = require("./adjusts/adjust");

@@ -17,2 +19,3 @@ exports.Adjust = adjust_1.default;

factory_1.registerAdjust('Symmetric', symmetric_1.default);
tslib_1.__exportStar(require("./interface"), exports);
//# sourceMappingURL=index.js.map

@@ -19,2 +19,10 @@ export interface AdjustCfg {

readonly dodgeBy?: string;
readonly intervalPadding?: number;
readonly dodgePadding?: number;
readonly xDimensionLength?: number;
readonly groupNum?: number;
readonly defaultSize?: number;
readonly maxColumnWidth?: number;
readonly minColumnWidth?: number;
readonly columnWidthRatio?: number;
}

@@ -21,0 +29,0 @@ export interface StackCfg {

{
"name": "@antv/adjust",
"version": "0.2.2",
"version": "0.2.3",
"description": "The adjust module for G2, F2.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc