
マウスでインタラクティブなグラフを作成したいのですが、たとえば、マウスをテキスト ラベルの上に置くと、関連する領域が強調表示されます。以下はグラフの例です。
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[yscale=-1,>=latex]
\foreach \a/\b/\c/\d/\desc [count=\j] in {
0/0/5/8/box1,
0/0/5/8/box2,
1/1/4/7/box3,
0/0/3/6/box4
}{
\path (-2,0) ++(0,\j) coordinate (A);
\draw (\a,\b) rectangle (\c,\d);
\draw[<-,red] (\a,\b) -- (A) node[anchor=east,pos=1] {\desc};
}
\end{tikzpicture}
\end{document}
マウスをボックス1に合わせると、領域 (0,0) - (5,8) がハイライト表示されます。アニメーションのサポートはわかっていますが、インタラクティブではありません (マウスの位置によって制御されます)。
答え1
以下は ocgx2 パッケージを使用した例です。ファイルは 2 回コンパイルする必要があり、PDF リーダーの Acrobat Reader、Foxit Reader、または evince が必要です。ゾーンをアクティブにするには、ボックスの名前をクリックする必要があります。
ocgx2
オプションを使用して、1 つのレイヤーをアクティブにすると他のレイヤーが無効になるようにする方法をコメントで指定してくれたパッケージのメンテナーである @AlexG に感謝しますopts={radiobtngrp=myBoxes}}
。
\documentclass[border=2mm]{standalone}
\usepackage[tikz]{ocgx2}
\begin{document}
\begin{tikzpicture}[yscale=-1,>=latex]
\foreach \a/\b/\c/\d/\desc [count=\j] in {
0/0/5/8/box1,
0/0/2/4/box2,
1/1/4/7/box3,
0/0/3/6/box4
}{
\path (-2,0) ++(0,\j) coordinate (A);
\draw (\a,\b) rectangle (\c,\d);
\begin{scope}[ocg={name=box\j,ref=box\j,status=invisible,opts={radiobtngrp=myBoxes}}]
\fill[red!30] (\a,\b) rectangle (\c,\d);
\end{scope}
\draw[<-,red] (\a,\b) -- (A) node[anchor=east,pos=1,switch ocg=box\j] {\desc};
}
\end{tikzpicture}
\end{document}