@@ -381,6 +381,31 @@ export class BarSeries<T extends IBarSeriesSpec = IBarSeriesSpec> extends Cartes
381
381
return this . dataToPositionY1 ( datum ) ;
382
382
}
383
383
384
+ protected _getLinearBarRange = ( x : number , x1 : number ) => {
385
+ const realBarWidth = x1 - x ;
386
+ if ( this . _spec . barPadding ) {
387
+ const tempX = x + this . _spec . barPadding ;
388
+ const tempX1 = x1 - this . _spec . barPadding ;
389
+ if ( tempX < tempX1 ) {
390
+ x = tempX ;
391
+ x1 = tempX1 ;
392
+ }
393
+ }
394
+
395
+ const curBarWidth = x1 - x ;
396
+ if ( this . _spec . barMinWidth ) {
397
+ const barMinWidth = getActualNumValue ( this . _spec . barMinWidth , realBarWidth ) ;
398
+ if ( curBarWidth < barMinWidth ) {
399
+ const widthDiff = barMinWidth - curBarWidth ;
400
+ const halfWidthDiff = widthDiff / 2 ;
401
+ x -= halfWidthDiff ;
402
+ x1 += halfWidthDiff ;
403
+ }
404
+ }
405
+
406
+ return [ x , x1 ] ;
407
+ } ;
408
+
384
409
protected _getBarXStart = ( datum : Datum , scale : IBaseScale , useWholeRange ?: boolean ) => {
385
410
if ( this . _shouldDoPreCalculate ( ) ) {
386
411
this . _calculateStackRectPosition ( false ) ;
@@ -403,6 +428,12 @@ export class BarSeries<T extends IBarSeriesSpec = IBarSeriesSpec> extends Cartes
403
428
return valueInScaleRange ( this . _dataToPosX1 ( datum ) , scale , useWholeRange ) ;
404
429
} ;
405
430
431
+ protected _getLinearBarXRange = ( datum : Datum , scale : IBaseScale , useWholeRange ?: boolean ) => {
432
+ const x = valueInScaleRange ( this . _dataToPosX ( datum ) , scale , useWholeRange ) ;
433
+ const x1 = valueInScaleRange ( this . _dataToPosX1 ( datum ) , scale , useWholeRange ) ;
434
+ return this . _getLinearBarRange ( Math . min ( x , x1 ) , Math . max ( x , x1 ) ) ;
435
+ } ;
436
+
406
437
protected _getBarYStart = ( datum : Datum , scale : IBaseScale ) => {
407
438
if ( this . _shouldDoPreCalculate ( ) ) {
408
439
this . _calculateStackRectPosition ( true ) ;
@@ -425,6 +456,12 @@ export class BarSeries<T extends IBarSeriesSpec = IBarSeriesSpec> extends Cartes
425
456
return valueInScaleRange ( this . _dataToPosY1 ( datum ) , scale ) ;
426
457
} ;
427
458
459
+ protected _getLinearBarYRange = ( datum : Datum , scale : IBaseScale , useWholeRange ?: boolean ) => {
460
+ const y = valueInScaleRange ( this . _dataToPosX ( datum ) , scale , useWholeRange ) ;
461
+ const y1 = valueInScaleRange ( this . _dataToPosX1 ( datum ) , scale , useWholeRange ) ;
462
+ return this . _getLinearBarRange ( Math . min ( y , y1 ) , Math . max ( y , y1 ) ) ;
463
+ } ;
464
+
428
465
initBandRectMarkStyle ( ) {
429
466
const xScale = this . _xAxisHelper ?. getScale ?.( 0 ) ;
430
467
const yScale = this . _yAxisHelper ?. getScale ?.( 0 ) ;
@@ -543,8 +580,8 @@ export class BarSeries<T extends IBarSeriesSpec = IBarSeriesSpec> extends Cartes
543
580
if ( this . direction === Direction . horizontal ) {
544
581
const yChannels = isValid ( this . _fieldY2 )
545
582
? {
546
- y : ( datum : Datum ) => valueInScaleRange ( this . _dataToPosY ( datum ) , yScale , true ) ,
547
- y1 : ( datum : Datum ) => valueInScaleRange ( this . _dataToPosY1 ( datum ) , yScale , true )
583
+ y : ( datum : Datum ) => this . _getLinearBarYRange ( datum , yScale , true ) [ 0 ] ,
584
+ y1 : ( datum : Datum ) => this . _getLinearBarYRange ( datum , yScale , true ) [ 1 ]
548
585
}
549
586
: {
550
587
y : ( datum : Datum ) =>
@@ -575,8 +612,8 @@ export class BarSeries<T extends IBarSeriesSpec = IBarSeriesSpec> extends Cartes
575
612
} else {
576
613
const xChannels = isValid ( this . _fieldX2 )
577
614
? {
578
- x : ( datum : Datum ) => valueInScaleRange ( this . _dataToPosX ( datum ) , xScale , true ) ,
579
- x1 : ( datum : Datum ) => valueInScaleRange ( this . _dataToPosX1 ( datum ) , xScale , true )
615
+ x : ( datum : Datum ) => this . _getLinearBarXRange ( datum , xScale , true ) [ 0 ] ,
616
+ x1 : ( datum : Datum ) => this . _getLinearBarXRange ( datum , xScale , true ) [ 1 ]
580
617
}
581
618
: {
582
619
x : ( datum : Datum ) =>
0 commit comments