<commit_before>// ==========================================================================
//                      DG.PlotDataConfiguration
//
//  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.
// ==========================================================================

/** @class  DG.PlotDataConfiguration - The object that describes the manner in which attributes are
 assigned to places in a graph.

 @extends SC.Object
 */
DG.PlotDataConfiguration = SC.Object.extend(
    /** @scope DG.PlotDataConfiguration.prototype */
    {
      /**
       The data context which is the source of the data for this graph.
       @property   {DG.DataContext}
       */
      _dataContext: null,
      dataContext: function( iKey, iValue) {
        if( iValue) {
          if( this._dataContext)
            this._dataContext.removeObserver('changeCount', this, 'handleDataContextNotification');
          this._dataContext = iValue;
          this._dataContext.addObserver('changeCount', this, 'handleDataContextNotification');
        }
        return this._dataContext;
      }.property(),

      handleDataContextNotification: function( iNotifier) {
        iNotifier.get('newChanges' ).forEach( function( iChange) {
          if( iChange.operation === 'moveAttribute')
            this.updateCaptionAttribute();
        }.bind(this));
      },

      /**
       * The 'caption' should always be the attribute leftmost in the child-most collection among those
       * belonging to the attributes that are plotted.
       */
      updateCaptionAttribute: function() {
        var tCollections = this.getPath('dataContext.collections'), // parent-most has index 0
            tChildMostCollectionIndex = -1; // deliberately out of bounds
        if( !tCollections)
          return; // Not ready for this yet
        ['x', 'y', 'legend', 'y2', 'top', 'right'].forEach(function( iKey) {
          var tAttributeCollection = this.getPath(iKey + 'AttributeDescription.attribute.collection'),
              tFoundIndex = tAttributeCollection ? tCollections.indexOf(tAttributeCollection) : -1;
          tChildMostCollectionIndex = Math.max(tChildMostCollectionIndex, tFoundIndex);
        }.bind(this));
        if( tChildMostCollectionIndex >= 0) {
          var tAttributes = tCollections[tChildMostCollectionIndex].get('attrs'),
              tLeftMostAttr = tAttributes.length >= 0 ? tAttributes[0] : null;
          this.setPath('captionAttributeDescription.attribute', tLeftMostAttr);
        }
      },

      dataContextDidChange: function () {
        this.invalidateCaches();
        this.notifyPropertyChange('defaultTitle');
      }.observes('dataContext'),

      /**
       The outer array is indexed by DG.GraphTypes.EPlace
       @property { [ [ {DG.AttributePlacementDescription}] ] }
       */
      attributesByPlace: null,

      /**
       @property { DG.CollectionClient }
       */
      collectionClient: function () {<commit_msg>[#175567809] Bug fix: Data tip does not change when attributes are reordered<commit_after>// ==========================================================================
//                      DG.PlotDataConfiguration
//
//  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.
// ==========================================================================

/** @class  DG.PlotDataConfiguration - The object that describes the manner in which attributes are
 assigned to places in a graph.

 @extends SC.Object
 */
DG.PlotDataConfiguration = SC.Object.extend(
    /** @scope DG.PlotDataConfiguration.prototype */
    {
      /**
       The data context which is the source of the data for this graph.
       @property   {DG.DataContext}
       */
      _dataContext: null,
      dataContext: function( iKey, iValue) {
        if( iValue) {
          if( this._dataContext)
            this._dataContext.removeObserver('changeCount', this, 'handleDataContextNotification');
          this._dataContext = iValue;
          this._dataContext.addObserver('changeCount', this, 'handleDataContextNotification');
        }
        return this._dataContext;
      }.property(),

      handleDataContextNotification: function( iNotifier) {
        iNotifier.get('newChanges' ).forEach( function( iChange) {
          if( iChange.operation === 'moveAttribute')
            this.updateCaptionAttribute();
        }.bind(this));
      },

      /**
       * The 'caption' should always be the attribute leftmost in the child-most collection among those
       * belonging to the attributes that are plotted.
       */
      updateCaptionAttribute: function() {
        var tCollections = this.getPath('dataContext.collections'), // parent-most has index 0
            tChildMostCollectionIndex = -1; // deliberately out of bounds
        if( !tCollections)
          return; // Not ready for this yet
        ['x', 'y', 'legend', 'y2', 'top', 'right', 'polygon'].forEach(function( iKey) {
          var tAttributeCollection = this.getPath(iKey + 'AttributeDescription.attribute.collection'),
              tFoundIndex = tAttributeCollection ? tCollections.indexOf(tAttributeCollection) : -1;
          tChildMostCollectionIndex = Math.max(tChildMostCollectionIndex, tFoundIndex);
        }.bind(this));
        if( tChildMostCollectionIndex >= 0) {
          var tAttributes = tCollections[tChildMostCollectionIndex].get('attrs'),
              tLeftMostAttr = tAttributes.length >= 0 ? tAttributes[0] : null;
          this.setPath('captionAttributeDescription.attribute', tLeftMostAttr);
        }
      },

      dataContextDidChange: function () {
        this.invalidateCaches();
        this.notifyPropertyChange('defaultTitle');
      }.observes('dataContext'),

      /**
       The outer array is indexed by DG.GraphTypes.EPlace
       @property { [ [ {DG.AttributePlacementDescription}] ] }
       */
      attributesByPlace: null,

      /**
       @property { DG.CollectionClient }
       */
      collectionClient: function () {
{'fraction_non_alphanumeric': 0.14448188711036225, 'fraction_numerical': 0.005475989890480202, 'mean_word_length': 2.7989333333333333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '6539854', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1738, 'n_words': 520}