<commit_before>import {select as d3Select} from "d3-selection";
import {transition as d3Transition} from "d3-transition";
import {max as d3Max, min as d3Min, sum as d3Sum} from "d3-array";
const d3 = {
  "max": d3Max,
  "min": d3Min,
  "select": d3Select,
  "sum": d3Sum,
  "transition": d3Transition
};

import {constant} from "d3plus-common";
import {default as boxSplit} from "./split";
import {default as measure} from "./width";
import {default as wrap} from "./wrap";

/**
    The default height accessor function.
    @private
*/
function boxHeight(d) {
  return d.height || 200;
}

/**
    The default id accessor function.
    @private
*/
function boxId(d, i) {
  return d.id || `${i}`;
}

/**
    The default text accessor function.
    @private
*/
function boxText(d) {
  return d.text;
}

/**
    The default width accessor function.
    @private
*/
function boxWidth(d) {
  return d.width || 200;
}

/**
    The default x accessor function.
    @private
*/
function boxX(d) {
  return d.x || 0;
}

/**
    The default y accessor function.
    @private
*/
function boxY(d) {
  return d.y || 0;
}


/**
    @function box
    @desc Creates a wrapped text box based on an array of data. If *data* is specified, immediately wraps the text based on the specified array and returns this generator. If *data* is not specified on instantiation, it can be passed/updated after instantiation using the [data](#box.data) method.
    @param {Array} [data = []]
    @example <caption>a sample row of data</caption>
var data = {"text": "Hello D3plus, please wrap this sentence for me."};
@example <caption>passed to the generator</caption>
box([data]);
@example <caption>creates the following</caption>
<text class="d3plus-text-box" id="d3plus-text-box-0" text-anchor="start" font-family="Helvetica Neue" font-size="16px" transform="translate(0,-3.6)">
  <tspan dominant-baseline="alphabetic" opacity="1" x="0px" dx="0px" dy="18px" style="baseline-shift: 0%;">
    Hello D3plus, please wrap
  </tspan>
  <tspan dominant-baseline="alphabetic" opacity="1" x="0px" dx="0px" dy="18px" style="baseline-shift: 0%;">
    this sentence for me.
  </tspan>
</text>
@example <caption>this is shorthand for the following</caption>
box().data([data])();
@example <caption>which also allows a post-draw callback function</caption>
box().data([data])(function() { alert("draw complete!"); })
*/
export default function(data = []) {

  /**
      The default ellipsis function.
      @private
  */
  function boxEllipsis(_) {
    return `${_}...`;
  }

  let delay = 0,
      duration = 0,
      ellipsis = boxEllipsis,
      fontColor,
      fontFamily = constant("sans-serif"),
      fontMax = constant(50),
      fontMin = constant(8),
      fontResize = constant(false),
      fontSize = constant(10),
      height = boxHeight,
      id = boxId,
      lineHeight,
      overflow = constant(false),
      select,
      split = boxSplit,
      text = boxText,
      textAnchor = constant("start"),
      verticalAlign = constant("top"),
      width = boxWidth,
      x = boxX,
      y = boxY;

  /**
      The inner return object and draw function that gets assigned the public methods.
      @private
  */
  function box(callback) {

    if (select === void 0) box.select(d3.select("body").append("svg").style("width", `${window.innerWidth}px`).style("height", `${window.innerHeight}px`).node());
    if (lineHeight === void 0) lineHeight = (d, i) => fontSize(d, i) * 1.1;

    const boxes = select.selectAll(".d3plus-text-box").data(data, id);

    boxes.exit().transition().delay(duration).remove();

    boxes.exit().selectAll("tspan").transition().duration(duration)
      .attr("opacity", 0);

    boxes.enter().append("text")
        .attr("class", "d3plus-text-box")
        .attr("id", (d, i) => `d3plus-text-box-${id(d, i)}`)<commit_msg>uses accessor shorthand from d3plus-common<commit_after>import {select as d3Select} from "d3-selection";
import {transition as d3Transition} from "d3-transition";
import {max as d3Max, min as d3Min, sum as d3Sum} from "d3-array";
const d3 = {
  "max": d3Max,
  "min": d3Min,
  "select": d3Select,
  "sum": d3Sum,
  "transition": d3Transition
};

import {accessor, constant} from "d3plus-common";
import {default as boxSplit} from "./split";
import {default as measure} from "./width";
import {default as wrap} from "./wrap";

/**
    The default height accessor function.
    @private
*/
function boxHeight(d) {
  return d.height || 200;
}

/**
    The default id accessor function.
    @private
*/
function boxId(d, i) {
  return d.id || `${i}`;
}

/**
    The default width accessor function.
    @private
*/
function boxWidth(d) {
  return d.width || 200;
}

/**
    The default x accessor function.
    @private
*/
function boxX(d) {
  return d.x || 0;
}

/**
    The default y accessor function.
    @private
*/
function boxY(d) {
  return d.y || 0;
}


/**
    @function box
    @desc Creates a wrapped text box based on an array of data. If *data* is specified, immediately wraps the text based on the specified array and returns this generator. If *data* is not specified on instantiation, it can be passed/updated after instantiation using the [data](#box.data) method.
    @param {Array} [data = []]
    @example <caption>a sample row of data</caption>
var data = {"text": "Hello D3plus, please wrap this sentence for me."};
@example <caption>passed to the generator</caption>
box([data]);
@example <caption>creates the following</caption>
<text class="d3plus-text-box" id="d3plus-text-box-0" text-anchor="start" font-family="Helvetica Neue" font-size="16px" transform="translate(0,-3.6)">
  <tspan dominant-baseline="alphabetic" opacity="1" x="0px" dx="0px" dy="18px" style="baseline-shift: 0%;">
    Hello D3plus, please wrap
  </tspan>
  <tspan dominant-baseline="alphabetic" opacity="1" x="0px" dx="0px" dy="18px" style="baseline-shift: 0%;">
    this sentence for me.
  </tspan>
</text>
@example <caption>this is shorthand for the following</caption>
box().data([data])();
@example <caption>which also allows a post-draw callback function</caption>
box().data([data])(function() { alert("draw complete!"); })
*/
export default function(data = []) {

  /**
      The default ellipsis function.
      @private
  */
  function boxEllipsis(_) {
    return `${_}...`;
  }

  let delay = 0,
      duration = 0,
      ellipsis = boxEllipsis,
      fontColor,
      fontFamily = constant("sans-serif"),
      fontMax = constant(50),
      fontMin = constant(8),
      fontResize = constant(false),
      fontSize = constant(10),
      height = boxHeight,
      id = boxId,
      lineHeight,
      overflow = constant(false),
      select,
      split = boxSplit,
      text = accessor("text"),
      textAnchor = constant("start"),
      verticalAlign = constant("top"),
      width = boxWidth,
      x = boxX,
      y = boxY;

  /**
      The inner return object and draw function that gets assigned the public methods.
      @private
  */
  function box(callback) {

    if (select === void 0) box.select(d3.select("body").append("svg").style("width", `${window.innerWidth}px`).style("height", `${window.innerHeight}px`).node());
    if (lineHeight === void 0) lineHeight = (d, i) => fontSize(d, i) * 1.1;

    const boxes = select.selectAll(".d3plus-text-box").data(data, id);

    boxes.exit().transition().delay(duration).remove();

    boxes.exit().selectAll("tspan").transition().duration(duration)
      .attr("opacity", 0);

    boxes.enter().append("text")
        .attr("class", "d3plus-text-box")
        .attr("id", (d, i) => `d3plus-text-box-${id(d, i)}`)
{'fraction_non_alphanumeric': 0.1613200105180121, 'fraction_numerical': 0.016171443597160138, 'mean_word_length': 3.432983682983683, 'pattern_counts': {'":': 12, '<': 35, '<?xml version=': 0, '>': 39, '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': '2787116', 'n_tokens_mistral': 2524, 'n_tokens_neox': 2450, 'n_words': 706}