Horserace chart

This template has been retired. New projects should use @flourish/horserace instead.

Updated 3 years ago by Template retirement home

How to use this template

Horserace chart

A simple charting template for plotting changing rank in a group of competitors over time. Useful for showing the changing fortunes of candidates in elections, football team, etc.

Usage

Each row must be a timeslice (week, day, etc). Each timeslice is plotted at an equal width. Use the column selectors to point to one column for the name of the timeslice, and two or more columns for the ranks of the “horses”.

Credits and feedback

Coded by Duncan Clark based on a design by Google News Lab. Want to see additional features? Let us know at support@flourish.studio (or submit a pull request).

This section documents API usage specific to this template, so for an introduction we suggest you refer to the generic API documentation instead.

template: _86

version: _10

Template data

There are two different formats in which you can supply data to this template. Which one will be more convenient for you likely depends on the source of your data, as described below.

Array of objects with arbitrary keys, and a bindings object

This format is most likely useful when you have data from an external source, such as CSV data loaded from d3-dsv. You should supply this attached to the opts.data, which might look like:

    {
        horserace: [
            { "HorseraceHeader1": ..., "HorseraceHeader2": ..., ... },
            { "HorseraceHeader1": ..., "HorseraceHeader2": ..., ... },
            { "HorseraceHeader1": ..., "HorseraceHeader2": ..., ... },
            ...
        ]
    }

... but with the keys being the column headers from your source data instead. To tell the API how these values from each column should be associated with the keys that the template is expecting, you must also supply an object attached to opts.bindings. (The meanings of the keys in the bindings object are documented below.) The minimal bindings you can supply for this template are as shown in this example:

{
    template: "_86",
    version: "_10",
    bindings: {
        horserace: {
            timeslice: "HorseraceHeader1"
        }
    },
    data: {
        horserace: [
            { "HorseraceHeader1": ..., "HorseraceHeader2": ..., ... },
            { "HorseraceHeader1": ..., "HorseraceHeader2": ..., ... },
            { "HorseraceHeader1": ..., "HorseraceHeader2": ..., ... },
            ...
        ]
    }
}

All possible bindings that you can supply are shown in this example:

{
    template: "_86",
    version: "_10",
    bindings: {
        horserace: {
            timeslice: "HorseraceHeader1",
            horses: ["HorseraceHeader2", "HorseraceHeader3", ...]
        }
    },
    data: {
        horserace: [
            { "HorseraceHeader1": ..., "HorseraceHeader2": ..., ... },
            { "HorseraceHeader1": ..., "HorseraceHeader2": ..., ... },
            { "HorseraceHeader1": ..., "HorseraceHeader2": ..., ... },
            ...
        ]
    }
}

(As before, the keys containing "Header" would be replaced by column names from your data source.)

Array of objects with template-defined keys

There is an alternative format you can use, which is likely to be easier to use if your data is not from a spreadsheet source. With this alternative format you supply your data to the template as an array of objects, attached to opts.data, where the keys must be those used by the template, as documented below. In this case there is no need to supply a bindings object, since the key names are already those expected by the template. The required properties in the data object are as follows (scroll down for a description of what each property is):

{
template: "_86",
version: "_10",
data: {
    horserace: [
        {
            timeslice: ...,
            horses: [...]
        },
        ...
    ]
},
...
}

And the full list of all possible properties is as follows:

{
template: "_86",
version: "_10",
data: {
    horserace: [
        {
            timeslice: ...,
            horses: [...]
        },
        ...
    ]
},
...
}

Meanings of the template data keys:

  • horserace.timeslice: timeslice
  • horserace.horses: horses

Template settings

Options for opts.state.

Lines

line_width number

Line width.

line_opacity number

Line opacity.

shade boolean

Show shading behind line.

shade_width number

Shading width.

shade_opacity number

Shading opacity.

Cirles and labels

start_circle_r number

Start circle radius.

end_circle_r number

End circle radius.

rank_font_size number

Rank font size.

label_font_size number

Label font size.

Colors

bgcolor color

Background color.

palette string

Color scheme. Choose a d3 color scheme, such as [[schemeCategory20]], [[schemeCategory20b]], [[schemeCategory20c]] or [[schemeCategory10]]

Animation

duration number

Animation duration. The animation speed, milliseconds per timeslice

Margins

margin_top number

Top.

margin_right number

Right.

margin_bottom number

Bottom.

margin_left number

Left.

Text

button_text string

Replay button text.