Infographic Javascript

The Infographiq method connects a clickable image with scientific data, using a Javascript library called InfographiqJS (located here) as shown in the image below:

Image of Infographiq approach

In this section of the guide, we get into how InfographiqJS works to create the clickable image.

Within the InfographiqJS library, there is a function called link_svg(): this is the function used to generate the interactive image. You can see many of the options available via link_svg() at this demonstration page.

Dependencies {#dependencies}

In order for link_svg() to work, it relies upon other Javascript and CSS libraries that must be loaded prior to the InfographiqJS Javascript being loaded. These other libraries are known as the dependencies for InfographiqJS.

link_svg() Dependencies:

  1. jQuery (version 3.6.0).

  2. D3 (version 5).

  3. Font Awesome (version 4.7).

  4. Bootstrap (version 3.4.1). Note that Bootstrap, which is a framework used for layout, is more of a pseudo-dependency for InfographiqJS. InfographiqJS does not strictly require Bootstrap to run, but we highly recommend its use for layout and our examples have Bootstrap embedded.

Example {#example}

To get started, if you haven't do so already, download the example folder and unzip it. In the example folder, you'll find a file called "infographic.html", which you can also see here. Open infographic.html in your handy-dandy code editor. Lines 9-21 in the <head> section of the HTML, which read in as follows, load in the dependencies for InfographiqJS.

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"
      integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
      crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" 
      integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" 
      crossorigin="anonymous"></script>
    <script src="https://d3js.org/d3.v5.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" 
      integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" 
      crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" 
      integrity="sha512-5A8nwdMOWrSz20fDsjczgUidUBR8liPYU+WymTZP1lmY9G6Oc7HlZv156XqnsgNUzTyMefFTcsFH/tnJE/+xBg==" 
      crossorigin="anonymous" />

Lines 37-48 of the HTML are where we load in the InfographiqJS Javascript and CSS. We also call the InfographiqJS function link_svg(). This placement is very important: the InfographiqJS Javascript, CSS, and link_svg() must show up at the bottom of the <body> of the HTML.

<script src='https://marinebon.org/infographiqJS/libs/infographiq_latest/infographiq.js'></script>
<link rel="stylesheet" href="https://marinebon.org/infographiqJS/libs/infographiq_latest/infographiq.css">
<script>
    link_svg({
      svg: "illustrator_example.svg", 
      csv: "icon_link.csv", 
      svg_id: "svg1", 
      toc_id: "toc1",
      toc_style: "sectioned_list",
      text_toggle: "toggle_off",
      svg_filter: "illustrator_example.svg"});
</script>

Function parameters {#parameters}

There are multiple parameters for the function link_svg(), which are detailed here:

Required parameters

Optional parameters



marinebon/infographiq documentation built on Oct. 13, 2023, 4:22 p.m.