UNPKG

@visactor/vdataset

Version:

data processing tool

1,416 lines (1,361 loc) 430 kB
(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.VDataset = {})); })(this, (function (exports) { 'use strict'; var thirdPi = Math.PI / 3, angles = [0, thirdPi, 2 * thirdPi, 3 * thirdPi, 4 * thirdPi, 5 * thirdPi]; function pointX(d) { return d[0]; } function pointY(d) { return d[1]; } function hexbin () { var x0 = 0, y0 = 0, x1 = 1, y1 = 1, x = pointX, y = pointY, r, dx, dy; function hexbin(points) { var binsById = {}, bins = [], i, n = points.length; for (i = 0; i < n; ++i) { if (isNaN(px = +x.call(null, point = points[i], i, points)) || isNaN(py = +y.call(null, point, i, points))) continue; var point, px, py, pj = Math.round(py = py / dy), pi = Math.round(px = px / dx - (pj & 1) / 2), py1 = py - pj; if (Math.abs(py1) * 3 > 1) { var px1 = px - pi, pi2 = pi + (px < pi ? -1 : 1) / 2, pj2 = pj + (py < pj ? -1 : 1), px2 = px - pi2, py2 = py - pj2; if (px1 * px1 + py1 * py1 > px2 * px2 + py2 * py2) pi = pi2 + (pj & 1 ? 1 : -1) / 2, pj = pj2; } var id = pi + "-" + pj, bin = binsById[id]; if (bin) bin.push(point);else { bins.push(bin = binsById[id] = [point]); bin.x = (pi + (pj & 1) / 2) * dx; bin.y = pj * dy; } } return bins; } function hexagon(radius) { var x0 = 0, y0 = 0; return angles.map(function (angle) { var x1 = Math.sin(angle) * radius, y1 = -Math.cos(angle) * radius, dx = x1 - x0, dy = y1 - y0; x0 = x1, y0 = y1; return [dx, dy]; }); } hexbin.hexagon = function (radius) { return "m" + hexagon(radius == null ? r : +radius).join("l") + "z"; }; hexbin.centers = function () { var centers = [], j = Math.round(y0 / dy), i = Math.round(x0 / dx); for (var y = j * dy; y < y1 + r; y += dy, ++j) { for (var x = i * dx + (j & 1) * dx / 2; x < x1 + dx / 2; x += dx) { centers.push([x, y]); } } return centers; }; hexbin.mesh = function () { var fragment = hexagon(r).slice(0, 4).join("l"); return hexbin.centers().map(function (p) { return "M" + p + "m" + fragment; }).join(""); }; hexbin.x = function (_) { return arguments.length ? (x = _, hexbin) : x; }; hexbin.y = function (_) { return arguments.length ? (y = _, hexbin) : y; }; hexbin.radius = function (_) { return arguments.length ? (r = +_, dx = r * 2 * Math.sin(thirdPi), dy = r * 1.5, hexbin) : r; }; hexbin.size = function (_) { return arguments.length ? (x0 = y0 = 0, x1 = +_[0], y1 = +_[1], hexbin) : [x1 - x0, y1 - y0]; }; hexbin.extent = function (_) { return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], hexbin) : [[x0, y0], [x1, y1]]; }; return hexbin.radius(1); } function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } function getAugmentedNamespace(n) { if (n.__esModule) return n; var f = n.default; if (typeof f == "function") { var a = function a () { if (this instanceof a) { var args = [null]; args.push.apply(args, arguments); var Ctor = Function.bind.apply(f, args); return new Ctor(); } return f.apply(this, arguments); }; a.prototype = f.prototype; } else a = {}; Object.defineProperty(a, '__esModule', {value: true}); Object.keys(n).forEach(function (k) { var d = Object.getOwnPropertyDescriptor(n, k); Object.defineProperty(a, k, d.get ? d : { enumerable: true, get: function () { return n[k]; } }); }); return a; } 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 = function (value) { let fuzzy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1; return 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 isString = function (value) { let fuzzy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !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 = function (value) { let fuzzy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1; const type = typeof value; return fuzzy ? "number" === type : "number" === type || isType$1(value, "Number"); }; var isNumber$1 = isNumber; const isValidNumber = value => isNumber$1(value) && Number.isFinite(value); var isValidNumber$1 = isValidNumber; 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) { let shallowArray = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1; let skipTargetArray = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : !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) { let shallowArray = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : !1; let skipTargetArray = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : !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$2(target) { let sourceIndex = -1; const length = arguments.length <= 1 ? 0 : arguments.length - 1; for (; ++sourceIndex < length;) { baseMerge(target, sourceIndex + 1 < 1 || arguments.length <= sourceIndex + 1 ? undefined : arguments[sourceIndex + 1], !0); } return target; } function array(arr) { return isValid$1(arr) ? isArray$1(arr) ? arr : [arr] : []; } function uniqArray(arr) { return arr && isArray$1(arr) ? Array.from(new Set(array(arr))) : arr; } function flattenArray(arr) { if (!isArray$1(arr)) return [arr]; const result = []; for (const value of arr) result.push(...flattenArray(value)); return result; } const hasConsole = "undefined" != typeof console; function log$1(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() { let level = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : LoggerLevel.None; let method = arguments.length > 1 ? arguments[1] : undefined; 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() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } 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() { var _a; for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } return this._level >= LoggerLevel.Error && (this._onErrorHandler.length ? this.callErrorHandler(...args) : log$1(null !== (_a = this._method) && void 0 !== _a ? _a : "error", "ERROR", args)), this; } warn() { for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { args[_key3] = arguments[_key3]; } return this._level >= LoggerLevel.Warn && log$1(this._method || "warn", "WARN", args), this; } info() { for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { args[_key4] = arguments[_key4]; } return this._level >= LoggerLevel.Info && log$1(this._method || "log", "INFO", args), this; } debug() { for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { args[_key5] = arguments[_key5]; } return this._level >= LoggerLevel.Debug && log$1(this._method || "log", "DEBUG", args), this; } } Logger._instance = null; const clamp = function (input, min, max) { return input < min ? min : input > max ? max : input; }; var clamp$1 = clamp; function radianToDegree(radian) { return 180 * radian / Math.PI; } class Matrix { constructor() { let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; let c = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; let d = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1; let e = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; let f = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0; this.a = a, this.b = b, this.c = c, this.d = d, this.e = e, this.f = f; } equalToMatrix(m2) { return !(this.e !== m2.e || this.f !== m2.f || this.a !== m2.a || this.d !== m2.d || this.b !== m2.b || this.c !== m2.c); } equalTo(a, b, c, d, e, f) { return !(this.e !== e || this.f !== f || this.a !== a || this.d !== d || this.b !== b || this.c !== c); } setValue(a, b, c, d, e, f) { return this.a = a, this.b = b, this.c = c, this.d = d, this.e = e, this.f = f, this; } reset() { return this.a = 1, this.b = 0, this.c = 0, this.d = 1, this.e = 0, this.f = 0, this; } getInverse() { const a = this.a, b = this.b, c = this.c, d = this.d, e = this.e, f = this.f, m = new Matrix(), dt = a * d - b * c; return m.a = d / dt, m.b = -b / dt, m.c = -c / dt, m.d = a / dt, m.e = (c * f - d * e) / dt, m.f = -(a * f - b * e) / dt, m; } rotate(rad) { const c = Math.cos(rad), s = Math.sin(rad), m11 = this.a * c + this.c * s, m12 = this.b * c + this.d * s, m21 = this.a * -s + this.c * c, m22 = this.b * -s + this.d * c; return this.a = m11, this.b = m12, this.c = m21, this.d = m22, this; } rotateByCenter(rad, cx, cy) { const cos = Math.cos(rad), sin = Math.sin(rad), rotateM13 = (1 - cos) * cx + sin * cy, rotateM23 = (1 - cos) * cy - sin * cx, m11 = cos * this.a - sin * this.b, m21 = sin * this.a + cos * this.b, m12 = cos * this.c - sin * this.d, m22 = sin * this.c + cos * this.d, m13 = cos * this.e - sin * this.f + rotateM13, m23 = sin * this.e + cos * this.f + rotateM23; return this.a = m11, this.b = m21, this.c = m12, this.d = m22, this.e = m13, this.f = m23, this; } scale(sx, sy) { return this.a *= sx, this.b *= sx, this.c *= sy, this.d *= sy, this; } setScale(sx, sy) { return this.b = this.b / this.a * sx, this.c = this.c / this.d * sy, this.a = sx, this.d = sy, this; } transform(a, b, c, d, e, f) { return this.multiply(a, b, c, d, e, f), this; } translate(x, y) { return this.e += this.a * x + this.c * y, this.f += this.b * x + this.d * y, this; } transpose() { const { a: a, b: b, c: c, d: d, e: e, f: f } = this; return this.a = b, this.b = a, this.c = d, this.d = c, this.e = f, this.f = e, this; } multiply(a2, b2, c2, d2, e2, f2) { const a1 = this.a, b1 = this.b, c1 = this.c, d1 = this.d, m11 = a1 * a2 + c1 * b2, m12 = b1 * a2 + d1 * b2, m21 = a1 * c2 + c1 * d2, m22 = b1 * c2 + d1 * d2, dx = a1 * e2 + c1 * f2 + this.e, dy = b1 * e2 + d1 * f2 + this.f; return this.a = m11, this.b = m12, this.c = m21, this.d = m22, this.e = dx, this.f = dy, this; } interpolate(m2, t) { const m = new Matrix(); return m.a = this.a + (m2.a - this.a) * t, m.b = this.b + (m2.b - this.b) * t, m.c = this.c + (m2.c - this.c) * t, m.d = this.d + (m2.d - this.d) * t, m.e = this.e + (m2.e - this.e) * t, m.f = this.f + (m2.f - this.f) * t, m; } transformPoint(source, target) { const { a: a, b: b, c: c, d: d, e: e, f: f } = this, dt = a * d - b * c, nextA = d / dt, nextB = -b / dt, nextC = -c / dt, nextD = a / dt, nextE = (c * f - d * e) / dt, nextF = -(a * f - b * e) / dt, { x: x, y: y } = source; target.x = x * nextA + y * nextC + nextE, target.y = x * nextB + y * nextD + nextF; } onlyTranslate() { let scale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; return this.a === scale && 0 === this.b && 0 === this.c && this.d === scale; } clone() { return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f); } toTransformAttrs() { const a = this.a, b = this.b, c = this.c, d = this.d, delta = a * d - b * c, result = { x: this.e, y: this.f, rotateDeg: 0, scaleX: 0, scaleY: 0, skewX: 0, skewY: 0 }; if (0 !== a || 0 !== b) { const r = Math.sqrt(a * a + b * b); result.rotateDeg = b > 0 ? Math.acos(a / r) : -Math.acos(a / r), result.scaleX = r, result.scaleY = delta / r, result.skewX = (a * c + b * d) / delta, result.skewY = 0; } else if (0 !== c || 0 !== d) { const s = Math.sqrt(c * c + d * d); result.rotateDeg = Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s)), result.scaleX = delta / s, result.scaleY = s, result.skewX = 0, result.skewY = (a * c + b * d) / delta; } return result.rotateDeg = radianToDegree(result.rotateDeg), result; } } function hslToRgb(h, s, l) { s /= 100, l /= 100; const c = (1 - Math.abs(2 * l - 1)) * s, x = c * (1 - Math.abs(h / 60 % 2 - 1)), m = l - c / 2; let r = 0, g = 0, b = 0; return 0 <= h && h < 60 ? (r = c, g = x, b = 0) : 60 <= h && h < 120 ? (r = x, g = c, b = 0) : 120 <= h && h < 180 ? (r = 0, g = c, b = x) : 180 <= h && h < 240 ? (r = 0, g = x, b = c) : 240 <= h && h < 300 ? (r = x, g = 0, b = c) : 300 <= h && h < 360 && (r = c, g = 0, b = x), r = Math.round(255 * (r + m)), g = Math.round(255 * (g + m)), b = Math.round(255 * (b + m)), { r: r, g: g, b: b }; } function rgbToHsl(r, g, b) { r /= 255, g /= 255, b /= 255; const cMin = Math.min(r, g, b), cMax = Math.max(r, g, b), delta = cMax - cMin; let h = 0, s = 0, l = 0; return h = 0 === delta ? 0 : cMax === r ? (g - b) / delta % 6 : cMax === g ? (b - r) / delta + 2 : (r - g) / delta + 4, h = Math.round(60 * h), h < 0 && (h += 360), l = (cMax + cMin) / 2, s = 0 === delta ? 0 : delta / (1 - Math.abs(2 * l - 1)), s = +(100 * s).toFixed(1), l = +(100 * l).toFixed(1), { h: h, s: s, l: l }; } const REG_HEX = /^#([0-9a-f]{3,8})$/, DEFAULT_COLORS_OPACITY = { transparent: 4294967040 }; const DEFAULT_COLORS = { aliceblue: 15792383, antiquewhite: 16444375, aqua: 65535, aquamarine: 8388564, azure: 15794175, beige: 16119260, bisque: 16770244, black: 0, blanchedalmond: 16772045, blue: 255, blueviolet: 9055202, brown: 10824234, burlywood: 14596231, cadetblue: 6266528, chartreuse: 8388352, chocolate: 13789470, coral: 16744272, cornflowerblue: 6591981, cornsilk: 16775388, crimson: 14423100, cyan: 65535, darkblue: 139, darkcyan: 35723, darkgoldenrod: 12092939, darkgray: 11119017, darkgreen: 25600, darkgrey: 11119017, darkkhaki: 12433259, darkmagenta: 9109643, darkolivegreen: 5597999, darkorange: 16747520, darkorchid: 10040012, darkred: 9109504, darksalmon: 15308410, darkseagreen: 9419919, darkslateblue: 4734347, darkslategray: 3100495, darkslategrey: 3100495, darkturquoise: 52945, darkviolet: 9699539, deeppink: 16716947, deepskyblue: 49151, dimgray: 6908265, dimgrey: 6908265, dodgerblue: 2003199, firebrick: 11674146, floralwhite: 16775920, forestgreen: 2263842, fuchsia: 16711935, gainsboro: 14474460, ghostwhite: 16316671, gold: 16766720, goldenrod: 14329120, gray: 8421504, green: 32768, greenyellow: 11403055, grey: 8421504, honeydew: 15794160, hotpink: 16738740, indianred: 13458524, indigo: 4915330, ivory: 16777200, khaki: 15787660, lavender: 15132410, lavenderblush: 16773365, lawngreen: 8190976, lemonchiffon: 16775885, lightblue: 11393254, lightcoral: 15761536, lightcyan: 14745599, lightgoldenrodyellow: 16448210, lightgray: 13882323, lightgreen: 9498256, lightgrey: 13882323, lightpink: 16758465, lightsalmon: 16752762, lightseagreen: 2142890, lightskyblue: 8900346, lightslategray: 7833753, lightslategrey: 7833753, lightsteelblue: 11584734, lightyellow: 16777184, lime: 65280, limegreen: 3329330, linen: 16445670, magenta: 16711935, maroon: 8388608, mediumaquamarine: 6737322, mediumblue: 205, mediumorchid: 12211667, mediumpurple: 9662683, mediumseagreen: 3978097, mediumslateblue: 8087790, mediumspringgreen: 64154, mediumturquoise: 4772300, mediumvioletred: 13047173, midnightblue: 1644912, mintcream: 16121850, mistyrose: 16770273, moccasin: 16770229, navajowhite: 16768685, navy: 128, oldlace: 16643558, olive: 8421376, olivedrab: 7048739, orange: 16753920, orangered: 16729344, orchid: 14315734, palegoldenrod: 15657130, palegreen: 10025880, paleturquoise: 11529966, palevioletred: 14381203, papayawhip: 16773077, peachpuff: 16767673, peru: 13468991, pink: 16761035, plum: 14524637, powderblue: 11591910, purple: 8388736, rebeccapurple: 6697881, red: 16711680, rosybrown: 12357519, royalblue: 4286945, saddlebrown: 9127187, salmon: 16416882, sandybrown: 16032864, seagreen: 3050327, seashell: 16774638, sienna: 10506797, silver: 12632256, skyblue: 8900331, slateblue: 6970061, slategray: 7372944, slategrey: 7372944, snow: 16775930, springgreen: 65407, steelblue: 4620980, tan: 13808780, teal: 32896, thistle: 14204888, tomato: 16737095, turquoise: 4251856, violet: 15631086, wheat: 16113331, white: 16777215, whitesmoke: 16119285, yellow: 16776960, yellowgreen: 10145074 }; function hex(value) { return ((value = Math.max(0, Math.min(255, Math.round(value) || 0))) < 16 ? "0" : "") + value.toString(16); } function rgb(value) { return isNumber$1(value) ? new RGB(value >> 16, value >> 8 & 255, 255 & value, 1) : isArray$1(value) ? new RGB(value[0], value[1], value[2]) : new RGB(255, 255, 255); } function rgba(value) { return isNumber$1(value) ? new RGB(value >>> 24, value >>> 16 & 255, value >>> 8 & 255, 255 & value) : isArray$1(value) ? new RGB(value[0], value[1], value[2], value[3]) : new RGB(255, 255, 255, 1); } function SRGBToLinear(c) { return c < .04045 ? .0773993808 * c : Math.pow(.9478672986 * c + .0521327014, 2.4); } function LinearToSRGB(c) { return c < .0031308 ? 12.92 * c : 1.055 * Math.pow(c, .41666) - .055; } const setHex = (formatValue, forceHex) => { const isHex = REG_HEX.exec(formatValue); if (forceHex || isHex) { const hex = parseInt(isHex[1], 16), hexLength = isHex[1].length; return 3 === hexLength ? new RGB((hex >> 8 & 15) + ((hex >> 8 & 15) << 4), (hex >> 4 & 15) + ((hex >> 4 & 15) << 4), (15 & hex) + ((15 & hex) << 4), 1) : 6 === hexLength ? rgb(hex) : 8 === hexLength ? new RGB(hex >> 24 & 255, hex >> 16 & 255, hex >> 8 & 255, (255 & hex) / 255) : null; } }; class Color { static Brighter(source) { let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; return 1 === b ? source : new Color(source).brighter(b).toRGBA(); } static SetOpacity(source) { let o = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; return 1 === o ? source : new Color(source).setOpacity(o).toRGBA(); } static getColorBrightness(source) { let model = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "hsl"; const color = source instanceof Color ? source : new Color(source); switch (model) { case "hsv": default: return color.getHSVBrightness(); case "hsl": return color.getHSLBrightness(); case "lum": return color.getLuminance(); case "lum2": return color.getLuminance2(); case "lum3": return color.getLuminance3(); case "wcag": return color.getLuminanceWCAG(); } } static parseColorString(value) { if (isValid$1(DEFAULT_COLORS_OPACITY[value])) return rgba(DEFAULT_COLORS_OPACITY[value]); if (isValid$1(DEFAULT_COLORS[value])) return rgb(DEFAULT_COLORS[value]); const formatValue = `${value}`.trim().toLowerCase(), hexRes = setHex(formatValue); if (void 0 !== hexRes) return hexRes; if (/^(rgb|RGB|rgba|RGBA)/.test(formatValue)) { const aColor = formatValue.replace(/(?:\(|\)|rgba|RGBA|rgb|RGB)*/g, "").split(","); return new RGB(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10), parseFloat(aColor[3])); } if (/^(hsl|HSL|hsla|HSLA)/.test(formatValue)) { const aColor = formatValue.replace(/(?:\(|\)|hsla|HSLA|hsl|HSL)*/g, "").split(","), rgb = hslToRgb(parseInt(aColor[0], 10), parseInt(aColor[1], 10), parseInt(aColor[2], 10)); return new RGB(rgb.r, rgb.g, rgb.b, parseFloat(aColor[3])); } } constructor(value) { const color = Color.parseColorString(value); color ? this.color = color : (console.warn(`Warn: 传入${value}无法解析为Color`), this.color = new RGB(255, 255, 255)); } toRGBA() { return this.color.formatRgb(); } toString() { return this.color.formatRgb(); } toHex() { return this.color.formatHex(); } toHsl() { return this.color.formatHsl(); } brighter(k) { const { r: r, g: g, b: b } = this.color; return this.color.r = Math.max(0, Math.min(255, Math.floor(r * k))), this.color.g = Math.max(0, Math.min(255, Math.floor(g * k))), this.color.b = Math.max(0, Math.min(255, Math.floor(b * k))), this; } add(color) { const { r: r, g: g, b: b } = this.color; return this.color.r += Math.min(255, r + color.color.r), this.color.g += Math.min(255, g + color.color.g), this.color.b += Math.min(255, b + color.color.b), this; } sub(color) { return this.color.r = Math.max(0, this.color.r - color.color.r), this.color.g = Math.max(0, this.color.g - color.color.g), this.color.b = Math.max(0, this.color.b - color.color.b), this; } multiply(color) { const { r: r, g: g, b: b } = this.color; return this.color.r = Math.max(0, Math.min(255, Math.floor(r * color.color.r))), this.color.g = Math.max(0, Math.min(255, Math.floor(g * color.color.g))), this.color.b = Math.max(0, Math.min(255, Math.floor(b * color.color.b))), this; } getHSVBrightness() { return Math.max(this.color.r, this.color.g, this.color.b) / 255; } getHSLBrightness() { return .5 * (Math.max(this.color.r, this.color.g, this.color.b) / 255 + Math.min(this.color.r, this.color.g, this.color.b) / 255); } setHsl(h, s, l) { const opacity = this.color.opacity, hsl = rgbToHsl(this.color.r, this.color.g, this.color.b), rgb = hslToRgb(isNil$1(h) ? hsl.h : clamp$1(h, 0, 360), isNil$1(s) ? hsl.s : s >= 0 && s <= 1 ? 100 * s : s, isNil$1(l) ? hsl.l : l <= 1 && l >= 0 ? 100 * l : l); return this.color = new RGB(rgb.r, rgb.g, rgb.b, opacity), this; } setRGB(r, g, b) { return !isNil$1(r) && (this.color.r = r), !isNil$1(g) && (this.color.g = g), !isNil$1(b) && (this.color.b = b), this; } setHex(value) { const formatValue = `${value}`.trim().toLowerCase(), res = setHex(formatValue, !0); return null != res ? res : this; } setColorName(name) { const hex = DEFAULT_COLORS[name.toLowerCase()]; return void 0 !== hex ? this.setHex(hex) : console.warn("THREE.Color: Unknown color " + name), this; } setScalar(scalar) { return this.color.r = scalar, this.color.g = scalar, this.color.b = scalar, this; } setOpacity() { let o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; return this.color.opacity = o, this; } getLuminance() { return (.2126 * this.color.r + .7152 * this.color.g + .0722 * this.color.b) / 255; } getLuminance2() { return (.2627 * this.color.r + .678 * this.color.g + .0593 * this.color.b) / 255; } getLuminance3() { return (.299 * this.color.r + .587 * this.color.g + .114 * this.color.b) / 255; } getLuminanceWCAG() { const RsRGB = this.color.r / 255, GsRGB = this.color.g / 255, BsRGB = this.color.b / 255; let R, G, B; R = RsRGB <= .03928 ? RsRGB / 12.92 : Math.pow((RsRGB + .055) / 1.055, 2.4), G = GsRGB <= .03928 ? GsRGB / 12.92 : Math.pow((GsRGB + .055) / 1.055, 2.4), B = BsRGB <= .03928 ? BsRGB / 12.92 : Math.pow((BsRGB + .055) / 1.055, 2.4); return .2126 * R + .7152 * G + .0722 * B; } clone() { return new Color(this.color.toString()); } copyGammaToLinear(color) { let gammaFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2; return this.color.r = Math.pow(color.color.r, gammaFactor), this.color.g = Math.pow(color.color.g, gammaFactor), this.color.b = Math.pow(color.color.b, gammaFactor), this; } copyLinearToGamma(color) { let gammaFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2; const safeInverse = gammaFactor > 0 ? 1 / gammaFactor : 1; return this.color.r = Math.pow(color.color.r, safeInverse), this.color.g = Math.pow(color.color.g, safeInverse), this.color.b = Math.pow(color.color.b, safeInverse), this; } convertGammaToLinear(gammaFactor) { return this.copyGammaToLinear(this, gammaFactor), this; } convertLinearToGamma(gammaFactor) { return this.copyLinearToGamma(this, gammaFactor), this; } copySRGBToLinear(color) { return this.color.r = SRGBToLinear(color.color.r), this.color.g = SRGBToLinear(color.color.g), this.color.b = SRGBToLinear(color.color.b), this; } copyLinearToSRGB(color) { return this.color.r = LinearToSRGB(color.color.r), this.color.g = LinearToSRGB(color.color.g), this.color.b = LinearToSRGB(color.color.b), this; } convertSRGBToLinear() { return this.copySRGBToLinear(this), this; } convertLinearToSRGB() { return this.copyLinearToSRGB(this), this; } } class RGB { constructor(r, g, b, opacity) { this.r = isNaN(+r) ? 255 : Math.max(0, Math.min(255, +r)), this.g = isNaN(+g) ? 255 : Math.max(0, Math.min(255, +g)), this.b = isNaN(+b) ? 255 : Math.max(0, Math.min(255, +b)), isValid$1(opacity) ? this.opacity = isNaN(+opacity) ? 1 : Math.max(0, Math.min(1, +opacity)) : this.opacity = 1; } formatHex() { return `#${hex(this.r) + hex(this.g) + hex(this.b) + (1 === this.opacity ? "" : hex(255 * this.opacity))}`; } formatRgb() { const opacity = this.opacity; return `${1 === opacity ? "rgb(" : "rgba("}${this.r},${this.g},${this.b}${1 === opacity ? ")" : `,${opacity})`}`; } formatHsl() { const opacity = this.opacity, { h: h, s: s, l: l } = rgbToHsl(this.r, this.g, this.b); return `${1 === opacity ? "hsl(" : "hsla("}${h},${s}%,${l}%${1 === opacity ? ")" : `,${opacity})`}`; } toString() { return this.formatHex(); } } function toCamelCase(str) { return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()); } /** * @module helpers */ /** * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}. * * @name feature * @param {Geometry} geometry input geometry * @param {Object} [properties={}] an Object of key-value pairs to add as properties * @param {Object} [options={}] Optional Parameters * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature * @param {string|number} [options.id] Identifier associated with the Feature * @returns {Feature} a GeoJSON Feature * @example * var geometry = { * "type": "Point", * "coordinates": [110, 50] * }; * * var feature = turf.feature(geometry); * * //=feature */ function feature$2(geom, properties, options) { if (options === void 0) { options = {}; } var feat = { type: "Feature" }; if (options.id === 0 || options.id) { feat.id = options.id; } if (options.bbox) { feat.bbox = options.bbox; } feat.properties = properties || {}; feat.geometry = geom; return feat; } /** * Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}. * * @name featureCollection * @param {Feature[]} features input features * @param {Object} [options={}] Optional Parameters * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature * @param {string|number} [options.id] Identifier associated with the Feature * @returns {FeatureCollection} FeatureCollection of Features * @example * var locationA = turf.point([-75.343, 39.984], {name: 'Location A'}); * var locationB = turf.point([-75.833, 39.284], {name: 'Location B'}); * var locationC = turf.point([-75.534, 39.123], {name: 'Location C'}); * * var collection = turf.featureCollection([ * locationA, * locationB, * locationC * ]); * * //=collection */ function featureCollection(features, options) { if (options === void 0) { options = {}; } var fc = { type: "FeatureCollection" }; if (options.id) { fc.id = options.id; } if (options.bbox) { fc.bbox = options.bbox; } fc.features = features; return fc; } /** * isObject * * @param {*} input variable to validate * @returns {boolean} true/false * @example * turf.isObject({elevation: 10}) * //=true * turf.isObject('foo') * //=false */ function isObject(input) { return !!input && input.constructor === Object; } function colorLinearGenerator(startColor, endColor, data, field) { if (!startColor) { console.warn(`Warn: 颜色 range 未传入 startColor`); return; } if (!endColor) { const colorObj = ColorObjGenerator(startColor); data.forEach((item, index) => { item.colorObj = colorObj; }); return; } const { color: startColorObj, opacity: startOpacity } = ColorObjGenerator(startColor); const { r: startR, g: startG, b: startB } = startColorObj.color; const { color: endColorObj, opacity: endOpacity } = ColorObjGenerator(endColor); const { r: endR, g: endG, b: endB } = endColorObj.color; const dR = endR - startR; const dG = endG - startG; const dB = endB - startB; const dA = endOpacity - startOpacity; const total = data.length; if (total === 0) { return; } if (total === 1) { data[0].colorObj = { color: new Color(new RGB(startR, startG, startB).toString()), transparent: true, opacity: startOpacity }; return; } else if (total === 2) { data[0].colorObj = { color: new Color(new RGB(startR, startG, startB).toString()), transparent: true, opacity: startOpacity }; data[1].colorObj = { color: new Color(new RGB(endR, endG, endB).toString()), transparent: true, opacity: endOpacity }; return; } const dValue = data[total - 1][field] - data[0][field]; data.forEach((item, index) => { const step = dValue === 0 ? 0 : (item[field] - data[0][field]) / dValue; const color = `rgba(${Math.floor((startR + dR * step) * 255)},${Math.floor((startG + dG * step) * 255)},${Math.floor((startB + dB * step) * 255)}, ${startOpacity + dA * step})`; const colorObj = ColorObjGenerator(color); item.colorObj = colorObj; }); return; } function ColorObjGenerator(color) { const reg = /^(rgba|RGBA)/; let rgbaColor; if (reg.test(color)) { rgbaColor = rgbaStr2RgbaObj(color); } return { color: new Color(color), transparent: !!rgbaColor, opacity: rgbaColor ? rgbaColor.a : 1 }; } function rgbaStr2RgbaObj(color) { const colorArr = color.replace(/(?:\(|\)|rgba|RGBA)*/g, '').split(','); return { r: Number(colorArr[0]), g: Number(colorArr[1]), b: Number(colorArr[2]), a: Number(colorArr[3]) }; } const point_hex_corner = (centerPoints, size, z, angle = 0) => { const position = []; const colors = [];