<commit_before>import * as React from "react";
import { TRACE_RENDERING, COLORS, Rectangle, Histogram, Vector, hashString } from "./analyzerTools";

export class HistogramComponent extends React.Component<{
  histograms: Histogram[];
  highlight?: number;
  width?: number;
  height?: number;
  scale?: string | number;
  color?: (name: string) => string;
  horizontal?: boolean;
}, {
}> {
  public static defaultProps = {
    width: 128,
    height: 128,
    scale: "relative",
    horizontal: true,
    color: function (name: string) {
      return COLORS[hashString(name) % COLORS.length];
    }
  };
  canvas: HTMLCanvasElement;
  ctx: CanvasRenderingContext2D;
  ratio: number;
  w: number;
  h: number;
  position: Vector;
  constructor() {
    super();
    this.ratio = window.devicePixelRatio || 1;
    this.position = new Vector(-1, -1);
  }
  componentDidUpdate(prevProps, prevState) {
    this.renderHistogram(this.ctx, this.props.histograms);
  }
  componentDidMount() {
    let w = this.w = this.props.width;
    let h = this.h = this.props.height;
    this.canvas.style.width = w + "px";
    this.canvas.style.height = h + "px";
    this.canvas.width = w * this.ratio;
    this.canvas.height = h * this.ratio;
    this.ctx = this.canvas.getContext("2d");
    this.renderHistogram(this.ctx, this.props.histograms);
    this.canvas.addEventListener("mousemove", this.handleMouseEvent.bind(this));
  }
  componentWillUnmount() {

  }
  renderHistogram(ctx: CanvasRenderingContext2D, histograms: Histogram[]) {
    TRACE_RENDERING && console.log("renderHistogram");
    let names: string [] = null;
    let nameMap: { [id: string]: number };
    if (!histograms.length) {
      return;
    }
    nameMap = histograms[0].names;<commit_msg>Don't crash if histogram data is not available.<commit_after>import * as React from "react";
import { TRACE_RENDERING, COLORS, Rectangle, Histogram, Vector, hashString } from "./analyzerTools";

export class HistogramComponent extends React.Component<{
  histograms: Histogram[];
  highlight?: number;
  width?: number;
  height?: number;
  scale?: string | number;
  color?: (name: string) => string;
  horizontal?: boolean;
}, {
}> {
  public static defaultProps = {
    width: 128,
    height: 128,
    scale: "relative",
    horizontal: true,
    color: function (name: string) {
      return COLORS[hashString(name) % COLORS.length];
    }
  };
  canvas: HTMLCanvasElement;
  ctx: CanvasRenderingContext2D;
  ratio: number;
  w: number;
  h: number;
  position: Vector;
  constructor() {
    super();
    this.ratio = window.devicePixelRatio || 1;
    this.position = new Vector(-1, -1);
  }
  componentDidUpdate(prevProps, prevState) {
    this.renderHistogram(this.ctx, this.props.histograms);
  }
  componentDidMount() {
    let w = this.w = this.props.width;
    let h = this.h = this.props.height;
    this.canvas.style.width = w + "px";
    this.canvas.style.height = h + "px";
    this.canvas.width = w * this.ratio;
    this.canvas.height = h * this.ratio;
    this.ctx = this.canvas.getContext("2d");
    this.renderHistogram(this.ctx, this.props.histograms);
    this.canvas.addEventListener("mousemove", this.handleMouseEvent.bind(this));
  }
  componentWillUnmount() {

  }
  renderHistogram(ctx: CanvasRenderingContext2D, histograms: Histogram[]) {
    TRACE_RENDERING && console.log("renderHistogram");
    let names: string [] = null;
    let nameMap: { [id: string]: number };
    if (!histograms.length || !histograms[0]) {
      return;
    }
    nameMap = histograms[0].names;
{'fraction_non_alphanumeric': 0.14120631341600903, 'fraction_numerical': 0.007609921082299887, 'mean_word_length': 3.591203104786546, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2734475', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1135, 'n_words': 261}