<commit_before>/* globals requestAnimationFrame */
import React, {Component, PropTypes} from "react";
import { assign, groupBy } from "lodash";
import ChartHelpers from "../victory-chart/helper-methods";
import ZoomHelpers from "./helper-methods";
import {VictoryClipContainer, Helpers} from "victory-core";

const fallbackProps = {
  width: 450,
  height: 300,
  padding: 50
};

class VictoryZoom extends Component {
  static displayName = "VictoryZoom";
  static role = "zoom";

  static propTypes = {
    children: PropTypes.node,
    domain: PropTypes.array,
    clipContainerComponent: PropTypes.element.isRequired
  }

  static defaultProps = {
    clipContainerComponent: <VictoryClipContainer/>
  }

  constructor(props) {
    super(props);

    const chart = React.Children.only(this.props.children);
    const chartChildren = React.Children.toArray(chart);

    this.domain = {
      x: ChartHelpers.getDomain(chart.props, "x", chartChildren)
    };

    const [rangex1, rangex0] = Helpers.getRange(
      Helpers.modifyProps(chart.props, {}, "chart"), // TODO: Don't presume chart role
      "x"
    );

    this.plottableWidth = rangex0 - rangex1;
    this.width = chart.props.width || fallbackProps.width;
    this.state = { domain: this.domain };

    this.events = this.initializeEvents();
    this.clipDataComponents = this.clipDataComponents.bind(this);
  }

  componentWillMount() {
    this.getChartRef = (chart) => { this.chartRef = chart; };
  }

  initializeEvents() {
    return [{
      target: "parent",
      eventHandlers: {
        onMouseDown: (evt) => {
          this.targetBounds = this.chartRef.getSvgBounds();
          const x = evt.clientX - this.targetBounds.left;
          this.isPanning = true;
          this.startX = x;
          this.lastDomain = this.state.domain;
        },
        onMouseUp: () => { this.isPanning = false; },
        onMouseLeave: () => { this.isPanning = false; },
        onMouseMove: (evt) => {
          const clientX = evt.clientX;
          if (this.isPanning) {<commit_msg>Add initial domain prop for setting initial zoom/pan<commit_after>/* globals requestAnimationFrame */
import React, {Component, PropTypes} from "react";
import { assign, groupBy } from "lodash";
import ChartHelpers from "../victory-chart/helper-methods";
import ZoomHelpers from "./helper-methods";
import {VictoryClipContainer, Helpers, PropTypes as CustomPropTypes} from "victory-core";

const fallbackProps = {
  width: 450,
  height: 300,
  padding: 50
};

class VictoryZoom extends Component {
  static displayName = "VictoryZoom";
  static role = "zoom";

  static propTypes = {
    children: PropTypes.node,
    initialDomain: PropTypes.oneOfType([
      CustomPropTypes.domain,
      PropTypes.shape({
        x: CustomPropTypes.domain,
        y: CustomPropTypes.domain
      })
    ]),
    clipContainerComponent: PropTypes.element.isRequired
  }

  static defaultProps = {
    clipContainerComponent: <VictoryClipContainer/>
  }

  constructor(props) {
    super(props);

    const chart = React.Children.only(this.props.children);
    const chartChildren = React.Children.toArray(chart);

    this.domain = {
      x: ChartHelpers.getDomain(chart.props, "x", chartChildren)
    };

    const [rangex1, rangex0] = Helpers.getRange(
      Helpers.modifyProps(chart.props, {}, "chart"), // TODO: Don't presume chart role
      "x"
    );

    this.plottableWidth = rangex0 - rangex1;
    this.width = chart.props.width || fallbackProps.width;
    this.state = { domain: props.initialDomain || this.domain };

    this.events = this.initializeEvents();
    this.clipDataComponents = this.clipDataComponents.bind(this);
  }

  componentWillMount() {
    this.getChartRef = (chart) => { this.chartRef = chart; };
  }

  initializeEvents() {
    return [{
      target: "parent",
      eventHandlers: {
        onMouseDown: (evt) => {
          this.targetBounds = this.chartRef.getSvgBounds();
          const x = evt.clientX - this.targetBounds.left;
          this.isPanning = true;
          this.startX = x;
          this.lastDomain = this.state.domain;
        },
        onMouseUp: () => { this.isPanning = false; },
        onMouseLeave: () => { this.isPanning = false; },
        onMouseMove: (evt) => {
          const clientX = evt.clientX;
          if (this.isPanning) {
{'fraction_non_alphanumeric': 0.1271342870327642, 'fraction_numerical': 0.0055376095985233045, 'mean_word_length': 2.9734188817598532, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '6636269', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1312, 'n_words': 281}