|
115 | 115 | ...extra, |
116 | 116 | }); |
117 | 117 |
|
| 118 | + const yTitle = y.includes("/") ? y.split("/").pop() : y; |
| 119 | + const tooltipEnc = [ |
| 120 | + { field: colorField, type: "nominal", title: "Run" }, |
| 121 | + { field: x, type: "quantitative", title: x }, |
| 122 | + { field: y, type: "quantitative", title: yTitle }, |
| 123 | + ]; |
| 124 | +
|
| 125 | + const hoverParams = [{ |
| 126 | + name: "hover", |
| 127 | + select: { type: "point", on: "pointerover", nearest: true, clear: "pointerout" }, |
| 128 | + }]; |
| 129 | +
|
| 130 | + const hoverPointLayer = (dataSpec, layerName) => ({ |
| 131 | + ...dataSpec, |
| 132 | + mark: { type: "circle", clip: true, size: 60, opacity: 0 }, |
| 133 | + encoding: { |
| 134 | + x: xEnc, |
| 135 | + y: yEnc, |
| 136 | + ...colorEnc, |
| 137 | + tooltip: tooltipEnc, |
| 138 | + opacity: { |
| 139 | + condition: { param: "hover", empty: false, value: 1 }, |
| 140 | + value: 0, |
| 141 | + }, |
| 142 | + }, |
| 143 | + params: hoverParams, |
| 144 | + name: layerName, |
| 145 | + }); |
| 146 | +
|
118 | 147 | if (hasSmoothed) { |
119 | 148 | layers.push({ |
120 | 149 | data: { name: "data_original", values: originalData }, |
|
128 | 157 | encoding: { x: xEnc, y: yEnc, ...colorEnc }, |
129 | 158 | name: "plot", |
130 | 159 | }); |
| 160 | + layers.push( |
| 161 | + hoverPointLayer({ data: { name: "data_smoothed", values: smoothedData } }, "hover_points"), |
| 162 | + ); |
131 | 163 | } else { |
132 | 164 | layers.push({ |
133 | 165 | data: { name: "data_plot", values: data }, |
134 | 166 | mark: lineMark(), |
135 | 167 | encoding: { x: xEnc, y: yEnc, ...colorEnc }, |
136 | 168 | name: "plot", |
137 | 169 | }); |
| 170 | + layers.push( |
| 171 | + hoverPointLayer({ data: { name: "data_plot", values: data } }, "hover_points"), |
| 172 | + ); |
138 | 173 | } |
139 | 174 |
|
140 | | - const yTitle = y.includes("/") ? y.split("/").pop() : y; |
141 | | -
|
142 | 175 | return { |
143 | 176 | $schema: "https://vega.github.io/schema/vega-lite/v5.json", |
144 | 177 | title: { |
|
0 commit comments