InterMine Ajax Embedding Tutorial

Changing the root class will clear your current query - are you sure?

The basics

You can now embed results from InterMine queries directly into your own web pages. All you need for this is a little knowledge of javascript - and there is a JavaScript client library available so you really do need only a little. If you want to do more, the techniques shown here are flexible and powerful enough to present information in any way you choose.

Example

Below you can see a table with results from the FlyMine preview site. On page ready the table structure was loaded in and the mine was queried for the count. The default behaviour is for results to be loaded into tables with only the title and count showing. Clicking the table will expand it, causing it to fetch data rows from the mine and insert them into itself, allowing you to see its contents.

This will be where the table goes

As you can see, you do not need a lot of code to get this effect:

Go here to see a very simple demo of the techniques shown on this page.

How To Set This Up

We have tried to keep the boilerplate you need to put into your code to a minimum, but there are a few things you need:

  • Some javascript libraries.

    To use the InterMine Embedding library (imbedding.js), you will need to include the following scripts into your page: jQuery, jQuery-JSONP and imbedding.js library.

  • Some css styles

    To style the tables, you will also need to include some css with the appropriate classes.

  • A placeholder (or several) on the page

    You will need to include an element to tell the table where to go.

  • A Script to load the table in

    You can either write your own separate library of functions and include it in your head, or you can insert a script element directly into the page:

Loading an Arbitrary Query

This tool is designed to help you write javascript functions for your pages by generating the code for you. You can paste in xml, experiment with JSON, or build a query from scratch. You can then see the generated code, and cut and paste it into your own page.

Queries can be passed to the loading function as either an xml text string, or as a json object. The loading module must be prepared with the base url before-hand in either case.

You can either define your query using the form below, or simply paste in some XML/JSON. When you press "Load Query" the results will be loaded, and the corresponding code will be generated for you to cut and paste into your own page (just click on the "Show the code" button.)

You can simply paste in xml or json into the appropriate box below, press load, and see the results, and the generating code for them.

The query defined above will go here

Loading a Template

This tool is designed to help you write javascript functions to load desired query results. It will generate code you can cut and paste into your web page to embed query results. Press "Show Source" to see the code generated for each query.

Enter a template name to see the list of templates for this mine. Selecting one will bring up a form for you to enter the values for the parameters that this template expects.


The template results will go here

Other ways to use the data you get back

The previous examples all demonstrate the default functionality, where a table is inserted into the page at the location of the given selector string. However, any arbitrary behaviour is possible by passing a function instead of a selector. The examples below demonstrate some potential applications of this, with two graphs and an alternative tabular display.

One difference between this and the default behaviour is the fact that you will need to specify a result format. The two that will be most useful are jsonpobjects, which all these examples use, and jsonprows, which is similar but provides less syntactic sugar for accessing fields of the result items.

This will be where the graph goes

Styling The Tables

The tables produced with the imbedding.js library are designed to be easily stylable. Customisation is possible by using the classes that the elements are decorated with:

Classes you can style in an embedded table:
  • .imbedded-table-container: The outer container that holds the table
  • .imbedded-table-titlebox: The box that holds the title and count
  • .imbedded-table-title: The text with the actual title
  • .imbedded-table: The table element
  • .imbedded-column-header-row: The row with the column headings
  • .imbedded-cell: Each cell of the table
  • .imbedded-row-odd: Odd numbered table rows
  • .imbedded-row-even: Even numbered table rows
  • .imbedded-column-odd: Odd numbered table columns
  • .imbedded-column-even: Even numbered table columns
  • .imbedded-exportlink: The CSV and TSV export links
  • .imbedded-pagelink: The previous/next paging links
  • .imbedded-mineresultslink: The link to the results in the originating mine
  • .imbedded-prev: The previous paging link
  • .imbedded-next: The next paging link
  • .imbedded-table-tooltip: The tooltip that contains the template description
  • .imbedded-table-expand-help: The link that says "show/hide table"
  • .imbedded-null: Cells that have no value

There are three styles supplied here with the tutorial, and you can see how changing them changes the appearance of the table below:

You May Be Interested In

  • jQuery

    A powerful javascript framework this site makes extensive use of

  • jQuery-JSONP

    A an extension to jQuery to improve jsonp requests (through the addition of better error handling).

  • jQuery-UI

    User interface extensions to jQuery. Used here for tabs, buttons and autocomplete.

  • jQuery-Syntax

    Used here for syntax highlighting in the code demonstration boxes.

  • Flot

    The library used to generate the graphs on the "other things you can do with data" tab.

  • Google Font API

    A webservice for supplying beautiful web-fonts so you don't have to do the messy business of hosting them.

Customising the Tables

What properties can I configure, and what are the defaults?

There are lots of user configurable properties, and they all have sane defaults. Below you can see a list of values you can pass into the options object of any loadQuery and loadTemplate call, and their default values:

property description takes default value
additionText the text to display in the "load x more rows" links string "Load [x] more rows"
afterBuildTable a function to call after the table is built function function(table) {}
afterTableUpdate a function to call after the table is updated with new data function function(table, resultSet) {}
allRowsText the text to display in the links offering to show the remaining rows string "Show remaining rows"
collapseHelpText the text to display in the "hide table" links string "hide table"
countText the text to display in parentheses beside the title string "[x] rows"
defaultQueryName the text to display in the title box if the query has no name string Query Results
emptyCellText the text to display in cells that have no value string "[NONE]"
expandHelpText the text to display in the "show table" links string "show table"
nextText the text to display in the "next page" links string "Next"
onTitleClick what to do when the user clicks the table title "collapse", "mine", "none", or function "collapse"
openOnLoad whether the table should be loaded open or not boolean false
previousText the text to display in the "previous page" links string "Previous"
queryTitleText the text to display as the title of the table. If given, this setting overrides any value returned from the server. string null
resultsDescriptionText the text to display in the toolbox. If given, this setting overrides any value returned from the server. string null
showAdditionsLink whether to show the links offering "x more rows" boolean true
showAllCeiling The maximum number of rows a query can return and still have the table offer to show all rows int 75
showAllLink whether to show the links offering "show remaining rows" boolean true
showCount whether to show the count or not boolean true
showExportLinks whether to show the export links (csv, tsv) or not boolean true
showMineLink whether to show the mine links boolean true
throbberSrc the location of a throbber to show when the table is first loaded location "images/throbber.gif"
titleHoverCursor the cursor to show when the mouse is held over the title (unless its behaviour is "none" string "pointer"

Note that options that take a parameter (such as countText) should indicate the position of the parameter with the string "[x]"

If you want all your tables to share the same set of options, you can specify that globally; the example below shows how this can be used for internationalisation:

Furthermore, the table itself is an object of type "Table", and upon production and and updates it is passed to the (no-op) functions IMBedding.afterBuildTable(table) and IMBedding.afterTableUpdate(table, resultSet) respectively. To get access to the table automatically, simply replace the no-op versions with your own code:

The table object provides you with deep low level access to many aspects, including all the elements (which are attributes of it, as jQuery objects) and many methods. For example if you load a template but don't want one of the columns, you could do something like this:

The above code will then apply to all tables built by IMBedding. To alter the behaviour for just one table, supply a value for the afterBuildTable and afterTableUpdate options values. Both the table specific function, and the global one will be run.

Showing Contents on Load

Setting openOnLoad to true loads the table pre-opened. Clicking on the titlebar of this table will collapse it.

Changing Title Click Behaviour

The default behaviour for a click on the title is to expand/collapse the table. You can choose other behaviours:

Default Behaviour

This will be where the table goes

Click Through to Mine

This will be where the table goes

No Behaviour

This will be where the table goes

Arbitrary Behaviour

This will be where the table goes

Configuring What is Shown

As well as the title, by default the table will also contain export links, a link to the results in the originating mine, a count of the total results, and pages with 10 rows of results. The tables below show adjustments to these features.

No Export Links

This will be where the table goes

No Count

This will be where the table goes

No Mine Link

This will be where the table goes

A Different Number of Rows

This will be where the table goes

A Different Language

This will be where the table goes