<commit_before>/* -*- mode: espresso; espresso-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set softtabstop=2 shiftwidth=2 tabstop=2 expandtab: */

"use strict";

/**
 * The tilelayer control element on the top-left of the stack window
 */
function TilelayerControl( stack )
{
  var self = this;

  /**
   * get the view object
   */
  self.getView = function()
  {
    return view;
  }

  /**
   * set opacity for a layer
   */
  self.setOpacity = function ( key, val )
  {
    if(self.layers.hasOwnProperty(key))
      self.layers[key].setOpacity( val / 100 );
  }

  /**
   * removes existing layer controls and re-creates them.
   */
  self.refresh = function()
  {
    // Empty container
    $(view).empty()

    // Add slider for each layer
    for( var key in self.layers)
    {

      var container = document.createElement("div");

      var setOpac = function ( val )
      {
        self.setOpacity( this.idd, val );
        stack.redraw();
        return;
      }

      self.layers[key].updateOpacity();

      var slider = new Slider(
          SLIDER_HORIZONTAL,
          false,
          1,
          100,
          100,
          self.layers[key].getOpacity() * 100,
          setOpac );

      slider.idd = key;
      container.setAttribute("id", key + "-container");
      container.appendChild( document.createElement("strong").appendChild( document.createTextNode(key)) );
      container.appendChild( slider.getView() );
      view.appendChild(container);
    }
  };

  self.layers = stack.getLayers();

  var view = document.createElement( "div" );
  view.className = "TilelayerControl";
  view.id = "TilelayerControl";
  view.style.zIndex = 8;

  stack.getView().appendChild( view );
};<commit_msg>Layer control: always use up-to-date set of layers<commit_after>/* -*- mode: espresso; espresso-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set softtabstop=2 shiftwidth=2 tabstop=2 expandtab: */

"use strict";

/**
 * The tilelayer control element on the top-left of the stack window
 */
function TilelayerControl( stack )
{
  var self = this;

  /**
   * get the view object
   */
  self.getView = function()
  {
    return view;
  }

  /**
   * set opacity for a layer
   */
  self.setOpacity = function ( key, val )
  {
    // Get current set of layers
    var layers = stack.getLayers();

    if(layers.hasOwnProperty(key))
      layers[key].setOpacity( val / 100 );
  }

  /**
   * removes existing layer controls and re-creates them.
   */
  self.refresh = function()
  {
    // Get current set of layers
    var layers = stack.getLayers();

    // Empty container
    $(view).empty()

    // Add slider for each layer
    for(var key in layers)
    {

      var container = document.createElement("div");

      var setOpac = function ( val )
      {
        self.setOpacity( this.idd, val );
        stack.redraw();
        return;
      }

      // Make layer re-evaluate it's opacity
      layers[key].setOpacity(layers[key].getOpacity());

      var slider = new Slider(
          SLIDER_HORIZONTAL,
          false,
          1,
          100,
          100,
          layers[key].getOpacity() * 100,
          setOpac );

      slider.idd = key;
      container.setAttribute("id", key + "-container");
      container.appendChild( document.createElement("strong").appendChild( document.createTextNode(key)) );
      container.appendChild( slider.getView() );
      view.appendChild(container);
    }
  };

  var view = document.createElement( "div" );
  view.className = "TilelayerControl";
  view.id = "TilelayerControl";
  view.style.zIndex = 8;

  stack.getView().appendChild( view );
};
{'fraction_non_alphanumeric': 0.13525377229080932, 'fraction_numerical': 0.009876543209876543, 'mean_word_length': 2.3449541284403668, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '526653', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1107, 'n_words': 275}