javascript - d3.js tree - How to set Y depth of a specific level?
问题描述
In d3.js tree code, there is the following which sets the y depth for all child levels/nodes:
// Normalize for fixed-depth.
nodes.forEach(function(d) {
d.y = d.depth * 220;
});
How can I set the Y depth of a specific level in the hierarchy, e.g. the 3rd level?
解决方案
I guess you refer to this code
Simple example for the third level.
nodes.forEach(function(d) {
(d.depth === 1) ? d.y = d.depth * 100: d.y = d.depth * 300;
});
It display this https://jsfiddle.net/0rv8z276/
You can use a switch to set for different level, or maybe use an array or a hashmap with the key associated to the level and depth as the value.
推荐阅读
- wordpress - 如何在帖子循环内的静态 wordpress 首页上显示自定义帖子类型?
- python - 登录视图Django中没有反向匹配,html模板解析错误
- javascript - 如何使元素适合整个屏幕而不是视口
- python - Python问题:将间距分散到字符串,字符串总有一个特定的宽度
- php - 将PHP文件转换为Prepared语句的问题
- excel - 需要选择列范围内的所有行(已占用和空白行)以便稍后格式化
- r - R - lm() 函数不返回系数的 p 值
- javascript - 在 Pug 中提交 JSON 数据
- r - 将 R 中的百分比绘制为块
- javascript - 服务器身份验证后如何为前端提供令牌(可能使用 axios)?