<commit_before>import { Selection, Data, Helpers } from "victory-core";
import { assign, throttle, isFunction, groupBy, keys, isEqual } from "lodash";
import { voronoi as d3Voronoi } from "d3-voronoi";
import React from "react";
import { attachId } from "../../helpers/event-handlers.js";

const VoronoiHelpers = {
  withinBounds(props, point) {
    const { width, height, voronoiPadding, polar, origin, scale } = props;
    const padding = voronoiPadding || 0;
    const { x, y } = point;
    if (polar) {
      const distanceSquared = Math.pow(x - origin.x, 2) + Math.pow(y - origin.y, 2);
      const radius = Math.max(...scale.y.range());
      return distanceSquared < Math.pow(radius, 2);
    } else {
      return x >= padding && x <= width - padding && y >= padding && y <= height - padding;
    }
  },

  getDatasets(props) {
    const addMeta = (data, name, child) => {
      const continuous = child && child.type && child.type.continuous;
      const style = child ? child.props && child.props.style : props.style;
      return data.map((datum, index) => {
        const { x, y } = Helpers.getPoint(datum);
        return assign({
          _voronoiX: props.dimension === "y" ? 0 : x,
          _voronoiY: props.dimension === "x" ? 0 : y,
          childName: name, eventKey: index, continuous, style
        }, datum);
      });
    };

    if (props.data) {
      return addMeta(props.data);
    }

    const getData = (childProps) => {
      const data = Data.getData(childProps);
      return Array.isArray(data) && data.length > 0 ? data : undefined;
    };

    const iteratee = (child, childName, parent) => {
      if (child.type && child.type.role === "axis") {
        return null;
      } else if (child.type && isFunction(child.type.getData)) {
        child = parent ? React.cloneElement(child, parent.props) : child;
        const childData = child.props && child.type.getData(child.props);
        return childData ? addMeta(childData, childName, child) : null;
      } else {
        const childData = getData(child.props);
        return childData ? addMeta(childData, childName, child) : null;
      }
    };
    return Helpers.reduceChildren(React.Children.toArray(props.children), iteratee);
  },

  // returns an array of objects with point and data where point is an x, y coordinate, and data is<commit_msg>bugfix: getData referred to the wrong domain<commit_after>import { Selection, Data, Helpers } from "victory-core";
import { assign, throttle, isFunction, groupBy, keys, isEqual } from "lodash";
import { voronoi as d3Voronoi } from "d3-voronoi";
import React from "react";
import { attachId } from "../../helpers/event-handlers.js";

const VoronoiHelpers = {
  withinBounds(props, point) {
    const { width, height, voronoiPadding, polar, origin, scale } = props;
    const padding = voronoiPadding || 0;
    const { x, y } = point;
    if (polar) {
      const distanceSquared = Math.pow(x - origin.x, 2) + Math.pow(y - origin.y, 2);
      const radius = Math.max(...scale.y.range());
      return distanceSquared < Math.pow(radius, 2);
    } else {
      return x >= padding && x <= width - padding && y >= padding && y <= height - padding;
    }
  },

  getDatasets(props) {
    const addMeta = (data, name, child) => {
      const continuous = child && child.type && child.type.continuous;
      const style = child ? child.props && child.props.style : props.style;
      return data.map((datum, index) => {
        const { x, y } = Helpers.getPoint(datum);
        return assign({
          _voronoiX: props.dimension === "y" ? 0 : x,
          _voronoiY: props.dimension === "x" ? 0 : y,
          childName: name, eventKey: index, continuous, style
        }, datum);
      });
    };

    if (props.data) {
      return addMeta(props.data);
    }

    const getData = (childProps) => {
      const data = Data.getData(childProps);
      return Array.isArray(data) && data.length > 0 ? data : undefined;
    };

    const iteratee = (child, childName, parent) => {
      if (child.type && child.type.role === "axis") {
        return null;
      } else if (child.type && isFunction(child.type.getData)) {
        child = parent ? React.cloneElement(child, parent.props) : child;
        const childData = child.props
          && child.type.getData({ ...child.props, domain: props.domain });
        return childData ? addMeta(childData, childName, child) : null;
      } else {
        const childData = getData({ ...child.props, domain: props.domain });
        return childData ? addMeta(childData, childName, child) : null;
      }
    };
    return Helpers.reduceChildren(React.Children.toArray(props.children), iteratee);
  },

  // returns an array of objects with point and data where point is an x, y coordinate, and data is
{'fraction_non_alphanumeric': 0.1424388203304748, 'fraction_numerical': 0.0037649027400125496, 'mean_word_length': 2.7156177156177157, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '5002377', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1463, 'n_words': 409}