UNPKG

@carto/airship-bridge

Version:

Airship bridge to other libs (CARTO VL, CARTO.js)

28 lines (27 loc) 966 B
import { findColorForCategory } from '../histogram'; /** * Converts a VL 'categorical' histogram to the format Airship's category widget requires * * @export * @param {VLCategoricalHistogram} histogram * @param {*} [colors] * @returns {object[]} */ export function vlToCategory(histogram, legendData) { if (legendData === void 0) { legendData = []; } var fullCategories = histogram.getAllCategories(); var values = histogram.value.reduce(function (acum, elem) { acum[elem.x] = elem; return acum; }, {}); return fullCategories.map(function (d) { var value = values[d.name]; return { color: findColorForCategory(d.name, legendData), name: d.name, value: value ? value.y : null }; }).sort(function (a, b) { return b.value - a.value; }); // TODO: Use getJoinedValues method properly here: histogram.getJoinedValues(legendData); } export default vlToCategory;