<commit_before>import helper from './legend';
import { dispatch } from 'd3-dispatch';
import { scaleLinear } from 'd3-scale';
import { format } from 'd3-format';
import { sum } from 'd3-array';

export default function color(){

  var scale = scaleLinear(),
    shape = "rect",
    shapeWidth = 15,
    shapeHeight = 15,
    shapeRadius = 10,
    shapePadding = 2,
    cells = [5],
    labels = [],
    classPrefix = "",
    useClass = false,
    title = "",
    labelFormat = format(".01f"),
    labelOffset = 10,
    labelAlign = "middle",
    labelDelimiter = "to",
    orient = "vertical",
    ascending = false,
    path,
    legendDispatcher = dispatch("cellover", "cellout", "cellclick");

    function legend(svg){

      var type = helper.d3_calcType(scale, ascending, cells, labels, labelFormat, labelDelimiter),
        legendG = svg.selectAll('g').data([scale]);

      legendG.enter().append('g').attr('class', classPrefix + 'legendCells');

      var cell = svg.select('.' + classPrefix + 'legendCells')
          .selectAll("." + classPrefix + "cell").data(type.data),
        cellEnter = cell.enter().append("g")
          .attr("class", classPrefix + "cell"),//.merge(cell).style("opacity", 1e-6),
        shapeEnter = cellEnter.append(shape).attr("class", classPrefix + "swatch"),
        shapes = svg.selectAll("g." + classPrefix + "cell " + shape);

      //add event handlers
      helper.d3_addEvents(cellEnter, legendDispatcher);

      cell.exit().transition().style("opacity", 0).remove();

      helper.d3_drawShapes(shape, shapes, shapeHeight, shapeWidth, shapeRadius, path);


      helper.d3_addText( svg, cellEnter, type.labels, classPrefix)
      
      // we need to merge the selection, otherwise changes in the legend (e.g. change of orientation) are applied only to the new cells and not the existing ones.
      cell = cellEnter.merge(cell);

      // sets placement
      var text = svg.selectAll("g." + classPrefix + "cell text"),
        textSize = text.nodes().map( function(d){ return d.getBBox(); }),
        shapeSize = shapes.nodes().map( function(d){ return d.getBBox(); }),
        // Determine the width the cell needs to be to include the shape and text (for horizontal orientation)
        cellWidths = shapeSize.map( function(d, i){
          if (orient === "horizontal" && textSize[i].width > d.width) {
              return textSize[i].width
          } else {
              d.width;
          }
        });

      //sets scale
      //everything is fill except for line which is stroke,
      if (!useClass){
        if (shape == "line"){
          shapes.style("stroke", type.feature);<commit_msg>Fixed missing return when the shape is wider than the text<commit_after>import helper from './legend';
import { dispatch } from 'd3-dispatch';
import { scaleLinear } from 'd3-scale';
import { format } from 'd3-format';
import { sum } from 'd3-array';

export default function color(){

  var scale = scaleLinear(),
    shape = "rect",
    shapeWidth = 15,
    shapeHeight = 15,
    shapeRadius = 10,
    shapePadding = 2,
    cells = [5],
    labels = [],
    classPrefix = "",
    useClass = false,
    title = "",
    labelFormat = format(".01f"),
    labelOffset = 10,
    labelAlign = "middle",
    labelDelimiter = "to",
    orient = "vertical",
    ascending = false,
    path,
    legendDispatcher = dispatch("cellover", "cellout", "cellclick");

    function legend(svg){

      var type = helper.d3_calcType(scale, ascending, cells, labels, labelFormat, labelDelimiter),
        legendG = svg.selectAll('g').data([scale]);

      legendG.enter().append('g').attr('class', classPrefix + 'legendCells');

      var cell = svg.select('.' + classPrefix + 'legendCells')
          .selectAll("." + classPrefix + "cell").data(type.data),
        cellEnter = cell.enter().append("g")
          .attr("class", classPrefix + "cell"),//.merge(cell).style("opacity", 1e-6),
        shapeEnter = cellEnter.append(shape).attr("class", classPrefix + "swatch"),
        shapes = svg.selectAll("g." + classPrefix + "cell " + shape);

      //add event handlers
      helper.d3_addEvents(cellEnter, legendDispatcher);

      cell.exit().transition().style("opacity", 0).remove();

      helper.d3_drawShapes(shape, shapes, shapeHeight, shapeWidth, shapeRadius, path);


      helper.d3_addText( svg, cellEnter, type.labels, classPrefix)
      
      // we need to merge the selection, otherwise changes in the legend (e.g. change of orientation) are applied only to the new cells and not the existing ones.
      cell = cellEnter.merge(cell);

      // sets placement
      var text = svg.selectAll("g." + classPrefix + "cell text"),
        textSize = text.nodes().map( function(d){ return d.getBBox(); }),
        shapeSize = shapes.nodes().map( function(d){ return d.getBBox(); }),
        // Determine the width the cell needs to be to include the shape and text (for horizontal orientation)
        cellWidths = shapeSize.map( function(d, i){
          if (orient === "horizontal" && textSize[i].width > d.width) {
              return textSize[i].width
          } else {
              return d.width;
          }
        });

      //sets scale
      //everything is fill except for line which is stroke,
      if (!useClass){
        if (shape == "line"){
          shapes.style("stroke", type.feature);
{'fraction_non_alphanumeric': 0.14643257377661562, 'fraction_numerical': 0.008591707134852447, 'mean_word_length': 2.7711267605633805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1297611', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1531, 'n_words': 434}