Source: commands/maximum.js

  1. /**
  2. * @namespace commands.maximum
  3. */
  4. import max from 'lodash/max';
  5. import { generateSentence, getIndependentValues } from './helpers';
  6. import { addThousandsSeparators } from '../utils';
  7. /**
  8. * Generates the response for the "maximum" command.
  9. * @memberOf commands.maximum
  10. * @param {Object} data - The data from the viz.
  11. * @param {string[]} data.x - Values of the independent variable.
  12. * @param {string[]} data.y - Values of the dependent variable.
  13. * @param {Object} options - The options supplied to voxlens when creating the viz.
  14. * @param {string} options.xLabel - Label for the x-axis.
  15. * @param {number} options.yLabel - Label for the y-axis.
  16. * @returns {object} - Response for the "maximum" command.
  17. */
  18. export default (data, options) => {
  19. const values = getIndependentValues(data, max);
  20. return {
  21. key: values[1],
  22. value: values[0],
  23. sentence: generateSentence(
  24. 'Maximum',
  25. `${addThousandsSeparators(values[0])} belonging to ${values[1]}`,
  26. options
  27. ),
  28. };
  29. };