imageMap-methods          package:biocGraph          R Documentation

_W_r_i_t_e _a_n _H_T_M_L _I_M_G _t_a_g _t_o_g_e_t_h_e_r _w_i_t_h _a _M_A_P _i_m_a_g_e _m_a_p.

_D_e_s_c_r_i_p_t_i_o_n:

     Write an HTML IMG tag together with a MAP image map.

_U_s_a_g_e:

       ## S4 method for signature 'Ragraph, connection, list,
       ##   character':
       imageMap(object, con, tags, imgname, width, height, usr = par("usr"))
     ## S4 method for signature 'graph, connection, list,
     ##   character':
     imageMap(object, con, tags, imgname, width, height)

_A_r_g_u_m_e_n_t_s:

  object: The graph layout for which we want to create an image map.

     con: Connection to which the image map is written.

    tags: Named list whose elements are named character vectors. Names
          must correspond to node names in 'object'. See details.

 imgname: Character. Name of the image file (for example PNG file) that
          contains the plot.

   width: Width of the image.

  height: Height of the image.

     usr: Numeric vector of length 4. The user coordinates in the plot
          window that 'object' was plotted into.

_D_e_t_a_i_l_s:

     The most important tags are 'TITLE', 'HREF', and 'TARGET'. If the
     list 'tags' contains an element with name 'TITLE', then this must
     be a named character vector containing the tooltips that are to be
     displayed when the mouse moves over a node. The names of the nodes
     are specified in the 'names' attribute  of the character vector
     and must match those of 'object'.

     Similarly, 'HREF' may be used to specify hyperlinks that the
     browser can follow when the mouse clicks on a node, and 'TARGET'
     to specify the target browser window.

     Currently, only rectangular regions are implemented; the actual
     shape of the nodes as specified in 'object' is ignored. Also, tags
     for edges of the graph are currently not supported.

     This function is typically used with the following sequence of
     steps:

        1.  Create a graph layout with 'agopen'

        2.  Plot it into a bitmap device, e.g. 'jpeg' or 'png'. 

        3.  Write HTML header.

        4.  Call the 'imageMap' function.

        5.  Optionally, write further text into the HTML connection.

        6.  Close HTML file.

     The new API for plotting of graphs now also allows for this
     alternative procedure:

        1.  Lay out the graph object 'foo' using 'layoutGraph'

        2.  render the graph on a bitmap device using 'renderGraph'
           like this: 'foo <- renderGraph(foo)'

        3.  Write HTML header.

        4.  Call the 'imageMap' on the graph object 'foo'.

        5.  Optionally, write further text into the HTML connection.

        6.  Close HTML file.

_V_a_l_u_e:

     The function is called for its side effect, which is writing text
     into the connection 'con'.

_A_u_t_h_o_r(_s):

     Wolfgang Huber <URL: http://www.ebi.ac.uk/huber>

_S_e_e _A_l_s_o:

     'agopen',  'openHTMLpage'

_E_x_a_m_p_l_e_s:

     fhtml = paste(tempfile(), ".html", sep="")
     fpng  =paste(tempfile(), ".png", sep="")

     if(capabilities()["png"] && interactive()) {

       ## Create a random graph, make tooltips and hyperlinks
       set.seed(123)
       g  = randomEGraph(letters[14:22], 0.2)

       tooltip = paste("This is node", nodes(g))
       url = paste("This could be a link for node", nodes(g))
       names(url) = names(tooltip) = nodes(g)

       ## Open plot device
       width = height = 512
       png(fpng, width=width, height=height)
       par(mai=rep(0,4))

       ## Layout and render
       lg = agopen(g, name="My layout")
       plot(lg)

       ## Write an HTML file with the image map
       con = file(fhtml, open="wt")
       writeLines("<html><head><title>Click Me</title></head><body>\n", con)

       imageMap(lg, con, fpng, tags=list(HREF=url, TITLE=tooltip), width=width, height=height)

       writeLines("</body></html>", con)
       close(con)
       dev.off()

       cat("Now have a look at file", fhtml, "with your browser.\n")
       browseURL(fhtml)
     }

