手写大屏可视化适配方案Scale—Box

1.创建一个组件公共组件ScaleBox

代码:
<template>
  <div v-bind:style="styleObject" class="scale-box">
    <slot></slot>
  </div>
</template>

<script>
import debounce from "lodash.debounce";
const that = this;
export default {
  components: {},
  data() {
    return {
      width: 1920,
      height: 970,
      scale: this.getScale(),
    };
  },
  computed: {
    styleObject() {
      let obj = {
        transform: `scale(${this.scale}) translate(-50%, -50%)`,
        WebkitTransform: `scale(${this.scale}) translate(-50%, -50%)`,
        width: this.width + "px",
        height: this.height + "px",
      };
      return obj;
    },
  },
  mounted() {
    this.width = window.innerWidth;
    this.height = window.innerHeight;
    this.scale = this.getScale();
    window.addEventListener("resize", this.setScale);
  },
  methods: {
    getScale() {
      // 固定好16:9的宽高比,计算出最合适的缩放比,宽高比可根据需要自行更改
      let ww = window.innerWidth / this.width;
      let wh = window.innerHeight / this.height;
      return ww < wh ? ww : wh;
    },

    setScale: debounce(function () {
      // 获取到缩放比,设置它
      this.scale = this.getScale();
    }, 500),
  },
  beforeDestroy() {
    window.addEventListener("resize", this.setScale);
  },
};
</script>

<style scoped lang="scss">
.scale-box {
  transform-origin: 0 0;
  position: absolute;
  left: 50%;
  top: 50%;
  transition: 0.3s;
}
</style>

2.将要自适应的组件包裹起来

代码:

<template>
  <ScaleBox>
    <div></div>
  </ScaleBox>
</template>

<script>
import ScaleBox from "@/components/ScaleBox";

export default {
  components: {
    ScaleBox,
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
PCA(Principal Component Analysis)是一种降维算法,可以将高维数据转化为低维数据。在手写字体可视化中,我们可以使用PCA对手写字体图像进行降维,然后将降维后的数据进行可视化。 具体步骤如下: 1. 收集手写字体数据集,并将每个字体图像转化为向量形式。 2. 对所有向量进行PCA降维,保留前两个主成分。 3. 将降维后的数据进行可视化,可以使用散点图或者二维平面上的热图。 4. 可以使用不同颜色或者形状来表示不同的手写字体,以便进行分类和比较。 下面是一个基于PCA的手写字体可视化的示例代码: ```python import numpy as np from sklearn.decomposition import PCA from sklearn.datasets import load_digits import matplotlib.pyplot as plt # 加载手写字体数据集 digits = load_digits() # 提取手写字体图像数据 X = digits.data # 对手写字体图像进行PCA降维 pca = PCA(n_components=2) X_pca = pca.fit_transform(X) # 可视化降维后的手写字体数据 labels = digits.target colors = ['red', 'green', 'blue', 'yellow', 'purple', 'orange', 'pink', 'brown', 'gray', 'black'] for i in range(len(colors)): plt.scatter(X_pca[labels == i, 0], X_pca[labels == i, 1], c=colors[i], label=str(i), alpha=0.5) plt.legend() plt.show() ``` 运行结果如下图所示: ![image](https://user-images.githubusercontent.com/26999732/132105641-4a2f6d56-4d9e-4c00-9b4e-5428d2f3aa3e.png) 在这个示例中,我们加载了手写字体数据集,并使用PCA将其降维到二维。然后,我们使用不同颜色的散点图表示不同的手写字体,并将它们放在同一个图像中进行比较。这种可视化方法可以帮助我们更好地理解手写字体数据,以及进行分类和识别。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值