@@ -1381,7 +1381,7 @@ export const transformPlotlyJsonToChartTableProps = (
1381
1381
let fontColor : React . CSSProperties [ 'color' ] | undefined ;
1382
1382
1383
1383
if ( Array . isArray ( fontColorRaw ) ) {
1384
- const colorEntry = fontColorRaw [ colIndex ] ;
1384
+ const colorEntry = fontColorRaw [ colIndex ] ?? fontColorRaw [ 0 ] ;
1385
1385
if ( Array . isArray ( colorEntry ) ) {
1386
1386
fontColor = typeof colorEntry [ 0 ] === 'string' ? colorEntry [ 0 ] : undefined ;
1387
1387
} else if ( typeof colorEntry === 'string' ) {
@@ -1395,17 +1395,24 @@ export const transformPlotlyJsonToChartTableProps = (
1395
1395
let fontSize : React . CSSProperties [ 'fontSize' ] | undefined ;
1396
1396
1397
1397
if ( Array . isArray ( fontSizeRaw ) ) {
1398
- fontSize = Array . isArray ( fontSizeRaw [ 0 ] ) ? fontSizeRaw [ 0 ] [ colIndex ] : fontSizeRaw [ colIndex ] ;
1398
+ const fontSizeEntry = fontSizeRaw [ colIndex ] ?? fontSizeRaw [ 0 ] ;
1399
+ fontSize = Array . isArray ( fontSizeRaw [ 0 ] )
1400
+ ? fontSizeRaw [ 0 ] [ colIndex ] ?? fontSizeRaw [ 0 ] [ 0 ]
1401
+ : typeof fontSizeEntry === 'number'
1402
+ ? fontSizeEntry
1403
+ : undefined ;
1399
1404
} else if ( typeof fontSizeRaw === 'number' ) {
1400
1405
fontSize = fontSizeRaw ;
1401
1406
}
1402
1407
1403
1408
const updatedColIndex = colIndex >= 1 ? 1 : 0 ;
1404
1409
const fillColorRaw = header ?. fill ?. color ;
1405
- const backgroundColor = Array . isArray ( fillColorRaw ) ? fillColorRaw [ updatedColIndex ] : fillColorRaw ;
1410
+ const backgroundColor = Array . isArray ( fillColorRaw )
1411
+ ? fillColorRaw [ updatedColIndex ] ?? fillColorRaw [ 0 ]
1412
+ : fillColorRaw ;
1406
1413
1407
1414
const textAlignRaw = header ?. align ;
1408
- const textAlign = Array . isArray ( textAlignRaw ) ? textAlignRaw [ colIndex ] : textAlignRaw ;
1415
+ const textAlign = Array . isArray ( textAlignRaw ) ? textAlignRaw [ colIndex ] ?? textAlignRaw [ 0 ] : textAlignRaw ;
1409
1416
1410
1417
const style : React . CSSProperties = {
1411
1418
...( typeof fontColor === 'string' ? { color : fontColor } : { } ) ,
@@ -1418,7 +1425,10 @@ export const transformPlotlyJsonToChartTableProps = (
1418
1425
} ) ;
1419
1426
} ;
1420
1427
const columns = tableData . cells ?. values ?? [ ] ;
1421
- const cells = tableData . cells ! . font ? tableData . cells ! : input . layout ?. template ?. data ?. table ! [ 0 ] . cells ;
1428
+ const cells =
1429
+ tableData . cells && Object . keys ( tableData . cells ) . length > 0
1430
+ ? tableData . cells
1431
+ : input . layout ?. template ?. data ?. table ?. [ 0 ] ?. cells ;
1422
1432
const rows = columns [ 0 ] . map ( ( _ , rowIndex : number ) =>
1423
1433
columns . map ( ( col , colIndex ) => {
1424
1434
const cellValue = col [ rowIndex ] ;
@@ -1432,7 +1442,7 @@ export const transformPlotlyJsonToChartTableProps = (
1432
1442
const rawFontColor = cells ?. font ?. color ;
1433
1443
let fontColor : React . CSSProperties [ 'color' ] | undefined ;
1434
1444
if ( Array . isArray ( rawFontColor ) ) {
1435
- const entry = rawFontColor [ colIndex ] ;
1445
+ const entry = rawFontColor [ colIndex ] ?? rawFontColor [ 0 ] ;
1436
1446
const colorValue = Array . isArray ( entry ) ? entry [ rowIndex ] : entry ;
1437
1447
fontColor = typeof colorValue === 'string' ? colorValue : undefined ;
1438
1448
} else if ( typeof rawFontColor === 'string' ) {
@@ -1442,7 +1452,7 @@ export const transformPlotlyJsonToChartTableProps = (
1442
1452
const rawFontSize = cells ?. font ?. size ;
1443
1453
let fontSize : React . CSSProperties [ 'fontSize' ] | undefined ;
1444
1454
if ( Array . isArray ( rawFontSize ) ) {
1445
- const entry = rawFontSize [ colIndex ] ;
1455
+ const entry = rawFontSize [ colIndex ] ?? rawFontSize [ 0 ] ;
1446
1456
const fontSizeValue = Array . isArray ( entry ) ? entry [ rowIndex ] : entry ;
1447
1457
fontSize = typeof fontSizeValue === 'number' ? fontSizeValue : undefined ;
1448
1458
} else if ( typeof rawFontSize === 'number' ) {
@@ -1453,14 +1463,14 @@ export const transformPlotlyJsonToChartTableProps = (
1453
1463
const rawBackgroundColor = cells ?. fill ?. color ;
1454
1464
let backgroundColor : React . CSSProperties [ 'backgroundColor' ] | undefined ;
1455
1465
if ( Array . isArray ( rawBackgroundColor ) ) {
1456
- const entry = rawBackgroundColor [ updatedColIndex ] ;
1466
+ const entry = rawBackgroundColor [ updatedColIndex ] ?? rawBackgroundColor [ 0 ] ;
1457
1467
const colorValue = Array . isArray ( entry ) ? entry [ rowIndex ] : entry ;
1458
1468
backgroundColor = typeof colorValue === 'string' ? colorValue : undefined ;
1459
1469
} else if ( typeof rawBackgroundColor === 'string' ) {
1460
1470
backgroundColor = rawBackgroundColor ;
1461
1471
}
1462
1472
1463
- const rawTextAlign = Array . isArray ( cells ?. align ) ? cells . align [ colIndex ] : cells ?. align ;
1473
+ const rawTextAlign = Array . isArray ( cells ?. align ) ? cells . align [ colIndex ] ?? cells . align [ 0 ] : cells ?. align ;
1464
1474
const textAlign = rawTextAlign as React . CSSProperties [ 'textAlign' ] | undefined ;
1465
1475
1466
1476
const style : React . CSSProperties = {
@@ -1486,7 +1496,9 @@ export const transformPlotlyJsonToChartTableProps = (
1486
1496
return {
1487
1497
headers : normalizeHeaders (
1488
1498
tableData . header ?. values ?? [ ] ,
1489
- tableData . header ?. font ? tableData . header : input . layout ?. template ?. data ?. table ! [ 0 ] . header ,
1499
+ tableData . header && Object . keys ( tableData . header ) . length > 0
1500
+ ? tableData . header
1501
+ : input . layout ?. template ?. data ?. table ! [ 0 ] . header ,
1490
1502
) ,
1491
1503
rows,
1492
1504
width : input . layout ?. width ,
0 commit comments