|
1 | 1 | import * as util from '../../../util/index.mjs'; |
2 | 2 | import * as math from '../../../math.mjs'; |
| 3 | +import { labelHalign, labelValign } from '../../../style/align.mjs'; |
3 | 4 |
|
4 | 5 | let CRp = {}; |
5 | 6 |
|
@@ -233,7 +234,10 @@ CRp.drawText = function( context, ele, prefix, applyRotation = true, useEleOpaci |
233 | 234 | textY = 0; |
234 | 235 | } |
235 | 236 |
|
236 | | - switch( valign ){ |
| 237 | + let boxHalign = labelHalign( halign ); |
| 238 | + let boxValign = labelValign( valign ); |
| 239 | + |
| 240 | + switch( boxValign ){ |
237 | 241 | case 'top': |
238 | 242 | break; |
239 | 243 | case 'center': |
@@ -266,7 +270,7 @@ CRp.drawText = function( context, ele, prefix, applyRotation = true, useEleOpaci |
266 | 270 | let doStroke = textBorderWidth > 0 && borderOpacity > 0; |
267 | 271 |
|
268 | 272 | let bgX = textX - backgroundPadding; |
269 | | - switch( halign ){ |
| 273 | + switch( boxHalign ){ |
270 | 274 | case 'left': bgX -= textW; break; |
271 | 275 | case 'center': bgX -= textW / 2; break; |
272 | 276 | } |
@@ -344,27 +348,27 @@ CRp.drawText = function( context, ele, prefix, applyRotation = true, useEleOpaci |
344 | 348 |
|
345 | 349 | if( justification === 'auto' ){ |
346 | 350 | // then it's already ok, so skip all the other ifs |
347 | | - } else if( halign === 'left' ){ // auto justification : right |
| 351 | + } else if( boxHalign === 'left' ){ // auto justification : right |
348 | 352 | if( justification === 'left' ){ |
349 | 353 | textX += -textW; |
350 | 354 | } else if( justification === 'center' ){ |
351 | 355 | textX += -halfTextW; |
352 | 356 | } // else same as auto |
353 | | - } else if( halign === 'center' ){ // auto justfication : center |
| 357 | + } else if( boxHalign === 'center' ){ // auto justfication : center |
354 | 358 | if( justification === 'left' ){ |
355 | 359 | textX += -halfTextW; |
356 | 360 | } else if( justification === 'right' ){ |
357 | 361 | textX += halfTextW; |
358 | 362 | } // else same as auto |
359 | | - } else if( halign === 'right' ){ // auto justification : left |
| 363 | + } else if( boxHalign === 'right' ){ // auto justification : left |
360 | 364 | if( justification === 'center' ){ |
361 | 365 | textX += halfTextW; |
362 | 366 | } else if( justification === 'right' ){ |
363 | 367 | textX += textW; |
364 | 368 | } // else same as auto |
365 | 369 | } |
366 | 370 |
|
367 | | - switch( valign ){ |
| 371 | + switch( boxValign ){ |
368 | 372 | case 'top': |
369 | 373 | textY -= ( lines.length - 1 ) * lineHeight; |
370 | 374 | break; |
|
0 commit comments