GraphPane.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <script lang="ts" setup>
  2. import { ref } from 'vue'
  3. import { useRafFn } from '@vueuse/core'
  4. import { useState } from '../composables/state'
  5. const width = 160
  6. const height = 40
  7. const strokeWidth = 2
  8. const updateInterval = 100 // Update interval in milliseconds
  9. const topOffset = 0 // Offset from the top
  10. const points = ref('')
  11. const frameTimes = ref([])
  12. const maxFrames = ref(width / strokeWidth)
  13. let lastUpdateTime = performance.now()
  14. const { renderingTimes } = useState()
  15. useRafFn(({ timestamp }) => {
  16. if (timestamp - lastUpdateTime >= updateInterval) {
  17. lastUpdateTime = timestamp
  18. frameTimes.value.push(renderingTimes?.value)
  19. renderingTimes.value = 0
  20. if (frameTimes.value.length > maxFrames.value) {
  21. frameTimes.value.shift()
  22. }
  23. points.value = frameTimes.value
  24. .map(
  25. (value, index) =>
  26. `${index * strokeWidth},${
  27. height + topOffset - strokeWidth / 2 - (value * (height + topOffset - strokeWidth)) / 2
  28. }`,
  29. )
  30. .join(' ')
  31. }
  32. })
  33. </script>
  34. <template>
  35. <div
  36. class="absolute
  37. right-2
  38. top-2
  39. flex
  40. px-4
  41. py-1
  42. justify-between
  43. gap-4
  44. items-center
  45. mb-2
  46. z-10
  47. bg-white
  48. dark:bg-dark
  49. shadow-xl
  50. rounded
  51. border-4
  52. border-solid
  53. bg-primary
  54. border-primary
  55. pointer-events-none
  56. overflow-hidden"
  57. >
  58. <label class="text-secondary text-xs w-1/3">Rendering Activity</label>
  59. <div
  60. class="
  61. bg-gray-100
  62. dark:bg-gray-600
  63. relative
  64. w-2/3
  65. p-1
  66. rounded
  67. text-right
  68. text-xs
  69. focus:border-gray-200
  70. outline-none
  71. border-none
  72. font-sans
  73. "
  74. >
  75. <svg
  76. :width="width"
  77. :height="height"
  78. xmlns="http://www.w3.org/2000/svg"
  79. fill="none"
  80. >
  81. <polyline
  82. :points="points"
  83. stroke="lightgray"
  84. :stroke-width="strokeWidth"
  85. stroke-linecap="round"
  86. stroke-linejoin="round"
  87. />
  88. </svg>
  89. </div>
  90. </div>
  91. </template>