Skip to content

Commit 7c95731

Browse files
committed
fix: reduce complexity
1 parent abae87c commit 7c95731

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/utils.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ function getScaleUnderPoint({ x, y }: Point, chart: Chart): Scale | null {
5454
return null
5555
}
5656

57+
type EnabledDirections = { x: boolean; y: boolean }
58+
5759
const convertOverScaleMode = (
5860
chart: Chart,
5961
overScaleMode: ModeOption | undefined,
60-
scaleEnabled: { x: boolean; y: boolean },
61-
enabled: { x: boolean; y: boolean }
62+
scaleEnabled: EnabledDirections,
63+
enabled: EnabledDirections
6264
) => {
6365
if (!overScaleMode) {
6466
return
@@ -73,6 +75,18 @@ const convertOverScaleMode = (
7375
}
7476
}
7577

78+
const getEnabledScales = (chart: Chart, enabled: EnabledDirections): Scale[] => {
79+
const enabledScales: Scale[] = []
80+
81+
for (const scaleItem of Object.values(chart.scales)) {
82+
if (enabled[scaleItem.axis as 'x' | 'y']) {
83+
enabledScales.push(scaleItem)
84+
}
85+
}
86+
87+
return enabledScales || Object.values(chart.scales)
88+
}
89+
7690
/**
7791
* Evaluate the chart's mode, scaleMode, and overScaleMode properties to
7892
* determine which axes are eligible for scaling.
@@ -92,13 +106,5 @@ export function getEnabledScalesByPoint(options: PanOptions | undefined, point:
92106
return [scale]
93107
}
94108

95-
const enabledScales: Scale[] = []
96-
97-
for (const scaleItem of Object.values(chart.scales)) {
98-
if (enabled[scaleItem.axis as 'x' | 'y']) {
99-
enabledScales.push(scaleItem)
100-
}
101-
}
102-
103-
return enabledScales || Object.values(chart.scales)
109+
return getEnabledScales(chart, enabled)
104110
}

0 commit comments

Comments
 (0)