From a9ef44bb886bdd1273115576197e85b722424486 Mon Sep 17 00:00:00 2001 From: james hadfield Date: Wed, 3 Jun 2020 17:16:33 +1200 Subject: [PATCH] Skip transmission calcs when not displayed This skips the creation of `transmissionData` and `transmissionIndices` when we are not displaying transmission lines, and the corresponding DOM elements are never created. --- src/components/map/map.js | 5 +++-- src/components/map/mapHelpers.js | 5 ++--- src/components/map/mapHelpersLatLong.js | 26 +++++++++++++++---------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/components/map/map.js b/src/components/map/map.js index 2ff7d90a8..3ec2b2c5b 100644 --- a/src/components/map/map.js +++ b/src/components/map/map.js @@ -220,6 +220,7 @@ class Map extends React.Component { this.props.pieChart, this.props.legendValues, this.props.colorBy, + this.props.showTransmissionLines, this.props.dispatch ); @@ -385,6 +386,7 @@ class Map extends React.Component { nextProps.pieChart, nextProps.legendValues, nextProps.colorBy, + nextProps.showTransmissionLines, nextProps.dispatch ); const d3elems = drawDemesAndTransmissions( @@ -397,8 +399,7 @@ class Map extends React.Component { nextProps.dateMaxNumeric, nextProps.pieChart, nextProps.geoResolution, - nextProps.dispatch, - nextProps.showTransmissionLines + nextProps.dispatch ); this.setState({ d3elems, diff --git a/src/components/map/mapHelpers.js b/src/components/map/mapHelpers.js index 23add1ee7..15a46f2ea 100644 --- a/src/components/map/mapHelpers.js +++ b/src/components/map/mapHelpers.js @@ -137,8 +137,7 @@ export const drawDemesAndTransmissions = ( numDateMax, pieChart, /* bool */ geoResolution, - dispatch, - showTransmissionLines + dispatch ) => { // add transmission lines @@ -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 = diff --git a/src/components/map/mapHelpersLatLong.js b/src/components/map/mapHelpersLatLong.js index cfb11f1ce..8a213e18b 100644 --- a/src/components/map/mapHelpersLatLong.js +++ b/src/components/map/mapHelpersLatLong.js @@ -399,6 +399,7 @@ export const createDemeAndTransmissionData = ( pieChart, legendValues, colorBy, + showTransmissionLines, dispatch ) => { /* @@ -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";