@@ -139,7 +139,7 @@ function jianpu(data)
139139 var number = note2number ( d ) ;
140140 var divisions = partAttr . divisions ;
141141 var dy = 0 ; //绘制下划线和点时的位置偏移
142-
142+ var ddy = 0 //绘制上方点和线时位置偏移
143143 //console.log(number);
144144 //绘制音符
145145 d3 . select ( this )
@@ -292,26 +292,30 @@ function jianpu(data)
292292 dy += 5 ;
293293 }
294294 else if ( number . octave == 5 )
295+ {
295296 d3 . select ( this )
296297 . append ( "circle" )
297298 . attr ( "transform" , `translate(${ marginLeft + start + reset * noteSpacing } ,${ marginTop + lineIndex * eachHeight } )` )
298299 . attr ( "cx" , 0 )
299300 . attr ( "cy" , - 18 )
300301 . attr ( "r" , 1.5 )
301302 . attr ( "fill" , "black" ) ;
303+ ddy += 5 ;
304+ }
302305 //绘制连音的曲线
303306 if ( number . tied )
304307 {
305308
306309 if ( tiePath [ 0 ] == - 1 )
307310 {
308311 tiePath [ 0 ] = marginLeft + start + reset * noteSpacing ;
309- tiePath [ 1 ] = marginTop + lineIndex * eachHeight + dy + 4 ;
312+ tiePath [ 1 ] = marginTop + lineIndex * eachHeight - ( ddy + 17 ) ;
310313 }
311314 else if ( tiePath [ 2 ] == - 1 )
312315 {
313316 tiePath [ 2 ] = marginLeft + start + reset * noteSpacing ;
314- tiePath [ 3 ] = marginTop + lineIndex * eachHeight + dy + 4 ;
317+ tiePath [ 3 ] = marginTop + lineIndex * eachHeight - ( ddy + 17 ) ;
318+ //如果两个音符在一行,绘制一条曲线;如果在两行,绘制两条曲线。
315319 if ( Math . abs ( tiePath [ 3 ] - tiePath [ 1 ] ) < 20 )
316320 {
317321 d3 . select ( this )
@@ -325,7 +329,7 @@ function jianpu(data)
325329 }
326330 else if ( Math . abs ( tiePath [ 3 ] - tiePath [ 1 ] ) > 20 )
327331 {
328- let path1 = [ tiePath [ 0 ] , tiePath [ 1 ] , tiePath [ 0 ] + 20 , tiePath [ 1 ] ] ;
332+ let path1 = [ tiePath [ 0 ] , tiePath [ 1 ] , tiePath [ 0 ] + noteSpacing , tiePath [ 1 ] ] ;
329333 let path2 = [ tiePath [ 2 ] - 10 , tiePath [ 3 ] , tiePath [ 2 ] , tiePath [ 3 ] ] ;
330334 d3 . select ( this )
331335 . append ( "path" )
@@ -349,22 +353,21 @@ function jianpu(data)
349353 {
350354 if ( i != 0 && i + 1 < length && durList [ i - 1 ] == number . dur && number . dur == durList [ i + 1 ] )
351355 {
352- var dTop = 0 ; //绘制三连音时的位置偏移
353356 if ( octList [ i - 1 ] == 5 || octList [ i ] == 5 || octList [ i + 1 ] == 5 )
354- dTop = 5 ;
357+ ddy = 5 ;
355358 d3 . select ( this )
356359 . append ( "path" )
357360 . attr ( "fill" , "none" )
358361 . attr ( "stroke" , "black" )
359362 . attr ( "stroke-width" , "1px" )
360363 . attr ( "transform" , `translate(${ marginLeft + start + reset * noteSpacing } ,${ marginTop + lineIndex * eachHeight } )` )
361- . attr ( "d" , `M ${ - noteSpacing } ${ - ( 16 + dTop ) } L ${ - noteSpacing } ${ - ( 19 + dTop ) } L ${ noteSpacing } ${ - ( 19 + dTop ) } L ${ noteSpacing } ${ - ( 16 + dTop ) } ` ) ;
364+ . attr ( "d" , `M ${ - noteSpacing } ${ - ( 16 + ddy ) } L ${ - noteSpacing } ${ - ( 19 + ddy ) } L ${ noteSpacing } ${ - ( 19 + ddy ) } L ${ noteSpacing } ${ - ( 16 + ddy ) } ` ) ;
362365 d3 . select ( this )
363366 . append ( "text" )
364367 . attr ( "font-size" , 10 )
365368 . attr ( "text-anchor" , "middle" )
366369 . attr ( "x" , 0 )
367- . attr ( "y" , - ( 16 + dTop ) )
370+ . attr ( "y" , - ( 16 + ddy ) )
368371 . attr ( "transform" , `translate(${ marginLeft + start + reset * noteSpacing } ,${ marginTop + lineIndex * eachHeight } )` )
369372 . text ( "3" ) ;
370373 }
@@ -384,7 +387,7 @@ function jianpu(data)
384387 else if ( p [ 3 ] > p [ 1 ] && p [ 3 ] - p [ 1 ] < 20 )
385388 p [ 1 ] = p [ 3 ] ;
386389 var dx = p [ 2 ] - p [ 0 ] ;
387- return `M ${ p [ 0 ] } ${ p [ 1 ] } C ${ p [ 0 ] + dx / 4 } ${ p [ 1 ] + 4 } ${ p [ 2 ] - dx / 4 } ${ p [ 1 ] + 4 } ${ p [ 2 ] } ${ p [ 1 ] } ` ;
390+ return `M ${ p [ 0 ] } ${ p [ 1 ] } C ${ p [ 0 ] + dx / 4 } ${ p [ 1 ] - 4 } ${ p [ 2 ] - dx / 4 } ${ p [ 1 ] - 4 } ${ p [ 2 ] } ${ p [ 1 ] } ` ;
388391 }
389392 function note2number ( note )
390393 {
0 commit comments