@@ -23,11 +23,15 @@ import { AnimatedMoveViewJob } from '../jobs/AnimatedMoveViewJob';
23
23
import { AnimatedZoomJob } from '../jobs/AnimatedZoomJob' ;
24
24
import { ZoomJob } from '../jobs/ZoomJob' ;
25
25
import { BarLineChartTouchListener } from '../listener/BarLineChartTouchListener' ;
26
+ import { getEventOrGestureName , EventData , Observable } from '@nativescript/core/ui/page/page' ;
27
+ import { GestureTypes , fromString as gestureFromString } from '@nativescript/core/ui/gestures/gestures' ;
26
28
27
29
const LOG_TAG = 'BarLineChartBase' ;
28
30
29
31
export abstract class BarLineChartBase < U extends Entry , D extends IBarLineScatterCandleBubbleDataSet < U > , T extends BarLineScatterCandleBubbleData < U , D > > extends Chart < U , D , T >
30
32
implements BarLineScatterCandleBubbleDataProvider {
33
+ protected mChartTouchListener : BarLineChartTouchListener ;
34
+
31
35
/**
32
36
* the maximum number of entries to which values will be drawn
33
37
* (entry numbers greater than this value will cause value-labels to disappear)
@@ -49,22 +53,22 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
49
53
/**
50
54
* flag that indicates if double tap zoom is enabled or not
51
55
*/
52
- protected mDoubleTapToZoomEnabled = true ;
56
+ protected mDoubleTapToZoomEnabled = false ;
53
57
54
58
/**
55
59
* flag that indicates if highlighting per dragging over a fully zoomed out
56
60
* chart is enabled
57
61
*/
58
- protected mHighlightPerDragEnabled = true ;
62
+ protected mHighlightPerDragEnabled = false ;
59
63
60
64
/**
61
65
* if true, dragging is enabled for the chart
62
66
*/
63
- private mDragXEnabled = true ;
64
- private mDragYEnabled = true ;
67
+ private mDragXEnabled = false ;
68
+ private mDragYEnabled = false ;
65
69
66
- private mScaleXEnabled = true ;
67
- private mScaleYEnabled = true ;
70
+ private mScaleXEnabled = false ;
71
+ private mScaleYEnabled = false ;
68
72
69
73
/**
70
74
* palet object for the (by default) lightgrey background of the grid
@@ -134,7 +138,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
134
138
135
139
this . setHighlighter ( new ChartHighlighter ( this ) ) ;
136
140
137
- this . mChartTouchListener = new BarLineChartTouchListener ( this , this . mViewPortHandler . getMatrixTouch ( ) , 3 ) ;
141
+ // this.mChartTouchListener = new BarLineChartTouchListener(this, this.mViewPortHandler.getMatrixTouch(), 3);
138
142
139
143
this . mGridBackgroundPaint = new Paint ( ) ;
140
144
this . mGridBackgroundPaint . setStyle ( Style . FILL ) ;
@@ -148,6 +152,16 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
148
152
this . mBorderPaint . setStrokeWidth ( Utils . convertDpToPixel ( 1 ) ) ;
149
153
}
150
154
155
+ getOrCreateBarTouchListener ( ) {
156
+ if ( ! this . mChartTouchListener ) {
157
+ this . mChartTouchListener = new BarLineChartTouchListener ( this , this . mViewPortHandler . getMatrixTouch ( ) , 3 ) ;
158
+ if ( ! ! this . nativeViewProtected ) {
159
+ this . mChartTouchListener . init ( ) ;
160
+ }
161
+ }
162
+ return this . mChartTouchListener ;
163
+ }
164
+
151
165
// for performance tracking
152
166
private totalTime = 0 ;
153
167
private drawCycles = 0 ;
@@ -256,7 +270,9 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
256
270
}
257
271
258
272
protected prepareValuePxMatrix ( ) {
259
- if ( this . mLogEnabled ) console . log ( LOG_TAG , 'Preparing Value-Px Matrix, xmin: ' + this . mXAxis . mAxisMinimum + ', xmax: ' + this . mXAxis . mAxisMaximum + ', xdelta: ' + this . mXAxis . mAxisRange ) ;
273
+ if ( this . mLogEnabled ) {
274
+ console . log ( LOG_TAG , 'Preparing Value-Px Matrix, xmin: ' + this . mXAxis . mAxisMinimum + ', xmax: ' + this . mXAxis . mAxisMaximum + ', xdelta: ' + this . mXAxis . mAxisRange ) ;
275
+ }
260
276
261
277
this . mRightAxisTransformer . prepareMatrixValuePx ( this . mXAxis . mAxisMinimum , this . mXAxis . mAxisRange , this . mAxisRight . mAxisRange , this . mAxisRight . mAxisMinimum ) ;
262
278
this . mLeftAxisTransformer . prepareMatrixValuePx ( this . mXAxis . mAxisMinimum , this . mXAxis . mAxisRange , this . mAxisLeft . mAxisRange , this . mAxisLeft . mAxisMinimum ) ;
@@ -269,13 +285,19 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
269
285
270
286
public notifyDataSetChanged ( ) {
271
287
if ( this . mData == null ) {
272
- if ( this . mLogEnabled ) console . log ( LOG_TAG , 'Preparing... DATA NOT SET.' ) ;
288
+ if ( this . mLogEnabled ) {
289
+ console . log ( LOG_TAG , 'Preparing... DATA NOT SET.' ) ;
290
+ }
273
291
return ;
274
292
} else if ( ! this . mViewPortHandler . hasChartDimens ( ) ) {
275
- if ( this . mLogEnabled ) console . log ( LOG_TAG , 'Preparing... NOT SIZED YET.' ) ;
293
+ if ( this . mLogEnabled ) {
294
+ console . log ( LOG_TAG , 'Preparing... NOT SIZED YET.' ) ;
295
+ }
276
296
return ;
277
297
} else {
278
- if ( this . mLogEnabled ) console . log ( LOG_TAG , 'Preparing...' ) ;
298
+ if ( this . mLogEnabled ) {
299
+ console . log ( LOG_TAG , 'Preparing...' ) ;
300
+ }
279
301
}
280
302
281
303
if ( this . mRenderer != null ) this . mRenderer . initBuffers ( ) ;
@@ -393,7 +415,6 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
393
415
offsetRight += this . mOffsetsBuffer . right ;
394
416
offsetBottom += this . mOffsetsBuffer . bottom ;
395
417
396
-
397
418
// offsets for y-labels
398
419
if ( this . mAxisLeft . needsOffset ( ) ) {
399
420
offsetLeft += this . mAxisLeft . getRequiredWidthSpace ( this . mAxisRendererLeft . getPaintAxisLabels ( ) ) ;
@@ -476,8 +497,8 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
476
497
// }
477
498
478
499
// public computeScroll() {
479
- // if (this.mChartTouchListener instanceof BarLineChartTouchListener)
480
- // (this.mChartTouchListener).computeScroll();
500
+ // if (this.mChartTouchListener instanceof BarLineChartTouchListener)
501
+ // (this.mChartTouchListener).computeScroll();
481
502
// }
482
503
483
504
/**
@@ -1054,6 +1075,11 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
1054
1075
*/
1055
1076
public setDoubleTapToZoomEnabled ( enabled ) {
1056
1077
this . mDoubleTapToZoomEnabled = enabled ;
1078
+ if ( enabled ) {
1079
+ this . getOrCreateBarTouchListener ( ) . setDoubleTap ( true ) ;
1080
+ } else if ( this . mChartTouchListener ) {
1081
+ this . mChartTouchListener . setDoubleTap ( false ) ;
1082
+ }
1057
1083
}
1058
1084
1059
1085
/**
@@ -1217,7 +1243,6 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
1217
1243
* @return
1218
1244
*/
1219
1245
public getDataSetByTouchPoint ( x , y ) {
1220
- console . log ( 'getDataSetByTouchPoint' , x , y ) ;
1221
1246
const h = this . getHighlightByTouchPoint ( x , y ) ;
1222
1247
if ( h != null ) {
1223
1248
return this . mData . getDataSetByIndex ( h . dataSetIndex ) ;
@@ -1482,7 +1507,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
1482
1507
1483
1508
protected mOnSizeChangedBuffer = Utils . createNativeArray ( 2 ) ;
1484
1509
1485
- public onSizeChanged ( w : number , h : number , oldw :number , oldh :number ) {
1510
+ public onSizeChanged ( w : number , h : number , oldw : number , oldh : number ) {
1486
1511
// Saving current position of chart.
1487
1512
this . mOnSizeChangedBuffer [ 0 ] = this . mOnSizeChangedBuffer [ 1 ] = 0 ;
1488
1513
@@ -1504,4 +1529,58 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
1504
1529
this . mViewPortHandler . refresh ( this . mViewPortHandler . getMatrixTouch ( ) , this , false ) ;
1505
1530
}
1506
1531
}
1532
+
1533
+ public addEventListener ( arg : string | GestureTypes , callback : ( data : EventData ) => void , thisArg ?: any ) {
1534
+ if ( typeof arg === 'number' ) {
1535
+ arg = GestureTypes [ arg ] ;
1536
+ }
1537
+ if ( typeof arg === 'string' ) {
1538
+ arg = getEventOrGestureName ( arg ) ;
1539
+ let events = arg . split ( ',' ) ;
1540
+ if ( events . length > 0 ) {
1541
+ for ( let i = 0 ; i < events . length ; i ++ ) {
1542
+ let evt = events [ i ] . trim ( ) ;
1543
+ if ( arg === 'tap' ) {
1544
+ this . getOrCreateBarTouchListener ( ) . setTap ( true ) ;
1545
+ } else if ( arg === 'doubleTap' ) {
1546
+ this . getOrCreateBarTouchListener ( ) . setDoubleTap ( true ) ;
1547
+ } else if ( arg === 'pan' ) {
1548
+ this . getOrCreateBarTouchListener ( ) . setPan ( true ) ;
1549
+ } else if ( arg === 'pinch' ) {
1550
+ this . getOrCreateBarTouchListener ( ) . setPinch ( true ) ;
1551
+ }
1552
+ Observable . prototype . addEventListener . call ( this , evt , callback , thisArg ) ;
1553
+ }
1554
+ } else {
1555
+ Observable . prototype . addEventListener . call ( this , arg , callback , thisArg ) ;
1556
+ }
1557
+ }
1558
+ }
1559
+
1560
+ public removeEventListener ( arg : string | GestureTypes , callback ?: any , thisArg ?: any ) {
1561
+ if ( typeof arg === 'number' ) {
1562
+ arg = GestureTypes [ arg ] ;
1563
+ }
1564
+ if ( typeof arg === 'string' ) {
1565
+ arg = getEventOrGestureName ( arg ) ;
1566
+ let events = arg . split ( ',' ) ;
1567
+ if ( events . length > 0 ) {
1568
+ for ( let i = 0 ; i < events . length ; i ++ ) {
1569
+ let evt = events [ i ] . trim ( ) ;
1570
+ if ( arg === 'tap' && ! this . isHighlightPerTapEnabled ( ) ) {
1571
+ this . getOrCreateBarTouchListener ( ) . setTap ( false ) ;
1572
+ } else if ( arg === 'doubleTap' && ! this . isDoubleTapToZoomEnabled ( ) ) {
1573
+ this . getOrCreateBarTouchListener ( ) . setDoubleTap ( false ) ;
1574
+ } else if ( arg === 'pan' && ! this . isHighlightPerDragEnabled ( ) && ! this . isDragEnabled ( ) ) {
1575
+ this . getOrCreateBarTouchListener ( ) . setPan ( false ) ;
1576
+ } else if ( arg === 'pinch' && ! this . isPinchZoomEnabled ( ) ) {
1577
+ this . getOrCreateBarTouchListener ( ) . setPinch ( false ) ;
1578
+ }
1579
+ Observable . prototype . removeEventListener . call ( this , evt , callback , thisArg ) ;
1580
+ }
1581
+ } else {
1582
+ Observable . prototype . removeEventListener . call ( this , arg , callback , thisArg ) ;
1583
+ }
1584
+ }
1585
+ }
1507
1586
}
0 commit comments