@@ -3,6 +3,8 @@ import { Screen } from '@nativescript/core/platform';
3
3
import { Align , Canvas , FontMetrics , Paint , Rect , StaticLayout } from '@nativescript-community/ui-canvas' ;
4
4
import { DefaultValueFormatter } from '../formatter/DefaultValueFormatter' ;
5
5
import { ValueFormatter } from '../formatter/ValueFormatter' ;
6
+ import Shape from '@nativescript-community/ui-canvas/shapes/shape' ;
7
+ import { Chart } from '../charts/Chart' ;
6
8
7
9
export type FloatArray = Float32Array | Float64Array ;
8
10
export let FloatConstructor : typeof Float32Array | typeof Float64Array ;
@@ -12,7 +14,6 @@ if (global.isAndroid) {
12
14
FloatConstructor = interop . sizeof ( interop . types . id ) === 4 ? Float32Array : Float64Array ;
13
15
}
14
16
15
-
16
17
let SDK_INT = - 1 ;
17
18
function getSDK ( ) {
18
19
if ( SDK_INT === - 1 ) {
@@ -462,10 +463,21 @@ export namespace Utils {
462
463
// canvas.restore();
463
464
// }
464
465
465
- export function drawImage ( canvas : Canvas , icon : ImageSource , x , y ) {
466
- const drawOffsetX = x - icon . width / 2 ;
467
- const drawOffsetY = y - icon . height / 2 ;
468
- canvas . drawBitmap ( global . isAndroid ? icon . android : icon , drawOffsetX , drawOffsetY , null ) ;
466
+ export function drawIcon ( canvas : Canvas , chart : Chart < any , any , any > , icon : ImageSource | Shape , x , y ) {
467
+ if ( icon instanceof Shape ) {
468
+ const availableWidth = canvas . getWidth ( ) ;
469
+ const availableHeight = canvas . getHeight ( ) ;
470
+ const width = icon . getWidth ( availableWidth , availableHeight ) ;
471
+ const height = icon . getHeight ( availableWidth , availableHeight ) ;
472
+ canvas . save ( ) ;
473
+ canvas . translate ( x - width / 2 , y - height / 2 ) ;
474
+ icon . drawMyShapeOnCanvas ( canvas , chart , availableWidth , availableHeight ) ;
475
+ canvas . restore ( ) ;
476
+ } else {
477
+ const drawOffsetX = x - icon . width / 2 ;
478
+ const drawOffsetY = y - icon . height / 2 ;
479
+ canvas . drawBitmap ( global . isAndroid ? icon . android : icon , drawOffsetX , drawOffsetY , null ) ;
480
+ }
469
481
}
470
482
471
483
export function drawXAxisValue ( c : Canvas , text , x , y , paint : Paint , anchor , angleDegrees ) {
@@ -624,7 +636,6 @@ export namespace Utils {
624
636
} ;
625
637
}
626
638
627
-
628
639
export function logMethod ( target , key , descriptor ) {
629
640
// save a reference to the original method this way we keep the values currently in the
630
641
// descriptor and don't overwrite what another decorator might have done to the descriptor.
0 commit comments