<commit_before>define([
  'underscore',
  'backbone',
  'backbone-super',
  'facade',
  'config',
  'helpers/utils',
  'views/abstract/base',
  'd3',
  'c3',
  'views/chart/pie',
  'views/chart/bar',
  'views/chart/scatter'
], function(_, Backbone, bSuper, fc, Config, Utils, BaseView, d3, c3,
    PieChartView, BarChartView, ScatterChartView) {

  'use strict';

  var ChartView = BaseView.extend({

    el: '#chartView',

    template: '{{#if error}}<p>{{{error}}}</p>{{/if}}',

    scatterOptions: {
      data: {
        type: 'scatter'
      },
      subchart: {
          show: false
      },
      legend: {
        hide: true
      },
      size: {
        width:  400,
        height: 200
      }
    },

    initialize: function() {
      this.setListeners();
    },

    setListeners: function() {
      var self = this;
      this.collection.on('sync', this.render, this);
      this.collection.on('request', function() {
        $('.l-chart').addClass('is-loading');
      });
      this.on('error', function(err) {
        this.error = err;
        this.render();
      }, this);
      $(window).resize(function() { self.resize(); });
    },

    serialize: function() {
      var error = this.error || this.collection.error || undefined;
      if(error) {
        return { error: error };
      }
      return {};
    },

    /**
     * Renders the chart once again
     * Note: the function only executes every 400ms
     */
    resize: _.debounce(function() {
      $('.l-chart').addClass('is-loading');
      this.renderChart();
      $('.l-chart').removeClass('is-loading');
    }, 400),

    /**
     * Renders the chart
     */
    renderChart: function() {
      if(this.chart) {
        this.chart.destroy();
        delete this.chart;
      }
      var params;
      var width  = this.getWidth(),
          height = this.getHeight();
      switch(fc.get('graph')) {
        case 'pie':
          var series = this.getPieSeries();
          this.chart = new PieChartView({
            el: this.el,
            width: width,
            height: height,
            series: series
          });
          break;<commit_msg>Fixes an issue where the app would try to resize the graph even if it didn't exist when the page would be reloaded<commit_after>define([
  'underscore',
  'backbone',
  'backbone-super',
  'facade',
  'config',
  'helpers/utils',
  'views/abstract/base',
  'd3',
  'c3',
  'views/chart/pie',
  'views/chart/bar',
  'views/chart/scatter'
], function(_, Backbone, bSuper, fc, Config, Utils, BaseView, d3, c3,
    PieChartView, BarChartView, ScatterChartView) {

  'use strict';

  var ChartView = BaseView.extend({

    el: '#chartView',

    template: '{{#if error}}<p>{{{error}}}</p>{{/if}}',

    scatterOptions: {
      data: {
        type: 'scatter'
      },
      subchart: {
          show: false
      },
      legend: {
        hide: true
      },
      size: {
        width:  400,
        height: 200
      }
    },

    initialize: function() {
      this.setListeners();
    },

    setListeners: function() {
      var self = this;
      this.collection.on('sync', this.render, this);
      this.collection.on('request', function() {
        $('.l-chart').addClass('is-loading');
      });
      this.on('error', function(err) {
        this.error = err;
        this.render();
      }, this);
      $(window).resize(function() {
        if(self.chart) {
          self.resize();
        }
      });
    },

    serialize: function() {
      var error = this.error || this.collection.error || undefined;
      if(error) {
        return { error: error };
      }
      return {};
    },

    /**
     * Renders the chart once again
     * Note: the function only executes every 400ms
     */
    resize: _.debounce(function() {
      $('.l-chart').addClass('is-loading');
      this.renderChart();
      $('.l-chart').removeClass('is-loading');
    }, 400),

    /**
     * Renders the chart
     */
    renderChart: function() {
      if(this.chart) {
        this.chart.destroy();
        delete this.chart;
      }
      var width  = this.getWidth(),
          height = this.getHeight();
      switch(fc.get('graph')) {
        case 'pie':
          var series = this.getPieSeries();
          this.chart = new PieChartView({
            el: this.el,
            width: width,
            height: height,
            series: series
          });
          break;
{'fraction_non_alphanumeric': 0.16350067842605157, 'fraction_numerical': 0.007236544549977386, 'mean_word_length': 1.9041365725541695, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3070241', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1367, 'n_words': 292}