<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import {
  ReferenceArea,
  XAxis,
  YAxis,
  Tooltip,
  Line,
  LineChart,
  CartesianGrid,
  ReferenceLine,
  Legend,
  ResponsiveContainer,
} from 'recharts';
import heroes from 'dotaconstants/build/heroes.json';
import playerColors from 'dotaconstants/build/player_colors.json';
import Heading from '../../Heading';
import constants from '../../constants';
import { StyledTooltip, StyledTooltipTeam, StyledRadiant, StyledDire, StyledHolder, GoldSpan, XpSpan, StyledTooltipGold, StyledCustomizedTooltip } from './Styled';

const formatGraphTime = minutes => `${minutes}:00`;

const generateDiffData = (match) => {
  const radiantGoldAdv = match.radiant_gold_adv;
  const radiantXpAdv = match.radiant_xp_adv;
  const data = [];
  radiantXpAdv.forEach((rXpAdv, index) => {
    if (index <= Math.floor(match.duration / 60)) {
      data.push({ time: index, rXpAdv, rGoldAdv: radiantGoldAdv[index] });
    }
  });
  return data;
};

const CustomizedTooltip = ({ label, payload }) => (
  <StyledCustomizedTooltip>
    <div className="label">{label}</div>
    {payload.map((data, i) => (
      <div value={data.value} className={`data ${i < 5 && 'isRadiant'}`} style={{ borderLeft: `8px solid ${data.color}` }}>
        {data.dataKey}: {data.value}
      </div>)).sort((a, b) => b.props.value - a.props.value)
    }
  </StyledCustomizedTooltip>
);
CustomizedTooltip.propTypes = {
  payload: PropTypes.shape({}),
  label: PropTypes.number,
};

const XpTooltipContent = ({ payload, strings }) => {
  try {
    const data = payload && payload[0] && payload[0].payload;
    const { rXpAdv, rGoldAdv, time } = data;
    return (
      <StyledTooltip>
        <StyledTooltipGold>
          <span>{`${formatGraphTime(time)}`}</span>
        </StyledTooltipGold>
        <br />
        <StyledTooltipGold>
          <StyledTooltipTeam
            color={rGoldAdv > 0 ? constants.colorSuccess : constants.colorDanger}
          >
            {rGoldAdv > 0 ? strings.general_radiant : strings.general_dire}
          </StyledTooltipTeam>
          <GoldSpan>{Math.abs(rGoldAdv)} {strings.heading_graph_gold}</GoldSpan>
        </StyledTooltipGold>
        <br />
        <StyledTooltipGold>
          <StyledTooltipTeam
            color={rXpAdv > 0 ? constants.colorSuccess : constants.colorDanger}
          >
            {rXpAdv > 0 ? strings.general_radiant : strings.general_dire}
          </StyledTooltipTeam>
          <XpSpan>{Math.abs(rXpAdv)} {strings.heading_graph_xp}</XpSpan>
        </StyledTooltipGold>
      </StyledTooltip>
    );
  } catch (e) {
    return null;
  }
};
XpTooltipContent.propTypes = {
  payload: PropTypes.shape({}),
  strings: PropTypes.shape({}),
};

const XpNetworthGraph = ({
  match, strings, sponsorURL, sponsorIcon,
}) => {
  const matchData = generateDiffData(match);
  const maxY =<commit_msg>fixes #2418<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import {
  ReferenceArea,
  XAxis,
  YAxis,
  Tooltip,
  Line,
  LineChart,
  CartesianGrid,
  ReferenceLine,
  Legend,
  ResponsiveContainer,
} from 'recharts';
import heroes from 'dotaconstants/build/heroes.json';
import playerColors from 'dotaconstants/build/player_colors.json';
import Heading from '../../Heading';
import constants from '../../constants';
import { StyledTooltip, StyledTooltipTeam, StyledRadiant, StyledDire, StyledHolder, GoldSpan, XpSpan, StyledTooltipGold, StyledCustomizedTooltip } from './Styled';

const formatGraphTime = minutes => `${minutes}:00`;

const generateDiffData = (match) => {
  const radiantGoldAdv = match.radiant_gold_adv;
  const radiantXpAdv = match.radiant_xp_adv;
  const data = [];
  if (radiantGoldAdv && radiantXpAdv) {
    radiantXpAdv.forEach((rXpAdv, index) => {
      if (index <= Math.floor(match.duration / 60)) {
        data.push({ time: index, rXpAdv, rGoldAdv: radiantGoldAdv[index] });
      }
    });
  }
  return data;
};

const CustomizedTooltip = ({ label, payload }) => (
  <StyledCustomizedTooltip>
    <div className="label">{label}</div>
    {payload.map((data, i) => (
      <div value={data.value} className={`data ${i < 5 && 'isRadiant'}`} style={{ borderLeft: `8px solid ${data.color}` }}>
        {data.dataKey}: {data.value}
      </div>)).sort((a, b) => b.props.value - a.props.value)
    }
  </StyledCustomizedTooltip>
);
CustomizedTooltip.propTypes = {
  payload: PropTypes.shape({}),
  label: PropTypes.number,
};

const XpTooltipContent = ({ payload, strings }) => {
  try {
    const data = payload && payload[0] && payload[0].payload;
    const { rXpAdv, rGoldAdv, time } = data;
    return (
      <StyledTooltip>
        <StyledTooltipGold>
          <span>{`${formatGraphTime(time)}`}</span>
        </StyledTooltipGold>
        <br />
        <StyledTooltipGold>
          <StyledTooltipTeam
            color={rGoldAdv > 0 ? constants.colorSuccess : constants.colorDanger}
          >
            {rGoldAdv > 0 ? strings.general_radiant : strings.general_dire}
          </StyledTooltipTeam>
          <GoldSpan>{Math.abs(rGoldAdv)} {strings.heading_graph_gold}</GoldSpan>
        </StyledTooltipGold>
        <br />
        <StyledTooltipGold>
          <StyledTooltipTeam
            color={rXpAdv > 0 ? constants.colorSuccess : constants.colorDanger}
          >
            {rXpAdv > 0 ? strings.general_radiant : strings.general_dire}
          </StyledTooltipTeam>
          <XpSpan>{Math.abs(rXpAdv)} {strings.heading_graph_xp}</XpSpan>
        </StyledTooltipGold>
      </StyledTooltip>
    );
  } catch (e) {
    return null;
  }
};
XpTooltipContent.propTypes = {
  payload: PropTypes.shape({}),
  strings: PropTypes.shape({}),
};

const XpNetworthGraph = ({
  match, strings, sponsorURL, sponsorIcon,
}) => {
  if (!match.radiant_gold_adv || !match.radiant_xp_adv) {
    return null;
  }
  const matchData = generateDiffData(match);
  const maxY =
{'fraction_non_alphanumeric': 0.14468651255612838, 'fraction_numerical': 0.004656577415599534, 'mean_word_length': 3.2773826458036983, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 79, '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': '3743326', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1990, 'n_words': 379}