Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getCandleYValues(value: number | number[]) {
const array = !isArray(value) ? [value] : value;
// 从大到小排序
const sorted = array.sort((a, b) => b - a);
return padEnd(sorted, 4, sorted[sorted.length - 1]);
}
function transform(view: View, options: Options): void {
options = assign({} as Options, DEFAULT_OPTIONS, options);
const field = getField(options);
// @ts-ignore
let geoView = options.geoView || options.geoDataView; // alias
if (isString(geoView)) {
geoView = view.dataSet.getView(geoView);
}
if (!geoView || geoView.dataType !== 'geo') {
throw new TypeError('Invalid geoView: must be a DataView of GEO dataType!');
}
const as = options.as;
if (!isArray(as) || as.length !== 2) {
throw new TypeError('Invalid as: it must be an array with 2 strings (e.g. [ "x", "y" ])!');
}
const lonField = as[0];
const latField = as[1];
view.rows.forEach((row) => {
const feature = geoView.geoFeatureByName(row[field]);
if (feature) {
if (geoView._projectedAs) {
row[lonField] = feature[geoView._projectedAs[0]];
row[latField] = feature[geoView._projectedAs[1]];
} else {
row[lonField] = feature.longitude;
row[latField] = feature.latitude;
}
}
});
function getLinePoints(pointInfo: ShapePoint): Point[] {
const { x, y, y0 } = pointInfo;
if (isArray(y)) {
return y.map((yItem, idx) => {
return {
x: isArray(x) ? x[idx] : x,
y: yItem,
};
});
}
// 起始点从 y0 开始
return [
{ x: x as number, y: y0 },
{ x: x as number, y },
];
}
private _setTooltip(point, _items, markersItems, target) {
const tooltip = this.tooltip;
const prePoint = this.prePoint;
if (!prePoint || (prePoint.x !== point.x || prePoint.y !== point.y)) {
const items = _uniqItems(_items);
this.prePoint = point;
const view = this.view;
const theme = this.theme;
const x = _.isArray(point.x) ? point.x[point.x.length - 1] : point.x;
const y = _.isArray(point.y) ? point.y[point.y.length - 1] : point.y;
if (!tooltip.get('visible')) {
view.emit('tooltip:show', {
x,
y,
tooltip,
});
}
const first = items[0];
let title = first.title || first.name;
if (tooltip.isContentChange(title, items)) {
view.emit('tooltip:change', {
tooltip,
x,
y,
items,
});
protected getArcPoint(mappingData: MappingDatum, index: number = 0): Point {
let arcPoint;
if (!isArray(mappingData.x) && !isArray(mappingData.y)) {
arcPoint = {
x: mappingData.x,
y: mappingData.y,
};
} else {
arcPoint = {
x: isArray(mappingData.x) ? mappingData.x[index] : mappingData.x,
y: isArray(mappingData.y) ? mappingData.y[index] : mappingData.y,
};
}
return arcPoint;
}
export function padEnd(source: string | any[], targetLength: number, padValue: any) {
if (isString(source)) {
return source.padEnd(targetLength, padValue);
} else if (isArray(source)) {
const sourceLength = source.length;
if (sourceLength < targetLength) {
const diff = targetLength - sourceLength;
for (let i = 0; i < diff; i++) {
source.push(padValue);
}
}
}
return source;
}
let rstX;
let rstY;
let obj;
const coordinate = this.coordinate;
if (_.isArray(y) && _.isArray(x)) {
rstX = [];
rstY = [];
for (let i = 0, j = 0, xLen = x.length, yLen = y.length; i < xLen && j < yLen; i += 1, j += 1) {
obj = coordinate.convertPoint({
x: x[i],
y: y[j],
});
rstX.push(obj.x);
rstY.push(obj.y);
}
} else if (_.isArray(y)) {
rstY = [];
y.forEach((yVal) => {
obj = coordinate.convertPoint({
x: x as number,
y: yVal,
});
if (rstX && rstX !== obj.x) {
if (!_.isArray(rstX)) {
rstX = [rstX];
}
rstX.push(obj.x);
} else {
rstX = obj.x;
}
rstY.push(obj.y);
});
function getColumnValues(view: View, column: string): any[] {
let values = view.getColumn(column);
if (isArray(values) && isArray(values[0])) {
values = flattenDeep(values);
}
return values;
}
private _convertPoint(mappedRecord: MappedRecord) {
const { x, y } = mappedRecord;
if (_.isNil(x) || _.isNil(y)) {
return;
}
let rstX;
let rstY;
let obj;
const coordinate = this.coordinate;
if (_.isArray(y) && _.isArray(x)) {
rstX = [];
rstY = [];
for (let i = 0, j = 0, xLen = x.length, yLen = y.length; i < xLen && j < yLen; i += 1, j += 1) {
obj = coordinate.convertPoint({
x: x[i],
y: y[j],
});
rstX.push(obj.x);
rstY.push(obj.y);
}
} else if (_.isArray(y)) {
rstY = [];
y.forEach((yVal) => {
obj = coordinate.convertPoint({
x: x as number,
y: yVal,