l0b0 / mian

Mine analysis - Graph blocks to height in a Minecraft save game
https://github.com/l0b0/mian/wiki
GNU General Public License v3.0
14 stars 4 forks source link

Toggle lines #11

Closed pepijndevos closed 13 years ago

pepijndevos commented 13 years ago

This patch allows one to fade lines by clicking them.

I did something stupid with the branching, so the logarithmic commits got included as well. I'm sorry for that.

With these combined commits, I'd like to propose a larger set of default blocks. Since it is now possible to discern coal and clay on the same graph, and either one can be faded.

Fenixin commented 13 years ago

Great features both!

But I don't know why I get very strange errors when I click a line in the graph with the toggle feature. It happens when the function calls fig.canvas.draw(), and the traceback is:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1413, in __call__
    return self.func(*args)
  File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_tkagg.py", line 261, in button_press_event
    FigureCanvasBase.button_press_event(self, x, y, num, guiEvent=event)
  File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", line 1196, in button_press_event
    self.callbacks.process(s, mouseevent)
  File "/usr/lib/pymodules/python2.6/matplotlib/cbook.py", line 163, in process
    func(*args, **kwargs)
  File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", line 1101, in pick
    self.figure.pick(mouseevent)
  File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 314, in pick
    a.pick(mouseevent)
  File "/usr/lib/pymodules/python2.6/matplotlib/axes.py", line 2631, in pick
    martist.Artist.pick(self,args[0])
  File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 314, in pick
    a.pick(mouseevent)
  File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 307, in pick
    self.figure.canvas.pick_event(mouseevent, self, **prop)
  File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", line 1162, in pick_event
    self.callbacks.process(s, event)
  File "/usr/lib/pymodules/python2.6/matplotlib/cbook.py", line 163, in process
    func(*args, **kwargs)
  File "./mian.py", line 204, in on_pick
    fig.canvas.draw()
  File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_tkagg.py", line 215, in draw
    FigureCanvasAgg.draw(self)
  File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_agg.py", line 314, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 46, in draw_wrapper
    draw(artist, renderer, *kl)
  File "/usr/lib/pymodules/python2.6/matplotlib/figure.py", line 773, in draw
    for a in self.axes: a.draw(renderer)
  File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 46, in draw_wrapper
    draw(artist, renderer, *kl)
  File "/usr/lib/pymodules/python2.6/matplotlib/axes.py", line 1735, in draw
    a.draw(renderer)
  File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 46, in draw_wrapper
    draw(artist, renderer, *kl)
  File "/usr/lib/pymodules/python2.6/matplotlib/lines.py", line 539, in draw
    drawFunc(renderer, gc, tpath, affine.frozen())
  File "/usr/lib/pymodules/python2.6/matplotlib/lines.py", line 876, in _draw_lines
    self._lineFunc(renderer, gc, path, trans)
  File "/usr/lib/pymodules/python2.6/matplotlib/lines.py", line 920, in _draw_solid
    renderer.draw_path(gc, path, trans)
  File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_agg.py", line 98, in draw_path
    self._renderer.draw_path(gc, path, transform, rgbFace)
TypeError: float() argument must be a string or a number

Tkinter bug? no idea... but when this traceback happens the graph, sometimes, don't let you zoom/pan or use other features, other times the line doesn't toggle. Also, for me, the line never toggles back to solid line. :/

pepijndevos commented 13 years ago

Could you tell me a bit about your system? OS, version numbers, etc...

Did you try upgrading Matplotlib, or using another backend? Macports lets me use QT, wxWidgets, GTK, etc...

It could be that you need to replace None with 1, and change some logic:

thisline.set_alpha(1)
l0b0 commented 13 years ago

@pepijndevos: Can you please rebase this on top of origin/master, so we get a nice linear history?

Fenixin commented 13 years ago

I use Ubuntu 10.04 LTS, and the computer is a old laptop of 32bits.

No, I didn't try to update Matplotlib, I have the version 0.99.1. How can I change the backend of mian?

I tried changing the code as you said and it works perfectly with:

    def on_pick(pickevent):
        thisline = pickevent.artist
        print "Toggeling", thisline.get_label()
        if thisline.get_alpha() == 1:
            thisline.set_alpha(0.3)
        else:
            thisline.set_alpha(1)

Maybe this is more compatible with older versions of Matplotlib

pepijndevos commented 13 years ago

Okay, I'll rebase and patch.

pepijndevos commented 13 years ago

Okay, I did as you said, rebased to origin/master, solved a bunch of conflicts, fixed the issue, but it still shows all 4 commits.

pepijndevos commented 13 years ago

Hm, the diff looks okay though, but it still had one conflict.

Fenixin commented 13 years ago

mmmh... re-do the pull request? That worked for me in wrong pull requests.

pepijndevos commented 13 years ago

I think it might be okay this way. The diff is good, and the history will be flat: https://github.com/l0b0/mian/network

Fenixin commented 13 years ago

great, waiting for the merge

l0b0 commented 13 years ago

Going for it..

l0b0 commented 13 years ago

Looks good, but I'd like your input on a few ideas in this regard:

  1. I think the line in the legend should look the same as the one in the graph - This makes it even easier to see which line is which material, instead of just distinguishing lines from each other. In other words, any transformation applied to one should be applied to the other (but not necessarily to the block type label).
  2. The trigger area is big - Something like 10^2 pixels. When one line is already highlighted, and you click on a line near it, both are changed to the opposite state, which feels a bit awkward. Maybe it would be better to click in the legend to change a line?
  3. There are more ways than alpha-level to distinguish lines: thickness, pattern and color. Maybe thickening a single line at a time could be just as powerful?
l0b0 commented 13 years ago

@everyone: Who thinks this should be merged now, as-is, and who thinks it should be changed in any way first? Either is fine, but I'm not sure whether to read the last few comments as "unsolved, but working on it" or "not really an issue".

pepijndevos commented 13 years ago

Ouch, is this still around? I'd say make the radius smaller and merge. I'll do that if no one has objections.

Fenixin commented 13 years ago

Thanks for merging this!