Cohort

Updated 2 years ago by Template retirement home

How to use this template

Flourish Cohort template

A template designed for exploring a sample of people, such as survey respondents or conference attendees.

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

template: _87

version: _12

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:

    {
        cohort: [
            { "CohortHeader1": ..., "CohortHeader2": ..., ... },
            { "CohortHeader1": ..., "CohortHeader2": ..., ... },
            { "CohortHeader1": ..., "CohortHeader2": ..., ... },
            ...
        ],
        locations: [
            { "LocationsHeader1": ..., "LocationsHeader2": ..., ... },
            { "LocationsHeader1": ..., "LocationsHeader2": ..., ... },
            { "LocationsHeader1": ..., "LocationsHeader2": ..., ... },
            ...
        ]
    }

... 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: "_87",
    version: "_12",
    bindings: {
        cohort: {
            name: "CohortHeader1",
            country_code: "CohortHeader12"
        },
        locations: {
            country_code: "LocationsHeader1",
            latitude: "LocationsHeader2",
            longitude: "LocationsHeader3"
        }
    },
    data: {
        cohort: [
            { "CohortHeader1": ..., "CohortHeader2": ..., ... },
            { "CohortHeader1": ..., "CohortHeader2": ..., ... },
            { "CohortHeader1": ..., "CohortHeader2": ..., ... },
            ...
        ],
        locations: [
            { "LocationsHeader1": ..., "LocationsHeader2": ..., ... },
            { "LocationsHeader1": ..., "LocationsHeader2": ..., ... },
            { "LocationsHeader1": ..., "LocationsHeader2": ..., ... },
            ...
        ]
    }
}

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

{
    template: "_87",
    version: "_12",
    bindings: {
        cohort: {
            name: "CohortHeader1",
            filters: ["CohortHeader2", "CohortHeader3", ...],
            size_by: ["CohortHeader4", "CohortHeader5", ...],
            group_by: ["CohortHeader6", "CohortHeader7", ...],
            shade_by: ["CohortHeader8", "CohortHeader9", ...],
            mouseovers: ["CohortHeader10", "CohortHeader11", ...],
            country_code: "CohortHeader12"
        },
        locations: {
            country_code: "LocationsHeader1",
            latitude: "LocationsHeader2",
            longitude: "LocationsHeader3"
        }
    },
    data: {
        cohort: [
            { "CohortHeader1": ..., "CohortHeader2": ..., ... },
            { "CohortHeader1": ..., "CohortHeader2": ..., ... },
            { "CohortHeader1": ..., "CohortHeader2": ..., ... },
            ...
        ],
        locations: [
            { "LocationsHeader1": ..., "LocationsHeader2": ..., ... },
            { "LocationsHeader1": ..., "LocationsHeader2": ..., ... },
            { "LocationsHeader1": ..., "LocationsHeader2": ..., ... },
            ...
        ]
    }
}

(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: "_87",
version: "_12",
data: {
    cohort: [
        {
            name: ...,
            filters: [...],
            size_by: [...],
            group_by: [...],
            shade_by: [...],
            mouseovers: [...],
            country_code: ...
        },
        ...
    ],
    locations: [
        {
            country_code: ...,
            latitude: ...,
            longitude: ...
        },
        ...
    ]
},
...
}

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

{
template: "_87",
version: "_12",
data: {
    cohort: [
        {
            name: ...,
            filters: [...],
            size_by: [...],
            group_by: [...],
            shade_by: [...],
            mouseovers: [...],
            country_code: ...
        },
        ...
    ],
    locations: [
        {
            country_code: ...,
            latitude: ...,
            longitude: ...
        },
        ...
    ]
},
...
}

Meanings of the template data keys:

  • cohort.name: name
  • cohort.filters: Each column represents a point on the timeline. The row is included at that point if the cell contains a 1.
  • cohort.size_by: size_by
  • cohort.group_by: group_by
  • cohort.shade_by: shade_by
  • cohort.mouseovers: Which columns to show in the mouseover popup
  • cohort.country_code: The column with the location codes used for mapping. The codes should match the codes in the Locations data sheet.
  • locations.country_code: These codes should match the codes used in the other data sheet.
  • locations.latitude: latitude
  • locations.longitude: longitude

Template settings

Options for opts.state.

Dots

gooey_effect boolean

Gooey effect. Add a gooey effect to turn the dots into overlapping droplets

opacity number

Dot opacity. Set the opacity from 0 to 1

Max: 1

radius number

Default dot radius. The default size of the dots. Ignored when bubbles are sized by the data. Reduce to fit more dots on the screen

Min: 1

Colors

dot_color color

Default dot color. The default colour of the dots. Ignored when bubbles are coloured by the data.

color_palette string

Default color scheme. The default color scheme when shading by a metric. Choose from [[schemeCategory10]], [[schemeCategory20]] or [[interpolatePlasma]]. Use the setting below to specify any overrides.

color_overrides text

Specific dot colors. Specify any specific colors as a comma-separated list using equals signs, e.g. "dogs=red,cats=#aaa". Cases are ignored.

ui_label_colour color

Label colours. The text colour of the labels on the menus and slider

Background

background_col color

Background colour. The colour behind the dots and buttons.

background_opacity number

Background opacity. The opacity of the background colour.

Max: 1

gradient_opacity number

Gradient opacity. The opacity of the background gradient shade at the top and left.

Max: 1

map_opacity_map_mode number

Map opacity in map mode.

Max: 1

map_opacity_non_map_mode number

Map opacity in other modes.

Max: 1

hide_nav boolean

Hide all navigation.