enthought / enthought/chaco

AbstractPlotRenderers return different array shapes when passing a single point to map_screen

Open
#550 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
305
Forks
97
PR merge metrics
No merged PRs in 30d

Description

`Base2DPlot` and `BaseXYPlot` both implement the `AbstractPlotRenderer` interface, in particular the `map_screen` method.

When a single `(x, y)` point is passed to `Base2DPlot.map_screen`, the returned array is of the form `[[x, y]]` (nested, shape = `(1, 2)`), as set by `GridMapper.map_screen`:

https://github.com/enthought/chaco/blob/4a6683521cce012b5df4830d64f41518798fc817/chaco/grid_mapper.py#L114-L123

When a single `(x, y)` point is passed to `BaseXYPlot.map_screen`, the returned array is of the form `[x, y]` (flattened, shape = `(2,)`):

https://github.com/enthought/chaco/blob/4a6683521cce012b5df4830d64f41518798fc817/chaco/base_xy_plot.py#L336-L353

This difference forces objects that interact with `AbstractPlotRenderer`s to make an assumption about the behavior of the `map_screen` method. For example, the `DataLabelTool` assumes the `map_screen` return shape matches that of `BaseXYPlot` for a single point (`(2,)`):

https://github.com/enthought/chaco/blob/4a6683521cce012b5df4830d64f41518798fc817/chaco/tools/data_label_tool.py#L53-L54

And therefore this tool throws an exception when used with a `Base2DPlot`:

```
File "/python3.6/site-packages/chaco/tools/data_label_tool.py", line 53, in drag_start
pointx, pointy = label.component.map_screen(label.data_point)
ValueError: not enough values to unpack (expected 2, got 1)
```

even though it would otherwise be compatible.

This issue also looks like it applies to the `map_data` method although I have not tested it.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.