UNPKG

bytev-charts

Version:

基于echarts和JavaScript及ES6封装的一个可以直接调用的图表组件库,内置主题设计,简单快捷,且支持用户自定义配置; npm 安装方式: npm install bytev-charts 若启动提示还需额外install插件,则运行 npm install @babel/runtime-corejs2 即可;

362 lines (312 loc) 14.7 kB
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && o[_Symbol$iterator] || o["@@iterator"]; if (!it) { if (_Array$isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.string.iterator.js"; import "core-js/modules/web.dom-collections.iterator.js"; import "core-js/modules/web.url.js"; import "core-js/modules/web.url-search-params.js"; import "core-js/modules/es.regexp.exec.js"; import "core-js/modules/es.string.split.js"; import "core-js/modules/es.array.join.js"; import "core-js/modules/es.array.slice.js"; import "core-js/modules/es.number.to-fixed.js"; import "core-js/modules/es.array-buffer.constructor.js"; import "core-js/modules/es.array-buffer.slice.js"; import "core-js/modules/es.typed-array.uint8-array.js"; import "core-js/modules/es.typed-array.copy-within.js"; import "core-js/modules/es.typed-array.every.js"; import "core-js/modules/es.typed-array.fill.js"; import "core-js/modules/es.typed-array.filter.js"; import "core-js/modules/es.typed-array.find.js"; import "core-js/modules/es.typed-array.find-index.js"; import "core-js/modules/es.typed-array.for-each.js"; import "core-js/modules/es.typed-array.includes.js"; import "core-js/modules/es.typed-array.index-of.js"; import "core-js/modules/es.typed-array.iterator.js"; import "core-js/modules/es.typed-array.join.js"; import "core-js/modules/es.typed-array.last-index-of.js"; import "core-js/modules/es.typed-array.map.js"; import "core-js/modules/es.typed-array.reduce.js"; import "core-js/modules/es.typed-array.reduce-right.js"; import "core-js/modules/es.typed-array.reverse.js"; import "core-js/modules/es.typed-array.set.js"; import "core-js/modules/es.typed-array.slice.js"; import "core-js/modules/es.typed-array.some.js"; import "core-js/modules/es.typed-array.sort.js"; import "core-js/modules/es.typed-array.subarray.js"; import "core-js/modules/es.typed-array.to-locale-string.js"; import "core-js/modules/es.typed-array.to-string.js"; import "core-js/modules/es.function.name.js"; import _Object$assign from "@babel/runtime-corejs2/core-js/object/assign"; import _Object$create from "@babel/runtime-corejs2/core-js/object/create"; import _Array$from from "@babel/runtime-corejs2/core-js/array/from"; import _Symbol from "@babel/runtime-corejs2/core-js/symbol"; import _Symbol$iterator from "@babel/runtime-corejs2/core-js/symbol/iterator"; import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array"; /** * Development repository: https://github.com/kaisalmen/WWOBJLoader */ import { FileLoader, Object3D, Loader } from "../../../build/three.module.js"; import { OBJLoader2Parser } from "./obj2/OBJLoader2Parser.js"; import { MeshReceiver } from "./obj2/shared/MeshReceiver.js"; import { MaterialHandler } from "./obj2/shared/MaterialHandler.js"; /** * Creates a new OBJLoader2. Use it to load OBJ data from files or to parse OBJ data from arraybuffer or text. * * @param {LoadingManager} [manager] The loadingManager for the loader to use. Default is {@link LoadingManager} * @constructor */ var OBJLoader2 = function OBJLoader2(manager) { Loader.call(this, manager); this.parser = new OBJLoader2Parser(); this.modelName = ''; this.instanceNo = 0; this.baseObject3d = new Object3D(); this.materialHandler = new MaterialHandler(); this.meshReceiver = new MeshReceiver(this.materialHandler); // as OBJLoader2 is no longer derived from OBJLoader2Parser, we need to override the default onAssetAvailable callback var scope = this; var defaultOnAssetAvailable = function defaultOnAssetAvailable(payload) { scope._onAssetAvailable(payload); }; this.parser.setCallbackOnAssetAvailable(defaultOnAssetAvailable); }; OBJLoader2.OBJLOADER2_VERSION = '3.2.0'; console.info('Using OBJLoader2 version: ' + OBJLoader2.OBJLOADER2_VERSION); OBJLoader2.prototype = _Object$assign(_Object$create(Loader.prototype), { constructor: OBJLoader2, /** * See {@link OBJLoader2Parser.setLogging} * @return {OBJLoader2} */ setLogging: function setLogging(enabled, debug) { this.parser.setLogging(enabled, debug); return this; }, /** * See {@link OBJLoader2Parser.setMaterialPerSmoothingGroup} * @return {OBJLoader2} */ setMaterialPerSmoothingGroup: function setMaterialPerSmoothingGroup(materialPerSmoothingGroup) { this.parser.setMaterialPerSmoothingGroup(materialPerSmoothingGroup); return this; }, /** * See {@link OBJLoader2Parser.setUseOAsMesh} * @return {OBJLoader2} */ setUseOAsMesh: function setUseOAsMesh(useOAsMesh) { this.parser.setUseOAsMesh(useOAsMesh); return this; }, /** * See {@link OBJLoader2Parser.setUseIndices} * @return {OBJLoader2} */ setUseIndices: function setUseIndices(useIndices) { this.parser.setUseIndices(useIndices); return this; }, /** * See {@link OBJLoader2Parser.setDisregardNormals} * @return {OBJLoader2} */ setDisregardNormals: function setDisregardNormals(disregardNormals) { this.parser.setDisregardNormals(disregardNormals); return this; }, /** * Set the name of the model. * * @param {string} modelName * @return {OBJLoader2} */ setModelName: function setModelName(modelName) { this.modelName = modelName ? modelName : this.modelName; return this; }, /** * Set the node where the loaded objects will be attached directly. * * @param {Object3D} baseObject3d Object already attached to scenegraph where new meshes will be attached to * @return {OBJLoader2} */ setBaseObject3d: function setBaseObject3d(baseObject3d) { this.baseObject3d = baseObject3d === undefined || baseObject3d === null ? this.baseObject3d : baseObject3d; return this; }, /** * Add materials as associated array. * * @param {Object} materials Object with named {@link Material} * @param overrideExisting boolean Override existing material * @return {OBJLoader2} */ addMaterials: function addMaterials(materials, overrideExisting) { this.materialHandler.addMaterials(materials, overrideExisting); return this; }, /** * See {@link OBJLoader2Parser.setCallbackOnAssetAvailable} * @return {OBJLoader2} */ setCallbackOnAssetAvailable: function setCallbackOnAssetAvailable(onAssetAvailable) { this.parser.setCallbackOnAssetAvailable(onAssetAvailable); return this; }, /** * See {@link OBJLoader2Parser.setCallbackOnProgress} * @return {OBJLoader2} */ setCallbackOnProgress: function setCallbackOnProgress(onProgress) { this.parser.setCallbackOnProgress(onProgress); return this; }, /** * See {@link OBJLoader2Parser.setCallbackOnError} * @return {OBJLoader2} */ setCallbackOnError: function setCallbackOnError(onError) { this.parser.setCallbackOnError(onError); return this; }, /** * See {@link OBJLoader2Parser.setCallbackOnLoad} * @return {OBJLoader2} */ setCallbackOnLoad: function setCallbackOnLoad(onLoad) { this.parser.setCallbackOnLoad(onLoad); return this; }, /** * Register a function that is called once a single mesh is available and it could be altered by the supplied function. * * @param {Function} [onMeshAlter] * @return {OBJLoader2} */ setCallbackOnMeshAlter: function setCallbackOnMeshAlter(onMeshAlter) { this.meshReceiver._setCallbacks(this.parser.callbacks.onProgress, onMeshAlter); return this; }, /** * Register a function that is called once all materials have been loaded and they could be altered by the supplied function. * * @param {Function} [onLoadMaterials] * @return {OBJLoader2} */ setCallbackOnLoadMaterials: function setCallbackOnLoadMaterials(onLoadMaterials) { this.materialHandler._setCallbacks(onLoadMaterials); return this; }, /** * Use this convenient method to load a file at the given URL. By default the fileLoader uses an ArrayBuffer. * * @param {string} url A string containing the path/URL of the file to be loaded. * @param {function} onLoad A function to be called after loading is successfully completed. The function receives loaded Object3D as an argument. * @param {function} [onFileLoadProgress] A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains total and Integer bytes. * @param {function} [onError] A function to be called if an error occurs during loading. The function receives the error as an argument. * @param {function} [onMeshAlter] Called after every single mesh is made available by the parser */ load: function load(url, onLoad, onFileLoadProgress, onError, onMeshAlter) { var scope = this; if (onLoad === null || onLoad === undefined || !(onLoad instanceof Function)) { var errorMessage = 'onLoad is not a function! Aborting...'; scope.parser.callbacks.onError(errorMessage); throw errorMessage; } else { this.parser.setCallbackOnLoad(onLoad); } if (onError === null || onError === undefined || !(onError instanceof Function)) { onError = function onError(event) { var errorMessage = event; if (event.currentTarget && event.currentTarget.statusText !== null) { errorMessage = 'Error occurred while downloading!\nurl: ' + event.currentTarget.responseURL + '\nstatus: ' + event.currentTarget.statusText; } scope.parser.callbacks.onError(errorMessage); }; } if (!url) { onError('An invalid url was provided. Unable to continue!'); } var urlFull = new URL(url, window.location.href).href; var filename = urlFull; var urlParts = urlFull.split('/'); if (urlParts.length > 2) { filename = urlParts[urlParts.length - 1]; this.path = urlParts.slice(0, urlParts.length - 1).join('/') + '/'; } if (onFileLoadProgress === null || onFileLoadProgress === undefined || !(onFileLoadProgress instanceof Function)) { var numericalValueRef = 0; var numericalValue = 0; onFileLoadProgress = function onFileLoadProgress(event) { if (!event.lengthComputable) return; numericalValue = event.loaded / event.total; if (numericalValue > numericalValueRef) { numericalValueRef = numericalValue; var output = 'Download of "' + url + '": ' + (numericalValue * 100).toFixed(2) + '%'; scope.parser.callbacks.onProgress('progressLoad', output, numericalValue); } }; } this.setCallbackOnMeshAlter(onMeshAlter); var fileLoaderOnLoad = function fileLoaderOnLoad(content) { scope.parser.callbacks.onLoad(scope.parse(content), "OBJLoader2#load: Parsing completed"); }; var fileLoader = new FileLoader(this.manager); fileLoader.setPath(this.path || this.resourcePath); fileLoader.setResponseType('arraybuffer'); fileLoader.load(filename, fileLoaderOnLoad, onFileLoadProgress, onError); }, /** * Parses OBJ data synchronously from arraybuffer or string and returns the {@link Object3D}. * * @param {arraybuffer|string} content OBJ data as Uint8Array or String * @return {Object3D} */ parse: function parse(content) { // fast-fail in case of illegal data if (content === null || content === undefined) { throw 'Provided content is not a valid ArrayBuffer or String. Unable to continue parsing'; } if (this.parser.logging.enabled) { console.time('OBJLoader parse: ' + this.modelName); } // Create default materials beforehand, but do not override previously set materials (e.g. during init) this.materialHandler.createDefaultMaterials(false); // code works directly on the material references, parser clear its materials before updating this.parser.setMaterials(this.materialHandler.getMaterials()); if (content instanceof ArrayBuffer || content instanceof Uint8Array) { if (this.parser.logging.enabled) console.info('Parsing arrayBuffer...'); this.parser.execute(content); } else if (typeof content === 'string' || content instanceof String) { if (this.parser.logging.enabled) console.info('Parsing text...'); this.parser.executeLegacy(content); } else { this.parser.callbacks.onError('Provided content was neither of type String nor Uint8Array! Aborting...'); } if (this.parser.logging.enabled) { console.timeEnd('OBJLoader parse: ' + this.modelName); } return this.baseObject3d; }, _onAssetAvailable: function _onAssetAvailable(payload) { if (payload.cmd !== 'assetAvailable') return; if (payload.type === 'mesh') { var meshes = this.meshReceiver.buildMeshes(payload); var _iterator = _createForOfIteratorHelper(meshes), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var mesh = _step.value; this.baseObject3d.add(mesh); } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } } else if (payload.type === 'material') { this.materialHandler.addPayloadMaterials(payload); } } }); export { OBJLoader2 };