<commit_before>HospitalCheckup.module("Common.Chart", function(Chart, HospitalCheckup, Backbone, Marionette, $, _){

  //all the common elements that all list charts in hospital app will share
  Chart.BarBase = ChartBaseView.extend({
    constructor: function(options) {
      ChartBaseView.apply(this, arguments);
      this.options.bar_padding = options.bar_padding || 4;
      this.options.section = options.section || "infections";
      this.options.stat = options.stat || "ratio";
      this.duration = 500;
      this.easing = "sin-in-out"; // https://github.com/mbostock/d3/wiki/Transitions#wiki-d3_ease
      this.bar_height = (this.dimensions.height / this.collection.length) - this.options.bar_padding;
      this.$chart_container.attr('id', this.el.id+"-container");
      return this;
    },
    draw: function() {
      var data = this.filter_data(this.data);
      this.get_scales(data);
      this.create_axis("x", "bottom"); //super
      this.create_axis("y", "left"); //super
      this.create_svg(); //super
      this.create_svg_containers();
      this.draw_base_bars(data);
      this.draw_data(data);
      this.draw_axes(data);//needs to be on top of bars
    },

    //remove items with no data and sort by stat
    filter_data: function(){
      var chart = this,
      section = chart.options.section,
      stat = chart.options.stat;

      var filtered = chart.data.filter(function(d){
        return d[section][chart.options.measure].na != 1;
      });
      filtered.sort(function(a,b){
        return d3.ascending(a[section][chart.options.measure][stat], b[section][chart.options.measure][stat]);
      });
      return filtered;
    },

    get_xMax: function(data){
      var chart = this;
      return d3.max(data, function(d) { return d[chart.options.section][chart.options.measure].upper });
    },

    get_currentHeight: function(data){
      return (this.options.bar_padding + this.bar_height) * data.length;
    },

    get_scales: function(data) {
      var chart = this;
      chart.yScale = d3.scale.ordinal()
        .rangeBands([0, chart.get_currentHeight(data)])
        .domain(_.map(data, function(d) { return d.display_name; }));

      chart.xScale = d3.scale.linear()
        .rangeRound([0, chart.dimensions.width])
        .domain([0, chart.get_xMax(data)])
        .nice(); //extend bounds to nearest round value
    },

    create_svg_containers: function(){
      //extend this
      return this;
    },

    draw_base_bars: function(data) {
      var chart = this;
      var bars = chart.svg.select("#baseBars").selectAll(".base.bar")
        .data(data, function(d){ return d.id });

      bars.exit().transition().duration(chart.duration)
        .ease(chart.easing)
        .style("opacity", 0).remove();

      bars.enter().append("rect")
        .attr("class", "base bar")
        .style("opacity", 0)
        .attr("y", function(d) {
          return chart.yScale(d.display_name);
        })
        .attr("width", chart.dimensions.width)
        .attr("height", chart.bar_height);

      bars.transition().duration(chart.duration)
        .ease(chart.easing)
        .style("opacity", 1)
        .attr("y", function(d){ return chart.yScale(d.display_name); })
    },

    draw_axes: function(data) {
      var chart = this;
      //create and set x axis position
      chart.svg.select("#axes").append("g")
        .attr("class", "x axis")<commit_msg>Don't move base bars during transitions<commit_after>HospitalCheckup.module("Common.Chart", function(Chart, HospitalCheckup, Backbone, Marionette, $, _){

  //all the common elements that all list charts in hospital app will share
  Chart.BarBase = ChartBaseView.extend({
    constructor: function(options) {
      ChartBaseView.apply(this, arguments);
      this.options.bar_padding = options.bar_padding || 4;
      this.options.section = options.section || "infections";
      this.options.stat = options.stat || "ratio";
      this.duration = 500;
      this.easing = "sin-in-out"; // https://github.com/mbostock/d3/wiki/Transitions#wiki-d3_ease
      this.bar_height = (this.dimensions.height / this.collection.length) - this.options.bar_padding;
      this.$chart_container.attr('id', this.el.id+"-container");
      return this;
    },
    draw: function() {
      var data = this.filter_data(this.data);
      this.get_scales(data);
      this.create_axis("x", "bottom"); //super
      this.create_axis("y", "left"); //super
      this.create_svg(); //super
      this.create_svg_containers();
      this.draw_base_bars(data);
      this.draw_data(data);
      this.draw_axes(data);//needs to be on top of bars
    },

    //remove items with no data and sort by stat
    filter_data: function(){
      var chart = this,
      section = chart.options.section,
      stat = chart.options.stat;

      var filtered = chart.data.filter(function(d){
        return d[section][chart.options.measure].na != 1;
      });
      filtered.sort(function(a,b){
        return d3.ascending(a[section][chart.options.measure][stat], b[section][chart.options.measure][stat]);
      });
      return filtered;
    },

    get_xMax: function(data){
      var chart = this;
      return d3.max(data, function(d) { return d[chart.options.section][chart.options.measure].upper });
    },

    get_currentHeight: function(data){
      return (this.options.bar_padding + this.bar_height) * data.length;
    },

    get_scales: function(data) {
      var chart = this;
      chart.yScale = d3.scale.ordinal()
        .rangeBands([0, chart.get_currentHeight(data)])
        .domain(_.map(data, function(d) { return d.display_name; }));

      chart.xScale = d3.scale.linear()
        .rangeRound([0, chart.dimensions.width])
        .domain([0, chart.get_xMax(data)])
        .nice(); //extend bounds to nearest round value
    },

    create_svg_containers: function(){
      //extend this
      return this;
    },

    draw_base_bars: function(data) {
      var chart = this;
      var bars = chart.svg.select("#baseBars").selectAll(".base.bar")
        .data(data);
        //.data(data, function(d){ return d.id });

      bars.exit().transition().duration(chart.duration)
        .ease(chart.easing)
        .style("opacity", 0).remove();

      bars.enter().append("rect")
        .attr("class", "base bar")
        .style("opacity", 0)
        .attr("y", function(d) {
          return chart.yScale(d.display_name);
        })
        .attr("width", chart.dimensions.width)
        .attr("height", chart.bar_height);

      bars.transition().duration(chart.duration)
        .ease(chart.easing)
        .style("opacity", 1)
        //.attr("y", function(d){ return chart.yScale(d.display_name); })
    },

    draw_axes: function(data) {
      var chart = this;
      //create and set x axis position
      chart.svg.select("#axes").append("g")
        .attr("class", "x axis")
{'fraction_non_alphanumeric': 0.1549745824255628, 'fraction_numerical': 0.0049382716049382715, 'mean_word_length': 2.7181425485961124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3380758', 'n_tokens_mistral': 2169, 'n_tokens_neox': 2113, 'n_words': 407}