Skip to content

Commit

Permalink
Allow "show transmission line" state to be set as a display default
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshadfield committed Jun 3, 2020
1 parent 290e482 commit f8b8b56
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs-src/docs/advanced-functionality/view-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ For instance, if you set `display_defaults.color_by` to `country`, but load the
| `layout` | Tree layout | "rect", "radial", "clock" or "unrooted |
| `branch_label` | Which set of branch labels are to be displayed | "aa", "lineage" |
| `panels` | List of panels which (if available) are to be displayed | ["tree", "map"] |
| `transmission_lines`| Should transmission lines (if available) be rendered on the map? | Boolean |


Note that `meta.display_defaults.panels` (optional) differs from `meta.panels` (required), where the latter lists the possible panels that auspice may display for the dataset.
Expand Down
11 changes: 6 additions & 5 deletions src/actions/recomputeReduxState.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ const modifyStateViaMetadata = (state, metadata) => {
console.warn("JSON did not include any filters");
}
if (metadata.displayDefaults) {
const keysToCheckFor = ["geoResolution", "colorBy", "distanceMeasure", "layout", "mapTriplicate", "selectedBranchLabel", 'sidebar'];
const expectedTypes = ["string", "string", "string", "string", "boolean", "string", 'string']; // eslint-disable-line no-multi-spaces
const keysToCheckFor = ["geoResolution", "colorBy", "distanceMeasure", "layout", "mapTriplicate", "selectedBranchLabel", 'sidebar', "showTransmissionLines"];
const expectedTypes = ["string", "string", "string", "string", "boolean", "string", 'string', "boolean" ]; // eslint-disable-line

for (let i = 0; i < keysToCheckFor.length; i += 1) {
if (metadata.displayDefaults[keysToCheckFor[i]]) {
if (Object.hasOwnProperty.call(metadata.displayDefaults, keysToCheckFor[i])) {
if (typeof metadata.displayDefaults[keysToCheckFor[i]] === expectedTypes[i]) { // eslint-disable-line valid-typeof
if (keysToCheckFor[i] === "sidebar") {
if (metadata.displayDefaults[keysToCheckFor[i]] === "open") {
Expand Down Expand Up @@ -631,10 +631,11 @@ const createMetadataStateFromJSON = (json) => {
map_triplicate: "mapTriplicate",
layout: "layout",
sidebar: "sidebar",
panels: "panels"
panels: "panels",
transmission_lines: "showTransmissionLines"
};
for (const [jsonKey, auspiceKey] of Object.entries(jsonKeyToAuspiceKey)) {
if (json.meta.display_defaults[jsonKey]) {
if (Object.prototype.hasOwnProperty.call(json.meta.display_defaults, jsonKey)) {
metadata.displayDefaults[auspiceKey] = json.meta.display_defaults[jsonKey];
}
}
Expand Down

0 comments on commit f8b8b56

Please sign in to comment.