refactor association metrics

This commit is contained in:
Qiuxia Fan 2022-07-28 15:34:40 +08:00
parent dc8e4bf273
commit 0512309290

View File

@ -105,22 +105,34 @@ function visTimeline() {
return; return;
} }
dashboardStore.selectWidget(props.data); dashboardStore.selectWidget(props.data);
associateMetrics(properties.items, events);
});
}
function associateMetrics(
items: number[],
events: {
id: number;
content: string;
start: Date;
end: Date;
data: unknown;
className: string;
}[]
) {
const all = getDashboard(dashboardStore.currentDashboard).widgets; const all = getDashboard(dashboardStore.currentDashboard).widgets;
const widgets = all.filter( const widgets = all.filter((d: any) => {
(d: { value: string; label: string } & LayoutConfig) => {
const isLinear = ["Bar", "Line", "Area"].includes( const isLinear = ["Bar", "Line", "Area"].includes(
(d.graph && d.graph.type) || "" (d.graph && d.graph.type) || ""
); );
if (isLinear) { if (isLinear) {
return d; return d;
} }
} });
); const index = items[0];
const index = properties.items[0];
const i = events[index - 1 || 0]; const i = events[index - 1 || 0];
for (const widget of widgets) { for (const widget of widgets) {
let end = i.end; let end: Date | number = i.end;
if (!isNaN(index)) { if (!isNaN(index)) {
let diff = 60000; let diff = 60000;
switch (appStore.duration.step) { switch (appStore.duration.step) {
@ -140,17 +152,19 @@ function visTimeline() {
} }
const startTime = dateFormatTime(i.start, appStore.duration.step); const startTime = dateFormatTime(i.start, appStore.duration.step);
const endTime = dateFormatTime(new Date(end), appStore.duration.step); const endTime = dateFormatTime(new Date(end), appStore.duration.step);
widget.filters = { const item = {
...widget,
filters: {
sourceId: dashboardStore.selectedGrid.id || "", sourceId: dashboardStore.selectedGrid.id || "",
isRange: true, isRange: true,
duration: { duration: {
startTime, startTime,
endTime, endTime,
}, },
},
}; };
dashboardStore.setWidget(widget); dashboardStore.setWidget(item);
} }
});
} }
function resize() { function resize() {
const observer = new ResizeObserver((entries) => { const observer = new ResizeObserver((entries) => {