简体   繁体   中英

Exclude entities from Legend in Sankey Diagram

I have a Sankey chart with a beginning and end node. When I create a legend using the function below.

I would like to FILTER out particular nodes from the legend (the first and end nodes).

The node names will ALWAYS be the same, but as the number of nodes changes dynamically their index will be different.

Is this possible, or very complicated?

Can I apply a filter or exclusion function to the

 svg.selectAll('.legendOrdinal .cell') .attr('transform', function(d,i) { // make 2 column legend var row = Math.floor(i / items_in_row) * element[0].offsetWidth/2; return 'translate(' + row +',' + (i % items_in_row) * 21 + ')'; }) 

  function render_legend(nodes) { var items_in_row = Math.ceil(nodes.length/2); d3.select(element[0]).select('#legend').remove(); var svg = d3.select(element[0]) .append("svg") .attr('width', '100%') .attr('height', ((items_in_row+1) * 25) + 'px') .attr('id', 'legend'); var ordinal = d3.scale.ordinal() .domain(nodes.map(function(d) { return d.name; })) .range(color.range()); // append legend text if (nodes.length != 0) { svg.append('text') .attr('x', 15) .attr('y', 15) .text('Enabling infrastructure investments:'); }; svg.append("g") .attr("class", "legendOrdinal") .attr("transform", "translate(20, 40)"); var legendOrdinal = d3.legend.color() .shape("path", d3.svg.symbol().type("circle").size(200)()) .shapePadding(5) .scale(ordinal); svg.select(".legendOrdinal") .call(legendOrdinal); svg.selectAll('.legendOrdinal .cell') .attr('transform', function(d,i) { // make 2 column legend var row = Math.floor(i / items_in_row) * element[0].offsetWidth/2; return 'translate(' + row +',' + (i % items_in_row) * 21 + ')'; }) }; 

Can you apply filtering to the domain call?

.domain(nodes.filter(function(d, i) {return i > 0 && i < N - 1; /*or anything else */})
             .map(function(d) {
                    return d.name;
                }))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM