<commit_before>import * as utils from 'base/utils';
import Component from 'base/component';
import colorPicker from 'helpers/d3.colorPicker';
import axisSmart from 'helpers/d3.axisWithLabelPicker';

/*!
 * VIZABI BUBBLE COLOR LEGEND COMPONENT
 */

var OPACITY_REGULAR = 0.8;
var OPACITY_DIM = 0.5;
var OPACITY_HIGHLIGHT = 1;

var ColorLegend = Component.extend({

  init: function(config, context) {
    var _this = this;
    this.template = '<div class="vzb-cl-outer"></div>';
    this.name = 'colorlegend';

    this.model_expects = [{
      name: "state",
      type: "model"
    }, {
      name: "language",
      type: "language"
    }];

    this.needsUpdate = false;
    this.which_1 = false;
    this.scaleType_1 = false;

    this.model_binds = {
      "change:state.marker.color.scaleType": function(evt, path) {
        if(!_this._readyOnce) return;
        _this.updateView();
      },
      "change:state.marker.color.which": function(evt, path) {
        if(!_this._readyOnce) return;
        if(_this.model.state.entities_minimap) {
          _this.forwardModelUpdate();
        }else{
          _this.updateView();
        }
      },
      "change:state.marker.color.palette": function(evt, path) {
        if(!_this._readyOnce) return;
        _this.updateView();
      },
      "change:state.entities.highlight": function(evt, values) {
        if(_this.colorModel.use !== "property") return;
        var _highlightedEntity = _this.model.state.entities.getHighlighted();
        if(_highlightedEntity.length > 1) return;

        if(_highlightedEntity.length) {
            _this.model.state.marker.getFrame(_this.model.state.time.value, function(frame) {
              if(!frame) return;
            
              var _highlightedEntity = _this.model.state.entities.getHighlighted();
              if(_highlightedEntity.length) {                
                _this.updateGroupsOpacity(frame["color"][_highlightedEntity[0]]);
              }
            });
        } else if (values !== null && values !== "highlight") {
          _this.updateGroupsOpacity(values["color"]);
        } else {
          _this.updateGroupsOpacity();         
        }
      }
    };

    //contructor is the same as any component
    this._super(config, context);
  },
  
  forwardModelUpdate: function(){
    if(this.colorModel.use === "property"){
      var newFilter = {};
      newFilter["is--" + this.colorModel.which] = true;
      this.model.state.entities_minimap.show = newFilter;
    }
  },

  readyOnce: function() {
    var _this = this;
    this.element = d3.select(this.element);
    
    //make color in options scrollable
    d3.select(this.placeholder.parentNode).classed("vzb-dialog-scrollable", true);

    this.markerModel = this.model.state.marker_minimap ? this.model.state.marker_minimap : this.model.state.marker;
    this.listColorsEl = this.element
      .append("div").attr("class", "vzb-cl-holder")
      .append("div").attr("class","vzb-cl-colorlist");

    this.rainbowEl = this.listColorsEl.append("div").attr("class", "vzb-cl-rainbow");
    this.minimapEl = this.listColorsEl.append("div").attr("class", "vzb-cl-minimap");
    this.rainbowLegendEl = this.listColorsEl.append("div").attr("class", "vzb-cl-rainbow-legend");
    this.rainbowLegendSVG = this.rainbowLegendEl.append("svg");
    this.rainbowLegendG = this.rainbowLegendSVG.append("g");
    this.rainbowLegend = null;

    this.labelScaleEl = this.listColorsEl.append("div").attr("class", "vzb-cl-labelscale");
    this.labelScaleSVG = this.labelScaleEl.append("svg");
    this.labelScaleG = this.labelScaleSVG.append("g");
    this.unitDiv = this.listColorsEl.append("div").attr("class", "vzb-cl-unit");
    this.unitText = this.unitDiv.append("text").attr("class", "vzb-cl-unit-text");

    this.minimapSVG = this.minimapEl.append("svg");
    this.minimapG = this.minimapSVG.append("g");

    this.colorPicker = colorPicker();
    
    // append color picker to the tool DOM. need to check if element is already a d3 selection to not do it twice
    this.root.element instanceof Array? this.root.element : d3.select(this.root.element)
      .call(this.colorPicker);

    this.colorModel = this.model.state.marker.color;
    

    OPACITY_DIM = this.model.state.entities.opacitySelectDim; 
  },
  
  
  ready: function(){
    var _this = this;
    
    this.KEY = this.model.state.entities.getDimension();
    this.minimapDim = this.model.state.entities_minimap.getDimension();
    
    this.canShowMap = false;

    if(this.model.state.marker_minimap){
      
      var timeModel = this.model.state.time;
      var filter = {};
      filter[timeModel.getDimension()] = timeModel.value;
      _this.frame = this.model.state.marker_minimap.getValues(filter,[_this.minimapDim]);
      
      this.canShowMap = utils.keys((this.frame||{}).geoshape||{}).length && this.colorModel.use == "property";

      var minimapKeys = this.model.state.marker_minimap.getKeys(_this.minimapDim);     
      minimapKeys.forEach(function(d){
        if(!((_this.frame||{}).geoshape||{})[d[_this.minimapDim]]) _this.canShowMap = false;
      });
    }
    _this.updateView();
  },


  updateView: function() {
    var _this = this;
    var KEY = this.KEY;

    var palette = this.colorModel.getPalette();
    var canShowMap = this.canShowMap;

    var minimapKeys = [];
<commit_msg>Hide entities_minimap filter from url for color use  non property<commit_after>import * as utils from 'base/utils';
import Component from 'base/component';
import colorPicker from 'helpers/d3.colorPicker';
import axisSmart from 'helpers/d3.axisWithLabelPicker';

/*!
 * VIZABI BUBBLE COLOR LEGEND COMPONENT
 */

var OPACITY_REGULAR = 0.8;
var OPACITY_DIM = 0.5;
var OPACITY_HIGHLIGHT = 1;

var ColorLegend = Component.extend({

  init: function(config, context) {
    var _this = this;
    this.template = '<div class="vzb-cl-outer"></div>';
    this.name = 'colorlegend';

    this.model_expects = [{
      name: "state",
      type: "model"
    }, {
      name: "language",
      type: "language"
    }];

    this.needsUpdate = false;
    this.which_1 = false;
    this.scaleType_1 = false;

    this.model_binds = {
      "change:state.marker.color.scaleType": function(evt, path) {
        if(!_this._readyOnce || _this.colorModel.use !== "indicator") return;
        _this.updateView();
      },
      "change:state.marker.color.which": function(evt, path) {
        if(!_this._readyOnce) return;
        if(_this.model.state.entities_minimap) {
          _this.forwardModelUpdate();
        }else{
          _this.updateView();
        }
      },
      "change:state.marker.color.palette": function(evt, path) {
        if(!_this._readyOnce) return;
        _this.updateView();
      },
      "change:state.entities.highlight": function(evt, values) {
        if(_this.colorModel.use !== "property") return;
        var _highlightedEntity = _this.model.state.entities.getHighlighted();
        if(_highlightedEntity.length > 1) return;

        if(_highlightedEntity.length) {
            _this.model.state.marker.getFrame(_this.model.state.time.value, function(frame) {
              if(!frame) return;
            
              var _highlightedEntity = _this.model.state.entities.getHighlighted();
              if(_highlightedEntity.length) {                
                _this.updateGroupsOpacity(frame["color"][_highlightedEntity[0]]);
              }
            });
        } else if (values !== null && values !== "highlight") {
          _this.updateGroupsOpacity(values["color"]);
        } else {
          _this.updateGroupsOpacity();         
        }
      }
    };

    //contructor is the same as any component
    this._super(config, context);
  },
  
  forwardModelUpdate: function(){
    if(this.colorModel.use === "property"){
      var newFilter = {};
      newFilter["is--" + this.colorModel.which] = true;
      this.model.state.entities_minimap.show = newFilter;
    } else {
      var defaultShow = utils.clone(this.root.default_model.state.entities_minimap.show._defs_);
      this.model.state.entities_minimap.show = defaultShow;
    }
  },

  readyOnce: function() {
    var _this = this;
    this.element = d3.select(this.element);
    
    //make color in options scrollable
    d3.select(this.placeholder.parentNode).classed("vzb-dialog-scrollable", true);

    this.markerModel = this.model.state.marker_minimap ? this.model.state.marker_minimap : this.model.state.marker;
    this.listColorsEl = this.element
      .append("div").attr("class", "vzb-cl-holder")
      .append("div").attr("class","vzb-cl-colorlist");

    this.rainbowEl = this.listColorsEl.append("div").attr("class", "vzb-cl-rainbow");
    this.minimapEl = this.listColorsEl.append("div").attr("class", "vzb-cl-minimap");
    this.rainbowLegendEl = this.listColorsEl.append("div").attr("class", "vzb-cl-rainbow-legend");
    this.rainbowLegendSVG = this.rainbowLegendEl.append("svg");
    this.rainbowLegendG = this.rainbowLegendSVG.append("g");
    this.rainbowLegend = null;

    this.labelScaleEl = this.listColorsEl.append("div").attr("class", "vzb-cl-labelscale");
    this.labelScaleSVG = this.labelScaleEl.append("svg");
    this.labelScaleG = this.labelScaleSVG.append("g");
    this.unitDiv = this.listColorsEl.append("div").attr("class", "vzb-cl-unit");
    this.unitText = this.unitDiv.append("text").attr("class", "vzb-cl-unit-text");

    this.minimapSVG = this.minimapEl.append("svg");
    this.minimapG = this.minimapSVG.append("g");

    this.colorPicker = colorPicker();
    
    // append color picker to the tool DOM. need to check if element is already a d3 selection to not do it twice
    this.root.element instanceof Array? this.root.element : d3.select(this.root.element)
      .call(this.colorPicker);

    this.colorModel = this.model.state.marker.color;
    

    OPACITY_DIM = this.model.state.entities.opacitySelectDim; 
  },
  
  
  ready: function(){
    var _this = this;
    
    this.KEY = this.model.state.entities.getDimension();
    this.minimapDim = this.model.state.entities_minimap.getDimension();
    
    this.canShowMap = false;

    if(this.model.state.marker_minimap){

      var timeModel = this.model.state.time;
      var filter = {};
      filter[timeModel.getDimension()] = timeModel.value;
      _this.frame = this.model.state.marker_minimap.getValues(filter,[_this.minimapDim]);
      
      this.canShowMap = utils.keys((this.frame||{}).geoshape||{}).length && this.colorModel.use == "property";

      var minimapKeys = this.model.state.marker_minimap.getKeys(_this.minimapDim);     
      minimapKeys.forEach(function(d){
        if(!((_this.frame||{}).geoshape||{})[d[_this.minimapDim]]) _this.canShowMap = false;
      });
    }
    _this.updateView();
  },


  updateView: function() {
    var _this = this;
    var KEY = this.KEY;

    var palette = this.colorModel.getPalette();
    var canShowMap = this.canShowMap;

    var minimapKeys = [];

{'fraction_non_alphanumeric': 0.14704810495626822, 'fraction_numerical': 0.0027332361516034984, 'mean_word_length': 2.923159399571122, 'pattern_counts': {'":': 8, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1202500', 'n_tokens_mistral': 3625, 'n_tokens_neox': 3580, 'n_words': 559}