You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2020/04/26 10:15:14 UTC

[GitHub] [incubator-echarts] wf123537200 commented on issue #12338: The callback function of toolip formatter will be executed multiple times

wf123537200 commented on issue #12338:
URL: https://github.com/apache/incubator-echarts/issues/12338#issuecomment-619523390


   
   Is it possible to make a layer of cache? If you have already called fomatter on the same tooltip, it will not be called again. It should be what you can try (you can see if the unique key here uses this)
   
   是不是可以做一层缓存,如果已经对同一个tooltip调用过fomatter,就不再调用,试了下应该是你可以的(这里的唯一key是否用这个可以大家再看看)
   
   ```
           // incubator-echarts/src/component/tooltip/TooltipView.js :Line 579
           else if (typeof formatter === 'function') {
               // cache object
               this._toopTipFormatterCache = this._toopTipFormatterCache || {}
               var key = params[0].seriesId + params[0].name
               
               var callback = bind(function (cbTicket, html) {
                   if (cbTicket === this._ticket) {
                       tooltipContent.setContent(html, markers, tooltipModel);
                       this._updatePosition(
                           tooltipModel, positionExpr, x, y, tooltipContent, params, el
                       );
                   }
               }, this);
               this._ticket = asyncTicket;
               html = this._toopTipFormatterCache[key] || formatter(params, asyncTicket, callback);
               // cache
               this._toopTipFormatterCache[key] = html;
           }
   ```
   result as follow:
   结果如下:
   ![image](https://user-images.githubusercontent.com/5130528/80304561-73506600-87e9-11ea-8207-2c1972630ed3.png)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org