1- import dh , {
1+ import type {
22 Axis ,
3+ AxisFormatType ,
4+ AxisPosition ,
5+ AxisType ,
36 Chart ,
7+ dh as DhType ,
48 Figure ,
59 Series ,
610 SeriesDataSource ,
7- } from '@deephaven/jsapi-shim ' ;
11+ } from '@deephaven/jsapi-types ' ;
812
913class ChartTestUtils {
1014 static DEFAULT_CHART_TITLE = 'Chart Title' ;
@@ -15,73 +19,85 @@ class ChartTestUtils {
1519
1620 static DEFAULT_SERIES_NAME = 'MySeries' ;
1721
18- static makeAxis ( {
22+ private dh : DhType ;
23+
24+ constructor ( dh : DhType ) {
25+ this . dh = dh ;
26+ }
27+
28+ makeAxis ( {
1929 label = 'Axis' ,
20- type = dh . plot . AxisType . X ,
21- position = dh . plot . AxisPosition . BOTTOM ,
22- formatType = dh . Axis . FORMAT_TYPE_NUMBER ,
30+ type = undefined ,
31+ position = undefined ,
32+ formatType = undefined ,
2333 formatPattern = '###,###0.00' ,
2434 log = false ,
35+ } : {
36+ label ?: string ;
37+ type ?: AxisType ;
38+ position ?: AxisPosition ;
39+ formatType ?: AxisFormatType ;
40+ formatPattern ?: string ;
41+ log ?: boolean ;
2542 } = { } ) : Axis {
43+ const { dh } = this ;
2644 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2745 return new ( dh as any ) . Axis ( {
2846 label,
29- type,
30- position,
31- formatType,
47+ type : type ?? dh . plot . AxisType . X ,
48+ position : position ?? dh . plot . AxisPosition . BOTTOM ,
49+ formatType : formatType ?? dh . Axis . FORMAT_TYPE_NUMBER ,
3250 formatPattern,
3351 log,
3452 } ) ;
3553 }
3654
37- static makeDefaultAxes ( ) : Axis [ ] {
55+ makeDefaultAxes ( ) : Axis [ ] {
56+ const { dh } = this ;
3857 return [
39- ChartTestUtils . makeAxis ( {
58+ this . makeAxis ( {
4059 label : ChartTestUtils . DEFAULT_X_TITLE ,
4160 type : dh . plot . AxisType . X ,
4261 } ) ,
43- ChartTestUtils . makeAxis ( {
62+ this . makeAxis ( {
4463 label : ChartTestUtils . DEFAULT_Y_TITLE ,
4564 type : dh . plot . AxisType . Y ,
4665 } ) ,
4766 ] ;
4867 }
4968
50- static makeSource ( {
51- axis = ChartTestUtils . makeAxis ( ) ,
52- } : {
53- axis : Axis ;
54- } ) : SeriesDataSource {
69+ makeSource ( { axis = this . makeAxis ( ) } : { axis : Axis } ) : SeriesDataSource {
5570 // eslint-disable-next-line @typescript-eslint/no-explicit-any
56- return new ( dh as any ) . SeriesDataSource ( { axis, type : axis . type } ) ;
71+ return new ( this . dh as any ) . SeriesDataSource ( { axis, type : axis . type } ) ;
5772 }
5873
59- static makeDefaultSources ( ) : SeriesDataSource [ ] {
60- const axes = ChartTestUtils . makeDefaultAxes ( ) ;
61- return axes . map ( axis => ChartTestUtils . makeSource ( { axis } ) ) ;
74+ makeDefaultSources ( ) : SeriesDataSource [ ] {
75+ const axes = this . makeDefaultAxes ( ) ;
76+ return axes . map ( axis => this . makeSource ( { axis } ) ) ;
6277 }
6378
64- static makeSeries ( {
79+ makeSeries ( {
6580 name = ChartTestUtils . DEFAULT_SERIES_NAME ,
66- plotStyle = dh . plot . SeriesPlotStyle . SCATTER ,
67- sources = ChartTestUtils . makeDefaultSources ( ) ,
81+ plotStyle = null ,
82+ sources = this . makeDefaultSources ( ) ,
6883 lineColor = null ,
6984 shapeColor = null ,
7085 } = { } ) : Series {
86+ const { dh } = this ;
7187 // eslint-disable-next-line @typescript-eslint/no-explicit-any
7288 return new ( dh as any ) . Series (
7389 name ,
74- plotStyle ,
90+ plotStyle ?? dh . plot . SeriesPlotStyle . SCATTER ,
7591 sources ,
7692 lineColor ,
7793 shapeColor
7894 ) ;
7995 }
8096
81- static makeChart ( {
97+ makeChart ( {
8298 title = ChartTestUtils . DEFAULT_CHART_TITLE ,
83- series = [ ChartTestUtils . makeSeries ( ) ] ,
84- axes = ChartTestUtils . makeDefaultAxes ( ) ,
99+ series = [ this . makeSeries ( ) ] ,
100+ axes = this . makeDefaultAxes ( ) ,
85101 showLegend = null ,
86102 rowspan = 1 ,
87103 colspan = 1 ,
@@ -98,7 +114,7 @@ class ChartTestUtils {
98114 column ?: number ;
99115 } = { } ) : Chart {
100116 // eslint-disable-next-line @typescript-eslint/no-explicit-any
101- return new ( dh as any ) . Chart ( {
117+ return new ( this . dh as any ) . Chart ( {
102118 title,
103119 series,
104120 axes,
@@ -110,14 +126,14 @@ class ChartTestUtils {
110126 } ) ;
111127 }
112128
113- static makeFigure ( {
129+ makeFigure ( {
114130 title = 'Figure' ,
115- charts = [ ChartTestUtils . makeChart ( ) ] ,
131+ charts = [ this . makeChart ( ) ] ,
116132 rows = 1 ,
117133 cols = 1 ,
118134 } = { } ) : Figure {
119135 // eslint-disable-next-line @typescript-eslint/no-explicit-any
120- return new ( dh as any ) . plot . Figure ( { title, charts, rows, cols } ) ;
136+ return new ( this . dh as any ) . plot . Figure ( { title, charts, rows, cols } ) ;
121137 }
122138}
123139
0 commit comments