@mptw/skylens-ui 1.4.12 → 1.4.13
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.
- package/package.json +1 -1
- package/utils/index.ts +33 -24
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -138,9 +138,9 @@ export const hexToRgba = (hex: string, opacity: number) => {
|
|
|
138
138
|
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
139
139
|
return result
|
|
140
140
|
? `rgba(${parseInt(result[1], 16)}, ${parseInt(result[2], 16)}, ${parseInt(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
result[3],
|
|
142
|
+
16
|
|
143
|
+
)}, ${opacity})`
|
|
144
144
|
: `rgba(255, 255, 255, 0)`;
|
|
145
145
|
};
|
|
146
146
|
|
|
@@ -233,8 +233,8 @@ export const getBarChartGridTop = (maxValue: number, showLabel = true) => {
|
|
|
233
233
|
30 +
|
|
234
234
|
(showLabel
|
|
235
235
|
? Number(maxValue).toLocaleString().length *
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
8 *
|
|
237
|
+
Math.sin((30 / 180) * Math.PI)
|
|
238
238
|
: 0)
|
|
239
239
|
);
|
|
240
240
|
};
|
|
@@ -250,8 +250,8 @@ export const getBarChartBarLabelHeight = (maxValue: string | number, showLabel =
|
|
|
250
250
|
16 +
|
|
251
251
|
(showLabel
|
|
252
252
|
? Number(maxValue).toLocaleString().length *
|
|
253
|
-
|
|
254
|
-
|
|
253
|
+
8 *
|
|
254
|
+
Math.sin((30 / 180) * Math.PI)
|
|
255
255
|
: 0)
|
|
256
256
|
);
|
|
257
257
|
};
|
|
@@ -286,11 +286,11 @@ export const getDayDatesMatchWeekDay = (dateRange1: IDateRange, dateRange2: IDat
|
|
|
286
286
|
const weekDayDiff = weekDayOfRange1Start - weekDayOfRange2Start;
|
|
287
287
|
|
|
288
288
|
if (
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
for(let i = 0; i < iteratorTimes; i += 1) {
|
|
289
|
+
(weekDayDiff > 0 && weekDayDiff <= 3)
|
|
290
|
+
|| (weekDayDiff < -3)
|
|
291
|
+
) {
|
|
292
|
+
const iteratorTimes = weekDayDiff > 0 ? weekDayDiff : (weekDayDiff + 7);
|
|
293
|
+
for (let i = 0; i < iteratorTimes; i += 1) {
|
|
294
294
|
const day = addDays(dateRange2.start, i);
|
|
295
295
|
dayDates.push({
|
|
296
296
|
date: formatDate(day, 'yyyy/MM/dd'),
|
|
@@ -301,7 +301,7 @@ export const getDayDatesMatchWeekDay = (dateRange1: IDateRange, dateRange2: IDat
|
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
const daysOfLastMonth = differenceInCalendarDays(dateRange1.end, dateRange1.start) + 1;
|
|
304
|
-
for(let i = 0; i < daysOfLastMonth; i += 1) {
|
|
304
|
+
for (let i = 0; i < daysOfLastMonth; i += 1) {
|
|
305
305
|
const day = addDays(dateRange1.start, i);
|
|
306
306
|
dayDates.push({
|
|
307
307
|
date: formatDate(day, 'yyyy/MM/dd'),
|
|
@@ -312,7 +312,7 @@ export const getDayDatesMatchWeekDay = (dateRange1: IDateRange, dateRange2: IDat
|
|
|
312
312
|
|
|
313
313
|
const overMonth1Days = getDate(dateRange2.end) - getDate(dateRange1.end) - (7 - Math.abs(weekDayDiff));
|
|
314
314
|
if (overMonth1Days > 0) {
|
|
315
|
-
for(let j = overMonth1Days; j > 0; j -= 1) {
|
|
315
|
+
for (let j = overMonth1Days; j > 0; j -= 1) {
|
|
316
316
|
const day = subDays(dateRange2.end, j);
|
|
317
317
|
dayDates.push({
|
|
318
318
|
date: formatDate(day, 'yyyy/MM/dd'),
|
|
@@ -327,7 +327,7 @@ export const getDayDatesMatchWeekDay = (dateRange1: IDateRange, dateRange2: IDat
|
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
export const translateDayToLocale = (day: number) => {
|
|
330
|
-
switch(day) {
|
|
330
|
+
switch (day) {
|
|
331
331
|
case 0:
|
|
332
332
|
return '日';
|
|
333
333
|
case 1:
|
|
@@ -402,11 +402,11 @@ export const downloadBlob = (data: ExcelJS.Buffer, fileName: string, mimeType: s
|
|
|
402
402
|
};
|
|
403
403
|
|
|
404
404
|
export const isDateRangesEqual = (dateRange1: IDateRange, dateRange2: IDateRange) => {
|
|
405
|
-
return getYear(dateRange1.start) === getYear(dateRange2.start) &&
|
|
406
|
-
getMonth(dateRange1.start) === getMonth(dateRange2.start) &&
|
|
407
|
-
getDate(dateRange1.start) === getDate(dateRange2.start) &&
|
|
408
|
-
getYear(dateRange1.end) === getYear(dateRange2.end) &&
|
|
409
|
-
getMonth(dateRange1.end) === getMonth(dateRange2.end) &&
|
|
405
|
+
return getYear(dateRange1.start) === getYear(dateRange2.start) &&
|
|
406
|
+
getMonth(dateRange1.start) === getMonth(dateRange2.start) &&
|
|
407
|
+
getDate(dateRange1.start) === getDate(dateRange2.start) &&
|
|
408
|
+
getYear(dateRange1.end) === getYear(dateRange2.end) &&
|
|
409
|
+
getMonth(dateRange1.end) === getMonth(dateRange2.end) &&
|
|
410
410
|
getDate(dateRange1.end) === getDate(dateRange2.end);
|
|
411
411
|
}
|
|
412
412
|
|
|
@@ -472,7 +472,16 @@ export const ga4ev = ({ category, action, label, value, cb }: {
|
|
|
472
472
|
data.eventCallback = cb;
|
|
473
473
|
}
|
|
474
474
|
|
|
475
|
-
|
|
475
|
+
const eventParams: any = {
|
|
476
|
+
action,
|
|
477
|
+
value,
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
if (cb) {
|
|
481
|
+
eventParams.event_callback = cb;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
window.dataLayer?.push('event', label, eventParams);
|
|
476
485
|
}
|
|
477
486
|
};
|
|
478
487
|
|
|
@@ -543,14 +552,14 @@ export const waitForTime = (ms: number) => {
|
|
|
543
552
|
}
|
|
544
553
|
|
|
545
554
|
export const waitForever = () => {
|
|
546
|
-
return new Promise(r => {});
|
|
555
|
+
return new Promise(r => { });
|
|
547
556
|
}
|
|
548
557
|
|
|
549
558
|
export const waitFor = async (condition: () => boolean, pollInterval = 50, timeoutAfter: number) => {
|
|
550
559
|
const startTime = Date.now();
|
|
551
560
|
|
|
552
|
-
while(true) {
|
|
553
|
-
if (typeof(timeoutAfter) === 'number' && Date.now() > startTime + timeoutAfter) {
|
|
561
|
+
while (true) {
|
|
562
|
+
if (typeof (timeoutAfter) === 'number' && Date.now() > startTime + timeoutAfter) {
|
|
554
563
|
throw 'Condition not met before timeout';
|
|
555
564
|
}
|
|
556
565
|
|