<commit_before>import {Channel} from '../channel';
import {defaultConfig, CellConfig, Config} from '../config';
import {FieldDef} from '../fielddef';
import {Legend} from '../legend';
import {Scale} from '../scale';
import {Axis} from '../axis';
import {LayerSpec} from '../spec';
import {StackProperties} from '../stack';
import {FILL_STROKE_CONFIG} from '../mark';
import {keys, duplicate, mergeDeep, flatten, vals, Dict} from '../util';
import {VgData, VgEncodeEntry} from '../vega.schema';
import {isUrlData} from '../data';

import {assembleData, parseLayerData} from './data/data';
import {applyConfig, buildModel} from './common';
import {assembleLayout, parseLayerLayout} from './layout';
import {Model} from './model';
import {UnitModel} from './unit';

import {ScaleComponents} from './scale/scale';
import {unionDomains} from './scale/domain';


export class LayerModel extends Model {
  public readonly children: UnitModel[];

  protected readonly scales: Dict<Scale> = {};

  protected readonly axes: Dict<Axis> = {};

  protected readonly legends: Dict<Legend> = {};

  public readonly config: Config;

  public readonly stack: StackProperties = null;

  /**
   * Fixed width for the unit visualization.
   * If undefined (e.g., for ordinal scale), the width of the
   * visualization will be calculated dynamically.
   */
  public readonly width: number;

  /**
   * Fixed height for the unit visualization.
   * If undefined (e.g., for ordinal scale), the height of the
   * visualization will be calculated dynamically.
   */
  public readonly height: number;

  constructor(spec: LayerSpec, parent: Model, parentGivenName: string) {
    super(spec, parent, parentGivenName);

    this.width = spec.width;
    this.height = spec.height;

    this.config = this.initConfig(spec.config, parent);
    this.children = spec.layer.map((layer, i) => {
      // we know that the model has to be a unit model because we pass in a unit spec
      return buildModel(layer, this, this.getName('layer_' + i)) as UnitModel;
    });
  }

  private initConfig(specConfig: Config, parent: Model) {
    return mergeDeep(duplicate(defaultConfig), specConfig, parent ? parent.config : {});
  }

  public channelHasField(_: Channel): boolean {
    // layer does not have any channels
    return false;
  }

  public hasDiscreteScale(channel: Channel) {
    // since we assume shared scales we can just ask the first child
    return this.children[0].hasDiscreteScale(channel);
  }

  public dataTable() {
    // FIXME: don't just use the first child
    return this.children[0].dataTable();
  }

  public fieldDef(_: Channel): FieldDef {
    return null; // layer does not have field defs
  }

  public parseData() {
    this.children.forEach((child) => {
      child.parseData();
    });
    this.component.data = parseLayerData(this);
  }

  public parseSelectionData() {
    // TODO: @arvind can write this
    // We might need to split this into compileSelectionData and compileSelectionSignals?
  }

  public parseLayoutData() {
    // TODO: correctly union ordinal scales rather than just using the layout of the first child
    this.children.forEach(child => {
      child.parseLayoutData();
    });
    this.component.layout = parseLayerLayout(this);
  }
<commit_msg>unused parameters are okay<commit_after>import {Channel} from '../channel';
import {defaultConfig, CellConfig, Config} from '../config';
import {FieldDef} from '../fielddef';
import {Legend} from '../legend';
import {Scale} from '../scale';
import {Axis} from '../axis';
import {LayerSpec} from '../spec';
import {StackProperties} from '../stack';
import {FILL_STROKE_CONFIG} from '../mark';
import {keys, duplicate, mergeDeep, flatten, vals, Dict} from '../util';
import {VgData, VgEncodeEntry} from '../vega.schema';
import {isUrlData} from '../data';

import {assembleData, parseLayerData} from './data/data';
import {applyConfig, buildModel} from './common';
import {assembleLayout, parseLayerLayout} from './layout';
import {Model} from './model';
import {UnitModel} from './unit';

import {ScaleComponents} from './scale/scale';
import {unionDomains} from './scale/domain';


export class LayerModel extends Model {
  public readonly children: UnitModel[];

  protected readonly scales: Dict<Scale> = {};

  protected readonly axes: Dict<Axis> = {};

  protected readonly legends: Dict<Legend> = {};

  public readonly config: Config;

  public readonly stack: StackProperties = null;

  /**
   * Fixed width for the unit visualization.
   * If undefined (e.g., for ordinal scale), the width of the
   * visualization will be calculated dynamically.
   */
  public readonly width: number;

  /**
   * Fixed height for the unit visualization.
   * If undefined (e.g., for ordinal scale), the height of the
   * visualization will be calculated dynamically.
   */
  public readonly height: number;

  constructor(spec: LayerSpec, parent: Model, parentGivenName: string) {
    super(spec, parent, parentGivenName);

    this.width = spec.width;
    this.height = spec.height;

    this.config = this.initConfig(spec.config, parent);
    this.children = spec.layer.map((layer, i) => {
      // we know that the model has to be a unit model because we pass in a unit spec
      return buildModel(layer, this, this.getName('layer_' + i)) as UnitModel;
    });
  }

  private initConfig(specConfig: Config, parent: Model) {
    return mergeDeep(duplicate(defaultConfig), specConfig, parent ? parent.config : {});
  }

  public channelHasField(channel: Channel): boolean {
    // layer does not have any channels
    return false;
  }

  public hasDiscreteScale(channel: Channel) {
    // since we assume shared scales we can just ask the first child
    return this.children[0].hasDiscreteScale(channel);
  }

  public dataTable() {
    // FIXME: don't just use the first child
    return this.children[0].dataTable();
  }

  public fieldDef(channel: Channel): FieldDef {
    return null; // layer does not have field defs
  }

  public parseData() {
    this.children.forEach((child) => {
      child.parseData();
    });
    this.component.data = parseLayerData(this);
  }

  public parseSelectionData() {
    // TODO: @arvind can write this
    // We might need to split this into compileSelectionData and compileSelectionSignals?
  }

  public parseLayoutData() {
    // TODO: correctly union ordinal scales rather than just using the layout of the first child
    this.children.forEach(child => {
      child.parseLayoutData();
    });
    this.component.layout = parseLayerLayout(this);
  }

{'fraction_non_alphanumeric': 0.126389523374448, 'fraction_numerical': 0.0006091061367443277, 'mean_word_length': 3.638418079096045, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '5483862', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1814, 'n_words': 637}