5
5
</template >
6
6
<script >
7
7
import timechart from " timechart" ;
8
+ import colors from " vuetify/lib/util/colors" ;
8
9
export default {
9
10
data : () => ({
10
11
ws: null ,
11
12
chart: null ,
12
- iColor: 0 ,
13
- colors: [
14
- " #F44336" ,
15
- " #9C27B0" ,
16
- " #3F51B5" ,
17
- " #00BCD4" ,
18
- " #4CAF50" ,
19
- " #FF9800" ,
20
- " #795548"
21
- ]
13
+ indexColor: 0 ,
14
+ lineColors: {
15
+ light: [
16
+ colors .red .lighten1 ,
17
+ colors .green .lighten1 ,
18
+ colors .orange .lighten1 ,
19
+ colors .purple .lighten1 ,
20
+ colors .indigo .lighten1 ,
21
+ colors .teal .lighten1 ,
22
+ colors .pink .lighten1
23
+ ],
24
+ dark: [
25
+ colors .red .darken4 ,
26
+ colors .green .darken4 ,
27
+ colors .orange .darken4 ,
28
+ colors .purple .darken4 ,
29
+ colors .indigo .darken4 ,
30
+ colors .teal .darken4 ,
31
+ colors .pink .darken4
32
+ ]
33
+ }
22
34
}),
35
+ computed: {
36
+ isDark () {
37
+ return this .$vuetify .theme .dark ;
38
+ }
39
+ },
23
40
created () {
24
41
this .initWS ();
25
42
},
@@ -35,9 +52,28 @@ export default {
35
52
realTime: true
36
53
});
37
54
},
55
+ watch: {
56
+ isDark : function () {
57
+ if (this .isDark ) {
58
+ for (var i in this .chart .options .series ) {
59
+ this .chart .options .series [i].color = this .lineColors .dark [i];
60
+ }
61
+ } else {
62
+ for (i in this .chart .options .series ) {
63
+ this .chart .options .series [i].color = this .lineColors .light [i];
64
+ }
65
+ }
66
+ this .chart .update ();
67
+ }
68
+ },
38
69
methods: {
39
70
initWS () {
40
- this .ws = new WebSocket ((document .location .protocol == ' https:' ? ' wss' : ' ws' )+ " ://" + window .location .host + " /ws" );
71
+ this .ws = new WebSocket (
72
+ (document .location .protocol == " https:" ? " wss" : " ws" ) +
73
+ " ://" +
74
+ window .location .host +
75
+ " /ws"
76
+ );
41
77
this .ws .onopen = this .WSonopen ;
42
78
this .ws .onclose = this .WSclose ;
43
79
this .ws .onmessage = this .WSonmessage ;
@@ -55,6 +91,15 @@ export default {
55
91
WSonerror (evt ) {
56
92
console .log (" ERROR: " + evt .data );
57
93
},
94
+ selectColor () {
95
+ this .indexColor ++ ;
96
+ this .indexColor == this .lineColors .light .length ? 0 : this .indexColor ;
97
+ if (this .$vuetify .theme .dark ) {
98
+ return this .lineColors .dark [this .indexColor ];
99
+ } else {
100
+ return this .lineColors .light [this .indexColor ];
101
+ }
102
+ },
58
103
praseWS (data ) {
59
104
if (data != " " ) {
60
105
const jsonWS = JSON .parse (data);
@@ -68,9 +113,10 @@ export default {
68
113
y: jsonWS .DataPack [i].Data
69
114
});
70
115
} else {
116
+ const color = this .selectColor ();
71
117
this .chart .options .series .push ({
72
118
name: jsonWS .DataPack [i].Name ,
73
- color: this . colors [ this . iColor ] ,
119
+ color: color ,
74
120
data: [{ x: jsonWS .DataPack [i].Tick , y: jsonWS .DataPack [i].Data }]
75
121
});
76
122
this .iColor ++ ;
0 commit comments