@@ -23,55 +23,74 @@ import {
2323} from ' chart.js' ;
2424import { convertSummaryTimeToString } from ' ../utils/converter' ;
2525import { TabListByDays } from ' ../dto/tabListSummary' ;
26+ import { ref , watch } from ' vue' ;
27+ import { log } from ' ../compositions/logger' ;
2628
2729const props = defineProps <{
2830 data: TabListByDays ;
2931}>();
3032
3133ChartJS .register (CategoryScale , LinearScale , BarElement , Title , Tooltip , Legend );
32- const labelsForChart = props .data .days .map (x => x .day );
33- const dataForChart = props .data .days .map (x => x .time );
34- const tickStep = Math .round (dataForChart [0 ] / 5 / 600 ) * 600 ;
3534
36- const data = {
37- labels: labelsForChart ,
38- datasets: [
39- {
40- backgroundColor: [' #5668e2' ],
41- data: dataForChart ,
42- },
43- ],
44- };
35+ const labelsForChart = ref <string []>();
36+ const dataForChart = ref <number []>();
37+ const data = ref <any >();
38+ const options = ref <any >();
4539
46- const options = {
47- responsive: true ,
48- maintainAspectRatio: false ,
49- plugins: {
50- legend: {
51- position: ' none' ,
52- },
53- legendDistance: {
54- padding: 50 ,
55- },
56- tooltip: {
57- callbacks: {
58- label : function (context : any ) {
59- return convertSummaryTimeToString (context .raw );
40+ watch (
41+ () => props .data ,
42+ () => {
43+ refreshChart ();
44+ },
45+ );
46+
47+ refreshChart ();
48+
49+ function refreshChart() {
50+ labelsForChart .value = props .data .days .map (x => x .day );
51+ dataForChart .value = props .data .days .map (x => x .time );
52+ const tickStep = Math .round (dataForChart .value [0 ] / 5 / 600 ) * 600 ;
53+
54+ data .value = {
55+ labels: labelsForChart .value ,
56+ datasets: [
57+ {
58+ backgroundColor: [' #5668e2' ],
59+ data: dataForChart .value ,
60+ },
61+ ],
62+ };
63+
64+ options .value = {
65+ responsive: true ,
66+ maintainAspectRatio: false ,
67+ plugins: {
68+ legend: {
69+ position: ' none' ,
70+ },
71+ legendDistance: {
72+ padding: 50 ,
73+ },
74+ tooltip: {
75+ callbacks: {
76+ label : function (context : any ) {
77+ return convertSummaryTimeToString (context .raw );
78+ },
6079 },
6180 },
6281 },
63- },
64- scales : {
65- y : {
66- ticks: {
67- stepSize: tickStep ,
68- callback : function ( value : any , index : number , ticks : number ) {
69- return convertSummaryTimeToString ( value );
82+ scales: {
83+ y : {
84+ ticks : {
85+ stepSize: tickStep ,
86+ callback : function ( value : any , index : number , ticks : number ) {
87+ return convertSummaryTimeToString ( value );
88+ },
7089 },
7190 },
7291 },
73- },
74- };
92+ };
93+ }
7594 </script >
7695
7796<style scoped>
0 commit comments