BUR-62 Изменен тултип на графике. Скорректирован градиент на графике для min-avg-max.
This commit is contained in:
@@ -60,6 +60,58 @@ function formatChartValue(value: number): string {
|
||||
}).format(value);
|
||||
}
|
||||
|
||||
/** Форматирует полную дату и время для начала/конца интервала в tooltip. */
|
||||
function formatTooltipDateTime(value: number): string {
|
||||
return new Intl.DateTimeFormat('ru-RU', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
}).format(new Date(value));
|
||||
}
|
||||
|
||||
/** Форматирует только время, когда конец интервала находится в тот же день. */
|
||||
function formatTooltipTime(value: number): string {
|
||||
return new Intl.DateTimeFormat('ru-RU', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
}).format(new Date(value));
|
||||
}
|
||||
|
||||
/** Проверяет, можно ли показать конец интервала без повторения даты. */
|
||||
function isSameDate(first: number, second: number): boolean {
|
||||
const firstDate = new Date(first);
|
||||
const secondDate = new Date(second);
|
||||
|
||||
return (
|
||||
firstDate.getFullYear() === secondDate.getFullYear()
|
||||
&& firstDate.getMonth() === secondDate.getMonth()
|
||||
&& firstDate.getDate() === secondDate.getDate()
|
||||
);
|
||||
}
|
||||
|
||||
/** Показывает bucket графика как интервал текущей грануляции, а не как одну точку времени. */
|
||||
function formatTooltipInterval(value: AvgPointValue): string {
|
||||
const time = value[0];
|
||||
const slotMs = value[5];
|
||||
|
||||
if (!slotMs) {
|
||||
return formatTooltipDateTime(time);
|
||||
}
|
||||
|
||||
const from = time - slotMs / 2;
|
||||
const to = time + slotMs / 2;
|
||||
|
||||
if (isSameDate(from, to)) {
|
||||
return `${formatTooltipDateTime(from)} — ${formatTooltipTime(to)}`;
|
||||
}
|
||||
|
||||
return `${formatTooltipDateTime(from)} — ${formatTooltipDateTime(to)}`;
|
||||
}
|
||||
|
||||
/** Форматирует значение tooltip: одно число для min=avg=max или среднее с диапазоном. */
|
||||
function formatTooltipValue(value: AvgPointValue): string {
|
||||
const avg = formatChartValue(value[1]);
|
||||
@@ -89,14 +141,7 @@ export function formatTooltip(params: unknown): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
const header = new Intl.DateTimeFormat('ru-RU', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
}).format(new Date(firstValue[0]));
|
||||
const header = formatTooltipInterval(firstValue);
|
||||
|
||||
const rows = avgItems.map((item) => {
|
||||
const value = item.value as AvgPointValue;
|
||||
|
||||
Reference in New Issue
Block a user