@@ -355,15 +355,11 @@ export default class ZoomPanSelection extends Toolbar {
355
355
} )
356
356
. resize ( )
357
357
. on ( 'resize' , ( ) => {
358
- // clearTimeout(this.w.globals.selectionResizeTimer)
359
- // this.w.globals.selectionResizeTimer = window.setTimeout(() => {
360
- // timer commented for now as performance drop is negligible
361
358
let zoomtype = w . globals . zoomEnabled
362
359
? w . config . chart . zoom . type
363
360
: w . config . chart . selection . type
364
361
365
362
this . handleMouseUp ( { zoomtype, isResized : true } )
366
- //}, 50)
367
363
} )
368
364
}
369
365
}
@@ -397,7 +393,7 @@ export default class ZoomPanSelection extends Toolbar {
397
393
x
398
394
if ( w . globals . isRangeBar ) {
399
395
// rangebars put datetime data in y axis
400
- x = // calculation: (selection left time - chart left time) / milliseconds per pixel = selection X value in pixels
396
+ x =
401
397
( w . config . chart . selection . xaxis . min -
402
398
w . globals . yAxisScale [ 0 ] . niceMin ) /
403
399
xyRatios . invertedYRatio
@@ -630,7 +626,7 @@ export default class ZoomPanSelection extends Toolbar {
630
626
let minX , maxX , minY , maxY
631
627
632
628
if ( ! w . globals . isRangeBar ) {
633
- // original code is in the IF. rangeBar exception is in the ELSE.
629
+ // normal XY charts
634
630
minX =
635
631
w . globals . xAxisScale . niceMin +
636
632
( selectionRect . left - gridRectDim . left ) * xyRatios . xRatio
@@ -645,15 +641,15 @@ export default class ZoomPanSelection extends Toolbar {
645
641
w . globals . yAxisScale [ 0 ] . niceMax -
646
642
( selectionRect . top - gridRectDim . top ) * xyRatios . yRatio [ 0 ]
647
643
} else {
648
- // rangeBars use x as the category, and y as the datetime data. // find data in y axis and use Y ratio
644
+ // rangeBars use y for datetime
649
645
minX =
650
646
w . globals . yAxisScale [ 0 ] . niceMin +
651
647
( selectionRect . left - gridRectDim . left ) * xyRatios . invertedYRatio
652
648
maxX =
653
649
w . globals . yAxisScale [ 0 ] . niceMin +
654
650
( selectionRect . right - gridRectDim . left ) * xyRatios . invertedYRatio
655
651
656
- minY = 0 // there is no y min/max with rangebars (it uses categories, not numeric data), so use dummy values
652
+ minY = 0
657
653
maxY = 1
658
654
}
659
655
@@ -685,48 +681,51 @@ export default class ZoomPanSelection extends Toolbar {
685
681
const xyRatios = this . xyRatios
686
682
const toolbar = this . ctx . toolbar
687
683
688
- if ( me . startX > me . endX ) {
689
- let tempX = me . startX
690
- me . startX = me . endX
691
- me . endX = tempX
692
- }
693
- if ( me . startY > me . endY ) {
694
- let tempY = me . startY
695
- me . startY = me . endY
696
- me . endY = tempY
697
- }
684
+ // Use boundingRect for final selection area
685
+ const selRect = me . selectionRect . node . getBoundingClientRect ( )
686
+ const gridRectDim = me . gridRect . getBoundingClientRect ( )
698
687
699
- let xLowestValue = undefined
700
- let xHighestValue = undefined
688
+ // Local coords in the chart's grid
689
+ const localStartX =
690
+ selRect . left - gridRectDim . left - w . globals . barPadForNumericAxis
691
+ const localEndX =
692
+ selRect . right - gridRectDim . left - w . globals . barPadForNumericAxis
693
+ const localStartY = selRect . top - gridRectDim . top
694
+ const localEndY = selRect . bottom - gridRectDim . top
695
+
696
+ // Convert those local coords to actual data values
697
+ let xLowestValue , xHighestValue
701
698
702
699
if ( ! w . globals . isRangeBar ) {
703
- xLowestValue = w . globals . xAxisScale . niceMin + me . startX * xyRatios . xRatio
704
- xHighestValue = w . globals . xAxisScale . niceMin + me . endX * xyRatios . xRatio
700
+ xLowestValue =
701
+ w . globals . xAxisScale . niceMin + localStartX * xyRatios . xRatio
702
+ xHighestValue = w . globals . xAxisScale . niceMin + localEndX * xyRatios . xRatio
705
703
} else {
706
704
xLowestValue =
707
- w . globals . yAxisScale [ 0 ] . niceMin + me . startX * xyRatios . invertedYRatio
705
+ w . globals . yAxisScale [ 0 ] . niceMin + localStartX * xyRatios . invertedYRatio
708
706
xHighestValue =
709
- w . globals . yAxisScale [ 0 ] . niceMin + me . endX * xyRatios . invertedYRatio
707
+ w . globals . yAxisScale [ 0 ] . niceMin + localEndX * xyRatios . invertedYRatio
710
708
}
711
709
712
- // TODO: we will consider the 1st y axis values here for getting highest and lowest y
710
+ // For Y values, pick from the first y- axis, but handle multi-axis
713
711
let yHighestValue = [ ]
714
712
let yLowestValue = [ ]
715
713
716
714
w . config . yaxis . forEach ( ( yaxe , index ) => {
717
- // We can use the index of any series referenced by the Yaxis
718
- // because they will all return the same value, so we choose the first.
715
+ // pick whichever series is mapped to this y-axis
719
716
let seriesIndex = w . globals . seriesYAxisMap [ index ] [ 0 ]
720
- yHighestValue . push (
717
+ let highestVal =
721
718
w . globals . yAxisScale [ index ] . niceMax -
722
- xyRatios . yRatio [ seriesIndex ] * me . startY
723
- )
724
- yLowestValue . push (
719
+ xyRatios . yRatio [ seriesIndex ] * localStartY
720
+ let lowestVal =
725
721
w . globals . yAxisScale [ index ] . niceMax -
726
- xyRatios . yRatio [ seriesIndex ] * me . endY
727
- )
722
+ xyRatios . yRatio [ seriesIndex ] * localEndY
723
+
724
+ yHighestValue . push ( highestVal )
725
+ yLowestValue . push ( lowestVal )
728
726
} )
729
727
728
+ // Only apply if user actually dragged far enough to consider it a selection
730
729
if (
731
730
me . dragged &&
732
731
( me . dragX > 10 || me . dragY > 10 ) &&
@@ -828,7 +827,7 @@ export default class ZoomPanSelection extends Toolbar {
828
827
const deltaX = w . globals . lastClientPosition . x - me . clientX
829
828
const deltaY = w . globals . lastClientPosition . y - me . clientY
830
829
831
- // check which direction had the highest amplitude and then figure out direction by checking if the value is greater or less than zero
830
+ // check which direction had the highest amplitude
832
831
if ( Math . abs ( deltaX ) > Math . abs ( deltaY ) && deltaX > 0 ) {
833
832
this . moveDirection = 'left'
834
833
} else if ( Math . abs ( deltaX ) > Math . abs ( deltaY ) && deltaX < 0 ) {
@@ -850,7 +849,7 @@ export default class ZoomPanSelection extends Toolbar {
850
849
851
850
let xHighestValue = w . globals . isRangeBar ? w . globals . maxY : w . globals . maxX
852
851
853
- // on a category, we don't pan continuosly as it causes bugs
852
+ // on a category, we don't pan continuously as it causes bugs
854
853
if ( ! w . config . xaxis . convertedCatToNumeric ) {
855
854
me . panScrolled ( xLowestValue , xHighestValue )
856
855
}
0 commit comments