@@ -16,6 +16,7 @@ export default class BeamPosition2dChart extends GenericChart {
16
16
this . render ( ) ;
17
17
18
18
this . _unit = "sigma" ;
19
+ this . _mode = "sep" ;
19
20
20
21
this . _data = null ;
21
22
this . sigmaInMM = 1 ; // NOTE: this needs to be changed later
@@ -28,21 +29,24 @@ export default class BeamPosition2dChart extends GenericChart {
28
29
*/
29
30
set unit ( newUnits ) {
30
31
this . _unit = newUnits ;
31
-
32
- this . chart . xAxis [ 0 ] . setTitle ( {
33
- text : `Sep Beam position [${ newUnits . replace ( "sigma" , sigmaChar ) } ]`
34
- } ) ;
35
-
36
- this . chart . yAxis [ 0 ] . setTitle ( {
37
- text : `Xing Beam position [${ newUnits . replace ( "sigma" , sigmaChar ) } ]`
38
- } ) ;
39
-
40
32
this . refresh ( ) ;
41
33
}
42
34
get unit ( ) {
43
35
return this . _unit ;
44
36
}
45
37
38
+ /**
39
+ * @param {string } newMode
40
+ */
41
+ set mode ( newMode ) {
42
+ this . _mode = newMode ;
43
+ this . refresh ( ) ;
44
+ }
45
+ get mode ( ) {
46
+ return this . _mode ;
47
+ }
48
+
49
+
46
50
set data ( data ) {
47
51
this . _data = data ;
48
52
this . refresh ( ) ;
@@ -53,7 +57,15 @@ export default class BeamPosition2dChart extends GenericChart {
53
57
}
54
58
55
59
refresh ( ) {
56
- if ( this . data == null ) return ;
60
+ if ( this . data == null || this . chart == null ) return ;
61
+
62
+ this . chart . xAxis [ 0 ] . setTitle ( {
63
+ text : `Sep Beam ${ this . mode } [${ this . unit . replace ( "sigma" , sigmaChar ) } ]`
64
+ } ) ;
65
+
66
+ this . chart . yAxis [ 0 ] . setTitle ( {
67
+ text : `Xing Beam ${ this . mode } [${ this . unit . replace ( "sigma" , sigmaChar ) } ]`
68
+ } ) ;
57
69
58
70
this . updateData ( this . data ) ;
59
71
}
@@ -72,17 +84,44 @@ export default class BeamPosition2dChart extends GenericChart {
72
84
73
85
/**
74
86
* @private
75
- * @param {any } newData
87
+ * @param {any } data
76
88
*/
77
- updateData ( newData ) {
78
- const crossing = newData . beamCrossing ;
79
- const separation = newData . beamSeparation ;
80
- if ( crossing != null && separation != null ) {
81
- this . chart . series [ 0 ] . setData ( this . toXYPoints ( separation [ 0 ] , crossing [ 0 ] ) . slice ( 0 , - 1 ) ) ;
82
- this . chart . series [ 1 ] . setData ( this . toXYPoints ( separation [ 1 ] , crossing [ 1 ] ) . slice ( 0 , - 1 ) ) ;
89
+ updateData ( data ) {
90
+ while ( this . chart . series . length ) {
91
+ this . chart . series [ 0 ] . remove ( ) ;
92
+ }
93
+
94
+ let positionBeam1 = [ ] ;
95
+ let positionBeam2 = [ ] ;
96
+ if ( data . beamCrossing != null && data . beamSeparation != null ) {
97
+ positionBeam1 = this . toXYPoints ( data . beamSeparation [ 0 ] , data . beamCrossing [ 0 ] ) . slice ( 0 , - 1 ) ;
98
+ positionBeam2 = this . toXYPoints ( data . beamSeparation [ 1 ] , data . beamCrossing [ 1 ] ) . slice ( 0 , - 1 ) ;
99
+ }
100
+
101
+ if ( this . mode == 'pos' ) {
102
+ this . chart . addSeries ( {
103
+ type : "scatter" ,
104
+ name : "Beam 1" ,
105
+ data : positionBeam1 ,
106
+ color : "hsl(240, 70%, 70%)"
107
+ } ) ;
108
+ this . chart . addSeries ( {
109
+ type : "scatter" ,
110
+ name : "Beam 2" ,
111
+ data : positionBeam2 ,
112
+ color : "hsl(0, 70%, 70%)"
113
+ } ) ;
83
114
} else {
84
- this . chart . series [ 0 ] . setData ( [ ] ) ;
85
- this . chart . series [ 1 ] . setData ( [ ] ) ;
115
+ const separation = positionBeam1 . map ( ( _ , i ) => [
116
+ positionBeam1 [ i ] [ 0 ] - positionBeam2 [ i ] [ 0 ] ,
117
+ positionBeam1 [ i ] [ 1 ] - positionBeam2 [ i ] [ 1 ] ,
118
+ ] ) ;
119
+ this . chart . addSeries ( {
120
+ type : "scatter" ,
121
+ name : "Nominal Separation" ,
122
+ data : separation ,
123
+ color : "hsl(0, 0, 0)"
124
+ } ) ;
86
125
}
87
126
}
88
127
@@ -110,7 +149,7 @@ export default class BeamPosition2dChart extends GenericChart {
110
149
111
150
tooltip : {
112
151
headerFormat : '<b>{series.name}</b><br/>' ,
113
- pointFormat : 'Separation: {point.x:.2f}<br/>Crossing: {point.y:.2f}' ,
152
+ pointFormat : 'Separation Plane : {point.x:.2f}<br/>Crossing Plane : {point.y:.2f}' ,
114
153
shared : true ,
115
154
// NOTE: disable this while https://github.com/highcharts/highcharts/issues/11688 is still a bug
116
155
//outside: true // this is needed to make the tooltip not go under the axis title
@@ -130,18 +169,8 @@ export default class BeamPosition2dChart extends GenericChart {
130
169
}
131
170
} ,
132
171
133
- series : [ {
134
- type : "scatter" ,
135
- name : "Beam 1" ,
136
- data : [ ] ,
137
- color : "hsl(240, 70%, 70%)"
138
- } , {
139
- type : "scatter" ,
140
- name : "Beam 2" ,
141
- data : [ ] ,
142
- color : "hsl(0, 70%, 70%)"
143
- }
144
- ] } ) ) ;
172
+ series : [ ]
173
+ } ) ) ;
145
174
146
175
window . chart = this . chart ;
147
176
}
0 commit comments