<commit_before>///<reference path="../reference.ts" />

module Plottable {
  export class Component extends PlottableObject {
    public element: D3.Selection;
    public content: D3.Selection;
    private hitBox: D3.Selection;
    private interactionsToRegister: Interaction[] = [];
    private boxes: D3.Selection[] = [];
    private boxContainer: D3.Selection;
    public backgroundContainer: D3.Selection;
    public foregroundContainer: D3.Selection;
    public clipPathEnabled = false;
    private broadcastersCurrentlyListeningTo: {[key: string]: Broadcaster} = {};
    private hasBeenRemoved = false;

    public _fixedWidth = true;
    public _fixedHeight = true;
    private _minimumHeight = 0;
    private _minimumWidth = 0;

    private rootSVG: D3.Selection;
    private isTopLevelComponent = false;

    public availableWidth : number; // Width and height of the component. Used to size the hitbox, bounding box, etc
    public availableHeight: number;
    public xOrigin        : number; // Origin of the coordinate space for the component. Passed down from parent
    public yOrigin        : number;
    private _xOffset = 0; // Offset from Origin, used for alignment and floating positioning
    private _yOffset = 0;
    public _xAlignProportion = 0; // What % along the free space do we want to position (0 = left, .5 = center, 1 = right)
    public _yAlignProportion = 0;

    private cssClasses: string[] = ["component"];

    /**
     * Attaches the Component to a DOM element. Usually only directly invoked on root-level Components.
     *
     * @param {D3.Selection} element A D3 selection consisting of the element to anchor to.
     * @returns {Component} The calling component.
     */
    public _anchor(element: D3.Selection) {
      if (element.node().childNodes.length > 0) {
        throw new Error("Can't anchor to a non-empty element");
      }
      if (this.hasBeenRemoved) {
        // Since we deregister all the model bindings, this would be dangerous
        throw new Error("Cannot reuse a component after removing it");
      }
      if (element.node().nodeName === "svg") {
        // svg node gets the "plottable" CSS class
        this.rootSVG = element;
        this.rootSVG.classed("plottable", true);
        // visible overflow for firefox https://stackoverflow.com/questions/5926986/why-does-firefox-appear-to-truncate-embedded-svgs
        this.rootSVG.style("overflow", "visible");
        this.element = element.append("g");
        this.isTopLevelComponent = true;
      } else {
        this.element = element;
      }

      this.cssClasses.forEach((cssClass: string) => {
        this.element.classed(cssClass, true);
      });
      this.cssClasses = null;

      this.backgroundContainer = this.element.append("g").classed("background-container", true);
      this.content = this.element.append("g").classed("content", true);
      this.foregroundContainer = this.element.append("g").classed("foreground-container", true);
      this.boxContainer = this.element.append("g").classed("box-container", true);

      if (this.clipPathEnabled) {
        this.generateClipPath();
      };
<commit_msg>Component should throw an error if re-anchoring is attempted<commit_after>///<reference path="../reference.ts" />

module Plottable {
  export class Component extends PlottableObject {
    public element: D3.Selection;
    public content: D3.Selection;
    private hitBox: D3.Selection;
    private interactionsToRegister: Interaction[] = [];
    private boxes: D3.Selection[] = [];
    private boxContainer: D3.Selection;
    public backgroundContainer: D3.Selection;
    public foregroundContainer: D3.Selection;
    public clipPathEnabled = false;
    private broadcastersCurrentlyListeningTo: {[key: string]: Broadcaster} = {};
    private hasBeenRemoved = false;

    public _fixedWidth = true;
    public _fixedHeight = true;
    private _minimumHeight = 0;
    private _minimumWidth = 0;

    private rootSVG: D3.Selection;
    private isTopLevelComponent = false;

    public availableWidth : number; // Width and height of the component. Used to size the hitbox, bounding box, etc
    public availableHeight: number;
    public xOrigin        : number; // Origin of the coordinate space for the component. Passed down from parent
    public yOrigin        : number;
    private _xOffset = 0; // Offset from Origin, used for alignment and floating positioning
    private _yOffset = 0;
    public _xAlignProportion = 0; // What % along the free space do we want to position (0 = left, .5 = center, 1 = right)
    public _yAlignProportion = 0;

    private cssClasses: string[] = ["component"];

    /**
     * Attaches the Component to a DOM element. Usually only directly invoked on root-level Components.
     *
     * @param {D3.Selection} element A D3 selection consisting of the element to anchor to.
     * @returns {Component} The calling component.
     */
    public _anchor(element: D3.Selection) {
      if (element.node().childNodes.length > 0) {
        throw new Error("Can't anchor to a non-empty element");
      }
      if (this.hasBeenRemoved) {
        // Since we deregister all the model bindings, this would be dangerous
        throw new Error("Cannot reuse a component after removing it");
      }
      if (this.element != null) {
        throw new Error("Cannot re-anchor a component after it is already anchored");
      }
      if (element.node().nodeName === "svg") {
        // svg node gets the "plottable" CSS class
        this.rootSVG = element;
        this.rootSVG.classed("plottable", true);
        // visible overflow for firefox https://stackoverflow.com/questions/5926986/why-does-firefox-appear-to-truncate-embedded-svgs
        this.rootSVG.style("overflow", "visible");
        this.element = element.append("g");
        this.isTopLevelComponent = true;
      } else {
        this.element = element;
      }

      this.cssClasses.forEach((cssClass: string) => {
        this.element.classed(cssClass, true);
      });
      this.cssClasses = null;

      this.backgroundContainer = this.element.append("g").classed("background-container", true);
      this.content = this.element.append("g").classed("content", true);
      this.foregroundContainer = this.element.append("g").classed("foreground-container", true);
      this.boxContainer = this.element.append("g").classed("box-container", true);

      if (this.clipPathEnabled) {
        this.generateClipPath();
      };

{'fraction_non_alphanumeric': 0.10886661526599846, 'fraction_numerical': 0.008635312259059369, 'mean_word_length': 3.0160990712074303, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '4893350', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1743, 'n_words': 538}