<commit_before>Template.homeResidentActivitySumsByType.onCreated(function () {
  // Get reference to template instance
  const templateInstance = this;

  let currentActivityPeriod;
  // Get current home ID
  const homeId = Router.current().params.homeId;

  // set up home resident activity sums by type reactive variable
 templateInstance.homeResidentsActivitySumsByType = new ReactiveVar();

  this.autorun(() => {
    const activityPeriod = Template.currentData().activityPeriod;

    // Not fetch data if period isn't changed
    if (currentActivityPeriod !== activityPeriod) {
      // Get home resident activity sums from server method
      Meteor.call('getHomeResidentsActivitySumsByType', { homeId, period: activityPeriod }, function (error, activitySums) {
        // Set the home resident activity sums variable with the returned activity sums
        templateInstance.homeResidentsActivitySumsByType.set(activitySums);
        // Re-save current period
        currentActivityPeriod = activityPeriod;
      });
    }
  })
});

Template.homeResidentActivitySumsByType.onRendered(function () {
  // Get reference to template instance
  const templateInstance = this;

  templateInstance.autorun(function () {
    // Get the chart data
    const homeResidentsActivitySumsByType = templateInstance.homeResidentsActivitySumsByType.get();
    const activityMetric = Template.currentData().activityMetric;

     if (homeResidentsActivitySumsByType) {
      // Render chart then data is ready
      const data = _.map(homeResidentsActivitySumsByType, dataset => {
        return {
          type: 'bar',
          orientation: 'h',
          // Activity type
          name: dataset.key,
          // Activity count
          x: _.map(dataset.values, item => item[activityMetric]),
          // Resident name
          y: _.map(dataset.values, item => item.label),
        }
      });

      // Add plot layout configuration
      const layout = {
        autosize: true,
        height: 300,
        xaxis: {
          showline: true,
          automargin: true,
          showticklabels: true,
          tickfont: {
            size: 10,
          },
          tickwidth: 1,
          ticklen: 4
        },
        yaxis: {
          showline: true,
          automargin: true,
          showticklabels: true,
          tickfont: {
            size: 10,
          },
          tickwidth: 1,
          ticklen: 4
        },
        margin: {
          r: 10,
          t: 10,
          b: 40,
          l: 10
        },
        bargap: 0.05,
        barmode: 'stack',
        showlegend: true,
        legend: {
          traceorder: 'normal',
          x: 0,
          y: 5,
          orientation: 'h'
        }
      };

      // Render plot
      Plotly.newPlot('residentActivitiesSummary', data, layout, { displayModeBar: false });
      }
  });
});<commit_msg>Responsive chart layout<commit_after>Template.homeResidentActivitySumsByType.onCreated(function () {
  // Get reference to template instance
  const templateInstance = this;

  let currentActivityPeriod;
  // Get current home ID
  const homeId = Router.current().params.homeId;

  // set up home resident activity sums by type reactive variable
 templateInstance.homeResidentsActivitySumsByType = new ReactiveVar();

  this.autorun(() => {
    const activityPeriod = Template.currentData().activityPeriod;

    // Not fetch data if period isn't changed
    if (currentActivityPeriod !== activityPeriod) {
      // Get home resident activity sums from server method
      Meteor.call('getHomeResidentsActivitySumsByType', { homeId, period: activityPeriod }, function (error, activitySums) {
        // Set the home resident activity sums variable with the returned activity sums
        templateInstance.homeResidentsActivitySumsByType.set(activitySums);
        // Re-save current period
        currentActivityPeriod = activityPeriod;
      });
    }
  })
});

Template.homeResidentActivitySumsByType.onRendered(function () {
  // Get reference to template instance
  const templateInstance = this;

  templateInstance.autorun(function () {
    // Get the chart data
    const homeResidentsActivitySumsByType = templateInstance.homeResidentsActivitySumsByType.get();
    const activityMetric = Template.currentData().activityMetric;

     if (homeResidentsActivitySumsByType) {
      // Render chart then data is ready
      const data = _.map(homeResidentsActivitySumsByType, dataset => {
        return {
          type: 'bar',
          orientation: 'h',
          // Activity type
          name: dataset.key,
          // Activity count
          x: _.map(dataset.values, item => item[activityMetric]),
          // Resident name
          y: _.map(dataset.values, item => item.label),
        }
      });

      // Add plot layout configuration
      const layout = {
        autosize: true,
        xaxis: {
          showline: true,
          automargin: true,
          showticklabels: true,
          tickfont: {
            size: 10,
          },
          tickwidth: 1,
          ticklen: 4
        },
        yaxis: {
          showline: true,
          automargin: true,
          showticklabels: true,
          tickfont: {
            size: 10,
          },
          tickwidth: 1,
          ticklen: 4
        },
        margin: {
          r: 10,
          t: 10,
          l: 10
        },
        bargap: 0.05,
        barmode: 'stack',
        showlegend: true,
        legend: {
          traceorder: 'normal',
          x: 0,
          y: 5,
          orientation: 'h'
        }
      };

      // Render plot
      Plotly.newPlot('residentActivitiesSummary', data, layout, { displayModeBar: false, responsive: true });
    }
  });
});
{'fraction_non_alphanumeric': 0.09598603839441536, 'fraction_numerical': 0.0075043630017452, 'mean_word_length': 2.072922252010724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7580080', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1512, 'n_words': 400}