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

Fix maximum call stack size exceeded on Math.min/max when creating Charts #6958

Merged
merged 5 commits into from
Nov 13, 2023
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
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
Loading