2018-11-07 17:19:59 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { find } from 'lodash';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a chart name returns the configuration for that chart from and array
|
|
|
|
* of charts. If the chart is not found it will return the first chart.
|
|
|
|
*
|
|
|
|
* @param {string} chartName - the name of the chart to get configuration for
|
2020-02-14 02:23:21 +00:00
|
|
|
* @param {Array} charts - list of charts for a particular report
|
|
|
|
* @return {Object} - chart configuration object
|
2018-11-07 17:19:59 +00:00
|
|
|
*/
|
|
|
|
export default function getSelectedChart( chartName, charts = [] ) {
|
|
|
|
const chart = find( charts, { key: chartName } );
|
|
|
|
if ( chart ) {
|
|
|
|
return chart;
|
|
|
|
}
|
|
|
|
return charts[ 0 ];
|
|
|
|
}
|