<commit_before>import Fluxxor from 'fluxxor';
import React from 'react';
import numeralLibs from 'numeral';
import {SERVICES} from '../services/services';
import {Actions} from '../actions/Actions';
import 'amcharts3/amcharts/amcharts';
import 'amcharts3/amcharts/serial';
import 'amcharts3/amcharts/pie';
import 'amcharts3-export';
import 'amcharts3-export/export.css';
import 'amcharts3/amcharts/themes/dark';


const MAX_ZOOM = 15;
const DEFAULT_LANGUAGE = "en";
const FluxMixin = Fluxxor.FluxMixin(React),
      StoreWatchMixin = Fluxxor.StoreWatchMixin("DataStore"),
      chartDivReference = "popularLocationsPieDiv";

export const PopularLocationsChart = React.createClass({
  mixins: [FluxMixin, StoreWatchMixin],
  
  getStateFromFlux: function() {
    return this.getFlux().store("DataStore").getState();
  },

  initializeGraph(){
    let self = this;

    this.popularLocationsChart = window.AmCharts.makeChart(chartDivReference, {
        "theme": "dark",
        "type": "pie",
        "startDuration": 1,
        "balloonText": "[[term]]: <b>[[mentionFmt]]</b>  mentions<br>Est Pop: <b>[[population]]</b> people",
        "labelColor": "#fff",
        "radius": 70,
        "pullOutRadius": 0,
        "labelRadius": 1,
        "innerRadius": 22,
        "gradientRatio": [-0.4, -0.4, -0.4, -0.4, -0.4, -0.4, 0, 0.1, 0.2, 0.1, 0, -0.2, -0.5],
        "outlineAlpha": 0,
        "valueField": "mentions",
        "labelText": "[[displayLabel]] - [[mentionFmt]]",
        "titleField": "displayLabel",
        "export": {
            "enabled": true
        },
        "allLabels": [{
            "text": "Top 5 Locations",
            "bold": true,
            "size": 12,
            "color": "#fff",
            "x": 0,
            "align": "center",
            "y": 200
        }]
    });

    this.popularLocationsChart.addListener("clickSlice", e => {
        if(e.dataItem.dataContext){
              let entity = {
                  "type": "Location",
                  "properties": {
                      "name": e.dataItem.dataContext.term,
                      "coordinates": e.dataItem.dataContext.coordinates,
                  }
              };
              self.getFlux().actions.DASHBOARD.changeSearchFilter(entity, this.props.siteKey);
        }
    });
 },

 refreshChart(locations){
    let maxAxesDisplayLabelChars = 16;
    let dataProvider = [];

    locations.forEach(location => {
              let label = location.properties.location;
              let mentions = location.properties.mentions;
              let coordinates = location.coordinates;
              let population = numeralLibs(location.properties.population).format(location.properties.population > 1000 ? '+0.0a' : '0a');
              let displayLabel = label.length > maxAxesDisplayLabelChars ? label.substring(0, maxAxesDisplayLabelChars) : label;
              let mentionFmt = numeralLibs(mentions).format(mentions > 1000 ? '+0.0a' : '0a');
              dataProvider.push({coordinates: coordinates, population: population, 
                                 displayLabel: displayLabel, term: label, category: "Location",
                                 mentions: mentions, mentionFmt: mentionFmt, color: '#ccc'});
    });

    this.popularLocationsChart.dataProvider = dataProvider;
    this.popularLocationsChart.validateData();
 },

 updateChart(period, timespanType, dataSource){
     let self = this;<commit_msg>Initial commit for the new admin page.<commit_after>import Fluxxor from 'fluxxor';
import React from 'react';
import numeralLibs from 'numeral';
import {SERVICES} from '../services/services';
import {Actions} from '../actions/Actions';
import 'amcharts3/amcharts/amcharts';
import 'amcharts3/amcharts/serial';
import 'amcharts3/amcharts/pie';
import 'amcharts3-export';
import 'amcharts3-export/export.css';
import 'amcharts3/amcharts/themes/dark';


const MAX_ZOOM = 15;
const DEFAULT_LANGUAGE = "en";
const FluxMixin = Fluxxor.FluxMixin(React),
      StoreWatchMixin = Fluxxor.StoreWatchMixin("DataStore"),
      chartDivReference = "popularLocationsPieDiv";

export const PopularLocationsChart = React.createClass({
  mixins: [FluxMixin, StoreWatchMixin],
  
  getStateFromFlux: function() {
    return this.getFlux().store("DataStore").getState();
  },

  initializeGraph(){
    let self = this;

    this.popularLocationsChart = window.AmCharts.makeChart(chartDivReference, {
        "theme": "dark",
        "type": "pie",
        "startDuration": 1,
        "balloonText": "[[term]]: <b>[[mentionFmt]]</b>  mentions<br>Est Pop: <b>[[population]]</b> people",
        "labelColor": "#fff",
        "radius": 70,
        "pullOutRadius": 0,
        "labelRadius": 1,
        "innerRadius": 22,
        "gradientRatio": [-0.4, -0.4, -0.4, -0.4, -0.4, -0.4, 0, 0.1, 0.2, 0.1, 0, -0.2, -0.5],
        "outlineAlpha": 0,
        "valueField": "mentions",
        "labelText": "[[displayLabel]] - [[mentionFmt]]",
        "titleField": "displayLabel",
        "export": {
            "enabled": true
        },
        "allLabels": [{
            "text": "Top 5 Locations",
            "bold": true,
            "size": 12,
            "color": "#fff",
            "x": 0,
            "align": "center",
            "y": 200
        }]
    });

    this.popularLocationsChart.addListener("clickSlice", e => {
        if(e.dataItem.dataContext){
              let entity = {
                  "type": "Location",
                  "name": e.dataItem.dataContext.term,
                  "coordinates": e.dataItem.dataContext.coordinates
              };
              self.getFlux().actions.DASHBOARD.changeSearchFilter(entity, this.props.siteKey);
        }
    });
 },

 refreshChart(locations){
    let maxAxesDisplayLabelChars = 16;
    let dataProvider = [];

    locations.forEach(location => {
              let label = location.properties.location;
              let mentions = location.properties.mentions;
              let coordinates = location.coordinates;
              let population = numeralLibs(location.properties.population).format(location.properties.population > 1000 ? '+0.0a' : '0a');
              let displayLabel = label.length > maxAxesDisplayLabelChars ? label.substring(0, maxAxesDisplayLabelChars) : label;
              let mentionFmt = numeralLibs(mentions).format(mentions > 1000 ? '+0.0a' : '0a');
              dataProvider.push({coordinates: coordinates, population: population, 
                                 displayLabel: displayLabel, term: label, category: "Location",
                                 mentions: mentions, mentionFmt: mentionFmt, color: '#ccc'});
    });

    this.popularLocationsChart.dataProvider = dataProvider;
    this.popularLocationsChart.validateData();
 },

 updateChart(period, timespanType, dataSource){
     let self = this;
{'fraction_non_alphanumeric': 0.14367311072056238, 'fraction_numerical': 0.018746338605741066, 'mean_word_length': 2.507447354904982, 'pattern_counts': {'":': 55, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4925207', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2005, 'n_words': 408}