<commit_before>import BaseLayer from 'ol/layer/Base';
import {HsConfig} from '../../config.service';
import {HsEventBusService} from '../core/event-bus.service';
import {HsLayerManagerService} from './layermanager.service';
import {Injectable} from '@angular/core';
@Injectable({
  providedIn: 'root',
})
export class HsLayermanagerPhysicalListService {
  layersCopy: Array<{
    title: string;
    layer: BaseLayer;
    active?: boolean;
  }> = [];
  private readonly reversed = this.HsConfig.reverseLayerList || false;

  constructor(
    public HsEventBusService: HsEventBusService,
    public HsLayerManagerService: HsLayerManagerService,
    public HsConfig: HsConfig
  ) {}
  fillLayers(): any {
    if (this.HsLayerManagerService.data.layers == undefined) {
      return;
    }
    this.layersCopy = this.HsLayerManagerService.sortLayersByZ(
      this.HsLayerManagerService.data.layers.map((l) => {
        return {title: l.title, layer: l.layer};
      })
    );
  }
  moveLayer(baseLayer: BaseLayer, orient: string): void {
    const currentLayerIndex = this.layersCopy.indexOf(baseLayer);
    switch (orient.toLocaleLowerCase()) {
      case 'up':
        if (currentLayerIndex != 0) {
          this.setLayerZIndex(currentLayerIndex - 1, baseLayer.layer);
        }
        break;
      case 'down':
        if (currentLayerIndex < this.layersCopy.length - 1) {
          this.setLayerZIndex(currentLayerIndex + 1, baseLayer.layer);
        }
        break;
      default:
    }
  }
  setLayerZIndex(indexTo: number, layer: any): void {
    const layerSwitchedWith = this.layersCopy[indexTo].layer;
    const interactedLayerZIndex = layer.getZIndex();
    layer.setZIndex(layerSwitchedWith.getZIndex());
    layerSwitchedWith.setZIndex(interactedLayerZIndex);
    this.HsEventBusService.layerManagerUpdates.next(layer);
  }
  moveToBottom(baseLayer: BaseLayer): void {
    const preferredZIndex = this.reversed ? this.getMinZ() : this.getMaxZ();
    this.moveAndShift(baseLayer, preferredZIndex, true);
  }

  moveToTop(baseLayer: BaseLayer): void {
    const preferredZIndex = this.reversed ? this.getMaxZ() : this.getMinZ();
    this.moveAndShift(baseLayer, preferredZIndex, false);
  }

  private moveAndShift(layer: any, preferredZIndex: number, shiftDir: boolean) {
    if (layer.layer.getZIndex() != preferredZIndex) {
      let zIndexVariable = this.getZIndexVariable(shiftDir);
      for (const lyr of this.layersCopy.filter((lyr) => lyr != layer)) {
        lyr.layer.setZIndex(zIndexVariable);
        zIndexVariable += this.reversed ? -1 : 1;
      }
      layer.layer.setZIndex(preferredZIndex);
      this.HsEventBusService.layerManagerUpdates.next(layer);
    }
  }

  getZIndexVariable(toTheListTop: boolean): number {
    if (this.reversed) {
      return !toTheListTop ? this.getMaxZ() - 1 : this.getMaxZ();
    } else {
      return toTheListTop ? this.getMinZ() : this.getMinZ() + 1;
    }
  }

  private zIndexList() {
    return this.layersCopy.map((lyr) => lyr.layer.getZIndex() || 0);
  }

  getMaxZ(): number {
    return Math.max(...this.zIndexList());
  }

  getMinZ(): number {
    return Math.min(...this.zIndexList());
  }
}<commit_msg>moveAndShift olLayers too<commit_after>import BaseLayer from 'ol/layer/Base';
import {HsConfig} from '../../config.service';
import {HsEventBusService} from '../core/event-bus.service';
import {HsLayerManagerService} from './layermanager.service';
import {Injectable} from '@angular/core';
@Injectable({
  providedIn: 'root',
})
export class HsLayermanagerPhysicalListService {
  layersCopy: Array<{
    title: string;
    layer: BaseLayer;
    active?: boolean;
  }> = [];
  private readonly reversed = this.HsConfig.reverseLayerList || false;

  constructor(
    public HsEventBusService: HsEventBusService,
    public HsLayerManagerService: HsLayerManagerService,
    public HsConfig: HsConfig
  ) {}
  fillLayers(): any {
    if (this.HsLayerManagerService.data.layers == undefined) {
      return;
    }
    this.layersCopy = this.HsLayerManagerService.sortLayersByZ(
      this.HsLayerManagerService.data.layers.map((l) => {
        return {title: l.title, layer: l.layer};
      })
    );
  }
  moveLayer(baseLayer: BaseLayer, orient: string): void {
    const currentLayerIndex = this.layersCopy.indexOf(baseLayer);
    switch (orient.toLocaleLowerCase()) {
      case 'up':
        if (currentLayerIndex != 0) {
          this.setLayerZIndex(currentLayerIndex - 1, baseLayer.layer);
        }
        break;
      case 'down':
        if (currentLayerIndex < this.layersCopy.length - 1) {
          this.setLayerZIndex(currentLayerIndex + 1, baseLayer.layer);
        }
        break;
      default:
    }
  }
  setLayerZIndex(indexTo: number, layer: any): void {
    const layerSwitchedWith = this.layersCopy[indexTo].layer;
    const interactedLayerZIndex = layer.getZIndex();
    layer.setZIndex(layerSwitchedWith.getZIndex());
    layerSwitchedWith.setZIndex(interactedLayerZIndex);
    this.HsEventBusService.layerManagerUpdates.next(layer);
  }
  moveToBottom(layer: any): void {
    if (layer === undefined) {
      return;
    }
    const preferredZIndex = this.reversed ? this.getMinZ() : this.getMaxZ();
    this.moveAndShift(this.getOlLayer(layer), preferredZIndex, true);
  }

  moveToTop(layer: any): void {
    if (layer === undefined) {
      return;
    }
    const preferredZIndex = this.reversed ? this.getMaxZ() : this.getMinZ();
    this.moveAndShift(this.getOlLayer(layer), preferredZIndex, false);
  }

  private moveAndShift(
    selectedLayer: any,
    preferredZIndex: number,
    shiftDir: boolean
  ) {
    if (selectedLayer.getZIndex() != preferredZIndex) {
      let zIndexVariable = this.getZIndexVariable(shiftDir);
      for (const lyr of this.layersCopy.filter(
        (lyr) => lyr.layer != selectedLayer
      )) {
        lyr.layer.setZIndex(zIndexVariable);
        zIndexVariable += this.reversed ? -1 : 1;
      }
      selectedLayer.setZIndex(preferredZIndex);
      this.HsEventBusService.layerManagerUpdates.next(selectedLayer);
    }
  }

  getZIndexVariable(toTheListTop: boolean): number {
    if (this.reversed) {
      return !toTheListTop ? this.getMaxZ() - 1 : this.getMaxZ();
    } else {
      return toTheListTop ? this.getMinZ() : this.getMinZ() + 1;
    }
  }
  private getOlLayer(layer: any): any {
    if (layer?.layer) {
      return layer.layer;
    } else {
      return layer;
    }
  }
  private zIndexList() {
    return this.layersCopy.map((lyr) => lyr.layer.getZIndex() || 0);
  }

  getMaxZ(): number {
    return Math.max(...this.zIndexList());
  }

  getMinZ(): number {
    return Math.min(...this.zIndexList());
  }
}
{'fraction_non_alphanumeric': 0.12979616306954436, 'fraction_numerical': 0.002697841726618705, 'mean_word_length': 3.3218911917098444, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '1093836', 'n_tokens_mistral': 2183, 'n_tokens_neox': 2119, 'n_words': 395}