视频
系统URL整合系列视频三(前端代码实现)
视频介绍
(全国)大型分布式系统Web资源URL整合需求前端代码实现。当今社会各行各业对软件系统的web资源访问权限控制越来越严格,控制粒度也越来越细。安全级别提高的同时也增加了使用成本,譬如让权限申请越来越繁琐。本文讲解的前端工程:用于实现在申请少量web资源权限的条件下访问更多的web资源的界面需求
项目附件
附件一:需求文档下载
https://download.youkuaiyun.com/download/jjk_02027/90335894
附件二:原型设计稿下载
https://download.youkuaiyun.com/download/jjk_02027/90335900
附件三:前端代码下载
https://download.youkuaiyun.com/download/jjk_02027/90335919
附件四:需求excel演示说明稿下载
https://download.youkuaiyun.com/download/jjk_02027/90335940
附件五:后端代码/配置下载
https://download.youkuaiyun.com/download/jjk_02027/90354803

D3JS相关网址
D3JS 官方网址: D3 by Observable | The JavaScript library for bespoke data visualization
D3JS 帮助文档:Getting started | D3 by Observable
D3JS 入门
D3.js(Data-Driven Documents)是一个强大的JavaScript库,用于基于数据操作文档,常用于创建动态、交互式的数据可视化。以下是D3.js的基本操作指南,分步骤讲解关键概念和常见用法:
1. 引入D3.js
在HTML文件中通过CDN引入D3.js:
<script src="https://d3js.org/d3.v7.min.js"></script>
2. 创建SVG容器
使用D3选择DOM元素并创建SVG画布:
const width = 600, height = 400;
const svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
3. 数据绑定与元素创建
绑定数据并创建元素(例如圆形):
const data = [10, 20, 30, 40, 50];
svg.selectAll("circle")
.data(data)
.enter() // 处理新增数据
.append("circle")
.attr("cx", (d, i) => 50 + i * 100) // x坐标
.attr("cy", height/2) // y坐标
.attr("r", d => d) // 半径由数据决定
.attr("fill", "steelblue");
4. 比例尺(Scales)
将数据范围映射到视觉属性(如位置、颜色):
// 线性比例尺(数据范围映射到宽度)
const xScale = d3.scaleLinear()
.domain([0, d3.max(data)]) // 输入范围(数据)
.range([0, width - 100]); // 输出范围(像素)
// 修改圆形的cx属性使用比例尺
.attr("cx", (d, i) => xScale(d))
5. 坐标轴(Axes)
生成坐标轴并添加到SVG中:
const xAxis = d3.axisBottom(xScale); // 底部对齐的x轴
svg.append("g")
.attr("transform", `translate(50, ${height - 30})`) // 调整轴的位置
.call(xAxis);
6. 过渡动画(Transitions)
为元素添加平滑的过渡效果:
d3.selectAll("circle")
.transition()
.duration(1000) // 动画时长(毫秒)
.attr("cy", height/2 - 50)
.attr("fill", "orange");
7. 交互事件(Events)
监听用户交互(如鼠标悬停):
d3.selectAll("circle")
.on("mouseover", function(event, d) {
d3.select(this)
.attr("fill", "red");
})
.on("mouseout", function() {
d3.select(this)
.attr("fill", "steelblue");
});
8. 数据更新模式
处理动态数据变化(enter/update/exit):
// 新数据
const newData = [15, 25, 35, 45, 55, 65];
// 绑定新数据
const circles = svg.selectAll("circle").data(newData);
// 新增元素(enter)
circles.enter()
.append("circle")
.attr("cx", (d, i) => 50 + i * 100)
.attr("cy", height/2)
.attr("r", 0)
.attr("fill", "green")
.transition().duration(500).attr("r", d => d);
// 更新现有元素(update)
circles.transition().duration(500)
.attr("r", d => d)
.attr("fill", "purple");
// 删除多余元素(exit)
circles.exit()
.transition().duration(500)
.attr("r", 0)
.remove();
9. 路径生成器(如折线图)
使用d3.line()生成路径数据:
const lineData = [[0, 50], [100, 80], [200, 40], [300, 60]];
const lineGenerator = d3.line()
.x(d => d)
.y(d => d);
svg.append("path")
.attr("d", lineGenerator(lineData))
.attr("stroke", "blue")
.attr("fill", "none");
总结
- 核心概念:数据绑定(
data())、元素操作(append/attr)、比例尺(scale)、坐标轴(axis)、过渡(transition)。 - 典型流程:选择元素 → 绑定数据 → 处理新增/更新/删除 → 设置视觉属性。
- 进阶技巧:力导向图、地图投影、布局(如饼图、树图)、自定义交互逻辑。
通过结合这些基本操作,可以逐步构建复杂的可视化效果,并根据需求添加交互和动画。建议从简单案例入手,逐步深入实践!
1099

被折叠的 条评论
为什么被折叠?



