Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance when transmission lines are not drawn #1153

Merged
merged 2 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good (later on) to link to a doc (e.g. this one - although that doc itself looks like a stub/TODO and not included in the auspice docs sidebar) so that folks can find out more about what transmission lines are when reading this doc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Those tutorials (how-to's, really) are desperately needed, but as you note that one's a stub which isn't actually part of the docs.



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
5 changes: 3 additions & 2 deletions src/components/map/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class Map extends React.Component {
this.props.pieChart,
this.props.legendValues,
this.props.colorBy,
this.props.showTransmissionLines,
this.props.dispatch
);

Expand Down Expand Up @@ -385,6 +386,7 @@ class Map extends React.Component {
nextProps.pieChart,
nextProps.legendValues,
nextProps.colorBy,
nextProps.showTransmissionLines,
nextProps.dispatch
);
const d3elems = drawDemesAndTransmissions(
Expand All @@ -397,8 +399,7 @@ class Map extends React.Component {
nextProps.dateMaxNumeric,
nextProps.pieChart,
nextProps.geoResolution,
nextProps.dispatch,
nextProps.showTransmissionLines
nextProps.dispatch
);
this.setState({
d3elems,
Expand Down
5 changes: 2 additions & 3 deletions src/components/map/mapHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ export const drawDemesAndTransmissions = (
numDateMax,
pieChart, /* bool */
geoResolution,
dispatch,
showTransmissionLines
dispatch
) => {

// add transmission lines
Expand All @@ -165,7 +164,7 @@ export const drawDemesAndTransmissions = (
.attr("stroke-opacity", 0.6)
.attr("stroke-linecap", "round")
.attr("stroke", (d) => { return d.color; })
.attr("stroke-width", showTransmissionLines ? 1 : 0);
.attr("stroke-width", 1);

const visibleTips = nodes[0].tipCount;
const demeMultiplier =
Expand Down
26 changes: 16 additions & 10 deletions src/components/map/mapHelpersLatLong.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ export const createDemeAndTransmissionData = (
pieChart,
legendValues,
colorBy,
showTransmissionLines,
dispatch
) => {
/*
Expand All @@ -414,16 +415,21 @@ export const createDemeAndTransmissionData = (
demeIndices
} = setupDemeData(nodes, visibility, geoResolution, nodeColors, triplicate, metadata, map, pieChart, legendValues, colorBy);

/* second time so that we can get Bezier */
const { transmissionData, transmissionIndices, demesMissingLatLongs } = setupTransmissionData(
nodes,
visibility,
geoResolution,
nodeColors,
triplicate,
metadata,
map
);
let transmissionData = [];
let transmissionIndices = {};
let demesMissingLatLongs = new Set(); // TODO: this won't be filled in if we're not showing transmission lines...
if (showTransmissionLines) {
/* second time so that we can get Bezier */
({ transmissionData, transmissionIndices, demesMissingLatLongs } = setupTransmissionData(
nodes,
visibility,
geoResolution,
nodeColors,
triplicate,
metadata,
map
));
}

const filteredDemesMissingLatLongs = [...demesMissingLatLongs].filter((value) => {
return value.toLowerCase() !== "unknown";
Expand Down