-
Notifications
You must be signed in to change notification settings - Fork 14
Style guide
Alison Appling edited this page Feb 28, 2018
·
16 revisions
Viz collaborations are smoother when we adopt a consistent code style. Here is the style we have chosen:
- Viz.yaml element ids:
{super_explicit_name}
, e.g.,transposed_yahara_geom_mobile
. Use and encourage your teammates to use highly informative names. - R functions that build viz.yaml elements:
{phase}.{step_id}()
, e.g.,process.transposed_yahara_geom()
- Other R function names: snake case, e.g.,
bbox_to_polygon()
- R variable names: snake case, e.g.,
county_centroids
- File names:
scripts/process/process.transposed_yahara_geom.R
,cache/fetch/watershed_boundaries.Rds
- CSS classes and IDs: kebab case, e.g.,
fig-text
- JavaScript functions and variables: camel case, e.g.,
playButtonInfo
,runDemo
- YAML key-value pairs: avoid quoting keys or values unless necessary.
- 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.
The fetch/process/visualization/publish phases are conceptually distinct. Within the constraints of efficiency and practicality, and allowing for exceptions, here is what each phase should produce:
- 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