<commit_before>
var React = require('react');
var d3 = require('d3');
var _ = require('underscore');

var refugeeConstants = require('../../model/refugee-constants.js');


var RefugeeMapCountryCountsLayer = React.createClass({
  

    getInitialState: function() {
      return {state: null}
    },


    renderText: function(country, count) {
      if (this.props.country === null) {
         return null;
      }

      var point = this.props.projection(
         this.props.mapModel.getCenterPointOfCountry(country));
      return (
         <text key={country} x={point[0]} y={point[1] + 30}>{count}</text>
      );
    },


    renderTexts: function() {
      var items = [];

      if (this.props.width > refugeeConstants.labelShowBreakPoint) {
        var counts = this.props.refugeeCountsModel
          .getDestinationCountsByOriginCountries(this.props.country, this.state.stamp);

        var totalReceivedCount = 0;
        var totalLeftCount = 0;

        _.difference(this.props.originCountries, refugeeConstants.disableLabels)
          .forEach(function(country) {
          var cc = counts[country]
          if (cc != null) {
            var val = cc.asylumApplications;
            items.push(this.renderText(country, val));
            totalReceivedCount += val;
          }
        }.bind(this));

       counts = this.props.refugeeCountsModel
          .getOriginCountsByDestinationCountries(this.props.country, this.state.stamp);
        
        _.difference(this.props.destinationCountries, refugeeConstants.disableLabels)
          .forEach(function(country) {
          var cc = counts[country]
          if (cc != null) {
            var val = cc.asylumApplications;
            items.push(this.renderText(country, cc.asylumApplications));
            totalLeftCount += val;
          }
        }.bind(this));
      }

      // On the hovered country we show either the amount of 
      // people received of the amount of people who have left
      //
      // Some countries both receive and generate asylum seekers
      // in most cases the other count is much larger, and 
      // each country is either mainly a receiver or originator
      // country.
      //
      // For such countries it is appropriate to simply know
      // whichever count is bigger
      //
      // Serbia is however a problem, as both numbers are similar
      // and the balance even shifts along the way
      // 
      var count = Math.max(totalReceivedCount, totalLeftCount);

      if (count > 0 && this.props.country !== "SRB") {
        items.push(this.renderText(this.props.country, count));
      }

      return items;
   },<commit_msg>Use negative count numbers for origin countries<commit_after>
var React = require('react');
var d3 = require('d3');
var _ = require('underscore');

var refugeeConstants = require('../../model/refugee-constants.js');


var RefugeeMapCountryCountsLayer = React.createClass({
  

    getInitialState: function() {
      return {state: null}
    },


    renderText: function(country, count) {
      if (this.props.country === null) {
         return null;
      }

      var point = this.props.projection(
         this.props.mapModel.getCenterPointOfCountry(country));
      return (
         <text key={country} x={point[0]} y={point[1] + 30}>{count}</text>
      );
    },


    renderTexts: function() {
      var items = [];

      if (this.props.width > refugeeConstants.labelShowBreakPoint) {
        var counts = this.props.refugeeCountsModel
          .getDestinationCountsByOriginCountries(this.props.country, this.state.stamp);

        var totalReceivedCount = 0;
        var totalLeftCount = 0;

        _.difference(this.props.originCountries, refugeeConstants.disableLabels)
          .forEach(function(country) {
          var cc = counts[country]
          if (cc != null) {
            var val = cc.asylumApplications;
            items.push(this.renderText(country, -val));
            totalReceivedCount += val;
          }
        }.bind(this));

       counts = this.props.refugeeCountsModel
          .getOriginCountsByDestinationCountries(this.props.country, this.state.stamp);
        
        _.difference(this.props.destinationCountries, refugeeConstants.disableLabels)
          .forEach(function(country) {
          var cc = counts[country]
          if (cc != null) {
            var val = cc.asylumApplications;
            items.push(this.renderText(country, cc.asylumApplications));
            totalLeftCount += val;
          }
        }.bind(this));
      }

      // On the hovered country we show either the amount of 
      // people received of the amount of people who have left
      //
      // Some countries both receive and generate asylum seekers
      // in most cases the other count is much larger, and 
      // each country is either mainly a receiver or originator
      // country.
      //
      // For such countries it is appropriate to simply know
      // whichever count is bigger
      //
      // Serbia is however a problem, as both numbers are similar
      // and the balance even shifts along the way
      // 
      
      var count = totalReceivedCount - totalLeftCount;
      
      // if (totalReceivedCount > totalLeftCount) {
      //   count = totalReceivedCount;
      // } else {
      //   count = -totalLeftCount;
      // }

      if (count != 0 && this.props.country !== "SRB") {
        items.push(this.renderText(this.props.country, count));
      }

      return items;
   },
{'fraction_non_alphanumeric': 0.10974061309631779, 'fraction_numerical': 0.0032650099764193726, 'mean_word_length': 2.179930795847751, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '1373061', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1472, 'n_words': 386}