<commit_before>import _ from 'lodash'
import moment from 'moment'
import Reflux from 'reflux'
import StateMixin from'reflux-state-mixin'

import ChartActions from 'actions/ChartActions'
import DatapointActions from 'actions/DatapointActions'
import builderDefinitions from 'components/molecules/charts_d3/utils/builderDefinitions'
import DatapointStore from 'stores/DatapointStore'
import CampaignStore from 'stores/CampaignStore'
import LocationStore from 'stores/LocationStore'
import IndicatorStore from 'stores/IndicatorStore'
import ChartStoreHelpers from 'stores/ChartStoreHelpers'

import palettes from 'components/molecules/charts_d3/utils/palettes'

var ChartStore = Reflux.createStore({

  mixins: [StateMixin.store],

  listenables: ChartActions,

  chart: {
    def: {
      data_format: 'pct',
      color: palettes['traffic_light'],
      type: 'RawData',
      features: [],
      indicator_ids: [],
      location_ids: [],
      selected_indicators: [],
      selected_locations: [],
      countries: [],
      groupBy: 'indicator',
      timeRange: null,
      end_date: moment().format('YYYY-MM-DD'),
      start_date: moment().subtract(1, 'y').format('YYYY-MM-DD'),
      title: null,
      cellSize: 36,
      fontSize: 14,
      margin: { top: 40, right: 40, bottom: 40, left: 40 },
      cellFontSize: 14,
      headers: [],
      parent_location_map: null,
      default_sort_order: null,
      x: 0,
      xFormat: ',.0f',
      y: 0,
      yFormat: ',.0f',
      z: 0
    },
    data: null,
    loading: false
  },

  init () {
    this.listenTo(DatapointStore, this.onDatapointStore)
    this.joinTrailing(LocationStore, IndicatorStore, CampaignStore, this.onGetInintialStores)
  },

  getInitialState () {
    return this.chart
  },

  // =========================================================================== //
  //                               API CALL HANDLERS                             //
  // =========================================================================== //

  // ===============================  Fetch Chart  ============================= //
  onFetchChart () {
    this.setState({ loading: true })
  },
  onFetchChartCompleted (response) {
    const chart_json = response.chart_json
    this.chart.def.campaign_ids = chart_json.campaign_ids
    this.chart.def.end_date = chart_json.end_date
    this.chart.def.indicator_ids = chart_json.indicator_ids
    this.chart.def.location_ids = chart_json.location_ids
    this.chart.def.start_date = chart_json.start_date
    this.chart.def.id = response.id
    this.chart.def.title = response.title
    this.chart.def.selected_locations = this.chart.def.location_ids.map(id => this.locations.index[id])
    this.chart.def.selected_indicators = this.chart.def.indicator_ids.map(id => this.indicators.index[id])
    this.chart.def.headers = this.chart.def.selected_indicators
    this.chart.def.xDomain = this.chart.def.headers.map(indicator => indicator.short_name)
    this.chart.def.x = this.chart.def.indicator_ids[0]
    this.chart.def.y = this.chart.def.indicator_ids[1] ? this.chart.def.indicator_ids[1] : 0
    this.chart.def.z = this.chart.def.indicator_ids[2] ? this.chart.def.indicator_ids[2] : 0
    ChartActions.setType(chart_json.type)
  },
  onFetchChartFailed (error) {
    this.setState({ error: error })
  },

  // ===============================  Post Chart  ============================= //
  onPostChart () {
    this.setState({ loading: true })
  },
  onPostChartCompleted (response) {
    window.location.replace('/charts/' + response.objects.id)
    this.trigger(this.chart)
  },
  onPostChartFailed (error) {
    this.setState({ error: error })
  },

  // ============================  Fetch Map Features  ========================= //
  onFetchMapFeatures () {
    this.setState({ loading: true })
  },
  onFetchMapFeaturesCompleted (response) {
    this.chart.def.features = response.objects.features
    this.updateChart()<commit_msg>Remove redirect after chart save<commit_after>import _ from 'lodash'
import moment from 'moment'
import Reflux from 'reflux'
import StateMixin from'reflux-state-mixin'

import ChartActions from 'actions/ChartActions'
import DatapointActions from 'actions/DatapointActions'
import builderDefinitions from 'components/molecules/charts_d3/utils/builderDefinitions'
import DatapointStore from 'stores/DatapointStore'
import CampaignStore from 'stores/CampaignStore'
import LocationStore from 'stores/LocationStore'
import IndicatorStore from 'stores/IndicatorStore'
import ChartStoreHelpers from 'stores/ChartStoreHelpers'

import palettes from 'components/molecules/charts_d3/utils/palettes'

var ChartStore = Reflux.createStore({

  mixins: [StateMixin.store],

  listenables: ChartActions,

  chart: {
    def: {
      data_format: 'pct',
      color: palettes['traffic_light'],
      type: 'RawData',
      features: [],
      indicator_ids: [],
      location_ids: [],
      selected_indicators: [],
      selected_locations: [],
      countries: [],
      groupBy: 'indicator',
      timeRange: null,
      end_date: moment().format('YYYY-MM-DD'),
      start_date: moment().subtract(1, 'y').format('YYYY-MM-DD'),
      title: null,
      cellSize: 36,
      fontSize: 14,
      margin: { top: 40, right: 40, bottom: 40, left: 40 },
      cellFontSize: 14,
      headers: [],
      parent_location_map: null,
      default_sort_order: null,
      x: 0,
      xFormat: ',.0f',
      y: 0,
      yFormat: ',.0f',
      z: 0
    },
    data: null,
    loading: false
  },

  init () {
    this.listenTo(DatapointStore, this.onDatapointStore)
    this.joinTrailing(LocationStore, IndicatorStore, CampaignStore, this.onGetInintialStores)
  },

  getInitialState () {
    return this.chart
  },

  // =========================================================================== //
  //                               API CALL HANDLERS                             //
  // =========================================================================== //

  // ===============================  Fetch Chart  ============================= //
  onFetchChart () {
    this.setState({ loading: true })
  },
  onFetchChartCompleted (response) {
    const chart_json = response.chart_json
    this.chart.def.campaign_ids = chart_json.campaign_ids
    this.chart.def.end_date = chart_json.end_date
    this.chart.def.indicator_ids = chart_json.indicator_ids
    this.chart.def.location_ids = chart_json.location_ids
    this.chart.def.start_date = chart_json.start_date
    this.chart.def.id = response.id
    this.chart.def.title = response.title
    this.chart.def.selected_locations = this.chart.def.location_ids.map(id => this.locations.index[id])
    this.chart.def.selected_indicators = this.chart.def.indicator_ids.map(id => this.indicators.index[id])
    this.chart.def.headers = this.chart.def.selected_indicators
    this.chart.def.xDomain = this.chart.def.headers.map(indicator => indicator.short_name)
    this.chart.def.x = this.chart.def.indicator_ids[0]
    this.chart.def.y = this.chart.def.indicator_ids[1] ? this.chart.def.indicator_ids[1] : 0
    this.chart.def.z = this.chart.def.indicator_ids[2] ? this.chart.def.indicator_ids[2] : 0
    ChartActions.setType(chart_json.type)
  },
  onFetchChartFailed (error) {
    this.setState({ error: error })
  },

  // ===============================  Post Chart  ============================= //
  onPostChart () {
    this.setState({ loading: true })
  },
  onPostChartCompleted (response) {
    this.trigger(this.chart)
  },
  onPostChartFailed (error) {
    this.setState({ error: error })
  },

  // ============================  Fetch Map Features  ========================= //
  onFetchMapFeatures () {
    this.setState({ loading: true })
  },
  onFetchMapFeaturesCompleted (response) {
    this.chart.def.features = response.objects.features
    this.updateChart()
{'fraction_non_alphanumeric': 0.1967483805410898, 'fraction_numerical': 0.00736695033659342, 'mean_word_length': 3.5097365406643757, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1533513', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2371, 'n_words': 419}