Frame map (USA states)
Updated 7 years ago by Template retirement home
How to use this template
USA framed-rectangle template
A template based around Cleveland and McGill's framed-rectangle alternative to a choropleth map. Sample data (which matches and updates the original data) comes from the FBI's Uniform Crime Reporting Program.
API information
This section documents API usage specific to this template, so for an introduction we suggest you refer to the generic API documentation instead.
template: _103
version: _2
Template data
There are three different formats in which you can supply data to this template. The most convenient for you to use likely depends on the source of your data, as described below.
1. Array of arrays, and a bindings object
You can supply arrays of arrays to opts.data
, which might look
like:
{ data: { "barData": [ [ "BarDataColumn1Value1", "BarDataColumn2Value1", [ "BarDataColumn1Value2", "BarDataColumn2Value2", [ "BarDataColumn1Value3", "BarDataColumn2Value3", ... ] } }
where each array of arrays represents the rows in a data sheet.
To tell the API how the 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: "_103", version: "_2", bindings: { "barData": { state: 0, // index of a column in your data } }, data: { "barData": [ [ "BarDataColumn1Value1", "BarDataColumn2Value1", [ "BarDataColumn1Value2", "BarDataColumn2Value2", [ "BarDataColumn1Value3", "BarDataColumn2Value3", ... ] } }
All possible bindings that you can supply are shown in this example:
{ template: "_103", version: "_2", bindings: { "barData": { state: 0, // index of a column in your data values: [1, 2, ...], // index(es) of column(s) in your data } }, data: { "barData": [ [ "BarDataColumn1Value1", "BarDataColumn2Value1", [ "BarDataColumn1Value2", "BarDataColumn2Value2", [ "BarDataColumn1Value3", "BarDataColumn2Value3", ... ] } }
2. 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:
{ "barData": [ { "BarDataHeader1": ..., "BarDataHeader2": ..., ... }, { "BarDataHeader1": ..., "BarDataHeader2": ..., ... }, { "BarDataHeader1": ..., "BarDataHeader2": ..., ... }, ... ] }
... but with the keys being the column headers from your
source data instead. You must also supply an object attached to
opts.bindings
. The minimal bindings you can
supply for this template are as shown in this example:
{ template: "_103", version: "_2", bindings: { "barData": { state: "BarDataHeader1", } }, data: { "barData": [ { "BarDataHeader1": ..., "BarDataHeader2": ..., ... }, { "BarDataHeader1": ..., "BarDataHeader2": ..., ... }, { "BarDataHeader1": ..., "BarDataHeader2": ..., ... }, ... ] } }
All possible bindings that you can supply are shown in this example:
{ template: "_103", version: "_2", bindings: { "barData": { state: "BarDataHeader1", values: ["BarDataHeader2", "BarDataHeader3", ...], } }, data: { "barData": [ { "BarDataHeader1": ..., "BarDataHeader2": ..., ... }, { "BarDataHeader1": ..., "BarDataHeader2": ..., ... }, { "BarDataHeader1": ..., "BarDataHeader2": ..., ... }, ... ] } }
(As before, the keys containing "Header" would be replaced by column names from your data source.)
3. 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: "_103", version: "_2", data: { barData: [ { state: ..., values: [...] }, ... ] }, ... }
And the full list of all possible properties is as follows:
{ template: "_103", version: "_2", data: { barData: [ { state: ..., values: [...] }, ... ] }, ... }
Meanings of the template data keys:
- barData.state: state
- barData.values: values
Template settings
Options for opts.state
.
Text & nav
textCol color
Colour of text annotations.
title string
Title.
mode string
Column browser style. Choose from [[Slider]] or [[Buttons]]. Ignored if you've only selected one column.
Frames & bars
outlineWidth number
Width of the frame border.
outlineCol color
Colour of frame outlines.
boxFillCol color
Colour of frame interiors.
dataCol color
Colour of data.
duration number
Duration. The duraiton of the animation in milliseconds
Map colors
seaCol color
Colour of sea.
landCol color
Colour of land.
lsCol color
Colour of external borders.
stateBorderCol color
Colour of state borders.