|
23 | 23 | /> |
24 | 24 | </template> |
25 | 25 |
|
26 | | -<script> |
| 26 | +<script setup lang="ts"> |
27 | 27 | import moment from 'moment'; |
28 | 28 | import prettyBytes from 'pretty-bytes'; |
| 29 | +import { computed } from 'vue'; |
29 | 30 | import { useI18n } from 'vue-i18n'; |
30 | 31 |
|
31 | 32 | import LineChart from '@/views/instances/details/LineChart'; |
32 | 33 |
|
33 | | -export default { |
34 | | - components: { LineChart }, |
35 | | - props: { |
36 | | - data: { |
37 | | - type: Array, |
38 | | - default: () => [], |
| 34 | +const { t } = useI18n(); |
| 35 | +
|
| 36 | +const { data } = defineProps<{ |
| 37 | + data: Array<any>; |
| 38 | +}>(); |
| 39 | +
|
| 40 | +const datasets = computed(() => { |
| 41 | + const hasMetaspace = Object.values(data).some((d) => d.metaspace !== null); |
| 42 | +
|
| 43 | + const _datasets: Record<string, { label: string }> = { |
| 44 | + used: { |
| 45 | + label: 'instances.details.memory.used', |
39 | 46 | }, |
40 | | - }, |
41 | | - setup(props) { |
42 | | - const { t } = useI18n(); |
43 | | - return { ...props, t }; |
44 | | - }, |
45 | | - data() { |
46 | | - return { |
47 | | - chart: undefined, |
48 | | - label: 'timestamp', |
49 | | - datasets: { |
50 | | - used: { |
51 | | - label: 'instances.details.memory.used', |
52 | | - }, |
53 | | - metaspace: { |
54 | | - label: 'instances.details.memory.metaspace', |
| 47 | + committed: { |
| 48 | + label: 'instances.details.memory.committed', |
| 49 | + }, |
| 50 | + }; |
| 51 | +
|
| 52 | + if (hasMetaspace) { |
| 53 | + _datasets.metaspace = { |
| 54 | + label: 'instances.details.memory.metaspace', |
| 55 | + }; |
| 56 | + } |
| 57 | +
|
| 58 | + return _datasets; |
| 59 | +}); |
| 60 | +
|
| 61 | +const config = { |
| 62 | + options: { |
| 63 | + plugins: { |
| 64 | + tooltip: { |
| 65 | + callbacks: { |
| 66 | + title: (ctx) => { |
| 67 | + return prettyBytes(ctx[0].parsed.y); |
| 68 | + }, |
| 69 | + label: (ctx) => { |
| 70 | + return t(ctx.dataset.label); |
| 71 | + }, |
55 | 72 | }, |
56 | | - committed: { |
57 | | - label: 'instances.details.memory.committed', |
| 73 | + }, |
| 74 | + }, |
| 75 | + scales: { |
| 76 | + y: { |
| 77 | + ticks: { |
| 78 | + callback: (label) => prettyBytes(label), |
58 | 79 | }, |
59 | 80 | }, |
60 | | - config: { |
61 | | - options: { |
62 | | - plugins: { |
63 | | - tooltip: { |
64 | | - callbacks: { |
65 | | - title: (ctx) => { |
66 | | - return prettyBytes(ctx[0].parsed.y); |
67 | | - }, |
68 | | - label: (ctx) => { |
69 | | - return this.t(ctx.dataset.label); |
70 | | - }, |
71 | | - }, |
72 | | - }, |
73 | | - }, |
74 | | - scales: { |
75 | | - y: { |
76 | | - ticks: { |
77 | | - callback: (label) => { |
78 | | - return prettyBytes(label); |
79 | | - }, |
80 | | - }, |
81 | | - }, |
82 | | - x: { |
83 | | - ticks: { |
84 | | - callback: (label) => { |
85 | | - return moment(label).format('HH:mm:ss'); |
86 | | - }, |
87 | | - }, |
88 | | - }, |
89 | | - }, |
| 81 | + x: { |
| 82 | + ticks: { |
| 83 | + callback: (label) => moment(label).format('HH:mm:ss'), |
90 | 84 | }, |
91 | 85 | }, |
92 | | - }; |
| 86 | + }, |
93 | 87 | }, |
94 | 88 | }; |
95 | 89 | </script> |
0 commit comments