- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想为 d3 map 中的每个社区添加一个社区名称。
我在这段代码中使用了 centroid() 函数。
var mapLabel = svg.selectAll("text")
.data(json)
.enter()
.append("text")
.text(function (d) {
return d.properties.nhood;
})
.attr('transform', function (d) {
return 'translate(' + path.centroid(d) + ')';
})
.attr('font-size', '6pt');
它将每个社区的名称放在远离中心的位置。
我尝试过 this代码也。
function addText(p)
{
var t = document.createElementNS("http://www.w3.org/2000/svg", "text");
var b = p.getBBox();
t.textContent = "a";
t.setAttribute("transform", "translate(" + (b.x + b.width/2) + " " + (b.y + b.height/2) + ")");
t.setAttribute("fill", "red");
t.setAttribute("font-size", "14");
p.parentNode.insertBefore(t, p.nextSibling);
}
var paths = document.querySelectorAll("path");
for (var p in paths)
{
addText(paths[p])
}
该代码可以将文本添加到每个 SVG 的中心,但我不知道如何让它为每个邻域添加自定义文本。相反,我得到了四十一次“a”。
我也尝试过 getBBox() 。我无法访问该函数,遇到了 getBBox() is not a function
错误。
这是创建 map 的代码部分。
var projection = d3.geoIdentity()
.reflectY(true)
.fitSize([w, h], jsonClone)
var pathFlipped = d3.geoPath()
.projection(projection);
const mapSelection = svg.selectAll("path")
.data(json)
mapSelection
.enter()
.append("path")
.attr("d", pathFlipped)
.style("fill", "lightgrey")
var mapLabel = svg.selectAll("text")
.data(json)
.enter()
.append("text")
.text(function (d) {
return d.properties.nhood;
})
.attr('transform', function (d) {
return 'translate(' + path.centroid(d) + ')';
})
.attr('font-size', '6pt');
这是 full map 的演示.
最佳答案
您需要对文本使用与路径相同的投影
.attr('transform', function(d) { return 'translate(' + pathFlipped.centroid(d) + ')'; })
关于javascript - 无法使用 path.centroid() 找到路径对象的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54822369/
我想计算存储为位压缩整数数组的位图(黑白)的质心。我知道有一些快速算法可以计算整数中设置位的数量,但这并不能帮助我计算质心。有什么想法吗? 举个例子,如果我的位图是这样的: 111000 111000
我想为 d3 map 中的每个社区添加一个社区名称。 我在这段代码中使用了 centroid() 函数。 var mapLabel = svg.selectAll("text") .data(
我需要获取 质心 (质心)用于一组具有亚像素精度的二值图像中的组件。 Mathematica 8 附带了一个很好的补充: i = Import@"http://i.stack.imgur.com/2
通过邮政编码质心进行地理编码,但是是否有一个 zip+4 质心,它会更细化但不完全是街道地址粒度? 最佳答案 就在这里。我在 SmartyStreets 工作,我们在这里验证和地理编码街道地址。 ZI
System.Windows.Shapes.Shape 命名空间提供对可在 XAML 或代码中使用的 Polygon 对象的访问。 是否有 Microsoft 库提供一些非常基本的多边形计算,例如面积
如何找到从质心到每个簇中所有数据点的平均距离。我能够从每个簇的质心找到每个点(在我的数据集中)的欧氏距离。现在我想找到从质心到每个集群中所有数据点的平均距离。计算与每个质心的平均距离的好方法是什么?到
此代码是我用于 silhouette_score 的代码. 在这里我使用凝聚聚类,链接作为病房。 我想获得凝聚聚类的“质心”,从凝聚聚类中可以获得吗?我只能得到 K 均值的质心和模糊 c 均值。 df
所以,最近我开始尝试使用 D3 library .我已经成功制作了一个有效的和弦图,here's the pen . var parentSelector = '#con1' var width =
我有一个多边形(在 Shapely 对象中转换)。我的目标是按照图形示例计算“内部质心”(也称为“表面上的点”)(返回 x、y 值)和“质心”(返回 x、y 值): from shapely.geom
我正在训练一种需要对数据点进行集群的无监督学习模型。现在,出于验证目的,我拥有每个类的数据点的平均值,并且我需要将每个数据点分配到不同的类。。假设我有4个班级,每个班级A、B、C、D和质心1、2、3、
公平警告:我是这里的 D3 新手。我正在使用 D3 构建一个 donut chart ,到目前为止一切都很好,除了切片上的标签没有与切片对齐。使用下面的代码,每个切片的标签都呈现在图表的中间,彼此堆叠
当使用 scipy.spatial.distance.pdist 创建压缩距离矩阵并将其传递给 ward 时,出现此错误: Valid methods when the raw observation
问题是我无法用现有代码实现质心,在检测到的对象被矩形包围后使用哪个图像对象等,这样我就可以获得路径的轨迹。 我正在使用 Opencv2.3 。我发现有两种方法 - Link1和 Link2谈谈mome
我有一个基于谷歌地图的程序,可以根据用户输入计算面积。这里是 Demo JSFiddle HTML 应该是这样的 Length (red line): 0 mt - Area (gr
我已经用 Java 实现了整个模糊逻辑系统,但我在去模糊化过程中遇到了严重的问题。 在我的代码中,我将输入定义为时间和距离,输出只是输出。我拥有构造输入和输出集的每个线性函数,因此我可以访问它的任何值
我一直在使用 scipy.cluster.vq.kmeans 进行一些 k 均值聚类,但想知道是否有一种方法可以确定每个数据点是哪个质心(假定)与相关联。 显然您可以手动执行此操作,但据我所知,kme
Sci-Kit学习Kmeans和PCA降维 我有一个 200 万行 x 7 列的数据集,其中包含不同的家庭用电量测量值以及每个测量值的日期。 日期, Global_active_power, Glob
我正在创建一个 donut (或饼图),并且我想将标签放置在该区域之外。我创建了一个 fiddle http://jsfiddle.net/VeeTee/mA3V7/为它。 arcs.append("
我正在尝试使用 centroid() 函数将圆弧标签居中,如 D3 documentation 中所述. arcs.append("text") .attr("transform", function
我正在编写一个用于 K 均值聚类的程序,以找到每个点应属于的聚类。此代码有 8 个点和 3 个簇。在我的代码中,“条目”函数以某种方式无限执行。我找不到哪里出错了。这是我遵循的逻辑: 8个点的硬编码输
我是一名优秀的程序员,十分优秀!