Diff
checker
文本
文本
图像
文档
Excel
文件夹
Legal
Enterprise
桌面版
定价
登录
下载 Diffchecker 桌面版
比较文本
查找两个文本文件之间的差异
工具
历史
实时编辑器
折叠未更改行
关闭换行
视图
拆分
统一
比对精度
智能
单词
字符
语法高亮
选择语法
忽略
文本转换
转到第一个差异
编辑输入
Diffchecker Desktop
运行Diffchecker最安全的方式。获取Diffchecker桌面应用:您的差异永远不会离开您的电脑!
获取桌面版
Sunburst Tutorial 2 vs. 3 --> https://denjn5.github.io/tutorials/
创建于
9年前
差异永不过期
清除
导出
分享
解释
5 删除
行
总计
删除
字符
总计
删除
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
57 行
全部复制
28 添加
行
总计
添加
字符
总计
添加
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
79 行
全部复制
<!DOCTYPE html>
<!DOCTYPE html>
<head>
<head>
复制
已复制
复制
已复制
<title>Sunburst Tutorial (d3 v4), Part
2
</title>
<title>Sunburst Tutorial (d3 v4), Part
3
</title>
<script src='../plugins/d3/d3.v4.min.js'></script>
<script src='../plugins/d3/d3.v4.min.js'></script>
</head>
</head>
<body>
<body>
<svg></svg>
<svg></svg>
</body>
</body>
<script>
<script>
var vWidth = 300;
var vWidth = 300;
var vHeight = 300;
var vHeight = 300;
var vRadius = Math.min(vWidth, vHeight) / 2;
var vRadius = Math.min(vWidth, vHeight) / 2;
var vColor = d3.scaleOrdinal(d3.schemeCategory20b);
var vColor = d3.scaleOrdinal(d3.schemeCategory20b);
// Prepare our physical space
// Prepare our physical space
var g = d3.select('svg')
var g = d3.select('svg')
.attr('width', vWidth).attr('height', vHeight)
.attr('width', vWidth).attr('height', vHeight)
.append('g')
.append('g')
.attr('transform', 'translate(' + vWidth / 2 + ',' + vHeight / 2 + ')');
.attr('transform', 'translate(' + vWidth / 2 + ',' + vHeight / 2 + ')');
// d3 layout
// d3 layout
var vLayout = d3.partition().size([2 * Math.PI, vRadius]);
var vLayout = d3.partition().size([2 * Math.PI, vRadius]);
var vArc = d3.arc()
var vArc = d3.arc()
.startAngle(function (d) { return d.x0; })
.startAngle(function (d) { return d.x0; })
.endAngle(function (d) { return d.x1; })
.endAngle(function (d) { return d.x1; })
.innerRadius(function (d) { return d.y0; })
.innerRadius(function (d) { return d.y0; })
.outerRadius(function (d) { return d.y1; });
.outerRadius(function (d) { return d.y1; });
// Get the data from our JSON file
// Get the data from our JSON file
d3.json('data-simple.json', function(error, vData) {
d3.json('data-simple.json', function(error, vData) {
if (error) throw error;
if (error) throw error;
drawSunburst(vData);
drawSunburst(vData);
});
});
/**
/**
* Draw our sunburst
* Draw our sunburst
* @param {object} data - Hierarchical data
* @param {object} data - Hierarchical data
*/
*/
function drawSunburst(data) {
function drawSunburst(data) {
// Layout prep
// Layout prep
var vRoot = d3.hierarchy(data).sum(function (d) { return d.size});
var vRoot = d3.hierarchy(data).sum(function (d) { return d.size});
var vNodes = vRoot.descendants();
var vNodes = vRoot.descendants();
vLayout(vRoot);
vLayout(vRoot);
复制
已复制
复制
已复制
var vSlices = g.selectAll('
path
').data(vNodes).enter().append('
path
');
var vSlices = g.selectAll('
g
').data(vNodes).enter().append('
g
');
// Draw sunburst
// Draw sunburst
复制
已复制
复制
已复制
vSlices
vSlices
.append('path')
.attr('display', function (d) { return d.depth ? null : 'none'; })
.attr('display', function (d) { return d.depth ? null : 'none'; })
.attr('d', vArc)
.attr('d', vArc)
.style('stroke', '#fff')
.style('stroke', '#fff')
复制
已复制
复制
已复制
.style('fill', function (d) {
.style('fill', function (d) {
return vColor((d.children ? d : d.parent).data.id); });
return vColor((d.children ? d : d.parent).data.id); });
// Add text
vSlices.append('text')
.filter(function(d) { return d.parent; })
.attr('transform', function(d) {
return 'translate(' + vArc.centroid(d) + ')rotate(' + computeTextRotation(d) + ')'; })
.attr('dx', '-20')
.attr('dy', '.5em')
.text(function(d) { return d.data.id });
}
/**
* Calculate the rotation for each label based on its location in the sunburst.
* @param {Node} d - the d3 note for which we're computing text rotation
* @return {Number} the value that should populate the transform: rotate() statement
*/
function computeTextRotation(d) {
var angle = (d.x0 + d.x1) / Math.PI * 90;
// Avoid upside-down labels
return (angle < 120 || angle > 270) ? angle : angle + 180; // labels as rims
//return (angle < 180) ? angle - 90 : angle + 90; // labels as spokes
}
}
</script>
</script>
已保存差异
原始文本
打开文件
<!DOCTYPE html> <head> <title>Sunburst Tutorial (d3 v4), Part 2</title> <script src='../plugins/d3/d3.v4.min.js'></script> </head> <body> <svg></svg> </body> <script> var vWidth = 300; var vHeight = 300; var vRadius = Math.min(vWidth, vHeight) / 2; var vColor = d3.scaleOrdinal(d3.schemeCategory20b); // Prepare our physical space var g = d3.select('svg') .attr('width', vWidth).attr('height', vHeight) .append('g') .attr('transform', 'translate(' + vWidth / 2 + ',' + vHeight / 2 + ')'); // d3 layout var vLayout = d3.partition().size([2 * Math.PI, vRadius]); var vArc = d3.arc() .startAngle(function (d) { return d.x0; }) .endAngle(function (d) { return d.x1; }) .innerRadius(function (d) { return d.y0; }) .outerRadius(function (d) { return d.y1; }); // Get the data from our JSON file d3.json('data-simple.json', function(error, vData) { if (error) throw error; drawSunburst(vData); }); /** * Draw our sunburst * @param {object} data - Hierarchical data */ function drawSunburst(data) { // Layout prep var vRoot = d3.hierarchy(data).sum(function (d) { return d.size}); var vNodes = vRoot.descendants(); vLayout(vRoot); var vSlices = g.selectAll('path').data(vNodes).enter().append('path'); // Draw sunburst vSlices .attr('display', function (d) { return d.depth ? null : 'none'; }) .attr('d', vArc) .style('stroke', '#fff') .style('fill', function (d) { return vColor((d.children ? d : d.parent).data.id); }); } </script>
更改后文本
打开文件
<!DOCTYPE html> <head> <title>Sunburst Tutorial (d3 v4), Part 3</title> <script src='../plugins/d3/d3.v4.min.js'></script> </head> <body> <svg></svg> </body> <script> var vWidth = 300; var vHeight = 300; var vRadius = Math.min(vWidth, vHeight) / 2; var vColor = d3.scaleOrdinal(d3.schemeCategory20b); // Prepare our physical space var g = d3.select('svg') .attr('width', vWidth).attr('height', vHeight) .append('g') .attr('transform', 'translate(' + vWidth / 2 + ',' + vHeight / 2 + ')'); // d3 layout var vLayout = d3.partition().size([2 * Math.PI, vRadius]); var vArc = d3.arc() .startAngle(function (d) { return d.x0; }) .endAngle(function (d) { return d.x1; }) .innerRadius(function (d) { return d.y0; }) .outerRadius(function (d) { return d.y1; }); // Get the data from our JSON file d3.json('data-simple.json', function(error, vData) { if (error) throw error; drawSunburst(vData); }); /** * Draw our sunburst * @param {object} data - Hierarchical data */ function drawSunburst(data) { // Layout prep var vRoot = d3.hierarchy(data).sum(function (d) { return d.size}); var vNodes = vRoot.descendants(); vLayout(vRoot); var vSlices = g.selectAll('g').data(vNodes).enter().append('g'); // Draw sunburst vSlices.append('path') .attr('display', function (d) { return d.depth ? null : 'none'; }) .attr('d', vArc) .style('stroke', '#fff') .style('fill', function (d) { return vColor((d.children ? d : d.parent).data.id); }); // Add text vSlices.append('text') .filter(function(d) { return d.parent; }) .attr('transform', function(d) { return 'translate(' + vArc.centroid(d) + ')rotate(' + computeTextRotation(d) + ')'; }) .attr('dx', '-20') .attr('dy', '.5em') .text(function(d) { return d.data.id }); } /** * Calculate the rotation for each label based on its location in the sunburst. * @param {Node} d - the d3 note for which we're computing text rotation * @return {Number} the value that should populate the transform: rotate() statement */ function computeTextRotation(d) { var angle = (d.x0 + d.x1) / Math.PI * 90; // Avoid upside-down labels return (angle < 120 || angle > 270) ? angle : angle + 180; // labels as rims //return (angle < 180) ? angle - 90 : angle + 90; // labels as spokes } </script>
查找差异