@@ -14,6 +14,7 @@ import { type CommonMonthlyTrendsChartProps, type MonthlyTrendsBarChartClickEven
14
14
15
15
import { useUserStore } from ' @/stores/user.ts' ;
16
16
17
+ import { itemAndIndex } from ' @/core/base.ts' ;
17
18
import { TextDirection } from ' @/core/text.ts' ;
18
19
import { type Year1BasedMonth , DateRangeScene } from ' @/core/datetime.ts' ;
19
20
import type { ColorStyleValue } from ' @/core/color.ts' ;
@@ -100,8 +101,7 @@ const isDarkMode = computed<boolean>(() => theme.global.name.value === ThemeType
100
101
const itemsMap = computed <Record <string , Record <string , unknown >>>(() => {
101
102
const map: Record <string , Record <string , unknown >> = {};
102
103
103
- for (let i = 0 ; i < props .items .length ; i ++ ) {
104
- const item = props .items [i ];
104
+ for (const item of props .items ) {
105
105
let id: string = ' ' ;
106
106
107
107
if (props .idField && item [props .idField ]) {
@@ -135,9 +135,7 @@ const itemsMap = computed<Record<string, Record<string, unknown>>>(() => {
135
135
const allDisplayDateRanges = computed <string []>(() => {
136
136
const allDisplayDateRanges: string [] = [];
137
137
138
- for (let i = 0 ; i < allDateRanges .value .length ; i ++ ) {
139
- const dateRange = allDateRanges .value [i ];
140
-
138
+ for (const dateRange of allDateRanges .value ) {
141
139
if (props .dateAggregationType === ChartDateAggregationType .Year .type ) {
142
140
allDisplayDateRanges .push (formatUnixTimeToGregorianLikeShortYear (dateRange .minUnixTime ));
143
141
} else if (props .dateAggregationType === ChartDateAggregationType .FiscalYear .type && ' year' in dateRange ) {
@@ -155,18 +153,15 @@ const allDisplayDateRanges = computed<string[]>(() => {
155
153
const allSeries = computed <MonthlyTrendsChartDataItem []>(() => {
156
154
const allSeries: MonthlyTrendsChartDataItem [] = [];
157
155
158
- for (let i = 0 ; i < props .items .length ; i ++ ) {
159
- const item = props .items [i ];
160
-
156
+ for (const [item, index] of itemAndIndex (props .items )) {
161
157
if (props .hiddenField && item [props .hiddenField ]) {
162
158
continue ;
163
159
}
164
160
165
161
const allAmounts: number [] = [];
166
162
const dateRangeAmountMap: Record <string , YearMonthDataItem []> = {};
167
163
168
- for (let j = 0 ; j < item .items .length ; j ++ ) {
169
- const dataItem = item .items [j ];
164
+ for (const dataItem of item .items ) {
170
165
let dateRangeKey = ' ' ;
171
166
172
167
if (props .dateAggregationType === ChartDateAggregationType .Year .type ) {
@@ -189,8 +184,7 @@ const allSeries = computed<MonthlyTrendsChartDataItem[]>(() => {
189
184
dateRangeAmountMap [dateRangeKey ] = dataItems ;
190
185
}
191
186
192
- for (let j = 0 ; j < allDateRanges .value .length ; j ++ ) {
193
- const dateRange = allDateRanges .value [j ];
187
+ for (const dateRange of allDateRanges .value ) {
194
188
let dateRangeKey = ' ' ;
195
189
196
190
if (props .dateAggregationType === ChartDateAggregationType .Year .type ) {
@@ -207,9 +201,7 @@ const allSeries = computed<MonthlyTrendsChartDataItem[]>(() => {
207
201
const dataItems = dateRangeAmountMap [dateRangeKey ];
208
202
209
203
if (isArray (dataItems )) {
210
- for (let i = 0 ; i < dataItems .length ; i ++ ) {
211
- const dataItem = dataItems [i ];
212
-
204
+ for (const dataItem of dataItems ) {
213
205
if (isNumber (dataItem [props .valueField ])) {
214
206
amount += dataItem [props .valueField ] as number ;
215
207
}
@@ -223,7 +215,7 @@ const allSeries = computed<MonthlyTrendsChartDataItem[]>(() => {
223
215
id: (props .idField && item [props .idField ]) ? item [props .idField ] as string : getItemName (item [props .nameField ] as string ),
224
216
name: (props .idField && item [props .idField ]) ? item [props .idField ] as string : getItemName (item [props .nameField ] as string ),
225
217
itemStyle: {
226
- color: getDisplayColor (props .colorField && item [props .colorField ] ? item [props .colorField ] as string : DEFAULT_CHART_COLORS [i % DEFAULT_CHART_COLORS .length ]),
218
+ color: getDisplayColor (props .colorField && item [props .colorField ] ? item [props .colorField ] as string : DEFAULT_CHART_COLORS [index % DEFAULT_CHART_COLORS .length ]),
227
219
},
228
220
selected: true ,
229
221
type: ' line' ,
@@ -253,10 +245,9 @@ const yAxisWidth = computed<number>(() => {
253
245
return width ;
254
246
}
255
247
256
- for (let i = 0 ; i < allSeries .value .length ; i ++ ) {
257
- for (let j = 0 ; j < allSeries .value [i ].data .length ; j ++ ) {
258
- const value = allSeries .value [i ].data [j ];
259
248
249
+ for (const series of allSeries .value ) {
250
+ for (const value of series .data ) {
260
251
if (value > maxValue ) {
261
252
maxValue = value ;
262
253
}
@@ -311,12 +302,12 @@ const chartOptions = computed<object>(() => {
311
302
let totalAmount = 0 ;
312
303
const displayItems: MonthlyTrendsChartTooltipItem [] = [];
313
304
314
- for (let i = 0 ; i < params . length ; i ++ ) {
315
- const id = params [ i ] .seriesId as string ;
305
+ for (const param of params ) {
306
+ const id = param .seriesId as string ;
316
307
const name = itemsMap .value [id ] && props .nameField && itemsMap .value [id ][props .nameField ] ? getItemName (itemsMap .value [id ][props .nameField ] as string ) : id ;
317
- const color = params [ i ] .color ;
308
+ const color = param .color ;
318
309
const displayOrders = itemsMap .value [id ] && props .displayOrdersField && itemsMap .value [id ][props .displayOrdersField ] ? itemsMap .value [id ][props .displayOrdersField ] as number [] : [0 ];
319
- const amount = params [ i ] .data as number ;
310
+ const amount = param .data as number ;
320
311
321
312
displayItems .push ({
322
313
name: name ,
@@ -330,9 +321,7 @@ const chartOptions = computed<object>(() => {
330
321
331
322
sortStatisticsItems (displayItems , props .sortingType );
332
323
333
- for (let i = 0 ; i < displayItems .length ; i ++ ) {
334
- const item = displayItems [i ];
335
-
324
+ for (const item of displayItems ) {
336
325
if (displayItems .length === 1 || item .totalAmount !== 0 ) {
337
326
const value = formatAmountToLocalizedNumeralsWithCurrency (item .totalAmount , props .defaultCurrency );
338
327
tooltip += ' <div><span class="chart-pointer" style="background-color: ' + item .color + ' "></span>' ;
@@ -349,7 +338,7 @@ const chartOptions = computed<object>(() => {
349
338
+ ' </div>' + tooltip ;
350
339
}
351
340
352
- if (params .length && params [0 ].name ) {
341
+ if (params .length && params [0 ] && params [ 0 ] .name ) {
353
342
tooltip = ` ${params [0 ].name }<br/> ` + tooltip ;
354
343
}
355
344
@@ -410,9 +399,14 @@ function clickItem(e: ECElementEvent): void {
410
399
}
411
400
412
401
const id = e .seriesId as string ;
413
- const item = itemsMap .value [id ];
402
+ const item = itemsMap .value [id ] as Record < string , unknown > ;
414
403
const itemId = props .idField ? item [props .idField ] as string : ' ' ;
415
404
const dateRange = allDateRanges .value [e .dataIndex ];
405
+
406
+ if (! dateRange ) {
407
+ return ;
408
+ }
409
+
416
410
let minUnixTime = dateRange .minUnixTime ;
417
411
let maxUnixTime = dateRange .maxUnixTime ;
418
412
@@ -450,16 +444,16 @@ function exportData(): { headers: string[], data: string[][] } {
450
444
451
445
headers .push (tt (' Date' ));
452
446
453
- for (let i = 0 ; i < allSeries .value . length ; i ++ ) {
454
- const id = allSeries . value [ i ] .id ;
447
+ for (const series of allSeries .value ) {
448
+ const id = series .id ;
455
449
const name = itemsMap .value [id ] && props .nameField && itemsMap .value [id ][props .nameField ] ? getItemName (itemsMap .value [id ][props .nameField ] as string ) : id ;
456
450
headers .push (name );
457
451
}
458
452
459
- for (let i = 0 ; i < allDisplayDateRanges .value . length ; i ++ ) {
453
+ for (const [displayDateRange, index] of itemAndIndex ( allDisplayDateRanges .value ) ) {
460
454
const row: string [] = [];
461
- row .push (allDisplayDateRanges . value [ i ] );
462
- row .push (... allSeries .value .map (item => formatAmountToWesternArabicNumeralsWithoutDigitGrouping (item .data [i ] )));
455
+ row .push (displayDateRange );
456
+ row .push (... allSeries .value .map (item => formatAmountToWesternArabicNumeralsWithoutDigitGrouping (item .data [index ] ?? 0 )));
463
457
data .push (row );
464
458
}
465
459
0 commit comments