Skip to content

Commit 87a063d

Browse files
Merge pull request #1692 from nextstrain/display-default-tip-label
Tip label can be defined in display_defaults
2 parents fca8b6f + e80cafd commit 87a063d

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Changelog
22

3-
## version 2.48.0 - 2023/08/31
43

4+
* Allow the tip label key to be defined in the JSON via `display_defaults.tip_label`, in addition to being settable via a URL query.
5+
See [the docs](https://docs.nextstrain.org/projects/auspice/en/stable/advanced-functionality/view-settings.html) or [PR #1668](https://github.com/nextstrain/auspice/pull/1668) for more.
56

7+
## version 2.48.0 - 2023/08/31
68

79
* Root sequence data may be inlined in the main dataset JSON
810
([Auspice PR #1688](https://github.com/nextstrain/auspice/pull/1688) and [Augur PR #1295](https://github.com/nextstrain/augur/pull/1295)).
@@ -32,8 +34,6 @@ detailed in [augur PR #1281](https://github.com/nextstrain/augur/pull/1281).
3234
* Dependencies updated. See [PR #1669](https://github.com/nextstrain/auspice/pull/1669) for more.
3335

3436
## version 2.46.0 - 2023/05/15
35-
36-
3737
* Fixed a bug where narratives with multiple datasets that had measurements panels would error when switching datasets. ([#1603](https://github.com/nextstrain/auspice/issues/1603))
3838

3939
_There have been a number of internal changes with this release, most of which should not result in any different behavior while using Auspice._

docs/advanced-functionality/view-settings.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Auspice has some hardcoded defaults, largely for historical reasons. Each of the
1717
- Default geographic resolution is "country", if available.
1818
- Default colouring is "country", if available.
1919
- Default branch labelling is "clade", if available.
20+
- Default tip labelling is the sample / strain name (`node.name`)
2021

2122
Dataset (JSON) configurable defaults
2223
------------------------------------
@@ -36,6 +37,8 @@ These are exported as the (optional) property of the dataset JSON ``meta.display
3637
+---------------------------+-----------------------------------------------------------------------+----------------------------------------------------+
3738
| ``layout`` | Tree layout | "rect", "radial", "unrooted", "clock" or "scatter" |
3839
+---------------------------+-----------------------------------------------------------------------+----------------------------------------------------+
40+
| ``tip_label`` | What attribute (in 'node_attrs') to use as tip (node) labels | "country" |
41+
+---------------------------+-----------------------------------------------------------------------+----------------------------------------------------+
3942
| ``branch_label`` | Which set of branch labels are to be displayed | "aa", "lineage" |
4043
+---------------------------+-----------------------------------------------------------------------+----------------------------------------------------+
4144
| ``sidebar`` | Should the sidebar start open or closed? | "open" or "closed" |
@@ -103,6 +106,8 @@ URL queries are the part of the URL coming after the ``?`` character, and typica
103106
+----------------------+-----------------------------------------------------------+---------------------------------------------------+
104107
| ``s`` | Selected strain | ``s=1_0199_PF`` |
105108
+----------------------+-----------------------------------------------------------+---------------------------------------------------+
109+
| ``tl`` | Tip label to display | ``tl=country`` |
110+
+----------------------+-----------------------------------------------------------+---------------------------------------------------+
106111
| ``branchLabel`` | Branch labels to display | ``branchLabel=aa`` |
107112
+----------------------+-----------------------------------------------------------+---------------------------------------------------+
108113
| ``showBranchLabels`` | Force all branch labels to be displayed | ``showBranchLabels=all`` |

src/actions/recomputeReduxState.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { isColorByGenotype, decodeColorByGenotype, encodeColorByGenotype, decode
2222
import { getTraitFromNode, getDivFromNode, collectGenotypeStates } from "../util/treeMiscHelpers";
2323
import { collectAvailableTipLabelOptions } from "../components/controls/choose-tip-label";
2424
import { hasMultipleGridPanels } from "./panelDisplay";
25+
import { strainSymbolUrlString } from "../middleware/changeURL";
2526

2627
export const doesColorByHaveConfidence = (controlsState, colorBy) =>
2728
controlsState.coloringsPresentOnTreeWithConfidence.has(colorBy);
@@ -89,7 +90,7 @@ const modifyStateViaURLQuery = (state, query) => {
8990
state["panelLayout"] = query.p;
9091
}
9192
if (query.tl) {
92-
state["tipLabelKey"] = query.tl;
93+
state["tipLabelKey"] = query.tl===strainSymbolUrlString ? strainSymbol : query.tl;
9394
}
9495
if (query.dmin) {
9596
state["dateMin"] = query.dmin;
@@ -238,8 +239,8 @@ const modifyStateViaMetadata = (state, metadata, genomeMap) => {
238239
state.filters[strainSymbol] = [];
239240
state.filters[genotypeSymbol] = []; // this doesn't necessitate that mutations are defined
240241
if (metadata.displayDefaults) {
241-
const keysToCheckFor = ["geoResolution", "colorBy", "distanceMeasure", "layout", "mapTriplicate", "selectedBranchLabel", 'sidebar', "showTransmissionLines", "normalizeFrequencies"];
242-
const expectedTypes = ["string", "string", "string", "string", "boolean", "string", 'string', "boolean" , "boolean"];
242+
const keysToCheckFor = ["geoResolution", "colorBy", "distanceMeasure", "layout", "mapTriplicate", "selectedBranchLabel", "tipLabelKey", 'sidebar', "showTransmissionLines", "normalizeFrequencies"];
243+
const expectedTypes = ["string", "string", "string", "string", "boolean", "string", 'string', 'string', "boolean" , "boolean"];
243244

244245
for (let i = 0; i < keysToCheckFor.length; i += 1) {
245246
if (Object.hasOwnProperty.call(metadata.displayDefaults, keysToCheckFor[i])) {
@@ -552,10 +553,21 @@ const checkAndCorrectErrorsInState = (state, metadata, genomeMap, query, tree, v
552553
state.defaults.selectedBranchLabel = "none";
553554
}
554555

555-
/* check tip label is valid. We use the function which generates the options for the dropdown here */
556-
if (!collectAvailableTipLabelOptions(metadata.colorings).map((o) => o.value).includes(state.tipLabelKey)) {
557-
console.error("Can't set selected tip label to ", state.tipLabelKey);
558-
state.tipLabelKey = strainSymbol;
556+
/* check tip label is valid. We use the function which generates the options for the dropdown here.
557+
* state.defaults.tipLabelKey is set by the JSON's display_defaults (default: strainSymbol)
558+
* state.tipLabelKey is first set the JSON and then overridden via the URL query (default: state.defaults.tipLabelKey)
559+
*/
560+
const validTipLabels = collectAvailableTipLabelOptions(metadata.colorings).map((o) => o.value);
561+
if (!validTipLabels.includes(state.defaults.tipLabelKey)) {
562+
console.error("Invalid JSON-defined tip label:", state.defaults.tipLabelKey);
563+
state.defaults.tipLabelKey = strainSymbol;
564+
}
565+
if (!validTipLabels.includes(state.tipLabelKey)) {
566+
if (query.tl) {
567+
console.error("Invalid URL-defined tip label:", state.tipLabelKey);
568+
delete query.tl;
569+
}
570+
state.tipLabelKey = state.defaults.tipLabelKey;
559571
}
560572

561573
/* temporalConfidence */
@@ -745,6 +757,7 @@ const createMetadataStateFromJSON = (json) => {
745757
geo_resolution: "geoResolution",
746758
distance_measure: "distanceMeasure",
747759
branch_label: "selectedBranchLabel",
760+
tip_label: "tipLabelKey",
748761
map_triplicate: "mapTriplicate",
749762
layout: "layout",
750763
language: "language",

src/middleware/changeURL.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { shouldDisplayTemporalConfidence } from "../reducers/controls";
55
import { genotypeSymbol, nucleotide_gene, strainSymbol } from "../util/globals";
66
import { encodeGenotypeFilters, decodeColorByGenotype, isColorByGenotype } from "../util/getGenotype";
77

8+
export const strainSymbolUrlString = "__strain__";
9+
810
/**
911
* This middleware acts to keep the app state and the URL query state in sync by
1012
* intercepting actions and updating the URL accordingly. Thus, in theory, this
@@ -167,7 +169,9 @@ export const changeURLMiddleware = (store) => (next) => (action) => {
167169
break;
168170
}
169171
case types.CHANGE_TIP_LABEL_KEY: {
170-
query.tl = action.key===strainSymbol ? undefined : action.key;
172+
query.tl = action.key===state.controls.defaults.tipLabelKey ? undefined :
173+
action.key===strainSymbol ? strainSymbolUrlString :
174+
action.key;
171175
break;
172176
}
173177
case types.CHANGE_DATES_VISIBILITY_THICKNESS: {

src/reducers/controls.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const getDefaultControlsState = () => {
2424
filtersInFooter: [],
2525
colorBy: defaultColorBy,
2626
selectedBranchLabel: "none",
27+
tipLabelKey: strainSymbol,
2728
showTransmissionLines: true
2829
};
2930
// a default sidebarOpen status is only set via JSON, URL query
@@ -78,7 +79,7 @@ export const getDefaultControlsState = () => {
7879
panelsAvailable: [],
7980
panelsToDisplay: [],
8081
panelLayout: calcBrowserDimensionsInitialState().width > twoColumnBreakpoint ? "grid" : "full",
81-
tipLabelKey: strainSymbol,
82+
tipLabelKey: defaults.tipLabelKey,
8283
showTreeToo: undefined,
8384
showTangle: false,
8485
zoomMin: undefined,

0 commit comments

Comments
 (0)