Skip to content

Commit 4211836

Browse files
committed
refactor(mem-chart): simplify component structure and conditionally include metaspace
1 parent 2440dd3 commit 4211836

File tree

1 file changed

+49
-55
lines changed
  • spring-boot-admin-server-ui/src/main/frontend/views/instances/details

1 file changed

+49
-55
lines changed

spring-boot-admin-server-ui/src/main/frontend/views/instances/details/mem-chart.vue

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,73 +23,67 @@
2323
/>
2424
</template>
2525

26-
<script>
26+
<script setup lang="ts">
2727
import moment from 'moment';
2828
import prettyBytes from 'pretty-bytes';
29+
import { computed } from 'vue';
2930
import { useI18n } from 'vue-i18n';
3031
3132
import LineChart from '@/views/instances/details/LineChart';
3233
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',
3946
},
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+
},
5572
},
56-
committed: {
57-
label: 'instances.details.memory.committed',
73+
},
74+
},
75+
scales: {
76+
y: {
77+
ticks: {
78+
callback: (label) => prettyBytes(label),
5879
},
5980
},
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'),
9084
},
9185
},
92-
};
86+
},
9387
},
9488
};
9589
</script>

0 commit comments

Comments
 (0)