<commit_before>import React, {Component, PropTypes} from 'react'
import update from 'react-addons-update'
import BenchmarkChart from '../charts/bar-chart/BenchmarkChart'
import BarChart from '../charts/bar-chart/BarChart'
import LineChart from '../charts/line-chart/LineChart'
import {norway, comparisonDescription} from '../../lib/regionUtil'
import {unitFormatter} from '../../lib/unitFormatter'
import {queryResultPresenter} from '../../lib/queryResultPresenter'
import * as ImdiPropTypes from '../proptypes/ImdiPropTypes'

export default class RegionSummaryChart extends Component {

  static propTypes = {
    region: ImdiPropTypes.region.isRequired,
    query: PropTypes.object.isRequired,
    config: PropTypes.object.isRequired,
    queryResult: PropTypes.array.isRequired,
    compareWith: PropTypes.shape({
      queryResult: PropTypes.array
    })
  };

  static contextTypes = {
    linkTo: PropTypes.func,
    goTo: PropTypes.func
  };

  getChart(chartKind) {
    if (chartKind == 'benchmark') {
      return BenchmarkChart
    } else if (chartKind == 'line') {
      return LineChart
    }
    return BarChart
  }

  getDimensions(chartKind) {
    if (chartKind == 'benchmark') {
      return [{name: 'region', variables: []}]
    } else if (chartKind == 'line') {
      return [{name: 'bosetting', variables: []}, {name: 'region', variables: []}, {name: 'year', variables: []}]
    }
    return [{name: 'region', variables: []}, {name: 'innvkat3', variables: []}]
  }

  render() {

    const {region, queryResult, query, config, compareWith} = this.props

    const data = queryResult && queryResultPresenter(query, queryResult, {chartKind: config.chartKind})
    const comparisonData = compareWith && compareWith.queryResult

    const isNorway = region.prefixedCode === norway.prefixedCode
    const isBenchmark = config.chartKind == 'benchmark'
    const isBorough = region.type == 'borough'

    const cardName = config.drillDown.card

    const formatter = unitFormatter(query.unit[0])

    const regionDataRow = data.rows.find(row => row.region == region.prefixedCode)

    let titleParams = {
      share: formatter.format(regionDataRow.value)
    }

    config.additionalTitleParams.map(param => {
      titleParams[param] = regionDataRow[param]
    })

    const title = config.title(titleParams)
    const subtitle = comparisonData && region.prefixedCode !== 'F00' && config.subTitle({share: formatter.format(comparisonData[0].tabellvariabel)})

    // secondary titles, atm only used in barchart
    let titleTwo = null
    let subtitleTwo = null
    if (config.chartKind == 'bar') {
      titleParams = {
        share: formatter.format(data.rows[1].value)
      }
      config.additionalTitleParams.map(param => {
        titleParams[param] = data.rows[1][param]
      })
      titleTwo = config.title(titleParams)
      subtitleTwo = comparisonData && region.prefixedCode !== 'F00' && config.subTitle({share: formatter.format(comparisonData[1].tabellvariabel)})
    }

    const Chart = this.getChart(config.chartKind)

    // BenchmarkChart can only handle one dimension
    const dimensions = this.getDimensions(config.chartKind)

    const modifiedData = update(data, {
      dimensions: {$set: dimensions},
      // highlight our current region
      highlight: {
        $set: {
          dimensionName: 'region',
          value: [region.prefixedCode]
        }
      }
    })


    const drillDownUrl = this.context.linkTo('/tall-og-statistikk/steder/:region/:cardsPageName/:cardName', {
      region: region.prefixedCode,
      cardsPageName: config.drillDown.page,
      cardName: config.drillDown.card
    })

    const similarUrl = this.context.linkTo('/tall-og-statistikk/steder/:region/lignende', {region: region.prefixedCode})
    const comparison = comparisonDescription(region).toLowerCase()

    if (isBorough && cardName == 'bosatt_anmodede') {
      return (
        <div>
          {cardName}Bydel
        </div><commit_msg>Removed text from render  that was used for testing purpose and not removed from last commit.<commit_after>import React, {Component, PropTypes} from 'react'
import update from 'react-addons-update'
import BenchmarkChart from '../charts/bar-chart/BenchmarkChart'
import BarChart from '../charts/bar-chart/BarChart'
import LineChart from '../charts/line-chart/LineChart'
import {norway, comparisonDescription} from '../../lib/regionUtil'
import {unitFormatter} from '../../lib/unitFormatter'
import {queryResultPresenter} from '../../lib/queryResultPresenter'
import * as ImdiPropTypes from '../proptypes/ImdiPropTypes'

export default class RegionSummaryChart extends Component {

  static propTypes = {
    region: ImdiPropTypes.region.isRequired,
    query: PropTypes.object.isRequired,
    config: PropTypes.object.isRequired,
    queryResult: PropTypes.array.isRequired,
    compareWith: PropTypes.shape({
      queryResult: PropTypes.array
    })
  };

  static contextTypes = {
    linkTo: PropTypes.func,
    goTo: PropTypes.func
  };

  getChart(chartKind) {
    if (chartKind == 'benchmark') {
      return BenchmarkChart
    } else if (chartKind == 'line') {
      return LineChart
    }
    return BarChart
  }

  getDimensions(chartKind) {
    if (chartKind == 'benchmark') {
      return [{name: 'region', variables: []}]
    } else if (chartKind == 'line') {
      return [{name: 'bosetting', variables: []}, {name: 'region', variables: []}, {name: 'year', variables: []}]
    }
    return [{name: 'region', variables: []}, {name: 'innvkat3', variables: []}]
  }

  render() {

    const {region, queryResult, query, config, compareWith} = this.props

    const data = queryResult && queryResultPresenter(query, queryResult, {chartKind: config.chartKind})
    const comparisonData = compareWith && compareWith.queryResult

    const isNorway = region.prefixedCode === norway.prefixedCode
    const isBenchmark = config.chartKind == 'benchmark'
    const isBorough = region.type == 'borough'

    const cardName = config.drillDown.card

    const formatter = unitFormatter(query.unit[0])

    const regionDataRow = data.rows.find(row => row.region == region.prefixedCode)

    let titleParams = {
      share: formatter.format(regionDataRow.value)
    }

    config.additionalTitleParams.map(param => {
      titleParams[param] = regionDataRow[param]
    })

    const title = config.title(titleParams)
    const subtitle = comparisonData && region.prefixedCode !== 'F00' && config.subTitle({share: formatter.format(comparisonData[0].tabellvariabel)})

    // secondary titles, atm only used in barchart
    let titleTwo = null
    let subtitleTwo = null
    if (config.chartKind == 'bar') {
      titleParams = {
        share: formatter.format(data.rows[1].value)
      }
      config.additionalTitleParams.map(param => {
        titleParams[param] = data.rows[1][param]
      })
      titleTwo = config.title(titleParams)
      subtitleTwo = comparisonData && region.prefixedCode !== 'F00' && config.subTitle({share: formatter.format(comparisonData[1].tabellvariabel)})
    }

    const Chart = this.getChart(config.chartKind)

    // BenchmarkChart can only handle one dimension
    const dimensions = this.getDimensions(config.chartKind)

    const modifiedData = update(data, {
      dimensions: {$set: dimensions},
      // highlight our current region
      highlight: {
        $set: {
          dimensionName: 'region',
          value: [region.prefixedCode]
        }
      }
    })


    const drillDownUrl = this.context.linkTo('/tall-og-statistikk/steder/:region/:cardsPageName/:cardName', {
      region: region.prefixedCode,
      cardsPageName: config.drillDown.page,
      cardName: config.drillDown.card
    })

    const similarUrl = this.context.linkTo('/tall-og-statistikk/steder/:region/lignende', {region: region.prefixedCode})
    const comparison = comparisonDescription(region).toLowerCase()

    if (isBorough && cardName == 'bosatt_anmodede') {
      return (
        <div></div>
{'fraction_non_alphanumeric': 0.1279549718574109, 'fraction_numerical': 0.0025015634771732333, 'mean_word_length': 3.422566371681416, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6190396', 'n_tokens_mistral': 2376, 'n_tokens_neox': 2329, 'n_words': 514}