@@ -81,4 +81,249 @@ describe("apply defaults", () => {
8181 const expanded = applyDefaults ( inputChartDef , { chartType : ChartType . Bubble } ) ;
8282 expect ( expanded . plotConfig ! . chartType ! ) . toEqual ( ChartType . Bubble ) ;
8383 } ) ;
84+
85+ const testData = {
86+ columnOrder : [ "a" , "b" ] ,
87+ columns : {
88+ a : "number" ,
89+ b : "number" ,
90+ } ,
91+ index : {
92+ type : "number" ,
93+ values : [ 2 , 3 , 4 ] ,
94+ } ,
95+ values : [
96+ {
97+ a : 10 ,
98+ b : 100 ,
99+ } ,
100+ {
101+ a : 20 ,
102+ b : 200 ,
103+ } ,
104+ {
105+ a : 30 ,
106+ b : 300 ,
107+ } ,
108+ ] ,
109+ } ;
110+
111+ it ( "y min can be passed through" , ( ) => {
112+
113+ const inputChartDef : any = {
114+ data : testData ,
115+ plotConfig : {
116+ y : {
117+ min : 15 ,
118+ } ,
119+ } ,
120+ } ;
121+
122+ const chartDef = applyDefaults ( inputChartDef ) ;
123+ expect ( chartDef . plotConfig . y ! . min ) . toBe ( 15 ) ;
124+ } ) ;
125+
126+ it ( "y min defaults to y series min" , ( ) => {
127+
128+ const inputChartDef : any = {
129+ data : testData ,
130+ plotConfig : {
131+ y : {
132+ } ,
133+ y2 : {
134+ } ,
135+ } ,
136+ axisMap : {
137+ y : [
138+ {
139+ series : "a" ,
140+ } ,
141+ {
142+ series : "b" ,
143+ } ,
144+ ] ,
145+ } ,
146+ } ;
147+
148+ const chartDef = applyDefaults ( inputChartDef ) ;
149+ expect ( chartDef . plotConfig . y ! . min ) . toBe ( 10 ) ;
150+ } ) ;
151+
152+ it ( "y max can be passed through" , ( ) => {
153+
154+ const inputChartDef : any = {
155+ data : testData ,
156+ plotConfig : {
157+ y : {
158+ max : 25 ,
159+ } ,
160+ } ,
161+ } ;
162+
163+ const chartDef = applyDefaults ( inputChartDef ) ;
164+ expect ( chartDef . plotConfig . y ! . max ) . toBe ( 25 ) ;
165+ } ) ;
166+
167+ it ( "y max defaults to y series max" , ( ) => {
168+
169+ const inputChartDef : any = {
170+ data : testData ,
171+ plotConfig : {
172+ y : {
173+ } ,
174+ y2 : {
175+ } ,
176+ } ,
177+ axisMap : {
178+ y : [
179+ {
180+ series : "a" ,
181+ } ,
182+ {
183+ series : "b" ,
184+ } ,
185+ ] ,
186+ } ,
187+ } ;
188+
189+ const chartDef = applyDefaults ( inputChartDef ) ;
190+ expect ( chartDef . plotConfig . y ! . max ) . toBe ( 300 ) ;
191+ } ) ;
192+
193+ it ( "y2 min can be passed through" , ( ) => {
194+
195+ const inputChartDef : any = {
196+ data : testData ,
197+ plotConfig : {
198+ y2 : {
199+ min : 0 ,
200+ } ,
201+ } ,
202+ } ;
203+
204+ const chartDef = applyDefaults ( inputChartDef ) ;
205+ expect ( chartDef . plotConfig . y2 ! . min ) . toBe ( 0 ) ;
206+ } ) ;
207+
208+ it ( "y2 min defaults to y2 series min" , ( ) => {
209+
210+ const inputChartDef : any = {
211+ data : testData ,
212+ plotConfig : {
213+ y : {
214+ } ,
215+ y2 : {
216+ } ,
217+ } ,
218+ axisMap : {
219+ y2 : [
220+ {
221+ series : "a" ,
222+ } ,
223+ {
224+ series : "b" ,
225+ } ,
226+ ] ,
227+ } ,
228+ } ;
229+
230+ const chartDef = applyDefaults ( inputChartDef ) ;
231+ expect ( chartDef . plotConfig . y2 ! . min ) . toBe ( 10 ) ;
232+ } ) ;
233+
234+ it ( "y2 max can be passed through" , ( ) => {
235+
236+ const inputChartDef : any = {
237+ data : testData ,
238+ plotConfig : {
239+ y2 : {
240+ max : 400 ,
241+ } ,
242+ } ,
243+ } ;
244+
245+ const chartDef = applyDefaults ( inputChartDef ) ;
246+ expect ( chartDef . plotConfig . y2 ! . max ) . toBe ( 400 ) ;
247+ } ) ;
248+
249+ it ( "y2 max defaults to y2 series max" , ( ) => {
250+
251+ const inputChartDef : any = {
252+ data : testData ,
253+ plotConfig : {
254+ y : {
255+ } ,
256+ y2 : {
257+ } ,
258+ } ,
259+ axisMap : {
260+ y2 : [
261+ {
262+ series : "a" ,
263+ } ,
264+ {
265+ series : "b" ,
266+ } ,
267+ ] ,
268+ } ,
269+ } ;
270+
271+ const chartDef = applyDefaults ( inputChartDef ) ;
272+ expect ( chartDef . plotConfig . y2 ! . max ) . toBe ( 300 ) ;
273+ } ) ;
274+
275+ it ( "min/max not computed for non number data" , ( ) => {
276+
277+ const data = {
278+ columnOrder : [ "a" , "b" ] ,
279+ columns : {
280+ a : "string" ,
281+ b : "string" ,
282+ } ,
283+ index : {
284+ type : "number" ,
285+ values : [ 2 , 3 , 4 ] ,
286+ } ,
287+ values : [
288+ {
289+ a : "10" ,
290+ b : "100" ,
291+ } ,
292+ {
293+ a : "20" ,
294+ b : "200" ,
295+ } ,
296+ {
297+ a : "30" ,
298+ b : "300" ,
299+ } ,
300+ ] ,
301+ } ;
302+
303+ const inputChartDef : any = {
304+ data,
305+ plotConfig : {
306+ y : {
307+ } ,
308+ y2 : {
309+ } ,
310+ } ,
311+ axisMap : {
312+ y : [
313+ {
314+ series : "a" ,
315+ } ,
316+ {
317+ series : "b" ,
318+ } ,
319+ ] ,
320+ } ,
321+ } ;
322+
323+ const chartDef = applyDefaults ( inputChartDef ) ;
324+ expect ( chartDef . plotConfig . y ! . min ) . toBeUndefined ( ) ;
325+ expect ( chartDef . plotConfig . y ! . max ) . toBeUndefined ( ) ;
326+ expect ( chartDef . plotConfig . y2 ! . min ) . toBeUndefined ( ) ;
327+ expect ( chartDef . plotConfig . y2 ! . max ) . toBeUndefined ( ) ;
328+ } ) ;
84329} ) ;
0 commit comments