plotly / plotly/react-plotly.js

Cannot access customdata array

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

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

主要言語
JavaScript
スター
1.1k
フォーク
138
平均マージ
3日 2時間
マージ済み PR(30日)
4

説明

I can access customdata without an issue if customdata is not an array, hovertemplate formats the x points according to the 1st function correctly.

customdata: d.x.map((x) => {
          const years = Math.floor(x);
          const months = Math.floor(12 * (x % 1));
          if (years === 0) return `${months}m`;
          if (months === 0) return `${years}y`;
          return `${years}y ${months}m`;
        }),

        hovertemplate: `<b>${eyeNames[i]}</b><br>
            <i>Risk</i>: <br>
            <i>Risk</i>: %{y:.2p}<br>
            <i>Time</i>: %{customdata}<extra></extra>`,
      }));
Screenshot 2022-02-25 at 12 10 16

To add another function to customdata, according to the documentation i need to convert customdata into an array, which i have done, but the hovertemplate no longer picks up customdata.

     customdata: [
          d.x.map((x) => {
            const years = Math.floor(x);
            const months = Math.floor(12 * (x % 1));
            if (years === 0) return `${months}m`;
            if (months === 0) return `${years}y`;
            return `${years}y ${months}m`;
          }),
          d.y.map((y) => {
            let p = y.toFixed(2);
            if (inverse1 === 0) return p;
            if (inverse1 === 1) {
              p = null;
            }
            return p;
          })
        ],

        hovertemplate: `<b>${eyeNames[i]}</b><br>
            <i>Risk</i>: %{customdata[1]}<br>
            <i>Risk</i>: %{y:.2p}<br>
            <i>Time</i>: %{customdata[0]}<extra></extra>`,
      }));
Screenshot 2022-02-25 at 11 54 38

In hovertemplate if i write %{fullData.customedata} it picks up the array, but the functions map out every point instead of the single point hovered on the graph.

hovertemplate: `<b>${eyeNames[i]}</b><br> <i>Risk</i>: %{fullData.customdata[1]}<br> <i>Risk</i>: %{y:.2p}<br> <i>Time</i>: %{fullData.customdata[0]}<extra></extra>`, }));

Screenshot 2022-02-25 at 12 02 11

What is the correct syntax here to access the customdata array and have the functions manipulate the hovered point on the graphs only, like in the first image, with the time variable. Thanks.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

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

調査の方向性

まず、issue に示されている 2 つの customdata の形状と hovertemplate の参照を比較します。Plotly の point-level customdata と hovertemplate の動作を確認し、その結果をレポートの例と照合します。ホバーしたポイントに意図した時間とリスクの値が表示され、マッピングされた配列が展開されなければ完了です。

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

評価

技術スタック
javascript, react
領域
data-visualization, frontend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
28/100

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

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