Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use svg:defs to create rect with same height in d3.js?
    primarykey
    data
    text
    <p>I am working on a d3.js project where I am displaying a number of rectangles to be the same height. The rectangles are connected to a <code>input[type=number]</code> that adjust the height of each group of rectangles. To make animation easier (so I only have to manipulate the <code>svg:defs</code> onchange of the number input), I would like to be able to specify the height of a group of rectangles with a <code>svg:def</code> tag like this:</p> <pre class="lang-js prettyprint-override"><code>var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500); svg.append("defs").selectAll(".rectdef") .data(data).enter() .append("rect") .attr("class", "rectdef") .attr("id", function (d, i){return "rect" + d.name;}) .attr("x", 0) // overridden below .attr("width", 0) // overridden below .attr("y", 0) // overridden below .attr("height", function (d, i){return d.height}); </code></pre> <p>and then to be able to just refine placement x, y and width of the rectangles with something like this:</p> <pre class="lang-js prettyprint-override"><code>svg.selectAll(".bar") .data(data).enter() .append("use") .attr("class", "bar") .attr("xlink:href",function (d){return "#rect"+d.type;}) .attr("x", function(d) { return d.x }) .attr("width", function (d) {return d.w;}) // this does NOT adjust width! .attr("y", function (d) {return 0;}); </code></pre> <p>This snippet correctly changes the x and y coordinates but it does not properly change the width! Any ideas what's wrong here? Is this a browser issue (I'm using Chrome 24.0.1312.52)? Is width not editable like this on an svg:use tag?</p> <p>There aren't any problems with the data (I've checked that) and I have been able to confirm that the animation does work correctly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload