【问题标题】:D3 Fisheye Distortion on simple Scatter plot简单散点图上的 D3 鱼眼失真
【发布时间】:2014-05-01 12:12:26
【问题描述】:

我正在尝试在一个简单的散点图上实现 d3 鱼眼失真 (http://bost.ocks.org/mike/fisheye/)。

这里是我到目前为止的代码: http://plnkr.co/edit/yDWld6?p=preview

我很不确定我应该如何称呼圆圈为失真。目前它看起来像这样,但到目前为止“mousemove”没有任何反应。

svg.on("mousemove", function() {
  fisheye.center(d3.mouse(this));

  circles
    .selectAll("circle")
    .each(function (d) { d.fisheye = fisheye(d); })
    .attr("cx", function (d) { return d.fisheye.pages })
    .attr("cy", function (d) { return d.fisheye.books });
});

感谢您的帮助!

【问题讨论】:

    标签: javascript d3.js scatter-plot fisheye


    【解决方案1】:

    您必须为鱼眼插件准备数据:

    var circles = svg.selectAll("circle")
        .data(data)
      .enter()
      .append("circle")
        .datum( function(d) {
            return {x: d.pages, y: d.books} // change data, to feed to the fisheye plugin
        })
        .attr("cx", function (d) {return d.x}) // changed data can be used here as well
        .attr("cy", function (d) {return d.y}) // ...and here
        .attr("r", 2);
    
    ...
    
    // now we can pass in the d.x and d.y values expected by the fisheye plugin...
    circles.each(function(d) { d.fisheye = fisheye(d); })
        .attr("cx", function(d) { return d.fisheye.x; })
        .attr("cy", function(d) { return d.fisheye.y; })
        .attr("r", function(d) { return d.fisheye.z * 2; });
    });
    

    我还根据我在下面链接的plunk中使用的插件的最新official version对鱼眼的声明进行了更改。

    所以,这是一个PLUNK,散点图应用了鱼眼失真。

    【讨论】:

    • @kim YMW。我很乐意提供帮助。我查看了您的网站...关于血钱的重要工作,这是一个一直存在的大问题。干得好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    相关资源
    最近更新 更多