【问题标题】:How to control the thickness of lines in the Hierarchical Edge Bundling chart?如何控制 Hierarchical Edge Bundling 图表中线条的粗细?
【发布时间】:2016-12-31 13:35:24
【问题描述】:

是否可以增加/减少Hierarchical Edge Bundling 图表中线条的粗细?

例如,在输入数据中有一个size 定义,但我在图表中看不到它的效果。尺寸越大,是否可以制作更多“肥”线?

我添加了这行代码:

.attr('stroke-width', function(d) { return d.size; })

...为了根据输入数据文件readme-flare-imports.json 中的字段size 定义stroke-width。但是,它没有任何作用。

 link = link
      .data(bundle(links))
      .enter().append("path")
      .each(function(d) { d.source = d[0], d.target = d[d.length - 1]; })
      .attr("class", "link")
      .attr('stroke-width', function(d) { return d.size; })
      .attr("d", line);

【问题讨论】:

    标签: javascript css d3.js svg


    【解决方案1】:

    问题在于attr 函数中的datum 是该特定节点的所有链接的数组。

    因此,要仅获取源的size 值,它应该是:

    .attr("stroke-width", function(d){
        return d[0].size;
    })
    

    由于size 属性的数值很大,我使用了一个比例尺,其中宽度从1 到10:

    var sizeScale = d3.scale.linear()
        .domain([0, d3.max(classes, function(d){ return d.size})])
        .range([1, 10]);  
    
    link.attr("stroke-width", function(d){
        return sizeScale(d[0].size)
    })
    

    这是一个小提琴:https://jsfiddle.net/cad2m2ue/

    【讨论】:

    • 您有什么建议可以让这种图表更具信息性吗?也许颜色渐变会更好地定义厚度而不是仅使用宽度?或者也许 stroe 宽度应该是对数刻度?
    • 要根据size 的值更改颜色(除了厚度),我试过这个,但它似乎不起作用:var colors = ["#c7e9b4","#41b6c4","#1d91c0","#225ea8"]; var colorScale = d3.scale.threshold() .domain(0, d3.max(classes, function(d){ return d.size})]) .range(colors); link.attr("stroke", function(d){ return colorScale(d[0].size) });
    • @Dinosaurius,对于您的colorScale,您可能想要使用d3.scale.quantiled3.extent。此外,您需要设置笔划style(不是attr),因为您的css 已经定义了笔划样式-style is more specific then attr。看到这个更新fiddle
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-13
    • 2023-03-12
    • 1970-01-01
    • 2017-12-05
    • 1970-01-01
    • 2011-07-10
    • 1970-01-01
    相关资源
    最近更新 更多