|
112 | 112 | type: "line", |
113 | 113 | clip: true, |
114 | 114 | strokeWidth: 2, |
115 | | - point: { size: 20, ...(extra.point || {}) }, |
116 | 115 | ...extra, |
117 | 116 | }); |
118 | 117 |
|
|
123 | 122 | { field: y, type: "quantitative", title: yTitle }, |
124 | 123 | ]; |
125 | 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 | +
|
126 | 147 | if (hasSmoothed) { |
127 | 148 | layers.push({ |
128 | 149 | data: { name: "data_original", values: originalData }, |
129 | | - mark: lineMark({ strokeWidth: 1, opacity: 0.3, point: { size: 20, opacity: 0.3 } }), |
130 | | - encoding: { x: xEnc, y: yEnc, ...colorEnc, tooltip: tooltipEnc }, |
| 150 | + mark: lineMark({ strokeWidth: 1, opacity: 0.3 }), |
| 151 | + encoding: { x: xEnc, y: yEnc, ...colorEnc }, |
131 | 152 | name: "original", |
132 | 153 | }); |
133 | 154 | layers.push({ |
134 | 155 | data: { name: "data_smoothed", values: smoothedData }, |
135 | 156 | mark: lineMark(), |
136 | | - encoding: { x: xEnc, y: yEnc, ...colorEnc, tooltip: tooltipEnc }, |
| 157 | + encoding: { x: xEnc, y: yEnc, ...colorEnc }, |
137 | 158 | name: "plot", |
138 | 159 | }); |
| 160 | + layers.push( |
| 161 | + hoverPointLayer({ data: { name: "data_smoothed", values: smoothedData } }, "hover_points"), |
| 162 | + ); |
139 | 163 | } else { |
140 | 164 | layers.push({ |
141 | 165 | data: { name: "data_plot", values: data }, |
142 | 166 | mark: lineMark(), |
143 | | - encoding: { x: xEnc, y: yEnc, ...colorEnc, tooltip: tooltipEnc }, |
| 167 | + encoding: { x: xEnc, y: yEnc, ...colorEnc }, |
144 | 168 | name: "plot", |
145 | 169 | }); |
| 170 | + layers.push( |
| 171 | + hoverPointLayer({ data: { name: "data_plot", values: data } }, "hover_points"), |
| 172 | + ); |
146 | 173 | } |
147 | 174 |
|
148 | 175 | return { |
|
0 commit comments