Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CursorTool does not work with LogMapper for both axes #289

Closed
spescha opened this issue Feb 11, 2016 · 1 comment · Fixed by #803
Closed

CursorTool does not work with LogMapper for both axes #289

spescha opened this issue Feb 11, 2016 · 1 comment · Fixed by #803

Comments

@spescha
Copy link

spescha commented Feb 11, 2016

Using LogMapper for both axes

mag = LinePlot(index = ArrayDataSource(w, sort_order='ascending'),
                        value = ArrayDataSource(H),
                        color = curve_color,
                        name = curve_name,
                        index_mapper = LogMapper(range=view_mag.index_range),
                        value_mapper = LogMapper(range=view_mag.value_range))

leads to the error below, when adding a cursor with following lines

cursor1 = CursorTool(mag,
                        drag_button="left",
                        show_value_line=False,
                        show_marker=True,
                        line_width=2.0,
                        color='black')
mag.overlays.append(cursor1)

The problem is, that LogMapper.map_screen returns a 1-element array, while LinearMapper returns a scalar value, if only one data point has to be mapped.

Following subclass of LogMapper works for me as a workaround

class LogMapperCorr(LogMapper):
    """
    Corrects chaco.log_mapper.LogMapper for the usage with cursors. Cursors need
    a 1D-array iterable to unpack the x and y values and the LogMapper returns
    a 2D-array. Therefore LogMapper.map_screen has to return a scalar, if the length 
    of the data array is 1.
    """

    def __init__(self, *args, **kwargs):
        LogMapper.__init__(self, *args, **kwargs)

    def map_screen(self, data_array):
        arr = LogMapper.map_screen(self, data_array)

        if len(arr)==1:
            return arr[0]
        else:
            return arr
Traceback (most recent call last):
  File "C:\Users\speschda\AppData\Local\Enthought\Canopy\User\lib\site-packages\enable\qt4\base_window.py", line 198, in paintEvent
    self.handler.paintEvent(event)
  File "C:\Users\speschda\AppData\Local\Enthought\Canopy\User\lib\site-packages\enable\qt4\base_window.py", line 50, in paintEvent
    self._enable_window._paint(event)
  File "C:\Users\speschda\AppData\Local\Enthought\Canopy\User\lib\site-packages\enable\abstract_window.py", line 467, in _paint
    self.component.draw(gc, view_bounds=(0, 0, size[0], size[1]))
  File "C:\Users\speschda\AppData\Local\Enthought\Canopy\User\lib\site-packages\enable\component.py", line 424, in draw
    self._draw(gc, view_bounds, mode)
  File "C:\Users\speschda\AppData\Local\Enthought\Canopy\User\lib\site-packages\enable\component.py", line 776, in _draw
    self._dispatch_draw(layer, gc, view_bounds, mode)
  File "C:\Users\speschda\AppData\Local\Enthought\Canopy\User\lib\site-packages\enable\container.py", line 272, in _dispatch_draw
    component._dispatch_draw(layer, gc, new_bounds, mode)
  File "C:\Users\speschda\AppData\Local\Enthought\Canopy\User\lib\site-packages\enable\container.py", line 272, in _dispatch_draw
    component._dispatch_draw(layer, gc, new_bounds, mode)
  File "C:\Users\speschda\AppData\Local\Enthought\Canopy\User\lib\site-packages\enable\component.py", line 796, in _dispatch_draw
    handler(gc, view_bounds, mode)
  File "C:\Users\speschda\AppData\Local\Enthought\Canopy\User\lib\site-packages\enable\component.py", line 874, in _draw_overlay
    overlay.overlay(self, gc, view_bounds, mode)
  File "C:\Users\speschda\AppData\Local\Enthought\Canopy\User\lib\site-packages\chaco\tools\line_inspector.py", line 106, in overlay
    self.draw(gc, view_bounds)
  File "C:\Users\speschda\AppData\Local\Enthought\Canopy\User\lib\site-packages\chaco\tools\cursor_tool.py", line 183, in draw
    sx, sy = plot.map_screen(self.current_position)
ValueError: need more than 1 value to unpack
@aaronayres35
Copy link
Contributor

aaronayres35 commented May 3, 2021

I am still able to reproduce this using the cursor_tool_demo by replacing:

line = create_line_plot(
[index, value],
add_grid=True,
add_axis=True,
index_sort="ascending",
orientation="h",
)

with

line = LinePlot(
    index=ArrayDataSource(index, sort_order='ascending'),
    value=ArrayDataSource(value),
    index_mapper=LogMapper(range=DataRange1D()),
    value_mapper=LogMapper(range=DataRange1D()),
    orientation='h',
    color='red',
    bgcolor='transparent',
    line_width=1.0,
    line_style='solid',
    border_visible=False,
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants