Skip to content

Commit

Permalink
Merge pull request #6958 from TerriaJS/minmax-exceed-stack
Browse files Browse the repository at this point in the history
Fix maximum call stack size exceeded on Math.min/max when creating Charts
  • Loading branch information
nf-s authored Nov 13, 2023
2 parents ba0a0e8 + d0f09b2 commit c6e0d51
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### next release (8.3.8)

- Fix maximum call stack size exceeded on Math.min/max when creating Charts
- Fix boolean flag in `MyDataTab` displaying number
- Remove `jsx-control-statements` dependency
- Fix WMS nested group IDs - nested groups with the same name were not being created
- WMS `isEsri` default value will now check for case-insensitive `mapserver/wmsserver` (instead of `MapServer/WMSServer`)
Expand Down
23 changes: 23 additions & 0 deletions lib/Core/math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export function getMax(nums: number[]) {
let len = nums.length;
if (len === 0) return undefined;

let max = -Infinity;

while (len--) {
max = nums[len] > max ? nums[len] : max;
}
return max;
}

export function getMin(nums: number[]) {
let len = nums.length;
if (len === 0) return undefined;

let min = Infinity;

while (len--) {
min = nums[len] < min ? nums[len] : min;
}
return min;
}
5 changes: 3 additions & 2 deletions lib/ModelMixins/ChartableMixin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { maxBy, minBy } from "lodash-es";
import AbstractConstructor from "../Core/AbstractConstructor";
import LatLonHeight from "../Core/LatLonHeight";
import { getMax, getMin } from "../Core/math";
import Model from "../Models/Definition/Model";
import { GlyphStyle } from "../ReactViews/Custom/Chart/Glyphs";
import ModelTraits from "../Traits/ModelTraits";
Expand All @@ -22,8 +23,8 @@ export function calculateDomain(points: ChartPoint[]): ChartDomain {
const ys = points.map((p) => p.y);
const asNum = (x: Date | number) => (x instanceof Date ? x.getTime() : x);
return {
x: [minBy(xs, asNum) || 0, maxBy(xs, asNum) || 0],
y: [Math.min(...ys), Math.max(...ys)]
x: [minBy(xs, asNum) ?? 0, maxBy(xs, asNum) ?? 0],
y: [getMin(ys) ?? 0, getMax(ys) ?? 0]
};
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ReactViews/ExplorerWindow/Tabs/MyDataTab/MyDataTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class MyDataTab extends React.Component {
}

render() {
const showTwoColumn = this.hasUserAddedData() & !this.state.activeTab;
const showTwoColumn = !!(this.hasUserAddedData() && !this.state.activeTab);
const { t, className } = this.props;
return (
<Box
Expand Down

0 comments on commit c6e0d51

Please sign in to comment.