UNPKG

bytev-charts

Version:

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

130 lines (113 loc) 4.54 kB
import "core-js/modules/es.array.sort.js"; import _Object$assign from "@babel/runtime-corejs2/core-js/object/assign"; import _Object$create from "@babel/runtime-corejs2/core-js/object/create"; import _WeakMap from "@babel/runtime-corejs2/core-js/weak-map"; console.warn("THREE.CSS2DRenderer: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation."); THREE.CSS2DObject = function (element) { THREE.Object3D.call(this); this.element = element || document.createElement('div'); this.element.style.position = 'absolute'; this.addEventListener('removed', function () { this.traverse(function (object) { if (object.element instanceof Element && object.element.parentNode !== null) { object.element.parentNode.removeChild(object.element); } }); }); }; THREE.CSS2DObject.prototype = _Object$assign(_Object$create(THREE.Object3D.prototype), { constructor: THREE.CSS2DObject, copy: function copy(source, recursive) { THREE.Object3D.prototype.copy.call(this, source, recursive); this.element = source.element.cloneNode(true); return this; } }); // THREE.CSS2DRenderer = function () { var _this = this; var _width, _height; var _widthHalf, _heightHalf; var vector = new THREE.Vector3(); var viewMatrix = new THREE.Matrix4(); var viewProjectionMatrix = new THREE.Matrix4(); var cache = { objects: new _WeakMap() }; var domElement = document.createElement('div'); domElement.style.overflow = 'hidden'; this.domElement = domElement; this.getSize = function () { return { width: _width, height: _height }; }; this.setSize = function (width, height) { _width = width; _height = height; _widthHalf = _width / 2; _heightHalf = _height / 2; domElement.style.width = width + 'px'; domElement.style.height = height + 'px'; }; var renderObject = function renderObject(object, scene, camera) { if (object instanceof THREE.CSS2DObject) { object.onBeforeRender(_this, scene, camera); vector.setFromMatrixPosition(object.matrixWorld); vector.applyMatrix4(viewProjectionMatrix); var element = object.element; var style = 'translate(-50%,-50%) translate(' + (vector.x * _widthHalf + _widthHalf) + 'px,' + (-vector.y * _heightHalf + _heightHalf) + 'px)'; element.style.WebkitTransform = style; element.style.MozTransform = style; element.style.oTransform = style; element.style.transform = style; element.style.display = object.visible && vector.z >= -1 && vector.z <= 1 ? '' : 'none'; var objectData = { distanceToCameraSquared: getDistanceToSquared(camera, object) }; cache.objects.set(object, objectData); if (element.parentNode !== domElement) { domElement.appendChild(element); } object.onAfterRender(_this, scene, camera); } for (var i = 0, l = object.children.length; i < l; i++) { renderObject(object.children[i], scene, camera); } }; var getDistanceToSquared = function () { var a = new THREE.Vector3(); var b = new THREE.Vector3(); return function (object1, object2) { a.setFromMatrixPosition(object1.matrixWorld); b.setFromMatrixPosition(object2.matrixWorld); return a.distanceToSquared(b); }; }(); var filterAndFlatten = function filterAndFlatten(scene) { var result = []; scene.traverse(function (object) { if (object instanceof THREE.CSS2DObject) result.push(object); }); return result; }; var zOrder = function zOrder(scene) { var sorted = filterAndFlatten(scene).sort(function (a, b) { var distanceA = cache.objects.get(a).distanceToCameraSquared; var distanceB = cache.objects.get(b).distanceToCameraSquared; return distanceA - distanceB; }); var zMax = sorted.length; for (var i = 0, l = sorted.length; i < l; i++) { sorted[i].element.style.zIndex = zMax - i; } }; this.render = function (scene, camera) { if (scene.autoUpdate === true) scene.updateMatrixWorld(); if (camera.parent === null) camera.updateMatrixWorld(); viewMatrix.copy(camera.matrixWorldInverse); viewProjectionMatrix.multiplyMatrices(camera.projectionMatrix, viewMatrix); renderObject(scene, scene, camera); zOrder(scene); }; };