<commit_before>// ==========================================================================
//                        DG.MapPolygonLayer
//
//  Author:   <NAME>
//
//  Copyright ©2014 Concord Consortium
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// ==========================================================================
/* global L */
sc_require('components/graph_map_common/plot_layer');


/** @class DG.MapPolygonLayer - A plot of dots placed according to numeric values

  @extends DG.PlotLayer
*/
DG.MapPolygonLayer = DG.PlotLayer.extend(
/** @scope DG.MapPolygonLayer.prototype */
{
  displayProperties: [],

  autoDestroyProperties: [],

  mapSource: null,

  _areFeaturesAdded: false,
  _featuresRemainingToFetch: 0,
  features: null,

  map: function() {
    return this.getPath('mapSource.mapLayer.map');
  }.property(),

  init: function() {
    sc_super();

    this.features = [];
  },

  destroy: function() {
    var tMap = this.get('map');
    this.features.forEach( function( iFeature) {
      tMap.removeLayer( iFeature);
    });
    this.features = null;

    sc_super();
  },

  /**
   * Augment my base class by checking to make sure we have the attributes we need.
   * @returns {boolean}
   */
  readyToDraw: function() {
    var tModel = this.get('model');
    return tModel && !SC.none(tModel.getPath('dataConfiguration.polygonAttributeDescription.attributeID'));
  },

  /**
   * Computing this context once at beginning of display loop speeds things up
   * @return {*}
   */
  createRenderContext: function() {
    var tModel = this.get('model');
    if( !tModel)
      return; // not ready yet
    var tConfig = tModel.get('dataConfiguration'),
        tLegendDesc = tModel.getPath('dataConfiguration.legendAttributeDescription'),
        tStrokeColorIsDefault = this.get('areaStrokeColor') === DG.PlotUtilities.kDefaultMapStrokeColor,
        tStrokeSameAsFill = tModel.get('strokeSameAsFill'),
        tIsNumeric = tLegendDesc.get('isNumeric'),
        tQuantileValues = (tLegendDesc && tIsNumeric) ?
            DG.MathUtilities.nQuantileValues(
                tConfig.numericValuesForPlace( DG.GraphTypes.EPlace.eLegend), 5):
            [];
    return {
      map: this.get('map' ),
      polygonVarID: tModel.getPath('dataConfiguration.polygonAttributeDescription.attributeID'),
      legendDesc: tLegendDesc,
      legendVarID: tLegendDesc && tLegendDesc.get('attributeID'),
      legendName: tLegendDesc && tLegendDesc.getPath('attribute.name'),
      areaTransparency: tModel.get('areaTransparency'),
      areaStrokeColor: tModel.get('areaStrokeColor'),
      areaStrokeColorIsDefault: tStrokeColorIsDefault,
      areaStrokeTransparency: tStrokeSameAsFill ?
          tModel.get('areaTransparency') :
          tModel.get('areaStrokeTransparency'),
      calcCaseColorString: function( iCase ) {
        if( !this.legendVarID)
          return tModel.get('areaColor');

        DG.assert( iCase );
        var tColorValue = tIsNumeric ? iCase.getForcedNumericValue(this.legendVarID) : iCase.getValue( this.legendVarID),
            tCaseColor = tColorValue ?
                DG.ColorUtilities.calcCaseColor( tColorValue, this.legendDesc, null, tQuantileValues) :
                DG.ColorUtilities.kMapMissingValueCaseColor;
        return tCaseColor.colorString || tCaseColor;
      },
      calcStrokeColorString: function( iCase ) {
        if( tStrokeSameAsFill)
          return this.calcCaseColorString( iCase);
        else return this.areaStrokeColor;<commit_msg>[#181756019] Bug fix: Crash in changing moments with Story Builder<commit_after>// ==========================================================================
//                        DG.MapPolygonLayer
//
//  Author:   <NAME>
//
//  Copyright ©2014 Concord Consortium
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// ==========================================================================
/* global L */
sc_require('components/graph_map_common/plot_layer');


/** @class DG.MapPolygonLayer - A plot of dots placed according to numeric values

  @extends DG.PlotLayer
*/
DG.MapPolygonLayer = DG.PlotLayer.extend(
/** @scope DG.MapPolygonLayer.prototype */
{
  displayProperties: [],

  autoDestroyProperties: [],

  mapSource: null,

  _areFeaturesAdded: false,
  _featuresRemainingToFetch: 0,
  features: null,

  map: function() {
    return this.getPath('mapSource.mapLayer.map');
  }.property(),

  init: function() {
    sc_super();

    this.features = [];
  },

  destroy: function() {
    var tMap = this.get('map');
    this.features.forEach( function( iFeature) {
      tMap.removeLayer( iFeature);
    });
    this.features = null;

    sc_super();
  },

  /**
   * Augment my base class by checking to make sure we have the attributes we need.
   * @returns {boolean}
   */
  readyToDraw: function() {
    var tModel = this.get('model');
    return tModel && !SC.none(tModel.getPath('dataConfiguration.polygonAttributeDescription.attributeID'));
  },

  /**
   * Computing this context once at beginning of display loop speeds things up
   * @return {*}
   */
  createRenderContext: function() {
    var tModel = this.get('model');
    if( !tModel)
      return; // not ready yet
    var tConfig = tModel.get('dataConfiguration'),
        tLegendDesc = tModel.getPath('dataConfiguration.legendAttributeDescription'),
        tStrokeColorIsDefault = this.get('areaStrokeColor') === DG.PlotUtilities.kDefaultMapStrokeColor,
        tStrokeSameAsFill = tModel.get('strokeSameAsFill'),
        tIsNumeric = tLegendDesc && tLegendDesc.get('isNumeric'),
        tQuantileValues = (tLegendDesc && tIsNumeric) ?
            DG.MathUtilities.nQuantileValues(
                tConfig.numericValuesForPlace( DG.GraphTypes.EPlace.eLegend), 5):
            [];
    return {
      map: this.get('map' ),
      polygonVarID: tModel.getPath('dataConfiguration.polygonAttributeDescription.attributeID'),
      legendDesc: tLegendDesc,
      legendVarID: tLegendDesc && tLegendDesc.get('attributeID'),
      legendName: tLegendDesc && tLegendDesc.getPath('attribute.name'),
      areaTransparency: tModel.get('areaTransparency'),
      areaStrokeColor: tModel.get('areaStrokeColor'),
      areaStrokeColorIsDefault: tStrokeColorIsDefault,
      areaStrokeTransparency: tStrokeSameAsFill ?
          tModel.get('areaTransparency') :
          tModel.get('areaStrokeTransparency'),
      calcCaseColorString: function( iCase ) {
        if( !this.legendVarID)
          return tModel.get('areaColor');

        DG.assert( iCase );
        var tColorValue = tIsNumeric ? iCase.getForcedNumericValue(this.legendVarID) : iCase.getValue( this.legendVarID),
            tCaseColor = tColorValue ?
                DG.ColorUtilities.calcCaseColor( tColorValue, this.legendDesc, null, tQuantileValues) :
                DG.ColorUtilities.kMapMissingValueCaseColor;
        return tCaseColor.colorString || tCaseColor;
      },
      calcStrokeColorString: function( iCase ) {
        if( tStrokeSameAsFill)
          return this.calcCaseColorString( iCase);
        else return this.areaStrokeColor;
{'fraction_non_alphanumeric': 0.1456644559076394, 'fraction_numerical': 0.0035617784328174896, 'mean_word_length': 3.303911205073996, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1211572', 'n_tokens_mistral': 2392, 'n_tokens_neox': 2280, 'n_words': 541}