function renderCohortLegend(map) {
    resetLegend(map);
    var opts = map.options;
    var legend = map.el.legend;
    var data = opts.fills.concat(opts.strokes).filter(function(d) { return d.inLegend; });
    var maxWidth = 0;
    var swatch = 20;
    var pad = 20;

    // Configure swatch rects:
    var swatches = legend.selectAll('rect').data(data);
    swatches.enter().append('rect');
    swatches.exit().remove();

    // Configure label texts:
    var labels = legend.selectAll('text').data(data);
    labels.enter().append('text');
    labels.exit().remove();

    // Set text for each label, then find maximum width label:
    labels
      .text(function(d) { return d.label; })
      .attr('style', 'font:'+opts.legend_font+';fill:'+opts.font_color)
      .each(function(d) {
        maxWidth = Math.max(maxWidth, this.getComputedTextLength());
      });

    // Calculate minimum allowed column width, then balance column count:
    maxWidth = Math.round(swatch + 10 + maxWidth + pad);
    var layout = columnLayout(data.length, maxWidth, opts.width * 0.66);

    // Layout swatches:
    swatches
      .each(function(d, i) {
        if (d.type === 'fill') {
          // Fill swatches:
          d3.select(this)
            .attr('x', layout.x(i))
            .attr('y', layout.y(i))
            .attr('width', swatch)
            .attr('height', swatch)
            .attr('style', 'fill:'+d.color);

        } else {
          // Stroke swatches:
          var stroke = d.size;

          d3.select(this)
            .attr('x', layout.x(i) + stroke/2)
            .attr('y', layout.y(i) + stroke/2)
            .attr('width', swatch - stroke)
            .attr('height', swatch - stroke)
            .attr('style', 'fill:none;stroke:'+ d.color +';stroke-width:'+stroke);
        }
      });

    // Layout labels:
    labels
      .each(function(d, i) {
        d3.select(this)
          .style('dominant-baseline', 'middle')
          .attr('x', swatch + 10 + layout.x(i))
          .attr('y', layout.y(i) + swatch * 0.6);
      });

    legend.attr('transform', 'translate(20,'+ map._y +')');

    map._y += layout.h() + pad;
  }
// Renders the cohort-color swatch grid & labels.
Renders the cohort-color swatch grid & labels.
Renders the cohort - color swatch grid & labels .
function renderCohortLegend(map) {
    resetLegend(map);
    var opts = map.options;
    var legend = map.el.legend;
    var data = opts.fills.concat(opts.strokes).filter(function(d) { return d.inLegend; });
    var maxWidth = 0;
    var swatch = 20;
    var pad = 20;
    var swatches = legend.selectAll('rect').data(data);
    swatches.enter().append('rect');
    swatches.exit().remove();
    var labels = legend.selectAll('text').data(data);
    labels.enter().append('text');
    labels.exit().remove();
    labels
      .text(function(d) { return d.label; })
      .attr('style', 'font:'+opts.legend_font+';fill:'+opts.font_color)
      .each(function(d) {
        maxWidth = Math.max(maxWidth, this.getComputedTextLength());
      });
    maxWidth = Math.round(swatch + 10 + maxWidth + pad);
    var layout = columnLayout(data.length, maxWidth, opts.width * 0.66);
    swatches
      .each(function(d, i) {
        if (d.type === 'fill') {
          d3.select(this)
            .attr('x', layout.x(i))
            .attr('y', layout.y(i))
            .attr('width', swatch)
            .attr('height', swatch)
            .attr('style', 'fill:'+d.color);
        } else {
          var stroke = d.size;
          d3.select(this)
            .attr('x', layout.x(i) + stroke/2)
            .attr('y', layout.y(i) + stroke/2)
            .attr('width', swatch - stroke)
            .attr('height', swatch - stroke)
            .attr('style', 'fill:none;stroke:'+ d.color +';stroke-width:'+stroke);
        }
      });
    labels
      .each(function(d, i) {
        d3.select(this)
          .style('dominant-baseline', 'middle')
          .attr('x', swatch + 10 + layout.x(i))
          .attr('y', layout.y(i) + swatch * 0.6);
      });
    legend.attr('transform', 'translate(20,'+ map._y +')');
    map._y += layout.h() + pad;
  }
function renderCohortLegend ( map ) { resetLegend ( map ) ; var opts = map . options ; var legend = map . el . legend ; var data = opts . fills . concat ( opts . strokes ) . filter ( function ( d ) { return d . inLegend ; } ) ; var maxWidth = 0 ; var swatch = 20 ; var pad = 20 ; var swatches = legend . selectAll ( 'rect' ) . data ( data ) ; swatches . enter ( ) . append ( 'rect' ) ; swatches . exit ( ) . remove ( ) ; var labels = legend . selectAll ( 'text' ) . data ( data ) ; labels . enter ( ) . append ( 'text' ) ; labels . exit ( ) . remove ( ) ; labels . text ( function ( d ) { return d . label ; } ) . attr ( 'style' , 'font:' + opts . legend_font + ';fill:' + opts . font_color ) . each ( function ( d ) { maxWidth = Math . max ( maxWidth , this . getComputedTextLength ( ) ) ; } ) ; maxWidth = Math . round ( swatch + 10 + maxWidth + pad ) ; var layout = columnLayout ( data . length , maxWidth , opts . width * 0.66 ) ; swatches . each ( function ( d , i ) { if ( d . type === 'fill' ) { d3 . select ( this ) . attr ( 'x' , layout . x ( i ) ) . attr ( 'y' , layout . y ( i ) ) . attr ( 'width' , swatch ) . attr ( 'height' , swatch ) . attr ( 'style' , 'fill:' + d . color ) ; } else { var stroke = d . size ; d3 . select ( this ) . attr ( 'x' , layout . x ( i ) + stroke / 2 ) . attr ( 'y' , layout . y ( i ) + stroke / 2 ) . attr ( 'width' , swatch - stroke ) . attr ( 'height' , swatch - stroke ) . attr ( 'style' , 'fill:none;stroke:' + d . color + ';stroke-width:' + stroke ) ; } } ) ; labels . each ( function ( d , i ) { d3 . select ( this ) . style ( 'dominant-baseline' , 'middle' ) . attr ( 'x' , swatch + 10 + layout . x ( i ) ) . attr ( 'y' , layout . y ( i ) + swatch * 0.6 ) ; } ) ; legend . attr ( 'transform' , 'translate(20,' + map . _y + ')' ) ; map . _y += layout . h ( ) + pad ; }
Renders the cohort-color swatch grid & labels.
Renders the cohort - color swatch grid & labels .
// Configure swatch rects: // Configure label texts: // Set text for each label, then find maximum width label: // Calculate minimum allowed column width, then balance column count: // Layout swatches: // Fill swatches: // Stroke swatches: // Layout labels: