evui 3.4.155 → 3.4.157

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,12 +5,37 @@ import { truthyNumber } from '@/common/utils';
5
5
  import Scale from './scale';
6
6
  import Util from '../helpers/helpers.util';
7
7
 
8
+ /**
9
+ * scrollbar 사용 시 스크롤마다 labels 전체를 재순회하지 않도록 결과를 캐시
10
+ */
11
+ const stringMinMaxByLabels = new WeakMap();
12
+
8
13
  class StepScale extends Scale {
9
14
  constructor(type, axisOpt, ctx, labels, options) {
10
15
  super(type, axisOpt, ctx, options);
11
16
  this.labels = labels;
12
17
  }
13
18
 
19
+ /**
20
+ * labels 배열의 문자열 min/max를 반환
21
+ * - alignToGridLine: 전달받은 minMax 그대로 사용
22
+ * - scrollbar 사용: WeakMap 캐시를 통해 O(n) → O(1)로 단축
23
+ * - 일반: 매번 getStringMinMax 계산
24
+ * @param {object} minMax 축 min/max 정보 (alignToGridLine 시 사용)
25
+ * @param {object} scrollbarOpt 스크롤바 옵션
26
+ * @returns {{ min: string, max: string }}
27
+ */
28
+ getStepMinMax(minMax, scrollbarOpt) {
29
+ if (this.labelStyle.alignToGridLine) return minMax;
30
+
31
+ if (!scrollbarOpt?.use) return Util.getStringMinMax(this.labels);
32
+
33
+ if (!stringMinMaxByLabels.has(this.labels)) {
34
+ stringMinMaxByLabels.set(this.labels, Util.getStringMinMax(this.labels));
35
+ }
36
+ return stringMinMaxByLabels.get(this.labels);
37
+ }
38
+
14
39
  /**
15
40
  * Calculate min/max value, label and size information for step scale
16
41
  * @param {object} minMax min/max information (unused on step scale)
@@ -20,8 +45,7 @@ class StepScale extends Scale {
20
45
  * @returns {object} min/max value and label
21
46
  */
22
47
  calculateScaleRange(minMax, scrollbarOpt, chartRect) {
23
- const stepMinMax = this.labelStyle.alignToGridLine
24
- ? minMax : Util.getStringMinMax(this.labels);
48
+ const stepMinMax = this.getStepMinMax(minMax, scrollbarOpt);
25
49
  let maxValue = stepMinMax.max;
26
50
  let minValue = stepMinMax.min;
27
51