[Bug] the tooltip of generated svg using renderToSVGString is not working.

オープン
#21,534 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript

調査の方向性

まず、playgroundの動作とrenderToSVGStringの出力を比較し、次に生成されたSVGとtooltipイベントの処理を追跡します。ブラウザーで開いたSVG出力が期待されるtooltipインタラクションをサポートできるか確認し、報告されたケースの回帰チェックを追加してください。

索引モデルが issue の本文から書いたものです。

説明

bug en pending
Version

5.2.2

Link to Minimal Reproduction

n.a.

Steps to Reproduce

use the same option (configure render to svg) in playground and renderToSVGString.

option = {
  tooltip: { trigger: 'item' },
  xAxis: {
    type: 'category',
    data: ['Apple', 'Banana', 'Orange', 'Melon', 'Grape']
  },
  yAxis: { type: 'value' },
  series: [
    {
      name: 'Sales',
      type: 'bar',
      data: [120, 200, 150, 80, 70],
      itemStyle: { color: '#5470c6' },
      emphasis: { itemStyle: { color: 'Orange' } },
      label: { show: true, position: 'top' }
    }
  ]
};
Current Behavior

the svg in playground is highlight and tooltip enabled. But open the generated svg in browser, only highlight, the tooltip is not working as expected.

I did some research, the highlight works because the gnerated svg of renderToSVGString contains some embeded css styles. And the tooltip maybe need some embeded js which is missing now.

Here is an example svg embeded some js for tooltip demo.

Image

svg source:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 200" width="400" height="200" style="background: #fafafa; border: 1px solid #ddd;">
  
  <style>
    .hover-target { cursor: help; fill-opacity: 0.8; }
    .hover-target:hover { fill-opacity: 1; }
    #tip-text { 
      font-family: sans-serif; 
      font-size: 14px; 
      fill: #333; 
      pointer-events: none; /* Prevents the tooltip from flickering when the mouse hits it */
      font-weight: bold;
    }
  </style>

  <circle class="hover-target" cx="80" cy="100" r="40" fill="#ff5722" data-tip="Orange Circle" />
  <rect class="hover-target" x="160" y="60" width="80" height="80" fill="#2196f3" data-tip="Blue Square" />
  <polygon class="hover-target" points="340,60 300,140 380,140" fill="#4caf50" data-tip="Green Triangle" />

  <text id="tip-text" x="0" y="0" visibility="hidden">Tip Content</text>

  <script type="text/javascript">
    <![CDATA[
      const svg = document.querySelector('svg');
      const tooltip = document.getElementById('tip-text');
      const targets = document.querySelectorAll('.hover-target');

      function showTip(e) {
        const msg = e.target.getAttribute('data-tip');
        tooltip.textContent = msg;
        tooltip.setAttribute('visibility', 'visible');
        moveTip(e);
      }

      function moveTip(e) {
        // Get mouse position relative to the SVG coordinate system
        let CTM = svg.getScreenCTM();
        let mouseX = (e.clientX - CTM.e) / CTM.a;
        let mouseY = (e.clientY - CTM.f) / CTM.d;

        // Position text 15px to the right and 5px above the cursor
        tooltip.setAttribute('x', mouseX + 15);
        tooltip.setAttribute('y', mouseY - 5);
      }

      function hideTip() {
        tooltip.setAttribute('visibility', 'hidden');
      }

      targets.forEach(el => {
        el.addEventListener('mouseover', showTip);
        el.addEventListener('mousemove', moveTip);
        el.addEventListener('mouseout', hideTip);
      });
    ]]>
  </script>
</svg>
Expected Behavior

the tooltip of generated svg using renderToSVGString is working like the normal usage. Maybe need to embed some js to svg.

Environment
- OS: windows
- Browser: edge, chrome
- Framework:
Any additional comments?

No response

主要言語
TypeScript
スター
67.7k
フォーク
19.9k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/echarts のほかの issue

apache/echarts の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。