Get zoom level & bounds of graph view

I’m working on an operator that draws an extra grid on the fcurve editor. I’ve figured out the bgl drawing part, but I don’t know where I can get the bounds of the view. (min-time, max-time, min-value, max-value). I was expecting to find it in the SpaceGraphEditor, but there I can’t find it.

Here’s what I have until now:


import bpy
import bgl


bl_info = {
    "name": "FCurve Speed grid",
    "description": "Show speed grid in fcurve window",
    "author": "Jonatan Bijl",
    "version": (1, 0),
    "blender": (2, 77, 0),
    "location": "",
    "warning": "", # used for warning icon and text in addons panel
    "wiki_url": "",
    "tracker_url": "",
    "support": "COMMUNITY",
    "category": "Show grid"
    }

def draw_callback(kmh, step, offset, context):
    space = context.space_data
    if space.mode == 'FCURVES':
        mps = kmh / 3.6
        mpf = mps / (context.scene.render.fps / context.scene.render.fps_base)
        dy = round(mpf * offset)
        
        # 50% alpha, 2 pixel width line
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
        bgl.glLineWidth(2)

        bgl.glBegin(bgl.GL_LINES)
        for x in range(context.scene.frame_start, context.scene.frame_end, 100):
            bgl.glVertex2i(x-offset, -dy)
            bgl.glVertex2i(x+offset, dy)
            bgl.glVertex2i(x+offset, -dy)
            bgl.glVertex2i(x-offset, dy)
        bgl.glEnd()

        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)


class ShowSpeedGridOperator(bpy.types.Operator):
    """Draw a grid in the curve view, that shows a certain speed"""
    bl_idname = "graph.speed_grid"
    bl_label = "Draw speed-grid in curve editor"
    _handle = None
    
    kmh = 30
    offset = 1000
    step = 100
    
    def execute(self, context):
        if context.area.type == 'GRAPH_EDITOR':
            if (self._handle):
                bpy.types.SpaceGraphEditor.draw_handler_remove(self._handle, 'WINDOW')
            else:
                # the arguments we pass the the callback
                args = (self.kmh, self.step, self.offset, context)
                # Add the region OpenGL drawing callback
                # draw in view space with 'POST_VIEW' and 'PRE_VIEW'
                self._handle = bpy.types.SpaceGraphEditor.draw_handler_add(draw_callback, args, 'WINDOW', 'PRE_VIEW')

            return {'FINISHED'}
        else:
            self.report({'WARNING'}, "Graph area not found, cannot run operator")
            return {'CANCELLED'}


def register():
    bpy.utils.register_class(ShowSpeedGridOperator)


def unregister():
    bpy.utils.unregister_class(ShowSpeedGridOperator)

if __name__ == "__main__":
    register()