UI-Research / greaterdc-data-explorer

Interactive Data Explorer map for the GreaterDC research initiative website.
0 stars 0 forks source link
webdev

Greater DC Data Explorer

Setup

Dev requirements:

* `node >= v12.13.1`

Run:

Learn:

Data Verification

Run

Learn

CSV Conversion

Run

Learn

Example /data folder structure:

data
├── help-text.csv
├── crime
│   ├── crime_anc12.csv
│   ├── crime_anc12_metadata.csv
│   ├── crime_tr10.csv
│   ├── crime_tr10_metadata.csv
│   └── ...
└── population
    ├── population_anc12.csv
    ├── population_anc12_metadata.csv
    ├── population_tr10.csv
    ├── population_tr10_metadata.csv
    └── ...

Notes

Render target

By default, the app is configured to render in a div with id #app. If you wish to change the render target, you can do so when invoking yarn start / yarn build commands, by prepending RENDER_TARGET="#my-div" to the command. This value can be any valid CSS selector (as used by document.QuerySelector). Examples:

Notes:

Assets Location

Because the application is designed to work as standalone or embedded in a non-root location, the REACT_APP_DATA_LOCATION ENV var is used to tell the application where to load the assets from. If not specified, it defaults to ".".

Example use:

Notes:

Filter dropdowns

Filters are generated prior to building / running the application in development mode, and are output to assets/data/filters.json. This file contains the dependencies between different dropdowns, providing a lookup for which values should be displayed in each of the dropdowns after selections change. The file is structured as follows:

{
  [geography]: {
    value: String (=== geography),
    label: String,
    topics: {
      [topic]: {
        value: String (=== topic),
        label: String,
        indicators: {
          [indicator]: {
            value: String (=== indicator),
            label: String,
            years: [
              value: String,
              label: String,
            ]
          }
        }
      }
    }
  },

  ...
}

At the top level, the object will contain a key for each geography present in the geographies export in app/constants/taxonomy.js:17-25. For each object present, the keys label and value are provided for using in a select element:

  <select>
    <option={value}>{label}</option>
    ...
   </select>

Drilling down further, we can get the possible values for the next dropdowns; these dropdowns should only be enabled / have values if the dropdown immediately before has a selected value.

This implies that:

Geography

Geography dropdown is code driven; the definition is in /app/constants/taxonomy.js

These values are used to build the Geography dropdown, and to reference the Tilesets uploaded to Mapbox (see /app/support/map.js), as well as their respective source layer and relevant key for the area, to link shapefile area with CSV data.

The constants defined in this file follow the notation below:

Geographies
Topics

Currently, there are 8 defined topics:

Adding more topics is a matter of adding new TOPIC_OPT_ and TOPIC_LABEL_ constants, and adding those to the topics constant;

Once more data is available, just make sure the TOPIC_OPT_* value matches the name of the folder, and data should be used automatically used.

Indicator / Year

Indicator and year are data-driven, so they should just work, provided the data is in good shape.

Help Text (Notes & Sources)

All notes & sources are expected to live in a help-text.csv file. This CSV must contain 3 columns:

Generating a template

Run yarn data-templates to generate template CSVs that should be filled and placed in /data/help-text.csv to be converted and read by the application. The resulting file will be placed under /templates/help-text.csv.

NOTE:

This function assumes the existence of a valid /app/assets/data/filters.json file. If that's not the case, this task will fail. Please ensure that yarn create-filters ran successfuly prior to attempting to generate this template.

Updating existing data / adding new data

Ignoring columns

Because this application is designed to work with lots of different data sources, it is expected that some work will need to be done in order to maintain the application working as expected. To that end, one of the most important file is app/constants/filters.js. This file contains a list of all column names that should be ignored when building / displaying indicators in filters. Additionaly, all columns that end in _nf, _m, or _moe will be automatically ignored, without the need to manually add them to the blacklist.

Issue with csv-parse

We need to use an older version of csv-parse ^2.0.0 due to an issue with parsing. With version ^4.5.0 numbers are getting parsed as strings. It is likely a configuration setting that was introduced. This can be looked into in the future but for now we are just pinning it at ^2.0.0.