|
36 | 36 | "\n", |
37 | 37 | " self.color = color\n", |
38 | 38 | " self.scheme = scheme\n", |
| 39 | + " \n", |
| 40 | + " self.background_color = '#f7f7f7'\n", |
39 | 41 | "\n", |
40 | 42 | " self.init_plot(x, y)\n", |
41 | 43 | "\n", |
|
75 | 77 | " background = self[0]\n", |
76 | 78 | "\n", |
77 | 79 | " # Draw background\n", |
78 | | - " background.fill_style = '#f7f7f7'\n", |
| 80 | + " background.fill_style = self.background_color\n", |
79 | 81 | " background.global_alpha = 0.3\n", |
80 | 82 | " background.fill_rect(drawarea_min_x, drawarea_min_y, drawarea_max_x, drawarea_max_y)\n", |
81 | 83 | " background.global_alpha = 1\n", |
|
130 | 132 | "\n", |
131 | 133 | " self.n_marks = min(x.shape[0], y.shape[0], size.shape[0], color.shape[0])\n", |
132 | 134 | "\n", |
| 135 | + " # Index of the dragged point\n", |
| 136 | + " self.i_mark = -1\n", |
| 137 | + "\n", |
133 | 138 | " self[2].on_mouse_down(self.mouse_down_handler)\n", |
134 | 139 | " self[2].on_mouse_move(self.mouse_move_handler)\n", |
135 | 140 | " self[2].on_mouse_up(self.mouse_up_handler)\n", |
136 | | - " \n", |
| 141 | + "\n", |
137 | 142 | " self.draw()\n", |
138 | 143 | "\n", |
139 | 144 | " def draw(self):\n", |
|
161 | 166 | " plot_layer.restore()\n", |
162 | 167 | "\n", |
163 | 168 | " def mouse_down_handler(self, pixel_x, pixel_y):\n", |
| 169 | + " plot_layer = self[1]\n", |
| 170 | + "\n", |
164 | 171 | " for idx in range(self.n_marks):\n", |
165 | 172 | " mark_x = self.x[idx]\n", |
166 | 173 | " mark_y = self.y[idx]\n", |
|
170 | 177 | " pixel_y > self.scale_y(mark_y) - mark_size and pixel_y < self.scale_y(mark_y) + mark_size):\n", |
171 | 178 | " self.i_mark = idx\n", |
172 | 179 | " self.dragging = True\n", |
| 180 | + "\n", |
| 181 | + " with hold_canvas(plot_layer):\n", |
| 182 | + " plot_layer.fill_style = self.background_color\n", |
| 183 | + " plot_layer.stroke_style = self.colormap(self.color[self.i_mark])\n", |
| 184 | + "\n", |
| 185 | + " plot_layer.fill_arc(self.scale_x(mark_x), self.scale_y(mark_y), mark_size, 0, 2 * pi)\n", |
| 186 | + " plot_layer.stroke_arc(self.scale_x(mark_x), self.scale_y(mark_y), mark_size, 0, 2 * pi)\n", |
173 | 187 | " break\n", |
174 | | - " \n", |
| 188 | + "\n", |
175 | 189 | " def mouse_move_handler(self, pixel_x, pixel_y):\n", |
176 | | - " if self.dragging:\n", |
| 190 | + " if self.dragging and self.i_mark != -1:\n", |
| 191 | + " interaction_layer = self[2]\n", |
| 192 | + "\n", |
177 | 193 | " unscaled_x = self.unscale_x(pixel_x)\n", |
178 | 194 | " unscaled_y = self.unscale_y(pixel_y)\n", |
179 | | - " self.x[self.i_mark] = unscaled_x\n", |
180 | | - " self.y[self.i_mark] = unscaled_y\n", |
181 | | - " self.draw()\n", |
182 | | - " \n", |
| 195 | + "\n", |
| 196 | + " with hold_canvas(interaction_layer):\n", |
| 197 | + " interaction_layer.clear()\n", |
| 198 | + " interaction_layer.fill_style = self.colormap(self.color[self.i_mark])\n", |
| 199 | + " interaction_layer.stroke_style = self.stroke_color\n", |
| 200 | + "\n", |
| 201 | + " self.x[self.i_mark] = unscaled_x\n", |
| 202 | + " self.y[self.i_mark] = unscaled_y\n", |
| 203 | + "\n", |
| 204 | + " interaction_layer.fill_arc(pixel_x, pixel_y, self.sizes[self.i_mark], 0, 2 * pi)\n", |
| 205 | + " interaction_layer.stroke_arc(pixel_x, pixel_y, self.sizes[self.i_mark], 0, 2 * pi)\n", |
| 206 | + "\n", |
183 | 207 | " def mouse_up_handler(self, pixel_x, pixel_y):\n", |
184 | | - " self.dragging = False" |
| 208 | + " self.dragging = False\n", |
| 209 | + "\n", |
| 210 | + " self.draw()\n", |
| 211 | + "\n", |
| 212 | + " interaction_layer = self[2]\n", |
| 213 | + " interaction_layer.clear()" |
185 | 214 | ] |
186 | 215 | }, |
187 | 216 | { |
|
0 commit comments