vue中实现3d词云效果(已封装组件)

<!--
 * @Description: 词云组件 页面
 * @Date: 2024/3/10 23:39
-->
<template>
  <div
    :style="{
      display: 'flex',
      justifyContent: 'center',
      border: '1px solid red',
    }"
  >
    <svg
      :width="width"
      :height="height"
      @mousemove="listener($event)"
      @mouseout="listener1($event)"
      @mouseover="listener2($event)"
    >
      <a
        href="#"
        v-for="(tag, index) in tags"
        :key="index"
        @click="showOptionsAndResult(tag.text)"
      >
        <text
          :x="tag.x"
          :y="tag.y"
          :font-size="7 * (1000 / (800 - tag.z * 2))"
          :font-weight="550"
          :fill-opacity="(600 + tag.z) / 800"
          :style="style(tag)"
        >
          {{ tag.text }}
        </text>
      </a>
    </svg>
  </div>
</template>

<script>
export default {
  props: {
    width: {
      type: Number,
      default: 600,
    },
    height: {
      type: Number,
      default: 600,
    },
    radius: {
      type: Number,
      default: 200,
    },
  },
  data() {
    return {
      speedX: Math.PI / 1800,
      speedY: Math.PI / 1800,
      tags: [],
      colorList: [
        "#e27027",
        "#cc7b2e",
        "#ad4331",
        "#88343b",
        "#d4902f",
        "#c7a736",
        "#8d7a3d",
        "#8d7a3d",
        "#d9b134",
      ],
      CXNum: 2,
      CYNum: 2,
    };
  },
  computed: {
    CX() {
      return this.width / this.CXNum;
    },
    CY() {
      return this.height / this.CYNum;
    },
  },
  mounted() {
    let _this = this;
    window.addEventListener(
      "resize",
      () => {
        let normalWidth = document.body.scrollWidth;
        _this.screenWidth = normalWidth;
        if (normalWidth <= 1550) {
          _this.CXNum = 2.7;
          _this.CYNum = 1.9;
        } else {
          _this.CXNum = 2.5;
          _this.CYNum = 1.8;
        }
      },
      false
    );
    setInterval(() => {
      this.rotateX(this.speedX);
      this.rotateY(this.speedY);
    }, 17);
  },
  methods: {
    rotateX(angleX) {
      var cos = Math.cos(angleX);
      var sin = Math.sin(angleX);
      for (let tag of this.tags) {
        var y1 = (tag.y - this.CY) * cos - tag.z * sin + this.CY;
        var z1 = tag.z * cos + (tag.y - this.CY) * sin;
        tag.y = y1;
        tag.z = z1;
      }
    },
    rotateY(angleY) {
      var cos = Math.cos(angleY);
      var sin = Math.sin(angleY);
      for (let tag of this.tags) {
        var x1 = (tag.x - this.CX) * cos - tag.z * sin + this.CX;
        var z1 = tag.z * cos + (tag.x - this.CX) * sin;
        tag.x = x1;
        tag.z = z1;
      }
    },
    listener(event) {
      var x = event.clientX - this.CX;
      var y = event.clientY - this.CY;
      this.speedX =
        x * 0.0001 > 0
          ? Math.min(this.radius * 0.00002, x * 0.0001)
          : Math.max(-this.radius * 0.00002, x * 0.0001);
      this.speedY =
        y * 0.0001 > 0
          ? Math.min(this.radius * 0.00002, y * 0.0001)
          : Math.max(-this.radius * 0.00002, y * 0.0001);
    },
    listener1(e) {
      this.speedX = Math.PI / 1800;
      this.speedY = Math.PI / 1800;
    },
    listener2(e) {
      this.speedX = 0;
      this.speedY = 0;
    },
    showOptionsAndResult(text) {
      this.$emit("showOptionsAndResult", true, text, "", "");
    },
    style(tag) {
      return `fill:${tag.color};`;
    },
    calculation3DWord(radius = "") {
      let tags = [];
      for (let i = 0; i < this.tags.length; i++) {
        let tag = {};
        let k = -1 + (2 * (i + 1) - 1) / this.tags.length;
        let a = Math.acos(k);
        let b = a * Math.sqrt(this.tags.length * Math.PI);
        tag.text =
          typeof this.tags[i] === "string" ? this.tags[i] : this.tags[i].text;
        if (radius === "") {
          tag.x = this.CX + this.radius * Math.sin(a) * Math.cos(b);
          tag.y = this.CY + this.radius * Math.sin(a) * Math.sin(b);
          tag.z = this.radius * Math.cos(a);
        } else {
          tag.x = 150 * (radius / 120) + radius * Math.sin(a) * Math.cos(b);
          tag.y = 150 * (radius / 120) + radius * Math.sin(a) * Math.sin(b);
          tag.z = radius * Math.cos(a);
        }
        if (i <= this.colorList.length - 1) {
          tag.color = this.colorList[i];
        } else {
          tag.color =
            i % this.colorList.length === 0
              ? this.colorList[0]
              : this.colorList[i % this.colorList.length];
        }
        tags.push(tag);
      }
      this.tags.splice(0);
      this.tags = tags;
    },
    setTags(tags = []) {
      this.tags.splice(0);
      this.tags.push(...tags);
      this.calculation3DWord();
    },
  },
};
</script>

<style></style>
// 使用
  <wordCloud
            ref="wordCloud"
            :width="rBox3.width"
            :height="rBox3.height"
          />
                
                import wordCloud from "@/views/dataScreen/wordCloud.vue";
  components: { wordCloud },

                
      init() {
			this.$refs.wordCloud.setTags([1, 2, 3 ,4 ,5 ,6]);
      }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/446931.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Linux动态追踪——ftrace

目录 摘要 1 初识 1.1 tracefs 1.2 文件描述 2 函数跟踪 2.1 函数的调用栈 2.2 函数调用栈 2.3 函数的子调用 3 事件跟踪 4 简化命令行工具 5 总结 摘要 Linux下有多种动态追踪的机制&#xff0c;常用的有 ftrace、perf、eBPF 等&#xff0c;每种机制适应于不同的场…

ES分页查询的最佳实践:三种方案

Elasticsearch&#xff08;ES&#xff09;中进行分页查询时&#xff0c;最佳实践取决于具体的使用场景和需求。 以下是对每种分页方法的简要分析以及它们适用的情况&#xff1a; 1. From Size 最常见且直观的方法&#xff0c;通过from参数指定跳过多少条记录&#xff0c;si…

Autosar Crypto Driver学习笔记(一)

文章目录 Crypto DriverPre-ConfigurationCryptographic capabilities加密能力Available Keys可用密钥 General BehaviorNormal OperationFunctional RequirementsSynchronous Job ProcessingAsynchronous Job Processing Design NotesPriority-dependent Job Queue基于优先级的…

docker安装jenkins并实现CICD流程

docker安装jenkins并实现CICD流程 本文目录 docker安装jenkins并实现CICD流程安装命令初始化设置更新jenkins及插件更新jenkins版本更新插件 创建第一个任务修改配置插件更新中心时区设置 安装命令 官方安装参考&#xff1a;https://www.jenkins.io/zh/doc/book/installing/ …

Docker安装tomcat

目录 一、安装Docker 二、Docker安装tomcat 三、安装tomcat 一、安装Docker 安装docker阅读 Docker整理之安装(1)-CSDN博客https://blog.csdn.net/ywanju/article/details/135442406 二、Docker安装tomcat 本案例安装的tomcat最新版本 搜(dockerhub搜索镜像版本) 拉(拉…

十二要素应用: 云原生应用最佳实践

本文介绍了开发部署云原生应用的一套最佳实践&#xff0c;通过这套最佳实践&#xff0c;可以最大限度利用云原生的能力&#xff0c;创建灵活、健壮、易管理的现代云原生应用程序。原文: The Twelve-Factor App: Best Practices for Cloud-Native Applications[1] 导言 软件如今…

爬虫与DataFrame对象小小结合

import pandas as pd import requests from lxml import etree #数据请求 url"https://www.maigoo.com/brand/list_1715.html" headers{User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.289 Safari…

【实验报告】C语言实现猜单词的小游戏

之前帮别人写的一个简单的报告&#xff0c;无偿分享给大家~代码在后面&#xff0c;有一些图片出于懒惰没有上传。比较简单&#xff0c;喜欢的话关注我~&#xff0c;请勿商用~ 1 系统功能模块结构图 该程序主要思路&#xff1a; 头文件设计&#xff0c;存储结构设计&#xff0…

Jmeter+Ant+Git/SVN+Jenkins实现持续集成接口测试,一文精通(一)

前言 Jmeter&#xff0c;Postman一些基本大家相比都懂。那么真实在项目中去使用&#xff0c;又是如何使用的呢&#xff1f;本文将一文详解jmeter接口测试 一、接口测试分类 二、目前接口架构设计 三、市面上的接口测试工具 四、Jmeter简介&#xff0c;安装&#xff0c;环境…

计算机网络—OSPF单区域配置

目录 目录 1.实验环境准备 2.配置 OSPF 3.验证 OSPF 配置 4.修改 OSPF hello 和 dead 时间参数 5.OSPF缺省路由发布及验证 6.控制 OSPF DR/BDR 的选举 7.配置文件 拓扑图&#xff1a; 1.实验环境准备 基本配置以及IP编址。 <Huawei>system-view Enter system vi…

YOLOv8改进 | 注意力篇 | 利用YOLO-Face提出的SEAM注意力机制优化物体遮挡检测(附代码 + 修改教程)

一、本文介绍 本文给大家带来的改进机制是由YOLO-Face提出能够改善物体遮挡检测的注意力机制SEAM&#xff0c;SEAM&#xff08;Spatially Enhanced Attention Module&#xff09;注意力网络模块旨在补偿被遮挡面部的响应损失&#xff0c;通过增强未遮挡面部的响应来实现这一目…

【JAVA】CSS定位与CSS3属性、渐变、CSS3字体、2D变换

1 定位 1.1 相对定位 相对定位没有脱离文档流 定位元素的显示层级比普通元素高 定位元素可以通过margin&#xff0c;float调整位置&#xff0c;但不推荐 包含块&#xff1a;父元素 left和right同时写&#xff0c;右失效 上下同时写&#xff0c;下失效 <head><s…

从零学习Linux操作系统 第三十四部分 Ansible中的执行流控制

一、ansible中的迭代循环 循环迭代任务# 1、简单循环# loop: ##赋值列表 – value1 – value2 – … {{item}} 迭代变量名称 2、循环散列或字典列表 二、Ansible中的条件语句 when: 条件1条件2 条件判断 ‘’value “字符串”,value 数字‘<’value < 数字‘>…

【基础计算机网络2】物理层——通信基础

【前言回顾】 【考纲内容】 一、物理层的基本概念 1.1 物理层的主要任务 物理层解决如何在连接各种计算机的传输媒体上传输数据比特流&#xff0c;而不是指具体的传输媒介。物理层的主要任务&#xff1a;确定与传输媒体接口有关的一些特性。 1.2 物理层的一些特性 机械特性…

C++变参模板

从c11开始&#xff0c;模板可以接受一组数量可变的参数&#xff0c;这种技术称为变参模板。 变参模板 下面一个例子&#xff0c;通过变参模板打印一组数量和类型都不确定的参数。 #include <iostream> #include <string>void print(void) {std::cout<<&quo…

【最新版】ChatGPT/GPT4科研应用与AI绘图论文写作(最新增加Claude3、Gemini、Sora、GPTs技术及AI领域中的集中大模型的最新技术)

2023年随着OpenAI开发者大会的召开&#xff0c;最重磅更新当属GPTs&#xff0c;多模态API&#xff0c;未来自定义专属的GPT。微软创始人比尔盖茨称ChatGPT的出现有着重大历史意义&#xff0c;不亚于互联网和个人电脑的问世。360创始人周鸿祎认为未来各行各业如果不能搭上这班车…

关于playbook中when条件过滤报The conditional check ‘result|failed‘ failed的问题

问题现象 在使用plabook中的when做过滤脚本如下&#xff1a; --- - hosts: realserversremote_user: roottasks:- name: Check if httpd service is runningcommand: systemctl status httpdregister: resultignore_errors: True- name: Handle failed service checkdebug:ms…

docker常用操作-docker私有仓库的搭建(Harbor),并将本地镜像推送至远程仓库中。

1、docker-compose安装&#xff0c;下载docker-compose的最新版本 第一步&#xff1a;创建docker-compose空白存放文件vi /usr/local/bin/docker-compose 第二步&#xff1a;使用curl命令在线下载&#xff0c;并制定写入路径 curl -L "https://github.com/docker/compos…

基于Spring Boot + Vue的电影购票系统

基于Spring Boot Vue的电影购票系统 功能介绍 分为用户端和商家端&#xff0c;商家端只能让拥有商家角色的人登录 商家可以在系统上面注册自己家的影院信息选择影院进去管理&#xff0c;在选择完要进行操作的影院后&#xff0c;可以在系统的电影库选择电影为当前的影院进行电…

Docker容器Docker桌面配置镜像加速

打开Docker Desktop应用程序&#xff0c;点击设置 具体配置如下&#xff1a; {"builder": {"gc": {"defaultKeepStorage": "20GB","enabled": true}},"experimental": false,"features": {"buil…
最新文章