@@ -6,6 +6,7 @@ import { Chart } from '../../../src/chart/chart';
66import { ChartSeriesType , ChartRangePadding , ValueType , LabelPlacement , } from '../../../src/chart/utils/enum' ;
77import { LineSeries } from '../../../src/chart/series/line-series' ;
88import { ColumnSeries } from '../../../src/chart/series/column-series' ;
9+ import { AreaSeries } from '../../../src/chart/series/area-series' ;
910import { Crosshair } from '../../../src/chart/user-interaction/crosshair' ;
1011import { Tooltip } from '../../../src/chart/user-interaction/tooltip' ;
1112
@@ -20,7 +21,7 @@ import { EmitType } from '@syncfusion/ej2-base';
2021import { profile , inMB , getMemoryProfile } from '../../common.spec' ;
2122import { ILoadedEventArgs , } from '../../../src/chart/model/chart-interface' ;
2223Chart . Inject ( LineSeries , ColumnSeries , DateTime , Category , Tooltip , DataEditing ) ;
23- Chart . Inject ( Crosshair ) ;
24+ Chart . Inject ( Crosshair , AreaSeries ) ;
2425
2526
2627describe ( 'Chart Crosshair' , ( ) => {
@@ -578,6 +579,115 @@ describe('Chart Crosshair', () => {
578579 chartObj . refresh ( ) ;
579580 } ) ;
580581 } ) ;
582+
583+ describe ( 'Crosshair customization' , ( ) => {
584+ let chartObj : Chart ; let x : number ; let y : number ;
585+ let loaded : EmitType < ILoadedEventArgs > ;
586+ let trigger : MouseEvents = new MouseEvents ( ) ;
587+ let elem : HTMLElement = createElement ( 'div' , { id : 'crosshairContainer' } ) ;
588+ let series1 : Object [ ] = [ ] ;
589+ let point1 : Object ;
590+ let value : number = 80 ;
591+ let i : number ;
592+ for ( i = 1 ; i < 500 ; i ++ ) {
593+ if ( Math . random ( ) > .5 ) {
594+ value += Math . random ( ) ;
595+ } else {
596+ value -= Math . random ( ) ;
597+ }
598+ point1 = { x : new Date ( 1910 , i + 2 , i ) , y : value . toFixed ( 1 ) } ;
599+ series1 . push ( point1 ) ;
600+ }
601+ beforeAll ( ( ) => {
602+ document . body . appendChild ( elem ) ;
603+ chartObj = new Chart (
604+ {
605+ //Initializing Primary X Axis
606+ primaryXAxis : {
607+ majorGridLines : { width : 0 } ,
608+ valueType : 'DateTime' ,
609+ crosshairTooltip : { enable : true } ,
610+ } ,
611+ primaryYAxis :
612+ {
613+ minimum : 83 , maximum : 95 , interval : 1 ,
614+ title : 'Millions in USD' ,
615+ labelFormat : '{value}M' ,
616+ rowIndex : 0 ,
617+ crosshairTooltip : {
618+ enable : true
619+ }
620+ } ,
621+
622+ //Initializing Chart Series
623+ series : [
624+ {
625+ type : 'Area' ,
626+ dataSource : series1 ,
627+ name : 'Product X' ,
628+ xName : 'x' ,
629+ yName : 'y' ,
630+ border : { width : 0.5 , color : 'black' } ,
631+ } ,
632+ ] ,
633+ //Initializing Zooming
634+
635+ //Initializing Chart title
636+ title : 'Sales History of Product X' ,
637+ crosshair : { enable : true } ,
638+ } ) ;
639+ chartObj . appendTo ( '#crosshairContainer' ) ;
640+
641+ } ) ;
642+ afterAll ( ( ) : void => {
643+ chartObj . destroy ( ) ;
644+ elem . remove ( ) ;
645+ } ) ;
646+
647+ it ( 'X axis crosshair opacity checking' , ( done : Function ) => {
648+ loaded = ( args : Object ) : void => {
649+ let chartArea : HTMLElement = document . getElementById ( 'crosshairContainer_ChartAreaBorder' ) ;
650+ y = parseFloat ( chartArea . getAttribute ( 'y' ) ) + parseFloat ( chartArea . getAttribute ( 'height' ) ) / 4 + elem . offsetTop ;
651+ x = parseFloat ( chartArea . getAttribute ( 'x' ) ) + parseFloat ( chartArea . getAttribute ( 'width' ) ) / 4 + elem . offsetLeft ;
652+ trigger . mousemovetEvent ( chartArea , Math . ceil ( x ) , Math . ceil ( y ) ) ;
653+ let crosshair : Element = < Element > document . getElementById ( 'crosshairContainer_svg' ) . lastChild ;
654+ let element1 : HTMLElement ;
655+ let element2 : HTMLElement ;
656+ expect ( crosshair . childNodes . length == 3 || crosshair . childNodes . length == 2 ) . toBe ( true ) ;
657+ element1 = < HTMLElement > crosshair . childNodes [ 0 ] ;
658+ expect ( element1 . getAttribute ( 'opacity' ) == '0.5' || element1 . getAttribute ( 'opacity' ) == '1' ) . toBe ( true ) ;
659+ element2 = < HTMLElement > crosshair . childNodes [ 1 ] ;
660+ expect ( element2 . getAttribute ( 'opacity' ) == '0.5' || element2 . getAttribute ( 'opacity' ) == null ) . toBe ( true ) ;
661+ done ( ) ;
662+ } ;
663+ chartObj . crosshair . opacity = 0.5 ;
664+ chartObj . loaded = loaded ;
665+ chartObj . refresh ( ) ;
666+ } ) ;
667+
668+ it ( 'Customizing crosshair color' , ( done : Function ) => {
669+ loaded = ( args : Object ) : void => {
670+ let chartArea : HTMLElement = document . getElementById ( 'crosshairContainer_ChartAreaBorder' ) ;
671+ y = parseFloat ( chartArea . getAttribute ( 'y' ) ) + parseFloat ( chartArea . getAttribute ( 'height' ) ) / 4 + elem . offsetTop ;
672+ x = parseFloat ( chartArea . getAttribute ( 'x' ) ) + parseFloat ( chartArea . getAttribute ( 'width' ) ) / 4 + elem . offsetLeft ;
673+ trigger . mousemovetEvent ( chartArea , Math . ceil ( x ) , Math . ceil ( y ) ) ;
674+ let crosshair : Element = < Element > document . getElementById ( 'crosshairContainer_svg' ) . lastChild ;
675+ let element1 : HTMLElement ;
676+ let element2 : HTMLElement ;
677+ expect ( crosshair . childNodes . length == 3 || crosshair . childNodes . length == 2 ) . toBe ( true ) ;
678+ element1 = < HTMLElement > crosshair . childNodes [ 0 ] ;
679+ element2 = < HTMLElement > crosshair . childNodes [ 1 ] ;
680+ expect ( element1 . getAttribute ( 'fill' ) == 'red' || element1 . getAttribute ( 'fill' ) == 'transparent' ) . toBe ( true ) ;
681+ expect ( element2 . getAttribute ( 'fill' ) == 'green' || element2 . getAttribute ( 'fill' ) == null ) . toBe ( true ) ;
682+ done ( ) ;
683+ } ;
684+ chartObj . crosshair . horizontalColor = 'red' ;
685+ chartObj . crosshair . verticalColor = 'green' ;
686+ chartObj . loaded = loaded ;
687+ chartObj . refresh ( ) ;
688+ } ) ;
689+ } ) ;
690+
581691 it ( 'memory leak' , ( ) => {
582692 profile . sample ( ) ;
583693 let average : any = inMB ( profile . averageChange )
0 commit comments