<commit_before>import React, { PureComponent } from 'react';
import Proptypes from 'prop-types';
import { format } from 'd3-format';
import cx from 'classnames';

import styles from './tooltip-chart-styles.scss';

class TooltipChart extends PureComponent {
  getTotal = (keys, data) => {
    let total = 0;
    keys.forEach(key => {
      total += data.payload[key];
    });
    return format('.3s')(total);
  };

  render() {
    const { config, content } = this.props;
    return (
      <div className={styles.tooltip}>
        <span className={styles.unit}>{config.axes.yLeft.unit}</span>
        {content.payload.length > 0 && (
          <div className={cx(styles.label, styles.labelTotal)}>
            <p>TOTAL</p>
            <p>{this.getTotal(config.columns.y, content.payload[0])}</p>
          </div>
        )}
        {content.payload.length > 0 &&
          content.payload.map(y => (
            <div key={y.dataKey} className={styles.label}>
              <div className={styles.legend}>
                <span
                  className={styles.labelDot}
                  style={{ backgroundColor: config.theme[y.dataKey].fill }}
                />
                <p className={styles.labelName}>
                  {config.tooltip[y.dataKey].label}
                </p>
              </div>
              <p className={styles.labelValue}>
                {y.payload ? format('.3s')(y.payload[y.dataKey]) : ''}
              </p>
            </div>
          ))}<commit_msg>Fix: only render tooltip total if more than one data element<commit_after>import React, { PureComponent } from 'react';
import Proptypes from 'prop-types';
import { format } from 'd3-format';
import cx from 'classnames';

import styles from './tooltip-chart-styles.scss';

class TooltipChart extends PureComponent {
  getTotal = (keys, data) => {
    let total = 0;
    keys.forEach(key => {
      total += data.payload[key];
    });
    return format('.3s')(total);
  };

  render() {
    const { config, content } = this.props;
    const needsTotal = content.payload && content.payload.length > 1;
    return (
      <div className={styles.tooltip}>
        <span className={styles.unit}>{config.axes.yLeft.unit}</span>
        {needsTotal && (
          <div className={cx(styles.label, styles.labelTotal)}>
            <p>TOTAL</p>
            <p>{this.getTotal(config.columns.y, content.payload[0])}</p>
          </div>
        )}
        {content.payload &&
          content.payload.length > 0 &&
          content.payload.map(y => (
            <div key={y.dataKey} className={styles.label}>
              <div className={styles.legend}>
                <span
                  className={styles.labelDot}
                  style={{ backgroundColor: config.theme[y.dataKey].fill }}
                />
                <p className={styles.labelName}>
                  {config.tooltip[y.dataKey].label}
                </p>
              </div>
              <p className={styles.labelValue}>
                {y.payload ? format('.3s')(y.payload[y.dataKey]) : ''}
              </p>
            </div>
          ))}
{'fraction_non_alphanumeric': 0.15372272143774068, 'fraction_numerical': 0.004492939666238768, 'mean_word_length': 1.9049394221808016, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 49, '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': '3319045', 'n_tokens_mistral': 919, 'n_tokens_neox': 886, 'n_words': 173}