UNPKG

@elastic/charts

Version:

Elastic-Charts data visualization library

25 lines 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLongestLegendFormattedValueWidthSelector = exports.getLongestLegendFormattedValueSelector = void 0; const get_internal_chart_state_1 = require("./get_internal_chart_state"); const default_theme_attributes_1 = require("../../common/default_theme_attributes"); const legend_1 = require("../../common/legend"); const canvas_text_bbox_calculator_1 = require("../../utils/bbox/canvas_text_bbox_calculator"); const create_selector_1 = require("../create_selector"); const LEGEND_VALUE_FONT = { fontFamily: default_theme_attributes_1.DEFAULT_FONT_FAMILY, fontVariant: 'normal', fontWeight: 700, fontStyle: 'normal', }; exports.getLongestLegendFormattedValueSelector = (0, create_selector_1.createCustomCachedSelector)([(globalChartState) => globalChartState, get_internal_chart_state_1.getInternalChartStateSelector], (globalChartState, internalChartState) => { return internalChartState?.getLongestLegendFormattedValue(globalChartState); }); exports.getLongestLegendFormattedValueWidthSelector = (0, create_selector_1.createCustomCachedSelector)([exports.getLongestLegendFormattedValueSelector], (maxFormattedValue) => { if (!maxFormattedValue) return undefined; const title = legend_1.legendValueTitlesMap[legend_1.LegendValue.CurrentAndLastValue]; const fullText = `${title.toUpperCase()}: ${maxFormattedValue}`; return (0, canvas_text_bbox_calculator_1.withTextMeasure)((textMeasure) => textMeasure(fullText, LEGEND_VALUE_FONT, 12, 1.5).width); }); //# sourceMappingURL=get_longest_legend_formatted_value.js.map