- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 D3 Flare Graph 中,当每个圆圈只有一个标签时,标题和标签会重叠。我想渲染内部标签,避免与圆圈标题重叠,它在每个圆圈的中间渲染。
var flareGraph = function(containerId, options, json) {
options.width = options.width || 1280; // circle width
options.height = options.height || 800; // circle height
options.radius = options.radius || 720; // circle radius
var w = options.width,
h = options.height,
r = options.radius,
x = d3.scale.linear().range([0, r]),
y = d3.scale.linear().range([0, r]),
node,
root;
var pack = d3.layout.pack()
.size([r, r])
.value(function(d) {
return d.size;
})
var vis = d3.select(containerId).insert("svg:svg", "h2")
.attr("width", w)
.attr("height", h)
.append("svg:g")
.attr("transform", "translate(" + (w - r) / 2 + "," + (h - r) / 2 + ")");
function zoom(d, i) {
var k = r / d.r / 2;
x.domain([d.x - d.r, d.x + d.r]);
y.domain([d.y - d.r, d.y + d.r]);
var t = vis.transition()
.duration(d3.event.altKey ? 7500 : 750);
t.selectAll("circle")
.attr("cx", function(d) {
return x(d.x);
})
.attr("cy", function(d) {
return y(d.y);
})
.attr("r", function(d) {
return k * d.r;
});
t.selectAll("text")
.attr("x", function(d) {
return x(d.x);
})
.attr("y", function(d) {
return y(d.y);
})
.style("opacity", function(d) {
return k * d.r > 20 ? 1 : 0;
});
node = d;
d3.event.stopPropagation();
} //zoom
node = root = json;
var nodes = pack.nodes(root);
vis.selectAll("circle")
.data(nodes)
.enter().append("svg:circle")
.attr("class", function(d) {
return d.children ? "parent" : "child";
})
.attr("cx", function(d) {
return d.x;
})
.attr("cy", function(d) {
return d.y;
})
.attr("r", function(d) {
return d.r;
})
.on("click", function(d) {
return zoom(node == d ? root : d);
});
vis.selectAll("text")
.data(nodes)
.enter().append("svg:text")
.attr("class", function(d) {
return d.children ? "parent" : "child";
})
.attr("x", function(d) {
return d.x;
})
.attr("y", function(d) {
return d.y;
})
.attr("dy", ".35em")
.attr("text-anchor", "middle")
.style("opacity", function(d) {
return d.r > 20 ? 1 : 0;
})
.text(function(d) {
return d.name;
});
d3.select(window).on("click", function() {
zoom(root);
});
} //displayFlareGraph
var nodes = {
"name": "TYPES",
"children": [{
"name": "TYPE #iPhone",
"children": [{
"name": "iPhone6",
"size": 0.109375
}]
}, {
"name": "TYPE #OS",
"children": [{
"name": "macOS",
"size": 0.140625
}]
}, {
"name": "Info #Android",
"children": [{
"name": "Marshmellow",
"size": 0.11467116357504215
}, {
"name": "Lollipop",
"size": 0.12228604553119728
}, {
"name": "Nougat",
"size": 0.028667790893760536
}]
}, {
"name": "TYPE #Laptop",
"children": [{
"name": "MacbookPro",
"size": 0.14062499999999997
}, {
"name": "Macbook",
"size": 0.0703125
}, {
"name": "Surface",
"size": 0.0703125
}]
}, {
"name": "TYPE #Browser",
"children": [{
"name": "Firefox",
"size": 0.109375
}]
}, {
"name": "Info #iOS",
"children": [{
"name": "iOS11",
"size": 0.0390625
}]
}]
}
flareGraph('#flare', {
width: 600,
height: 400,
radius: 400
}, nodes); // update graph
body>svg {
position: absolute;
top: -80px;
left: -160px;
}
text {
font-size: 11px;
pointer-events: none;
}
text.parent {
fill: blue;
}
circle {
fill: #ddd;
stroke: #999;
pointer-events: all;
}
circle.parent {
fill: lightblue;
fill-opacity: .1;
stroke: gray;
}
circle.parent:hover {
stroke: #ff7f0e;
stroke-width: .5px;
}
circle.child {
pointer-events: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<div id="flare" />
最佳答案
您告诉所有文本标签显示在相同的 x 和 y 位置,所以它们当然是重叠的。您需要根据标签代码是否有子项来更新条件位置的标签代码。
.attr("y", function(d) {
return d.children? y(d.y): y(d.y+10);
})
var flareGraph = function(containerId, options, json) {
options.width = options.width || 1280; // circle width
options.height = options.height || 800; // circle height
options.radius = options.radius || 720; // circle radius
var w = options.width,
h = options.height,
r = options.radius,
x = d3.scale.linear().range([0, r]),
y = d3.scale.linear().range([0, r]),
node,
root;
var pack = d3.layout.pack()
.size([r, r])
.value(function(d) {
return d.size;
})
var vis = d3.select(containerId).insert("svg:svg", "h2")
.attr("width", w)
.attr("height", h)
.append("svg:g")
.attr("transform", "translate(" + (w - r) / 2 + "," + (h - r) / 2 + ")");
function zoom(d, i) {
var k = r / d.r / 2;
x.domain([d.x - d.r, d.x + d.r]);
y.domain([d.y - d.r, d.y + d.r]);
var t = vis.transition()
.duration(d3.event.altKey ? 7500 : 750);
t.selectAll("circle")
.attr("cx", function(d) {
return x(d.x);
})
.attr("cy", function(d) {
return y(d.y);
})
.attr("r", function(d) {
return k * d.r;
});
t.selectAll("text")
.attr("x", function(d) {
return x(d.x);
})
.attr("y", function(d) {
return d.children? y(d.y): y(d.y+10);
})
.style("opacity", function(d) {
return k * d.r > 20 ? 1 : 0;
});
node = d;
d3.event.stopPropagation();
} //zoom
node = root = json;
var nodes = pack.nodes(root);
vis.selectAll("circle")
.data(nodes)
.enter().append("svg:circle")
.attr("class", function(d) {
return d.children ? "parent" : "child";
})
.attr("cx", function(d) {
return d.x;
})
.attr("cy", function(d) {
return d.y;
})
.attr("r", function(d) {
return d.r;
})
.on("click", function(d) {
return zoom(node == d ? root : d);
});
vis.selectAll("text")
.data(nodes)
.enter().append("svg:text")
.attr("class", function(d) {
return d.children ? "parent" : "child";
})
.attr("x", function(d) {
return d.x;
})
.attr("y", function(d) {
return d.children? d.y : d.y+10;
})
.attr("dy", ".35em")
.attr("text-anchor", "middle")
.style("opacity", function(d) {
return d.r > 20 ? 1 : 0;
})
.text(function(d) {
return d.name;
});
d3.select(window).on("click", function() {
zoom(root);
});
} //displayFlareGraph
var nodes = {
"name": "TYPES",
"children": [{
"name": "TYPE #iPhone",
"children": [{
"name": "iPhone6",
"size": 0.109375
}]
}, {
"name": "TYPE #OS",
"children": [{
"name": "macOS",
"size": 0.140625
}]
}, {
"name": "Info #Android",
"children": [{
"name": "Marshmellow",
"size": 0.11467116357504215
}, {
"name": "Lollipop",
"size": 0.12228604553119728
}, {
"name": "Nougat",
"size": 0.028667790893760536
}]
}, {
"name": "TYPE #Laptop",
"children": [{
"name": "MacbookPro",
"size": 0.14062499999999997
}, {
"name": "Macbook",
"size": 0.0703125
}, {
"name": "Surface",
"size": 0.0703125
}]
}, {
"name": "TYPE #Browser",
"children": [{
"name": "Firefox",
"size": 0.109375
}]
}, {
"name": "Info #iOS",
"children": [{
"name": "iOS11",
"size": 0.0390625
}]
}]
}
flareGraph('#flare', {
width: 600,
height: 400,
radius: 400
}, nodes); // update graph
body>svg {
position: absolute;
top: -80px;
left: -160px;
}
text {
font-size: 11px;
pointer-events: none;
}
text.parent {
fill: blue;
}
circle {
fill: #ddd;
stroke: #999;
pointer-events: all;
}
circle.parent {
fill: lightblue;
fill-opacity: .1;
stroke: gray;
}
circle.parent:hover {
stroke: #ff7f0e;
stroke-width: .5px;
}
circle.child {
pointer-events: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<div id="flare" />
关于javascript - D3 : Render Flare Graph Titles avoiding text overlap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49757785/
所以我正在做一个Java作业,我必须创建一个矩形类,该类在一个绘制重叠矩形的程序中使用,并且在矩形重叠的地方,用新的颜色绘制一个新的矩形。我添加了硬件描述的链接,因为我认为让您查看它比我试图解释它更容
如何将两个重叠的 div 加上第三个 div 放在那些重叠的 div 的右侧(但第三个 div 没有一直 float )? I overlap id=two. I overlap id=one. I
我需要你的帮助,我有一个问题(见图),我假设有两个数组,每个数组都包含不同长度和实际值的间隔,我需要找出我如何有效地重叠这些间隔。 我对想法、论文理论或具体算法持开放态度,它们会让我找到出路! 我猜想
尝试编写一个从聚合数据返回气泡图的函数。 我将“agg”中的 data.frame 列传递给它。 aggs2 9) } ##order data.frame by mean agg1 <
我正在使用 d3.js 以这种方式生成一些直接位于彼此上方的矩形: var greenRed = d3.select(".green-red").append("svg") .attr("he
我正在尝试创建一个库,它提供一个简单的链表实现以及该链表的一些概括,例如堆栈和队列,所有这些都基于基本链表。 问题是,我希望拥有具有自己的“私有(private)”函数的不同类型,这样您就不会使用“s
我使用 AJAX 和 JQuery 从 MySQL 数据库中提取数据,基本上使用以下内容: function getCard(card, lineNr, linedisplay, type){ var
如何在 SQL OVERLAPS 中包含开始日期和结束日期? 喜欢=。怎么办? 因为在我看来 OVERLAPS 只检查两者之间的范围,但是例如: 日期 2001 年 1 月 1 日 - 2001 年
我在使用在 Google Web Fonts 上找到的字体时遇到了一些问题. 正如您在下面发布的图片中看到的,当我使用 Firefox 时,“Versus”中的大写 V 与“e”重叠。尽管当我使用 C
题目地址:https://leetcode.com/problems/image-overlap/description/ 题目描述 Twoimages A and B are given, re
题目地址:https://leetcode.com/problems/rectangle-overlap/description/ 题目描述: Arectangle is represented
在我们的测试环境中,我们的 solr 搜索引擎一直存在许多问题。我们在 4.6 版、单分片、4 个节点上有一个 solr 云设置。我们看到领导节点上的 CPU 水平线达到 100% 几个小时,然后服务
我正在做一个 excel 任务,我必须找出是否有重叠的日期。 在我的 excel 工作表中有 startDate(column D) 和 EndDate(comun E) 的列,由此我必须确定是否存在
在这张图片中,一个全景项目的内容渗透到前一个项目上: 如何在 Expression Blend/with XAML 中执行此操作? 这是我目前的 XAML:
我已经以编程方式创建了一个 iPhone UI,但我只是不知道如何调整 View ,以免它被 TabBar 重叠。这是所有权层次结构: -AppDelegate UITabBarController
我正在使用 wxMaxima 16.12.0 (Maxima 5.39.0),当我尝试打印输出时,出现重叠文本。 这是一个例子(请忽略命令不正确的事实) 第一张图片 有时也会发生在 print和 pr
我尝试为 javascript 添加一些语法高亮到 vim,但我一直遇到一个问题:当字符已经高亮时,它们似乎被所有其他正则表达式完全忽略。 例如,我尝试为函数的参数列表添加语法高亮显示。在创建正确的
我有五个 ImageView(ImageButton),我想将其显示在一行上,但是当我在小型设备上时,我的最后一个图像被裁剪了? 我该如何修复它? 有没有办法检测屏幕宽度? |一个 |乙| C | d
我尝试为 javascript 添加一些语法高亮到 vim,但我一直遇到一个问题:当字符已经高亮时,它们似乎被所有其他正则表达式完全忽略。 例如,我尝试为函数的参数列表添加语法高亮显示。在创建正确的
我将用数学解释,这是我正在努力为以下内容编写 Scheme 代码的转换: (f '(a b c) '(d e f)) = '(ad (+ bd ae) (+ cd be af) (+ ce bf) c
我是一名优秀的程序员,十分优秀!