<commit_before>import {IFormElementDesc, IFormParent} from '../interfaces';
import * as d3 from 'd3';
import {AFormElement} from './AFormElement';
import {IFormSelectOption} from './FormSelect';

export interface IRadioElementDesc extends IFormElementDesc {
  options: {
    buttons: IFormSelectOption[];
  };
}

export default class FormRadio extends AFormElement<IRadioElementDesc> {

  /**
   * Constructor
   * @param parent
   * @param $parent
   * @param desc
   */
  constructor(parent: IFormParent, $parent: d3.Selection<any>, desc: IRadioElementDesc) {
    super(parent, Object.assign({options: { buttons: [] }}, desc));

    this.$node = $parent.append('div');

    this.build();
  }

  /**
   * Build the label and input element
   * Bind the change listener and propagate the selection by firing a change event
   */
  protected build() {
    super.build();
    const $label = this.$node.select('label');

    const options = this.desc.options;
    // this.setAttributes(this.$input, this.desc.attributes);
    const $buttons = this.$node.selectAll('label.radio-inline').data(options.buttons);
    $buttons.enter().append('label').classed('radio-inline', true).html((d, i) => `<input type="radio" name="${this.id}" id="${this.id}${i === 0 ? '' : i}" value="${d.value}"> ${d.name}`);

    $buttons.select('input').on('change', (d) => {
      this.fire(FormRadio.EVENT_CHANGE, d, $buttons);
    });

    const defaultOption = options.buttons[0].data;
    const defaultValue = this.getStoredValue(defaultOption);
    this.value = defaultValue;
    this.previousValue = defaultValue;

    if (defaultValue !== defaultOption) {
      this.fire(FormRadio.EVENT_INITIAL_VALUE, this.value, defaultOption);
    }

    this.handleDependent();
  }

  /**
   * Returns the value
   * @returns {string}
   */
  get value() {<commit_msg>apply custom classes for FormRadio element<commit_after>import {IFormElementDesc, IFormParent} from '../interfaces';
import * as d3 from 'd3';
import {AFormElement} from './AFormElement';
import {IFormSelectOption} from './FormSelect';

export interface IRadioElementDesc extends IFormElementDesc {
  options: {
    buttons: IFormSelectOption[];
  };
}

export default class FormRadio extends AFormElement<IRadioElementDesc> {

  /**
   * Constructor
   * @param parent
   * @param $parent
   * @param desc
   */
  constructor(parent: IFormParent, $parent: d3.Selection<any>, desc: IRadioElementDesc) {
    super(parent, Object.assign({options: { buttons: [] }}, desc));

    this.$node = $parent.append('div');

    this.build();
  }

  /**
   * Build the label and input element
   * Bind the change listener and propagate the selection by firing a change event
   */
  protected build() {
    super.build();
    const $label = this.$node.select('label');

    const options = this.desc.options;
    // this.setAttributes(this.$input, this.desc.attributes);
    const $buttons = this.$node.selectAll('label.radio-inline').data(options.buttons);
    $buttons.enter().append('label').classed('radio-inline', true).html((d, i) => `<input type="radio" name="${this.id}" id="${this.id}${i === 0 ? '' : i}" value="${d.value}"> ${d.name}`);

    const $buttonElements = $buttons.select('input');

    $buttonElements.on('change', (d) => {
      this.fire(FormRadio.EVENT_CHANGE, d, $buttons);
    });

    this.setAttributes($buttonElements, this.desc.attributes);

    const defaultOption = options.buttons[0].data;
    const defaultValue = this.getStoredValue(defaultOption);
    this.value = defaultValue;
    this.previousValue = defaultValue;

    if (defaultValue !== defaultOption) {
      this.fire(FormRadio.EVENT_INITIAL_VALUE, this.value, defaultOption);
    }

    this.handleDependent();
  }

  /**
   * Returns the value
   * @returns {string}
   */
  get value() {
{'fraction_non_alphanumeric': 0.15962194801785246, 'fraction_numerical': 0.002625360987135731, 'mean_word_length': 3.828897338403042, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '1054135', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1153, 'n_words': 260}