imageMap                package:prada                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:

       imageMap(con, imgname, coord, tooltips, url, target="extra")

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

     con: Connection (see argument 'con' of 'writeLines').

 imgname: Character. Name of the image file for which you want to
          construct the map.

   coord: Matrix with 4 columns. Each row specifies the corners of a 
          rectangle within the image, in the following order: (left x,
          lower y, right x, upper y). Note that the point (x=0, y=0) is
           at the left upper side of the image.

tooltips: Character vector of length 'nrow(coord)'. It contains the
          text that is displayed when the mouse moves over a rectangle.

     url: Character vector of length 'nrow(coord)'. It contains the
          hyperlinks that the browser can follow when the mouse clicks
          into a rectangle.

  target: Character. Name of the target browser window in which the
          target of the hyperlinks are displayed. If its length is less
          than 'nrow(coord)', the recycling rule is invoked.

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

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

        1.  generate your graphic and save it as a bitmap file, e.g.
           using the 'jpeg' or 'png' devices. At this stage, you also
           need to figure out the pixel coordinates of the interesting
           regions within your graphic. Since the mapping between
           device coordinates and pixel coordinates is not very
           transparent, this may be a little tricky. See the examples
           below, and for a more complex example, see the source code
           of the function 'plotPlate'.

        2.  open an HTML page for writing, e.g. using the
           'openHTMLpage' function.

        3.  optionally write some header information into the HTML
           page.

        4.  call the 'imageMap' function, using for 'coord' the
           coordinates you have from step 1.

        5.  optionally write some further information into the HTML
           page.

        6.  close the HTML page, e.g. using the 'closeHTMLpage'
           function.

_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.dkfz.de/abt0840/whuber>

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

     'plotPlate',  'writeLines'

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

     fhtml  <- tempfile()
     fpng   <- tempfile()

     if(capabilities()["png"] && interactive()) {
       width <- height <- 512
       png(fpng, width=width, height=height)
       par(mai=rep(0,4))
       plot(0, xlim=c(0, width-1), ylim=c(0, height-1), xaxs="i", yaxs="i",
            type="n")
       coord=cbind(c(100,360),c(400, 50),c(200,460),c(500,150))
       rect(coord[,1], height-coord[,2], coord[,3], height-coord[,4], col=c("#1f77b4", "#b2df8a"))
       dev.off()

       con <- openHTMLpage(fhtml, "Hello world")
       imageMap(con, fpng, coord=coord, 
         url=paste("http://", c("link1", "link2"), sep=""),
         tooltips=c("Blue box", "Green box"))
       closeHTMLpage(con)

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

