From 1e1e66c38aa46392f7799f76dfb14671e7870625 Mon Sep 17 00:00:00 2001 From: Nick Forbes-Smith Date: Thu, 2 Nov 2023 21:08:54 +1100 Subject: [PATCH 1/4] Fix maximum call stack size exceeded on Math.min/max when creating Charts --- CHANGES.md | 1 + lib/Core/math.ts | 23 +++++++++++++++++++++++ lib/ModelMixins/ChartableMixin.ts | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 lib/Core/math.ts diff --git a/CHANGES.md b/CHANGES.md index 3bb3ea568c1..625749b8db6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ #### next release (8.3.8) - [The next improvement] +- Fix maximum call stack size exceeded on Math.min/max when creating Charts - Remove `jsx-control-statements` dependency #### 8.3.7 - 2023-10-26 diff --git a/lib/Core/math.ts b/lib/Core/math.ts new file mode 100644 index 00000000000..0659572674f --- /dev/null +++ b/lib/Core/math.ts @@ -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; +} diff --git a/lib/ModelMixins/ChartableMixin.ts b/lib/ModelMixins/ChartableMixin.ts index 9da5b576d1c..e6806b34d57 100644 --- a/lib/ModelMixins/ChartableMixin.ts +++ b/lib/ModelMixins/ChartableMixin.ts @@ -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"; @@ -23,7 +24,7 @@ export function calculateDomain(points: ChartPoint[]): ChartDomain { 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)] + y: [getMin(ys) ?? 0, getMax(ys) ?? 0] }; } From 7a7ea6706eb3a0ddf597909b375784cde067e6e7 Mon Sep 17 00:00:00 2001 From: Nick Forbes-Smith Date: Thu, 2 Nov 2023 21:09:20 +1100 Subject: [PATCH 2/4] Fix boolean flag in `MyDataTab` displaying number --- CHANGES.md | 1 + lib/ReactViews/ExplorerWindow/Tabs/MyDataTab/MyDataTab.jsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 625749b8db6..4a74e1041b5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ - [The next improvement] - 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 #### 8.3.7 - 2023-10-26 diff --git a/lib/ReactViews/ExplorerWindow/Tabs/MyDataTab/MyDataTab.jsx b/lib/ReactViews/ExplorerWindow/Tabs/MyDataTab/MyDataTab.jsx index 7fbb75a9057..bfec39c7c72 100644 --- a/lib/ReactViews/ExplorerWindow/Tabs/MyDataTab/MyDataTab.jsx +++ b/lib/ReactViews/ExplorerWindow/Tabs/MyDataTab/MyDataTab.jsx @@ -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 ( Date: Thu, 2 Nov 2023 21:15:31 +1100 Subject: [PATCH 3/4] make operator consistent --- lib/ModelMixins/ChartableMixin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ModelMixins/ChartableMixin.ts b/lib/ModelMixins/ChartableMixin.ts index e6806b34d57..b3884db2a77 100644 --- a/lib/ModelMixins/ChartableMixin.ts +++ b/lib/ModelMixins/ChartableMixin.ts @@ -23,7 +23,7 @@ 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], + x: [minBy(xs, asNum) ?? 0, maxBy(xs, asNum) ?? 0], y: [getMin(ys) ?? 0, getMax(ys) ?? 0] }; } From 244e43bc3276b0c8e35454f1134b84146c4d0585 Mon Sep 17 00:00:00 2001 From: Nick Forbes-Smith Date: Mon, 13 Nov 2023 13:48:48 +1100 Subject: [PATCH 4/4] Update lib/ReactViews/ExplorerWindow/Tabs/MyDataTab/MyDataTab.jsx Co-authored-by: Lawrence Owen --- lib/ReactViews/ExplorerWindow/Tabs/MyDataTab/MyDataTab.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ReactViews/ExplorerWindow/Tabs/MyDataTab/MyDataTab.jsx b/lib/ReactViews/ExplorerWindow/Tabs/MyDataTab/MyDataTab.jsx index bfec39c7c72..cec82e8d5b6 100644 --- a/lib/ReactViews/ExplorerWindow/Tabs/MyDataTab/MyDataTab.jsx +++ b/lib/ReactViews/ExplorerWindow/Tabs/MyDataTab/MyDataTab.jsx @@ -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 (