@flourish/sdk 3.17.2 → 3.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +1 -0
  2. package/README.md~ +473 -0
  3. package/RELEASE_NOTES.md +12 -0
  4. package/RELEASE_NOTES.md~ +372 -0
  5. package/bin/{flourish → flourish.js} +31 -42
  6. package/lib/cmd/assign-version-number.js +4 -6
  7. package/lib/cmd/build.js +6 -10
  8. package/lib/cmd/delete.js +4 -6
  9. package/lib/cmd/help.js +3 -5
  10. package/lib/cmd/history.js +4 -6
  11. package/lib/cmd/list.js +4 -6
  12. package/lib/cmd/login.js +5 -7
  13. package/lib/cmd/logout.js +3 -5
  14. package/lib/cmd/new.js +3 -5
  15. package/lib/cmd/publish.js +9 -10
  16. package/lib/cmd/register.js +5 -7
  17. package/lib/cmd/run.js +3 -5
  18. package/lib/cmd/upgrade/1-convert-config-to-yaml.js +6 -8
  19. package/lib/cmd/upgrade/2-convert-index-html.js +3 -4
  20. package/lib/cmd/upgrade/3-add-build-config.js +3 -4
  21. package/lib/cmd/upgrade/4-remove-autoheight-config.js +3 -4
  22. package/lib/cmd/upgrade/index.js +5 -7
  23. package/lib/cmd/version.js +5 -13
  24. package/lib/cmd/whoami.js +4 -6
  25. package/lib/log.js +7 -7
  26. package/lib/sdk.js +43 -54
  27. package/lib/sdk.js~ +540 -0
  28. package/lib/validate_config.js +7 -1
  29. package/lib/validate_config.js~ +437 -0
  30. package/package-lock.json~ +2669 -0
  31. package/package.json +5 -5
  32. package/package.json~ +53 -0
  33. package/server/comms_js.js +1 -0
  34. package/server/data.js +40 -5
  35. package/server/index.js~ +540 -0
  36. package/server/views/index.html +9 -5
  37. package/site/embedded.js +1 -1
  38. package/site/images/flourish_in_canva.png +0 -0
  39. package/site/images/share_image.jpg +0 -0
  40. package/site/script.js +2 -2
  41. package/site/sdk.css +1 -1
  42. package/test/lib/validate_config.js +11 -2
  43. package/test/lib/validate_config.js~ +1006 -0
package/README.md CHANGED
@@ -52,6 +52,7 @@ The main Flourish configuration file for your template. The top-level properties
52
52
  * `credits` Optional credits for data sources, map tiles, etc, in Markdown format
53
53
  * `image_download` Flag to indicate whether image snapshots work for the template (default is `true`)
54
54
  * `svg_download` Flag to indicate whether downloading a snapshot of template as SVG will work (default is `true`)
55
+ * `is_premium` Flag to indicate that this is a premium template, meaning only particular feature bundles give access to it (default is `false`)
55
56
 
56
57
  Other properties are [settings](#settings), [data](#data), [build](#build), and [tour](#tour), which are described below.
57
58
 
package/README.md~ ADDED
@@ -0,0 +1,473 @@
1
+ # The Flourish SDK
2
+
3
+ [**Flourish**](https://flourish.studio) is a platform for visualising and storytelling with data. It allows users to quickly create high-quality visualisations, stories, presentations and other interactive content by putting their own data and text into configurable templates.
4
+
5
+ This SDK allows developers to make templates and upload them to Flourish.
6
+
7
+ ## Quickstart
8
+ * [Install the SDK](#using-the-sdk): `npm install -g @flourish/sdk`
9
+ * [Create a new template](#create-a-new-template): `flourish new [dir_name]`
10
+ * [Run/view a template](#run-and-view-a-template): `flourish run [dir_name]`
11
+ * [Register an account](#login-logout-register-check-status): `flourish register`
12
+ * [Publish your template](#publish-a-template): `flourish publish [dir_name]`
13
+
14
+ See [all commands and options](#using-the-sdk). There are also a few [example templates](https://flourish.studio/developers/examples/) you can use for reference.
15
+
16
+ ## Template overview
17
+ There is no limit to what a Flourish template can be or do. It may be a simple chart, a 3D visualisation in WebGL, or a richly interactive app with a complex UI. There's also no limit to how you can write your code, what libraries you can use, etc. The only requirement is that the template directory includes [certain files](#template-files), as specified below, and that the `template.js` creates a `window.template` object with the following properties:
18
+
19
+ * [`state`](#state) The template's current state; updated by Flourish when the user changes a setting or switches slide
20
+ * [`draw()`](#draw) Called by Flourish when the template is loaded
21
+ * [`update()`](#update) Called by Flourish when the user changes a setting or data table, or switches slide
22
+ * [`data`](#data-1) Optional; updated by Flourish with data from any user-editable data tables
23
+
24
+ ## Template files
25
+ A Flourish template is a directory containing, at a minimum:
26
+ * [`template.yml`](#templateyml) Flourish configuration
27
+ * [`template.js`](#templatejs) The template’s JavaScript code, usually generated
28
+
29
+ Templates often also include:
30
+ * [`thumbnail.jpg` or `thumbnail.png`](#thumbnailjpg-or-thumbnailpng) Template image for use on Flourish: strongly recommended, and may become mandatory in the future
31
+ * [`index.html`](#indexhtml) The template HTML
32
+ * [`src/`](#src) JavaScript source files
33
+ * [`data/`](#data) Data tables in CSV format that define the sample data shipped with the template
34
+ * [`static/`](#static) Arbitrary static files that can be referenced by the template
35
+ * [`GUIDE.md`](#guidemd) Documentation for end users of the template in Flourish, in Markdown format
36
+ * [`README.md`](#readmemd) Documentation for developers working on the template, in Markdown format
37
+
38
+ The following files are not treated specially by Flourish, but many templates include them as part of the way they are packaged and built:
39
+ * [`package.json`](#packagejson) NPM package configuration specifying dependencies etc.
40
+ * [`rollup.config.js`](#rollupconfigjs) rollup.js configuration
41
+
42
+ ### `template.js`
43
+ The template script. Typically generated using a build process, such as rollup.js, from Javascript modules in `src/`, though in principle you could write it directly as long as it creates a `window.template` object that has function properties [`update()`](#update) and [`draw()`](#draw), and object properties [`state`](#state) and optionally [`data`](#data-1).
44
+
45
+ ### `template.yml`
46
+ The main Flourish configuration file for your template. The top-level properties are:
47
+ * `sdk_version` Which major version of the Flourish SDK the template is compatible with. Currently this should be `3`.
48
+ * `id` A unique identifier for your template. If you publish a template and the `id` is already in use by you, the Flourish server will assume you are updating an existing template and overwrite it.
49
+ * `name` What the template will be called within Flourish
50
+ * `author` Who wrote the template
51
+ * `description` A short description of the template
52
+ * `credits` Optional credits for data sources, map tiles, etc, in Markdown format
53
+ * `image_download` Flag to indicate whether image snapshots work for the template (default is `true`)
54
+ * `svg_download` Flag to indicate whether downloading a snapshot of template as SVG will work (default is `true`)
55
+ * `is_premium` Flat to indicate that this is a premium template, meaning on particular feature bundles give access to it (default is `false`)
56
+
57
+ Other properties are [settings](#settings), [data](#data), [build](#build), and [tour](#tour), which are described below.
58
+
59
+ #### build configuration
60
+ The `template.yml` file will usually also include a `build` section defining build rules. For example:
61
+
62
+ ```yaml
63
+ build:
64
+ # Defines the build processes used to build your template from source.
65
+ # You can have any number of build processes, and changes to the relevant
66
+ # files will trigger the appropriate build. Here we define build scripts
67
+ # for JavaScript and CSS.
68
+
69
+ src:
70
+ script: npm run build
71
+ # You can specify a whole directory, or individual files, or both.
72
+ # A change inside the directory or to any of the listed files will
73
+ # trigger a rebuild and reload.
74
+ directory: src
75
+ files:
76
+ - rollup.config.js
77
+
78
+ less:
79
+ script: npm run less
80
+ directory: less
81
+ ```
82
+
83
+ It’s also possible to use a custom watch command, instead of relying on Flourish to run your build script when one of the specified files has changed. Specify the watch script using the `watch:` key within the build rule. In this case the build script will not execute when you use `flourish run`, but the watch script will be run instead. You may not specify `files:` or `directory:` if you use `watch:`.
84
+
85
+ #### settings
86
+ The `template.yml` file will usually also include a `settings` section which populates the settings panel in the Flourish visualisation editor (and SDK). Each setting allows the user to change a specific property in the template [`state`](#state). When a setting is changed by the user , `state` is updated and the template's `update()` function is called.
87
+
88
+ If an entry in the settings array is a string, it is interpreted as a section title. Otherwise it must be an object with the `property` and `type` properties. Other properties are optional, but `name` and `description` are recommended to help the user understand the role of the setting. (As a special case, a section titled "State documentation" will be hidden in the visualisation editor: it's just for grouping documentation of non-settings state properties.)
89
+
90
+ ```yaml
91
+ settings:
92
+ - Section title # Headings can be used to break up the settings into collapsible sections
93
+ - property: my_state_property # Required; must be a property of the state object
94
+ name: Example number setting # Optional; appears next to the setting
95
+ description: A setting for changing a number # Optional; appears on mouseover
96
+ type: number # Required; see available types below
97
+ ```
98
+
99
+ To improve the layout of your settings, you can set the `width` of any setting to be `full`, `half`, `three quarters` or `quarter` of the width of the settings panel. You can also add a horizontal separator above a setting using `new_section: true`, or a subheading using `new_section: This is a subheading`.
100
+
101
+ ```yaml
102
+ - property: my_number
103
+ name: Neat little number input
104
+ width: quarter # Optional; sets the width of the setting
105
+ new_section: true # Optional; starts a new line with the current setting and adds a line above
106
+ ```
107
+
108
+ The following types of settings are supported:
109
+
110
+ ##### `boolean`
111
+ Creates a checkbox that sets the state property to `true` or `false`. Alternatively can be displayed as two buttons using the `choices` attribute to specify labels and/or images. For example:
112
+
113
+ ```yaml
114
+ - property: ranked
115
+ type: boolean
116
+ choices:
117
+ - [ Ranks, true ]
118
+ - [ Scores, false ]
119
+ ```
120
+
121
+ ##### `color`
122
+ Creates a colour picker that sets the state property to a string containing a hex RGB colour e.g. `"#123456"`.
123
+
124
+ ##### `colors`
125
+ Creates a colour palette picker that sets the state property to an array of strings, each containing a colour value, e.g. `"#ff33c0"`. The menu contains the Flourish standard palettes plus any additional ones associated with the user's company. The user can edit the selected palette to add/remove/change colours.
126
+
127
+ ##### `number`
128
+ Creates a number input that sets the state property to a number. Optionally add `min` and `max` properties to limit the range, `step` to control the input’s increment buttons. By default number settings always return a number and blanked inputs are set to zero; to allow blanked input, with `null` returned as the value, add `optional: true`. Width defaults to `half`.
129
+
130
+ ##### `string`
131
+ By default, creates a single-line text input that sets the state property to the relevant string text. If you add a valid `choices` property, the setting instead creates a dropdown (by default) or button group (if you also add `style: buttons`). The `choices` property must be an array. Each of its element can be a string (in which case this string is returned to the state) or an array containing a display name, the associated string value and (for button groups) a background image.
132
+
133
+ To add a special dropdown that allows the user to specify any text in addition to choosing from the list, add `choices_other: true`. This is ignored for button groups.
134
+
135
+ ```yaml
136
+ - property: size
137
+ name: Size
138
+ type: string
139
+ choices: # An array of values to fill the dropdown
140
+ – small_size # A choice can be a string
141
+ – # Or a choice can be an array of two or three elements …
142
+ – Absolutely enormous # … in which case the first string is the display name,
143
+ – large_size # … the second string is the value passed to the template
144
+ – massive.jpg # … the third is an image file name in your `static` directory
145
+ choices_other: true # allows the user to input any value they like
146
+ ```
147
+
148
+ ##### `text`
149
+ Creates a user-resizeable multiline text input. Defaults to two lines tall. Can be made taller by adding `size: large`, which sets the height to half of the viewport height.
150
+
151
+ ##### `code`
152
+ Same as `text` but with a monospace font and text-wrapping control.
153
+
154
+ ##### `font`
155
+ Creates a font picker that sets the state property to the URL of a CSS stylesheet that will specify font imports. By default these are Google fonts, with URLs like `https://fonts.googleapis.com/css?family=Montserrat`. The value passed to the template `state` will be an object specifying both the font name and URL, for example: `body_font: { name: "Mali", url: "https://fonts.googleapis.com/css?family=Mali" }`. A template can load the font by inserting a `link` tag into the document, like this:
156
+ ```javascript
157
+ var font_link = document.createElement("link");
158
+ font_link.setAttribute("rel", "stylesheet");
159
+ document.body.appendChild(font_link);
160
+ // Assuming the setting property is named "body_font"
161
+ font_link.setAttribute("href", state.body_font.url);
162
+ ```
163
+ Then elements can be styled by referencing the font name, whether in attributes or in CSS. If the font is being inherited in CSS, you could just add it to the document body, like this:
164
+ ```javascript
165
+ document.body.style.fontFamily = state.body_font.url;
166
+ ```
167
+
168
+ #### `hidden`
169
+ This type is for documenting state properties which should not be editable from the settings panel in the visualisation editor. Any property with a `hidden` type will not be editable within the visualisation editor interface.
170
+
171
+ #### Conditional settings
172
+ Sometimes you might want to simplify the user experience for Flourish users by hiding some settings depending on whether they are needed or not. You can use the `show_if` and `hide_if` properties to control whether or not a setting should be displayed based on another setting’s value.
173
+
174
+ In the following example, the x axis label setting will only be displayed if “Show x axis” is selected:
175
+
176
+ ```yaml
177
+ - property: show_x_axis
178
+ name: Show x axis
179
+ type: boolean
180
+
181
+ - property: x_axis_label
182
+ name: X axis label
183
+ type: string
184
+ show_if:
185
+ show_x_axis: true
186
+ ```
187
+
188
+ You can use the following shorthand syntax for booleans. This is equivalent to the previous example:
189
+
190
+ ```yaml
191
+ show_if: show_x_axis
192
+ ```
193
+
194
+ If you specify an array of conditional values, this setting will be displayed if the referenced setting has _any_ of the specified values. In the following example, the setting is displayed if `color_mode` is set to either `"diverging"` or `"continuous"`:
195
+
196
+ ```yaml
197
+ show_if:
198
+ color_mode: [diverging, continuous]
199
+ ```
200
+
201
+ You can specify multiple conditions. All of these tests must pass for the setting to be displayed. For example:
202
+
203
+ ```yaml
204
+ show_if:
205
+ show_x_axis: true
206
+ color_mode: diverging
207
+ ```
208
+
209
+ The `hide_if` option works in exactly the same way, except that the setting is hidden if the conditional test passes.
210
+
211
+ ```yaml
212
+ hide_if:
213
+ color_mode: diverging
214
+ ```
215
+
216
+ You can also control settings display depending on whether or not particular data bindings have been specified. A binding is specified using the syntax `data.[dataset].[key]`. For example:
217
+
218
+ ```yaml
219
+ show_if: data.values.filter1 // shorthand syntax
220
+
221
+ show_if:
222
+ data.values.filter1: true
223
+ ```
224
+
225
+ You cannot specify both `show_if` and `hide_if` options on the same setting.
226
+
227
+ #### data bindings
228
+ The `template.yml` file may also include a `data` section. This section consists of an array of data ‘bindings’ that sets how the template should use and refer to the template’s editable data tables (which are initially populated by the CSV files in [`data/`](#data)). Each binding adds one or more columns of data to a `dataset` under a particular `key`. You can define as many datasets as you like. They are made available to the template as properties of [the `data` object](#data-1). Each one consists of an array containing an object for each row of the relevant data table, as shown in the example below.
229
+
230
+ Once your template is published, Flourish users can change the data in the Flourish editor, and also change which columns are linked to each binding. But in your code you don’t need to worry about this because you just refer to the `key` rather than referencing the column header or index.
231
+
232
+ There are two types of data binding: `column` is used when the number of columns is and must always be one; `columns` supports any number of columns, including none.
233
+
234
+ A default value must be supplied for each data binding, unless you have specified `optional: true` (only supported for single `column` bindings). The example below shows how this is done.
235
+
236
+ The following example sets up a dataset with two keys, one single-column and one multi-column.
237
+
238
+ ```yaml
239
+ data:
240
+ - Locations # Optional; breaks up the bindings into collapsible sections
241
+ - Description string # Optional; additional description to explain to the user how the data binding works
242
+ - name: Country code # Name shown in UI
243
+ description: Requires ISO 3166-1 alpha-2 codes # Optional description for the UI
244
+ dataset: country_scores # Which dataset this binding is part of
245
+ key: iso_code # The key used to access the data in this binding in the template code
246
+ type: column # This binding can take only one column
247
+ column: By Decade::A # The default values are drawn from column A of `By Decade.csv`
248
+ - name: Values
249
+ dataset: country_scores
250
+ key: values
251
+ type: columns # This binding can take any number of columns
252
+ columns: By Decade::B-D,F # The default values are arrays drawing from columns B-D and F of `By Decade.csv`
253
+ - name: Flag image
254
+ dataset: country_scores
255
+ key: flag_pic
256
+ type: column
257
+ optional: true # Default values can be omitted for an optional binding
258
+ ```
259
+
260
+ In this example, if `By Decade.csv` contained the following…
261
+
262
+ ```csv
263
+ Country,1970s,1980s,1990s,20th_century_mean,2000s
264
+ US,3122,3128,3129,984,3119
265
+ GB,1203,1205,1208,1121,1200
266
+ FR,1030,1005,1010,3076,1024
267
+ ```
268
+ … then in your template `data.country_scores` would be:
269
+
270
+ ```js
271
+ [
272
+ { iso_code: "US", values: [ "3122", "3128", "3129", "3119" ]},
273
+ { iso_code: "GB", values: [ "1203", "1205", "1208", "1200" ]},
274
+ { iso_code: "FR", values: [ "1030", "1005", "1010", "1024" ]}
275
+ ]
276
+ ```
277
+ The column headers are available in any dataset via the `column_names` property of the data array. E.g. in the above example `data.country_scores.column_names` is:
278
+
279
+ ```js
280
+ { iso_code: "Country", values: [ "1980s", "1990s", "2000s", "2010s" ]}
281
+ ```
282
+
283
+ #### tour
284
+ You can optionally include a `tour` block which can be used to guide people through using the template in the Flourish editor.
285
+
286
+ A tour is an array of steps, each of which will be presented to the user in a popup. Here’s an example:
287
+
288
+ ```yaml
289
+ tour:
290
+ - text: This template is ideal for displaying categorical data.
291
+ - text: Adjust these settings to customise the appearance of your visualisation.
292
+ anchor: '.settings'
293
+ ```
294
+ Each step must include a `text` property, which will be displayed in the modal. Additional optional properties are as follows:
295
+
296
+ * `anchor`: CSS selector for a DOM element in the editor to which the tour popup should be anchored. Use your browser’s web inspector to discover suitable class names or ids.
297
+ * `position`: Where the popup should be positioned relative to its anchor. One of `bottom` (the default), `top`, `left` or `right`.
298
+ * `button_text`: By default, each step displays with a button reading “Next”. You can specify an alternative label here.
299
+ * `trigger`: In some cases, you might need to ensure a particular action has been triggered in the UI before you display the next step. For example, if you want to highlight something in the Data tab, then you need to ensure that the data tab has been selected. You can use the `trigger` property to do this, by supplying a string of the form `[event type] [selector]`, e.g. `click button.data`. If the user triggers this event, the next step will automatically be displayed. If they press the “Next” button first, then the specified event will be dispatched before the next popup is displayed.
300
+
301
+ #### `thumbnail.jpg` or `thumbnail.png`
302
+ A thumbnail image for your template in JPEG or PNG format. No particular size is required – the precise size at which the image is displayed depends on the size of the browser window – but we recommend approximately 600px × 400px.
303
+
304
+ #### `index.html`
305
+ The base HTML for the template, if required.
306
+
307
+ To reference resources in the [static directory](#static) use relative links, e.g.
308
+ ```html
309
+ <img src="logo.png">
310
+ ```
311
+ These relative links will be replaced by a suitable path when the template is rendered. If you’re creating links to static resources with code, you need to prefix them with the value of `Flourish.static_prefix`. [See below for more about static resources.](#static)
312
+
313
+ You can add DOM elements, script tags, external stylesheets, etc, to your `index.html`, as with any other html page. Do not reference assets at non-`https` addresses, since these will cause problems when the template is embedded in Flourish or any other secure website.
314
+
315
+ If the `index.html` file is missing, the following default HTML is used:
316
+ ```html
317
+ <!doctype html>
318
+ <html>
319
+ <head>
320
+ <meta charset="utf-8">
321
+ <style>
322
+ html, body { height: 100%; margin: 0; overflow: hidden; }
323
+ </style>
324
+ </head>
325
+ <body>
326
+ </body>
327
+ </html>
328
+ ```
329
+ There is no need to include a `<title>` element, because Flourish will insert an appropriate one when it renders the template. If you do include a `<title>` then it will be replaced.
330
+
331
+ #### `src/`
332
+ JavaScript source code. Typically these will be [bundled in a build process](#build-configuration) to create [`template.js`](#templatejs).
333
+
334
+ In simple templates `src/` may contain just a single `index.js` which will export the three key template properties – [`state`](#state), [`draw()`](#draw), [`update()`](#update) – and, optionally, [`data`](#data-1).
335
+
336
+ If you modify a source file while the SDK is running, the SDK will run the appropriate build script [specified in `template.yml`](#build-configuration) and then reload the preview.
337
+
338
+ Source files are not uploaded to the server when you publish a template.
339
+
340
+ #### `data/`
341
+
342
+ A directory containing CSV data tables (with header rows) that the user will be able to see and edit in the Flourish visualisation editor's spreadsheet interface. These can be used for sample data that you intend the end user to replace with their own data. They can also be useful for create editable look-up tables for configuration options.
343
+
344
+ Columns from these CSV files (or the data tables in the Flourish editor) are made available in the template as one or more datasets, as specified in the [data bindings of the `template.yml`](#data-bindings).
345
+
346
+ (It's also possible to import data into your template manually from your `static` directory or elsewhere, using D3 or any other technique. But the end user won't be able to edit the data or update the column selection if you do that.)
347
+
348
+ #### `static/`
349
+ A directory for any static files used in the template, such as images, fonts, stylesheets or code libraries. To reference the static directory in your [`index.html`](#indexhtml) file, use relative links:
350
+ ```html
351
+ <script src="leaflet/leaflet.js"></script>
352
+
353
+ ```
354
+ Or from JavaScript use `Flourish.static_prefix`:
355
+
356
+ ```js
357
+ var img_url = Flourish.static_prefix + "/my_image.jpg";
358
+ ```
359
+
360
+ #### `GUIDE.md`
361
+ A file documenting the template for end Flourish users, in Markdown format. This documentation will be displayed on the template’s page on the Flourish site, when the template is [published](#publish-a-template) and made live.
362
+
363
+ #### `README.md`
364
+ A standard README file for developers, available as part of the source like other files.
365
+
366
+ ### Other files
367
+ In general any files not listed above will be ignored by Flourish, and you may use them as part of your template’s build process or for any other purpose. They won’t be uploaded when you publish the template.
368
+
369
+ The skeleton template you get when you run `flourish new` and the Flourish example templates contain a couple of such files:
370
+
371
+ #### `package.json`
372
+ A standard npm configuration file, listing any dependencies. If you’re not starting with a skeleton template, you can create this file using `npm init`. This file is not treated specially by Flourish, and is only needed if your template is packaged as an npm module.
373
+
374
+ #### `rollup.config.js`
375
+ This is the default filename for a rollup.js configuration file, and specifies how the source code is to be bundled by rollup.js. It might look something like this:
376
+ ```js
377
+ export default {
378
+ entry: "src/index.js",
379
+ format: "iife",
380
+ moduleName: "template",
381
+ dest: "template.js",
382
+
383
+ sourceMap: true,
384
+ plugins: [
385
+ require("rollup-plugin-node-resolve"),
386
+ require("rollup-plugin-uglify"),
387
+ ]
388
+ };
389
+ ```
390
+ You only need this if you’re using rollup.js to bundle your template.
391
+
392
+ ## Using the SDK
393
+ ### Installation
394
+ Install the SDK with npm, as follows. If you don't already have it you'll need to [install node](https://nodejs.org/en/download/).
395
+ ```sh
396
+ npm install -g @flourish/sdk
397
+ ```
398
+ The `-g` means the package will be installed globally, enabling access to the `flourish` command across your system.
399
+
400
+ ### Create a new template
401
+ ```sh
402
+ flourish new [dir_name]
403
+ ```
404
+ Where `dir_name` is the name of the template directory that will be created. The new directory will be populated with skeleton files and directories that you can edit with your own code and files.
405
+
406
+ ### Build
407
+ ```sh
408
+ flourish build [rules]
409
+ ```
410
+ Build the template in the current directory, using the scripts [specified in `template.yml`](#build-configuration).
411
+ if you don’t specify any build rules, it will run all of them. You shouldn’t usually need to use this command explicitly,
412
+ because `flourish run` will do a full build before it runs the server, and then monitor your files for changes and
413
+ trigger appropriate rebuilds automatically when something changes.
414
+
415
+ ### Run and view a template
416
+ ```sh
417
+ flourish run [dir_name]
418
+ ```
419
+ Builds the template and runs the SDK viewer in your web browser. If `dir_name` is omitted it uses the current directory.
420
+
421
+ While it’s running it watches the template directory for changes:
422
+ * if you edit any static template files (`index.html`, `template.yml`, `data/*`, `static/*`) the SDK will refresh the page in the browser;
423
+ * if you edit a file that is the source for a [build rule](#build-configuration), the SDK will run that build rule and then refresh the page.
424
+
425
+ Options:
426
+ * `--open` or `-o` Try to open the SDK in your web browser once the server is running. At present this only works on macOS.
427
+ * `--port` Specify a particular port; defaults to [1685](https://en.wikipedia.org/wiki/Johann_Sebastian_Bach)
428
+ * `--no-build` Skip the build process
429
+
430
+ ### Publish a template
431
+ ```sh
432
+ flourish publish [dir_name]
433
+ ```
434
+ You'll first need to be logged in. If `dir_name` is omitted it uses the current directory.
435
+
436
+ ### Login, logout, register, check status
437
+ New users should `flourish register` and follow the prompts. Existing users can log in and out with `flourish login` and `flourish logout`. To check which account you are currently logged in with, use `flourish whoami`.
438
+
439
+ ### Download a template
440
+ To download an existing template, such as one of our examples or an open-source template, simply `git clone` the repo, then change into the new directory and `npm install` then `flourish run`. For example:
441
+ ```sh
442
+ git clone https://github.com/kiln/example-template-circle
443
+ cd example-template-circle/
444
+ npm install
445
+ flourish run
446
+ ```
447
+
448
+ ### Upgrade from an older version of the SDK
449
+ ```sh
450
+ flourish upgrade [dir_name]
451
+ ```
452
+ Sometimes changes to the Flourish SDK will require templates to be changed to be compatible with the new version. This command will attempt to convert a template made for an earlier version of Flourish to be compatible with the current version.
453
+
454
+ ## Template API
455
+ Your compiled JavaScript should assign an object with the following properties to `window.template`:
456
+
457
+ ### `.state`
458
+ Records the current state of template. Default values for each of its properties are set where the object is declared in the JavaScript. These are updated by Flourish when the user changes a setting in the visualisation editor, or programmatically, e.g. when the user interacts with the template output.
459
+
460
+ To make sure your template works nicely in the story editor, ensure that all visual aspects of the template – including the UI – are set from the `state` by the `update()` function. For example, if the user clicks a menu item and you want to highlight that item, do this by updating the `state` and calling `update()`. Do not do it in the click handler for the menu item, as this will only work when the user clicks the button manually, not when the story editor moves from one state to another.
461
+
462
+ ### `.draw()`
463
+ Called when the template loads. Typically used for initialisation code such as adding elements to the DOM. In some cases, however, it might do nothing except call update().
464
+
465
+ In most templates `draw()` will not be called except once by Flourish after the template is loaded, though in some cases you may want to call it manually – for example if you want to delete the DOM and redraw it when the user resizes the window.
466
+
467
+ ### `.update()`
468
+ Called whenever the user changes a data table or setting in the visualisation editor, or when changing slides in the story editor. Typically will also be called by the template in response to user interaction.
469
+
470
+ ### `.data`
471
+ An object into which Flourish will put the data from user-editable data tables. Usually your code will initialise `data` as an empty object `{}`, and read from it in the `draw()` and `update()` functions.
472
+
473
+ Each property is a `dataset`: an array containing an object for each row in the relevant data table. The structure of each `dataset` is defined in the [data bindings of the `template.yml`](#data-bindings), and the data is loaded from the tables in the [`data/`](#data) directory.
package/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 3.19.0
2
+ * Add the `is_premium` top level property in template.yml to indicate that this is a premium template
3
+
4
+ # 3.18.1
5
+ * Addresses some technical debt.
6
+
7
+ # 3.18.0
8
+ * Support `tag` property in setting
9
+
10
+ # 3.17.3
11
+ * Use seeded random sample of column values to interpret columns
12
+
1
13
  # 3.17.2
2
14
  * Fixes an issue which could cause template publication to fail
3
15