MCPcopy Create free account
hub / github.com/apache/echarts / buildNameValue

Function buildNameValue

src/component/tooltip/tooltipMarkup.ts:315–376  ·  view source on GitHub ↗
(
    ctx: TooltipMarkupBuildContext,
    fragment: TooltipMarkupNameValueBlock,
    topMarginForOuterGap: number,
    toolTipTextStyle: TooltipOption['textStyle']
)

Source from the content-addressed store, hash-verified

313}
314
315function buildNameValue(
316 ctx: TooltipMarkupBuildContext,
317 fragment: TooltipMarkupNameValueBlock,
318 topMarginForOuterGap: number,
319 toolTipTextStyle: TooltipOption['textStyle']
320) {
321 const renderMode = ctx.renderMode;
322 const noName = fragment.noName;
323 const noValue = fragment.noValue;
324 const noMarker = !fragment.markerType;
325 const name = fragment.name;
326 const useUTC = ctx.useUTC;
327 const valueFormatter = fragment.valueFormatter || ctx.valueFormatter || ((value) => {
328 value = isArray(value) ? value : [value];
329 return map(value as unknown[], (val, idx) => makeValueReadable(
330 val, isArray(valueTypeOption) ? valueTypeOption[idx] : valueTypeOption, useUTC
331 ));
332 });
333
334 if (noName && noValue) {
335 return;
336 }
337
338 const markerStr = noMarker
339 ? ''
340 : ctx.markupStyleCreator.makeTooltipMarker(
341 fragment.markerType,
342 fragment.markerColor || tokens.color.secondary,
343 renderMode
344 );
345 const readableName = noName
346 ? ''
347 : makeValueReadable(name, 'ordinal', useUTC);
348 const valueTypeOption = fragment.valueType;
349 const readableValueList = noValue
350 ? []
351 : valueFormatter(fragment.value as OptionDataValue, fragment.rawDataIndex);
352 const valueAlignRight = !noMarker || !noName;
353 // It little weird if only value next to marker but far from marker.
354 const valueCloseToMarker = !noMarker && noName;
355
356 const {nameStyle, valueStyle} = getTooltipTextStyle(toolTipTextStyle, renderMode);
357
358 return renderMode === 'richText'
359 ? (
360 (noMarker ? '' : markerStr)
361 + (noName ? '' : wrapInlineNameRichText(ctx, readableName, nameStyle as RichTextStyle))
362 // Value has commas inside, so use ' ' as delimiter for multiple values.
363 + (noValue ? '' : wrapInlineValueRichText(
364 ctx, readableValueList, valueAlignRight, valueCloseToMarker, valueStyle as RichTextStyle
365 ))
366 )
367 : wrapBlockHTML(
368 toolTipTextStyle,
369 (noMarker ? '' : markerStr)
370 + (noName ? '' : wrapInlineNameHTML(readableName, !noMarker, nameStyle as string))
371 + (noValue ? '' : wrapInlineValueHTML(
372 readableValueList, valueAlignRight, valueCloseToMarker, valueStyle as string

Callers

nothing calls this directly

Calls 9

makeValueReadableFunction · 0.90
isArrayFunction · 0.85
getTooltipTextStyleFunction · 0.85
wrapInlineNameRichTextFunction · 0.85
wrapInlineValueRichTextFunction · 0.85
wrapBlockHTMLFunction · 0.85
wrapInlineNameHTMLFunction · 0.85
wrapInlineValueHTMLFunction · 0.85
makeTooltipMarkerMethod · 0.80

Tested by

no test coverage detected