@@ -25,6 +25,7 @@ interface SvgLayerArray {
25
25
interface PanelConfig {
26
26
backgroundColor : string ;
27
27
message : string ;
28
+ viewBoxWidth : number ;
28
29
namespaces : {
29
30
[ key : string ] : {
30
31
visible : boolean ;
@@ -36,6 +37,7 @@ interface PanelConfig {
36
37
const defaultConfig : PanelConfig = {
37
38
backgroundColor : "#585858ff" ,
38
39
message : "" ,
40
+ viewBoxWidth : 10000 ,
39
41
namespaces : { } ,
40
42
} ;
41
43
@@ -51,13 +53,21 @@ const CraneVisualizer: React.FC<{ context: PanelExtensionContext }> = ({ context
51
53
const [ latest_msg , setLatestMsg ] = useState < SvgLayerArray > ( ) ;
52
54
53
55
const resetViewBox = useCallback ( ( ) => {
54
- setViewBox ( "-5000 -3000 10000 6000" ) ;
55
- } , [ setViewBox ] ) ;
56
+ const x = - config . viewBoxWidth / 2 ;
57
+ const aspectRatio = 0.6 ; // 元のアスペクト比 (6000 / 10000)
58
+ const height = config . viewBoxWidth * aspectRatio ;
59
+ const y = - height / 2 ;
60
+ setViewBox ( `${ x } ${ y } ${ config . viewBoxWidth } ${ height } ` ) ;
61
+ } , [ setViewBox , config ] ) ;
56
62
57
63
useEffect ( ( ) => {
58
64
const handleKeyDown = ( event : KeyboardEvent ) => {
59
65
if ( event . ctrlKey && event . key === "0" ) {
60
- resetViewBox ( ) ;
66
+ const x = - config . viewBoxWidth / 2 ;
67
+ const aspectRatio = 0.6 ; // 元のアスペクト比 (6000 / 10000)
68
+ const height = config . viewBoxWidth * aspectRatio ;
69
+ const y = - height / 2 ;
70
+ setViewBox ( `${ x } ${ y } ${ config . viewBoxWidth } ${ height } ` ) ;
61
71
}
62
72
} ;
63
73
@@ -66,7 +76,7 @@ const CraneVisualizer: React.FC<{ context: PanelExtensionContext }> = ({ context
66
76
return ( ) => {
67
77
document . removeEventListener ( "keydown" , handleKeyDown ) ;
68
78
} ;
69
- } , [ resetViewBox ] ) ;
79
+ } , [ resetViewBox , config ] ) ;
70
80
71
81
// トピックが設定されたときにサブスクライブする
72
82
useEffect ( ( ) => {
@@ -94,6 +104,7 @@ const CraneVisualizer: React.FC<{ context: PanelExtensionContext }> = ({ context
94
104
fields : {
95
105
topic : { label : "トピック名" , input : "string" , value : topic } ,
96
106
backgroundColor : { label : "背景色" , input : "rgba" , value : config . backgroundColor } ,
107
+ viewBoxWidth : { label : "ViewBox 幅" , input : "number" , value : config . viewBoxWidth } ,
97
108
} ,
98
109
} ,
99
110
namespaces : {
@@ -109,7 +120,12 @@ const CraneVisualizer: React.FC<{ context: PanelExtensionContext }> = ({ context
109
120
setTopic ( action . payload . value as string ) ;
110
121
} else if ( path == "general.backgroundColor" ) {
111
122
setConfig ( ( prevConfig ) => ( { ...prevConfig , backgroundColor : action . payload . value as string } ) ) ;
112
- } else if ( action . payload . path [ 0 ] == "namespaces" ) {
123
+ } else if ( path == "general.viewBoxWidth" ) {
124
+ setConfig ( ( prevConfig ) => ( { ...prevConfig , viewBoxWidth : action . payload . value as number } ) ) ;
125
+ } else if ( path == "general.viewBoxHeight" ) {
126
+ setConfig ( ( prevConfig ) => ( { ...prevConfig , viewBoxHeight : action . payload . value as number } ) ) ;
127
+ }
128
+ else if ( action . payload . path [ 0 ] == "namespaces" ) {
113
129
const pathParts = path . split ( "." ) ;
114
130
const namespacePath = pathParts . slice ( 1 , - 1 ) ;
115
131
const leafNamespace = pathParts [ pathParts . length - 1 ] ;
@@ -164,7 +180,7 @@ const CraneVisualizer: React.FC<{ context: PanelExtensionContext }> = ({ context
164
180
context . watch ( "topics" ) ;
165
181
context . watch ( "currentFrame" ) ;
166
182
167
- } , [ context ] ) ;
183
+ } , [ context , topic ] ) ;
168
184
169
185
useEffect ( ( ) => {
170
186
if ( messages ) {
0 commit comments