@antv/attr
Advanced tools
Comparing version 0.0.3 to 0.0.4
133
lib/base.js
@@ -0,1 +1,3 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/** | ||
@@ -5,6 +7,6 @@ * @fileOverview the Attribute base class | ||
const isString = require('@antv/util/src/type/isString'); | ||
const isArray = require('@antv/util/src/type/isArray'); | ||
const mix = require('@antv/util/src/mix'); | ||
const each = require('@antv/util/src/each'); | ||
var isString = require('@antv/util/src/type/isString'); | ||
var isArray = require('@antv/util/src/type/isArray'); | ||
var mix = require('@antv/util/src/mix'); | ||
var each = require('@antv/util/src/each'); | ||
@@ -22,5 +24,7 @@ function toScaleString(scale, value) { | ||
*/ | ||
class AttributeBase { | ||
constructor(cfg) { | ||
var AttributeBase = function () { | ||
function AttributeBase(cfg) { | ||
_classCallCheck(this, AttributeBase); | ||
/** | ||
@@ -66,11 +70,13 @@ * 属性的类型 | ||
// 获取属性值,将值映射到视觉通道 | ||
_getAttrValue(scale, value) { | ||
const values = this.values; | ||
AttributeBase.prototype._getAttrValue = function _getAttrValue(scale, value) { | ||
var values = this.values; | ||
if (scale.isCategory && !this.linear) { | ||
const index = scale.translate(value); | ||
var index = scale.translate(value); | ||
return values[index % values.length]; | ||
} | ||
const percent = scale.scale(value); | ||
var percent = scale.scale(value); | ||
return this.getLinearValue(percent); | ||
} | ||
}; | ||
@@ -83,12 +89,14 @@ /** | ||
*/ | ||
getLinearValue(percent) { | ||
const values = this.values; | ||
const steps = values.length - 1; | ||
const step = Math.floor(steps * percent); | ||
const leftPercent = steps * percent - step; | ||
const start = values[step]; | ||
const end = step === steps ? start : values[step + 1]; | ||
const rstValue = start + (end - start) * leftPercent; | ||
AttributeBase.prototype.getLinearValue = function getLinearValue(percent) { | ||
var values = this.values; | ||
var steps = values.length - 1; | ||
var step = Math.floor(steps * percent); | ||
var leftPercent = steps * percent - step; | ||
var start = values[step]; | ||
var end = step === steps ? start : values[step + 1]; | ||
var rstValue = start + (end - start) * leftPercent; | ||
return rstValue; | ||
} | ||
}; | ||
@@ -101,6 +109,8 @@ /** | ||
*/ | ||
callback(value) { | ||
const self = this; | ||
const scale = self.scales[0]; | ||
let rstValue = null; | ||
AttributeBase.prototype.callback = function callback(value) { | ||
var self = this; | ||
var scale = self.scales[0]; | ||
var rstValue = null; | ||
if (scale.type === 'identity') { | ||
@@ -112,3 +122,3 @@ rstValue = scale.value; | ||
return rstValue; | ||
} | ||
}; | ||
@@ -119,12 +129,14 @@ /** | ||
*/ | ||
getNames() { | ||
const scales = this.scales; | ||
const names = this.names; | ||
const length = Math.min(scales.length, names.length); | ||
const rst = []; | ||
for (let i = 0; i < length; i++) { | ||
AttributeBase.prototype.getNames = function getNames() { | ||
var scales = this.scales; | ||
var names = this.names; | ||
var length = Math.min(scales.length, names.length); | ||
var rst = []; | ||
for (var i = 0; i < length; i++) { | ||
rst.push(names[i]); | ||
} | ||
return rst; | ||
} | ||
}; | ||
@@ -135,10 +147,12 @@ /** | ||
*/ | ||
getFields() { | ||
const scales = this.scales; | ||
const rst = []; | ||
each(scales, scale => { | ||
AttributeBase.prototype.getFields = function getFields() { | ||
var scales = this.scales; | ||
var rst = []; | ||
each(scales, function (scale) { | ||
rst.push(scale.field); | ||
}); | ||
return rst; | ||
} | ||
}; | ||
@@ -150,8 +164,10 @@ /** | ||
*/ | ||
getScale(name) { | ||
const scales = this.scales; | ||
const names = this.names; | ||
const index = names.indexOf(name); | ||
AttributeBase.prototype.getScale = function getScale(name) { | ||
var scales = this.scales; | ||
var names = this.names; | ||
var index = names.indexOf(name); | ||
return scales[index]; | ||
} | ||
}; | ||
@@ -163,8 +179,15 @@ /** | ||
*/ | ||
mapping(...params) { | ||
const scales = this.scales; | ||
const callback = this.callback; | ||
let values = params; | ||
AttributeBase.prototype.mapping = function mapping() { | ||
var scales = this.scales; | ||
var callback = this.callback; | ||
for (var _len = arguments.length, params = Array(_len), _key = 0; _key < _len; _key++) { | ||
params[_key] = arguments[_key]; | ||
} | ||
var values = params; | ||
if (callback) { | ||
for (let i = 0, len = params.length; i < len; i++) { | ||
for (var i = 0, len = params.length; i < len; i++) { | ||
params[i] = this._toOriginParam(params[i], scales[i]); | ||
@@ -176,11 +199,13 @@ } | ||
return values; | ||
} | ||
}; | ||
// 原始的参数 | ||
_toOriginParam(param, scale) { | ||
let rst = param; | ||
AttributeBase.prototype._toOriginParam = function _toOriginParam(param, scale) { | ||
var rst = param; | ||
if (!scale.isLinear) { | ||
if (isArray(param)) { | ||
rst = []; | ||
for (let i = 0, len = param.length; i < len; i++) { | ||
for (var i = 0, len = param.length; i < len; i++) { | ||
rst.push(toScaleString(scale, param[i])); | ||
@@ -193,5 +218,7 @@ } | ||
return rst; | ||
} | ||
} | ||
}; | ||
return AttributeBase; | ||
}(); | ||
module.exports = AttributeBase; |
@@ -5,12 +5,12 @@ /** | ||
*/ | ||
const isNumber = require('@antv/util/src/type/isNumber'); | ||
const isString = require('@antv/util/src/type/isString'); | ||
const each = require('@antv/util/src/each'); | ||
var isNumber = require('@antv/util/src/type/isNumber'); | ||
var isString = require('@antv/util/src/type/isString'); | ||
var each = require('@antv/util/src/each'); | ||
// const RGB_REG = /rgb\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/; | ||
const RGB_REG = /rgba?\(([\s.,0-9]+)\)/; | ||
var RGB_REG = /rgba?\(([\s.,0-9]+)\)/; | ||
// 创建辅助 tag 取颜色 | ||
function createTmp() { | ||
const i = document.createElement('i'); | ||
var i = document.createElement('i'); | ||
i.title = 'Web Colour Picker'; | ||
@@ -24,3 +24,3 @@ i.style.display = 'none'; | ||
function getValue(start, end, percent, index) { | ||
const value = start[index] + (end[index] - start[index]) * percent; | ||
var value = start[index] + (end[index] - start[index]) * percent; | ||
return value; | ||
@@ -48,8 +48,8 @@ } | ||
} | ||
const steps = colors.length - 1; | ||
const step = Math.floor(steps * percent); | ||
const left = steps * percent - step; | ||
const start = colors[step]; | ||
const end = step === steps ? start : colors[step + 1]; | ||
const rgb = arr2rgb([getValue(start, end, left, 0), getValue(start, end, left, 1), getValue(start, end, left, 2)]); | ||
var steps = colors.length - 1; | ||
var step = Math.floor(steps * percent); | ||
var left = steps * percent - step; | ||
var start = colors[step]; | ||
var end = step === steps ? start : colors[step + 1]; | ||
var rgb = arr2rgb([getValue(start, end, left, 0), getValue(start, end, left, 1), getValue(start, end, left, 2)]); | ||
return rgb; | ||
@@ -60,3 +60,3 @@ } | ||
function rgb2arr(str) { | ||
const arr = []; | ||
var arr = []; | ||
arr.push(parseInt(str.substr(1, 2), 16)); | ||
@@ -68,5 +68,5 @@ arr.push(parseInt(str.substr(3, 2), 16)); | ||
const colorCache = {}; | ||
let iEl = null; | ||
const ColorUtil = { | ||
var colorCache = {}; | ||
var iEl = null; | ||
var ColorUtil = { | ||
/** | ||
@@ -77,3 +77,3 @@ * 将颜色转换到 rgb 的格式 | ||
*/ | ||
toRGB(color) { | ||
toRGB: function toRGB(color) { | ||
// 如果已经是 rgb的格式 | ||
@@ -87,3 +87,3 @@ if (color[0] === '#' && color.length === 7) { | ||
} | ||
let rst; | ||
var rst = void 0; | ||
if (colorCache[color]) { | ||
@@ -94,4 +94,4 @@ rst = colorCache[color]; | ||
rst = document.defaultView.getComputedStyle(iEl, '').getPropertyValue('color'); | ||
const matchs = RGB_REG.exec(rst); | ||
const cArray = matchs[1].split(/\s*,\s*/); | ||
var matchs = RGB_REG.exec(rst); | ||
var cArray = matchs[1].split(/\s*,\s*/); | ||
rst = arr2rgb(cArray); | ||
@@ -103,4 +103,5 @@ colorCache[color] = rst; | ||
rgb2arr, | ||
rgb2arr: rgb2arr, | ||
/** | ||
@@ -111,8 +112,8 @@ * 获取渐变函数 | ||
*/ | ||
gradient(colors) { | ||
const points = []; | ||
gradient: function gradient(colors) { | ||
var points = []; | ||
if (isString(colors)) { | ||
colors = colors.split('-'); | ||
} | ||
each(colors, color => { | ||
each(colors, function (color) { | ||
if (color.indexOf('#') === -1) { | ||
@@ -119,0 +120,0 @@ color = ColorUtil.toRGB(color); |
@@ -1,15 +0,26 @@ | ||
const ColorUtil = require('./color-util'); | ||
const Base = require('./base'); | ||
const isString = require('@antv/util/src/type/isString'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class Color extends Base { | ||
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; } | ||
constructor(cfg) { | ||
super(cfg); | ||
this.names = ['color']; | ||
this.type = 'color'; | ||
this.gradient = null; | ||
if (isString(this.values)) { | ||
this.linear = true; | ||
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 ColorUtil = require('./color-util'); | ||
var Base = require('./base'); | ||
var isString = require('@antv/util/src/type/isString'); | ||
var Color = function (_Base) { | ||
_inherits(Color, _Base); | ||
function Color(cfg) { | ||
_classCallCheck(this, Color); | ||
var _this = _possibleConstructorReturn(this, _Base.call(this, cfg)); | ||
_this.names = ['color']; | ||
_this.type = 'color'; | ||
_this.gradient = null; | ||
if (isString(_this.values)) { | ||
_this.linear = true; | ||
} | ||
return _this; | ||
} | ||
@@ -20,6 +31,8 @@ | ||
*/ | ||
getLinearValue(percent) { | ||
let gradient = this.gradient; | ||
Color.prototype.getLinearValue = function getLinearValue(percent) { | ||
var gradient = this.gradient; | ||
if (!gradient) { | ||
const values = this.values; | ||
var values = this.values; | ||
gradient = ColorUtil.gradient(values); | ||
@@ -29,5 +42,7 @@ this.gradient = gradient; | ||
return gradient(percent); | ||
} | ||
} | ||
}; | ||
return Color; | ||
}(Base); | ||
module.exports = Color; |
@@ -1,12 +0,26 @@ | ||
const Base = require('./base'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class Opacity extends Base { | ||
constructor(cfg) { | ||
super(cfg); | ||
this.names = ['opacity']; | ||
this.type = 'opacity'; | ||
this.gradient = null; | ||
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 Base = require('./base'); | ||
var Opacity = function (_Base) { | ||
_inherits(Opacity, _Base); | ||
function Opacity(cfg) { | ||
_classCallCheck(this, Opacity); | ||
var _this = _possibleConstructorReturn(this, _Base.call(this, cfg)); | ||
_this.names = ['opacity']; | ||
_this.type = 'opacity'; | ||
_this.gradient = null; | ||
return _this; | ||
} | ||
} | ||
return Opacity; | ||
}(Base); | ||
module.exports = Opacity; |
@@ -1,21 +0,33 @@ | ||
const isNil = require('@antv/util/src/type/isNil'); | ||
const isArray = require('@antv/util/src/type/isArray'); | ||
const each = require('@antv/util/src/each'); | ||
const Base = require('./base'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class Position extends Base { | ||
constructor(cfg) { | ||
super(cfg); | ||
this.names = ['x', 'y']; | ||
this.type = 'position'; | ||
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 isNil = require('@antv/util/src/type/isNil'); | ||
var isArray = require('@antv/util/src/type/isArray'); | ||
var each = require('@antv/util/src/each'); | ||
var Base = require('./base'); | ||
var Position = function (_Base) { | ||
_inherits(Position, _Base); | ||
function Position(cfg) { | ||
_classCallCheck(this, Position); | ||
var _this = _possibleConstructorReturn(this, _Base.call(this, cfg)); | ||
_this.names = ['x', 'y']; | ||
_this.type = 'position'; | ||
return _this; | ||
} | ||
mapping(x, y) { | ||
const scales = this.scales; | ||
const coord = this.coord; | ||
const scaleX = scales[0]; | ||
const scaleY = scales[1]; | ||
let rstX; | ||
let rstY; | ||
let obj; | ||
Position.prototype.mapping = function mapping(x, y) { | ||
var scales = this.scales; | ||
var coord = this.coord; | ||
var scaleX = scales[0]; | ||
var scaleY = scales[1]; | ||
var rstX = void 0; | ||
var rstY = void 0; | ||
var obj = void 0; | ||
if (isNil(x) || isNil(y)) { | ||
@@ -27,3 +39,3 @@ return []; | ||
rstY = []; | ||
for (let i = 0, j = 0, xLen = x.length, yLen = y.length; i < xLen && j < yLen; i++, j++) { | ||
for (var i = 0, j = 0, xLen = x.length, yLen = y.length; i < xLen && j < yLen; i++, j++) { | ||
obj = coord.convertPoint({ | ||
@@ -42,3 +54,3 @@ x: scaleX.scale(x[i]), | ||
obj = coord.convertPoint({ | ||
x, | ||
x: x, | ||
y: yVal | ||
@@ -63,3 +75,3 @@ }); | ||
x: xVal, | ||
y | ||
y: y | ||
}); | ||
@@ -79,5 +91,5 @@ if (rstY && rstY !== obj.y) { | ||
y = scaleY.scale(y); | ||
const point = coord.convertPoint({ | ||
x, | ||
y | ||
var point = coord.convertPoint({ | ||
x: x, | ||
y: y | ||
}); | ||
@@ -88,5 +100,7 @@ rstX = point.x; | ||
return [rstX, rstY]; | ||
} | ||
} | ||
}; | ||
return Position; | ||
}(Base); | ||
module.exports = Position; |
@@ -1,9 +0,21 @@ | ||
const Base = require('./base'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class Shape extends Base { | ||
constructor(cfg) { | ||
super(cfg); | ||
this.names = ['shape']; | ||
this.type = 'shape'; | ||
this.gradient = null; | ||
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 Base = require('./base'); | ||
var Shape = function (_Base) { | ||
_inherits(Shape, _Base); | ||
function Shape(cfg) { | ||
_classCallCheck(this, Shape); | ||
var _this = _possibleConstructorReturn(this, _Base.call(this, cfg)); | ||
_this.names = ['shape']; | ||
_this.type = 'shape'; | ||
_this.gradient = null; | ||
return _this; | ||
} | ||
@@ -14,9 +26,13 @@ | ||
*/ | ||
getLinearValue(percent) { | ||
const values = this.values; | ||
const index = Math.round((values.length - 1) * percent); | ||
Shape.prototype.getLinearValue = function getLinearValue(percent) { | ||
var values = this.values; | ||
var index = Math.round((values.length - 1) * percent); | ||
return values[index]; | ||
} | ||
} | ||
}; | ||
return Shape; | ||
}(Base); | ||
module.exports = Shape; |
@@ -1,12 +0,26 @@ | ||
const Base = require('./base'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
class Size extends Base { | ||
constructor(cfg) { | ||
super(cfg); | ||
this.names = ['size']; | ||
this.type = 'size'; | ||
this.gradient = null; | ||
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 Base = require('./base'); | ||
var Size = function (_Base) { | ||
_inherits(Size, _Base); | ||
function Size(cfg) { | ||
_classCallCheck(this, Size); | ||
var _this = _possibleConstructorReturn(this, _Base.call(this, cfg)); | ||
_this.names = ['size']; | ||
_this.type = 'size'; | ||
_this.gradient = null; | ||
return _this; | ||
} | ||
} | ||
return Size; | ||
}(Base); | ||
module.exports = Size; |
{ | ||
"name": "@antv/attr", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "The Attribute module for G2, F2.", | ||
@@ -5,0 +5,0 @@ "browser": "build/attr.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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
2
2
1
121424
39
1940