Hi,
 I'm trying to implement a simple interface where I can click on points in 
a plot an get their (x,y) value. I was wondering how I can convert the 
(x,y) value returned by the Gtk mouse event to Winston data coordinates?

I am using this function to get a PlotContext from the GtkCanvas

function get_context(c::Gtk.Canvas, pc::Winston.PlotContainer)
    device = Winston.CairoRenderer(Gtk.cairo_surface(c))
    ext_bbox = Winston.BoundingBox(0,Winston.width(c),0,Winston.height(c))
    Winston._get_context(device, ext_bbox, pc)
end



 This is my interact function

function interact()
    c = Gtk.@Canvas()
    win = Gtk.@Window(c,"Test")
    p =  Winston.FramedPlot()
    Winston.plot(p,[1,2,3])
    display(c,p)
    Winston.show(c)

    function motion(w,event)
        cc = get_context(c, p)
        x, y = Winston.project(cc.geom, 1.0,1.0) # just testing what we can 
map from data to device coordinates
        println("$x, $y")
        x,y = Winston.device_to_data(cc,event.x,event.y)
        println("$xx, $yy")

    end
    c.mouse.button1press = motion
end 


           #I just copied this function from the Gtk implementation of 
Winston

function display(c::Gtk.Canvas, pc::Winston.PlotContainer)
    c.draw = let bad=false
        function (_)
            bad && return
            ctx = Winston.getgc(c)
            Winston.set_source_rgb(ctx, 1, 1, 1)
            Winston.paint(ctx)
            try
                Winston.page_compose(pc, Gtk.cairo_surface(c))
            catch e
                bad = true
                isa(e, WinstonException) || rethrow(e)
                println("Winston: ", e.msg)
            end
        end
    end
    Gtk.draw(c)
end 


The resulting (xx,yy) coordinates do not seem to correspond to the data 
coordinates that I'm clicking. Any thoughts on how to do this? Thanks! 

Reply via email to