title: Error using d3.format in d3-legend when upgrading from D3 v3 to v5
body: <p>I'm in the process of upgrading a visualisation from D3 v3 to v5.</p>
  
  <p>I've been using <a href="https://d3-legend.susielu.com/" rel="nofollow noreferrer">d3-legend</a> to draw the legend, so I've also changed which version of d3-legend I'm using, from v1.13.0 (the latest version compatible with D3 v3) to v2.25.6.</p>
  
  <p>I previously used <code>d3.format</code> together with d3-legend's <code>labelFormat</code> to format the legend text labels - applying different formatting depending which dataset had been loaded. The code which was working for me in D3 v3 isn't working for me in v5 and I can't figure out why.</p>
  
  <p>My code (D3 v5 version):</p>
  
  <pre><code>var value = 'ks4prog'
  
  var quantize=d3.scaleQuantize()
  
  quantize.domain([-0.8,0.8])
      .range(["rgb(230,0,126)", "rgb(207,21,138)","rgb(184,43,151)"])
  
  d3.legendColor()
      .shapeWidth(30)
      .orient('vertical')
      .scale(quantize)
      .labelFormat(function(d) {
          if (value=="ks2att" || value=="ks4basics") {
              return d3.format(".0f")(d) + "%";
          }
          else {
              return d3.format(".1f")(d);
          }
      });
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Uncaught Error: invalid format: function(d) {
          if (value=="ks2att" || value=="ks4basics") {
              return d3.format(".0f")(d) + "%";
          }
          else {
              return d3.format(".1f")(d);
          }
      }
      at new FormatSpecifier (d3-format.js:111)
      at formatSpecifier (d3-format.js:107)
      at Function.legend.labelFormat (color.js:233)
      at collapsibletree_edited.js:12
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/18474620/d3-js-tickformat-adding-a-sign-without-multiplying-by-100">This answer</a> led me to think I might need to change the format of the function I use to set <code>.labelFormat</code> - but I can't figure out how, in a case like mine where I'm setting <code>.labelFormat</code> conditionally.</p>