<commit_before>import React, { PropTypes } from 'react'
import { ascending, descending } from 'd3'

import { setScale, isOrdinalScale } from '../util/d3'
import { spreadRelated } from '../util/react'
import Chart from '../Chart'
import Axis from '../Axis'
import Tooltip from '../Tooltip'
import Histogram from '../Histogram'

class HistogramChart extends React.Component {
  constructor (props) {
    super(props)
    this.xScale = setScale(props.xScaleType)
    this.yScale = setScale(props.yScaleType)

    this.xDomain = this.props.xDomain
    this.yDomain = this.props.yDomain

    this.onClick = this.onClick.bind(this)
    this.onBrush = this._onBrush.bind(this)
    this.onEnter = this.onEnter.bind(this)
    this.onLeave = this.onLeave.bind(this)
    this.onResize = this.onResize.bind(this)

    this.updateDomain = this.updateDomain.bind(this)
    this.updateRange = this.updateRange.bind(this)

    this.sortData = this.sortData.bind(this)
    this.getMaxCount = this.getMaxCount.bind(this)
    this.interval = null

    this.tip = props.tipFunction
      ? new Tooltip().attr('className', 'd3-tip').html(props.tipFunction)
      : props.tipFunction

    this.updateDomain(props, this.state)
  }

  componentWillReceiveProps (nextProps) {
    if (this.props.xScaleType !== nextProps.xScaleType) {
      console.log('Updating scale from : ' + this.props.xScaleType + ' ==> ' + nextProps.xScaleType)
      this.xScale = setScale(nextProps.xScaleType)
    }
    if (this.props.yScaleType !== nextProps.yScaleType) {
      this.yScale = setScale(nextProps.yScaleType)
    }
    this.updateDomain(nextProps, this.state)
  }

  componentWillUnmount () {
    if (this.props.tipFunction) {
      this.tip.destroy()
    }
  }

  sortData (data, props, state) {
    let sortArr = []
    data[0].bins.sort((a, b) => {
      let i = 0
      if (props.sortBy === 'x') {
        i = props.sortOrder === 'ascending'
          ? ascending(a[props.xAccessor], b[props.xAccessor])
          : descending(a[props.xAccessor], b[props.xAccessor])
      } else {
        let useBin = (props.sortTypes.indexOf(data[0].type) > -1 || props.sortTypes.length === 0)
        let ya = useBin ? a[props.yAccessor] : 0
        let yb = useBin ? b[props.yAccessor] : 0
        for (let j = 1; j < data.length; j++) {
          let useBin = (props.sortTypes.indexOf(data[j].type) > -1 || props.sortTypes.length === 0)
          if (useBin) {
            data[j].bins.forEach((d, i) => {
              if (d[props.xAccessor] === a[props.xAccessor]) {
                ya += d[props.yAccessor]
              }
              if (d[props.xAccessor] === b[props.xAccessor]) {
                yb += d[props.yAccessor]<commit_msg>added support to sort with asc || ascending<commit_after>import React, { PropTypes } from 'react'
import { ascending, descending } from 'd3'

import { setScale, isOrdinalScale } from '../util/d3'
import { spreadRelated } from '../util/react'
import Chart from '../Chart'
import Axis from '../Axis'
import Tooltip from '../Tooltip'
import Histogram from '../Histogram'

class HistogramChart extends React.Component {
  constructor (props) {
    super(props)
    this.xScale = setScale(props.xScaleType)
    this.yScale = setScale(props.yScaleType)

    this.xDomain = this.props.xDomain
    this.yDomain = this.props.yDomain

    this.onClick = this.onClick.bind(this)
    this.onBrush = this._onBrush.bind(this)
    this.onEnter = this.onEnter.bind(this)
    this.onLeave = this.onLeave.bind(this)
    this.onResize = this.onResize.bind(this)

    this.updateDomain = this.updateDomain.bind(this)
    this.updateRange = this.updateRange.bind(this)

    this.sortData = this.sortData.bind(this)
    this.getMaxCount = this.getMaxCount.bind(this)
    this.interval = null

    this.tip = props.tipFunction
      ? new Tooltip().attr('className', 'd3-tip').html(props.tipFunction)
      : props.tipFunction

    this.updateDomain(props, this.state)
  }

  componentWillReceiveProps (nextProps) {
    if (this.props.xScaleType !== nextProps.xScaleType) {
      console.log('Updating scale from : ' + this.props.xScaleType + ' ==> ' + nextProps.xScaleType)
      this.xScale = setScale(nextProps.xScaleType)
    }
    if (this.props.yScaleType !== nextProps.yScaleType) {
      this.yScale = setScale(nextProps.yScaleType)
    }
    this.updateDomain(nextProps, this.state)
  }

  componentWillUnmount () {
    if (this.props.tipFunction) {
      this.tip.destroy()
    }
  }

  sortData (data, props, state) {
    let sortArr = []
    data[0].bins.sort((a, b) => {
      let i = 0
      if (props.sortBy === 'x') {
        i = props.sortOrder === 'ascending' || props.sortOrder === 'asc'
          ? ascending(a[props.xAccessor], b[props.xAccessor])
          : descending(a[props.xAccessor], b[props.xAccessor])
      } else {
        let useBin = (props.sortTypes.indexOf(data[0].type) > -1 || props.sortTypes.length === 0)
        let ya = useBin ? a[props.yAccessor] : 0
        let yb = useBin ? b[props.yAccessor] : 0
        for (let j = 1; j < data.length; j++) {
          let useBin = (props.sortTypes.indexOf(data[j].type) > -1 || props.sortTypes.length === 0)
          if (useBin) {
            data[j].bins.forEach((d, i) => {
              if (d[props.xAccessor] === a[props.xAccessor]) {
                ya += d[props.yAccessor]
              }
              if (d[props.xAccessor] === b[props.xAccessor]) {
                yb += d[props.yAccessor]
{'fraction_non_alphanumeric': 0.14649331624244644, 'fraction_numerical': 0.004761032777879509, 'mean_word_length': 2.7334244702665753, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '5299058', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1781, 'n_words': 339}