@@ -315,6 +315,101 @@ describe('updating layout axes', () => {
315315 } ) ;
316316} ) ;
317317
318+ describe ( 'handles subplots and columns/rows correctly' , ( ) => {
319+ const width = ChartUtils . AXIS_SIZE_PX * 5 ;
320+ const height = ChartUtils . AXIS_SIZE_PX * 10 ;
321+ const halfXMargin = ChartUtils . AXIS_SIZE_PX / width / 2 ;
322+ const halfYMargin = ChartUtils . AXIS_SIZE_PX / height / 2 ;
323+
324+ it ( 'handles row location correctly' , ( ) => {
325+ const axes = ChartTestUtils . makeDefaultAxes ( ) ;
326+ const charts = [
327+ ChartTestUtils . makeChart ( { axes, row : 0 } ) ,
328+ ChartTestUtils . makeChart ( { axes, row : 1 } ) ,
329+ ] ;
330+ const figure = ChartTestUtils . makeFigure ( { charts, rows : 2 } ) ;
331+ expect (
332+ ChartUtils . getChartBounds ( figure , charts [ 0 ] , width , height )
333+ ) . toEqual ( { bottom : 0.5 + halfYMargin , top : 1 , left : 0 , right : 1 } ) ;
334+ expect (
335+ ChartUtils . getChartBounds ( figure , charts [ 1 ] , width , height )
336+ ) . toEqual ( { bottom : 0 , top : 0.5 - halfYMargin , left : 0 , right : 1 } ) ;
337+ } ) ;
338+
339+ it ( 'handles column location correctly' , ( ) => {
340+ const axes = ChartTestUtils . makeDefaultAxes ( ) ;
341+ const charts = [
342+ ChartTestUtils . makeChart ( { axes, column : 0 } ) ,
343+ ChartTestUtils . makeChart ( { axes, column : 1 } ) ,
344+ ] ;
345+ const figure = ChartTestUtils . makeFigure ( { charts, cols : 2 } ) ;
346+ expect (
347+ ChartUtils . getChartBounds ( figure , charts [ 0 ] , width , height )
348+ ) . toEqual ( { bottom : 0 , top : 1 , left : 0 , right : 0.5 - halfXMargin } ) ;
349+ expect (
350+ ChartUtils . getChartBounds ( figure , charts [ 1 ] , width , height )
351+ ) . toEqual ( { bottom : 0 , top : 1 , left : 0.5 + halfXMargin , right : 1 } ) ;
352+ } ) ;
353+
354+ it ( 'handles colspan' , ( ) => {
355+ const axes = ChartTestUtils . makeDefaultAxes ( ) ;
356+ const charts = [
357+ ChartTestUtils . makeChart ( { axes, column : 0 } ) ,
358+ ChartTestUtils . makeChart ( { axes, column : 1 } ) ,
359+ ChartTestUtils . makeChart ( { axes, row : 1 , colspan : 2 } ) ,
360+ ] ;
361+ const figure = ChartTestUtils . makeFigure ( { charts, cols : 2 , rows : 2 } ) ;
362+ expect ( ChartUtils . getChartBounds ( figure , charts [ 0 ] , width , height ) ) . toEqual (
363+ {
364+ bottom : 0.5 + halfYMargin ,
365+ top : 1 ,
366+ left : 0 ,
367+ right : 0.5 - halfXMargin ,
368+ }
369+ ) ;
370+ expect ( ChartUtils . getChartBounds ( figure , charts [ 1 ] , width , height ) ) . toEqual (
371+ {
372+ bottom : 0.5 + halfYMargin ,
373+ top : 1 ,
374+ left : 0.5 + halfXMargin ,
375+ right : 1 ,
376+ }
377+ ) ;
378+ expect (
379+ ChartUtils . getChartBounds ( figure , charts [ 2 ] , width , height )
380+ ) . toEqual ( { bottom : 0 , top : 0.5 - halfYMargin , left : 0 , right : 1 } ) ;
381+ } ) ;
382+
383+ it ( 'handles rowspan' , ( ) => {
384+ const axes = ChartTestUtils . makeDefaultAxes ( ) ;
385+ const charts = [
386+ ChartTestUtils . makeChart ( { axes, row : 0 } ) ,
387+ ChartTestUtils . makeChart ( { axes, row : 1 } ) ,
388+ ChartTestUtils . makeChart ( { axes, column : 1 , rowspan : 2 } ) ,
389+ ] ;
390+ const figure = ChartTestUtils . makeFigure ( { charts, cols : 2 , rows : 2 } ) ;
391+ expect ( ChartUtils . getChartBounds ( figure , charts [ 0 ] , width , height ) ) . toEqual (
392+ {
393+ bottom : 0.5 + halfYMargin ,
394+ top : 1 ,
395+ left : 0 ,
396+ right : 0.5 - halfXMargin ,
397+ }
398+ ) ;
399+ expect ( ChartUtils . getChartBounds ( figure , charts [ 1 ] , width , height ) ) . toEqual (
400+ {
401+ bottom : 0 ,
402+ top : 0.5 - halfYMargin ,
403+ left : 0 ,
404+ right : 0.5 - halfXMargin ,
405+ }
406+ ) ;
407+ expect (
408+ ChartUtils . getChartBounds ( figure , charts [ 2 ] , width , height )
409+ ) . toEqual ( { bottom : 0 , top : 1 , left : 0.5 + halfXMargin , right : 1 } ) ;
410+ } ) ;
411+ } ) ;
412+
318413describe ( 'returns the axis layout ranges properly' , ( ) => {
319414 function makeLayout ( layout ) {
320415 return {
0 commit comments