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: @duncan/word-cloud
version: 1
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: { words: [ [ "WordsColumn1Value1", "WordsColumn2Value1", [ "WordsColumn1Value2", "WordsColumn2Value2", [ "WordsColumn1Value3", "WordsColumn2Value3", ... ] } }
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: "@duncan/word-cloud", version: "1", bindings: { words: { word: 0, // index of a column in your data frequency: 1, // index of a column in your data } }, data: { words: [ [ "WordsColumn1Value1", "WordsColumn2Value1", [ "WordsColumn1Value2", "WordsColumn2Value2", [ "WordsColumn1Value3", "WordsColumn2Value3", ... ] } }
All possible bindings that you can supply are shown in this example:
{ template: "@duncan/word-cloud", version: "1", bindings: { words: { word: 0, // index of a column in your data frequency: 1, // index of a column in your data } }, data: { words: [ [ "WordsColumn1Value1", "WordsColumn2Value1", [ "WordsColumn1Value2", "WordsColumn2Value2", [ "WordsColumn1Value3", "WordsColumn2Value3", ... ] } }
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:
{ words: [ { "WordsHeader1": ..., "WordsHeader2": ..., ... }, { "WordsHeader1": ..., "WordsHeader2": ..., ... }, { "WordsHeader1": ..., "WordsHeader2": ..., ... }, ... ] }
... 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: "@duncan/word-cloud", version: "1", bindings: { words: { word: "WordsHeader1", frequency: "WordsHeader2", } }, data: { words: [ { "WordsHeader1": ..., "WordsHeader2": ..., ... }, { "WordsHeader1": ..., "WordsHeader2": ..., ... }, { "WordsHeader1": ..., "WordsHeader2": ..., ... }, ... ] } }
All possible bindings that you can supply are shown in this example:
{ template: "@duncan/word-cloud", version: "1", bindings: { words: { word: "WordsHeader1", frequency: "WordsHeader2", } }, data: { words: [ { "WordsHeader1": ..., "WordsHeader2": ..., ... }, { "WordsHeader1": ..., "WordsHeader2": ..., ... }, { "WordsHeader1": ..., "WordsHeader2": ..., ... }, ... ] } }
(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: "@duncan/word-cloud", version: "1", data: { words: [ { word: ..., frequency: ... }, ... ] }, ... }
And the full list of all possible properties is as follows:
{ template: "@duncan/word-cloud", version: "1", data: { words: [ { word: ..., frequency: ... }, ... ] }, ... }
Meanings of the template data keys:
- words.word: word
- words.frequency: frequency
Template settings
Options for opts.state
.
title string
Title.
subtitle string
Subtitle.
titles_margin number
Titles margin.
text_color color
Text.
bg_color color
Backgrnd.
data_tables boolean
Text input. Allowed values:
raw_text text
Text.
font string
Font. You can use any font on your computer but for publishing online stick to universal fonts (such as Georgia, Verdana, Times New Roman) or Source Sans Pro, which is included in the template and used for the title and subtitle.
padding number
Word spacing.
word_limit number
Word limit. Limits the number of words, in order of frequency. Leave blank to show all words in the data table. Min: 1
random_seed number
Randomiser. Change the number to try different layouts
exclusions boolean
Exclude common words.
excluded_words text
Exclude words.