Skip to content

Commit

Permalink
Observe only finite numerical values in getMaxTotalValue helper in Ar…
Browse files Browse the repository at this point in the history
…eaGraph component (electricitymaps#2285)
  • Loading branch information
fbarl authored Mar 16, 2020
1 parent 56f8aa6 commit 03eaa9a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion web/src/components/graph/areagraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
first,
last,
max,
filter,
flattenDeep,
isFinite,
isNumber,
isEmpty,
} from 'lodash';
Expand Down Expand Up @@ -35,7 +38,14 @@ const getTimeScale = (width, datetimes, startTime, endTime) => scaleTime()
])
.range([0, width]);

const getMaxTotalValue = layers => (last(layers) ? max(last(layers).datapoints.map(d => d[1])) : 0);
const getMaxTotalValue = (layers) => {
const values = flattenDeep(
layers.map(
layer => layer.datapoints.map(d => d[1])
)
);
return max(filter(values, isFinite)) || 0;
};

const getValueScale = (height, maxTotalValue) => scaleLinear()
.domain([0, maxTotalValue * 1.1])
Expand Down

0 comments on commit 03eaa9a

Please sign in to comment.