MCPcopy
hub / github.com/apache/echarts / _showComponentItemTooltip

Method _showComponentItemTooltip

src/component/tooltip/TooltipView.ts:740–810  ·  view source on GitHub ↗
(
        e: TryShowParams,
        el: ECElement,
        dispatchAction: ExtensionAPI['dispatchAction']
    )

Source from the content-addressed store, hash-verified

738 }
739
740 private _showComponentItemTooltip(
741 e: TryShowParams,
742 el: ECElement,
743 dispatchAction: ExtensionAPI['dispatchAction']
744 ) {
745 const isHTMLRenderMode = this._renderMode === 'html';
746 const ecData = getECData(el);
747 const tooltipConfig = ecData.tooltipConfig;
748 let tooltipOpt = tooltipConfig.option || {};
749 let encodeHTMLContent = tooltipOpt.encodeHTMLContent;
750 if (isString(tooltipOpt)) {
751 const content = tooltipOpt;
752 tooltipOpt = {
753 content: content,
754 // Fixed formatter
755 formatter: content
756 };
757 // when `tooltipConfig.option` is a string rather than an object,
758 // we can't know if the content needs to be encoded
759 // for the sake of security, encode it by default.
760 encodeHTMLContent = true;
761 }
762
763 if (encodeHTMLContent && isHTMLRenderMode && tooltipOpt.content) {
764 // clone might be unnecessary?
765 tooltipOpt = clone(tooltipOpt);
766 tooltipOpt.content = encodeHTML(tooltipOpt.content);
767 }
768
769 const tooltipModelCascade = [tooltipOpt] as TooltipModelOptionCascade[];
770 const cmpt = this._ecModel.getComponent(ecData.componentMainType, ecData.componentIndex);
771 if (cmpt) {
772 tooltipModelCascade.push(cmpt as Model<TooltipableOption>);
773 }
774 // In most cases, component tooltip formatter has different params with series tooltip formatter,
775 // so that they cannot share the same formatter. Since the global tooltip formatter is used for series
776 // by convention, we do not use it as the default formatter for component.
777 tooltipModelCascade.push({ formatter: tooltipOpt.content });
778
779 const positionDefault = e.positionDefault;
780 const subTooltipModel = buildTooltipModel(
781 tooltipModelCascade,
782 this._tooltipModel,
783 positionDefault ? { position: positionDefault } : null
784 );
785
786 const defaultHtml = subTooltipModel.get('content');
787 const asyncTicket = Math.random() + '';
788 // PENDING: this case do not support richText style yet.
789 const markupStyleCreator = new TooltipMarkupStyleCreator();
790
791 // Do not check whether `trigger` is 'none' here, because `trigger`
792 // only works on coordinate system. In fact, we have not found case
793 // that requires setting `trigger` nothing on component yet.
794
795 this._showOrMove(subTooltipModel, function (this: TooltipView) {
796 // Use formatterParams from element defined in component
797 // Avoid users modify it.

Callers 1

_tryShowMethod · 0.95

Calls 8

_showOrMoveMethod · 0.95
_showTooltipContentMethod · 0.95
cloneFunction · 0.85
encodeHTMLFunction · 0.85
buildTooltipModelFunction · 0.85
getComponentMethod · 0.80
dispatchActionFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected