set time range

This commit is contained in:
Fine 2022-08-20 15:11:31 +08:00
parent 3ccb605e67
commit eea3ba894a
2 changed files with 20 additions and 41 deletions

View File

@ -17,14 +17,11 @@ limitations under the License. -->
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, onMounted, watch } from "vue"; import { ref, onMounted, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useNetworkProfilingStore } from "@/store/modules/network-profiling"; import { useNetworkProfilingStore } from "@/store/modules/network-profiling";
import { DataSet, Timeline } from "vis-timeline/standalone"; import { DataSet, Timeline } from "vis-timeline/standalone";
import "vis-timeline/styles/vis-timeline-graph2d.css"; import "vis-timeline/styles/vis-timeline-graph2d.css";
import { useThrottleFn } from "@vueuse/core";
/*global Nullable */ /*global Nullable */
const { t } = useI18n();
const networkProfilingStore = useNetworkProfilingStore(); const networkProfilingStore = useNetworkProfilingStore();
const timeRange = ref<Nullable<HTMLDivElement>>(null); const timeRange = ref<Nullable<HTMLDivElement>>(null);
const visGraph = ref<Nullable<any>>(null); const visGraph = ref<Nullable<any>>(null);
@ -36,7 +33,7 @@ onMounted(() => {
width: 0, width: 0,
height: 0, height: 0,
}; };
useThrottleFn(resize, 500)(); visTimeline();
}); });
function visTimeline() { function visTimeline() {
@ -50,19 +47,18 @@ function visTimeline() {
return; return;
} }
const h = timeRange.value.getBoundingClientRect().height; const h = timeRange.value.getBoundingClientRect().height;
const { taskStartTime, fixedTriggerDuration, name } =
networkProfilingStore.selectedNetworkTask;
const startTime =
fixedTriggerDuration > 1800
? taskStartTime + fixedTriggerDuration * 1000 - 30 * 60 * 1000
: taskStartTime;
const task = [ const task = [
{ {
id: 1, id: 1,
content: networkProfilingStore.selectedNetworkTask.name, content: name,
start: new Date( start: new Date(Number(startTime)),
Number(networkProfilingStore.selectedNetworkTask.taskStartTime) end: new Date(Number(taskStartTime + fixedTriggerDuration)),
),
end: new Date(
Number(
networkProfilingStore.selectedNetworkTask.taskStartTime +
networkProfilingStore.selectedNetworkTask.fixedTriggerDuration
)
),
data: networkProfilingStore.selectedNetworkTask, data: networkProfilingStore.selectedNetworkTask,
className: networkProfilingStore.selectedNetworkTask.type, className: networkProfilingStore.selectedNetworkTask.type,
}, },
@ -77,23 +73,6 @@ function visTimeline() {
}; };
visGraph.value = new Timeline(timeRange.value, items, options); visGraph.value = new Timeline(timeRange.value, items, options);
} }
function resize() {
const observer = new ResizeObserver((entries) => {
const entry = entries[0];
const cr = entry.contentRect;
if (
Math.abs(cr.width - oldVal.value.width) < 3 &&
Math.abs(cr.height - oldVal.value.height) < 3
) {
return;
}
visTimeline();
oldVal.value = { width: cr.width, height: cr.height };
});
if (timeRange.value) {
observer.observe(timeRange.value);
}
}
watch( watch(
() => networkProfilingStore.selectedNetworkTask, () => networkProfilingStore.selectedNetworkTask,
() => { () => {
@ -104,7 +83,7 @@ watch(
<style lang="scss" scoped> <style lang="scss" scoped>
.time-ranges { .time-ranges {
width: calc(100% - 5px); width: calc(100% - 5px);
margin: 0 5px 5px 0; padding: 10px;
height: 150px; height: 150px;
} }
</style> </style>

View File

@ -121,27 +121,27 @@ async function changeTask(item: EBPFTaskList) {
getTopology(); getTopology();
} }
async function getTopology() { async function getTopology() {
const { taskStartTime, fixedTriggerDuration } =
networkProfilingStore.selectedNetworkTask;
const serviceInstanceId = const serviceInstanceId =
(selectorStore.currentPod && selectorStore.currentPod.id) || ""; (selectorStore.currentPod && selectorStore.currentPod.id) || "";
const startTime =
fixedTriggerDuration > 1800
? taskStartTime + fixedTriggerDuration * 1000 - 30 * 60 * 1000
: taskStartTime;
const resp = await networkProfilingStore.getProcessTopology({ const resp = await networkProfilingStore.getProcessTopology({
serviceInstanceId, serviceInstanceId,
duration: { duration: {
start: dateFormatStep( start: dateFormatStep(
getLocalTime( getLocalTime(appStore.utc, new Date(startTime)),
appStore.utc,
new Date(networkProfilingStore.selectedNetworkTask.taskStartTime)
),
appStore.duration.step, appStore.duration.step,
true true
), ),
end: dateFormatStep( end: dateFormatStep(
getLocalTime( getLocalTime(
appStore.utc, appStore.utc,
new Date( new Date(taskStartTime + fixedTriggerDuration * 1000)
networkProfilingStore.selectedNetworkTask.taskStartTime +
networkProfilingStore.selectedNetworkTask.fixedTriggerDuration *
1000
)
), ),
appStore.duration.step, appStore.duration.step,
true true