-
Notifications
You must be signed in to change notification settings - Fork 14
Style guide
Alison Appling edited this page Oct 13, 2017
·
16 revisions
Viz collaborations are smoother when we adopt a consistent code style. Here is the style we have chosen:
- Viz.yaml element ids:
{phase}-{step-id}
, e.g.,process-my-element-mobile
- R functions that build viz.yaml elements:
{phase}.{step_id}()
, e.g.,process.my_element()
- Other R function names: snake case, e.g.,
my_function_name()
- R variable names: snake case, e.g.,
my_variable_name
- File names:
scripts/process/process.my_element.R
,cache/fetch_watershed_boundaries.tsv
- CSS classes and IDs: kebab case, e.g.,
fig-text
- JavaScript functions and variables: camel case, e.g.,
myVariableName
,myFunctionName
- In JavaScript, use namespacing to put related things together and to keep variables localized.
- Fetch/process/visualize functions should each produce a single file (at the viz 'location') for the sake of clean dependency management.
Within the constraints of efficiency and practicality, and allowing for exceptions:
- Fetch functions should preserve a raw or near-raw data format. Limit any processing to actions you're sure no one will need to revise during the viz sprint, so that downloads can be infrequent.
- The process phase should bring the data all the way from just-fetched to visualization-ready. As much as possible, say 'yes' to tabular and spatial data manipulation, 'no' to SVG, CSS, and JavaScript. There can be 2+ process phases for a single dataset.
- Visualization functions should produce static (but interaction-ready) graphics.
- The publish phase is the ideal place for layout, styling, and interactivity.
Collaborating
Using vizlab
Specific concepts