<commit_before>/**
 * Created by <NAME> on 23.05.2017.
 */


import {IVisInstanceOptions} from 'phovea_core/src/vis';
import Histogram, {IHistogramOptions} from 'phovea_vis/src/distribution/Histogram';
import {IStratification} from 'phovea_core/src/stratification';
import {
  IHistAbleDataType, ICategoricalValueTypeDesc, INumberValueTypeDesc,
} from 'phovea_core/src/datatype';

export interface ILabelOptions extends IVisInstanceOptions {
  /**
   * width
   * @default 200
   */
  width?: number;

  /**
   * scale such that the height matches the argument
   * @default 100
   */
  heightTo?: number;
}

/**
 * Switches to a mosaic representation if only one bin is present
 */
export class SpecialHistogram extends Histogram {

  constructor(public readonly data: IHistAbleDataType<ICategoricalValueTypeDesc|INumberValueTypeDesc>|IStratification, parent: Element, options: ILabelOptions = {}) {
    super(data, parent, options);

  }
  protected build($parent: d3.Selection<any>) {
    const size = this.size,
      data = this.data,
      o = this.options;

    const $svg = $parent.append('svg').attr({
      width: size[0],
      height: size[1],
      'class': 'phovea-histogram'
    });

    return $svg;
  }

}

export default SpecialHistogram;

export function create(data: IHistAbleDataType<ICategoricalValueTypeDesc|INumberValueTypeDesc>, parent: Element, options?: IHistogramOptions) {
  return new SpecialHistogram(data, parent, options);
}
<commit_msg>Added logic for deciding if only one bin is present<commit_after>/**
 * Created by <NAME> on 23.05.2017.
 */


import {IVisInstanceOptions} from 'phovea_core/src/vis';
import Histogram, {IHistogramOptions} from 'phovea_vis/src/distribution/Histogram';
import {IStratification} from 'phovea_core/src/stratification';
import {
  IHistAbleDataType, ICategoricalValueTypeDesc, INumberValueTypeDesc,
} from 'phovea_core/src/datatype';
import * as d3 from 'd3';

export interface ILabelOptions extends IVisInstanceOptions {
  /**
   * width
   * @default 200
   */
  width?: number;

  /**
   * scale such that the height matches the argument
   * @default 100
   */
  heightTo?: number;
}

/**
 * Switches to a mosaic representation if only one bin is present
 */
export class SpecialHistogram extends Histogram {

  constructor(public readonly data: IHistAbleDataType<ICategoricalValueTypeDesc|INumberValueTypeDesc>|IStratification, parent: Element, options: ILabelOptions = {}) {
    super(data, parent, options);

  }
  protected build($parent: d3.Selection<any>) {
   const $svg = super.build($parent);
    this.data.hist(Math.floor(this.options.nbins)).then((hist) => {
      const arr : number[] = [];

      let foundNonZero = false;
      hist.forEach(function(value, index) {
        if(value > 0) {
          if(foundNonZero) {
            return;
          }
          foundNonZero = true;
        }
      });
      if(foundNonZero) {
        this.buildAsMosaic();
      }
    });
    return $svg;
  }

  private buildAsMosaic() {

  }
}

export default SpecialHistogram;

export function create(data: IHistAbleDataType<ICategoricalValueTypeDesc|INumberValueTypeDesc>, parent: Element, options?: IHistogramOptions) {
  return new SpecialHistogram(data, parent, options);
}

{'fraction_non_alphanumeric': 0.11357340720221606, 'fraction_numerical': 0.01077254539858418, 'mean_word_length': 3.9019607843137254, 'pattern_counts': {'":': 0, '<': 11, '<?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': '4093197', 'n_tokens_mistral': 1037, 'n_tokens_neox': 998, 'n_words': 242}