@visactor/vchart
Version:
charts lib based @visactor/VGrammar
1,301 lines (1,216 loc) • 4.7 MB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.VChart = {}));
})(this, (function (exports) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __rest$e(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
}
function __awaiter$a(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
const arrayParser = (array) => {
return array;
};
exports.RenderModeEnum = void 0;
(function (RenderModeEnum) {
RenderModeEnum["desktop-browser"] = "desktop-browser";
RenderModeEnum["mobile-browser"] = "mobile-browser";
RenderModeEnum["node"] = "node";
RenderModeEnum["worker"] = "worker";
RenderModeEnum["miniApp"] = "miniApp";
RenderModeEnum["wx"] = "wx";
RenderModeEnum["tt"] = "tt";
RenderModeEnum["harmony"] = "harmony";
RenderModeEnum["desktop-miniApp"] = "desktop-miniApp";
RenderModeEnum["lynx"] = "lynx";
})(exports.RenderModeEnum || (exports.RenderModeEnum = {}));
var ComponentTypeEnum;
(function (ComponentTypeEnum) {
ComponentTypeEnum["cartesianAxis"] = "cartesianAxis";
ComponentTypeEnum["cartesianBandAxis"] = "cartesianAxis-band";
ComponentTypeEnum["cartesianLinearAxis"] = "cartesianAxis-linear";
ComponentTypeEnum["cartesianTimeAxis"] = "cartesianAxis-time";
ComponentTypeEnum["cartesianLogAxis"] = "cartesianAxis-log";
ComponentTypeEnum["cartesianSymlogAxis"] = "cartesianAxis-symlog";
ComponentTypeEnum["polarAxis"] = "polarAxis";
ComponentTypeEnum["polarBandAxis"] = "polarAxis-band";
ComponentTypeEnum["polarLinearAxis"] = "polarAxis-linear";
ComponentTypeEnum["crosshair"] = "crosshair";
ComponentTypeEnum["cartesianCrosshair"] = "cartesianCrosshair";
ComponentTypeEnum["polarCrosshair"] = "polarCrosshair";
ComponentTypeEnum["dataZoom"] = "dataZoom";
ComponentTypeEnum["geoCoordinate"] = "geoCoordinate";
ComponentTypeEnum["indicator"] = "indicator";
ComponentTypeEnum["discreteLegend"] = "discreteLegend";
ComponentTypeEnum["continuousLegend"] = "continuousLegend";
ComponentTypeEnum["colorLegend"] = "colorLegend";
ComponentTypeEnum["sizeLegend"] = "sizeLegend";
ComponentTypeEnum["markLine"] = "markLine";
ComponentTypeEnum["markArea"] = "markArea";
ComponentTypeEnum["markPoint"] = "markPoint";
ComponentTypeEnum["polarMarkLine"] = "polarMarkLine";
ComponentTypeEnum["polarMarkArea"] = "polarMarkArea";
ComponentTypeEnum["polarMarkPoint"] = "polarMarkPoint";
ComponentTypeEnum["geoMarkPoint"] = "geoMarkPoint";
ComponentTypeEnum["tooltip"] = "tooltip";
ComponentTypeEnum["title"] = "title";
ComponentTypeEnum["player"] = "player";
ComponentTypeEnum["scrollBar"] = "scrollBar";
ComponentTypeEnum["label"] = "label";
ComponentTypeEnum["totalLabel"] = "totalLabel";
ComponentTypeEnum["brush"] = "brush";
ComponentTypeEnum["poptip"] = "poptip";
ComponentTypeEnum["customMark"] = "customMark";
})(ComponentTypeEnum || (ComponentTypeEnum = {}));
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
var eventemitter3 = {exports: {}};
(function (module) {
var has = Object.prototype.hasOwnProperty,
prefix = '~';
/**
* Constructor to create a storage for our `EE` objects.
* An `Events` instance is a plain object whose properties are event names.
*
* @constructor
* @private
*/
function Events() {}
//
// We try to not inherit from `Object.prototype`. In some engines creating an
// instance in this way is faster than calling `Object.create(null)` directly.
// If `Object.create(null)` is not supported we prefix the event names with a
// character to make sure that the built-in object properties are not
// overridden or used as an attack vector.
//
if (Object.create) {
Events.prototype = Object.create(null);
//
// This hack is needed because the `__proto__` property is still inherited in
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
//
if (!new Events().__proto__) prefix = false;
}
/**
* Representation of a single event listener.
*
* @param {Function} fn The listener function.
* @param {*} context The context to invoke the listener with.
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
* @constructor
* @private
*/
function EE(fn, context, once) {
this.fn = fn;
this.context = context;
this.once = once || false;
}
/**
* Add a listener for a given event.
*
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} context The context to invoke the listener with.
* @param {Boolean} once Specify if the listener is a one-time listener.
* @returns {EventEmitter}
* @private
*/
function addListener(emitter, event, fn, context, once) {
if (typeof fn !== 'function') {
throw new TypeError('The listener must be a function');
}
var listener = new EE(fn, context || emitter, once),
evt = prefix ? prefix + event : event;
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);else emitter._events[evt] = [emitter._events[evt], listener];
return emitter;
}
/**
* Clear event by name.
*
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
* @param {(String|Symbol)} evt The Event name.
* @private
*/
function clearEvent(emitter, evt) {
if (--emitter._eventsCount === 0) emitter._events = new Events();else delete emitter._events[evt];
}
/**
* Minimal `EventEmitter` interface that is molded against the Node.js
* `EventEmitter` interface.
*
* @constructor
* @public
*/
function EventEmitter() {
this._events = new Events();
this._eventsCount = 0;
}
/**
* Return an array listing the events for which the emitter has registered
* listeners.
*
* @returns {Array}
* @public
*/
EventEmitter.prototype.eventNames = function eventNames() {
var names = [],
events,
name;
if (this._eventsCount === 0) return names;
for (name in events = this._events) {
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
}
if (Object.getOwnPropertySymbols) {
return names.concat(Object.getOwnPropertySymbols(events));
}
return names;
};
/**
* Return the listeners registered for a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Array} The registered listeners.
* @public
*/
EventEmitter.prototype.listeners = function listeners(event) {
var evt = prefix ? prefix + event : event,
handlers = this._events[evt];
if (!handlers) return [];
if (handlers.fn) return [handlers.fn];
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
ee[i] = handlers[i].fn;
}
return ee;
};
/**
* Return the number of listeners listening to a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Number} The number of listeners.
* @public
*/
EventEmitter.prototype.listenerCount = function listenerCount(event) {
var evt = prefix ? prefix + event : event,
listeners = this._events[evt];
if (!listeners) return 0;
if (listeners.fn) return 1;
return listeners.length;
};
/**
* Calls each of the listeners registered for a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Boolean} `true` if the event had listeners, else `false`.
* @public
*/
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
var evt = prefix ? prefix + event : event;
if (!this._events[evt]) return false;
var listeners = this._events[evt],
len = arguments.length,
args,
i;
if (listeners.fn) {
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
switch (len) {
case 1:
return listeners.fn.call(listeners.context), true;
case 2:
return listeners.fn.call(listeners.context, a1), true;
case 3:
return listeners.fn.call(listeners.context, a1, a2), true;
case 4:
return listeners.fn.call(listeners.context, a1, a2, a3), true;
case 5:
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
case 6:
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
}
for (i = 1, args = new Array(len - 1); i < len; i++) {
args[i - 1] = arguments[i];
}
listeners.fn.apply(listeners.context, args);
} else {
var length = listeners.length,
j;
for (i = 0; i < length; i++) {
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
switch (len) {
case 1:
listeners[i].fn.call(listeners[i].context);
break;
case 2:
listeners[i].fn.call(listeners[i].context, a1);
break;
case 3:
listeners[i].fn.call(listeners[i].context, a1, a2);
break;
case 4:
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
break;
default:
if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
args[j - 1] = arguments[j];
}
listeners[i].fn.apply(listeners[i].context, args);
}
}
}
return true;
};
/**
* Add a listener for a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} [context=this] The context to invoke the listener with.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.on = function on(event, fn, context) {
return addListener(this, event, fn, context, false);
};
/**
* Add a one-time listener for a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} [context=this] The context to invoke the listener with.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.once = function once(event, fn, context) {
return addListener(this, event, fn, context, true);
};
/**
* Remove the listeners of a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn Only remove the listeners that match this function.
* @param {*} context Only remove the listeners that have this context.
* @param {Boolean} once Only remove one-time listeners.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
var evt = prefix ? prefix + event : event;
if (!this._events[evt]) return this;
if (!fn) {
clearEvent(this, evt);
return this;
}
var listeners = this._events[evt];
if (listeners.fn) {
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
clearEvent(this, evt);
}
} else {
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
events.push(listeners[i]);
}
}
//
// Reset the array, or remove it completely if we have no more listeners.
//
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;else clearEvent(this, evt);
}
return this;
};
/**
* Remove all listeners, or those of the specified event.
*
* @param {(String|Symbol)} [event] The event name.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
var evt;
if (event) {
evt = prefix ? prefix + event : event;
if (this._events[evt]) clearEvent(this, evt);
} else {
this._events = new Events();
this._eventsCount = 0;
}
return this;
};
//
// Alias methods names because people roll like that.
//
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
//
// Expose the prefix.
//
EventEmitter.prefixed = prefix;
//
// Allow `EventEmitter` to be imported as module namespace.
//
EventEmitter.EventEmitter = EventEmitter;
//
// Expose the module.
//
{
module.exports = EventEmitter;
}
})(eventemitter3);
var eventemitter3Exports = eventemitter3.exports;
var EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports);
const isType = (value, type) => Object.prototype.toString.call(value) === `[object ${type}]`;
var isType$1 = isType;
const isBoolean = (value, fuzzy = !1) => fuzzy ? "boolean" == typeof value : !0 === value || !1 === value || isType$1(value, "Boolean");
var isBoolean$1 = isBoolean;
const isFunction = value => "function" == typeof value;
var isFunction$1 = isFunction;
const isNil = value => null == value;
var isNil$1 = isNil;
const isValid = value => null != value;
var isValid$1 = isValid;
const isObject$1 = value => {
const type = typeof value;
return null !== value && "object" === type || "function" === type;
};
var isObject$2 = isObject$1;
const isObjectLike = value => "object" == typeof value && null !== value;
var isObjectLike$1 = isObjectLike;
const isPlainObject = function (value) {
if (!isObjectLike$1(value) || !isType$1(value, "Object")) return !1;
if (null === Object.getPrototypeOf(value)) return !0;
let proto = value;
for (; null !== Object.getPrototypeOf(proto);) proto = Object.getPrototypeOf(proto);
return Object.getPrototypeOf(value) === proto;
};
var isPlainObject$1 = isPlainObject;
const isUndefined = value => void 0 === value;
var isUndefined$1 = isUndefined;
const isString = (value, fuzzy = !1) => {
const type = typeof value;
return fuzzy ? "string" === type : "string" === type || isType$1(value, "String");
};
var isString$1 = isString;
const isArray = value => Array.isArray ? Array.isArray(value) : isType$1(value, "Array");
var isArray$1 = isArray;
const isArrayLike = function (value) {
return null !== value && "function" != typeof value && Number.isFinite(value.length);
};
var isArrayLike$1 = isArrayLike;
const isDate = value => isType$1(value, "Date");
var isDate$1 = isDate;
const isNumber = (value, fuzzy = !1) => {
const type = typeof value;
return fuzzy ? "number" === type : "number" === type || isType$1(value, "Number");
};
var isNumber$1 = isNumber;
const isNumeric = value => "string" == typeof value && !isNaN(Number(value)) && !isNaN(parseFloat(value));
var isNumeric$1 = isNumeric;
const isValidNumber = value => isNumber$1(value) && Number.isFinite(value);
var isValidNumber$1 = isValidNumber;
const isValidUrl = value => new RegExp(/^(http(s)?:\/\/)\w+[^\s]+(\.[^\s]+){1,}$/).test(value);
var isValidUrl$1 = isValidUrl;
const isBase64 = value => new RegExp(/^data:image\/(?:gif|png|jpeg|bmp|webp|svg\+xml)(?:;charset=utf-8)?;base64,(?:[A-Za-z0-9]|[+/])+={0,2}/g).test(value);
var isBase64$1 = isBase64;
const getType = value => ({}).toString.call(value).replace(/^\[object /, "").replace(/]$/, "");
var getType$1 = getType;
const objectProto = Object.prototype,
isPrototype = function (value) {
const Ctor = value && value.constructor;
return value === ("function" == typeof Ctor && Ctor.prototype || objectProto);
};
var isPrototype$1 = isPrototype;
const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
function isEmpty(value) {
if (isNil$1(value)) return !0;
if (isArrayLike$1(value)) return !value.length;
const type = getType$1(value);
if ("Map" === type || "Set" === type) return !value.size;
if (isPrototype$1(value)) return !Object.keys(value).length;
for (const key in value) if (hasOwnProperty$1.call(value, key)) return !1;
return !0;
}
const get = (obj, path, defaultValue) => {
const paths = isString$1(path) ? path.split(".") : path;
for (let p = 0; p < paths.length; p++) obj = obj ? obj[paths[p]] : void 0;
return void 0 === obj ? defaultValue : obj;
};
var get$1 = get;
const hasOwnProperty = Object.prototype.hasOwnProperty,
has = (object, key) => null != object && hasOwnProperty.call(object, key);
var has$1 = has;
function cloneDeep(value, ignoreWhen, excludeKeys) {
let result;
if (!isValid$1(value) || "object" != typeof value || ignoreWhen && ignoreWhen(value)) return value;
const isArr = isArray$1(value),
length = value.length;
result = isArr ? new Array(length) : "object" == typeof value ? {} : isBoolean$1(value) || isNumber$1(value) || isString$1(value) ? value : isDate$1(value) ? new Date(+value) : void 0;
const props = isArr ? void 0 : Object.keys(Object(value));
let index = -1;
if (result) for (; ++index < (props || value).length;) {
const key = props ? props[index] : index,
subValue = value[key];
excludeKeys && excludeKeys.includes(key.toString()) ? result[key] = subValue : result[key] = cloneDeep(subValue, ignoreWhen, excludeKeys);
}
return result;
}
function baseMerge(target, source, shallowArray = !1, skipTargetArray = !1) {
if (source) {
if (target === source) return;
if (isValid$1(source) && "object" == typeof source) {
const iterable = Object(source),
props = [];
for (const key in iterable) props.push(key);
let {
length: length
} = props,
propIndex = -1;
for (; length--;) {
const key = props[++propIndex];
!isValid$1(iterable[key]) || "object" != typeof iterable[key] || skipTargetArray && isArray$1(target[key]) ? assignMergeValue(target, key, iterable[key]) : baseMergeDeep(target, source, key, shallowArray, skipTargetArray);
}
}
}
}
function baseMergeDeep(target, source, key, shallowArray = !1, skipTargetArray = !1) {
const objValue = target[key],
srcValue = source[key];
let newValue = source[key],
isCommon = !0;
if (isArray$1(srcValue)) {
if (shallowArray) newValue = [];else if (isArray$1(objValue)) newValue = objValue;else if (isArrayLike$1(objValue)) {
newValue = new Array(objValue.length);
let index = -1;
const length = objValue.length;
for (; ++index < length;) newValue[index] = objValue[index];
}
} else isPlainObject$1(srcValue) ? (newValue = null != objValue ? objValue : {}, "function" != typeof objValue && "object" == typeof objValue || (newValue = {})) : isCommon = !1;
isCommon && baseMerge(newValue, srcValue, shallowArray, skipTargetArray), assignMergeValue(target, key, newValue);
}
function assignMergeValue(target, key, value) {
(void 0 !== value && !eq(target[key], value) || void 0 === value && !(key in target)) && (target[key] = value);
}
function eq(value, other) {
return value === other || Number.isNaN(value) && Number.isNaN(other);
}
function merge$1(target, ...sources) {
let sourceIndex = -1;
const length = sources.length;
for (; ++sourceIndex < length;) {
baseMerge(target, sources[sourceIndex], !0);
}
return target;
}
function pickWithout(obj, keys) {
if (!obj || !isPlainObject$1(obj)) return obj;
const result = {};
return Object.keys(obj).forEach(k => {
const v = obj[k];
let match = !1;
keys.forEach(itKey => {
(isString$1(itKey) && itKey === k || itKey instanceof RegExp && k.match(itKey)) && (match = !0);
}), match || (result[k] = v);
}), result;
}
function objToString(obj) {
return Object.prototype.toString.call(obj);
}
function objectKeys(obj) {
return Object.keys(obj);
}
function isEqual(a, b, options) {
if (a === b) return !0;
if (typeof a != typeof b) return !1;
if (null == a || null == b) return !1;
if (Number.isNaN(a) && Number.isNaN(b)) return !0;
if (objToString(a) !== objToString(b)) return !1;
if (isFunction$1(a)) return !!(null == options ? void 0 : options.skipFunction);
if ("object" != typeof a) return !1;
if (isArray$1(a)) {
if (a.length !== b.length) return !1;
for (let i = a.length - 1; i >= 0; i--) if (!isEqual(a[i], b[i], options)) return !1;
return !0;
}
if (!isPlainObject$1(a)) return !1;
const ka = objectKeys(a),
kb = objectKeys(b);
if (ka.length !== kb.length) return !1;
ka.sort(), kb.sort();
for (let i = ka.length - 1; i >= 0; i--) if (ka[i] != kb[i]) return !1;
for (let i = ka.length - 1; i >= 0; i--) {
const key = ka[i];
if (!isEqual(a[key], b[key], options)) return !1;
}
return !0;
}
function keys(obj) {
if (!obj) return [];
if (Object.keys) return Object.keys(obj);
const keyList = [];
for (const key in obj) obj.hasOwnProperty(key) && keyList.push(key);
return keyList;
}
function defaults(target, source, overlay) {
const keysArr = keys(source);
for (let i = 0; i < keysArr.length; i++) {
const key = keysArr[i];
(overlay ? null != source[key] : null == target[key]) && (target[key] = source[key]);
}
return target;
}
function mixin(target, source, override = !0) {
if (target = "prototype" in target ? target.prototype : target, source = "prototype" in source ? source.prototype : source, Object.getOwnPropertyNames) {
const keyList = Object.getOwnPropertyNames(source);
for (let i = 0; i < keyList.length; i++) {
const key = keyList[i];
"constructor" !== key && (override ? null != source[key] : null == target[key]) && (target[key] = source[key]);
}
} else defaults(target, source, override);
}
function array(arr) {
return isValid$1(arr) ? isArray$1(arr) ? arr : [arr] : [];
}
function last(val) {
if (isArrayLike$1(val)) {
return val[val.length - 1];
}
}
const maxInArray = (arr, compareFn) => {
var _a;
if (0 === arr.length) return;
let max = arr[0];
for (let i = 1; i < arr.length; i++) {
const value = arr[i];
(null !== (_a = null == compareFn ? void 0 : compareFn(value, max)) && void 0 !== _a ? _a : value - max) > 0 && (max = value);
}
return max;
};
const minInArray = (arr, compareFn) => {
var _a;
if (0 === arr.length) return;
let min = arr[0];
for (let i = 1; i < arr.length; i++) {
const value = arr[i];
(null !== (_a = null == compareFn ? void 0 : compareFn(value, min)) && void 0 !== _a ? _a : value - min) < 0 && (min = value);
}
return min;
};
function arrayEqual(a, b) {
if (!isArray$1(a) || !isArray$1(b)) return !1;
if (a.length !== b.length) return !1;
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return !1;
return !0;
}
function uniqArray(arr) {
return arr && isArray$1(arr) ? Array.from(new Set(array(arr))) : arr;
}
function shuffleArray(arr, random = Math.random) {
let j,
x,
i = arr.length;
for (; i;) j = Math.floor(random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x;
return arr;
}
function flattenArray(arr) {
if (!isArray$1(arr)) return [arr];
const result = [];
for (const value of arr) result.push(...flattenArray(value));
return result;
}
function range(start, stop, step) {
isValid$1(stop) || (stop = start, start = 0), isValid$1(step) || (step = 1);
let i = -1;
const n = 0 | Math.max(0, Math.ceil((stop - start) / step)),
range = new Array(n);
for (; ++i < n;) range[i] = start + i * step;
return range;
}
function ascending$1(a, b) {
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
}
function toNumber(a) {
return Number(a);
}
function quantileSorted(values, percent, valueof = toNumber) {
const n = values.length;
if (!n) return;
if (percent <= 0 || n < 2) return valueof(values[0], 0, values);
if (percent >= 1) return valueof(values[n - 1], n - 1, values);
const i = (n - 1) * percent,
i0 = Math.floor(i),
value0 = valueof(values[i0], i0, values);
return value0 + (valueof(values[i0 + 1], i0 + 1, values) - value0) * (i - i0);
}
const hasConsole = "undefined" != typeof console;
function log$2(method, level, input) {
const args = [level].concat([].slice.call(input));
hasConsole && console[method].apply(console, args);
}
var LoggerLevel;
!function (LoggerLevel) {
LoggerLevel[LoggerLevel.None = 0] = "None", LoggerLevel[LoggerLevel.Error = 1] = "Error", LoggerLevel[LoggerLevel.Warn = 2] = "Warn", LoggerLevel[LoggerLevel.Info = 3] = "Info", LoggerLevel[LoggerLevel.Debug = 4] = "Debug";
}(LoggerLevel || (LoggerLevel = {}));
class Logger {
static getInstance(level, method) {
return Logger._instance && isNumber$1(level) ? Logger._instance.level(level) : Logger._instance || (Logger._instance = new Logger(level, method)), Logger._instance;
}
static setInstance(logger) {
return Logger._instance = logger;
}
static setInstanceLevel(level) {
Logger._instance ? Logger._instance.level(level) : Logger._instance = new Logger(level);
}
static clearInstance() {
Logger._instance = null;
}
constructor(level = LoggerLevel.None, method) {
this._onErrorHandler = [], this._level = level, this._method = method;
}
addErrorHandler(handler) {
this._onErrorHandler.find(h => h === handler) || this._onErrorHandler.push(handler);
}
removeErrorHandler(handler) {
const index = this._onErrorHandler.findIndex(h => h === handler);
index < 0 || this._onErrorHandler.splice(index, 1);
}
callErrorHandler(...args) {
this._onErrorHandler.forEach(h => h(...args));
}
canLogInfo() {
return this._level >= LoggerLevel.Info;
}
canLogDebug() {
return this._level >= LoggerLevel.Debug;
}
canLogError() {
return this._level >= LoggerLevel.Error;
}
canLogWarn() {
return this._level >= LoggerLevel.Warn;
}
level(levelValue) {
return arguments.length ? (this._level = +levelValue, this) : this._level;
}
error(...args) {
var _a;
return this._level >= LoggerLevel.Error && (this._onErrorHandler.length ? this.callErrorHandler(...args) : log$2(null !== (_a = this._method) && void 0 !== _a ? _a : "error", "ERROR", args)), this;
}
warn(...args) {
return this._level >= LoggerLevel.Warn && log$2(this._method || "warn", "WARN", args), this;
}
info(...args) {
return this._level >= LoggerLevel.Info && log$2(this._method || "log", "INFO", args), this;
}
debug(...args) {
return this._level >= LoggerLevel.Debug && log$2(this._method || "log", "DEBUG", args), this;
}
}
Logger._instance = null;
function bisect(a, x, lo = 0, hi) {
for (isNil$1(hi) && (hi = a.length); lo < hi;) {
const mid = lo + hi >>> 1;
ascending$1(a[mid], x) > 0 ? hi = mid : lo = mid + 1;
}
return lo;
}
function findZeroOfFunction(f, a, b, parameters) {
var _a, _b;
const maxIterations = null !== (_a = null == parameters ? void 0 : parameters.maxIterations) && void 0 !== _a ? _a : 100,
tolerance = null !== (_b = null == parameters ? void 0 : parameters.tolerance) && void 0 !== _b ? _b : 1e-10,
fA = f(a),
fB = f(b);
let delta = b - a;
if (fA * fB > 0) {
return Logger.getInstance().error("Initial bisect points must have opposite signs"), NaN;
}
if (0 === fA) return a;
if (0 === fB) return b;
for (let i = 0; i < maxIterations; ++i) {
delta /= 2;
const mid = a + delta,
fMid = f(mid);
if (fMid * fA >= 0 && (a = mid), Math.abs(delta) < tolerance || 0 === fMid) return mid;
}
return a + delta;
}
const binaryFuzzySearch = (arr, compareFn) => binaryFuzzySearchInNumberRange(0, arr.length, value => compareFn(arr[value]));
const binaryFuzzySearchInNumberRange = (x1, x2, compareFn) => {
let left = x1,
right = x2;
for (; left < right;) {
const mid = Math.floor((left + right) / 2);
compareFn(mid) >= 0 ? right = mid : left = mid + 1;
}
return left;
};
const median$1 = (values, isSorted) => {
let sorted = values;
return !0 !== isSorted && (sorted = values.sort(ascending$1)), quantileSorted(sorted, .5);
};
const DEFAULT_ABSOLUTE_TOLERATE = 1e-10,
DEFAULT_RELATIVE_TOLERATE = 1e-10;
function isNumberClose(a, b, relTol = DEFAULT_RELATIVE_TOLERATE, absTol = DEFAULT_ABSOLUTE_TOLERATE) {
const abs = absTol,
rel = relTol * Math.max(a, b);
return Math.abs(a - b) <= Math.max(abs, rel);
}
function isGreater(a, b, relTol, absTol) {
return a > b && !isNumberClose(a, b, relTol, absTol);
}
function isLess(a, b, relTol, absTol) {
return a < b && !isNumberClose(a, b, relTol, absTol);
}
const memoize = func => {
let lastArgs = null,
lastResult = null;
return (...args) => (lastArgs && args.every((val, i) => val === lastArgs[i]) || (lastArgs = args, lastResult = func(...args)), lastResult);
};
const clamp = function (input, min, max) {
return input < min ? min : input > max ? max : input;
};
var clamp$1 = clamp;
const clampRange = (range, min, max) => {
let [lowValue, highValue] = range;
highValue < lowValue && (lowValue = range[1], highValue = range[0]);
const span = highValue - lowValue;
return span >= max - min ? [min, max] : (lowValue = Math.min(Math.max(lowValue, min), max - span), [lowValue, lowValue + span]);
};
var clampRange$1 = clampRange;
function clamper(a, b) {
let t;
return a > b && (t = a, a = b, b = t), x => Math.max(a, Math.min(b, x));
}
let hasRaf = !1;
try {
hasRaf = "function" == typeof requestAnimationFrame && "function" == typeof cancelAnimationFrame;
} catch (err) {
hasRaf = !1;
}
function debounce(func, wait, options) {
let lastArgs,
lastThis,
maxWait,
result,
timerId,
lastCallTime,
lastInvokeTime = 0,
leading = !1,
maxing = !1,
trailing = !0;
const useRAF = !wait && 0 !== wait && hasRaf;
if ("function" != typeof func) throw new TypeError("Expected a function");
function invokeFunc(time) {
const args = lastArgs,
thisArg = lastThis;
return lastArgs = lastThis = void 0, lastInvokeTime = time, result = func.apply(thisArg, args), result;
}
function startTimer(pendingFunc, wait) {
return useRAF ? (cancelAnimationFrame(timerId), requestAnimationFrame(pendingFunc)) : setTimeout(pendingFunc, wait);
}
function shouldInvoke(time) {
const timeSinceLastCall = time - lastCallTime;
return void 0 === lastCallTime || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && time - lastInvokeTime >= maxWait;
}
function timerExpired() {
const time = Date.now();
if (shouldInvoke(time)) return trailingEdge(time);
timerId = startTimer(timerExpired, function (time) {
const timeSinceLastInvoke = time - lastInvokeTime,
timeWaiting = wait - (time - lastCallTime);
return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
}(time));
}
function trailingEdge(time) {
return timerId = void 0, trailing && lastArgs ? invokeFunc(time) : (lastArgs = lastThis = void 0, result);
}
function debounced(...args) {
const time = Date.now(),
isInvoking = shouldInvoke(time);
if (lastArgs = args, lastThis = this, lastCallTime = time, isInvoking) {
if (void 0 === timerId) return function (time) {
return lastInvokeTime = time, timerId = startTimer(timerExpired, wait), leading ? invokeFunc(time) : result;
}(lastCallTime);
if (maxing) return timerId = startTimer(timerExpired, wait), invokeFunc(lastCallTime);
}
return void 0 === timerId && (timerId = startTimer(timerExpired, wait)), result;
}
return wait = +wait || 0, isObject$2(options) && (leading = !!options.leading, maxing = "maxWait" in options, maxing && (maxWait = Math.max(isValidNumber$1(options.maxWait) ? options.maxWait : 0, wait)), trailing = "trailing" in options ? !!options.trailing : trailing), debounced.cancel = function () {
void 0 !== timerId && function (id) {
if (useRAF) return cancelAnimationFrame(id);
clearTimeout(id);
}(timerId), lastInvokeTime = 0, lastArgs = lastCallTime = lastThis = timerId = void 0;
}, debounced.flush = function () {
return void 0 === timerId ? result : trailingEdge(Date.now());
}, debounced.pending = function () {
return void 0 !== timerId;
}, debounced;
}
hasRaf = !1;
function throttle(func, wait, options) {
let leading = !0,
trailing = !0;
if ("function" != typeof func) throw new TypeError("Expected a function");
return isObject$2(options) && (leading = "leading" in options ? !!options.leading : leading, trailing = "trailing" in options ? !!options.trailing : trailing), debounce(func, wait, {
leading: leading,
trailing: trailing,
maxWait: wait
});
}
function interpolateNumber$1(a, b) {
return t => a * (1 - t) + b * t;
}
function interpolateNumberRound(a, b) {
return function (t) {
return Math.round(a * (1 - t) + b * t);
};
}
function interpolateDate(a, b) {
const aVal = a.valueOf(),
bVal = b.valueOf(),
d = new Date();
return t => (d.setTime(aVal * (1 - t) + bVal * t), d);
}
function toValidNumber$1(v) {
if (isValidNumber$1(v)) return v;
const value = +v;
return isValidNumber$1(value) ? value : 0;
}
function seedRandom(seed) {
return parseFloat("0." + Math.sin(seed).toString().substring(6));
}
const a = 1664525,
c$1 = 1013904223,
m$2 = 4294967296;
function randomLCG(initS = 1) {
let s = initS;
return () => (s = (a * s + c$1) % m$2) / m$2;
}
const fakeRandom = () => {
let i = -1;
const arr = [0, .1, .2, .3, .4, .5, .6, .7, .8, .9];
return () => (i = (i + 1) % arr.length, arr[i]);
};
const getter = path => obj => get$1(obj, path);
const fieldSingle = (fieldStr, opt = {}) => {
if (isFunction$1(fieldStr)) return fieldStr;
const path = [fieldStr];
return (opt && opt.get || getter)(path);
};
const field$2 = (fieldStr, opt = {}) => {
if (isArray$1(fieldStr)) {
const funcs = fieldStr.map(entry => fieldSingle(entry, opt));
return datum => funcs.map(func => func(datum));
}
return fieldSingle(fieldStr, opt);
};
const simpleField = option => option ? "string" == typeof option || "number" == typeof option ? () => option : isFunction$1(option) ? option : datum => datum[option.field] : null;
const toPercent = (percent, total) => isNil$1(percent) ? total : isString$1(percent) ? total * parseFloat(percent) / 100 : percent;
const zero = _ => 0;
const extent$2 = (array, func) => {
const valueGetter = isFunction$1(func) ? func : val => val;
let min, max;
if (array && array.length) {
const n = array.length;
for (let i = 0; i < n; i += 1) {
let value = valueGetter(array[i]);
isNil$1(value) || !isNumber$1(value = +value) || Number.isNaN(value) || (isNil$1(min) ? (min = value, max = value) : (min = Math.min(min, value), max = Math.max(max, value)));
}
return [min, max];
}
return [min, max];
};
function ordinaryLeastSquares(uX, uY, uXY, uX2) {
const delta = uX2 - uX * uX,
slope = Math.abs(delta) < 1e-24 ? 0 : (uXY - uX * uY) / delta;
return [uY - slope * uX, slope];
}
function visitPoints(data, x, y, callback) {
let u,
v,
i = -1;
data.forEach(d => {
u = x(d), v = y(d), !isNil$1(u) && (u = +u) >= u && !isNil$1(v) && (v = +v) >= v && callback(u, v, ++i);
});
}
function rSquared(data, x, y, uY, predict) {
let SSE = 0,
SST = 0;
return visitPoints(data, x, y, (dx, dy) => {
const sse = dy - predict(dx),
sst = dy - uY;
SSE += sse * sse, SST += sst * sst;
}), 1 - SSE / SST;
}
function regressionLinear(data, x = datum => datum.x, y = datum => datum.y) {
let X = 0,
Y = 0,
XY = 0,
X2 = 0,
n = 0;
visitPoints(data, x, y, (dx, dy) => {
++n, X += (dx - X) / n, Y += (dy - Y) / n, XY += (dx * dy - XY) / n, X2 += (dx * dx - X2) / n;
});
const coef = ordinaryLeastSquares(X, Y, XY, X2),
predict = x => coef[0] + coef[1] * x;
return {
coef: coef,
predict: predict,
rSquared: rSquared(data, x, y, Y, predict)
};
}
const epsilon$1 = 1e-12;
const pi$1 = Math.PI;
const halfPi$2 = pi$1 / 2;
const tau$1 = 2 * pi$1;
const pi2 = 2 * Math.PI;
const abs$1 = Math.abs;
const atan2$1 = Math.atan2;
const cos$1 = Math.cos;
const max$1 = Math.max;
const min$1 = Math.min;
const sin$1 = Math.sin;
const sqrt$3 = Math.sqrt;
const pow$1 = Math.pow;
function acos$1(x) {
return x > 1 ? 0 : x < -1 ? pi$1 : Math.acos(x);
}
function asin$1(x) {
return x >= 1 ? halfPi$2 : x <= -1 ? -halfPi$2 : Math.asin(x);
}
function pointAt(x1, y1, x2, y2, t) {
let x = x2,
y = y2;
return "number" == typeof x1 && "number" == typeof x2 && (x = (1 - t) * x1 + t * x2), "number" == typeof y1 && "number" == typeof y2 && (y = (1 - t) * y1 + t * y2), {
x: x,
y: y
};
}
function crossProduct$1(dir1, dir2) {
return dir1[0] * dir2[1] - dir1[1] * dir2[0];
}
function dotProduct(a, b) {
let ret = 0;
for (let i = 0; i < a.length; ++i) ret += a[i] * b[i];
return ret;
}
function fuzzyEqualVec(a, b) {
return abs$1(a[0] - b[0]) + abs$1(a[1] - b[1]) < 1e-12;
}
function fixPrecision$1(num, precision = 10) {
return Math.round(num * precision) / precision;
}
function getDecimalPlaces(n) {
const dStr = n.toString().split(/[eE]/),
s = (dStr[0].split(".")[1] || "").length - (+dStr[1] || 0);
return s > 0 ? s : 0;
}
function precisionAdd(a, b) {
return fixPrecision$1(a + b, 10 ** Math.max(getDecimalPlaces(a), getDecimalPlaces(b)));
}
function precisionSub(a, b) {
return fixPrecision$1(a - b, 10 ** Math.max(getDecimalPlaces(a), getDecimalPlaces(b)));
}
class Point {
constructor(x = 0, y = 0, x1, y1) {
this.x = 0, this.y = 0, this.x = x, this.y = y, this.x1 = x1, this.y1 = y1;
}
clone() {
return new Point(this.x, this.y);
}
copyFrom(p) {
return this.x = p.x, this.y = p.y, this.x1 = p.x1, this.y1 = p.y1, this.defined = p.defined, this.context = p.context, this;
}
set(x, y) {
return this.x = x, this.y = y, this;
}
add(point) {
return isNumber$1(point) ? (this.x += point, void (this.y += point)) : (this.x += point.x, this.y += point.y, this);
}
sub(point) {
return isNumber$1(point) ? (this.x -= point, void (this.y -= point)) : (this.x -= point.x, this.y -= point.y, this);
}
multi(point) {
throw new Error("暂不支持");
}
div(point) {
throw new Error("暂不支持");
}
}
class PointService {
static distancePP(p1, p2) {
return sqrt$3(pow$1(p1.x - p2.x, 2) + pow$1(p1.y - p2.y, 2));
}
static distanceNN(x, y, x1, y1) {
return sqrt$3(pow$1(x - x1, 2) + pow$1(y - y1, 2));
}
static distancePN(point, x, y) {
return sqrt$3(pow$1(x - point.x, 2) + pow$1(y - point.y, 2));
}
static pointAtPP(p1, p2, t) {
return new Point((p2.x - p1.x) * t + p1.x, (p2.y - p1.y) * t + p1.y);
}
}
function degreeToRadian(degree) {
return degree * (Math.PI / 180);
}
function radianToDegree(radian) {
return 180 * radian / Math.PI;
}
const clampRadian = (angle = 0) => {
if (angle < 0) for (; angle < -tau$1;) angle += tau$1;else if (angle > 0) for (; angle > tau$1;) angle -= tau$1;
return angle;
};
const clampAngleByRadian = clampRadian;
function polarToCartesian(center, radius, angleInRadian) {
return radius ? {
x: center.x + radius * Math.cos(angleInRadian),
y: center.y + radius * Math.sin(angleInRadian)
} : {
x: center.x,
y: center.y
};
}
function cartesianToPolar(point, center = {
x: 0,
y: 0
}, startAngle = 0, endAngle = 2 * Math.PI) {
const {
x: x,
y: y
} = point,
{
x: centerX,
y: centerY
} = center;
let dx = x - centerX,
dy = y - centerY;
const radius = Math.sqrt(dx * dx + dy * dy);
if (0 === radius) return {
radius: 0,
angle: 0
};
dx /= radius, dy /= radius;
let radian = Math.atan2(dy, dx);
if (radian < startAngle) for (; radian <= startAngle;) radian += 2 * Math.PI;
if (radian > endAngle) for (; radian >= endAngle;) radian -= 2 * Math.PI;
return {
radius: radius,
angle: radian
};
}
function getAngleByPoint(center, point) {
return Math.atan2(point.y - center.y, point.x - center.x);
}
function normalizeAngle(angle) {
for (; angle < 0;) angle += 2 * Math.PI;
for (; angle >= 2 * Math.PI;) angle -= 2 * Math.PI;
return angle;
}
function findBoundaryAngles(startAngle, endAngle) {
const deltaAngle = Math.abs(endAngle - startAngle);
if (deltaAngle >= 2 * Math.PI || 2 * Math.PI - deltaAngle < 1e-6) return [0, Math.PI / 2, Math.PI, 1.5 * Math.PI];
const normalMin = normalizeAngle(Math.min(startAngle, endAngle)),
normalMax = normalMin + deltaAngle,
steps = [normalMin, normalMax];
let directionAngle = Math.floor(normalMin / Math.PI) * Math.PI / 2;
for (; directionAngle < normalMax;) directionAngle > normalMin && steps.push(directionAngle), directionAngle += Math.PI / 2;
return steps;
}
function calculateMaxRadius(rect, center, startAngle, endAngle) {
const {
x: x,
y: y
} = center,
steps = findBoundaryAngles(startAngle, endAngle),
{
width: width,
height: height
} = rect,
radiusList = [];
return steps.forEach(step => {
const sin = Math.sin(step),
cos = Math.cos(step);
1 === sin ? radiusList.push(height - y) : -1 === sin ? radiusList.push(y) : 1 === cos ? radiusList.push(width - x) : -1 === cos ? radiusList.push(x) : (sin > 0 ? radiusList.push(Math.abs((height - y) / sin)) : radiusList.push(Math.abs(y / sin)), cos > 0 ? radiusList.push(Math.abs((width - x) / cos)) : radiusList.push(Math.abs(x / cos)));
}), Math.min.apply(null, radiusList);
}
function computeQuadrant(angle) {
return (angle = normalizeAngle(angle)) > 0 && angle <= Math.PI / 2 ? 2 : angle > Math.PI / 2 && angle <= Math.PI ? 3 : angle > Math.PI && angle <= 3 * Math.PI / 2 ? 4 : 1;
}
function sub(out, v1, v2) {
out[0] = v1[0] - v2[0], out[1] = v1[1] - v2[1];
}
function isIntersect$1(left1, right1, left2, right2) {
let min1 = left1[0],
max1 = right1[0],
min2 = left2[0],
max2 = right2[0];
return max1 < min1 && ([min1, max1] = [max1, min1]), max2 < min2 && ([max2, min2] = [min2, max2]), !(max1 < min2 || max2 < min1) && (min1 = left1[1], max1 = right1[1], min2 = left2[1], max2 = right2[1], max1 < min1 && ([min1, max1] = [max1, min1]), max2 < min2 && ([max2, min2] = [min2, max2]), !(max1 < min2 || max2 < min1));
}
function getIntersectPoint(left1, right1, left2, right2) {
if (!isIntersect$1(left1, right1, left2, right2)) return !1;
const dir1 = [0, 0],
dir2 = [0, 0],
tempVec = [0, 0];
if (sub(dir1, right1, left1), sub(dir2, right2, left2), fuzzyEqualVec(dir1, dir2)) return !0;
sub(tempVec, left2, left1);
const t = crossProduct$1(tempVec, dir2) / crossProduct$1(dir1, dir2);
return t >= 0 && t <= 1 && [left1[0] + dir1[0] * t, left1[1] + dir1[1] * t];
}
function getRectIntersect(bbox1, bbox2, format) {
if (null === bbox1) return bbox2;
if (null === bbox2) return bbox1;
const {
x11: x11,
x12: x12,
y11: y11,
y12: y12,
x21: x21,
x22: x22,
y21: y21,
y22: y22
} = formatTwoBBox(bbox1, bbox2, format);
return x11 >= x22 || x12 <= x21 || y11 >= y22 || y12 <= y21 ? {
x1: 0,
y