<commit_before>import { defaults, omit } from "lodash";
import { Helpers, Events } from "victory-core";
import Data from "../../helpers/data";
import Domain from "../../helpers/domain";
import Scale from "../../helpers/scale";

export default {

  getScale(props) {
    const { horizontal } = props;
    const range = {
      x: Helpers.getRange(props, "x"),
      y: Helpers.getRange(props, "y")
    };
    const domain = {
      x: Domain.getDomainWithZero(props, "x"),
      y: Domain.getDomainWithZero(props, "y")
    };
    const xScale = Scale.getBaseScale(props, "x").domain(domain.x).range(range.x);
    const yScale = Scale.getBaseScale(props, "y").domain(domain.y).range(range.y);
    return {
      x: horizontal ? yScale : xScale,
      y: horizontal ? xScale : yScale
    };
  },

  getBarPosition(props, datum, scale) {
    const yOffset = datum.yOffset || 0;
    const xOffset = datum.xOffset || 0;
    const y0 = yOffset;
    const y = datum.y + yOffset;
    const x = datum.x + xOffset;
    const formatValue = (value, axis) => {
      return datum[axis] instanceof Date ? new Date(value) : value;
    };
    return {
      x: scale.x(formatValue(x, "x")),
      y0: scale.y(formatValue(y0, "y")),
      y: scale.y(formatValue(y, "y"))
    };
  },

  getBarStyle(datum, baseStyle) {
    const styleData = omit(datum, [
      "xName", "yName", "x", "y", "label"
    ]);
    return defaults({}, styleData, baseStyle);
  },

  getLabelStyle(style, datum) {
    const labelStyle = defaults({
      angle: datum.angle,
      textAnchor: datum.textAnchor,
      verticalAnchor: datum.verticalAnchor
    }, style);
    return Helpers.evaluateStyle(labelStyle, datum);
  },

  getLabel(props, datum, index) {
    const propsLabel = Array.isArray(props.labels) ?
      props.labels[index] : Helpers.evaluateProp(props.labels, datum);
    return datum.label || propsLabel;
  },

  getLabelAnchors(datum, horizontal) {
    const sign = datum.y >= 0 ? 1 : -1;
    if (!horizontal) {
      return {
        vertical: sign >= 0 ? "end" : "start",
        text: "middle"
      };
    } else {
      return {
        vertical: "middle",
        text: sign >= 0 ? "start" : "end"
      };
    }
  },

  getlabelPadding(style, horizontal) {
    const defaultPadding = style.padding || 0;
    return {
      x: horizontal ? defaultPadding : 0,
      y: horizontal ? 0 : defaultPadding
    };
  },

  getBaseProps(props, fallbackProps) {
    const defaultStyles = props.theme && props.theme.bar ? props.theme.bar
    : fallbackProps.style;
    const modifiedProps = Helpers.modifyProps(props, fallbackProps);
    const style = Helpers.getStyles(modifiedProps.style, defaultStyles, "auto", "100%");
    const data = Events.addEventKeys(modifiedProps, Data.getData(props));
    const scale = this.getScale(modifiedProps);
    const { horizontal, width, height } = modifiedProps;
    const parentProps = {scale, width, height, data, style: style.parent};

    return data.reduce((memo, datum, index) => {
      const eventKey = datum.eventKey;
      const position = this.getBarPosition(modifiedProps, datum, scale);
      const barStyle = this.getBarStyle(datum, style.data);
      const dataProps = Object.assign(
        {
          style: Helpers.evaluateStyle(barStyle, datum),
          index,
          datum,
          scale,
          horizontal
        },
        position
      );

      const text = this.getLabel(modifiedProps, datum, index);
      const labelPadding = style.labels.padding;
      const labelStyleObj = datum.y < 0 ? Object.assign({}, style.labels,
        {padding: labelPadding - 7}) : style.labels;
      const labelStyle = this.getLabelStyle(labelStyleObj, datum);
      const padding = this.getlabelPadding(labelStyle, horizontal);
      const anchors = this.getLabelAnchors(datum, horizontal);
      const labelPosition = {
        x: horizontal ? position.y : position.x,
        y: horizontal ? position.x : position.y
      };
      const labelProps = {
        style: labelStyle,
        x: labelPosition.x + padding.x,
        y: labelPosition.y - padding.y,<commit_msg>change padding based on existing padding<commit_after>import { defaults, omit } from "lodash";
import { Helpers, Events } from "victory-core";
import Data from "../../helpers/data";
import Domain from "../../helpers/domain";
import Scale from "../../helpers/scale";

export default {

  getScale(props) {
    const { horizontal } = props;
    const range = {
      x: Helpers.getRange(props, "x"),
      y: Helpers.getRange(props, "y")
    };
    const domain = {
      x: Domain.getDomainWithZero(props, "x"),
      y: Domain.getDomainWithZero(props, "y")
    };
    const xScale = Scale.getBaseScale(props, "x").domain(domain.x).range(range.x);
    const yScale = Scale.getBaseScale(props, "y").domain(domain.y).range(range.y);
    return {
      x: horizontal ? yScale : xScale,
      y: horizontal ? xScale : yScale
    };
  },

  getBarPosition(props, datum, scale) {
    const yOffset = datum.yOffset || 0;
    const xOffset = datum.xOffset || 0;
    const y0 = yOffset;
    const y = datum.y + yOffset;
    const x = datum.x + xOffset;
    const formatValue = (value, axis) => {
      return datum[axis] instanceof Date ? new Date(value) : value;
    };
    return {
      x: scale.x(formatValue(x, "x")),
      y0: scale.y(formatValue(y0, "y")),
      y: scale.y(formatValue(y, "y"))
    };
  },

  getBarStyle(datum, baseStyle) {
    const styleData = omit(datum, [
      "xName", "yName", "x", "y", "label"
    ]);
    return defaults({}, styleData, baseStyle);
  },

  getLabelStyle(style, datum) {
    const labelStyle = defaults({
      angle: datum.angle,
      textAnchor: datum.textAnchor,
      verticalAnchor: datum.verticalAnchor
    }, style);
    return Helpers.evaluateStyle(labelStyle, datum);
  },

  getLabel(props, datum, index) {
    const propsLabel = Array.isArray(props.labels) ?
      props.labels[index] : Helpers.evaluateProp(props.labels, datum);
    return datum.label || propsLabel;
  },

  getLabelAnchors(datum, horizontal) {
    const sign = datum.y >= 0 ? 1 : -1;
    if (!horizontal) {
      return {
        vertical: sign >= 0 ? "end" : "start",
        text: "middle"
      };
    } else {
      return {
        vertical: "middle",
        text: sign >= 0 ? "start" : "end"
      };
    }
  },

  getlabelPadding(style, horizontal) {
    const defaultPadding = style.padding || 0;
    return {
      x: horizontal ? defaultPadding : 0,
      y: horizontal ? 0 : defaultPadding
    };
  },

  getBaseProps(props, fallbackProps) {
    const defaultStyles = props.theme && props.theme.bar ? props.theme.bar
    : fallbackProps.style;
    const modifiedProps = Helpers.modifyProps(props, fallbackProps);
    const style = Helpers.getStyles(modifiedProps.style, defaultStyles, "auto", "100%");
    const data = Events.addEventKeys(modifiedProps, Data.getData(props));
    const scale = this.getScale(modifiedProps);
    const { horizontal, width, height } = modifiedProps;
    const parentProps = {scale, width, height, data, style: style.parent};

    return data.reduce((memo, datum, index) => {
      const eventKey = datum.eventKey;
      const position = this.getBarPosition(modifiedProps, datum, scale);
      const barStyle = this.getBarStyle(datum, style.data);
      const dataProps = Object.assign(
        {
          style: Helpers.evaluateStyle(barStyle, datum),
          index,
          datum,
          scale,
          horizontal
        },
        position
      );

      const text = this.getLabel(modifiedProps, datum, index);
      const labelPadding = style.labels.padding;
      const labelStyleObj = datum.y < 0 ? Object.assign({}, style.labels,
        {padding: labelPadding * -Math.abs(labelPadding / 2.5)}) : style.labels;
      const labelStyle = this.getLabelStyle(labelStyleObj, datum);
      const padding = this.getlabelPadding(labelStyle, horizontal);
      const anchors = this.getLabelAnchors(datum, horizontal);
      const labelPosition = {
        x: horizontal ? position.y : position.x,
        y: horizontal ? position.x : position.y
      };
      const labelProps = {
        style: labelStyle,
        x: labelPosition.x + padding.x,
        y: labelPosition.y - padding.y,
{'fraction_non_alphanumeric': 0.13575317604355716, 'fraction_numerical': 0.004476709013914095, 'mean_word_length': 2.735201084500678, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3303923', 'n_tokens_mistral': 2617, 'n_tokens_neox': 2563, 'n_words': 609}