<commit_before>import _ from "lodash";
import React, { PropTypes } from "react";
import Radium from "radium";
import { VictoryLabel } from "victory-label";
import { Chart } from "victory-util";

@Radium
export default class BarLabel extends React.Component {

  static propTypes = {
    position: PropTypes.object,
    horizontal: PropTypes.bool,
    style: PropTypes.object,
    data: PropTypes.object,
    labelText: PropTypes.string,
    labelComponent: PropTypes.any
  };

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

  getlabelPadding(props, style) {
    return {
      x: props.horizontal ? style.padding : 0,
      y: props.horizontal ? 0 : style.padding
    };
  }

  renderLabelComponent(props, position, anchors) {
    const component = props.labelComponent;
    const baseStyle = _.merge({padding: 0}, props.style, component.props.style);
    const style = Chart.evaluateStyle(baseStyle, props.data);
    const padding = this.getlabelPadding(props, style);
    const children = component.props.children || props.labelText;
    const newProps = {
      x: component.props.x || position.x + padding.x,
      y: component.props.y || position.y - padding.y,
      data: props.data, // Pass data for custom label component to access
      textAnchor: component.props.textAnchor || anchors.text,
      verticalAnchor: component.props.verticalAnchor || anchors.vertical,
      style
    };
    return React.cloneElement(component, newProps, children);
  }

  renderVictoryLabel(props, position, anchors) {
    const baseStyle = _.merge({padding: 0}, props.style);
    const style = Chart.evaluateStyle(baseStyle, props.data);
    const padding = this.getlabelPadding(props, style);
    return (
      <VictoryLabel
        x={position.x + padding.x}
        y={position.y - padding.y}
        data={props.data}
        textAnchor={anchors.text}
        verticalAnchor={anchors.vertical}
        style={style}
      >
        {props.labelText}<commit_msg>use lodash modules in bar-label<commit_after>import merge from "lodash/object/merge";
import React, { PropTypes } from "react";
import Radium from "radium";
import { VictoryLabel } from "victory-label";
import { Chart } from "victory-util";

@Radium
export default class BarLabel extends React.Component {

  static propTypes = {
    position: PropTypes.object,
    horizontal: PropTypes.bool,
    style: PropTypes.object,
    data: PropTypes.object,
    labelText: PropTypes.string,
    labelComponent: PropTypes.any
  };

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

  getlabelPadding(props, style) {
    return {
      x: props.horizontal ? style.padding : 0,
      y: props.horizontal ? 0 : style.padding
    };
  }

  renderLabelComponent(props, position, anchors) {
    const component = props.labelComponent;
    const baseStyle = merge({padding: 0}, props.style, component.props.style);
    const style = Chart.evaluateStyle(baseStyle, props.data);
    const padding = this.getlabelPadding(props, style);
    const children = component.props.children || props.labelText;
    const newProps = {
      x: component.props.x || position.x + padding.x,
      y: component.props.y || position.y - padding.y,
      data: props.data, // Pass data for custom label component to access
      textAnchor: component.props.textAnchor || anchors.text,
      verticalAnchor: component.props.verticalAnchor || anchors.vertical,
      style
    };
    return React.cloneElement(component, newProps, children);
  }

  renderVictoryLabel(props, position, anchors) {
    const baseStyle = merge({padding: 0}, props.style);
    const style = Chart.evaluateStyle(baseStyle, props.data);
    const padding = this.getlabelPadding(props, style);
    return (
      <VictoryLabel
        x={position.x + padding.x}
        y={position.y - padding.y}
        data={props.data}
        textAnchor={anchors.text}
        verticalAnchor={anchors.vertical}
        style={style}
      >
        {props.labelText}
{'fraction_non_alphanumeric': 0.12201650680347981, 'fraction_numerical': 0.004015168414008476, 'mean_word_length': 2.8655172413793104, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '95875', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1310, 'n_words': 324}