<commit_before>import Ember from 'ember';

import { select } from 'd3-selection';
import { scaleOrdinal, scaleBand, scaleLinear, schemeCategory10 } from 'd3-scale';
import { max } from 'd3-array';
import { axisBottom, axisLeft } from 'd3-axis';
import { stack } from 'd3-shape';

const { Component, run, get } = Ember;

export default Component.extend({
  tagName: 'svg',
  classNames: ['chart-bar-stacked'],
  attributeBindings: ['width', 'height'],
  didReceiveAttrs() {
    // Anytime we get an update schedule a draw
    run.scheduleOnce('render', this, this.draw);
  },
  data: null,
  width: null,
  height: null,
  draw(){
    const data = get(this, 'data') || [];
    const svg = select(this.element);
    const margin = {top: 0, right: 20, bottom: 40, left: 20};
    const chartWidth = get(this, 'width') - margin.left - margin.right;
    const chartHeight = get(this, 'height') - margin.top - margin.bottom;
    const color = scaleOrdinal(schemeCategory10);

    const x = scaleBand().range([0, chartWidth]).padding(0.4);
    const y = scaleLinear().range([chartHeight, 0]);
    const z = scaleOrdinal(schemeCategory10);

    var keys_set = {};
    var keys_list = [];

    let reformattedData = data.map((d) => {
      let obj = {label: d.label, total: d.total};
      d.values.forEach((value, index) => {
        var value_key = value.label + '-' + index;
        obj[value_key] = value.value;
        if (!keys_set[value_key]) {
          keys_set[value_key] = 1;
          keys_list.push(value_key);
        }
      });
      return obj;
    }).map((d) => {
      keys_list.forEach((key) => {
        d[key] = d[key] || 0;
      });
      return d;
    });

    const dataOrArray = reformattedData?reformattedData:[];

    x.domain(dataOrArray.map(d => d.label));
    y.domain([0, max(dataOrArray, d => d.total)]);
    z.domain(keys_list);

    svg.append('g').attr('transform', "translate(" + margin.left + "," + margin.top + ")");

    svg.selectAll('.bar')
      .data(stack().keys(keys_list)(dataOrArray))
      .enter().append("g")
      .attr("class", "bar")
      .attr("fill", function(d) { return z(d.key); })
      .selectAll("rect")
      .data(function(d) { return d; })
      .enter().append("rect")
      .attr("x", function(d) { return x(d.data.label); })
      .attr("y", function(d) { return y(d[1]); })
      .attr("height", function(d) {return y(d[0]) - y(d[1]); })
      .attr("width", x.bandwidth());

    svg.append("g").attr("transform", "translate(0," + chartHeight + ")").call(axisBottom(x))
      .selectAll("text")
      .attr("y", 0)
      .attr("x", 9)
      .attr("dy", ".35em")
      .attr("transform", "rotate(75)")
      .style("text-anchor", "start");

    svg.append("g").call(axisLeft(y).ticks(10, "s"))
      .selectAll("text")
      .attr("x", 4)
      .attr("y", y(y.ticks(10).pop()) + 0.5)
      .attr("dy", "0.35em")
      .attr("text-anchor", "start")
      .attr("fill", d =>  color(d.label));<commit_msg>Fix color error<commit_after>import Ember from 'ember';

import { select } from 'd3-selection';
import { scaleOrdinal, scaleBand, scaleLinear, schemeCategory10 } from 'd3-scale';
import { max } from 'd3-array';
import { axisBottom, axisLeft } from 'd3-axis';
import { stack } from 'd3-shape';

const { Component, run, get } = Ember;

export default Component.extend({
  tagName: 'svg',
  classNames: ['chart-bar-stacked'],
  attributeBindings: ['width', 'height'],
  didReceiveAttrs() {
    // Anytime we get an update schedule a draw
    run.scheduleOnce('render', this, this.draw);
  },
  data: null,
  width: null,
  height: null,
  draw(){
    const data = get(this, 'data') || [];
    const svg = select(this.element);
    const margin = {top: 0, right: 20, bottom: 40, left: 20};
    const chartWidth = get(this, 'width') - margin.left - margin.right;
    const chartHeight = get(this, 'height') - margin.top - margin.bottom;

    const x = scaleBand().range([0, chartWidth]).padding(0.4);
    const y = scaleLinear().range([chartHeight, 0]);
    const z = scaleOrdinal(schemeCategory10);

    var keys_set = {};
    var keys_list = [];

    let reformattedData = data.map((d) => {
      let obj = {label: d.label, total: d.total};
      d.values.forEach((value, index) => {
        var value_key = value.label + '-' + index;
        obj[value_key] = value.value;
        if (!keys_set[value_key]) {
          keys_set[value_key] = 1;
          keys_list.push(value_key);
        }
      });
      return obj;
    }).map((d) => {
      keys_list.forEach((key) => {
        d[key] = d[key] || 0;
      });
      return d;
    });

    const dataOrArray = reformattedData?reformattedData:[];

    x.domain(dataOrArray.map(d => d.label));
    y.domain([0, max(dataOrArray, d => d.total)]);
    z.domain(keys_list);

    svg.append('g').attr('transform', "translate(" + margin.left + "," + margin.top + ")");

    svg.append("g").attr("transform", "translate(0," + chartHeight + ")").call(axisBottom(x))
      .selectAll("text")
      .attr("y", 0)
      .attr("x", 9)
      .attr("dy", ".35em")
      .attr("transform", "rotate(75)")
      .style("text-anchor", "start");

    svg.append("g").call(axisLeft(y).ticks(10, "s"))
      .selectAll("text")
      .attr("x", 4)
      .attr("y", y(y.ticks(10).pop()) + 0.5)
      .attr("dy", "0.35em")
      .attr("text-anchor", "start")
      .attr("fill", "#000");

    svg.selectAll('.bar')
      .data(stack().keys(keys_list)(dataOrArray))
      .enter().append("g")
      .attr("class", "bar")
      .attr("fill", function(d) { return z(d.key); })
      .selectAll("rect")
      .data(function(d) { return d; })
      .enter().append("rect")
      .attr("x", function(d) { return x(d.data.label); })
      .attr("y", function(d) { return y(d[1]); })
      .attr("height", function(d) {return y(d[0]) - y(d[1]); })
      .attr("width", x.bandwidth());
{'fraction_non_alphanumeric': 0.20504947117024905, 'fraction_numerical': 0.015523712043671102, 'mean_word_length': 2.916499665998664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '2473027', 'n_tokens_mistral': 2087, 'n_tokens_neox': 2015, 'n_words': 423}