@@ -14,7 +14,7 @@ const T = type({
1414 type : LineType ,
1515} )
1616
17- export const line = defineComponent < 'line' , typeof T . infer > ( ( attrs , context ) => {
17+ export const line = defineComponent < 'line' , typeof T . infer , { division : number | undefined } > ( ( attrs , context ) => {
1818 const space = new Map ( )
1919 space . set ( 'start-point' , lineStartPoint )
2020 space . set ( 'end-point' , lineEndPoint )
@@ -30,17 +30,22 @@ export const line = defineComponent<'line', typeof T.infer>((attrs, context) =>
3030 } ,
3131 attrs : T ,
3232 setup ( _children ) {
33+ const division = context . division ?? 1
3334 const container = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'g' )
3435 container . id = 'canvas-line'
36+
37+ const pos_from = { x : attrs . from . value [ 0 ] * division , y : attrs . from . value [ 1 ] * division }
38+ const pos_to = { x : attrs . to . value [ 0 ] * division , y : attrs . to . value [ 1 ] * division }
39+
3540 const path = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'path' )
36- path . setAttribute ( 'd' , `M ${ attrs . from . value [ 0 ] } ${ attrs . from . value [ 1 ] } L ${ attrs . to . value [ 0 ] } ${ attrs . to . value [ 1 ] } ` )
41+ path . setAttribute ( 'd' , `M ${ pos_from . x } ${ pos_from . y } L ${ pos_to . x } ${ pos_to . y } ` )
3742 path . id = 'line-path'
3843 path . setAttribute ( 'stroke' , theme . pallete ( 'primary' ) )
3944 path . setAttribute ( 'stroke-dasharray' , resolveDasharray ( attrs . type . value ) )
4045 const texElement = generateTexNode ( attrs . value ?. value )
4146 const texPosition = [
42- attrs . from . value [ 0 ] + ( attrs . to . value [ 0 ] - attrs . from . value [ 0 ] ) / 2 ,
43- attrs . from . value [ 1 ] + ( attrs . to . value [ 1 ] - attrs . from . value [ 1 ] ) / 2 ,
47+ pos_from . x + ( pos_to . x - pos_from . x ) / 2 ,
48+ pos_from . y + ( pos_to . y - pos_from . y ) / 2 ,
4449 ]
4550 const texContainer = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'g' )
4651 texContainer . setAttribute ( 'transform' , `translate(${ texPosition [ 0 ] } , ${ texPosition [ 1 ] } )` )
0 commit comments