<commit_before>import CompositeClosureHelper from '../../../Common/Core/CompositeClosureHelper';

// ----------------------------------------------------------------------------
// Expected Data Format for Histogram2D
// ----------------------------------------------------------------------------
//
// {
//   "x": {
//     delta: 3.5,
//     extent: [0, 35],
//     name: "Name of X",
//   },
//   "y": {
//     delta: 1,
//     extent: [0, 10],
//     name: "Name of Y",
//   },
//   "bins": [
//     { x: 3.5, y: 5, count: 46 }, ...
//   ]
// }
//
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Global
// ----------------------------------------------------------------------------

function flipHistogram(histo2d) {
  const newHisto2d = {
    bins: histo2d.bins.map(bin => {
      const { x, y, count } = bin;
      return {
        x: y,
        y: x,
        count,
      };
    }),
    x: histo2d.y,
    y: histo2d.x,
    maxCount: histo2d.maxCount,
  };

  return newHisto2d;
}

// ----------------------------------------------------------------------------
// Histogram 2D Provider
// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, initialValues);

  CompositeClosureHelper.destroy(publicAPI, model);
  CompositeClosureHelper.isA(publicAPI, model, 'Histogram2DProvider');<commit_msg>fix(Histogram2DProvider): Ensure we keep number of bins when flipping a 2D histogram<commit_after>import CompositeClosureHelper from '../../../Common/Core/CompositeClosureHelper';

// ----------------------------------------------------------------------------
// Expected Data Format for Histogram2D
// ----------------------------------------------------------------------------
//
// {
//   "x": {
//     delta: 3.5,
//     extent: [0, 35],
//     name: "Name of X",
//   },
//   "y": {
//     delta: 1,
//     extent: [0, 10],
//     name: "Name of Y",
//   },
//   "bins": [
//     { x: 3.5, y: 5, count: 46 }, ...
//   ]
// }
//
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Global
// ----------------------------------------------------------------------------

function flipHistogram(histo2d) {
  const newHisto2d = {
    bins: histo2d.bins.map(bin => {
      const { x, y, count } = bin;
      return {
        x: y,
        y: x,
        count,
      };
    }),
    x: histo2d.y,
    y: histo2d.x,
    maxCount: histo2d.maxCount,
    numberOfBins: histo2d.numberOfBins,
  };

  return newHisto2d;
}

// ----------------------------------------------------------------------------
// Histogram 2D Provider
// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, initialValues);

  CompositeClosureHelper.destroy(publicAPI, model);
  CompositeClosureHelper.isA(publicAPI, model, 'Histogram2DProvider');
{'fraction_non_alphanumeric': 0.45974107988632773, 'fraction_numerical': 0.016103568045468898, 'mean_word_length': 0.8051282051282052, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 5, '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': '2393032', 'n_tokens_mistral': 847, 'n_tokens_neox': 809, 'n_words': 166}