大屏可视化:阿里 DataV 大屏怎么做自适应的?

news/2024/9/19 4:49:28/ 标签: 数据可视化, 前端, javascript

你好,我是沐爸,欢迎点赞、收藏、评论和关注。

阿里 DataV 大屏是一款功能强大的数据可视化应用搭建工具,由阿里云提供,旨在帮助用户通过图形化的界面轻松搭建专业水准的可视化应用。

下面我们一起看下 DataV 大屏 是如何做自适应的?

了解 阿里 DataV 大屏,可注册账号免费试用,时长为1个月。随便打开一个大屏模板,点击画布,编辑器右侧会显示页面配置,其中“缩放方式”即为自适应方案,一共有5种。

一、全屏铺满

特点:
  • 铺满屏幕,不保持纵横比。
  • 页面元素可能被拉伸或压缩。

<template><div id="root-el" :style="{ transform: 'scale(' + x + ',' + y + ')' }">这里放一张图片</div>
</template><script>javascript">export default {data() {return {x: 1,y: 1}},mounted() {this.x = window.innerWidth / 1920this.y = window.innerHeight / 1080window.onresize = () => {this.x = window.innerWidth / 1920this.y = window.innerHeight / 1080}}}
</script>     

二、等比宽度铺满可滚动

特点:
  • 保持纵横比。
  • 缩小时可能会留白。
  • 屏幕内容被遮挡时显示滚动条,未被遮挡时无滚动条。

<style>html {width: 100% !important;height: 100% !important;overflow: hidden !important;}body {width: 100%;height: 100%;overflow: hidden;}body:hover ::-webkit-scrollbar-thumb{display: block;}::-webkit-scrollbar-thumb {display: none;background: #525252;border-radius: 2px}::-webkit-scrollbar-track {background: transparent;}::-webkit-scrollbar {display: block;width: 4px;height: 4px}::-webkit-scrollbar-corner {background-color: transparent}#app {width: 100%;height: 100%;}
</style>
<template><div id="root"><div class="preview-page"><div id="runtime"><div class="datav-common-hoc"><div class="datav-com-wrapper"><div class="datav-absolute-page-wp" :style="{ height: innerHeight + 'px' }"><div id="index" ref="appRef" :style="{ transform: 'scale(' + x + ')' }"><div class="bg">......</div></div></div></div></div></div></div></div>
</template><script>javascript">
export default {data() {return {x: 1,y: 1,innerHeight: 1080}},mounted() {this.x = window.innerWidth / 1920this.y = window.innerHeight / 1080this.innerHeight = 1080 * this.xwindow.onresize = () => {this.x = window.innerWidth / 1920this.y = window.innerHeight / 1080this.innerHeight = 1080 * this.x}}
}
</script><style lang="scss" scoped>#root {width: 100%;height: 100%;display: flex;flex-direction: column;.preview-page {width: 100%;height: 100%;overflow: auto;flex: 1 1;#runtime {width: 100%;height: 100%;.datav-common-hoc {height: 100%;width: 100%;position: relative;.datav-com-wrapper {height: 100%;width: 100%;position: relative;transform: translate(0, 0);box-sizing: border-box;transform-origin: left top;overflow: inherit;.datav-absolute-page-wp {width: 100%;height: 100%;position: relative;overflow: hidden;#index {width: 1920px;height: 1080px;background: rgb(255, 255, 255);transform-origin: left top;overflow: hidden;.bg {width: 100%;height: 100%;padding: 16px 16px 0 16px;background-image: url("../assets/pageBg.png");background-size: cover;background-position: center center;}}}}}}}}
</style>

三、等比高度铺满居中

特点:
  • 保持纵横比
  • 页面居中显示,两侧可能留白。宽度不够时,两侧可能被隐藏。


<template><div id="root"><div class="preview-page"><div id="runtime"><div class="datav-common-hoc"><div class="datav-com-wrapper"><!--datav-absolute-page-wp 不再动态设置高度--><div class="datav-absolute-page-wp"><div id="index" ref="appRef" :style="{ transform: 'scale(' + x + ')', 'margin-left': ml + 'px' }"><div class="bg">......</div></div></div></div></div></div></div></div>
</template><script>javascript">export default {data() {return {x: 1,y: 1,ml: 0 // 水平方向的左外边距}},mounted() {this.x = window.innerWidth / 1920this.y = window.innerHeight / 1080this.ml = (window.innerWidth - 1920 * this.y) / 2window.onresize = () => {this.x = window.innerWidth / 1920this.y = window.innerHeight / 1080this.ml = (window.innerWidth - 1920 * this.y) / 2}}}
</script><style lang="scss" scoped>/*保持不变*/
</style>

四、等比高度可滚动

特点:
  • 保持纵横比
  • 窗口宽度大于内容宽度时,右侧留白。窗口宽度小于内容宽度时,显示滚动条。


<template><div id="root"><div class="preview-page"><div id="runtime"><div class="datav-common-hoc"><div class="datav-com-wrapper"><div class="datav-absolute-page-wp" style="overflow-x: auto;"><div class="datav-absolute-page" :style="{width: scaleWidth + 'px', height: innerHeight + 'px'}"><div id="index" ref="appRef" :style="{ transform: 'scale(' + y + ')' }"><div class="bg">......</div></div></div></div></div></div></div></div></div>
</template><script>javascript">export default {data() {return {x: 1,y: 1,scaleWidth: 1920}},mounted() {this.x = window.innerWidth / 1920this.y = window.innerHeight / 1080this.innerHeight = window.innerHeightthis.scaleWidth = 1920 * this.ywindow.onresize = () => {this.x = window.innerWidth / 1920this.y = window.innerHeight / 1080this.innerHeight = window.innerHeightthis.scaleWidth = 1920 * this.y}}}
</script><style lang="scss" scoped>/*保持不变*/
</style>

五、居中

特点:
  • 保持纵横比
  • 无论页面怎么缩放,总保持居中显示

<template><div id="root"><div class="preview-page"><div id="runtime"><div class="datav-common-hoc"><div class="datav-com-wrapper"><div class="datav-absolute-page-wp"><div class="datav-absolute-page" :style="{transform: 'translateX(-50%) translateY(-50%) scale(' + dynamicScale + ')'}"><div id="index" ref="appRef"><div class="bg">......</div></div></div></div></div></div></div></div></div>
</template><script>javascript">export default {data() {return {x: 1,y: 1,dynamicScale: 1}},mounted() {if (window.innerWidth / window.innerHeight < 1920 / 1080) {this.dynamicScale = (window.innerWidth / 1920)} else {this.dynamicScale = (window.innerHeight / 1080)}window.onresize = () => {if (window.innerWidth / window.innerHeight < 1920 / 1080) {this.dynamicScale = (window.innerWidth / 1920)} else {this.dynamicScale = (window.innerHeight / 1080)}}}}
</script><style lang="scss" scoped>.datav-absolute-page {width: 1920px;height: 1080px;background: rgb(255, 255, 255);transform: translateX(-50%) translateY(-50%) scale(0.550521);left: 50%;top: 50%;position: absolute;}/*其他保持不变*/
</style>

六、堪称完美的适配

DataV 大屏的5种自适应方案,多多少少都有些缺陷,有没有更完美的适配方式呢?看看下图

上面这种自适应如何实现?我们明天接着唠。

好了,分享结束,谢谢点赞,下期再见。


http://www.ppmy.cn/news/1520927.html

相关文章

Android 读取 XML 文件之 SAX 解析编码模板

一、SAX 解析概述 SAX&#xff08;Simple API for XML&#xff09;是一种基于事件的 XML 解析技术&#xff0c;它一边读取 XML 文件一边解析&#xff0c;占用内存少&#xff0c;适用于大型文件 SAX 解析器会触发一系列事件&#xff0c;例如&#xff0c;开始解析元素、结束解析…

【微处理器系统原理和应用设计第六讲】片上微处理器系统系统架构

一、概念辨析 首先来厘清以下概念&#xff1a;微处理器&#xff0c;微控制器&#xff0c;单片机&#xff0c;片上微处理器系统 &#xff08;1&#xff09;微处理器&#xff1a;即MPU&#xff08;Microprocessor Unit&#xff09;&#xff0c;微处理器是一种计算机的中央处理单…

【Next】5. 全局权限管理

以下笔记来源&#xff1a;编程导航 需求 能够灵活配置每个页面所需要的用户权限&#xff0c;由全局权限管理系统自动校验和拦截路由&#xff0c;而不需要在每个页面中编写权限校验代码&#xff0c;提高开发效率。&#xff08;路由权限&#xff09;还要能够根据权限控制导航菜单…

生活因科技而美好:一键解锁PDF处理的无限可能

前言 “科技&#xff0c;是时代的诗篇&#xff0c;书写着人类不断超越自我、追求卓越的壮丽篇章。”这一理念深刻地影响着每一位开发者&#xff0c;他们不断探索、创新&#xff0c;旨在为用户带来更加便捷、高效的生活体验。正是在这样的背景下&#xff0c;一款旨在提升PDF处理…

MySQL case when【用法详解】

MySQL case when【用法详解】 语法1. 简单CASE表达式2. 搜索CASE表达式 示例示例1&#xff1a;使用简单CASE表达式示例2&#xff1a;使用搜索CASE表达式示例3&#xff1a;在UPDATE语句中使用CASE示例4&#xff1a;在DELETE语句中使用CASE注意事项 总结 在MySQL中&#xff0c;CA…

【技术解析】工厂内部导航系统:高精度定位与智能路径规划的技术实现

一、工厂内部导航系统概述 工厂内部导航系统集成了最新的GPS室内定位技术、蓝牙定位技术&#xff0c;实现了对工厂内部环境的无缝覆盖与高精度定位。无论是繁忙的生产线、错综复杂的仓库还是广阔的厂区&#xff0c;都能轻松应对。 二、工厂内部导航系统核心功能 实时定位&…

深度学习的发展历程

深度学习的起源 在机器学习中&#xff0c;我们经常使用两种方式来表示特征&#xff1a;局部表示&#xff08;Local Representation&#xff09;和分布式表示&#xff08;Distributed Representation&#xff09;。以颜色表示为例&#xff0c;见下图&#xff1a; 要学习到一种好…

电信500M宽带+AX210无线网卡测速

500M电信宽带&#xff0c;PC的Wifi模块是AX210 一、PC测速 2.4G Wifi 5G Wifi 有线网口 二、 手机端&#xff0c;小翼管家App测速 2.4G Wifi 5G Wifi 结论&#xff1a; 手机上网要快的话&#xff0c;还是要选择5G wifi

使用实例:xxl-job应用在spring cloud微服务下

1、首先下载&#xff0c;从github上下载&#xff0c;选择zip然后直接解压 https://github.com/xuxueli/xxl-job/releases 2、解压完后用idea启动。 启动这个启动类&#xff0c;然后按照路径访问 http://localhost:8080/xxl-job-admin/ 3、在你的项目里编写一个单独的微服务&a…

目标跟踪算法——ByteTrack算法原理解析

文章目录 ByteTrack1. ByteTrack算法步骤&#xff1a;2. 算法解释2.1 模型初始化2.2 模型更新算法流程2.2.1 检测结果划分&#xff0c;划分为高分和较低分段2.2.2 高分段处理手段2.2.3 最优匹配与未匹配划分2.2.4 低分框再匹配2.2.5 未确认轨迹处理2.2.6 更新状态 2.3 匈牙利匹…

ffplay源码分析(五)包缓存队列和帧缓存队列

在音视频处理流程中&#xff0c;ffplay的有两种队列&#xff0c;包缓存队列&#xff08;Packet Buffer Queue&#xff09;和帧缓存队列&#xff08;Frame Buffer Queue&#xff09;。这两个队列的存在&#xff0c;是为了适应音视频数据处理过程中的多线程架构——包括收包线程、…

图像白平衡

目录 效果 背景 什么是白平衡&#xff1f; 实现原理 将指定图色调调整为参考图色调主要流程 示例代码 效果 将图一效果转换为图二效果色调&#xff1a; 调整后&#xff0c;可实现色调对换 背景 现有两张图像&#xff0c;色调不一致&#xff0c;对于模型重建会有影响。因…

RabbitMQ 02 操作,配置信息,用户权限

01.介绍启动&#xff0c;关闭 02.环境 2.1 MQ是用Erlang语言写的 2.2 一个RabbitMQ 节点 一个 Erlang节点一个Erlang 程序 &#xff08;RabbitMQ程序&#xff09; 2.3 Erlang节点&#xff1a; 这个是Erlang节点集群状态下&#xff1a; 2.4 启动节点 2.5 查看日志信息 …

2021年大厂Java面试题(基础+框架+系统架构+分布式+实战)

Java线程的状态 进程和线程的区别&#xff0c;进程间如何通讯&#xff0c;线程间如何通讯 HashMap的数据结构是什么&#xff1f;如何实现的。和HashTable&#xff0c;ConcurrentHashMap的区别 Cookie和Session的区别 索引有什么用&#xff1f;如何建索引&#xff1f; Arra…

Elasticsearch 中,term 查询和 match 查询的区别

文章目录 前言Elasticsearch 中&#xff0c;term 查询和 match 查询的区别1. Term 查询2. Match 查询3. 总结 前言 如果您觉得有用的话&#xff0c;记得给博主点个赞&#xff0c;评论&#xff0c;收藏一键三连啊&#xff0c;写作不易啊^ _ ^。   而且听说点赞的人每天的运气都…

各种各样的正则表达式

一、校验数字的表达式 数字:^[0-9]*$ n位的数字:^\d{n}$ 至少n位的数字:^\d{n,}$ m-n位的数字:^\d{m,n}$ 零和非零开头的数字:^(0|[1-9][0-9]*)$ 非零开头的最多带两位小数的数字:^([1-9][0-9]*)+(.[0-9]{1,2})?$ 带1-2位小数的正数或负数:^(\-)?\d+(\.\d{1,2})?$ 正…

【flask】python框架flask的hello world

创建一个py文件&#xff0c;写如下内容 # save this as app.py from flask import Flaskapp Flask(__name__)app.route("/") def hello():return "Hello, World!"如下图 在此py文件路径下启动cmd&#xff0c;输入 flask run结果如下图 在浏览器中访问…

【科普】数字化和数字化转型:是什么,为什么,怎么做?

​一、什么是数字化转型&#xff1f; 近年来 “数字化”、“数字化转型”概念已经渗透到各个行业&#xff0c;成为业界的热点议题。对于什么是“数字化转型”&#xff0c;众说纷纭。 有人说“数字化转型不过就是给传统的信息化穿上皇帝的新衣”&#xff0c;也有人说“数字化转…

策略优化:提升MySQL数据备份效率的实用指南

在当今数据驱动的商业环境中&#xff0c;数据备份策略的优化对于确保数据安全和业务连续性至关重要。MySQL作为广泛使用的数据库系统&#xff0c;其数据备份策略的优化不仅可以提高数据恢复的效率&#xff0c;还能降低存储成本和提高系统性能。本文将深入探讨如何在MySQL中实现…

用户管理和授权

授权 mysql> show databases; -------------------- | Database | -------------------- | information_schema | | day01db | | employees | | mysql | | mysql01 | | mysql02 | | performance_schema …