<commit_before>'use strict';

const d3 = require('d3');

export default class D3Tree {

  constructor(options) {
    this.tree = null;
    this.container = null;
    this.isVertical = true;
    this.options = Object.assign({
      width: 800,
      height: 600,
      duration: 0,
      selector: 'body',
      prefixClass: 'd3-tree',
      imageWidth: 100,
      imageHeight: 100,
      direction: 'vertical',
      margin: {
        left: 10,
        right: 10,
        top: 10,
        bottom: 10
      },
      data: []
    }, options);
  }

  init() {
    this.isVertical = this.options.direction === 'vertical';

    if (this.isVertical) {
      this.diagonal = d3
        .linkVertical()
        .x(d => {
          return d.x;
        })
        .y(d => {
          return d.y;
        });
    } else {
      this.diagonal = d3
        .linkHorizontal()
        .x(d => {
          return d.y;
        })
        .y(d => {
          return d.x;
        });
    }
    this.tree = d3
      .tree()
      .size(
      this.isVertical ?
        [
          this.options.width - this.options.margin.left - this.options.margin.right - 2 * this.options.imageWidth,
          this.options.height - this.options.margin.top - this.options.margin.bottom - 2 * this.options.imageHeight
        ] : [
          this.options.height - this.options.margin.top - this.options.margin.bottom - 2 * this.options.imageHeight,
          this.options.width - this.options.margin.left - this.options.margin.right - 2 * this.options.imageWidth
        ]);
    this.container = d3
      .select(this.options.selector)
      .append('svg')
      .attr('width', this.options.width)
      .attr('height', this.options.height)
      .append('g')
      .attr('transform', `translate(${this.options.imageWidth / 2}, ${this.options.imageHeight / 2})`);
    this.render();
  }

  render() {
    var nodesData = this.tree(d3.hierarchy(this.options.data, d => {
      return d.children;
    }));
    this.container.selectAll(`.${this.options.prefixClass}-node`).remove();
    this.container.selectAll(`.${this.options.prefixClass}-link`).remove();
    var node = this.container
      .selectAll(`.${this.options.prefixClass}-node`);
    var link = this.container
      .selectAll(`.${this.options.prefixClass}-link`);
    var container = node
      .data(nodesData.descendants())
      .enter()
      .append('g')
      .attr('class', `${this.options.prefixClass}-node`)

    container
      .append('image')
      .attr('class', `${this.options.prefixClass}-image`)
      .attr('xlink:href', d => {
        return d.data.data.image;
      })
      .attr(this.isVertical ? 'x' : 'y', d => {
        return d.x - this.options.imageWidth / 2;
      })
      .attr(this.isVertical ? 'y' : 'x', d => {
        return d.y;
      });

    container
      .append('text')
      .attr('fill', '#111')
      .attr('text-anchor', 'middle')
      .attr('class', `${this.options.prefixClass}-text`)
      .text(d => {
        return d.data.data.text;
      })
      .attr(this.isVertical ? 'x' : 'y', d => {
        return d.x;
      })
      .attr(this.isVertical ? 'y' : 'x', d => {
        return d.y + this.options.imageHeight + 30;<commit_msg>adaption<commit_after>'use strict';

const d3 = require('d3');

export default class D3Tree {

  constructor(options) {
    this.tree = null;
    this.container = null;
    this.isVertical = true;
    this.options = Object.assign({
      width: 800,
      height: 600,
      duration: 0,
      selector: 'body',
      prefixClass: 'd3-tree',
      imageWidth: 100,
      imageHeight: 100,
      direction: 'vertical',
      margin: {
        left: 10,
        right: 10,
        top: 10,
        bottom: 10
      },
      data: []
    }, options);
  }

  init() {
    this.isVertical = this.options.direction === 'vertical';

    if (this.isVertical) {
      this.diagonal = d3
        .linkVertical()
        .x(d => {
          return d.x;
        })
        .y(d => {
          return d.y;
        });
    } else {
      this.diagonal = d3
        .linkHorizontal()
        .x(d => {
          return d.y;
        })
        .y(d => {
          return d.x;
        });
    }
    this.tree = d3
      .tree()
      .size(
      this.isVertical ?
        [
          this.options.width - this.options.margin.left - this.options.margin.right - 2 * this.options.imageWidth,
          this.options.height - this.options.margin.top - this.options.margin.bottom - 2 * this.options.imageHeight
        ] : [
          this.options.height - this.options.margin.top - this.options.margin.bottom - 2 * this.options.imageHeight,
          this.options.width - this.options.margin.left - this.options.margin.right - 2 * this.options.imageWidth
        ]);
    this.container = d3
      .select(this.options.selector)
      .append('svg')
      .attr('width', this.options.width)
      .attr('height', this.options.height)
      .append('g')
      .attr('transform', `translate(${this.options.imageWidth / 2}, ${this.options.imageHeight / 2})`);
    this.render();
  }

  render() {
    var nodesData = this.tree(d3.hierarchy(this.options.data, d => {
      return d.children;
    }));
    this.container.selectAll(`.${this.options.prefixClass}-node`).remove();
    this.container.selectAll(`.${this.options.prefixClass}-link`).remove();
    var node = this.container
      .selectAll(`.${this.options.prefixClass}-node`);
    var link = this.container
      .selectAll(`.${this.options.prefixClass}-link`);
    var container = node
      .data(nodesData.descendants())
      .enter()
      .append('g')
      .attr('class', `${this.options.prefixClass}-node`);

    container
      .append('image')
      .attr('class', `${this.options.prefixClass}-image`)
      .attr('xlink:href', d => {
        return d.data.data.image;
      })
      .attr(this.isVertical ? 'x' : 'y', d => {
        return d.x - this.options.imageWidth / 2;
      })
      .attr(this.isVertical ? 'y' : 'x', d => {
        return d.y;
      });

    container
      .append('text')
      .attr('fill', '#111')
      .attr('text-anchor', 'middle')
      .attr('class', `${this.options.prefixClass}-text`)
      .text(d => {
        return d.data.data.text;
      })
      .attr(this.isVertical ? 'x' : 'y', d => {
        return d.x;
      })
      .attr(this.isVertical ? 'y' : 'x', d => {
        return d.y + this.options.imageHeight + 30;
{'fraction_non_alphanumeric': 0.17046163443543355, 'fraction_numerical': 0.013100436681222707, 'mean_word_length': 1.9243046055631554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '1249420', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2057, 'n_words': 363}